Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: [Spanner] Upgrade to V2 (Part 1/2) #7193

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0f9b3b7
feat!: [Spanner] Upgrade to PHP V2
ajupazhamayil Apr 1, 2024
37076aa
add RequestHandler to SpannerClient
ajupazhamayil Apr 1, 2024
f9fb788
make LRO work for create database operation
ajupazhamayil Apr 18, 2024
6ae9e61
Replace Connection class in Database.php
ajupazhamayil May 7, 2024
4bed2dd
Replace Conncection class objects in Operation and Session classess
ajupazhamayil May 8, 2024
996fecf
Resolve unittest issues in TransactionTypeTest and TransactionTest
ajupazhamayil May 14, 2024
dd44928
Resolve System/AdminTest issues
ajupazhamayil May 15, 2024
dd83885
Resolve System test issues: BatchTest
ajupazhamayil May 15, 2024
0966a99
Resolve system/TransactionTest issues
ajupazhamayil May 15, 2024
5b9841d
resolve system tests issues of CacheSessionPool
ajupazhamayil May 15, 2024
c555140
make requestHandler return Promise
ajupazhamayil May 15, 2024
143e700
Resolve styling issues
ajupazhamayil May 15, 2024
677d853
Resolve PG tests
ajupazhamayil May 16, 2024
1bb522e
rename LROManagerTrait to LongRunningOperationTrait
ajupazhamayil May 19, 2024
560d12e
Remove extra decodeMessages
ajupazhamayil May 21, 2024
3da94d1
Resolve system tests issues
ajupazhamayil May 21, 2024
aca7c7a
Improve code readablity
ajupazhamayil May 22, 2024
d254501
Resolve unit test issues
ajupazhamayil May 23, 2024
5b440b4
remove scopes to see the unit tests failures
ajupazhamayil May 23, 2024
0fcd821
rollback the changes for testing
ajupazhamayil May 23, 2024
a743df5
Fix tests/Unit/DatabaseTest.php
ajupazhamayil May 24, 2024
6ddc272
Remove projectId from the DatabaseTest
ajupazhamayil May 24, 2024
abf2102
Resolve unittest ADC issues
ajupazhamayil May 24, 2024
8dd9cfe
make the unittests pass
ajupazhamayil May 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
163 changes: 163 additions & 0 deletions Core/src/LongRunning/LROTraitV2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<?php
/**
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Cloud\Core\LongRunning;

use Google\ApiCore\Serializer;
use Google\Cloud\Core\Iterator\ItemIterator;
use Google\Cloud\Core\Iterator\PageIterator;
use Google\Cloud\Core\RequestHandler;
use Google\LongRunning\ListOperationsRequest;
use Google\LongRunning\OperationsGrpcClient;

/**
* Provide Long Running Operation support to Google Cloud PHP Clients.
*
* This trait should be used by a user-facing client which implements LRO.
*/
trait LROTraitV2
bshaffer marked this conversation as resolved.
Show resolved Hide resolved
{
/**
* @var RequestHandler
*/
private RequestHandler $requestHandler;

/**
* @var Serializer
*/
private Serializer $serializer;

/**
* @var string
*/
private $clientClass;

/**
* @var array
*/
private $lroCallables;

/**
* @var string
*/
private $lroResource;

/**
* Populate required LRO properties.
*
* @param RequestHandler The request handler that is responsible for sending a request
* and serializing responses into relevant classes.
* @param Serializer $serializer The serializer instance to encode/decode messages.
* @param array $callablesMap An collection of form [(string) typeUrl, (callable) callable]
* providing a function to invoke when an operation completes. The
* callable Type should correspond to an expected value of
* operation.metadata.typeUrl.
* @param array $lroResponseMappers A list of mappers for deserializing operation results.
* @param string $lroResource [optional] The resource for which operations
* may be listed.
*/
private function setLroProperties(
RequestHandler $requestHandler,
Serializer $serializer,
string $clientClass,
array $lroCallables,
array $lroResponseMappers,
$resource = null
) {
$this->requestHandler = $requestHandler;
$this->serializer = $serializer;
$this->clientClass = $clientClass;
$this->lroCallables = $lroCallables;
$this->lroResponseMappers = $lroResponseMappers;
$this->lroResource = $resource;
}

/**
* Resume a Long Running Operation
*
* @param string $operationName The Long Running Operation name.
* @param array $lroResponseMappers A list of mappers for deserializing operation results.
* @param array $info [optional] The operation data.
* @return LongRunningOperationManger
*/
public function resumeOperation($operationName, array $info = [])
{
return new LongRunningOperationManager(
$this->requestHandler,
$this->serializer,
$this->lroCallables,
$this->lroResponseMappers,
$this->clientClass,
$operationName,
$info
);
}

/**
* List long running operations.
*
* @param array $options [optional] {
* Configuration Options.
*
* @type string $name The name of the operation collection.
* @type string $filter The standard list filter.
* @type int $pageSize Maximum number of results to return per
* request.
* @type int $resultLimit Limit the number of results returned in total.
* **Defaults to** `0` (return all results).
* @type string $pageToken A previously-returned page token used to
* resume the loading of results from a specific point.
* }
* @return ItemIterator<LongRunningOperation>
*/
public function longRunningOperations(array $options = [])
{
if (is_null($this->lroResource)) {
throw new \BadMethodCallException('This service does not support listing operations.');
}
list($data, $optionalArgs) = $this->splitOptionalArgs($options);
$resultLimit = $this->pluck('resultLimit', $data, false) ?: 0;
$data['name'] = $this->lroResource .'/operations';

$request = $this->serializer->decodeMessage(new ListOperationsRequest(), $data);

return new ItemIterator(
new PageIterator(
function (array $operation) {
return $this->resumeOperation($operation['name'], $operation);
},
function ($callOptions) use ($optionalArgs, $request) {
if (isset($callOptions['pageToken'])) {
$request->setPageToken($callOptions['pageToken']);
}

return $this->requestHandler->sendRequest(
OperationsGrpcClient::class,
bshaffer marked this conversation as resolved.
Show resolved Hide resolved
'listOperations',
$request,
$optionalArgs
);
},
$options,
[
'itemsKey' => 'operations',
'resultLimit' => $resultLimit
]
)
);
}
}