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

Migrate to new protobuf implementation #512

Merged
merged 66 commits into from
Jun 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
6be2e07
Update for new proto3 types
michaelbausor May 10, 2017
4dc99ee
Fixes for spanner
michaelbausor May 20, 2017
42b04d1
Address PR comments
michaelbausor May 22, 2017
d261bbb
Update tests
michaelbausor May 23, 2017
7398560
Fix Mutation Write
michaelbausor May 23, 2017
20efc87
Update spanner serialization
michaelbausor May 23, 2017
8f748c8
Merge branch 'master' into proto3-pr
michaelbausor May 23, 2017
cf5d921
Support message type transformers
michaelbausor May 23, 2017
f0909c2
Update spanner unpacking
michaelbausor May 23, 2017
1924e27
Merge branch 'master' into proto3-pr
michaelbausor May 31, 2017
6aa7ff1
Update to match latest gax
michaelbausor May 31, 2017
ec2fa7c
Remove proto dir
michaelbausor Jun 2, 2017
51b1724
Update GAPIC clients and tests
michaelbausor Jun 2, 2017
1f12e7e
Add protobuf types
michaelbausor Jun 2, 2017
fd386cf
Update psr-4
michaelbausor Jun 2, 2017
08f037e
Move GPBMetadata classes, update pubsub namespaces
michaelbausor Jun 13, 2017
91e9ba5
Update API composer files, remove trace GAPIC
michaelbausor Jun 14, 2017
5ef7131
Merge branch 'master' into proto3-pr
michaelbausor Jun 14, 2017
42cb13b
Update composer
michaelbausor Jun 14, 2017
a3bb8af
Remove label formatting, update field mask handling
michaelbausor Jun 14, 2017
a7f8cff
Check isset and true instead of only isset
michaelbausor Jun 14, 2017
29761fa
Update composer
michaelbausor Jun 14, 2017
ed85cc6
Merge branch 'master' into proto3-pr
michaelbausor Jun 15, 2017
51cd484
Update constants, fix update instance tests
michaelbausor Jun 15, 2017
ffd5ca8
Fix formatting, exclude proto files from formatting rule
michaelbausor Jun 15, 2017
079fcf9
Update composer.json
michaelbausor Jun 15, 2017
a518c92
Update snippets
michaelbausor Jun 16, 2017
9c4b04b
Update snippet and doc gen parsers
michaelbausor Jun 16, 2017
8e69c36
Support undocumented classes and methods
michaelbausor Jun 16, 2017
bc2acb0
Regenerate with updated docs
michaelbausor Jun 16, 2017
bae598e
Update protobuf type docblocks
michaelbausor Jun 17, 2017
b3f6eaf
Fix LIST enum
michaelbausor Jun 17, 2017
f3c87a6
Merge branch 'master' into proto3-pr
michaelbausor Jun 19, 2017
11c9f67
Update GAPIC and protobuf classes
michaelbausor Jun 20, 2017
398ad11
Update Core to ensure changes are not breaking
michaelbausor Jun 20, 2017
5bae78f
Remove protobuf types
michaelbausor Jun 20, 2017
18d47ec
Revert "Update snippets"
michaelbausor Jun 21, 2017
0b3d7c4
Revert "Update snippet and doc gen parsers"
michaelbausor Jun 21, 2017
2ae6e43
Add GAPIC clients
michaelbausor Jun 21, 2017
531ea97
Update composer, use GPBGrpc classes from Core
michaelbausor Jun 21, 2017
a083e5c
Fix pubsub namespaces
michaelbausor Jun 21, 2017
5c6b697
Update composer, small fixes
michaelbausor Jun 21, 2017
2ada452
Revert "Support undocumented classes and methods"
michaelbausor Jun 21, 2017
6276119
Revert "Update API composer files, remove trace GAPIC"
michaelbausor Jun 21, 2017
2f02e89
Revert ruleset
michaelbausor Jun 21, 2017
92a189d
Update composer, add deprecation notice
michaelbausor Jun 21, 2017
b59762d
Remove HHVM from travis testing
michaelbausor Jun 21, 2017
97d556c
Skip gRPC tests for HHVM
michaelbausor Jun 22, 2017
ed3a9ab
Skip dataProviders for gRPC tests
michaelbausor Jun 22, 2017
77d331e
Enable xdebug for testing
michaelbausor Jun 22, 2017
e1eaeb8
Update xdebug for travis
michaelbausor Jun 22, 2017
f8d50cc
Remove protobuf deps when running hhvm
michaelbausor Jun 22, 2017
5921244
Skip Spanner tests that use gRPC
michaelbausor Jun 22, 2017
707a910
Remove test code
michaelbausor Jun 23, 2017
df68e90
Revert "Update Core to ensure changes are not breaking"
michaelbausor Jun 23, 2017
82b7021
Revert "Update composer, use GPBGrpc classes from Core"
michaelbausor Jun 23, 2017
87532e9
Revert "Remove test code"
michaelbausor Jun 23, 2017
8776d4c
Reintroduce namespace changes
michaelbausor Jun 23, 2017
e11d574
Update snippet tests
michaelbausor Jun 23, 2017
c271202
Check for external classes in Google\Cloud namespace
michaelbausor Jun 23, 2017
ab8fc4c
Remove debug and unused code
michaelbausor Jun 23, 2017
cfe71c2
Rename SpannerClient imports
michaelbausor Jun 23, 2017
cabb852
Update gax and proto-client versions
michaelbausor Jun 23, 2017
0517090
Update links to GAX and proto-clien docs
michaelbausor Jun 24, 2017
4f1a9ee
Update proto-client in travis
michaelbausor Jun 24, 2017
c3368d2
Address PR comments
michaelbausor Jun 26, 2017
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ matrix:
before_script:
- pecl install grpc || echo 'Failed to install grpc'
- composer install
- if [[ $TRAVIS_PHP_VERSION =~ ^hhvm ]]; then composer --no-interaction --dev remove google/protobuf google/gax google/proto-client; fi

