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

Enhance Commit API readability #7296

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
0baef28
feat!: [Datastore] Upgrade to PHP v2
yash30201 Mar 26, 2024
7215b2e
Enable Gapic Client support for Request Handler.
yash30201 Mar 26, 2024
237531f
Add credentials wrapper support in DatastoreClient
yash30201 Mar 26, 2024
cac76f1
Add request handler and serializer in DatastoreClient
yash30201 Mar 26, 2024
f39189f
Update Resource classes to add serializer and requesthandler in their…
yash30201 Mar 26, 2024
be2533c
Update snippet and unit tests to add request handler and serializer.
yash30201 Mar 26, 2024
d06abf7
Update beginTransaction and allocateIds rpc + unit + snippet tests
yash30201 Mar 31, 2024
cee1539
Update lookup rpc + unit + snippet tests
yash30201 Apr 1, 2024
927d510
Update RunQuery rpc + unit + snippet tests
yash30201 Apr 3, 2024
c9d2186
Update RunAggregationQuery rpc + unit + snippet tests
yash30201 Apr 3, 2024
82716bd
Update Commit rpc + unit + snippet tests
yash30201 Apr 3, 2024
fcdcf9b
Update Rollback rpc + unit + snippet tests
yash30201 Apr 3, 2024
4c32fc9
Remove all connection classes and references
yash30201 Apr 3, 2024
0596f27
Remove old gapic files and class aliases
yash30201 Apr 4, 2024
fa9e30a
Fix unit test failures
yash30201 Apr 4, 2024
e6fa30a
Fix PHP style checks
yash30201 Apr 4, 2024
2d01ea6
Fix aggregation query snippet test
yash30201 Apr 4, 2024
e098d66
Add MIGRATION.md
yash30201 Apr 4, 2024
2196aa2
Update documentation for DatastoreClient
yash30201 Apr 4, 2024
bf2c50b
Increase minimum core version to 1.55
yash30201 Apr 4, 2024
d6e2823
Mark `Operation` as internal
yash30201 Apr 4, 2024
6a03125
Merge branch 'main' into datastore-php-v2
yash30201 Apr 4, 2024
af549dd
Increase minimum core version to 1.57 (to be version)
yash30201 Apr 4, 2024
170d590
Fix emulator tests
yash30201 Apr 5, 2024
8e43aab
Self iteration
yash30201 Apr 5, 2024
9cf8493
Merge branch 'main' into datastore-php-v2
yash30201 May 6, 2024
fad4022
Iteration 1
yash30201 May 6, 2024
d45178c
fix(Spanner):Properly remove redundant keys from request options
yash30201 May 7, 2024
14fc795
pr iteration
yash30201 May 7, 2024
b9f0661
Add comments
yash30201 May 7, 2024
c6275bd
fix(Datastore):Properly remove redundant keys from request options
yash30201 May 7, 2024
81655e1
chore(Datastore): Update Composer version to use the upcoming latest.
yash30201 May 7, 2024
7e1dfa3
chore(Datastore): Update Composer version to use the upcoming latest.
yash30201 May 7, 2024
8c5a721
Merge branch 'main' into datastore-tryout-1
yash30201 May 7, 2024
b49d34e
Merge branch 'main' into datastore-php-v2
yash30201 May 7, 2024
2f33be4
Merge branch 'datastore-php-v2' of https://github.com/yash30201/googl…
yash30201 May 7, 2024
4c29341
chore(Datastore): Enhance readability of RunQuery and RunAggregationQ…
yash30201 May 7, 2024
dd24b76
Merge branch 'datastore-php-v2' into datastore-tryout-1
yash30201 May 7, 2024
ab08e92
Enhance Commit API readability
yash30201 May 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ keys/
.testing
.split
__pycache__

# VS Code local workspace settings
.vscode
85 changes: 81 additions & 4 deletions Core/src/Testing/DatastoreOperationRefreshTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

namespace Google\Cloud\Core\Testing;

