-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
159 changed files
with
8,655 additions
and
19,204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
/* | ||
* Copyright 2024 Google LLC | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are | ||
* met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following disclaimer | ||
* in the documentation and/or other materials provided with the | ||
* distribution. | ||
* * Neither the name of Google Inc. nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
namespace Google\Cloud\Core\Middleware; | ||
|
||
use Google\ApiCore\ApiException; | ||
use Google\ApiCore\BidiStream; | ||
use Google\ApiCore\Call; | ||
use Google\ApiCore\ClientStream; | ||
use Google\ApiCore\Middleware\MiddlewareInterface; | ||
use Google\ApiCore\ServerStream; | ||
use Google\Cloud\Core\RequestProcessorTrait; | ||
use GuzzleHttp\Promise\PromiseInterface; | ||
use Throwable; | ||
|
||
/** | ||
* Middleware that wraps any Api Exception to a `Google\Cloud\Core\Exception` | ||
* exception class. This is primarily to maintain backwards compatibility with | ||
* previous Spanner versions. | ||
* | ||
* @internal | ||
*/ | ||
class ExceptionMiddleware implements MiddlewareInterface | ||
{ | ||
use RequestProcessorTrait; | ||
|
||
/** @var callable */ | ||
private $nextHandler; | ||
|
||
public function __construct(callable $nextHandler) { | ||
$this->nextHandler = $nextHandler; | ||
} | ||
|
||
/** | ||
* @param Call $call | ||
* @param array $options | ||
* | ||
* @return PromiseInterface|ClientStream|ServerStream|BidiStream | ||
*/ | ||
public function __invoke(Call $call, array $options) | ||
{ | ||
$response = ($this->nextHandler)($call, $options); | ||
if ($response instanceof PromiseInterface) { | ||
return $response->then(null, function ($value) { | ||
if ($value instanceof \Google\ApiCore\ApiException) { | ||
throw $this->convertToGoogleException($value); | ||
} | ||
if ($value instanceof Throwable) { | ||
throw $value; | ||
} | ||
}); | ||
} | ||
// this can also be a Stream | ||
return $response; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# Migrating Google Spanner from V1 to V2 | ||
|
||
## How to upgrade | ||
|
||
Update your `google/cloud-spanner` dependency to `^2.0`: | ||
|
||
``` | ||
{ | ||
"require": { | ||
"google/cloud-spanner": "^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` | ||
- `FetchAuthTokenInterface` -> 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` | ||
- `quotaProject` -> Moved to `credentialsConfig.quotaProject` | ||
- `httpHandler` -> Moved to `transportConfig.rest.httpHandler` | ||
- `authHttpHandler` -> Moved to `credentialsConfig.authHttpHandler` | ||
- `retries` -> Removed from client options and moved to call options `retrySettings.maxRetries` | ||
|
||
### Retry Options changes | ||
|
||
The retry options have been moved to use [`RetrySettings`][RetrySettings] in call options | ||
and function parameters. | ||
|
||
- `retries` -> Renamed to `retrySettings.maxRetries` | ||
- `maxRetries` -> Renamed to `retrySettings.maxRetries` | ||
|
||
[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 any users. When the | ||
`SpannerClient` was created, behind the scenes a connection adapter was initialized. | ||
This connection object was then forwarded to any resource classes internally, | ||
like so: | ||
|
||
```php | ||
// This initialized a connection object | ||
$client = new SpannerClient(); | ||
// This passed on the connection object to the Instance class | ||
$instance = $spanner->instance('my-instance'); | ||
``` | ||
|
||
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 `Instance` class, this will break in Spanner `v2`: | ||
|
||
```php | ||
// Not intended | ||
$connObj = new Grpc([]); | ||
$instance = new Instance( | ||
$connObj, | ||
// other constructor options | ||
); | ||
``` | ||
|
||
### `Google\Cloud\Spanner\Duration` class is not used anymore. | ||
We have removed the `Google\Cloud\Spanner\Duration` class from the library. Instead we will be using the `Google\Protobuf\Duration` class. | ||
|
||
### IAM class changes | ||
|
||
We have kept the functionality of `IAM` the same, however the underlying `IAM` class has changed. | ||
```php | ||
// In V1, this used to return an instance of Google\Cloud\Core\Iam\Iam | ||
$iam = $instance->iam(); | ||
|
||
// In V2, this will return an instance of Google\Cloud\Core\Iam\IamManager | ||
$iam = $instance->iam(); | ||
|
||
// Both the classes share the same functionality, so the following methods will work for both versions. | ||
$iam->policy(); | ||
$iam->setPolicy(); | ||
$iam->testIamPermissions(); | ||
``` | ||
|
||
### LongRunningOperation class changes | ||
|
||
We have kept the functionality of `LongRunningOperation` the same, | ||
however the underlying `LongRunningOperation` class has changed. | ||
```php | ||
// In V1, this used to return an instance of Google\Cloud\Core\LongRunning\LongRunningOperation. | ||
$lro = $instance->create($configuration); | ||
|
||
// In V2, this will return an instance of Google\ApiCore\OperationResponse. | ||
$lro = $instance->create($configuration); | ||
|
||
// Both the classes share the same functionality, so the following methods will work for both versions. | ||
$lro->name(); | ||
$lro->done(); | ||
$lro->state(); | ||
$lro->result(); | ||
$lro->error(); | ||
$lro->info(); | ||
$lro->reload(); | ||
$lro->pollUntilComplete(); | ||
$lro->cancel(); | ||
$lro->delete(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.