script:
- ./dev/sh/tests
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@
"league/json-guard": "^0.3",
"erusev/parsedown": "^1.6",
"vierbergenlars/php-semver": "^3.0",
"google/proto-client-php": "^0.13",
"google/gax": "^0.10",
"google/proto-client": "^0.20.0",
"google/gax": "^0.20.0",
"symfony/lock": "3.3.x-dev#1ba6ac9"
},
"suggest": {
"google/gax": "Required to support gRPC",
"google/proto-client-php": "Required to support gRPC",

This comment was marked as spam.

This comment was marked as spam.

"google/proto-client": "Required to support gRPC",
"symfony/lock": "Required for the Spanner cached based session pool. Please require the following commit: 3.3.x-dev#1ba6ac9"
},
"autoload": {
Expand All @@ -74,6 +74,7 @@
"autoload-dev": {
"psr-4": {
"Google\\Cloud\\Dev\\": "dev/src",
"Google\\Cloud\\Tests\\": "tests",
"Google\\Cloud\\Tests\\System\\": "tests/system",
"Google\\Cloud\\Tests\\Unit\\": "tests/unit"
},
Expand Down
14 changes: 12 additions & 2 deletions dev/src/DocGenerator/Parser/CodeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private function buildDescription($docBlock, $content = null)
if ($part instanceof Seetag) {
$reference = $part->getReference();

if (substr_compare($reference, 'Google\Cloud', 0, 12) === 0) {
if ($this->hasInternalType($reference)) {
$part = $this->buildLink($reference);
} elseif ($this->hasExternalType(trim(str_replace('@see', '', $part)))) {
$part = $this->buildExternalType(trim(str_replace('@see', '', $part)));
Expand Down Expand Up @@ -477,7 +477,7 @@ private function handleTypes($types, array $aliases = [])
}

$type = sprintf(htmlentities('%s<%s>'), $matches[1], $matches[2]);
} elseif (substr_compare($type, '\\Google\\Cloud', 0, 13) === 0) {
} elseif ($this->hasInternalType($type)) {
$type = $this->buildLink($type);
} elseif ($this->hasExternalType($type)) {
$type = $this->buildExternalType($type);
Expand All @@ -500,6 +500,16 @@ private function resolveTypeAlias($type, array $aliases)
return $type;
}

private function hasInternalType($type)
{
$type = trim($type, '\\');
if (substr_compare($type, 'Google\\Cloud', 0, 12) === 0) {
$file = __DIR__ . '/../../../src/' . str_replace('\\', '/', $type) . ".php";
return file_exists($file);
}
return false;
}

private function hasExternalType($type)
{
$type = trim($type, '\\');
Expand Down
11 changes: 10 additions & 1 deletion dev/src/Snippet/Coverage/Coverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

class Coverage
{
private static $snippetExcludeList = [
'/\\\Google\\\Cloud\\\Core\\\PhpArray/',
];

/**
* @var ScannerInterface
*/
Expand All @@ -42,6 +46,11 @@ public function __construct(ScannerInterface $scanner)
$this->scanner = $scanner;
}

private function getSnippetExcludeList()
{
return static::$snippetExcludeList;
}

/**
* Creates a list of all snippets which should be covered.
*
Expand All @@ -50,7 +59,7 @@ public function __construct(ScannerInterface $scanner)
public function buildListToCover()
{
$files = $this->scanner->files();
$classes = $this->scanner->classes($files);
$classes = $this->scanner->classes($files, $this->getSnippetExcludeList());

$this->snippets = $this->scanner->snippets($classes);

Expand Down
16 changes: 14 additions & 2 deletions dev/src/Snippet/Coverage/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,32 @@ public function files()
return $files;
}

private function checkExclude($className, array $exclude)
{
foreach ($exclude as $pattern) {
if (preg_match($pattern, $className)) {
return true;
}
}
return false;
}

/**
* {@inheritDoc}
*/
public function classes(array $files)
public function classes(array $files, array $exclude = [])
{
$classes = [];
foreach ($files as $file) {
$f = new FileReflector($file);
$f->process();
foreach ($f->getClasses() as $class) {
if ($this->checkExclude($class->getName(), $exclude)) {
continue;
}
$classes[] = $class->getName();
}
}

return $classes;
}

Expand Down
106 changes: 29 additions & 77 deletions docs/external-classes.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,96 +3,48 @@
"uri": "https://github.com/google/google-auth-library-php/blob/master/src/%s.php"
}, {
"name": "Google\\GAX\\",
"uri": "https://github.com/googleapis/gax-php/tree/master/src/%s.php"
"uri": "https://googleapis.github.io/gax-php/#Google/GAX/%s.html"
}, {
"name": "google\\iam\\v1\\",
"uri": "https://github.com/googleapis/proto-client-php/blob/master/src/iam/v1"
"name": "Google\\Api\\",
"uri": "https://googleapis.github.io/gax-php/#Google/Api/%s.html"
}, {
"name": "google\\devtools\\clouderrorreporting\\v1beta1\\",
"uri": "https://github.com/googleapis/proto-client-php/tree/master/src/errorreporting/v1beta1"
"name": "Google\\Cloud\\Audit\\",
"uri": "https://googleapis.github.io/gax-php/#Google/Cloud/Audit/%s.html"
}, {
"name": "google\\cloud\\language\\v1\\",
"uri": "https://github.com/googleapis/proto-client-php/tree/master/src/language/v1"
"name": "Google\\Iam\\V1\\",
"uri": "https://googleapis.github.io/gax-php/#Google/Iam/V1/%s.html"
}, {
"name": "google\\cloud\\language\\v1beta2\\",
"uri": "https://github.com/googleapis/proto-client-php/tree/master/src/language/v1beta2"
"name": "Google\\Logging\\Type\\",
"uri": "https://googleapis.github.io/gax-php/#Google/Logging/Type/%s.html"
}, {
"name": "google\\logging\\v2\\",
"uri": "https://github.com/googleapis/proto-client-php/tree/master/src/logging/v2"
"name": "Google\\Longrunning\\",
"uri": "https://googleapis.github.io/gax-php/#Google/Longrunning/%s.html"
}, {
"name": "google\\monitoring\\v3\\",
"uri": "https://github.com/googleapis/proto-client-php/tree/master/src/monitoring/v3"
"name": "Google\\Protobuf\\",
"uri": "https://googleapis.github.io/gax-php/#Google/Protobuf/%s.html"
}, {
"name": "google\\pubsub\\v1\\",
"uri": "https://github.com/googleapis/proto-client-php/blob/master/src/pubsub/v1/pubsub.php"
"name": "Google\\Rpc\\",
"uri": "https://googleapis.github.io/gax-php/#Google/Rpc/%s.html"
}, {
"name": "google\\spanner\\admin\\database\\v1\\",
"name": "https://github.com/googleapis/proto-client-php/blob/master/src/spanner/admin/database/v1/spanner_database_admin.php"
"name": "Google\\Type\\",
"uri": "https://googleapis.github.io/gax-php/#Google/Type/%s.html"
}, {
"name": "google\\spanner\\admin\\instance\\v1\\",
"uri": "https://github.com/googleapis/proto-client-php/blob/master/src/spanner/admin/instance/v1/spanner_instance_admin.php"
"name": "Google\\Cloud\\",
"uri": "https://googleapis.github.io/gax-php/#Google/Cloud/%s.html"
}, {
"name": "google\\spanner\\v1\\",
"uri": "https://github.com/googleapis/proto-client-php/blob/master/src/spanner/v1"
"name": "Google\\Devtools\\",
"uri": "https://googleapis.github.io/gax-php/#Google/Devtools/%s.html"
}, {
"name": "google\\cloud\\speech\\v1beta1\\",
"uri": "https://github.com/googleapis/proto-client-php/blob/master/src/speech/v1beta1/cloud_speech.php"
"name": "Google\\Logging\\V2\\",
"uri": "https://googleapis.github.io/gax-php/#Google/Logging/V2/%s.html"
}, {
"name": "google\\cloud\\speech\\v1\\",
"uri": "https://github.com/googleapis/proto-client-php/blob/master/src/speech/v1/cloud_speech.php"
"name": "Google\\Monitoring\\",
"uri": "https://googleapis.github.io/gax-php/#Google/Monitoring/%s.html"
}, {
"name": "google\\devtools\\cloudtrace\\v1\\",
"uri": "https://github.com/googleapis/proto-client-php/blob/master/src/trace/v1/trace.php"
"name": "Google\\Pubsub\\",
"uri": "https://googleapis.github.io/gax-php/#Google/Pubsub/%s.html"
}, {
"name": "google\\cloud\\vision\\v1\\",
"uri": "https://github.com/googleapis/proto-client-php/tree/master/src/vision/v1"
}, {
"name": "google\\longrunning\\",
"uri": "https://github.com/googleapis/gax-php/blob/master/src/generated/operations.php"
}, {
"name": "MonitoredResource",
"uri": "https://github.com/googleapis/gax-php/blob/master/src/generated/monitored_resource.php"
}, {
"name": "ServiceContextFilter",
"uri": "https://github.com/googleapis/proto-client-php/blob/master/src/errorreporting/v1beta1/error_stats_service.php#L1985"
}, {
"name": "QueryTimeRange",
"uri": "https://github.com/googleapis/proto-client-php/blob/master/src/errorreporting/v1beta1/error_stats_service.php#L1915"
}, {
"name": "Duration",
"uri": "https://github.com/googleapis/gax-php/blob/master/src/generated/well-known-types/duration.php"
}, {
"name": "TimedCountAlignment",
"uri": "https://github.com/googleapis/proto-client-php/blob/master/src/errorreporting/v1beta1/error_stats_service.php#L8"
}, {
"name": "Timestamp",
"uri": "https://github.com/googleapis/gax-php/blob/master/src/generated/well-known-types/timestamp.php"
}, {
"name": "ErrorGroupOrder",
"uri": "https://github.com/googleapis/proto-client-php/blob/master/src/errorreporting/v1beta1/error_stats_service.php#L16"
}, {
"name": "TimeInterval",
"uri": "https://github.com/googleapis/proto-client-php/blob/master/src/monitoring/v3/common.php#L270"
}, {
"name": "google\\api\\MetricDescriptor",
"uri": "https://github.com/googleapis/gax-php/blob/master/src/generated/metric.php#L29"
}, {
"name": "google\\api\\MonitoredResourceDescriptor",
"uri": "https://github.com/googleapis/gax-php/blob/master/src/generated/monitored_resource.php#L8"
}, {
"name": "Aggregation",
"uri": "https://github.com/googleapis/proto-client-php/blob/master/src/monitoring/v3/common.php#L429"
}, {
"name": "PushConfig",
"uri": "https://github.com/googleapis/proto-client-php/blob/master/src/pubsub/v1/pubsub.php#L1827"
}, {
"name": "google\\cloud\\videointelligence\\v1beta1\\Feature",
"uri": "https://github.com/googleapis/proto-client-php/blob/master/src/videointelligence/v1beta1/video_intelligence.php#8"
}, {
"name": "google\\cloud\\videointelligence\\v1beta1\\VideoContext",
"uri": "https://github.com/googleapis/proto-client-php/blob/master/src/videointelligence/v1beta1/video_intelligence.php#L379"
}, {
"name": "google\\cloud\\videointelligence\\v1beta1\\",
"uri": "https://github.com/googleapis/proto-client-php/tree/master/src/videointelligence/v1beta1/video_intelligence.php"
"name": "Google\\Spanner\\",
"uri": "https://googleapis.github.io/gax-php/#Google/Spanner/%s.html"
}]

2 changes: 1 addition & 1 deletion src/Core/ClientTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private function getConnectionType(array $config)
'from the command line: ' .
'pecl install grpc && ' .
'composer require google/gax && ' .
'composer require google/proto-client-php'
'composer require google/proto-client'
);
}
}
Expand Down
42 changes: 16 additions & 26 deletions src/Core/GrpcRequestWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@