use Google\Cloud\Datastore\Connection\ConnectionInterface;
use Google\ApiCore\Serializer;
use Google\Cloud\Core\RequestHandler;
use Google\Cloud\Datastore\EntityMapper;
use Google\Cloud\Datastore\Operation;
use Google\Cloud\Datastore\V1\Client\DatastoreClient;
use Prophecy\Argument;

/**
* Refresh Datastore operation class
Expand All @@ -33,7 +36,7 @@ trait DatastoreOperationRefreshTrait
* Refresh the operation property of a given stubbed class.
*
* @param mixed $stub
* @param ConnectionInterface $connection
* @param RequestHandler $requestHandler
* @param array $options {
* Configuration Options
*
Expand All @@ -43,7 +46,7 @@ trait DatastoreOperationRefreshTrait
* }
* @return mixed
*/
public function refreshOperation($stub, ConnectionInterface $connection, array $options = [])
public function refreshOperation($stub, RequestHandler $requestHandler, array $options = [])
{
$options += [
'projectId' => null,
Expand All @@ -57,13 +60,87 @@ public function refreshOperation($stub, ConnectionInterface $connection, array $
$options['returnInt64AsObject']
);

$serializer = $this->getSerializer();

$stub->___setProperty('operation', new Operation(
$connection,
$requestHandler,
$serializer,
$options['projectId'],
$options['returnInt64AsObject'],
$mapper
));

return $stub;
}

/**
* Helper method for Unit and Snippet test classes. This mocks the
* $requestHandler class property present in the Test Class with
* given arguments.
*
* @param string $methodName The method name to mock in RequestHandler::sendRequest
* @param array<string, mixed> $params The parameters to look for in the
* array equivalent of rpc request.
* @param mixed $returnValue The value to be returned by sendRequest mock.
* @param null|int $shouldBeCalledTimes Adds a shouldBeCalled prophecy. Defaults to `null`, implying nothing is added.
* [
* `0` => `shouldBeCalled`,
* Non zero positive integer $x => `shouldBeCalledTimes($x)`
* ]
*/
private function mockSendRequest($methodName, $params, $returnValue, $shouldBeCalledTimes = null)
{
$serializer = $this->getSerializer();

$prophecy = $this->requestHandler->sendRequest(
DatastoreClient::class,
$methodName,
Argument::that(function ($arg) use ($methodName, $params, $serializer) {
$requestName = ucfirst($methodName . 'Request');
$x = explode('\\', get_class($arg));
$argName = end($x);

if ($requestName != $argName) {
return false;
}
$data = $serializer->encodeMessage($arg);
return array_replace_recursive($data, $params) == $data;
}),
Argument::cetera()
);

if (!is_null($shouldBeCalledTimes)) {
if ($shouldBeCalledTimes == 0) {
$prophecy->shouldBeCalled();
} else {
$prophecy->shouldBeCalledTimes($shouldBeCalledTimes);
}
}

$prophecy->willReturn($returnValue);
}

private function getSerializer()
{
if (isset($this->serializer)) {
return $this->serializer;
}

return new Serializer([], [
'google.protobuf.Value' => function ($v) {
return $this->flattenValue($v);
},
'google.protobuf.Timestamp' => function ($v) {
return $this->formatTimestampFromApi($v);
}
], [], [
'google.protobuf.Timestamp' => function ($v) {
if (is_string($v)) {
$dt = new \DateTime($v);
return ['seconds' => $dt->format('U')];
}
return $v;
}
]);
}
}
4 changes: 0 additions & 4 deletions Core/tests/Unit/ServiceBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Google\Cloud\Core\ServiceBuilder;
use Google\Cloud\Core\Testing\CheckForClassTrait;
use Google\Cloud\Core\Testing\GrpcTestTrait;
use Google\Cloud\Datastore\DatastoreClient;
use Google\Cloud\Firestore\FirestoreClient;
use Google\Cloud\Language\LanguageClient;
use Google\Cloud\Logging\LoggingClient;
Expand Down Expand Up @@ -161,9 +160,6 @@ public function serviceProvider()
[
'bigQuery',
BigQueryClient::class
], [
'datastore',
DatastoreClient::class
], [
'firestore',
FirestoreClient::class,
Expand Down
83 changes: 83 additions & 0 deletions Datastore/MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Migrating Google Datastore from V1 to V2

## How to upgrade

Update your `google/cloud-datastore` dependency to `^2.0`:

```
{
"require": {
"google/cloud-datastore": "^2.0"
}
}
```

## Changes

### Client Options changes

The following client options are removed/replaced with other options present in
[`ClientOptions`][ClientOptions]. This was done to ensure client options are consistent across all
Google Cloud clients.

- `authCache` -> Moved to `credentialsConfig.authCache`
- `authCacheOptions` -> Moved to `credentialsConfig.authCacheOptions`
- `credentialsFetcher` -> Moved to `credentials`
- `keyFile` -> Moved to `credentials`
- `keyFilePath` -> Moved to `credentials`
- `requestTimeout` -> Removed from client options and moved to a call option `timeoutMillis`
- `scopes` -> Moved to `credentialsConfig.scopes`
- `defaultScopes` -> Moved to `credentialsConfig.defaultScopes`
- `quotaProject` -> Moved to `credentialsConfig.quotaProject`
- `httpHandler` -> Moved to `transportConfig.rest.httpHandler`
- `authHttpHandler` -> Moved to `credentialsConfig.authHttpHandler`
- `asyncHttpHandler` -> Removed in favour of a single httpHandler option.
- `restOptions` -> Moved to `transportConfig.rest`
- `grpcOptions` -> Moved to `transportConfig.grpc`
- `accessToken` -> Removed
- `shouldSignRequest` -> Removed
- `preferNumericProjectId` -> Removed

### Retry Options changes

The retry options have been moved to use [`RetrySettings`][RetrySettings] in Client Options and in
call options.

- `retries` -> Renamed to `retrySettings.maxRetries`
- `restRetryFunction` -> Renamed to `retrySettings.retryFunction`
- `grpcRetryFunction` -> Renamed to `retrySettings.retryFunction`
- `delayFunc`/`calcDelayFunction` -> Removed in favor of the properties
`retrySettings.initialRetryDelayMillis`, `retrySettings.retryDelayMultiplier` and
`retrySettings.maxRetryDelayMillis`.

[RetrySettings]: https://googleapis.github.io/gax-php/v1.26.1/Google/ApiCore/RetrySettings.html

[ClientOptions]: https://googleapis.github.io/gax-php/v1.26.1/Google/ApiCore/Options/ClientOptions.html

### Connection classes are not used anymore.

This is a major change with this major version but one that we hope won't break most users. When one
created a `DatastoreClient`, behind the scenes a connection adapter was initialized based on your
transport preferences and then forwarded to operation class internally. This connection adapter was used
to deliver requests internally:

```php
// This initialized a connection object and passed it internally to Operation class.
$client = new DatastoreClient(['transport' => 'rest']);
// This used the connection object internally to deliver the lookup request.
$client->lookup($key);
```

As you can see the connection object was handled internally. If you used the library in this way,
you will not need to make any changes. However, if you created the connection classes directly
and passed it to the Operation class, this will break in Datastore `v2`:

```php
// Not intended
$connObj = new Rest([]);
$operation = new Operation(
$connObj,
// other operation options
);
$operation->lookup($keys);
```
2 changes: 1 addition & 1 deletion Datastore/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"minimum-stability": "stable",
"require": {
"php": "^8.0",
"google/cloud-core": "^1.52.7",
"google/cloud-core": "^1.59",
"google/gax": "^1.30"
},
"require-dev": {
Expand Down
62 changes: 0 additions & 62 deletions Datastore/src/Connection/ConnectionInterface.php

This file was deleted.

Loading
Loading