namespace Google\Cloud\Core;

use DrSlump\Protobuf\Codec\Binary;
use DrSlump\Protobuf\Codec\CodecInterface;
use DrSlump\Protobuf\Message;
use Google\Auth\FetchAuthTokenInterface;
use Google\Auth\HttpHandler\HttpHandlerFactory;
use Google\Cloud\Core\Exception;
use Google\Cloud\Core\PhpArray;
use Google\Cloud\Core\RequestWrapperTrait;
use Google\GAX\ApiException;
use Google\GAX\OperationResponse;
use Google\GAX\PagedListResponse;
use Google\GAX\RetrySettings;
use Google\GAX\Serializer;
use Google\GAX\ServerStream;
use Google\Protobuf\Internal\Message;
use Google\Rpc\BadRequest;
use Google\Rpc\RetryInfo;
use Grpc;

/**
Expand All @@ -46,14 +44,9 @@ class GrpcRequestWrapper
private $authHttpHandler;

/**
* @var CodecInterface A codec used to encode responses.
* @var Serializer A serializer used to encode responses.
*/
private $codec;

/**
* @var CodecInterface A codec used for binary deserialization.
*/
private $binaryCodec;
private $serializer;

/**
* @var array gRPC specific configuration options passed off to the GAX
Expand All @@ -75,8 +68,8 @@ class GrpcRequestWrapper
* @var array Map of error metadata types to RPC wrappers.
*/
private $metadataTypes = [
'google.rpc.retryinfo-bin' => \google\rpc\RetryInfo::class,
'google.rpc.badrequest-bin' => \google\rpc\BadRequest::class
'google.rpc.retryinfo-bin' => RetryInfo::class,
'google.rpc.badrequest-bin' => BadRequest::class
];

/**
Expand All @@ -87,7 +80,7 @@ class GrpcRequestWrapper
*
* @type callable $authHttpHandler A handler used to deliver Psr7
* requests specifically for authentication.
* @type CodecInterface $codec A codec used to encode responses.
* @type Serializer $serializer A serializer used to encode responses.
* @type array $grpcOptions gRPC specific configuration options passed
* off to the GAX library.
* }
Expand All @@ -97,14 +90,13 @@ public function __construct(array $config = [])
$this->setCommonDefaults($config);
$config += [
'authHttpHandler' => null,
'codec' => new PhpArray(),
'serializer' => new Serializer(),
'grpcOptions' => []
];

$this->authHttpHandler = $config['authHttpHandler'] ?: HttpHandlerFactory::build();
$this->codec = $config['codec'];
$this->serializer = $config['serializer'];
$this->grpcOptions = $config['grpcOptions'];
$this->binaryCodec = new Binary;
}

/**
Expand Down Expand Up @@ -169,8 +161,7 @@ private function handleResponse($response)
}

if ($response instanceof Message) {
$res = $response->serialize($this->codec);
return $res;
return $this->serializer->encodeMessage($response);
}

if ($response instanceof OperationResponse) {
Expand All @@ -194,7 +185,7 @@ private function handleStream(ServerStream $response)
{
try {
foreach ($response->readAll() as $count => $result) {
$res = $result->serialize($this->codec);
$res = $this->serializer->encodeMessage($result);
yield $res;
}
} catch (\Exception $ex) {
Expand Down Expand Up @@ -251,10 +242,9 @@ private function convertToGoogleException(ApiException $ex)
if (!isset($this->metadataTypes[$type])) {
continue;
}

$metadata[] = (new $this->metadataTypes[$type])
->deserialize($binaryValue[0], $this->binaryCodec)
->serialize($this->codec);
$metadataElement = new $this->metadataTypes[$type];
$metadataElement->mergeFromString($binaryValue[0]);
$metadata[] = $this->serializer->encodeMessage($metadataElement);
}
}

Expand Down
Loading