From f4c523511532e84870a763f7f99c461609e1295f Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Fri, 15 Sep 2017 12:00:57 -0700 Subject: [PATCH 01/17] Spanner updates --- src/Spanner/Database.php | 16 ++++++++----- src/Spanner/Instance.php | 7 +++--- src/Spanner/InstanceConfiguration.php | 2 +- src/Spanner/Session/Session.php | 2 +- src/Spanner/SpannerClient.php | 18 ++++++++------ tests/snippets/Spanner/DatabaseTest.php | 8 +++---- .../Spanner/InstanceConfigurationTest.php | 10 ++++---- tests/snippets/Spanner/InstanceTest.php | 10 ++++---- tests/snippets/Spanner/SpannerClientTest.php | 10 ++++---- tests/system/Spanner/AdminTest.php | 4 ++-- tests/unit/Spanner/DatabaseTest.php | 18 +++++++------- .../Spanner/InstanceConfigurationTest.php | 6 ++--- tests/unit/Spanner/InstanceTest.php | 24 +++++++++---------- tests/unit/Spanner/SpannerClientTest.php | 22 ++++++++--------- tests/unit/Spanner/TransactionTypeTest.php | 6 ++--- 15 files changed, 86 insertions(+), 77 deletions(-) diff --git a/src/Spanner/Database.php b/src/Spanner/Database.php index 27fb931b3d78..fd0b4ff6fff3 100644 --- a/src/Spanner/Database.php +++ b/src/Spanner/Database.php @@ -309,7 +309,9 @@ public function create(array $options = []) 'statements' => [], ]; - $statement = sprintf('CREATE DATABASE `%s`', DatabaseAdminClient::parseDatabaseFromDatabaseName($this->name)); + $databaseNameComponents = DatabaseAdminClient::parseName($this->name()); + $databaseName = $databaseNameComponents['database']; + $statement = sprintf('CREATE DATABASE `%s`', $databaseName); $operation = $this->connection->createDatabase([ 'instance' => $this->instance->name(), @@ -1430,12 +1432,13 @@ public function createSession(array $options = []) */ public function session($name) { + $sessionNameComponents = GapicSpannerClient::parseName($name); return new Session( $this->connection, $this->projectId, - GapicSpannerClient::parseInstanceFromSessionName($name), - GapicSpannerClient::parseDatabaseFromSessionName($name), - GapicSpannerClient::parseSessionFromSessionName($name) + $sessionNameComponents['instance'], + $sessionNameComponents['database'], + $sessionNameComponents['session'] ); } @@ -1526,10 +1529,11 @@ private function commitInSingleUseTransaction(array $mutations, array $options = */ private function fullyQualifiedDatabaseName($name) { - $instance = InstanceAdminClient::parseInstanceFromInstanceName($this->instance->name()); + $instanceNameComponents = InstanceAdminClient::parseName($this->instance->name()); + $instance = $instanceNameComponents['instance']; try { - return GapicSpannerClient::formatDatabaseName( + return GapicSpannerClient::databaseName( $this->projectId, $instance, $name diff --git a/src/Spanner/Instance.php b/src/Spanner/Instance.php index 2fd7187f2759..3b0293d7d93d 100644 --- a/src/Spanner/Instance.php +++ b/src/Spanner/Instance.php @@ -268,7 +268,8 @@ public function reload(array $options = []) */ public function create(InstanceConfiguration $config, array $options = []) { - $instanceId = InstanceAdminClient::parseInstanceFromInstanceName($this->name); + $instanceNameComponents = InstanceAdminClient::parseName($this->name); + $instanceId = $instanceNameComponents['instance']; $options += [ 'displayName' => $instanceId, 'nodeCount' => self::DEFAULT_NODE_COUNT, @@ -281,7 +282,7 @@ public function create(InstanceConfiguration $config, array $options = []) $operation = $this->connection->createInstance([ 'instanceId' => $instanceId, 'name' => $this->name, - 'projectId' => InstanceAdminClient::formatProjectName($this->projectId), + 'projectId' => InstanceAdminClient::projectName($this->projectId), 'config' => $config->name() ] + $options); @@ -508,7 +509,7 @@ public function iam() private function fullyQualifiedInstanceName($name, $project) { // try { - return InstanceAdminClient::formatInstanceName( + return InstanceAdminClient::instanceName( $project, $name ); diff --git a/src/Spanner/InstanceConfiguration.php b/src/Spanner/InstanceConfiguration.php index ffa08fb62363..59ba5ba53d1d 100644 --- a/src/Spanner/InstanceConfiguration.php +++ b/src/Spanner/InstanceConfiguration.php @@ -202,7 +202,7 @@ public function __debugInfo() private function fullyQualifiedConfigName($name, $projectId) { try { - return InstanceAdminClient::formatInstanceConfigName( + return InstanceAdminClient::instanceConfigName( $projectId, $name ); diff --git a/src/Spanner/Session/Session.php b/src/Spanner/Session/Session.php index b0c8218b4d7b..9ec566b5eab2 100644 --- a/src/Spanner/Session/Session.php +++ b/src/Spanner/Session/Session.php @@ -133,7 +133,7 @@ public function delete(array $options = []) */ public function name() { - return SpannerClient::formatSessionName( + return SpannerClient::sessionName( $this->projectId, $this->instance, $this->database, diff --git a/src/Spanner/SpannerClient.php b/src/Spanner/SpannerClient.php index 68af4c122dfd..eb61c0bcb27c 100644 --- a/src/Spanner/SpannerClient.php +++ b/src/Spanner/SpannerClient.php @@ -127,14 +127,16 @@ public function __construct(array $config = []) [ 'typeUrl' => 'type.googleapis.com/google.spanner.admin.instance.v1.UpdateInstanceMetadata', 'callable' => function ($instance) { - $name = InstanceAdminClient::parseInstanceFromInstanceName($instance['name']); + $instanceNameComponents = InstanceAdminClient::parseName($instance['name']); + $name = $instanceNameComponents['instance']; return $this->instance($name, $instance); } ], [ 'typeUrl' => 'type.googleapis.com/google.spanner.admin.database.v1.CreateDatabaseMetadata', 'callable' => function ($database) { - $instanceName = DatabaseAdminClient::parseInstanceFromDatabaseName($database['name']); - $databaseName = DatabaseAdminClient::parseDatabaseFromDatabaseName($database['name']); + $databaseNameComponents = InstanceAdminClient::parseName($database['name']); + $instanceName = $databaseNameComponents['instance']; + $databaseName = $databaseNameComponents['database']; $instance = $this->instance($instanceName); return $instance->database($databaseName); @@ -142,7 +144,8 @@ public function __construct(array $config = []) ], [ 'typeUrl' => 'type.googleapis.com/google.spanner.admin.instance.v1.CreateInstanceMetadata', 'callable' => function ($instance) { - $name = InstanceAdminClient::parseInstanceFromInstanceName($instance['name']); + $instanceNameComponents = InstanceAdminClient::parseName($instance['name']); + $name = $instanceNameComponents['instance']; return $this->instance($name, $instance); } ] @@ -183,7 +186,7 @@ function (array $config) { return $this->instanceConfiguration($config['name'], $config); }, [$this->connection, 'listInstanceConfigs'], - ['projectId' => InstanceAdminClient::formatProjectName($this->projectId)] + $options, + ['projectId' => InstanceAdminClient::projectName($this->projectId)] + $options, [ 'itemsKey' => 'instanceConfigs', 'resultLimit' => $resultLimit @@ -309,11 +312,12 @@ public function instances(array $options = []) return new ItemIterator( new PageIterator( function (array $instance) { - $name = InstanceAdminClient::parseInstanceFromInstanceName($instance['name']); + $instanceNameComponents = InstanceAdminClient::parseName($instance['name']); + $name = $instanceNameComponents['instance']; return $this->instance($name, $instance); }, [$this->connection, 'listInstances'], - ['projectId' => InstanceAdminClient::formatProjectName($this->projectId)] + $options, + ['projectId' => InstanceAdminClient::projectName($this->projectId)] + $options, [ 'itemsKey' => 'instances', 'resultLimit' => $resultLimit diff --git a/tests/snippets/Spanner/DatabaseTest.php b/tests/snippets/Spanner/DatabaseTest.php index dfb0c98b643f..1e173dfe9afc 100644 --- a/tests/snippets/Spanner/DatabaseTest.php +++ b/tests/snippets/Spanner/DatabaseTest.php @@ -59,7 +59,7 @@ public function setUp() $this->checkAndSkipGrpcTests(); $instance = $this->prophesize(Instance::class); - $instance->name()->willReturn(InstanceAdminClient::formatInstanceName(self::PROJECT, self::INSTANCE)); + $instance->name()->willReturn(InstanceAdminClient::instanceName(self::PROJECT, self::INSTANCE)); $session = $this->prophesize(Session::class); @@ -95,7 +95,7 @@ public function testClass() $snippet = $this->snippetFromClass(Database::class); $res = $snippet->invoke('database'); $this->assertInstanceOf(Database::class, $res->returnVal()); - $this->assertEquals(self::DATABASE, DatabaseAdminClient::parseDatabaseFromDatabaseName($res->returnVal()->name())); + $this->assertEquals(self::DATABASE, DatabaseAdminClient::parseName($res->returnVal()->name())['database']); } public function testClassViaInstance() @@ -107,7 +107,7 @@ public function testClassViaInstance() $snippet = $this->snippetFromClass(Database::class, 1); $res = $snippet->invoke('database'); $this->assertInstanceOf(Database::class, $res->returnVal()); - $this->assertEquals(self::DATABASE, DatabaseAdminClient::parseDatabaseFromDatabaseName($res->returnVal()->name())); + $this->assertEquals(self::DATABASE, DatabaseAdminClient::parseName($res->returnVal()->name())['database']); } public function testName() @@ -115,7 +115,7 @@ public function testName() $snippet = $this->snippetFromMethod(Database::class, 'name'); $snippet->addLocal('database', $this->database); $res = $snippet->invoke('name'); - $this->assertEquals(self::DATABASE, DatabaseAdminClient::parseDatabaseFromDatabaseName($res->returnVal())); + $this->assertEquals(self::DATABASE, DatabaseAdminClient::parseName($res->returnVal()->name())['database']); } /** diff --git a/tests/snippets/Spanner/InstanceConfigurationTest.php b/tests/snippets/Spanner/InstanceConfigurationTest.php index a11c9c35e7a2..fb32afff0131 100644 --- a/tests/snippets/Spanner/InstanceConfigurationTest.php +++ b/tests/snippets/Spanner/InstanceConfigurationTest.php @@ -56,7 +56,7 @@ public function testClass() $res = $snippet->invoke('configuration'); $this->assertInstanceOf(InstanceConfiguration::class, $res->returnVal()); - $this->assertEquals(InstanceAdminClient::formatInstanceConfigName(self::PROJECT, self::CONFIG), $res->returnVal()->name()); + $this->assertEquals(InstanceAdminClient::instanceConfigName(self::PROJECT, self::CONFIG), $res->returnVal()->name()); } public function testName() @@ -65,7 +65,7 @@ public function testName() $snippet->addLocal('configuration', $this->config); $res = $snippet->invoke('name'); - $this->assertEquals(InstanceAdminClient::formatInstanceConfigName(self::PROJECT, self::CONFIG), $res->returnVal()); + $this->assertEquals(InstanceAdminClient::instanceConfigName(self::PROJECT, self::CONFIG), $res->returnVal()); } public function testInfo() @@ -74,7 +74,7 @@ public function testInfo() $snippet->addLocal('configuration', $this->config); $info = [ - 'name' => InstanceAdminClient::formatInstanceConfigName(self::PROJECT, self::CONFIG), + 'name' => InstanceAdminClient::instanceConfigName(self::PROJECT, self::CONFIG), 'displayName' => self::CONFIG ]; @@ -96,7 +96,7 @@ public function testExists() $this->connection->getInstanceConfig(Argument::any()) ->shouldBeCalled() ->willReturn([ - 'name' => InstanceAdminClient::formatInstanceConfigName(self::PROJECT, self::CONFIG), + 'name' => InstanceAdminClient::instanceConfigName(self::PROJECT, self::CONFIG), 'displayName' => self::CONFIG ]); @@ -109,7 +109,7 @@ public function testExists() public function testReload() { $info = [ - 'name' => InstanceAdminClient::formatInstanceConfigName(self::PROJECT, self::CONFIG), + 'name' => InstanceAdminClient::instanceConfigName(self::PROJECT, self::CONFIG), 'displayName' => self::CONFIG ]; diff --git a/tests/snippets/Spanner/InstanceTest.php b/tests/snippets/Spanner/InstanceTest.php index 76717b19a253..06c6fe9b74e8 100644 --- a/tests/snippets/Spanner/InstanceTest.php +++ b/tests/snippets/Spanner/InstanceTest.php @@ -65,7 +65,7 @@ public function testClass() $snippet = $this->snippetFromClass(Instance::class); $res = $snippet->invoke('instance'); $this->assertInstanceOf(Instance::class, $res->returnVal()); - $this->assertEquals(InstanceAdminClient::formatInstanceName(self::PROJECT, self::INSTANCE), $res->returnVal()->name()); + $this->assertEquals(InstanceAdminClient::instanceName(self::PROJECT, self::INSTANCE), $res->returnVal()->name()); } /** @@ -74,7 +74,7 @@ public function testClass() public function testCreate() { $config = $this->prophesize(InstanceConfiguration::class); - $config->name()->willReturn(InstanceAdminClient::formatInstanceConfigName(self::PROJECT, 'foo')); + $config->name()->willReturn(InstanceAdminClient::instanceConfigName(self::PROJECT, 'foo')); $snippet = $this->snippetFromMethod(Instance::class, 'create'); $snippet->addLocal('configuration', $config->reveal()); @@ -96,7 +96,7 @@ public function testName() $snippet->addLocal('instance', $this->instance); $res = $snippet->invoke('name'); - $this->assertEquals(InstanceAdminClient::formatInstanceName(self::PROJECT, self::INSTANCE), $res->returnVal()); + $this->assertEquals(InstanceAdminClient::instanceName(self::PROJECT, self::INSTANCE), $res->returnVal()); } public function testInfo() @@ -212,7 +212,7 @@ public function testDatabase() $res = $snippet->invoke('database'); $this->assertInstanceOf(Database::class, $res->returnVal()); - $this->assertEquals(self::DATABASE, DatabaseAdminClient::parseDatabaseFromDatabaseName($res->returnVal()->name())); + $this->assertEquals(self::DATABASE, DatabaseAdminClient::parseName($res->returnVal()->name())['database']); } public function testDatabases() @@ -225,7 +225,7 @@ public function testDatabases() ->willReturn([ 'databases' => [ [ - 'name' => DatabaseAdminClient::formatDatabaseName(self::PROJECT, self::INSTANCE, self::DATABASE) + 'name' => DatabaseAdminClient::databaseName(self::PROJECT, self::INSTANCE, self::DATABASE) ] ] ]); diff --git a/tests/snippets/Spanner/SpannerClientTest.php b/tests/snippets/Spanner/SpannerClientTest.php index 44af7775e945..aace5adfb41b 100644 --- a/tests/snippets/Spanner/SpannerClientTest.php +++ b/tests/snippets/Spanner/SpannerClientTest.php @@ -105,7 +105,7 @@ public function testInstanceConfiguration() $res = $snippet->invoke('configuration'); $this->assertInstanceOf(InstanceConfiguration::class, $res->returnVal()); - $this->assertEquals(InstanceAdminClient::formatInstanceConfigName(self::PROJECT, $configName), $res->returnVal()->name()); + $this->assertEquals(InstanceAdminClient::instanceConfigName(self::PROJECT, $configName), $res->returnVal()->name()); } /** @@ -137,7 +137,7 @@ public function testInstance() $res = $snippet->invoke('instance'); $this->assertInstanceOf(Instance::class, $res->returnVal()); - $this->assertEquals(InstanceAdminClient::formatInstanceName(self::PROJECT, self::INSTANCE), $res->returnVal()->name()); + $this->assertEquals(InstanceAdminClient::instanceName(self::PROJECT, self::INSTANCE), $res->returnVal()->name()); } /** @@ -152,8 +152,8 @@ public function testInstances() ->shouldBeCalled() ->willReturn([ 'instances' => [ - ['name' => InstanceAdminClient::formatInstanceName(self::PROJECT, self::INSTANCE)], - ['name' => InstanceAdminClient::formatInstanceName(self::PROJECT, 'bar')] + ['name' => InstanceAdminClient::instanceName(self::PROJECT, self::INSTANCE)], + ['name' => InstanceAdminClient::instanceName(self::PROJECT, 'bar')] ] ]); @@ -162,7 +162,7 @@ public function testInstances() $res = $snippet->invoke('instances'); $this->assertInstanceOf(ItemIterator::class, $res->returnVal()); $this->assertInstanceOf(Instance::class, $res->returnVal()->current()); - $this->assertEquals(InstanceAdminClient::formatInstanceName(self::PROJECT, self::INSTANCE), $res->returnVal()->current()->name()); + $this->assertEquals(InstanceAdminClient::instanceName(self::PROJECT, self::INSTANCE), $res->returnVal()->current()->name()); } public function testConnect() diff --git a/tests/system/Spanner/AdminTest.php b/tests/system/Spanner/AdminTest.php index 8a5f8e473e75..c699721c12b4 100644 --- a/tests/system/Spanner/AdminTest.php +++ b/tests/system/Spanner/AdminTest.php @@ -125,11 +125,11 @@ public function testConfigurations() private function parseName($name) { - return InstanceAdminClient::parseInstanceFromInstanceName($name); + return InstanceAdminClient::parseName($name)['instance']; } private function parseDbName($name) { - return DatabaseAdminClient::parseDatabaseFromDatabaseName($name); + return DatabaseAdminClient::parseName($name)['database']; } } diff --git a/tests/unit/Spanner/DatabaseTest.php b/tests/unit/Spanner/DatabaseTest.php index 9b479a088daa..4c4944a0aaa6 100644 --- a/tests/unit/Spanner/DatabaseTest.php +++ b/tests/unit/Spanner/DatabaseTest.php @@ -82,7 +82,7 @@ public function setUp() $this->sessionPool->release(Argument::type(Session::class)) ->willReturn(null); - $this->instance->name()->willReturn(InstanceAdminClient::formatInstanceName(self::PROJECT, self::INSTANCE)); + $this->instance->name()->willReturn(InstanceAdminClient::instanceName(self::PROJECT, self::INSTANCE)); $args = [ $this->connection->reveal(), @@ -103,7 +103,7 @@ public function setUp() public function testName() { - $this->assertEquals($this->database->name(), DatabaseAdminClient::formatDatabaseName(self::PROJECT, self::INSTANCE, self::DATABASE)); + $this->assertEquals($this->database->name(), DatabaseAdminClient::databaseName(self::PROJECT, self::INSTANCE, self::DATABASE)); } public function testInfo() @@ -148,7 +148,7 @@ public function testReload() public function testExists() { $this->connection->getDatabase(Argument::withEntry( - 'name', DatabaseAdminClient::formatDatabaseName(self::PROJECT, self::INSTANCE, self::DATABASE) + 'name', DatabaseAdminClient::databaseName(self::PROJECT, self::INSTANCE, self::DATABASE) )) ->shouldBeCalled() ->willReturn([]); @@ -179,7 +179,7 @@ public function testUpdateDdl() { $statement = 'foo'; $this->connection->updateDatabaseDdl([ - 'name' => DatabaseAdminClient::formatDatabaseName(self::PROJECT, self::INSTANCE, self::DATABASE), + 'name' => DatabaseAdminClient::databaseName(self::PROJECT, self::INSTANCE, self::DATABASE), 'statements' => [$statement] ])->willReturn([ 'name' => 'my-operation' @@ -197,7 +197,7 @@ public function testUpdateDdlBatch() { $statements = ['foo', 'bar']; $this->connection->updateDatabaseDdl([ - 'name' => DatabaseAdminClient::formatDatabaseName(self::PROJECT, self::INSTANCE, self::DATABASE), + 'name' => DatabaseAdminClient::databaseName(self::PROJECT, self::INSTANCE, self::DATABASE), 'statements' => $statements ])->willReturn([ 'name' => 'my-operation' @@ -215,7 +215,7 @@ public function testUpdateWithSingleStatement() { $statement = 'foo'; $this->connection->updateDatabaseDdl([ - 'name' => DatabaseAdminClient::formatDatabaseName(self::PROJECT, self::INSTANCE, self::DATABASE), + 'name' => DatabaseAdminClient::databaseName(self::PROJECT, self::INSTANCE, self::DATABASE), 'statements' => ['foo'] ])->shouldBeCalled()->willReturn(['name' => 'operations/foo']); @@ -231,7 +231,7 @@ public function testUpdateWithSingleStatement() public function testDrop() { $this->connection->dropDatabase([ - 'name' => DatabaseAdminClient::formatDatabaseName(self::PROJECT, self::INSTANCE, self::DATABASE) + 'name' => DatabaseAdminClient::databaseName(self::PROJECT, self::INSTANCE, self::DATABASE) ])->shouldBeCalled(); $this->database->___setProperty('connection', $this->connection->reveal()); @@ -246,7 +246,7 @@ public function testDdl() { $ddl = ['create table users', 'create table posts']; $this->connection->getDatabaseDDL([ - 'name' => DatabaseAdminClient::formatDatabaseName(self::PROJECT, self::INSTANCE, self::DATABASE) + 'name' => DatabaseAdminClient::databaseName(self::PROJECT, self::INSTANCE, self::DATABASE) ])->willReturn(['statements' => $ddl]); $this->database->___setProperty('connection', $this->connection->reveal()); @@ -260,7 +260,7 @@ public function testDdl() public function testDdlNoResult() { $this->connection->getDatabaseDDL([ - 'name' => DatabaseAdminClient::formatDatabaseName(self::PROJECT, self::INSTANCE, self::DATABASE) + 'name' => DatabaseAdminClient::databaseName(self::PROJECT, self::INSTANCE, self::DATABASE) ])->willReturn([]); $this->database->___setProperty('connection', $this->connection->reveal()); diff --git a/tests/unit/Spanner/InstanceConfigurationTest.php b/tests/unit/Spanner/InstanceConfigurationTest.php index e654d9687439..87a6fabaedbb 100644 --- a/tests/unit/Spanner/InstanceConfigurationTest.php +++ b/tests/unit/Spanner/InstanceConfigurationTest.php @@ -52,7 +52,7 @@ public function setUp() public function testName() { - $this->assertEquals(self::NAME, InstanceAdminClient::parseInstanceConfigFromInstanceConfigName($this->configuration->name())); + $this->assertEquals(self::NAME, InstanceAdminClient::parseName($this->configuration->name())['instance_config']); } public function testInfo() @@ -76,7 +76,7 @@ public function testInfoWithReload() $info = ['foo' => 'bar']; $this->connection->getInstanceConfig([ - 'name' => InstanceAdminClient::formatInstanceConfigName(self::PROJECT_ID, self::NAME), + 'name' => InstanceAdminClient::instanceConfigName(self::PROJECT_ID, self::NAME), 'projectId' => self::PROJECT_ID ])->shouldBeCalled()->willReturn($info); @@ -106,7 +106,7 @@ public function testReload() $info = ['foo' => 'bar']; $this->connection->getInstanceConfig([ - 'name' => InstanceAdminClient::formatInstanceConfigName(self::PROJECT_ID, self::NAME), + 'name' => InstanceAdminClient::instanceConfigName(self::PROJECT_ID, self::NAME), 'projectId' => self::PROJECT_ID ])->shouldBeCalledTimes(1)->willReturn($info); diff --git a/tests/unit/Spanner/InstanceTest.php b/tests/unit/Spanner/InstanceTest.php index e313e4dbc95b..34d2c9b52e6e 100644 --- a/tests/unit/Spanner/InstanceTest.php +++ b/tests/unit/Spanner/InstanceTest.php @@ -65,7 +65,7 @@ public function setUp() public function testName() { - $this->assertEquals(self::NAME, InstanceAdminClient::parseInstanceFromInstanceName($this->instance->name())); + $this->assertEquals(self::NAME, InstanceAdminClient::parseName($this->instance->name())['instance']); } public function testInfo() @@ -213,7 +213,7 @@ public function testUpdateWithChanges() public function testDelete() { $this->connection->deleteInstance([ - 'name' => InstanceAdminClient::formatInstanceName(self::PROJECT_ID, self::NAME) + 'name' => InstanceAdminClient::instanceName(self::PROJECT_ID, self::NAME) ])->shouldBeCalled(); $this->instance->___setProperty('connection', $this->connection->reveal()); @@ -226,7 +226,7 @@ public function testCreateDatabase() $extra = ['foo', 'bar']; $this->connection->createDatabase([ - 'instance' => InstanceAdminClient::formatInstanceName(self::PROJECT_ID, self::NAME), + 'instance' => InstanceAdminClient::instanceName(self::PROJECT_ID, self::NAME), 'createStatement' => 'CREATE DATABASE `test-database`', 'extraStatements' => $extra ]) @@ -246,14 +246,14 @@ public function testDatabase() { $database = $this->instance->database('test-database'); $this->assertInstanceOf(Database::class, $database); - $this->assertEquals('test-database', DatabaseAdminClient::parseDatabaseFromDatabaseName($database->name())); + $this->assertEquals('test-database', DatabaseAdminClient::parseName($database->name())['database']); } public function testDatabases() { $databases = [ - ['name' => DatabaseAdminClient::formatDatabaseName(self::PROJECT_ID, self::NAME, 'database1')], - ['name' => DatabaseAdminClient::formatDatabaseName(self::PROJECT_ID, self::NAME, 'database2')] + ['name' => DatabaseAdminClient::databaseName(self::PROJECT_ID, self::NAME, 'database1')], + ['name' => DatabaseAdminClient::databaseName(self::PROJECT_ID, self::NAME, 'database2')] ]; $this->connection->listDatabases(Argument::any()) @@ -269,15 +269,15 @@ public function testDatabases() $dbs = iterator_to_array($dbs); $this->assertEquals(2, count($dbs)); - $this->assertEquals('database1', DatabaseAdminClient::parseDatabaseFromDatabaseName($dbs[0]->name())); - $this->assertEquals('database2', DatabaseAdminClient::parseDatabaseFromDatabaseName($dbs[1]->name())); + $this->assertEquals('database1', DatabaseAdminClient::parseName($dbs[0]->name())['database']); + $this->assertEquals('database2', DatabaseAdminClient::parseName($dbs[1]->name())['database']); } public function testDatabasesPaged() { $databases = [ - ['name' => DatabaseAdminClient::formatDatabaseName(self::PROJECT_ID, self::NAME, 'database1')], - ['name' => DatabaseAdminClient::formatDatabaseName(self::PROJECT_ID, self::NAME, 'database2')] + ['name' => DatabaseAdminClient::databaseName(self::PROJECT_ID, self::NAME, 'database1')], + ['name' => DatabaseAdminClient::databaseName(self::PROJECT_ID, self::NAME, 'database2')] ]; $iteration = 0; @@ -294,8 +294,8 @@ public function testDatabasesPaged() $dbs = iterator_to_array($dbs); $this->assertEquals(2, count($dbs)); - $this->assertEquals('database1', DatabaseAdminClient::parseDatabaseFromDatabaseName($dbs[0]->name())); - $this->assertEquals('database2', DatabaseAdminClient::parseDatabaseFromDatabaseName($dbs[1]->name())); + $this->assertEquals('database1', DatabaseAdminClient::parseName($dbs[0]->name())['database']); + $this->assertEquals('database2', DatabaseAdminClient::parseName($dbs[1]->name())['database']); } public function testIam() diff --git a/tests/unit/Spanner/SpannerClientTest.php b/tests/unit/Spanner/SpannerClientTest.php index a58d762443bd..3ed469241990 100644 --- a/tests/unit/Spanner/SpannerClientTest.php +++ b/tests/unit/Spanner/SpannerClientTest.php @@ -70,10 +70,10 @@ public function testInstanceConfigurations() ->willReturn([ 'instanceConfigs' => [ [ - 'name' => InstanceAdminClient::formatInstanceConfigName(self::PROJECT, self::CONFIG), + 'name' => InstanceAdminClient::instanceConfigName(self::PROJECT, self::CONFIG), 'displayName' => 'Bar' ], [ - 'name' => InstanceAdminClient::formatInstanceConfigName(self::PROJECT, self::CONFIG), + 'name' => InstanceAdminClient::instanceConfigName(self::PROJECT, self::CONFIG), 'displayName' => 'Bat' ] ] @@ -139,7 +139,7 @@ public function testInstanceConfiguration() $config = $this->client->instanceConfiguration('bar'); $this->assertInstanceOf(InstanceConfiguration::class, $config); - $this->assertEquals('bar', InstanceAdminClient::parseInstanceConfigFromInstanceConfigName($config->name())); + $this->assertEquals('bar', InstanceAdminClient::parseName($config->name())['instance_config']); } /** @@ -148,8 +148,8 @@ public function testInstanceConfiguration() public function testCreateInstance() { $this->connection->createInstance(Argument::that(function ($arg) { - if ($arg['name'] !== InstanceAdminClient::formatInstanceName(self::PROJECT, self::INSTANCE)) return false; - if ($arg['config'] !== InstanceAdminClient::formatInstanceConfigName(self::PROJECT, self::CONFIG)) return false; + if ($arg['name'] !== InstanceAdminClient::instanceName(self::PROJECT, self::INSTANCE)) return false; + if ($arg['config'] !== InstanceAdminClient::instanceConfigName(self::PROJECT, self::CONFIG)) return false; return true; })) @@ -161,7 +161,7 @@ public function testCreateInstance() $this->client->___setProperty('connection', $this->connection->reveal()); $config = $this->prophesize(InstanceConfiguration::class); - $config->name()->willReturn(InstanceAdminClient::formatInstanceConfigName(self::PROJECT, self::CONFIG)); + $config->name()->willReturn(InstanceAdminClient::instanceConfigName(self::PROJECT, self::CONFIG)); $operation = $this->client->createInstance($config->reveal(), self::INSTANCE); @@ -175,7 +175,7 @@ public function testInstance() { $i = $this->client->instance('foo'); $this->assertInstanceOf(Instance::class, $i); - $this->assertEquals('foo', InstanceAdminClient::parseInstanceFromInstanceName($i->name())); + $this->assertEquals('foo', InstanceAdminClient::parseName($i->name())['instance']); } /** @@ -208,8 +208,8 @@ public function testInstances() $instances = iterator_to_array($instances); $this->assertEquals(2, count($instances)); - $this->assertEquals('foo', InstanceAdminClient::parseInstanceFromInstanceName($instances[0]->name())); - $this->assertEquals('bar', InstanceAdminClient::parseInstanceFromInstanceName($instances[1]->name())); + $this->assertEquals('foo', InstanceAdminClient::parseName($instances[0]->name())['instance']); + $this->assertEquals('bar', InstanceAdminClient::parseName($instances[1]->name())['instance']); } /** @@ -228,7 +228,7 @@ public function testConnect() { $database = $this->client->connect(self::INSTANCE, self::DATABASE); $this->assertInstanceOf(Database::class, $database); - $this->assertEquals(self::DATABASE, DatabaseAdminClient::parseDatabaseFromDatabaseName($database->name())); + $this->assertEquals(self::DATABASE, DatabaseAdminClient::parseName($database->name())['database']); } public function testConnectWithInstance() @@ -236,7 +236,7 @@ public function testConnectWithInstance() $inst = $this->client->instance(self::INSTANCE); $database = $this->client->connect($inst, self::DATABASE); $this->assertInstanceOf(Database::class, $database); - $this->assertEquals(self::DATABASE, DatabaseAdminClient::parseDatabaseFromDatabaseName($database->name())); + $this->assertEquals(self::DATABASE, DatabaseAdminClient::parseName($database->name())['database']); } public function testKeyset() diff --git a/tests/unit/Spanner/TransactionTypeTest.php b/tests/unit/Spanner/TransactionTypeTest.php index 5c947c558bfd..b551c938e533 100644 --- a/tests/unit/Spanner/TransactionTypeTest.php +++ b/tests/unit/Spanner/TransactionTypeTest.php @@ -61,7 +61,7 @@ public function setUp() $this->connection = $this->prophesize(ConnectionInterface::class); $this->connection->createSession(Argument::any()) - ->willReturn(['name' => SpannerClient::formatSessionName( + ->willReturn(['name' => SpannerClient::sessionName( self::PROJECT, self::INSTANCE, self::DATABASE, @@ -732,7 +732,7 @@ public function testTransactionPreAllocatedRollback() $this->connection->rollback(Argument::that(function ($arg) { if ($arg['transactionId'] !== self::TRANSACTION) return false; - if ($arg['session'] !== SpannerClient::formatSessionName( + if ($arg['session'] !== SpannerClient::sessionName( self::PROJECT, self::INSTANCE, self::DATABASE, @@ -764,7 +764,7 @@ private function database(ConnectionInterface $connection) { $operation = new Operation($connection, false); $instance = $this->prophesize(Instance::class); - $instance->name()->willReturn(InstanceAdminClient::formatInstanceName(self::PROJECT, self::INSTANCE)); + $instance->name()->willReturn(InstanceAdminClient::instanceName(self::PROJECT, self::INSTANCE)); $database = \Google\Cloud\Dev\stub(Database::class, [ $connection, From 1fee02822a9e4406624981b070fa8946bdd8e555 Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Mon, 18 Sep 2017 15:20:41 -0700 Subject: [PATCH 02/17] Update GAPICs --- .../V2beta1/Gapic/DlpServiceGapicClient.php | 197 +++--- .../Gapic/ErrorGroupServiceGapicClient.php | 148 +++-- .../Gapic/ErrorStatsServiceGapicClient.php | 168 ++--- .../Gapic/ReportErrorsServiceGapicClient.php | 123 ++-- .../Gapic/LanguageServiceGapicClient.php | 111 ++-- .../V2/Gapic/ConfigServiceV2GapicClient.php | 260 ++++---- .../V2/Gapic/LoggingServiceV2GapicClient.php | 254 ++++---- .../V2/Gapic/MetricsServiceV2GapicClient.php | 260 ++++---- .../V3/Gapic/GroupServiceGapicClient.php | 271 ++++---- .../V3/Gapic/MetricServiceGapicClient.php | 365 +++++------ src/PubSub/V1/Gapic/PublisherGapicClient.php | 312 +++++---- src/PubSub/V1/Gapic/SubscriberGapicClient.php | 601 +++++++----------- .../V1/resources/publisher_client_config.json | 5 + .../resources/subscriber_client_config.json | 5 + .../V1/Gapic/DatabaseAdminGapicClient.php | 349 +++++----- .../V1/Gapic/InstanceAdminGapicClient.php | 390 ++++++------ src/Spanner/V1/Gapic/SpannerGapicClient.php | 362 +++++------ src/Spanner/V1/SpannerClient.php | 26 +- src/Speech/V1/Gapic/SpeechGapicClient.php | 75 ++- .../V1beta1/Gapic/SpeechGapicClient.php | 75 ++- .../VideoIntelligenceServiceGapicClient.php | 57 +- .../VideoIntelligenceServiceGapicClient.php | 57 +- .../V1/Gapic/ImageAnnotatorGapicClient.php | 56 +- 23 files changed, 2160 insertions(+), 2367 deletions(-) diff --git a/src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php b/src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php index e3fb6df64c17..6e68ff8fa541 100644 --- a/src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php +++ b/src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php @@ -33,11 +33,11 @@ use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; -use Google\GAX\GrpcConstants; use Google\GAX\GrpcCredentialsHelper; use Google\GAX\LongRunning\OperationsClient; use Google\GAX\OperationResponse; use Google\GAX\PathTemplate; +use Google\GAX\ValidationException; use Google\Privacy\Dlp\V2beta1\ContentItem; use Google\Privacy\Dlp\V2beta1\CreateInspectOperationRequest; use Google\Privacy\Dlp\V2beta1\DlpServiceGrpcClient; @@ -91,8 +91,8 @@ * * Many parameters require resource names to be formatted in a particular way. To assist * with these names, this class includes a format method for each type of name, and additionally - * a parse method to extract the individual identifiers contained within names that are - * returned. + * a parseName method to extract the individual identifiers contained within formatted names + * that are returned by the API. * * @experimental */ @@ -124,6 +124,9 @@ class DlpServiceGapicClient const CODEGEN_VERSION = '0.0.5'; private static $resultNameTemplate; + private static $pathTemplateList = null; + private static $gapicVersion = null; + private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; protected $dlpServiceStub; @@ -132,36 +135,6 @@ class DlpServiceGapicClient private $descriptors; private $operationsClient; - /** - * Formats a string containing the fully-qualified path to represent - * a result resource. - * - * @param string $result - * - * @return string The formatted result resource. - * @experimental - */ - public static function formatResultName($result) - { - return self::getResultNameTemplate()->render([ - 'result' => $result, - ]); - } - - /** - * Parses the result from the given fully-qualified path which - * represents a result resource. - * - * @param string $resultName The fully-qualified result resource. - * - * @return string The extracted result value. - * @experimental - */ - public static function parseResultFromResultName($resultName) - { - return self::getResultNameTemplate()->match($resultName)['result']; - } - private static function getResultNameTemplate() { if (self::$resultNameTemplate == null) { @@ -170,6 +143,16 @@ private static function getResultNameTemplate() return self::$resultNameTemplate; } + private static function getPathTemplateList() + { + if (self::$pathTemplateList == null) { + self::$pathTemplateList = [ + self::getResultNameTemplate(), + ]; + } + + return self::$pathTemplateList; + } private static function getLongRunningDescriptors() { @@ -183,13 +166,54 @@ private static function getLongRunningDescriptors() private static function getGapicVersion() { - if (file_exists(__DIR__.'/../VERSION')) { - return trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - return \Google\Cloud\ServiceBuilder::VERSION; - } else { - return; + if (!self::$gapicVersionLoaded) { + if (file_exists(__DIR__.'/../VERSION')) { + self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } + self::$gapicVersionLoaded = true; + } + + return self::$gapicVersion; + } + + /** + * Formats a string containing the fully-qualified path to represent + * a result resource. + * + * @param string $result + * + * @return string The formatted result resource. + * @experimental + */ + public static function resultName($result) + { + return self::getResultNameTemplate()->render([ + 'result' => $result, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * - inspect/results/{result}. + * + * @param string $formattedName The formatted name string + * + * @return array An associative array from name component IDs to component values. + * @experimental + */ + public static function parseName($formattedName) + { + foreach (self::getPathTemplateList() as $pathTemplate) { + try { + return $pathTemplate->match($formattedName); + } catch (ValidationException $ex) { + // Swallow the exception to continue trying other path templates + } } + throw new ValidationException("Input did not match any known format. Input: $formattedName"); } /** @@ -254,15 +278,18 @@ public function resumeOperation($operationName, $methodName = null) * A CredentialsLoader object created using the Google\Auth library. * @type array $scopes A string array of scopes to use when acquiring credentials. * Defaults to the scopes for the DLP API. + * @type string $clientConfigPath + * Path to a JSON file containing client method configuration, including retry settings. + * Specify this setting to specify the retry behavior of all methods on the client. + * By default this settings points to the default client config file, which is provided + * in the resources folder. * @type array $retryingOverride - * An associative array of string => RetryOptions, where the keys - * are method names (e.g. 'createFoo'), that overrides default retrying - * settings. A value of null indicates that the method in question should - * not retry. - * @type int $timeoutMillis The timeout in milliseconds to use for calls - * that don't use retries. For calls that use retries, - * set the timeout in RetryOptions. - * Default: 30000 (30 seconds) + * An associative array in which the keys are method names (e.g. 'createFoo'), and + * the values are retry settings to use for that method. The retry settings for each + * method can be a {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} + * for example usage. Passing a value of null is equivalent to a value of + * ['retriesEnabled' => false]. * } * @experimental */ @@ -278,6 +305,7 @@ public function __construct($options = []) 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, + 'clientConfigPath' => __DIR__.'/../resources/dlp_service_client_config.json', ]; $options = array_merge($defaultOptions, $options); @@ -287,6 +315,7 @@ public function __construct($options = []) $operationsClientOptions = $options; unset($operationsClientOptions['timeoutMillis']); unset($operationsClientOptions['retryingOverride']); + unset($operationsClientOptions['clientConfigPath']); $this->operationsClient = new OperationsClient($operationsClientOptions); } @@ -312,15 +341,13 @@ public function __construct($options = []) $this->descriptors[$method]['longRunningDescriptor'] = $longRunningDescriptor + ['operationsClient' => $this->operationsClient]; } - $clientConfigJsonString = file_get_contents(__DIR__.'/../resources/dlp_service_client_config.json'); + $clientConfigJsonString = file_get_contents($options['clientConfigPath']); $clientConfig = json_decode($clientConfigJsonString, true); $this->defaultCallSettings = CallSettings::load( 'google.privacy.dlp.v2beta1.DlpService', $clientConfig, - $options['retryingOverride'], - GrpcConstants::getStatusCodeNames(), - $options['timeoutMillis'] + $options['retryingOverride'] ); $this->scopes = $options['scopes']; @@ -373,12 +400,11 @@ public function __construct($options = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Privacy\Dlp\V2beta1\InspectContentResponse @@ -451,12 +477,11 @@ public function inspectContent($inspectConfig, $items, $optionalArgs = []) * * @type ImageRedactionConfig[] $imageRedactionConfigs * The configuration for specifying what content to redact from images. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Privacy\Dlp\V2beta1\RedactContentResponse @@ -566,12 +591,11 @@ public function redactContent($inspectConfig, $items, $replaceConfigs, $optional * * @type OperationConfig $operationConfig * Additional configuration settings for long running operations. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\OperationResponse @@ -612,7 +636,7 @@ public function createInspectOperation($inspectConfig, $storageConfig, $outputCo * ``` * try { * $dlpServiceClient = new DlpServiceClient(); - * $formattedName = DlpServiceClient::formatResultName("[RESULT]"); + * $formattedName = $dlpServiceClient->resultName("[RESULT]"); * $response = $dlpServiceClient->listInspectFindings($formattedName); * } finally { * $dlpServiceClient->close(); @@ -640,12 +664,11 @@ public function createInspectOperation($inspectConfig, $storageConfig, $outputCo *
  • likelihood=VERY_LIKELY *
  • likelihood=VERY_LIKELY,LIKELY *
  • info_type=EMAIL_ADDRESS,likelihood=VERY_LIKELY,LIKELY - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Privacy\Dlp\V2beta1\ListInspectFindingsResponse @@ -705,12 +728,11 @@ public function listInspectFindings($name, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Privacy\Dlp\V2beta1\ListInfoTypesResponse @@ -760,12 +782,11 @@ public function listInfoTypes($category, $languageCode, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Privacy\Dlp\V2beta1\ListRootCategoriesResponse diff --git a/src/ErrorReporting/V1beta1/Gapic/ErrorGroupServiceGapicClient.php b/src/ErrorReporting/V1beta1/Gapic/ErrorGroupServiceGapicClient.php index a024985cdbc5..f2b980c6e8c2 100644 --- a/src/ErrorReporting/V1beta1/Gapic/ErrorGroupServiceGapicClient.php +++ b/src/ErrorReporting/V1beta1/Gapic/ErrorGroupServiceGapicClient.php @@ -37,9 +37,9 @@ use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; -use Google\GAX\GrpcConstants; use Google\GAX\GrpcCredentialsHelper; use Google\GAX\PathTemplate; +use Google\GAX\ValidationException; /** * Service Description: Service for retrieving and updating individual error groups. @@ -54,7 +54,7 @@ * ``` * try { * $errorGroupServiceClient = new ErrorGroupServiceClient(); - * $formattedGroupName = ErrorGroupServiceClient::formatGroupName("[PROJECT]", "[GROUP]"); + * $formattedGroupName = $errorGroupServiceClient->groupName("[PROJECT]", "[GROUP]"); * $response = $errorGroupServiceClient->getGroup($formattedGroupName); * } finally { * $errorGroupServiceClient->close(); @@ -63,8 +63,8 @@ * * Many parameters require resource names to be formatted in a particular way. To assist * with these names, this class includes a format method for each type of name, and additionally - * a parse method to extract the individual identifiers contained within names that are - * returned. + * a parseName method to extract the individual identifiers contained within formatted names + * that are returned by the API. * * @experimental */ @@ -96,6 +96,9 @@ class ErrorGroupServiceGapicClient const CODEGEN_VERSION = '0.0.5'; private static $groupNameTemplate; + private static $pathTemplateList = null; + private static $gapicVersion = null; + private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; protected $errorGroupServiceStub; @@ -103,6 +106,39 @@ class ErrorGroupServiceGapicClient private $defaultCallSettings; private $descriptors; + private static function getGroupNameTemplate() + { + if (self::$groupNameTemplate == null) { + self::$groupNameTemplate = new PathTemplate('projects/{project}/groups/{group}'); + } + + return self::$groupNameTemplate; + } + private static function getPathTemplateList() + { + if (self::$pathTemplateList == null) { + self::$pathTemplateList = [ + self::getGroupNameTemplate(), + ]; + } + + return self::$pathTemplateList; + } + + private static function getGapicVersion() + { + if (!self::$gapicVersionLoaded) { + if (file_exists(__DIR__.'/../VERSION')) { + self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } + self::$gapicVersionLoaded = true; + } + + return self::$gapicVersion; + } + /** * Formats a string containing the fully-qualified path to represent * a group resource. @@ -113,7 +149,7 @@ class ErrorGroupServiceGapicClient * @return string The formatted group resource. * @experimental */ - public static function formatGroupName($project, $group) + public static function groupName($project, $group) { return self::getGroupNameTemplate()->render([ 'project' => $project, @@ -122,51 +158,25 @@ public static function formatGroupName($project, $group) } /** - * Parses the project from the given fully-qualified path which - * represents a group resource. - * - * @param string $groupName The fully-qualified group resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromGroupName($groupName) - { - return self::getGroupNameTemplate()->match($groupName)['project']; - } - - /** - * Parses the group from the given fully-qualified path which - * represents a group resource. + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * - projects/{project}/groups/{group}. * - * @param string $groupName The fully-qualified group resource. + * @param string $formattedName The formatted name string * - * @return string The extracted group value. + * @return array An associative array from name component IDs to component values. * @experimental */ - public static function parseGroupFromGroupName($groupName) - { - return self::getGroupNameTemplate()->match($groupName)['group']; - } - - private static function getGroupNameTemplate() - { - if (self::$groupNameTemplate == null) { - self::$groupNameTemplate = new PathTemplate('projects/{project}/groups/{group}'); - } - - return self::$groupNameTemplate; - } - - private static function getGapicVersion() + public static function parseName($formattedName) { - if (file_exists(__DIR__.'/../VERSION')) { - return trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - return \Google\Cloud\ServiceBuilder::VERSION; - } else { - return; + foreach (self::getPathTemplateList() as $pathTemplate) { + try { + return $pathTemplate->match($formattedName); + } catch (ValidationException $ex) { + // Swallow the exception to continue trying other path templates + } } + throw new ValidationException("Input did not match any known format. Input: $formattedName"); } /** @@ -193,15 +203,18 @@ private static function getGapicVersion() * A CredentialsLoader object created using the Google\Auth library. * @type array $scopes A string array of scopes to use when acquiring credentials. * Defaults to the scopes for the Stackdriver Error Reporting API. + * @type string $clientConfigPath + * Path to a JSON file containing client method configuration, including retry settings. + * Specify this setting to specify the retry behavior of all methods on the client. + * By default this settings points to the default client config file, which is provided + * in the resources folder. * @type array $retryingOverride - * An associative array of string => RetryOptions, where the keys - * are method names (e.g. 'createFoo'), that overrides default retrying - * settings. A value of null indicates that the method in question should - * not retry. - * @type int $timeoutMillis The timeout in milliseconds to use for calls - * that don't use retries. For calls that use retries, - * set the timeout in RetryOptions. - * Default: 30000 (30 seconds) + * An associative array in which the keys are method names (e.g. 'createFoo'), and + * the values are retry settings to use for that method. The retry settings for each + * method can be a {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} + * for example usage. Passing a value of null is equivalent to a value of + * ['retriesEnabled' => false]. * } * @experimental */ @@ -217,6 +230,7 @@ public function __construct($options = []) 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, + 'clientConfigPath' => __DIR__.'/../resources/error_group_service_client_config.json', ]; $options = array_merge($defaultOptions, $options); @@ -234,15 +248,13 @@ public function __construct($options = []) 'updateGroup' => $defaultDescriptors, ]; - $clientConfigJsonString = file_get_contents(__DIR__.'/../resources/error_group_service_client_config.json'); + $clientConfigJsonString = file_get_contents($options['clientConfigPath']); $clientConfig = json_decode($clientConfigJsonString, true); $this->defaultCallSettings = CallSettings::load( 'google.devtools.clouderrorreporting.v1beta1.ErrorGroupService', $clientConfig, - $options['retryingOverride'], - GrpcConstants::getStatusCodeNames(), - $options['timeoutMillis'] + $options['retryingOverride'] ); $this->scopes = $options['scopes']; @@ -269,7 +281,7 @@ public function __construct($options = []) * ``` * try { * $errorGroupServiceClient = new ErrorGroupServiceClient(); - * $formattedGroupName = ErrorGroupServiceClient::formatGroupName("[PROJECT]", "[GROUP]"); + * $formattedGroupName = $errorGroupServiceClient->groupName("[PROJECT]", "[GROUP]"); * $response = $errorGroupServiceClient->getGroup($formattedGroupName); * } finally { * $errorGroupServiceClient->close(); @@ -287,12 +299,11 @@ public function __construct($options = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Devtools\Clouderrorreporting\V1beta1\ErrorGroup @@ -340,12 +351,11 @@ public function getGroup($groupName, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Devtools\Clouderrorreporting\V1beta1\ErrorGroup diff --git a/src/ErrorReporting/V1beta1/Gapic/ErrorStatsServiceGapicClient.php b/src/ErrorReporting/V1beta1/Gapic/ErrorStatsServiceGapicClient.php index 40ea53b5eec9..dd7b6a5e6fc9 100644 --- a/src/ErrorReporting/V1beta1/Gapic/ErrorStatsServiceGapicClient.php +++ b/src/ErrorReporting/V1beta1/Gapic/ErrorStatsServiceGapicClient.php @@ -39,10 +39,10 @@ use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; -use Google\GAX\GrpcConstants; use Google\GAX\GrpcCredentialsHelper; use Google\GAX\PageStreamingDescriptor; use Google\GAX\PathTemplate; +use Google\GAX\ValidationException; use Google\Protobuf\Duration; use Google\Protobuf\Timestamp; @@ -60,7 +60,7 @@ * ``` * try { * $errorStatsServiceClient = new ErrorStatsServiceClient(); - * $formattedProjectName = ErrorStatsServiceClient::formatProjectName("[PROJECT]"); + * $formattedProjectName = $errorStatsServiceClient->projectName("[PROJECT]"); * $timeRange = new QueryTimeRange(); * // Iterate through all elements * $pagedResponse = $errorStatsServiceClient->listGroupStats($formattedProjectName, $timeRange); @@ -82,8 +82,8 @@ * * Many parameters require resource names to be formatted in a particular way. To assist * with these names, this class includes a format method for each type of name, and additionally - * a parse method to extract the individual identifiers contained within names that are - * returned. + * a parseName method to extract the individual identifiers contained within formatted names + * that are returned by the API. * * @experimental */ @@ -115,6 +115,9 @@ class ErrorStatsServiceGapicClient const CODEGEN_VERSION = '0.0.5'; private static $projectNameTemplate; + private static $pathTemplateList = null; + private static $gapicVersion = null; + private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; protected $errorStatsServiceStub; @@ -122,36 +125,6 @@ class ErrorStatsServiceGapicClient private $defaultCallSettings; private $descriptors; - /** - * Formats a string containing the fully-qualified path to represent - * a project resource. - * - * @param string $project - * - * @return string The formatted project resource. - * @experimental - */ - public static function formatProjectName($project) - { - return self::getProjectNameTemplate()->render([ - 'project' => $project, - ]); - } - - /** - * Parses the project from the given fully-qualified path which - * represents a project resource. - * - * @param string $projectName The fully-qualified project resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromProjectName($projectName) - { - return self::getProjectNameTemplate()->match($projectName)['project']; - } - private static function getProjectNameTemplate() { if (self::$projectNameTemplate == null) { @@ -160,7 +133,16 @@ private static function getProjectNameTemplate() return self::$projectNameTemplate; } + private static function getPathTemplateList() + { + if (self::$pathTemplateList == null) { + self::$pathTemplateList = [ + self::getProjectNameTemplate(), + ]; + } + return self::$pathTemplateList; + } private static function getPageStreamingDescriptors() { $listGroupStatsPageStreamingDescriptor = @@ -192,13 +174,54 @@ private static function getPageStreamingDescriptors() private static function getGapicVersion() { - if (file_exists(__DIR__.'/../VERSION')) { - return trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - return \Google\Cloud\ServiceBuilder::VERSION; - } else { - return; + if (!self::$gapicVersionLoaded) { + if (file_exists(__DIR__.'/../VERSION')) { + self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } + self::$gapicVersionLoaded = true; + } + + return self::$gapicVersion; + } + + /** + * Formats a string containing the fully-qualified path to represent + * a project resource. + * + * @param string $project + * + * @return string The formatted project resource. + * @experimental + */ + public static function projectName($project) + { + return self::getProjectNameTemplate()->render([ + 'project' => $project, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * - projects/{project}. + * + * @param string $formattedName The formatted name string + * + * @return array An associative array from name component IDs to component values. + * @experimental + */ + public static function parseName($formattedName) + { + foreach (self::getPathTemplateList() as $pathTemplate) { + try { + return $pathTemplate->match($formattedName); + } catch (ValidationException $ex) { + // Swallow the exception to continue trying other path templates + } } + throw new ValidationException("Input did not match any known format. Input: $formattedName"); } /** @@ -225,15 +248,18 @@ private static function getGapicVersion() * A CredentialsLoader object created using the Google\Auth library. * @type array $scopes A string array of scopes to use when acquiring credentials. * Defaults to the scopes for the Stackdriver Error Reporting API. + * @type string $clientConfigPath + * Path to a JSON file containing client method configuration, including retry settings. + * Specify this setting to specify the retry behavior of all methods on the client. + * By default this settings points to the default client config file, which is provided + * in the resources folder. * @type array $retryingOverride - * An associative array of string => RetryOptions, where the keys - * are method names (e.g. 'createFoo'), that overrides default retrying - * settings. A value of null indicates that the method in question should - * not retry. - * @type int $timeoutMillis The timeout in milliseconds to use for calls - * that don't use retries. For calls that use retries, - * set the timeout in RetryOptions. - * Default: 30000 (30 seconds) + * An associative array in which the keys are method names (e.g. 'createFoo'), and + * the values are retry settings to use for that method. The retry settings for each + * method can be a {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} + * for example usage. Passing a value of null is equivalent to a value of + * ['retriesEnabled' => false]. * } * @experimental */ @@ -249,6 +275,7 @@ public function __construct($options = []) 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, + 'clientConfigPath' => __DIR__.'/../resources/error_stats_service_client_config.json', ]; $options = array_merge($defaultOptions, $options); @@ -271,15 +298,13 @@ public function __construct($options = []) $this->descriptors[$method]['pageStreamingDescriptor'] = $pageStreamingDescriptor; } - $clientConfigJsonString = file_get_contents(__DIR__.'/../resources/error_stats_service_client_config.json'); + $clientConfigJsonString = file_get_contents($options['clientConfigPath']); $clientConfig = json_decode($clientConfigJsonString, true); $this->defaultCallSettings = CallSettings::load( 'google.devtools.clouderrorreporting.v1beta1.ErrorStatsService', $clientConfig, - $options['retryingOverride'], - GrpcConstants::getStatusCodeNames(), - $options['timeoutMillis'] + $options['retryingOverride'] ); $this->scopes = $options['scopes']; @@ -306,7 +331,7 @@ public function __construct($options = []) * ``` * try { * $errorStatsServiceClient = new ErrorStatsServiceClient(); - * $formattedProjectName = ErrorStatsServiceClient::formatProjectName("[PROJECT]"); + * $formattedProjectName = $errorStatsServiceClient->projectName("[PROJECT]"); * $timeRange = new QueryTimeRange(); * // Iterate through all elements * $pagedResponse = $errorStatsServiceClient->listGroupStats($formattedProjectName, $timeRange); @@ -371,12 +396,11 @@ public function __construct($options = []) * If no page token is specified (the default), the first page * of values will be returned. Any page token used here must have * been generated by a previous call to the API. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\PagedListResponse @@ -437,7 +461,7 @@ public function listGroupStats($projectName, $timeRange, $optionalArgs = []) * ``` * try { * $errorStatsServiceClient = new ErrorStatsServiceClient(); - * $formattedProjectName = ErrorStatsServiceClient::formatProjectName("[PROJECT]"); + * $formattedProjectName = $errorStatsServiceClient->projectName("[PROJECT]"); * $groupId = ""; * // Iterate through all elements * $pagedResponse = $errorStatsServiceClient->listEvents($formattedProjectName, $groupId); @@ -483,12 +507,11 @@ public function listGroupStats($projectName, $timeRange, $optionalArgs = []) * If no page token is specified (the default), the first page * of values will be returned. Any page token used here must have * been generated by a previous call to the API. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\PagedListResponse @@ -537,7 +560,7 @@ public function listEvents($projectName, $groupId, $optionalArgs = []) * ``` * try { * $errorStatsServiceClient = new ErrorStatsServiceClient(); - * $formattedProjectName = ErrorStatsServiceClient::formatProjectName("[PROJECT]"); + * $formattedProjectName = $errorStatsServiceClient->projectName("[PROJECT]"); * $response = $errorStatsServiceClient->deleteEvents($formattedProjectName); * } finally { * $errorStatsServiceClient->close(); @@ -552,12 +575,11 @@ public function listEvents($projectName, $groupId, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Devtools\Clouderrorreporting\V1beta1\DeleteEventsResponse diff --git a/src/ErrorReporting/V1beta1/Gapic/ReportErrorsServiceGapicClient.php b/src/ErrorReporting/V1beta1/Gapic/ReportErrorsServiceGapicClient.php index 6872418f026b..01f87b078ee0 100644 --- a/src/ErrorReporting/V1beta1/Gapic/ReportErrorsServiceGapicClient.php +++ b/src/ErrorReporting/V1beta1/Gapic/ReportErrorsServiceGapicClient.php @@ -36,9 +36,9 @@ use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; -use Google\GAX\GrpcConstants; use Google\GAX\GrpcCredentialsHelper; use Google\GAX\PathTemplate; +use Google\GAX\ValidationException; /** * Service Description: An API for reporting error events. @@ -53,7 +53,7 @@ * ``` * try { * $reportErrorsServiceClient = new ReportErrorsServiceClient(); - * $formattedProjectName = ReportErrorsServiceClient::formatProjectName("[PROJECT]"); + * $formattedProjectName = $reportErrorsServiceClient->projectName("[PROJECT]"); * $event = new ReportedErrorEvent(); * $response = $reportErrorsServiceClient->reportErrorEvent($formattedProjectName, $event); * } finally { @@ -63,8 +63,8 @@ * * Many parameters require resource names to be formatted in a particular way. To assist * with these names, this class includes a format method for each type of name, and additionally - * a parse method to extract the individual identifiers contained within names that are - * returned. + * a parseName method to extract the individual identifiers contained within formatted names + * that are returned by the API. * * @experimental */ @@ -96,6 +96,9 @@ class ReportErrorsServiceGapicClient const CODEGEN_VERSION = '0.0.5'; private static $projectNameTemplate; + private static $pathTemplateList = null; + private static $gapicVersion = null; + private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; protected $reportErrorsServiceStub; @@ -103,6 +106,39 @@ class ReportErrorsServiceGapicClient private $defaultCallSettings; private $descriptors; + private static function getProjectNameTemplate() + { + if (self::$projectNameTemplate == null) { + self::$projectNameTemplate = new PathTemplate('projects/{project}'); + } + + return self::$projectNameTemplate; + } + private static function getPathTemplateList() + { + if (self::$pathTemplateList == null) { + self::$pathTemplateList = [ + self::getProjectNameTemplate(), + ]; + } + + return self::$pathTemplateList; + } + + private static function getGapicVersion() + { + if (!self::$gapicVersionLoaded) { + if (file_exists(__DIR__.'/../VERSION')) { + self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } + self::$gapicVersionLoaded = true; + } + + return self::$gapicVersion; + } + /** * Formats a string containing the fully-qualified path to represent * a project resource. @@ -112,7 +148,7 @@ class ReportErrorsServiceGapicClient * @return string The formatted project resource. * @experimental */ - public static function formatProjectName($project) + public static function projectName($project) { return self::getProjectNameTemplate()->render([ 'project' => $project, @@ -120,37 +156,25 @@ public static function formatProjectName($project) } /** - * Parses the project from the given fully-qualified path which - * represents a project resource. + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * - projects/{project}. * - * @param string $projectName The fully-qualified project resource. + * @param string $formattedName The formatted name string * - * @return string The extracted project value. + * @return array An associative array from name component IDs to component values. * @experimental */ - public static function parseProjectFromProjectName($projectName) - { - return self::getProjectNameTemplate()->match($projectName)['project']; - } - - private static function getProjectNameTemplate() - { - if (self::$projectNameTemplate == null) { - self::$projectNameTemplate = new PathTemplate('projects/{project}'); - } - - return self::$projectNameTemplate; - } - - private static function getGapicVersion() + public static function parseName($formattedName) { - if (file_exists(__DIR__.'/../VERSION')) { - return trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - return \Google\Cloud\ServiceBuilder::VERSION; - } else { - return; + foreach (self::getPathTemplateList() as $pathTemplate) { + try { + return $pathTemplate->match($formattedName); + } catch (ValidationException $ex) { + // Swallow the exception to continue trying other path templates + } } + throw new ValidationException("Input did not match any known format. Input: $formattedName"); } /** @@ -177,15 +201,18 @@ private static function getGapicVersion() * A CredentialsLoader object created using the Google\Auth library. * @type array $scopes A string array of scopes to use when acquiring credentials. * Defaults to the scopes for the Stackdriver Error Reporting API. + * @type string $clientConfigPath + * Path to a JSON file containing client method configuration, including retry settings. + * Specify this setting to specify the retry behavior of all methods on the client. + * By default this settings points to the default client config file, which is provided + * in the resources folder. * @type array $retryingOverride - * An associative array of string => RetryOptions, where the keys - * are method names (e.g. 'createFoo'), that overrides default retrying - * settings. A value of null indicates that the method in question should - * not retry. - * @type int $timeoutMillis The timeout in milliseconds to use for calls - * that don't use retries. For calls that use retries, - * set the timeout in RetryOptions. - * Default: 30000 (30 seconds) + * An associative array in which the keys are method names (e.g. 'createFoo'), and + * the values are retry settings to use for that method. The retry settings for each + * method can be a {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} + * for example usage. Passing a value of null is equivalent to a value of + * ['retriesEnabled' => false]. * } * @experimental */ @@ -201,6 +228,7 @@ public function __construct($options = []) 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, + 'clientConfigPath' => __DIR__.'/../resources/report_errors_service_client_config.json', ]; $options = array_merge($defaultOptions, $options); @@ -217,15 +245,13 @@ public function __construct($options = []) 'reportErrorEvent' => $defaultDescriptors, ]; - $clientConfigJsonString = file_get_contents(__DIR__.'/../resources/report_errors_service_client_config.json'); + $clientConfigJsonString = file_get_contents($options['clientConfigPath']); $clientConfig = json_decode($clientConfigJsonString, true); $this->defaultCallSettings = CallSettings::load( 'google.devtools.clouderrorreporting.v1beta1.ReportErrorsService', $clientConfig, - $options['retryingOverride'], - GrpcConstants::getStatusCodeNames(), - $options['timeoutMillis'] + $options['retryingOverride'] ); $this->scopes = $options['scopes']; @@ -259,7 +285,7 @@ public function __construct($options = []) * ``` * try { * $reportErrorsServiceClient = new ReportErrorsServiceClient(); - * $formattedProjectName = ReportErrorsServiceClient::formatProjectName("[PROJECT]"); + * $formattedProjectName = $reportErrorsServiceClient->projectName("[PROJECT]"); * $event = new ReportedErrorEvent(); * $response = $reportErrorsServiceClient->reportErrorEvent($formattedProjectName, $event); * } finally { @@ -275,12 +301,11 @@ public function __construct($options = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Devtools\Clouderrorreporting\V1beta1\ReportErrorEventResponse diff --git a/src/Language/V1beta2/Gapic/LanguageServiceGapicClient.php b/src/Language/V1beta2/Gapic/LanguageServiceGapicClient.php index 64833f1ccf7b..2ccffa027f61 100644 --- a/src/Language/V1beta2/Gapic/LanguageServiceGapicClient.php +++ b/src/Language/V1beta2/Gapic/LanguageServiceGapicClient.php @@ -43,7 +43,6 @@ use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; -use Google\GAX\GrpcConstants; use Google\GAX\GrpcCredentialsHelper; /** @@ -96,6 +95,9 @@ class LanguageServiceGapicClient */ const CODEGEN_VERSION = '0.0.5'; + private static $gapicVersion = null; + private static $gapicVersionLoaded = false; + protected $grpcCredentialsHelper; protected $languageServiceStub; private $scopes; @@ -104,13 +106,16 @@ class LanguageServiceGapicClient private static function getGapicVersion() { - if (file_exists(__DIR__.'/../VERSION')) { - return trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - return \Google\Cloud\ServiceBuilder::VERSION; - } else { - return; + if (!self::$gapicVersionLoaded) { + if (file_exists(__DIR__.'/../VERSION')) { + self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } + self::$gapicVersionLoaded = true; } + + return self::$gapicVersion; } /** @@ -137,15 +142,18 @@ private static function getGapicVersion() * A CredentialsLoader object created using the Google\Auth library. * @type array $scopes A string array of scopes to use when acquiring credentials. * Defaults to the scopes for the Google Cloud Natural Language API. + * @type string $clientConfigPath + * Path to a JSON file containing client method configuration, including retry settings. + * Specify this setting to specify the retry behavior of all methods on the client. + * By default this settings points to the default client config file, which is provided + * in the resources folder. * @type array $retryingOverride - * An associative array of string => RetryOptions, where the keys - * are method names (e.g. 'createFoo'), that overrides default retrying - * settings. A value of null indicates that the method in question should - * not retry. - * @type int $timeoutMillis The timeout in milliseconds to use for calls - * that don't use retries. For calls that use retries, - * set the timeout in RetryOptions. - * Default: 30000 (30 seconds) + * An associative array in which the keys are method names (e.g. 'createFoo'), and + * the values are retry settings to use for that method. The retry settings for each + * method can be a {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} + * for example usage. Passing a value of null is equivalent to a value of + * ['retriesEnabled' => false]. * } * @experimental */ @@ -161,6 +169,7 @@ public function __construct($options = []) 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, + 'clientConfigPath' => __DIR__.'/../resources/language_service_client_config.json', ]; $options = array_merge($defaultOptions, $options); @@ -182,15 +191,13 @@ public function __construct($options = []) 'annotateText' => $defaultDescriptors, ]; - $clientConfigJsonString = file_get_contents(__DIR__.'/../resources/language_service_client_config.json'); + $clientConfigJsonString = file_get_contents($options['clientConfigPath']); $clientConfig = json_decode($clientConfigJsonString, true); $this->defaultCallSettings = CallSettings::load( 'google.cloud.language.v1beta2.LanguageService', $clientConfig, - $options['retryingOverride'], - GrpcConstants::getStatusCodeNames(), - $options['timeoutMillis'] + $options['retryingOverride'] ); $this->scopes = $options['scopes']; @@ -232,12 +239,11 @@ public function __construct($options = []) * The encoding type used by the API to calculate sentence offsets for the * sentence sentiment. * For allowed values, use constants defined on {@see \Google\Cloud\Language\V1beta2\EncodingType} - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Cloud\Language\V1beta2\AnalyzeSentimentResponse @@ -292,12 +298,11 @@ public function analyzeSentiment($document, $optionalArgs = []) * @type int $encodingType * The encoding type used by the API to calculate offsets. * For allowed values, use constants defined on {@see \Google\Cloud\Language\V1beta2\EncodingType} - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Cloud\Language\V1beta2\AnalyzeEntitiesResponse @@ -351,12 +356,11 @@ public function analyzeEntities($document, $optionalArgs = []) * @type int $encodingType * The encoding type used by the API to calculate offsets. * For allowed values, use constants defined on {@see \Google\Cloud\Language\V1beta2\EncodingType} - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Cloud\Language\V1beta2\AnalyzeEntitySentimentResponse @@ -411,12 +415,11 @@ public function analyzeEntitySentiment($document, $optionalArgs = []) * @type int $encodingType * The encoding type used by the API to calculate offsets. * For allowed values, use constants defined on {@see \Google\Cloud\Language\V1beta2\EncodingType} - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Cloud\Language\V1beta2\AnalyzeSyntaxResponse @@ -466,12 +469,11 @@ public function analyzeSyntax($document, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Cloud\Language\V1beta2\ClassifyTextResponse @@ -524,12 +526,11 @@ public function classifyText($document, $optionalArgs = []) * @type int $encodingType * The encoding type used by the API to calculate offsets. * For allowed values, use constants defined on {@see \Google\Cloud\Language\V1beta2\EncodingType} - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Cloud\Language\V1beta2\AnnotateTextResponse diff --git a/src/Logging/V2/Gapic/ConfigServiceV2GapicClient.php b/src/Logging/V2/Gapic/ConfigServiceV2GapicClient.php index 9098371ccea9..354d6e7c5abb 100644 --- a/src/Logging/V2/Gapic/ConfigServiceV2GapicClient.php +++ b/src/Logging/V2/Gapic/ConfigServiceV2GapicClient.php @@ -33,10 +33,10 @@ use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; -use Google\GAX\GrpcConstants; use Google\GAX\GrpcCredentialsHelper; use Google\GAX\PageStreamingDescriptor; use Google\GAX\PathTemplate; +use Google\GAX\ValidationException; use Google\Logging\V2\ConfigServiceV2GrpcClient; use Google\Logging\V2\CreateSinkRequest; use Google\Logging\V2\DeleteSinkRequest; @@ -59,7 +59,7 @@ * ``` * try { * $configServiceV2Client = new ConfigServiceV2Client(); - * $formattedParent = ConfigServiceV2Client::formatProjectName("[PROJECT]"); + * $formattedParent = $configServiceV2Client->projectName("[PROJECT]"); * // Iterate through all elements * $pagedResponse = $configServiceV2Client->listSinks($formattedParent); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -80,8 +80,8 @@ * * Many parameters require resource names to be formatted in a particular way. To assist * with these names, this class includes a format method for each type of name, and additionally - * a parse method to extract the individual identifiers contained within names that are - * returned. + * a parseName method to extract the individual identifiers contained within formatted names + * that are returned by the API. * * @experimental */ @@ -114,6 +114,9 @@ class ConfigServiceV2GapicClient private static $projectNameTemplate; private static $sinkNameTemplate; + private static $pathTemplateList = null; + private static $gapicVersion = null; + private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; protected $configServiceV2Stub; @@ -121,82 +124,6 @@ class ConfigServiceV2GapicClient private $defaultCallSettings; private $descriptors; - /** - * Formats a string containing the fully-qualified path to represent - * a project resource. - * - * @param string $project - * - * @return string The formatted project resource. - * @experimental - */ - public static function formatProjectName($project) - { - return self::getProjectNameTemplate()->render([ - 'project' => $project, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent - * a sink resource. - * - * @param string $project - * @param string $sink - * - * @return string The formatted sink resource. - * @experimental - */ - public static function formatSinkName($project, $sink) - { - return self::getSinkNameTemplate()->render([ - 'project' => $project, - 'sink' => $sink, - ]); - } - - /** - * Parses the project from the given fully-qualified path which - * represents a project resource. - * - * @param string $projectName The fully-qualified project resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromProjectName($projectName) - { - return self::getProjectNameTemplate()->match($projectName)['project']; - } - - /** - * Parses the project from the given fully-qualified path which - * represents a sink resource. - * - * @param string $sinkName The fully-qualified sink resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromSinkName($sinkName) - { - return self::getSinkNameTemplate()->match($sinkName)['project']; - } - - /** - * Parses the sink from the given fully-qualified path which - * represents a sink resource. - * - * @param string $sinkName The fully-qualified sink resource. - * - * @return string The extracted sink value. - * @experimental - */ - public static function parseSinkFromSinkName($sinkName) - { - return self::getSinkNameTemplate()->match($sinkName)['sink']; - } - private static function getProjectNameTemplate() { if (self::$projectNameTemplate == null) { @@ -214,7 +141,17 @@ private static function getSinkNameTemplate() return self::$sinkNameTemplate; } + private static function getPathTemplateList() + { + if (self::$pathTemplateList == null) { + self::$pathTemplateList = [ + self::getProjectNameTemplate(), + self::getSinkNameTemplate(), + ]; + } + return self::$pathTemplateList; + } private static function getPageStreamingDescriptors() { $listSinksPageStreamingDescriptor = @@ -236,13 +173,73 @@ private static function getPageStreamingDescriptors() private static function getGapicVersion() { - if (file_exists(__DIR__.'/../VERSION')) { - return trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - return \Google\Cloud\ServiceBuilder::VERSION; - } else { - return; + if (!self::$gapicVersionLoaded) { + if (file_exists(__DIR__.'/../VERSION')) { + self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } + self::$gapicVersionLoaded = true; + } + + return self::$gapicVersion; + } + + /** + * Formats a string containing the fully-qualified path to represent + * a project resource. + * + * @param string $project + * + * @return string The formatted project resource. + * @experimental + */ + public static function projectName($project) + { + return self::getProjectNameTemplate()->render([ + 'project' => $project, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a sink resource. + * + * @param string $project + * @param string $sink + * + * @return string The formatted sink resource. + * @experimental + */ + public static function sinkName($project, $sink) + { + return self::getSinkNameTemplate()->render([ + 'project' => $project, + 'sink' => $sink, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * - projects/{project} + * - projects/{project}/sinks/{sink}. + * + * @param string $formattedName The formatted name string + * + * @return array An associative array from name component IDs to component values. + * @experimental + */ + public static function parseName($formattedName) + { + foreach (self::getPathTemplateList() as $pathTemplate) { + try { + return $pathTemplate->match($formattedName); + } catch (ValidationException $ex) { + // Swallow the exception to continue trying other path templates + } } + throw new ValidationException("Input did not match any known format. Input: $formattedName"); } /** @@ -269,15 +266,18 @@ private static function getGapicVersion() * A CredentialsLoader object created using the Google\Auth library. * @type array $scopes A string array of scopes to use when acquiring credentials. * Defaults to the scopes for the Stackdriver Logging API. + * @type string $clientConfigPath + * Path to a JSON file containing client method configuration, including retry settings. + * Specify this setting to specify the retry behavior of all methods on the client. + * By default this settings points to the default client config file, which is provided + * in the resources folder. * @type array $retryingOverride - * An associative array of string => RetryOptions, where the keys - * are method names (e.g. 'createFoo'), that overrides default retrying - * settings. A value of null indicates that the method in question should - * not retry. - * @type int $timeoutMillis The timeout in milliseconds to use for calls - * that don't use retries. For calls that use retries, - * set the timeout in RetryOptions. - * Default: 30000 (30 seconds) + * An associative array in which the keys are method names (e.g. 'createFoo'), and + * the values are retry settings to use for that method. The retry settings for each + * method can be a {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} + * for example usage. Passing a value of null is equivalent to a value of + * ['retriesEnabled' => false]. * } * @experimental */ @@ -297,6 +297,7 @@ public function __construct($options = []) 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, + 'clientConfigPath' => __DIR__.'/../resources/config_service_v2_client_config.json', ]; $options = array_merge($defaultOptions, $options); @@ -321,15 +322,13 @@ public function __construct($options = []) $this->descriptors[$method]['pageStreamingDescriptor'] = $pageStreamingDescriptor; } - $clientConfigJsonString = file_get_contents(__DIR__.'/../resources/config_service_v2_client_config.json'); + $clientConfigJsonString = file_get_contents($options['clientConfigPath']); $clientConfig = json_decode($clientConfigJsonString, true); $this->defaultCallSettings = CallSettings::load( 'google.logging.v2.ConfigServiceV2', $clientConfig, - $options['retryingOverride'], - GrpcConstants::getStatusCodeNames(), - $options['timeoutMillis'] + $options['retryingOverride'] ); $this->scopes = $options['scopes']; @@ -356,7 +355,7 @@ public function __construct($options = []) * ``` * try { * $configServiceV2Client = new ConfigServiceV2Client(); - * $formattedParent = ConfigServiceV2Client::formatProjectName("[PROJECT]"); + * $formattedParent = $configServiceV2Client->projectName("[PROJECT]"); * // Iterate through all elements * $pagedResponse = $configServiceV2Client->listSinks($formattedParent); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -393,12 +392,11 @@ public function __construct($options = []) * The maximum number of resources contained in the underlying API * response. The API may return fewer values in a page, even if * there are additional values to be retrieved. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\PagedListResponse @@ -440,7 +438,7 @@ public function listSinks($parent, $optionalArgs = []) * ``` * try { * $configServiceV2Client = new ConfigServiceV2Client(); - * $formattedSinkName = ConfigServiceV2Client::formatSinkName("[PROJECT]", "[SINK]"); + * $formattedSinkName = $configServiceV2Client->sinkName("[PROJECT]", "[SINK]"); * $response = $configServiceV2Client->getSink($formattedSinkName); * } finally { * $configServiceV2Client->close(); @@ -458,12 +456,11 @@ public function listSinks($parent, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Logging\V2\LogSink @@ -503,7 +500,7 @@ public function getSink($sinkName, $optionalArgs = []) * ``` * try { * $configServiceV2Client = new ConfigServiceV2Client(); - * $formattedParent = ConfigServiceV2Client::formatProjectName("[PROJECT]"); + * $formattedParent = $configServiceV2Client->projectName("[PROJECT]"); * $sink = new LogSink(); * $response = $configServiceV2Client->createSink($formattedParent, $sink); * } finally { @@ -536,12 +533,11 @@ public function getSink($sinkName, $optionalArgs = []) * resource such as an organization, then the value of `writer_identity` will * be a unique service account used only for exports from the new sink. For * more information, see `writer_identity` in [LogSink][google.logging.v2.LogSink]. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Logging\V2\LogSink @@ -585,7 +581,7 @@ public function createSink($parent, $sink, $optionalArgs = []) * ``` * try { * $configServiceV2Client = new ConfigServiceV2Client(); - * $formattedSinkName = ConfigServiceV2Client::formatSinkName("[PROJECT]", "[SINK]"); + * $formattedSinkName = $configServiceV2Client->sinkName("[PROJECT]", "[SINK]"); * $sink = new LogSink(); * $response = $configServiceV2Client->updateSink($formattedSinkName, $sink); * } finally { @@ -620,12 +616,11 @@ public function createSink($parent, $sink, $optionalArgs = []) * `writer_identity` is changed to a unique service account. * + It is an error if the old value is true and the new value is * set to false or defaulted to false. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Logging\V2\LogSink @@ -666,7 +661,7 @@ public function updateSink($sinkName, $sink, $optionalArgs = []) * ``` * try { * $configServiceV2Client = new ConfigServiceV2Client(); - * $formattedSinkName = ConfigServiceV2Client::formatSinkName("[PROJECT]", "[SINK]"); + * $formattedSinkName = $configServiceV2Client->sinkName("[PROJECT]", "[SINK]"); * $configServiceV2Client->deleteSink($formattedSinkName); * } finally { * $configServiceV2Client->close(); @@ -685,12 +680,11 @@ public function updateSink($sinkName, $sink, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @throws \Google\GAX\ApiException if the remote call fails diff --git a/src/Logging/V2/Gapic/LoggingServiceV2GapicClient.php b/src/Logging/V2/Gapic/LoggingServiceV2GapicClient.php index 96beea321d21..20ce81b71f87 100644 --- a/src/Logging/V2/Gapic/LoggingServiceV2GapicClient.php +++ b/src/Logging/V2/Gapic/LoggingServiceV2GapicClient.php @@ -34,10 +34,10 @@ use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; -use Google\GAX\GrpcConstants; use Google\GAX\GrpcCredentialsHelper; use Google\GAX\PageStreamingDescriptor; use Google\GAX\PathTemplate; +use Google\GAX\ValidationException; use Google\Logging\V2\DeleteLogRequest; use Google\Logging\V2\ListLogEntriesRequest; use Google\Logging\V2\ListLogsRequest; @@ -59,7 +59,7 @@ * ``` * try { * $loggingServiceV2Client = new LoggingServiceV2Client(); - * $formattedLogName = LoggingServiceV2Client::formatLogName("[PROJECT]", "[LOG]"); + * $formattedLogName = $loggingServiceV2Client->logName("[PROJECT]", "[LOG]"); * $loggingServiceV2Client->deleteLog($formattedLogName); * } finally { * $loggingServiceV2Client->close(); @@ -68,8 +68,8 @@ * * Many parameters require resource names to be formatted in a particular way. To assist * with these names, this class includes a format method for each type of name, and additionally - * a parse method to extract the individual identifiers contained within names that are - * returned. + * a parseName method to extract the individual identifiers contained within formatted names + * that are returned by the API. * * @experimental */ @@ -102,6 +102,9 @@ class LoggingServiceV2GapicClient private static $projectNameTemplate; private static $logNameTemplate; + private static $pathTemplateList = null; + private static $gapicVersion = null; + private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; protected $loggingServiceV2Stub; @@ -109,82 +112,6 @@ class LoggingServiceV2GapicClient private $defaultCallSettings; private $descriptors; - /** - * Formats a string containing the fully-qualified path to represent - * a project resource. - * - * @param string $project - * - * @return string The formatted project resource. - * @experimental - */ - public static function formatProjectName($project) - { - return self::getProjectNameTemplate()->render([ - 'project' => $project, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent - * a log resource. - * - * @param string $project - * @param string $log - * - * @return string The formatted log resource. - * @experimental - */ - public static function formatLogName($project, $log) - { - return self::getLogNameTemplate()->render([ - 'project' => $project, - 'log' => $log, - ]); - } - - /** - * Parses the project from the given fully-qualified path which - * represents a project resource. - * - * @param string $projectName The fully-qualified project resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromProjectName($projectName) - { - return self::getProjectNameTemplate()->match($projectName)['project']; - } - - /** - * Parses the project from the given fully-qualified path which - * represents a log resource. - * - * @param string $logName The fully-qualified log resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromLogName($logName) - { - return self::getLogNameTemplate()->match($logName)['project']; - } - - /** - * Parses the log from the given fully-qualified path which - * represents a log resource. - * - * @param string $logName The fully-qualified log resource. - * - * @return string The extracted log value. - * @experimental - */ - public static function parseLogFromLogName($logName) - { - return self::getLogNameTemplate()->match($logName)['log']; - } - private static function getProjectNameTemplate() { if (self::$projectNameTemplate == null) { @@ -202,7 +129,17 @@ private static function getLogNameTemplate() return self::$logNameTemplate; } + private static function getPathTemplateList() + { + if (self::$pathTemplateList == null) { + self::$pathTemplateList = [ + self::getProjectNameTemplate(), + self::getLogNameTemplate(), + ]; + } + return self::$pathTemplateList; + } private static function getPageStreamingDescriptors() { $listLogEntriesPageStreamingDescriptor = @@ -244,13 +181,73 @@ private static function getPageStreamingDescriptors() private static function getGapicVersion() { - if (file_exists(__DIR__.'/../VERSION')) { - return trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - return \Google\Cloud\ServiceBuilder::VERSION; - } else { - return; + if (!self::$gapicVersionLoaded) { + if (file_exists(__DIR__.'/../VERSION')) { + self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } + self::$gapicVersionLoaded = true; + } + + return self::$gapicVersion; + } + + /** + * Formats a string containing the fully-qualified path to represent + * a project resource. + * + * @param string $project + * + * @return string The formatted project resource. + * @experimental + */ + public static function projectName($project) + { + return self::getProjectNameTemplate()->render([ + 'project' => $project, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a log resource. + * + * @param string $project + * @param string $log + * + * @return string The formatted log resource. + * @experimental + */ + public static function logName($project, $log) + { + return self::getLogNameTemplate()->render([ + 'project' => $project, + 'log' => $log, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * - projects/{project} + * - projects/{project}/logs/{log}. + * + * @param string $formattedName The formatted name string + * + * @return array An associative array from name component IDs to component values. + * @experimental + */ + public static function parseName($formattedName) + { + foreach (self::getPathTemplateList() as $pathTemplate) { + try { + return $pathTemplate->match($formattedName); + } catch (ValidationException $ex) { + // Swallow the exception to continue trying other path templates + } } + throw new ValidationException("Input did not match any known format. Input: $formattedName"); } /** @@ -277,15 +274,18 @@ private static function getGapicVersion() * A CredentialsLoader object created using the Google\Auth library. * @type array $scopes A string array of scopes to use when acquiring credentials. * Defaults to the scopes for the Stackdriver Logging API. + * @type string $clientConfigPath + * Path to a JSON file containing client method configuration, including retry settings. + * Specify this setting to specify the retry behavior of all methods on the client. + * By default this settings points to the default client config file, which is provided + * in the resources folder. * @type array $retryingOverride - * An associative array of string => RetryOptions, where the keys - * are method names (e.g. 'createFoo'), that overrides default retrying - * settings. A value of null indicates that the method in question should - * not retry. - * @type int $timeoutMillis The timeout in milliseconds to use for calls - * that don't use retries. For calls that use retries, - * set the timeout in RetryOptions. - * Default: 30000 (30 seconds) + * An associative array in which the keys are method names (e.g. 'createFoo'), and + * the values are retry settings to use for that method. The retry settings for each + * method can be a {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} + * for example usage. Passing a value of null is equivalent to a value of + * ['retriesEnabled' => false]. * } * @experimental */ @@ -305,6 +305,7 @@ public function __construct($options = []) 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, + 'clientConfigPath' => __DIR__.'/../resources/logging_service_v2_client_config.json', ]; $options = array_merge($defaultOptions, $options); @@ -329,15 +330,13 @@ public function __construct($options = []) $this->descriptors[$method]['pageStreamingDescriptor'] = $pageStreamingDescriptor; } - $clientConfigJsonString = file_get_contents(__DIR__.'/../resources/logging_service_v2_client_config.json'); + $clientConfigJsonString = file_get_contents($options['clientConfigPath']); $clientConfig = json_decode($clientConfigJsonString, true); $this->defaultCallSettings = CallSettings::load( 'google.logging.v2.LoggingServiceV2', $clientConfig, - $options['retryingOverride'], - GrpcConstants::getStatusCodeNames(), - $options['timeoutMillis'] + $options['retryingOverride'] ); $this->scopes = $options['scopes']; @@ -367,7 +366,7 @@ public function __construct($options = []) * ``` * try { * $loggingServiceV2Client = new LoggingServiceV2Client(); - * $formattedLogName = LoggingServiceV2Client::formatLogName("[PROJECT]", "[LOG]"); + * $formattedLogName = $loggingServiceV2Client->logName("[PROJECT]", "[LOG]"); * $loggingServiceV2Client->deleteLog($formattedLogName); * } finally { * $loggingServiceV2Client->close(); @@ -389,12 +388,11 @@ public function __construct($options = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @throws \Google\GAX\ApiException if the remote call fails @@ -499,12 +497,11 @@ public function deleteLog($logName, $optionalArgs = []) * entry is not written, then the response status is the error associated * with one of the failed entries and the response includes error details * keyed by the entries' zero-based index in the `entries.write` method. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Logging\V2\WriteLogEntriesResponse @@ -615,12 +612,11 @@ public function writeLogEntries($entries, $optionalArgs = []) * If no page token is specified (the default), the first page * of values will be returned. Any page token used here must have * been generated by a previous call to the API. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\PagedListResponse @@ -703,12 +699,11 @@ public function listLogEntries($resourceNames, $optionalArgs = []) * If no page token is specified (the default), the first page * of values will be returned. Any page token used here must have * been generated by a previous call to the API. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\PagedListResponse @@ -750,7 +745,7 @@ public function listMonitoredResourceDescriptors($optionalArgs = []) * ``` * try { * $loggingServiceV2Client = new LoggingServiceV2Client(); - * $formattedParent = LoggingServiceV2Client::formatProjectName("[PROJECT]"); + * $formattedParent = $loggingServiceV2Client->projectName("[PROJECT]"); * // Iterate through all elements * $pagedResponse = $loggingServiceV2Client->listLogs($formattedParent); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -787,12 +782,11 @@ public function listMonitoredResourceDescriptors($optionalArgs = []) * If no page token is specified (the default), the first page * of values will be returned. Any page token used here must have * been generated by a previous call to the API. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\PagedListResponse diff --git a/src/Logging/V2/Gapic/MetricsServiceV2GapicClient.php b/src/Logging/V2/Gapic/MetricsServiceV2GapicClient.php index f60547ee7165..482c8846b1d3 100644 --- a/src/Logging/V2/Gapic/MetricsServiceV2GapicClient.php +++ b/src/Logging/V2/Gapic/MetricsServiceV2GapicClient.php @@ -33,10 +33,10 @@ use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; -use Google\GAX\GrpcConstants; use Google\GAX\GrpcCredentialsHelper; use Google\GAX\PageStreamingDescriptor; use Google\GAX\PathTemplate; +use Google\GAX\ValidationException; use Google\Logging\V2\CreateLogMetricRequest; use Google\Logging\V2\DeleteLogMetricRequest; use Google\Logging\V2\GetLogMetricRequest; @@ -58,7 +58,7 @@ * ``` * try { * $metricsServiceV2Client = new MetricsServiceV2Client(); - * $formattedParent = MetricsServiceV2Client::formatProjectName("[PROJECT]"); + * $formattedParent = $metricsServiceV2Client->projectName("[PROJECT]"); * // Iterate through all elements * $pagedResponse = $metricsServiceV2Client->listLogMetrics($formattedParent); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -79,8 +79,8 @@ * * Many parameters require resource names to be formatted in a particular way. To assist * with these names, this class includes a format method for each type of name, and additionally - * a parse method to extract the individual identifiers contained within names that are - * returned. + * a parseName method to extract the individual identifiers contained within formatted names + * that are returned by the API. * * @experimental */ @@ -113,6 +113,9 @@ class MetricsServiceV2GapicClient private static $projectNameTemplate; private static $metricNameTemplate; + private static $pathTemplateList = null; + private static $gapicVersion = null; + private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; protected $metricsServiceV2Stub; @@ -120,82 +123,6 @@ class MetricsServiceV2GapicClient private $defaultCallSettings; private $descriptors; - /** - * Formats a string containing the fully-qualified path to represent - * a project resource. - * - * @param string $project - * - * @return string The formatted project resource. - * @experimental - */ - public static function formatProjectName($project) - { - return self::getProjectNameTemplate()->render([ - 'project' => $project, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent - * a metric resource. - * - * @param string $project - * @param string $metric - * - * @return string The formatted metric resource. - * @experimental - */ - public static function formatMetricName($project, $metric) - { - return self::getMetricNameTemplate()->render([ - 'project' => $project, - 'metric' => $metric, - ]); - } - - /** - * Parses the project from the given fully-qualified path which - * represents a project resource. - * - * @param string $projectName The fully-qualified project resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromProjectName($projectName) - { - return self::getProjectNameTemplate()->match($projectName)['project']; - } - - /** - * Parses the project from the given fully-qualified path which - * represents a metric resource. - * - * @param string $metricName The fully-qualified metric resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromMetricName($metricName) - { - return self::getMetricNameTemplate()->match($metricName)['project']; - } - - /** - * Parses the metric from the given fully-qualified path which - * represents a metric resource. - * - * @param string $metricName The fully-qualified metric resource. - * - * @return string The extracted metric value. - * @experimental - */ - public static function parseMetricFromMetricName($metricName) - { - return self::getMetricNameTemplate()->match($metricName)['metric']; - } - private static function getProjectNameTemplate() { if (self::$projectNameTemplate == null) { @@ -213,7 +140,17 @@ private static function getMetricNameTemplate() return self::$metricNameTemplate; } + private static function getPathTemplateList() + { + if (self::$pathTemplateList == null) { + self::$pathTemplateList = [ + self::getProjectNameTemplate(), + self::getMetricNameTemplate(), + ]; + } + return self::$pathTemplateList; + } private static function getPageStreamingDescriptors() { $listLogMetricsPageStreamingDescriptor = @@ -235,13 +172,73 @@ private static function getPageStreamingDescriptors() private static function getGapicVersion() { - if (file_exists(__DIR__.'/../VERSION')) { - return trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - return \Google\Cloud\ServiceBuilder::VERSION; - } else { - return; + if (!self::$gapicVersionLoaded) { + if (file_exists(__DIR__.'/../VERSION')) { + self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } + self::$gapicVersionLoaded = true; + } + + return self::$gapicVersion; + } + + /** + * Formats a string containing the fully-qualified path to represent + * a project resource. + * + * @param string $project + * + * @return string The formatted project resource. + * @experimental + */ + public static function projectName($project) + { + return self::getProjectNameTemplate()->render([ + 'project' => $project, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a metric resource. + * + * @param string $project + * @param string $metric + * + * @return string The formatted metric resource. + * @experimental + */ + public static function metricName($project, $metric) + { + return self::getMetricNameTemplate()->render([ + 'project' => $project, + 'metric' => $metric, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * - projects/{project} + * - projects/{project}/metrics/{metric}. + * + * @param string $formattedName The formatted name string + * + * @return array An associative array from name component IDs to component values. + * @experimental + */ + public static function parseName($formattedName) + { + foreach (self::getPathTemplateList() as $pathTemplate) { + try { + return $pathTemplate->match($formattedName); + } catch (ValidationException $ex) { + // Swallow the exception to continue trying other path templates + } } + throw new ValidationException("Input did not match any known format. Input: $formattedName"); } /** @@ -268,15 +265,18 @@ private static function getGapicVersion() * A CredentialsLoader object created using the Google\Auth library. * @type array $scopes A string array of scopes to use when acquiring credentials. * Defaults to the scopes for the Stackdriver Logging API. + * @type string $clientConfigPath + * Path to a JSON file containing client method configuration, including retry settings. + * Specify this setting to specify the retry behavior of all methods on the client. + * By default this settings points to the default client config file, which is provided + * in the resources folder. * @type array $retryingOverride - * An associative array of string => RetryOptions, where the keys - * are method names (e.g. 'createFoo'), that overrides default retrying - * settings. A value of null indicates that the method in question should - * not retry. - * @type int $timeoutMillis The timeout in milliseconds to use for calls - * that don't use retries. For calls that use retries, - * set the timeout in RetryOptions. - * Default: 30000 (30 seconds) + * An associative array in which the keys are method names (e.g. 'createFoo'), and + * the values are retry settings to use for that method. The retry settings for each + * method can be a {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} + * for example usage. Passing a value of null is equivalent to a value of + * ['retriesEnabled' => false]. * } * @experimental */ @@ -296,6 +296,7 @@ public function __construct($options = []) 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, + 'clientConfigPath' => __DIR__.'/../resources/metrics_service_v2_client_config.json', ]; $options = array_merge($defaultOptions, $options); @@ -320,15 +321,13 @@ public function __construct($options = []) $this->descriptors[$method]['pageStreamingDescriptor'] = $pageStreamingDescriptor; } - $clientConfigJsonString = file_get_contents(__DIR__.'/../resources/metrics_service_v2_client_config.json'); + $clientConfigJsonString = file_get_contents($options['clientConfigPath']); $clientConfig = json_decode($clientConfigJsonString, true); $this->defaultCallSettings = CallSettings::load( 'google.logging.v2.MetricsServiceV2', $clientConfig, - $options['retryingOverride'], - GrpcConstants::getStatusCodeNames(), - $options['timeoutMillis'] + $options['retryingOverride'] ); $this->scopes = $options['scopes']; @@ -355,7 +354,7 @@ public function __construct($options = []) * ``` * try { * $metricsServiceV2Client = new MetricsServiceV2Client(); - * $formattedParent = MetricsServiceV2Client::formatProjectName("[PROJECT]"); + * $formattedParent = $metricsServiceV2Client->projectName("[PROJECT]"); * // Iterate through all elements * $pagedResponse = $metricsServiceV2Client->listLogMetrics($formattedParent); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -389,12 +388,11 @@ public function __construct($options = []) * The maximum number of resources contained in the underlying API * response. The API may return fewer values in a page, even if * there are additional values to be retrieved. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\PagedListResponse @@ -436,7 +434,7 @@ public function listLogMetrics($parent, $optionalArgs = []) * ``` * try { * $metricsServiceV2Client = new MetricsServiceV2Client(); - * $formattedMetricName = MetricsServiceV2Client::formatMetricName("[PROJECT]", "[METRIC]"); + * $formattedMetricName = $metricsServiceV2Client->metricName("[PROJECT]", "[METRIC]"); * $response = $metricsServiceV2Client->getLogMetric($formattedMetricName); * } finally { * $metricsServiceV2Client->close(); @@ -449,12 +447,11 @@ public function listLogMetrics($parent, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Logging\V2\LogMetric @@ -490,7 +487,7 @@ public function getLogMetric($metricName, $optionalArgs = []) * ``` * try { * $metricsServiceV2Client = new MetricsServiceV2Client(); - * $formattedParent = MetricsServiceV2Client::formatProjectName("[PROJECT]"); + * $formattedParent = $metricsServiceV2Client->projectName("[PROJECT]"); * $metric = new LogMetric(); * $response = $metricsServiceV2Client->createLogMetric($formattedParent, $metric); * } finally { @@ -508,12 +505,11 @@ public function getLogMetric($metricName, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Logging\V2\LogMetric @@ -550,7 +546,7 @@ public function createLogMetric($parent, $metric, $optionalArgs = []) * ``` * try { * $metricsServiceV2Client = new MetricsServiceV2Client(); - * $formattedMetricName = MetricsServiceV2Client::formatMetricName("[PROJECT]", "[METRIC]"); + * $formattedMetricName = $metricsServiceV2Client->metricName("[PROJECT]", "[METRIC]"); * $metric = new LogMetric(); * $response = $metricsServiceV2Client->updateLogMetric($formattedMetricName, $metric); * } finally { @@ -569,12 +565,11 @@ public function createLogMetric($parent, $metric, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Logging\V2\LogMetric @@ -611,7 +606,7 @@ public function updateLogMetric($metricName, $metric, $optionalArgs = []) * ``` * try { * $metricsServiceV2Client = new MetricsServiceV2Client(); - * $formattedMetricName = MetricsServiceV2Client::formatMetricName("[PROJECT]", "[METRIC]"); + * $formattedMetricName = $metricsServiceV2Client->metricName("[PROJECT]", "[METRIC]"); * $metricsServiceV2Client->deleteLogMetric($formattedMetricName); * } finally { * $metricsServiceV2Client->close(); @@ -624,12 +619,11 @@ public function updateLogMetric($metricName, $metric, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @throws \Google\GAX\ApiException if the remote call fails diff --git a/src/Monitoring/V3/Gapic/GroupServiceGapicClient.php b/src/Monitoring/V3/Gapic/GroupServiceGapicClient.php index 05475a813410..de9dd9476b96 100644 --- a/src/Monitoring/V3/Gapic/GroupServiceGapicClient.php +++ b/src/Monitoring/V3/Gapic/GroupServiceGapicClient.php @@ -33,10 +33,10 @@ use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; -use Google\GAX\GrpcConstants; use Google\GAX\GrpcCredentialsHelper; use Google\GAX\PageStreamingDescriptor; use Google\GAX\PathTemplate; +use Google\GAX\ValidationException; use Google\Monitoring\V3\CreateGroupRequest; use Google\Monitoring\V3\DeleteGroupRequest; use Google\Monitoring\V3\GetGroupRequest; @@ -71,7 +71,7 @@ * ``` * try { * $groupServiceClient = new GroupServiceClient(); - * $formattedName = GroupServiceClient::formatProjectName("[PROJECT]"); + * $formattedName = $groupServiceClient->projectName("[PROJECT]"); * // Iterate through all elements * $pagedResponse = $groupServiceClient->listGroups($formattedName); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -92,8 +92,8 @@ * * Many parameters require resource names to be formatted in a particular way. To assist * with these names, this class includes a format method for each type of name, and additionally - * a parse method to extract the individual identifiers contained within names that are - * returned. + * a parseName method to extract the individual identifiers contained within formatted names + * that are returned by the API. * * @experimental */ @@ -126,6 +126,9 @@ class GroupServiceGapicClient private static $projectNameTemplate; private static $groupNameTemplate; + private static $pathTemplateList = null; + private static $gapicVersion = null; + private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; protected $groupServiceStub; @@ -133,82 +136,6 @@ class GroupServiceGapicClient private $defaultCallSettings; private $descriptors; - /** - * Formats a string containing the fully-qualified path to represent - * a project resource. - * - * @param string $project - * - * @return string The formatted project resource. - * @experimental - */ - public static function formatProjectName($project) - { - return self::getProjectNameTemplate()->render([ - 'project' => $project, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent - * a group resource. - * - * @param string $project - * @param string $group - * - * @return string The formatted group resource. - * @experimental - */ - public static function formatGroupName($project, $group) - { - return self::getGroupNameTemplate()->render([ - 'project' => $project, - 'group' => $group, - ]); - } - - /** - * Parses the project from the given fully-qualified path which - * represents a project resource. - * - * @param string $projectName The fully-qualified project resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromProjectName($projectName) - { - return self::getProjectNameTemplate()->match($projectName)['project']; - } - - /** - * Parses the project from the given fully-qualified path which - * represents a group resource. - * - * @param string $groupName The fully-qualified group resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromGroupName($groupName) - { - return self::getGroupNameTemplate()->match($groupName)['project']; - } - - /** - * Parses the group from the given fully-qualified path which - * represents a group resource. - * - * @param string $groupName The fully-qualified group resource. - * - * @return string The extracted group value. - * @experimental - */ - public static function parseGroupFromGroupName($groupName) - { - return self::getGroupNameTemplate()->match($groupName)['group']; - } - private static function getProjectNameTemplate() { if (self::$projectNameTemplate == null) { @@ -226,7 +153,17 @@ private static function getGroupNameTemplate() return self::$groupNameTemplate; } + private static function getPathTemplateList() + { + if (self::$pathTemplateList == null) { + self::$pathTemplateList = [ + self::getProjectNameTemplate(), + self::getGroupNameTemplate(), + ]; + } + return self::$pathTemplateList; + } private static function getPageStreamingDescriptors() { $listGroupsPageStreamingDescriptor = @@ -258,13 +195,73 @@ private static function getPageStreamingDescriptors() private static function getGapicVersion() { - if (file_exists(__DIR__.'/../VERSION')) { - return trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - return \Google\Cloud\ServiceBuilder::VERSION; - } else { - return; + if (!self::$gapicVersionLoaded) { + if (file_exists(__DIR__.'/../VERSION')) { + self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } + self::$gapicVersionLoaded = true; + } + + return self::$gapicVersion; + } + + /** + * Formats a string containing the fully-qualified path to represent + * a project resource. + * + * @param string $project + * + * @return string The formatted project resource. + * @experimental + */ + public static function projectName($project) + { + return self::getProjectNameTemplate()->render([ + 'project' => $project, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a group resource. + * + * @param string $project + * @param string $group + * + * @return string The formatted group resource. + * @experimental + */ + public static function groupName($project, $group) + { + return self::getGroupNameTemplate()->render([ + 'project' => $project, + 'group' => $group, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * - projects/{project} + * - projects/{project}/groups/{group}. + * + * @param string $formattedName The formatted name string + * + * @return array An associative array from name component IDs to component values. + * @experimental + */ + public static function parseName($formattedName) + { + foreach (self::getPathTemplateList() as $pathTemplate) { + try { + return $pathTemplate->match($formattedName); + } catch (ValidationException $ex) { + // Swallow the exception to continue trying other path templates + } } + throw new ValidationException("Input did not match any known format. Input: $formattedName"); } /** @@ -291,15 +288,18 @@ private static function getGapicVersion() * A CredentialsLoader object created using the Google\Auth library. * @type array $scopes A string array of scopes to use when acquiring credentials. * Defaults to the scopes for the Stackdriver Monitoring API. + * @type string $clientConfigPath + * Path to a JSON file containing client method configuration, including retry settings. + * Specify this setting to specify the retry behavior of all methods on the client. + * By default this settings points to the default client config file, which is provided + * in the resources folder. * @type array $retryingOverride - * An associative array of string => RetryOptions, where the keys - * are method names (e.g. 'createFoo'), that overrides default retrying - * settings. A value of null indicates that the method in question should - * not retry. - * @type int $timeoutMillis The timeout in milliseconds to use for calls - * that don't use retries. For calls that use retries, - * set the timeout in RetryOptions. - * Default: 30000 (30 seconds) + * An associative array in which the keys are method names (e.g. 'createFoo'), and + * the values are retry settings to use for that method. The retry settings for each + * method can be a {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} + * for example usage. Passing a value of null is equivalent to a value of + * ['retriesEnabled' => false]. * } * @experimental */ @@ -318,6 +318,7 @@ public function __construct($options = []) 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, + 'clientConfigPath' => __DIR__.'/../resources/group_service_client_config.json', ]; $options = array_merge($defaultOptions, $options); @@ -343,15 +344,13 @@ public function __construct($options = []) $this->descriptors[$method]['pageStreamingDescriptor'] = $pageStreamingDescriptor; } - $clientConfigJsonString = file_get_contents(__DIR__.'/../resources/group_service_client_config.json'); + $clientConfigJsonString = file_get_contents($options['clientConfigPath']); $clientConfig = json_decode($clientConfigJsonString, true); $this->defaultCallSettings = CallSettings::load( 'google.monitoring.v3.GroupService', $clientConfig, - $options['retryingOverride'], - GrpcConstants::getStatusCodeNames(), - $options['timeoutMillis'] + $options['retryingOverride'] ); $this->scopes = $options['scopes']; @@ -378,7 +377,7 @@ public function __construct($options = []) * ``` * try { * $groupServiceClient = new GroupServiceClient(); - * $formattedName = GroupServiceClient::formatProjectName("[PROJECT]"); + * $formattedName = $groupServiceClient->projectName("[PROJECT]"); * // Iterate through all elements * $pagedResponse = $groupServiceClient->listGroups($formattedName); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -426,12 +425,11 @@ public function __construct($options = []) * If no page token is specified (the default), the first page * of values will be returned. Any page token used here must have * been generated by a previous call to the API. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\PagedListResponse @@ -482,7 +480,7 @@ public function listGroups($name, $optionalArgs = []) * ``` * try { * $groupServiceClient = new GroupServiceClient(); - * $formattedName = GroupServiceClient::formatGroupName("[PROJECT]", "[GROUP]"); + * $formattedName = $groupServiceClient->groupName("[PROJECT]", "[GROUP]"); * $response = $groupServiceClient->getGroup($formattedName); * } finally { * $groupServiceClient->close(); @@ -494,12 +492,11 @@ public function listGroups($name, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Monitoring\V3\Group @@ -535,7 +532,7 @@ public function getGroup($name, $optionalArgs = []) * ``` * try { * $groupServiceClient = new GroupServiceClient(); - * $formattedName = GroupServiceClient::formatProjectName("[PROJECT]"); + * $formattedName = $groupServiceClient->projectName("[PROJECT]"); * $group = new Group(); * $response = $groupServiceClient->createGroup($formattedName, $group); * } finally { @@ -552,12 +549,11 @@ public function getGroup($name, $optionalArgs = []) * * @type bool $validateOnly * If true, validate this request but do not create the group. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Monitoring\V3\Group @@ -612,12 +608,11 @@ public function createGroup($name, $group, $optionalArgs = []) * * @type bool $validateOnly * If true, validate this request but do not update the existing group. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Monitoring\V3\Group @@ -656,7 +651,7 @@ public function updateGroup($group, $optionalArgs = []) * ``` * try { * $groupServiceClient = new GroupServiceClient(); - * $formattedName = GroupServiceClient::formatGroupName("[PROJECT]", "[GROUP]"); + * $formattedName = $groupServiceClient->groupName("[PROJECT]", "[GROUP]"); * $groupServiceClient->deleteGroup($formattedName); * } finally { * $groupServiceClient->close(); @@ -668,12 +663,11 @@ public function updateGroup($group, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @throws \Google\GAX\ApiException if the remote call fails @@ -707,7 +701,7 @@ public function deleteGroup($name, $optionalArgs = []) * ``` * try { * $groupServiceClient = new GroupServiceClient(); - * $formattedName = GroupServiceClient::formatGroupName("[PROJECT]", "[GROUP]"); + * $formattedName = $groupServiceClient->groupName("[PROJECT]", "[GROUP]"); * // Iterate through all elements * $pagedResponse = $groupServiceClient->listGroupMembers($formattedName); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -753,12 +747,11 @@ public function deleteGroup($name, $optionalArgs = []) * members that were part of the group during the specified interval are * included in the response. If no interval is provided then the group * membership over the last minute is returned. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\PagedListResponse diff --git a/src/Monitoring/V3/Gapic/MetricServiceGapicClient.php b/src/Monitoring/V3/Gapic/MetricServiceGapicClient.php index b50d330297fa..aef92da27616 100644 --- a/src/Monitoring/V3/Gapic/MetricServiceGapicClient.php +++ b/src/Monitoring/V3/Gapic/MetricServiceGapicClient.php @@ -34,10 +34,10 @@ use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; -use Google\GAX\GrpcConstants; use Google\GAX\GrpcCredentialsHelper; use Google\GAX\PageStreamingDescriptor; use Google\GAX\PathTemplate; +use Google\GAX\ValidationException; use Google\Monitoring\V3\Aggregation; use Google\Monitoring\V3\CreateMetricDescriptorRequest; use Google\Monitoring\V3\CreateTimeSeriesRequest; @@ -66,7 +66,7 @@ * ``` * try { * $metricServiceClient = new MetricServiceClient(); - * $formattedName = MetricServiceClient::formatProjectName("[PROJECT]"); + * $formattedName = $metricServiceClient->projectName("[PROJECT]"); * // Iterate through all elements * $pagedResponse = $metricServiceClient->listMonitoredResourceDescriptors($formattedName); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -87,8 +87,8 @@ * * Many parameters require resource names to be formatted in a particular way. To assist * with these names, this class includes a format method for each type of name, and additionally - * a parse method to extract the individual identifiers contained within names that are - * returned. + * a parseName method to extract the individual identifiers contained within formatted names + * that are returned by the API. * * @experimental */ @@ -122,6 +122,9 @@ class MetricServiceGapicClient private static $projectNameTemplate; private static $metricDescriptorNameTemplate; private static $monitoredResourceDescriptorNameTemplate; + private static $pathTemplateList = null; + private static $gapicVersion = null; + private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; protected $metricServiceStub; @@ -129,128 +132,6 @@ class MetricServiceGapicClient private $defaultCallSettings; private $descriptors; - /** - * Formats a string containing the fully-qualified path to represent - * a project resource. - * - * @param string $project - * - * @return string The formatted project resource. - * @experimental - */ - public static function formatProjectName($project) - { - return self::getProjectNameTemplate()->render([ - 'project' => $project, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent - * a metric_descriptor resource. - * - * @param string $project - * @param string $metricDescriptor - * - * @return string The formatted metric_descriptor resource. - * @experimental - */ - public static function formatMetricDescriptorName($project, $metricDescriptor) - { - return self::getMetricDescriptorNameTemplate()->render([ - 'project' => $project, - 'metric_descriptor' => $metricDescriptor, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent - * a monitored_resource_descriptor resource. - * - * @param string $project - * @param string $monitoredResourceDescriptor - * - * @return string The formatted monitored_resource_descriptor resource. - * @experimental - */ - public static function formatMonitoredResourceDescriptorName($project, $monitoredResourceDescriptor) - { - return self::getMonitoredResourceDescriptorNameTemplate()->render([ - 'project' => $project, - 'monitored_resource_descriptor' => $monitoredResourceDescriptor, - ]); - } - - /** - * Parses the project from the given fully-qualified path which - * represents a project resource. - * - * @param string $projectName The fully-qualified project resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromProjectName($projectName) - { - return self::getProjectNameTemplate()->match($projectName)['project']; - } - - /** - * Parses the project from the given fully-qualified path which - * represents a metric_descriptor resource. - * - * @param string $metricDescriptorName The fully-qualified metric_descriptor resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromMetricDescriptorName($metricDescriptorName) - { - return self::getMetricDescriptorNameTemplate()->match($metricDescriptorName)['project']; - } - - /** - * Parses the metric_descriptor from the given fully-qualified path which - * represents a metric_descriptor resource. - * - * @param string $metricDescriptorName The fully-qualified metric_descriptor resource. - * - * @return string The extracted metric_descriptor value. - * @experimental - */ - public static function parseMetricDescriptorFromMetricDescriptorName($metricDescriptorName) - { - return self::getMetricDescriptorNameTemplate()->match($metricDescriptorName)['metric_descriptor']; - } - - /** - * Parses the project from the given fully-qualified path which - * represents a monitored_resource_descriptor resource. - * - * @param string $monitoredResourceDescriptorName The fully-qualified monitored_resource_descriptor resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromMonitoredResourceDescriptorName($monitoredResourceDescriptorName) - { - return self::getMonitoredResourceDescriptorNameTemplate()->match($monitoredResourceDescriptorName)['project']; - } - - /** - * Parses the monitored_resource_descriptor from the given fully-qualified path which - * represents a monitored_resource_descriptor resource. - * - * @param string $monitoredResourceDescriptorName The fully-qualified monitored_resource_descriptor resource. - * - * @return string The extracted monitored_resource_descriptor value. - * @experimental - */ - public static function parseMonitoredResourceDescriptorFromMonitoredResourceDescriptorName($monitoredResourceDescriptorName) - { - return self::getMonitoredResourceDescriptorNameTemplate()->match($monitoredResourceDescriptorName)['monitored_resource_descriptor']; - } - private static function getProjectNameTemplate() { if (self::$projectNameTemplate == null) { @@ -277,7 +158,18 @@ private static function getMonitoredResourceDescriptorNameTemplate() return self::$monitoredResourceDescriptorNameTemplate; } + private static function getPathTemplateList() + { + if (self::$pathTemplateList == null) { + self::$pathTemplateList = [ + self::getProjectNameTemplate(), + self::getMetricDescriptorNameTemplate(), + self::getMonitoredResourceDescriptorNameTemplate(), + ]; + } + return self::$pathTemplateList; + } private static function getPageStreamingDescriptors() { $listMonitoredResourceDescriptorsPageStreamingDescriptor = @@ -319,13 +211,92 @@ private static function getPageStreamingDescriptors() private static function getGapicVersion() { - if (file_exists(__DIR__.'/../VERSION')) { - return trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - return \Google\Cloud\ServiceBuilder::VERSION; - } else { - return; + if (!self::$gapicVersionLoaded) { + if (file_exists(__DIR__.'/../VERSION')) { + self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } + self::$gapicVersionLoaded = true; + } + + return self::$gapicVersion; + } + + /** + * Formats a string containing the fully-qualified path to represent + * a project resource. + * + * @param string $project + * + * @return string The formatted project resource. + * @experimental + */ + public static function projectName($project) + { + return self::getProjectNameTemplate()->render([ + 'project' => $project, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a metric_descriptor resource. + * + * @param string $project + * @param string $metricDescriptor + * + * @return string The formatted metric_descriptor resource. + * @experimental + */ + public static function metricDescriptorName($project, $metricDescriptor) + { + return self::getMetricDescriptorNameTemplate()->render([ + 'project' => $project, + 'metric_descriptor' => $metricDescriptor, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a monitored_resource_descriptor resource. + * + * @param string $project + * @param string $monitoredResourceDescriptor + * + * @return string The formatted monitored_resource_descriptor resource. + * @experimental + */ + public static function monitoredResourceDescriptorName($project, $monitoredResourceDescriptor) + { + return self::getMonitoredResourceDescriptorNameTemplate()->render([ + 'project' => $project, + 'monitored_resource_descriptor' => $monitoredResourceDescriptor, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * - projects/{project} + * - projects/{project}/metricDescriptors/{metric_descriptor=**} + * - projects/{project}/monitoredResourceDescriptors/{monitored_resource_descriptor}. + * + * @param string $formattedName The formatted name string + * + * @return array An associative array from name component IDs to component values. + * @experimental + */ + public static function parseName($formattedName) + { + foreach (self::getPathTemplateList() as $pathTemplate) { + try { + return $pathTemplate->match($formattedName); + } catch (ValidationException $ex) { + // Swallow the exception to continue trying other path templates + } } + throw new ValidationException("Input did not match any known format. Input: $formattedName"); } /** @@ -352,15 +323,18 @@ private static function getGapicVersion() * A CredentialsLoader object created using the Google\Auth library. * @type array $scopes A string array of scopes to use when acquiring credentials. * Defaults to the scopes for the Stackdriver Monitoring API. + * @type string $clientConfigPath + * Path to a JSON file containing client method configuration, including retry settings. + * Specify this setting to specify the retry behavior of all methods on the client. + * By default this settings points to the default client config file, which is provided + * in the resources folder. * @type array $retryingOverride - * An associative array of string => RetryOptions, where the keys - * are method names (e.g. 'createFoo'), that overrides default retrying - * settings. A value of null indicates that the method in question should - * not retry. - * @type int $timeoutMillis The timeout in milliseconds to use for calls - * that don't use retries. For calls that use retries, - * set the timeout in RetryOptions. - * Default: 30000 (30 seconds) + * An associative array in which the keys are method names (e.g. 'createFoo'), and + * the values are retry settings to use for that method. The retry settings for each + * method can be a {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} + * for example usage. Passing a value of null is equivalent to a value of + * ['retriesEnabled' => false]. * } * @experimental */ @@ -379,6 +353,7 @@ public function __construct($options = []) 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, + 'clientConfigPath' => __DIR__.'/../resources/metric_service_client_config.json', ]; $options = array_merge($defaultOptions, $options); @@ -406,15 +381,13 @@ public function __construct($options = []) $this->descriptors[$method]['pageStreamingDescriptor'] = $pageStreamingDescriptor; } - $clientConfigJsonString = file_get_contents(__DIR__.'/../resources/metric_service_client_config.json'); + $clientConfigJsonString = file_get_contents($options['clientConfigPath']); $clientConfig = json_decode($clientConfigJsonString, true); $this->defaultCallSettings = CallSettings::load( 'google.monitoring.v3.MetricService', $clientConfig, - $options['retryingOverride'], - GrpcConstants::getStatusCodeNames(), - $options['timeoutMillis'] + $options['retryingOverride'] ); $this->scopes = $options['scopes']; @@ -441,7 +414,7 @@ public function __construct($options = []) * ``` * try { * $metricServiceClient = new MetricServiceClient(); - * $formattedName = MetricServiceClient::formatProjectName("[PROJECT]"); + * $formattedName = $metricServiceClient->projectName("[PROJECT]"); * // Iterate through all elements * $pagedResponse = $metricServiceClient->listMonitoredResourceDescriptors($formattedName); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -482,12 +455,11 @@ public function __construct($options = []) * If no page token is specified (the default), the first page * of values will be returned. Any page token used here must have * been generated by a previous call to the API. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\PagedListResponse @@ -532,7 +504,7 @@ public function listMonitoredResourceDescriptors($name, $optionalArgs = []) * ``` * try { * $metricServiceClient = new MetricServiceClient(); - * $formattedName = MetricServiceClient::formatMonitoredResourceDescriptorName("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]"); + * $formattedName = $metricServiceClient->monitoredResourceDescriptorName("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]"); * $response = $metricServiceClient->getMonitoredResourceDescriptor($formattedName); * } finally { * $metricServiceClient->close(); @@ -546,12 +518,11 @@ public function listMonitoredResourceDescriptors($name, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Api\MonitoredResourceDescriptor @@ -587,7 +558,7 @@ public function getMonitoredResourceDescriptor($name, $optionalArgs = []) * ``` * try { * $metricServiceClient = new MetricServiceClient(); - * $formattedName = MetricServiceClient::formatProjectName("[PROJECT]"); + * $formattedName = $metricServiceClient->projectName("[PROJECT]"); * // Iterate through all elements * $pagedResponse = $metricServiceClient->listMetricDescriptors($formattedName); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -629,12 +600,11 @@ public function getMonitoredResourceDescriptor($name, $optionalArgs = []) * If no page token is specified (the default), the first page * of values will be returned. Any page token used here must have * been generated by a previous call to the API. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\PagedListResponse @@ -679,7 +649,7 @@ public function listMetricDescriptors($name, $optionalArgs = []) * ``` * try { * $metricServiceClient = new MetricServiceClient(); - * $formattedName = MetricServiceClient::formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]"); + * $formattedName = $metricServiceClient->metricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]"); * $response = $metricServiceClient->getMetricDescriptor($formattedName); * } finally { * $metricServiceClient->close(); @@ -693,12 +663,11 @@ public function listMetricDescriptors($name, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Api\MetricDescriptor @@ -736,7 +705,7 @@ public function getMetricDescriptor($name, $optionalArgs = []) * ``` * try { * $metricServiceClient = new MetricServiceClient(); - * $formattedName = MetricServiceClient::formatProjectName("[PROJECT]"); + * $formattedName = $metricServiceClient->projectName("[PROJECT]"); * $metricDescriptor = new MetricDescriptor(); * $response = $metricServiceClient->createMetricDescriptor($formattedName, $metricDescriptor); * } finally { @@ -751,12 +720,11 @@ public function getMetricDescriptor($name, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Api\MetricDescriptor @@ -794,7 +762,7 @@ public function createMetricDescriptor($name, $metricDescriptor, $optionalArgs = * ``` * try { * $metricServiceClient = new MetricServiceClient(); - * $formattedName = MetricServiceClient::formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]"); + * $formattedName = $metricServiceClient->metricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]"); * $metricServiceClient->deleteMetricDescriptor($formattedName); * } finally { * $metricServiceClient->close(); @@ -808,12 +776,11 @@ public function createMetricDescriptor($name, $metricDescriptor, $optionalArgs = * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @throws \Google\GAX\ApiException if the remote call fails @@ -847,7 +814,7 @@ public function deleteMetricDescriptor($name, $optionalArgs = []) * ``` * try { * $metricServiceClient = new MetricServiceClient(); - * $formattedName = MetricServiceClient::formatProjectName("[PROJECT]"); + * $formattedName = $metricServiceClient->projectName("[PROJECT]"); * $filter = ""; * $interval = new TimeInterval(); * $view = TimeSeriesView::FULL; @@ -903,12 +870,11 @@ public function deleteMetricDescriptor($name, $optionalArgs = []) * If no page token is specified (the default), the first page * of values will be returned. Any page token used here must have * been generated by a previous call to the API. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\PagedListResponse @@ -962,7 +928,7 @@ public function listTimeSeries($name, $filter, $interval, $view, $optionalArgs = * ``` * try { * $metricServiceClient = new MetricServiceClient(); - * $formattedName = MetricServiceClient::formatProjectName("[PROJECT]"); + * $formattedName = $metricServiceClient->projectName("[PROJECT]"); * $timeSeries = []; * $metricServiceClient->createTimeSeries($formattedName, $timeSeries); * } finally { @@ -980,12 +946,11 @@ public function listTimeSeries($name, $filter, $interval, $view, $optionalArgs = * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @throws \Google\GAX\ApiException if the remote call fails diff --git a/src/PubSub/V1/Gapic/PublisherGapicClient.php b/src/PubSub/V1/Gapic/PublisherGapicClient.php index 5add6e38230c..c74acdd16611 100644 --- a/src/PubSub/V1/Gapic/PublisherGapicClient.php +++ b/src/PubSub/V1/Gapic/PublisherGapicClient.php @@ -33,10 +33,10 @@ use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; -use Google\GAX\GrpcConstants; use Google\GAX\GrpcCredentialsHelper; use Google\GAX\PageStreamingDescriptor; use Google\GAX\PathTemplate; +use Google\GAX\ValidationException; use Google\Iam\V1\GetIamPolicyRequest; use Google\Iam\V1\IAMPolicyGrpcClient; use Google\Iam\V1\Policy; @@ -65,7 +65,7 @@ * ``` * try { * $publisherClient = new PublisherClient(); - * $formattedName = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]"); + * $formattedName = $publisherClient->topicName("[PROJECT]", "[TOPIC]"); * $response = $publisherClient->createTopic($formattedName); * } finally { * $publisherClient->close(); @@ -74,8 +74,8 @@ * * Many parameters require resource names to be formatted in a particular way. To assist * with these names, this class includes a format method for each type of name, and additionally - * a parse method to extract the individual identifiers contained within names that are - * returned. + * a parseName method to extract the individual identifiers contained within formatted names + * that are returned by the API. * * @experimental */ @@ -108,6 +108,9 @@ class PublisherGapicClient private static $projectNameTemplate; private static $topicNameTemplate; + private static $pathTemplateList = null; + private static $gapicVersion = null; + private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; protected $iamPolicyStub; @@ -116,82 +119,6 @@ class PublisherGapicClient private $defaultCallSettings; private $descriptors; - /** - * Formats a string containing the fully-qualified path to represent - * a project resource. - * - * @param string $project - * - * @return string The formatted project resource. - * @experimental - */ - public static function formatProjectName($project) - { - return self::getProjectNameTemplate()->render([ - 'project' => $project, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent - * a topic resource. - * - * @param string $project - * @param string $topic - * - * @return string The formatted topic resource. - * @experimental - */ - public static function formatTopicName($project, $topic) - { - return self::getTopicNameTemplate()->render([ - 'project' => $project, - 'topic' => $topic, - ]); - } - - /** - * Parses the project from the given fully-qualified path which - * represents a project resource. - * - * @param string $projectName The fully-qualified project resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromProjectName($projectName) - { - return self::getProjectNameTemplate()->match($projectName)['project']; - } - - /** - * Parses the project from the given fully-qualified path which - * represents a topic resource. - * - * @param string $topicName The fully-qualified topic resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromTopicName($topicName) - { - return self::getTopicNameTemplate()->match($topicName)['project']; - } - - /** - * Parses the topic from the given fully-qualified path which - * represents a topic resource. - * - * @param string $topicName The fully-qualified topic resource. - * - * @return string The extracted topic value. - * @experimental - */ - public static function parseTopicFromTopicName($topicName) - { - return self::getTopicNameTemplate()->match($topicName)['topic']; - } - private static function getProjectNameTemplate() { if (self::$projectNameTemplate == null) { @@ -209,7 +136,17 @@ private static function getTopicNameTemplate() return self::$topicNameTemplate; } + private static function getPathTemplateList() + { + if (self::$pathTemplateList == null) { + self::$pathTemplateList = [ + self::getProjectNameTemplate(), + self::getTopicNameTemplate(), + ]; + } + return self::$pathTemplateList; + } private static function getPageStreamingDescriptors() { $listTopicsPageStreamingDescriptor = @@ -241,13 +178,73 @@ private static function getPageStreamingDescriptors() private static function getGapicVersion() { - if (file_exists(__DIR__.'/../VERSION')) { - return trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - return \Google\Cloud\ServiceBuilder::VERSION; - } else { - return; + if (!self::$gapicVersionLoaded) { + if (file_exists(__DIR__.'/../VERSION')) { + self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } + self::$gapicVersionLoaded = true; + } + + return self::$gapicVersion; + } + + /** + * Formats a string containing the fully-qualified path to represent + * a project resource. + * + * @param string $project + * + * @return string The formatted project resource. + * @experimental + */ + public static function projectName($project) + { + return self::getProjectNameTemplate()->render([ + 'project' => $project, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a topic resource. + * + * @param string $project + * @param string $topic + * + * @return string The formatted topic resource. + * @experimental + */ + public static function topicName($project, $topic) + { + return self::getTopicNameTemplate()->render([ + 'project' => $project, + 'topic' => $topic, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * - projects/{project} + * - projects/{project}/topics/{topic}. + * + * @param string $formattedName The formatted name string + * + * @return array An associative array from name component IDs to component values. + * @experimental + */ + public static function parseName($formattedName) + { + foreach (self::getPathTemplateList() as $pathTemplate) { + try { + return $pathTemplate->match($formattedName); + } catch (ValidationException $ex) { + // Swallow the exception to continue trying other path templates + } } + throw new ValidationException("Input did not match any known format. Input: $formattedName"); } /** @@ -274,15 +271,18 @@ private static function getGapicVersion() * A CredentialsLoader object created using the Google\Auth library. * @type array $scopes A string array of scopes to use when acquiring credentials. * Defaults to the scopes for the Google Cloud Pub/Sub API. + * @type string $clientConfigPath + * Path to a JSON file containing client method configuration, including retry settings. + * Specify this setting to specify the retry behavior of all methods on the client. + * By default this settings points to the default client config file, which is provided + * in the resources folder. * @type array $retryingOverride - * An associative array of string => RetryOptions, where the keys - * are method names (e.g. 'createFoo'), that overrides default retrying - * settings. A value of null indicates that the method in question should - * not retry. - * @type int $timeoutMillis The timeout in milliseconds to use for calls - * that don't use retries. For calls that use retries, - * set the timeout in RetryOptions. - * Default: 30000 (30 seconds) + * An associative array in which the keys are method names (e.g. 'createFoo'), and + * the values are retry settings to use for that method. The retry settings for each + * method can be a {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} + * for example usage. Passing a value of null is equivalent to a value of + * ['retriesEnabled' => false]. * } * @experimental */ @@ -299,6 +299,7 @@ public function __construct($options = []) 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, + 'clientConfigPath' => __DIR__.'/../resources/publisher_client_config.json', ]; $options = array_merge($defaultOptions, $options); @@ -327,15 +328,13 @@ public function __construct($options = []) $this->descriptors[$method]['pageStreamingDescriptor'] = $pageStreamingDescriptor; } - $clientConfigJsonString = file_get_contents(__DIR__.'/../resources/publisher_client_config.json'); + $clientConfigJsonString = file_get_contents($options['clientConfigPath']); $clientConfig = json_decode($clientConfigJsonString, true); $this->defaultCallSettings = CallSettings::load( 'google.pubsub.v1.Publisher', $clientConfig, - $options['retryingOverride'], - GrpcConstants::getStatusCodeNames(), - $options['timeoutMillis'] + $options['retryingOverride'] ); $this->scopes = $options['scopes']; @@ -369,7 +368,7 @@ public function __construct($options = []) * ``` * try { * $publisherClient = new PublisherClient(); - * $formattedName = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]"); + * $formattedName = $publisherClient->topicName("[PROJECT]", "[TOPIC]"); * $response = $publisherClient->createTopic($formattedName); * } finally { * $publisherClient->close(); @@ -387,12 +386,11 @@ public function __construct($options = []) * * @type array $labels * User labels. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Pubsub\V1\Topic @@ -433,7 +431,7 @@ public function createTopic($name, $optionalArgs = []) * ``` * try { * $publisherClient = new PublisherClient(); - * $formattedTopic = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]"); + * $formattedTopic = $publisherClient->topicName("[PROJECT]", "[TOPIC]"); * $data = ""; * $messagesElement = new PubsubMessage(); * $messagesElement->setData($data); @@ -450,12 +448,11 @@ public function createTopic($name, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Pubsub\V1\PublishResponse @@ -492,7 +489,7 @@ public function publish($topic, $messages, $optionalArgs = []) * ``` * try { * $publisherClient = new PublisherClient(); - * $formattedTopic = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]"); + * $formattedTopic = $publisherClient->topicName("[PROJECT]", "[TOPIC]"); * $response = $publisherClient->getTopic($formattedTopic); * } finally { * $publisherClient->close(); @@ -504,12 +501,11 @@ public function publish($topic, $messages, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Pubsub\V1\Topic @@ -545,7 +541,7 @@ public function getTopic($topic, $optionalArgs = []) * ``` * try { * $publisherClient = new PublisherClient(); - * $formattedProject = PublisherClient::formatProjectName("[PROJECT]"); + * $formattedProject = $publisherClient->projectName("[PROJECT]"); * // Iterate through all elements * $pagedResponse = $publisherClient->listTopics($formattedProject); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -578,12 +574,11 @@ public function getTopic($topic, $optionalArgs = []) * If no page token is specified (the default), the first page * of values will be returned. Any page token used here must have * been generated by a previous call to the API. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\PagedListResponse @@ -625,7 +620,7 @@ public function listTopics($project, $optionalArgs = []) * ``` * try { * $publisherClient = new PublisherClient(); - * $formattedTopic = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]"); + * $formattedTopic = $publisherClient->topicName("[PROJECT]", "[TOPIC]"); * // Iterate through all elements * $pagedResponse = $publisherClient->listTopicSubscriptions($formattedTopic); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -658,12 +653,11 @@ public function listTopics($project, $optionalArgs = []) * If no page token is specified (the default), the first page * of values will be returned. Any page token used here must have * been generated by a previous call to the API. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\PagedListResponse @@ -709,7 +703,7 @@ public function listTopicSubscriptions($topic, $optionalArgs = []) * ``` * try { * $publisherClient = new PublisherClient(); - * $formattedTopic = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]"); + * $formattedTopic = $publisherClient->topicName("[PROJECT]", "[TOPIC]"); * $publisherClient->deleteTopic($formattedTopic); * } finally { * $publisherClient->close(); @@ -721,12 +715,11 @@ public function listTopicSubscriptions($topic, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @throws \Google\GAX\ApiException if the remote call fails @@ -761,7 +754,7 @@ public function deleteTopic($topic, $optionalArgs = []) * ``` * try { * $publisherClient = new PublisherClient(); - * $formattedResource = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]"); + * $formattedResource = $publisherClient->topicName("[PROJECT]", "[TOPIC]"); * $policy = new Policy(); * $response = $publisherClient->setIamPolicy($formattedResource, $policy); * } finally { @@ -779,12 +772,11 @@ public function deleteTopic($topic, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Iam\V1\Policy @@ -823,7 +815,7 @@ public function setIamPolicy($resource, $policy, $optionalArgs = []) * ``` * try { * $publisherClient = new PublisherClient(); - * $formattedResource = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]"); + * $formattedResource = $publisherClient->topicName("[PROJECT]", "[TOPIC]"); * $response = $publisherClient->getIamPolicy($formattedResource); * } finally { * $publisherClient->close(); @@ -836,12 +828,11 @@ public function setIamPolicy($resource, $policy, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Iam\V1\Policy @@ -879,7 +870,7 @@ public function getIamPolicy($resource, $optionalArgs = []) * ``` * try { * $publisherClient = new PublisherClient(); - * $formattedResource = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]"); + * $formattedResource = $publisherClient->topicName("[PROJECT]", "[TOPIC]"); * $permissions = []; * $response = $publisherClient->testIamPermissions($formattedResource, $permissions); * } finally { @@ -897,12 +888,11 @@ public function getIamPolicy($resource, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Iam\V1\TestIamPermissionsResponse diff --git a/src/PubSub/V1/Gapic/SubscriberGapicClient.php b/src/PubSub/V1/Gapic/SubscriberGapicClient.php index 52181dca86ea..1c8c172bf482 100644 --- a/src/PubSub/V1/Gapic/SubscriberGapicClient.php +++ b/src/PubSub/V1/Gapic/SubscriberGapicClient.php @@ -33,17 +33,16 @@ use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; -use Google\GAX\GrpcConstants; use Google\GAX\GrpcCredentialsHelper; use Google\GAX\PageStreamingDescriptor; use Google\GAX\PathTemplate; +use Google\GAX\ValidationException; use Google\Iam\V1\GetIamPolicyRequest; use Google\Iam\V1\IAMPolicyGrpcClient; use Google\Iam\V1\Policy; use Google\Iam\V1\SetIamPolicyRequest; use Google\Iam\V1\TestIamPermissionsRequest; use Google\Protobuf\Duration; -use Google\Protobuf\FieldMask; use Google\Protobuf\Timestamp; use Google\Pubsub\V1\AcknowledgeRequest; use Google\Pubsub\V1\CreateSnapshotRequest; @@ -60,7 +59,6 @@ use Google\Pubsub\V1\StreamingPullRequest; use Google\Pubsub\V1\SubscriberGrpcClient; use Google\Pubsub\V1\Subscription; -use Google\Pubsub\V1\UpdateSubscriptionRequest; /** * Service Description: The service that an application uses to manipulate subscriptions and to @@ -76,8 +74,8 @@ * ``` * try { * $subscriberClient = new SubscriberClient(); - * $formattedName = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); - * $formattedTopic = SubscriberClient::formatTopicName("[PROJECT]", "[TOPIC]"); + * $formattedName = $subscriberClient->subscriptionName("[PROJECT]", "[SUBSCRIPTION]"); + * $formattedTopic = $subscriberClient->topicName("[PROJECT]", "[TOPIC]"); * $response = $subscriberClient->createSubscription($formattedName, $formattedTopic); * } finally { * $subscriberClient->close(); @@ -86,8 +84,8 @@ * * Many parameters require resource names to be formatted in a particular way. To assist * with these names, this class includes a format method for each type of name, and additionally - * a parse method to extract the individual identifiers contained within names that are - * returned. + * a parseName method to extract the individual identifiers contained within formatted names + * that are returned by the API. * * @experimental */ @@ -122,6 +120,9 @@ class SubscriberGapicClient private static $snapshotNameTemplate; private static $subscriptionNameTemplate; private static $topicNameTemplate; + private static $pathTemplateList = null; + private static $gapicVersion = null; + private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; protected $iamPolicyStub; @@ -130,174 +131,6 @@ class SubscriberGapicClient private $defaultCallSettings; private $descriptors; - /** - * Formats a string containing the fully-qualified path to represent - * a project resource. - * - * @param string $project - * - * @return string The formatted project resource. - * @experimental - */ - public static function formatProjectName($project) - { - return self::getProjectNameTemplate()->render([ - 'project' => $project, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent - * a snapshot resource. - * - * @param string $project - * @param string $snapshot - * - * @return string The formatted snapshot resource. - * @experimental - */ - public static function formatSnapshotName($project, $snapshot) - { - return self::getSnapshotNameTemplate()->render([ - 'project' => $project, - 'snapshot' => $snapshot, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent - * a subscription resource. - * - * @param string $project - * @param string $subscription - * - * @return string The formatted subscription resource. - * @experimental - */ - public static function formatSubscriptionName($project, $subscription) - { - return self::getSubscriptionNameTemplate()->render([ - 'project' => $project, - 'subscription' => $subscription, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent - * a topic resource. - * - * @param string $project - * @param string $topic - * - * @return string The formatted topic resource. - * @experimental - */ - public static function formatTopicName($project, $topic) - { - return self::getTopicNameTemplate()->render([ - 'project' => $project, - 'topic' => $topic, - ]); - } - - /** - * Parses the project from the given fully-qualified path which - * represents a project resource. - * - * @param string $projectName The fully-qualified project resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromProjectName($projectName) - { - return self::getProjectNameTemplate()->match($projectName)['project']; - } - - /** - * Parses the project from the given fully-qualified path which - * represents a snapshot resource. - * - * @param string $snapshotName The fully-qualified snapshot resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromSnapshotName($snapshotName) - { - return self::getSnapshotNameTemplate()->match($snapshotName)['project']; - } - - /** - * Parses the snapshot from the given fully-qualified path which - * represents a snapshot resource. - * - * @param string $snapshotName The fully-qualified snapshot resource. - * - * @return string The extracted snapshot value. - * @experimental - */ - public static function parseSnapshotFromSnapshotName($snapshotName) - { - return self::getSnapshotNameTemplate()->match($snapshotName)['snapshot']; - } - - /** - * Parses the project from the given fully-qualified path which - * represents a subscription resource. - * - * @param string $subscriptionName The fully-qualified subscription resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromSubscriptionName($subscriptionName) - { - return self::getSubscriptionNameTemplate()->match($subscriptionName)['project']; - } - - /** - * Parses the subscription from the given fully-qualified path which - * represents a subscription resource. - * - * @param string $subscriptionName The fully-qualified subscription resource. - * - * @return string The extracted subscription value. - * @experimental - */ - public static function parseSubscriptionFromSubscriptionName($subscriptionName) - { - return self::getSubscriptionNameTemplate()->match($subscriptionName)['subscription']; - } - - /** - * Parses the project from the given fully-qualified path which - * represents a topic resource. - * - * @param string $topicName The fully-qualified topic resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromTopicName($topicName) - { - return self::getTopicNameTemplate()->match($topicName)['project']; - } - - /** - * Parses the topic from the given fully-qualified path which - * represents a topic resource. - * - * @param string $topicName The fully-qualified topic resource. - * - * @return string The extracted topic value. - * @experimental - */ - public static function parseTopicFromTopicName($topicName) - { - return self::getTopicNameTemplate()->match($topicName)['topic']; - } - private static function getProjectNameTemplate() { if (self::$projectNameTemplate == null) { @@ -333,7 +166,19 @@ private static function getTopicNameTemplate() return self::$topicNameTemplate; } + private static function getPathTemplateList() + { + if (self::$pathTemplateList == null) { + self::$pathTemplateList = [ + self::getProjectNameTemplate(), + self::getSnapshotNameTemplate(), + self::getSubscriptionNameTemplate(), + self::getTopicNameTemplate(), + ]; + } + return self::$pathTemplateList; + } private static function getPageStreamingDescriptors() { $listSubscriptionsPageStreamingDescriptor = @@ -375,13 +220,111 @@ private static function getGrpcStreamingDescriptors() private static function getGapicVersion() { - if (file_exists(__DIR__.'/../VERSION')) { - return trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - return \Google\Cloud\ServiceBuilder::VERSION; - } else { - return; + if (!self::$gapicVersionLoaded) { + if (file_exists(__DIR__.'/../VERSION')) { + self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } + self::$gapicVersionLoaded = true; + } + + return self::$gapicVersion; + } + + /** + * Formats a string containing the fully-qualified path to represent + * a project resource. + * + * @param string $project + * + * @return string The formatted project resource. + * @experimental + */ + public static function projectName($project) + { + return self::getProjectNameTemplate()->render([ + 'project' => $project, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a snapshot resource. + * + * @param string $project + * @param string $snapshot + * + * @return string The formatted snapshot resource. + * @experimental + */ + public static function snapshotName($project, $snapshot) + { + return self::getSnapshotNameTemplate()->render([ + 'project' => $project, + 'snapshot' => $snapshot, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a subscription resource. + * + * @param string $project + * @param string $subscription + * + * @return string The formatted subscription resource. + * @experimental + */ + public static function subscriptionName($project, $subscription) + { + return self::getSubscriptionNameTemplate()->render([ + 'project' => $project, + 'subscription' => $subscription, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a topic resource. + * + * @param string $project + * @param string $topic + * + * @return string The formatted topic resource. + * @experimental + */ + public static function topicName($project, $topic) + { + return self::getTopicNameTemplate()->render([ + 'project' => $project, + 'topic' => $topic, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * - projects/{project} + * - projects/{project}/snapshots/{snapshot} + * - projects/{project}/subscriptions/{subscription} + * - projects/{project}/topics/{topic}. + * + * @param string $formattedName The formatted name string + * + * @return array An associative array from name component IDs to component values. + * @experimental + */ + public static function parseName($formattedName) + { + foreach (self::getPathTemplateList() as $pathTemplate) { + try { + return $pathTemplate->match($formattedName); + } catch (ValidationException $ex) { + // Swallow the exception to continue trying other path templates + } } + throw new ValidationException("Input did not match any known format. Input: $formattedName"); } /** @@ -408,15 +351,18 @@ private static function getGapicVersion() * A CredentialsLoader object created using the Google\Auth library. * @type array $scopes A string array of scopes to use when acquiring credentials. * Defaults to the scopes for the Google Cloud Pub/Sub API. + * @type string $clientConfigPath + * Path to a JSON file containing client method configuration, including retry settings. + * Specify this setting to specify the retry behavior of all methods on the client. + * By default this settings points to the default client config file, which is provided + * in the resources folder. * @type array $retryingOverride - * An associative array of string => RetryOptions, where the keys - * are method names (e.g. 'createFoo'), that overrides default retrying - * settings. A value of null indicates that the method in question should - * not retry. - * @type int $timeoutMillis The timeout in milliseconds to use for calls - * that don't use retries. For calls that use retries, - * set the timeout in RetryOptions. - * Default: 30000 (30 seconds) + * An associative array in which the keys are method names (e.g. 'createFoo'), and + * the values are retry settings to use for that method. The retry settings for each + * method can be a {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} + * for example usage. Passing a value of null is equivalent to a value of + * ['retriesEnabled' => false]. * } * @experimental */ @@ -433,6 +379,7 @@ public function __construct($options = []) 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, + 'clientConfigPath' => __DIR__.'/../resources/subscriber_client_config.json', ]; $options = array_merge($defaultOptions, $options); @@ -448,7 +395,6 @@ public function __construct($options = []) $this->descriptors = [ 'createSubscription' => $defaultDescriptors, 'getSubscription' => $defaultDescriptors, - 'updateSubscription' => $defaultDescriptors, 'listSubscriptions' => $defaultDescriptors, 'deleteSubscription' => $defaultDescriptors, 'modifyAckDeadline' => $defaultDescriptors, @@ -473,15 +419,13 @@ public function __construct($options = []) $this->descriptors[$method]['grpcStreamingDescriptor'] = $grpcStreamingDescriptor; } - $clientConfigJsonString = file_get_contents(__DIR__.'/../resources/subscriber_client_config.json'); + $clientConfigJsonString = file_get_contents($options['clientConfigPath']); $clientConfig = json_decode($clientConfigJsonString, true); $this->defaultCallSettings = CallSettings::load( 'google.pubsub.v1.Subscriber', $clientConfig, - $options['retryingOverride'], - GrpcConstants::getStatusCodeNames(), - $options['timeoutMillis'] + $options['retryingOverride'] ); $this->scopes = $options['scopes']; @@ -524,8 +468,8 @@ public function __construct($options = []) * ``` * try { * $subscriberClient = new SubscriberClient(); - * $formattedName = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); - * $formattedTopic = SubscriberClient::formatTopicName("[PROJECT]", "[TOPIC]"); + * $formattedName = $subscriberClient->subscriptionName("[PROJECT]", "[SUBSCRIPTION]"); + * $formattedTopic = $subscriberClient->topicName("[PROJECT]", "[TOPIC]"); * $response = $subscriberClient->createSubscription($formattedName, $formattedTopic); * } finally { * $subscriberClient->close(); @@ -583,12 +527,11 @@ public function __construct($options = []) * minutes. * @type array $labels * User labels. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Pubsub\V1\Subscription @@ -640,7 +583,7 @@ public function createSubscription($name, $topic, $optionalArgs = []) * ``` * try { * $subscriberClient = new SubscriberClient(); - * $formattedSubscription = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); + * $formattedSubscription = $subscriberClient->subscriptionName("[PROJECT]", "[SUBSCRIPTION]"); * $response = $subscriberClient->getSubscription($formattedSubscription); * } finally { * $subscriberClient->close(); @@ -652,12 +595,11 @@ public function createSubscription($name, $topic, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Pubsub\V1\Subscription @@ -686,67 +628,6 @@ public function getSubscription($subscription, $optionalArgs = []) ['call_credentials_callback' => $this->createCredentialsCallback()]); } - /** - * Updates an existing subscription. Note that certain properties of a - * subscription, such as its topic, are not modifiable. - * NOTE: The style guide requires body: "subscription" instead of body: "*". - * Keeping the latter for internal consistency in V1, however it should be - * corrected in V2. See - * https://cloud.google.com/apis/design/standard_methods#update for details. - * - * Sample code: - * ``` - * try { - * $subscriberClient = new SubscriberClient(); - * $subscription = new Subscription(); - * $updateMask = new FieldMask(); - * $response = $subscriberClient->updateSubscription($subscription, $updateMask); - * } finally { - * $subscriberClient->close(); - * } - * ``` - * - * @param Subscription $subscription The updated subscription object. - * @param FieldMask $updateMask Indicates which fields in the provided subscription to update. - * Must be specified and non-empty. - * @param array $optionalArgs { - * Optional. - * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @return \Google\Pubsub\V1\Subscription - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function updateSubscription($subscription, $updateMask, $optionalArgs = []) - { - $request = new UpdateSubscriptionRequest(); - $request->setSubscription($subscription); - $request->setUpdateMask($updateMask); - - $mergedSettings = $this->defaultCallSettings['updateSubscription']->merge( - new CallSettings($optionalArgs) - ); - $callable = ApiCallable::createApiCall( - $this->subscriberStub, - 'UpdateSubscription', - $mergedSettings, - $this->descriptors['updateSubscription'] - ); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - /** * Lists matching subscriptions. * @@ -754,7 +635,7 @@ public function updateSubscription($subscription, $updateMask, $optionalArgs = [ * ``` * try { * $subscriberClient = new SubscriberClient(); - * $formattedProject = SubscriberClient::formatProjectName("[PROJECT]"); + * $formattedProject = $subscriberClient->projectName("[PROJECT]"); * // Iterate through all elements * $pagedResponse = $subscriberClient->listSubscriptions($formattedProject); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -787,12 +668,11 @@ public function updateSubscription($subscription, $updateMask, $optionalArgs = [ * If no page token is specified (the default), the first page * of values will be returned. Any page token used here must have * been generated by a previous call to the API. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\PagedListResponse @@ -838,7 +718,7 @@ public function listSubscriptions($project, $optionalArgs = []) * ``` * try { * $subscriberClient = new SubscriberClient(); - * $formattedSubscription = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); + * $formattedSubscription = $subscriberClient->subscriptionName("[PROJECT]", "[SUBSCRIPTION]"); * $subscriberClient->deleteSubscription($formattedSubscription); * } finally { * $subscriberClient->close(); @@ -850,12 +730,11 @@ public function listSubscriptions($project, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @throws \Google\GAX\ApiException if the remote call fails @@ -893,7 +772,7 @@ public function deleteSubscription($subscription, $optionalArgs = []) * ``` * try { * $subscriberClient = new SubscriberClient(); - * $formattedSubscription = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); + * $formattedSubscription = $subscriberClient->subscriptionName("[PROJECT]", "[SUBSCRIPTION]"); * $ackIds = []; * $ackDeadlineSeconds = 0; * $subscriberClient->modifyAckDeadline($formattedSubscription, $ackIds, $ackDeadlineSeconds); @@ -915,12 +794,11 @@ public function deleteSubscription($subscription, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @throws \Google\GAX\ApiException if the remote call fails @@ -962,7 +840,7 @@ public function modifyAckDeadline($subscription, $ackIds, $ackDeadlineSeconds, $ * ``` * try { * $subscriberClient = new SubscriberClient(); - * $formattedSubscription = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); + * $formattedSubscription = $subscriberClient->subscriptionName("[PROJECT]", "[SUBSCRIPTION]"); * $ackIds = []; * $subscriberClient->acknowledge($formattedSubscription, $ackIds); * } finally { @@ -977,12 +855,11 @@ public function modifyAckDeadline($subscription, $ackIds, $ackDeadlineSeconds, $ * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @throws \Google\GAX\ApiException if the remote call fails @@ -1020,7 +897,7 @@ public function acknowledge($subscription, $ackIds, $optionalArgs = []) * ``` * try { * $subscriberClient = new SubscriberClient(); - * $formattedSubscription = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); + * $formattedSubscription = $subscriberClient->subscriptionName("[PROJECT]", "[SUBSCRIPTION]"); * $maxMessages = 0; * $response = $subscriberClient->pull($formattedSubscription, $maxMessages); * } finally { @@ -1042,12 +919,11 @@ public function acknowledge($subscription, $ackIds, $optionalArgs = []) * least one message is available, rather than returning no messages. The * client may cancel the request if it does not wish to wait any longer for * the response. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Pubsub\V1\PullResponse @@ -1098,7 +974,7 @@ public function pull($subscription, $maxMessages, $optionalArgs = []) * ``` * try { * $subscriberClient = new SubscriberClient(); - * $formattedSubscription = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); + * $formattedSubscription = $subscriberClient->subscriptionName("[PROJECT]", "[SUBSCRIPTION]"); * $streamAckDeadlineSeconds = 0; * $request = new StreamingPullRequest(); * $request->setSubscription($formattedSubscription); @@ -1148,6 +1024,13 @@ public function pull($subscription, $maxMessages, $optionalArgs = []) */ public function streamingPull($optionalArgs = []) { + if (array_key_exists('timeoutMillis', $optionalArgs)) { + $optionalArgs['retrySettings'] = [ + 'retriesEnabled' => false, + 'noRetriesRpcTimeoutMillis' => $optionalArgs['timeoutMillis'], + ]; + } + $mergedSettings = $this->defaultCallSettings['streamingPull']->merge( new CallSettings($optionalArgs) ); @@ -1176,7 +1059,7 @@ public function streamingPull($optionalArgs = []) * ``` * try { * $subscriberClient = new SubscriberClient(); - * $formattedSubscription = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); + * $formattedSubscription = $subscriberClient->subscriptionName("[PROJECT]", "[SUBSCRIPTION]"); * $pushConfig = new PushConfig(); * $subscriberClient->modifyPushConfig($formattedSubscription, $pushConfig); * } finally { @@ -1195,12 +1078,11 @@ public function streamingPull($optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @throws \Google\GAX\ApiException if the remote call fails @@ -1235,7 +1117,7 @@ public function modifyPushConfig($subscription, $pushConfig, $optionalArgs = []) * ``` * try { * $subscriberClient = new SubscriberClient(); - * $formattedProject = SubscriberClient::formatProjectName("[PROJECT]"); + * $formattedProject = $subscriberClient->projectName("[PROJECT]"); * // Iterate through all elements * $pagedResponse = $subscriberClient->listSnapshots($formattedProject); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -1268,12 +1150,11 @@ public function modifyPushConfig($subscription, $pushConfig, $optionalArgs = []) * If no page token is specified (the default), the first page * of values will be returned. Any page token used here must have * been generated by a previous call to the API. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\PagedListResponse @@ -1324,8 +1205,8 @@ public function listSnapshots($project, $optionalArgs = []) * ``` * try { * $subscriberClient = new SubscriberClient(); - * $formattedName = SubscriberClient::formatSnapshotName("[PROJECT]", "[SNAPSHOT]"); - * $formattedSubscription = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); + * $formattedName = $subscriberClient->snapshotName("[PROJECT]", "[SNAPSHOT]"); + * $formattedSubscription = $subscriberClient->subscriptionName("[PROJECT]", "[SUBSCRIPTION]"); * $response = $subscriberClient->createSnapshot($formattedName, $formattedSubscription); * } finally { * $subscriberClient->close(); @@ -1349,12 +1230,11 @@ public function listSnapshots($project, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Pubsub\V1\Snapshot @@ -1394,7 +1274,7 @@ public function createSnapshot($name, $subscription, $optionalArgs = []) * ``` * try { * $subscriberClient = new SubscriberClient(); - * $formattedSnapshot = SubscriberClient::formatSnapshotName("[PROJECT]", "[SNAPSHOT]"); + * $formattedSnapshot = $subscriberClient->snapshotName("[PROJECT]", "[SNAPSHOT]"); * $subscriberClient->deleteSnapshot($formattedSnapshot); * } finally { * $subscriberClient->close(); @@ -1406,12 +1286,11 @@ public function createSnapshot($name, $subscription, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @throws \Google\GAX\ApiException if the remote call fails @@ -1446,7 +1325,7 @@ public function deleteSnapshot($snapshot, $optionalArgs = []) * ``` * try { * $subscriberClient = new SubscriberClient(); - * $formattedSubscription = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); + * $formattedSubscription = $subscriberClient->subscriptionName("[PROJECT]", "[SUBSCRIPTION]"); * $response = $subscriberClient->seek($formattedSubscription); * } finally { * $subscriberClient->close(); @@ -1473,12 +1352,11 @@ public function deleteSnapshot($snapshot, $optionalArgs = []) * The snapshot to seek to. The snapshot's topic must be the same as that of * the provided subscription. * Format is `projects/{project}/snapshots/{snap}`. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Pubsub\V1\SeekResponse @@ -1521,7 +1399,7 @@ public function seek($subscription, $optionalArgs = []) * ``` * try { * $subscriberClient = new SubscriberClient(); - * $formattedResource = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); + * $formattedResource = $subscriberClient->subscriptionName("[PROJECT]", "[SUBSCRIPTION]"); * $policy = new Policy(); * $response = $subscriberClient->setIamPolicy($formattedResource, $policy); * } finally { @@ -1539,12 +1417,11 @@ public function seek($subscription, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Iam\V1\Policy @@ -1583,7 +1460,7 @@ public function setIamPolicy($resource, $policy, $optionalArgs = []) * ``` * try { * $subscriberClient = new SubscriberClient(); - * $formattedResource = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); + * $formattedResource = $subscriberClient->subscriptionName("[PROJECT]", "[SUBSCRIPTION]"); * $response = $subscriberClient->getIamPolicy($formattedResource); * } finally { * $subscriberClient->close(); @@ -1596,12 +1473,11 @@ public function setIamPolicy($resource, $policy, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Iam\V1\Policy @@ -1639,7 +1515,7 @@ public function getIamPolicy($resource, $optionalArgs = []) * ``` * try { * $subscriberClient = new SubscriberClient(); - * $formattedResource = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); + * $formattedResource = $subscriberClient->subscriptionName("[PROJECT]", "[SUBSCRIPTION]"); * $permissions = []; * $response = $subscriberClient->testIamPermissions($formattedResource, $permissions); * } finally { @@ -1657,12 +1533,11 @@ public function getIamPolicy($resource, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Iam\V1\TestIamPermissionsResponse diff --git a/src/PubSub/V1/resources/publisher_client_config.json b/src/PubSub/V1/resources/publisher_client_config.json index 9fb679cbad27..b1e3be747fd0 100644 --- a/src/PubSub/V1/resources/publisher_client_config.json +++ b/src/PubSub/V1/resources/publisher_client_config.json @@ -43,6 +43,11 @@ "retry_codes_name": "idempotent", "retry_params_name": "default" }, + "UpdateTopic": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, "Publish": { "timeout_millis": 60000, "retry_codes_name": "one_plus_delivery", diff --git a/src/PubSub/V1/resources/subscriber_client_config.json b/src/PubSub/V1/resources/subscriber_client_config.json index 413a57aed9f2..37a5f16fe8f7 100644 --- a/src/PubSub/V1/resources/subscriber_client_config.json +++ b/src/PubSub/V1/resources/subscriber_client_config.json @@ -103,6 +103,11 @@ "retry_codes_name": "idempotent", "retry_params_name": "default" }, + "UpdateSnapshot": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, "DeleteSnapshot": { "timeout_millis": 60000, "retry_codes_name": "idempotent", diff --git a/src/Spanner/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php b/src/Spanner/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php index 1faacf3af681..0e0b65fae666 100644 --- a/src/Spanner/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php +++ b/src/Spanner/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php @@ -33,12 +33,12 @@ use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; -use Google\GAX\GrpcConstants; use Google\GAX\GrpcCredentialsHelper; use Google\GAX\LongRunning\OperationsClient; use Google\GAX\OperationResponse; use Google\GAX\PageStreamingDescriptor; use Google\GAX\PathTemplate; +use Google\GAX\ValidationException; use Google\Iam\V1\GetIamPolicyRequest; use Google\Iam\V1\Policy; use Google\Iam\V1\SetIamPolicyRequest; @@ -71,7 +71,7 @@ * ``` * try { * $databaseAdminClient = new DatabaseAdminClient(); - * $formattedParent = DatabaseAdminClient::formatInstanceName("[PROJECT]", "[INSTANCE]"); + * $formattedParent = $databaseAdminClient->instanceName("[PROJECT]", "[INSTANCE]"); * // Iterate through all elements * $pagedResponse = $databaseAdminClient->listDatabases($formattedParent); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -92,8 +92,8 @@ * * Many parameters require resource names to be formatted in a particular way. To assist * with these names, this class includes a format method for each type of name, and additionally - * a parse method to extract the individual identifiers contained within names that are - * returned. + * a parseName method to extract the individual identifiers contained within formatted names + * that are returned by the API. * * @experimental */ @@ -126,6 +126,9 @@ class DatabaseAdminGapicClient private static $instanceNameTemplate; private static $databaseNameTemplate; + private static $pathTemplateList = null; + private static $gapicVersion = null; + private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; protected $databaseAdminStub; @@ -134,114 +137,6 @@ class DatabaseAdminGapicClient private $descriptors; private $operationsClient; - /** - * Formats a string containing the fully-qualified path to represent - * a instance resource. - * - * @param string $project - * @param string $instance - * - * @return string The formatted instance resource. - * @experimental - */ - public static function formatInstanceName($project, $instance) - { - return self::getInstanceNameTemplate()->render([ - 'project' => $project, - 'instance' => $instance, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent - * a database resource. - * - * @param string $project - * @param string $instance - * @param string $database - * - * @return string The formatted database resource. - * @experimental - */ - public static function formatDatabaseName($project, $instance, $database) - { - return self::getDatabaseNameTemplate()->render([ - 'project' => $project, - 'instance' => $instance, - 'database' => $database, - ]); - } - - /** - * Parses the project from the given fully-qualified path which - * represents a instance resource. - * - * @param string $instanceName The fully-qualified instance resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromInstanceName($instanceName) - { - return self::getInstanceNameTemplate()->match($instanceName)['project']; - } - - /** - * Parses the instance from the given fully-qualified path which - * represents a instance resource. - * - * @param string $instanceName The fully-qualified instance resource. - * - * @return string The extracted instance value. - * @experimental - */ - public static function parseInstanceFromInstanceName($instanceName) - { - return self::getInstanceNameTemplate()->match($instanceName)['instance']; - } - - /** - * Parses the project from the given fully-qualified path which - * represents a database resource. - * - * @param string $databaseName The fully-qualified database resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromDatabaseName($databaseName) - { - return self::getDatabaseNameTemplate()->match($databaseName)['project']; - } - - /** - * Parses the instance from the given fully-qualified path which - * represents a database resource. - * - * @param string $databaseName The fully-qualified database resource. - * - * @return string The extracted instance value. - * @experimental - */ - public static function parseInstanceFromDatabaseName($databaseName) - { - return self::getDatabaseNameTemplate()->match($databaseName)['instance']; - } - - /** - * Parses the database from the given fully-qualified path which - * represents a database resource. - * - * @param string $databaseName The fully-qualified database resource. - * - * @return string The extracted database value. - * @experimental - */ - public static function parseDatabaseFromDatabaseName($databaseName) - { - return self::getDatabaseNameTemplate()->match($databaseName)['database']; - } - private static function getInstanceNameTemplate() { if (self::$instanceNameTemplate == null) { @@ -259,7 +154,17 @@ private static function getDatabaseNameTemplate() return self::$databaseNameTemplate; } + private static function getPathTemplateList() + { + if (self::$pathTemplateList == null) { + self::$pathTemplateList = [ + self::getInstanceNameTemplate(), + self::getDatabaseNameTemplate(), + ]; + } + return self::$pathTemplateList; + } private static function getPageStreamingDescriptors() { $listDatabasesPageStreamingDescriptor = @@ -295,13 +200,77 @@ private static function getLongRunningDescriptors() private static function getGapicVersion() { - if (file_exists(__DIR__.'/../VERSION')) { - return trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - return \Google\Cloud\ServiceBuilder::VERSION; - } else { - return; + if (!self::$gapicVersionLoaded) { + if (file_exists(__DIR__.'/../VERSION')) { + self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } + self::$gapicVersionLoaded = true; + } + + return self::$gapicVersion; + } + + /** + * Formats a string containing the fully-qualified path to represent + * a instance resource. + * + * @param string $project + * @param string $instance + * + * @return string The formatted instance resource. + * @experimental + */ + public static function instanceName($project, $instance) + { + return self::getInstanceNameTemplate()->render([ + 'project' => $project, + 'instance' => $instance, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a database resource. + * + * @param string $project + * @param string $instance + * @param string $database + * + * @return string The formatted database resource. + * @experimental + */ + public static function databaseName($project, $instance, $database) + { + return self::getDatabaseNameTemplate()->render([ + 'project' => $project, + 'instance' => $instance, + 'database' => $database, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * - projects/{project}/instances/{instance} + * - projects/{project}/instances/{instance}/databases/{database}. + * + * @param string $formattedName The formatted name string + * + * @return array An associative array from name component IDs to component values. + * @experimental + */ + public static function parseName($formattedName) + { + foreach (self::getPathTemplateList() as $pathTemplate) { + try { + return $pathTemplate->match($formattedName); + } catch (ValidationException $ex) { + // Swallow the exception to continue trying other path templates + } } + throw new ValidationException("Input did not match any known format. Input: $formattedName"); } /** @@ -366,15 +335,18 @@ public function resumeOperation($operationName, $methodName = null) * A CredentialsLoader object created using the Google\Auth library. * @type array $scopes A string array of scopes to use when acquiring credentials. * Defaults to the scopes for the Cloud Spanner Database Admin API. + * @type string $clientConfigPath + * Path to a JSON file containing client method configuration, including retry settings. + * Specify this setting to specify the retry behavior of all methods on the client. + * By default this settings points to the default client config file, which is provided + * in the resources folder. * @type array $retryingOverride - * An associative array of string => RetryOptions, where the keys - * are method names (e.g. 'createFoo'), that overrides default retrying - * settings. A value of null indicates that the method in question should - * not retry. - * @type int $timeoutMillis The timeout in milliseconds to use for calls - * that don't use retries. For calls that use retries, - * set the timeout in RetryOptions. - * Default: 30000 (30 seconds) + * An associative array in which the keys are method names (e.g. 'createFoo'), and + * the values are retry settings to use for that method. The retry settings for each + * method can be a {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} + * for example usage. Passing a value of null is equivalent to a value of + * ['retriesEnabled' => false]. * } * @experimental */ @@ -391,6 +363,7 @@ public function __construct($options = []) 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, + 'clientConfigPath' => __DIR__.'/../resources/database_admin_client_config.json', ]; $options = array_merge($defaultOptions, $options); @@ -400,6 +373,7 @@ public function __construct($options = []) $operationsClientOptions = $options; unset($operationsClientOptions['timeoutMillis']); unset($operationsClientOptions['retryingOverride']); + unset($operationsClientOptions['clientConfigPath']); $this->operationsClient = new OperationsClient($operationsClientOptions); } @@ -432,15 +406,13 @@ public function __construct($options = []) $this->descriptors[$method]['longRunningDescriptor'] = $longRunningDescriptor + ['operationsClient' => $this->operationsClient]; } - $clientConfigJsonString = file_get_contents(__DIR__.'/../resources/database_admin_client_config.json'); + $clientConfigJsonString = file_get_contents($options['clientConfigPath']); $clientConfig = json_decode($clientConfigJsonString, true); $this->defaultCallSettings = CallSettings::load( 'google.spanner.admin.database.v1.DatabaseAdmin', $clientConfig, - $options['retryingOverride'], - GrpcConstants::getStatusCodeNames(), - $options['timeoutMillis'] + $options['retryingOverride'] ); $this->scopes = $options['scopes']; @@ -467,7 +439,7 @@ public function __construct($options = []) * ``` * try { * $databaseAdminClient = new DatabaseAdminClient(); - * $formattedParent = DatabaseAdminClient::formatInstanceName("[PROJECT]", "[INSTANCE]"); + * $formattedParent = $databaseAdminClient->instanceName("[PROJECT]", "[INSTANCE]"); * // Iterate through all elements * $pagedResponse = $databaseAdminClient->listDatabases($formattedParent); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -500,12 +472,11 @@ public function __construct($options = []) * If no page token is specified (the default), the first page * of values will be returned. Any page token used here must have * been generated by a previous call to the API. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\PagedListResponse @@ -554,7 +525,7 @@ public function listDatabases($parent, $optionalArgs = []) * ``` * try { * $databaseAdminClient = new DatabaseAdminClient(); - * $formattedParent = DatabaseAdminClient::formatInstanceName("[PROJECT]", "[INSTANCE]"); + * $formattedParent = $databaseAdminClient->instanceName("[PROJECT]", "[INSTANCE]"); * $createStatement = ""; * $operationResponse = $databaseAdminClient->createDatabase($formattedParent, $createStatement); * $operationResponse->pollUntilComplete(); @@ -600,12 +571,11 @@ public function listDatabases($parent, $optionalArgs = []) * database. Statements can create tables, indexes, etc. These * statements execute atomically with the creation of the database: * if there is an error in any statement, the database is not created. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\OperationResponse @@ -645,7 +615,7 @@ public function createDatabase($parent, $createStatement, $optionalArgs = []) * ``` * try { * $databaseAdminClient = new DatabaseAdminClient(); - * $formattedName = DatabaseAdminClient::formatDatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"); + * $formattedName = $databaseAdminClient->databaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"); * $response = $databaseAdminClient->getDatabase($formattedName); * } finally { * $databaseAdminClient->close(); @@ -657,12 +627,11 @@ public function createDatabase($parent, $createStatement, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Spanner\Admin\Database\V1\Database @@ -704,7 +673,7 @@ public function getDatabase($name, $optionalArgs = []) * ``` * try { * $databaseAdminClient = new DatabaseAdminClient(); - * $formattedDatabase = DatabaseAdminClient::formatDatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"); + * $formattedDatabase = $databaseAdminClient->databaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"); * $statements = []; * $operationResponse = $databaseAdminClient->updateDatabaseDdl($formattedDatabase, $statements); * $operationResponse->pollUntilComplete(); @@ -760,12 +729,11 @@ public function getDatabase($name, $optionalArgs = []) * underscore. If the named operation already exists, * [UpdateDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabaseDdl] returns * `ALREADY_EXISTS`. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\OperationResponse @@ -805,7 +773,7 @@ public function updateDatabaseDdl($database, $statements, $optionalArgs = []) * ``` * try { * $databaseAdminClient = new DatabaseAdminClient(); - * $formattedDatabase = DatabaseAdminClient::formatDatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"); + * $formattedDatabase = $databaseAdminClient->databaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"); * $databaseAdminClient->dropDatabase($formattedDatabase); * } finally { * $databaseAdminClient->close(); @@ -816,12 +784,11 @@ public function updateDatabaseDdl($database, $statements, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @throws \Google\GAX\ApiException if the remote call fails @@ -857,7 +824,7 @@ public function dropDatabase($database, $optionalArgs = []) * ``` * try { * $databaseAdminClient = new DatabaseAdminClient(); - * $formattedDatabase = DatabaseAdminClient::formatDatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"); + * $formattedDatabase = $databaseAdminClient->databaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"); * $response = $databaseAdminClient->getDatabaseDdl($formattedDatabase); * } finally { * $databaseAdminClient->close(); @@ -868,12 +835,11 @@ public function dropDatabase($database, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Spanner\Admin\Database\V1\GetDatabaseDdlResponse @@ -913,7 +879,7 @@ public function getDatabaseDdl($database, $optionalArgs = []) * ``` * try { * $databaseAdminClient = new DatabaseAdminClient(); - * $formattedResource = DatabaseAdminClient::formatDatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"); + * $formattedResource = $databaseAdminClient->databaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"); * $policy = new Policy(); * $response = $databaseAdminClient->setIamPolicy($formattedResource, $policy); * } finally { @@ -931,12 +897,11 @@ public function getDatabaseDdl($database, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Iam\V1\Policy @@ -977,7 +942,7 @@ public function setIamPolicy($resource, $policy, $optionalArgs = []) * ``` * try { * $databaseAdminClient = new DatabaseAdminClient(); - * $formattedResource = DatabaseAdminClient::formatDatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"); + * $formattedResource = $databaseAdminClient->databaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"); * $response = $databaseAdminClient->getIamPolicy($formattedResource); * } finally { * $databaseAdminClient->close(); @@ -990,12 +955,11 @@ public function setIamPolicy($resource, $policy, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Iam\V1\Policy @@ -1036,7 +1000,7 @@ public function getIamPolicy($resource, $optionalArgs = []) * ``` * try { * $databaseAdminClient = new DatabaseAdminClient(); - * $formattedResource = DatabaseAdminClient::formatDatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"); + * $formattedResource = $databaseAdminClient->databaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"); * $permissions = []; * $response = $databaseAdminClient->testIamPermissions($formattedResource, $permissions); * } finally { @@ -1054,12 +1018,11 @@ public function getIamPolicy($resource, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Iam\V1\TestIamPermissionsResponse diff --git a/src/Spanner/Admin/Instance/V1/Gapic/InstanceAdminGapicClient.php b/src/Spanner/Admin/Instance/V1/Gapic/InstanceAdminGapicClient.php index 6582d937ab09..712248a3c5cf 100644 --- a/src/Spanner/Admin/Instance/V1/Gapic/InstanceAdminGapicClient.php +++ b/src/Spanner/Admin/Instance/V1/Gapic/InstanceAdminGapicClient.php @@ -33,12 +33,12 @@ use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; -use Google\GAX\GrpcConstants; use Google\GAX\GrpcCredentialsHelper; use Google\GAX\LongRunning\OperationsClient; use Google\GAX\OperationResponse; use Google\GAX\PageStreamingDescriptor; use Google\GAX\PathTemplate; +use Google\GAX\ValidationException; use Google\Iam\V1\GetIamPolicyRequest; use Google\Iam\V1\Policy; use Google\Iam\V1\SetIamPolicyRequest; @@ -89,7 +89,7 @@ * ``` * try { * $instanceAdminClient = new InstanceAdminClient(); - * $formattedParent = InstanceAdminClient::formatProjectName("[PROJECT]"); + * $formattedParent = $instanceAdminClient->projectName("[PROJECT]"); * // Iterate through all elements * $pagedResponse = $instanceAdminClient->listInstanceConfigs($formattedParent); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -110,8 +110,8 @@ * * Many parameters require resource names to be formatted in a particular way. To assist * with these names, this class includes a format method for each type of name, and additionally - * a parse method to extract the individual identifiers contained within names that are - * returned. + * a parseName method to extract the individual identifiers contained within formatted names + * that are returned by the API. * * @experimental */ @@ -145,6 +145,9 @@ class InstanceAdminGapicClient private static $projectNameTemplate; private static $instanceConfigNameTemplate; private static $instanceNameTemplate; + private static $pathTemplateList = null; + private static $gapicVersion = null; + private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; protected $instanceAdminStub; @@ -153,128 +156,6 @@ class InstanceAdminGapicClient private $descriptors; private $operationsClient; - /** - * Formats a string containing the fully-qualified path to represent - * a project resource. - * - * @param string $project - * - * @return string The formatted project resource. - * @experimental - */ - public static function formatProjectName($project) - { - return self::getProjectNameTemplate()->render([ - 'project' => $project, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent - * a instance_config resource. - * - * @param string $project - * @param string $instanceConfig - * - * @return string The formatted instance_config resource. - * @experimental - */ - public static function formatInstanceConfigName($project, $instanceConfig) - { - return self::getInstanceConfigNameTemplate()->render([ - 'project' => $project, - 'instance_config' => $instanceConfig, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent - * a instance resource. - * - * @param string $project - * @param string $instance - * - * @return string The formatted instance resource. - * @experimental - */ - public static function formatInstanceName($project, $instance) - { - return self::getInstanceNameTemplate()->render([ - 'project' => $project, - 'instance' => $instance, - ]); - } - - /** - * Parses the project from the given fully-qualified path which - * represents a project resource. - * - * @param string $projectName The fully-qualified project resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromProjectName($projectName) - { - return self::getProjectNameTemplate()->match($projectName)['project']; - } - - /** - * Parses the project from the given fully-qualified path which - * represents a instance_config resource. - * - * @param string $instanceConfigName The fully-qualified instance_config resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromInstanceConfigName($instanceConfigName) - { - return self::getInstanceConfigNameTemplate()->match($instanceConfigName)['project']; - } - - /** - * Parses the instance_config from the given fully-qualified path which - * represents a instance_config resource. - * - * @param string $instanceConfigName The fully-qualified instance_config resource. - * - * @return string The extracted instance_config value. - * @experimental - */ - public static function parseInstanceConfigFromInstanceConfigName($instanceConfigName) - { - return self::getInstanceConfigNameTemplate()->match($instanceConfigName)['instance_config']; - } - - /** - * Parses the project from the given fully-qualified path which - * represents a instance resource. - * - * @param string $instanceName The fully-qualified instance resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromInstanceName($instanceName) - { - return self::getInstanceNameTemplate()->match($instanceName)['project']; - } - - /** - * Parses the instance from the given fully-qualified path which - * represents a instance resource. - * - * @param string $instanceName The fully-qualified instance resource. - * - * @return string The extracted instance value. - * @experimental - */ - public static function parseInstanceFromInstanceName($instanceName) - { - return self::getInstanceNameTemplate()->match($instanceName)['instance']; - } - private static function getProjectNameTemplate() { if (self::$projectNameTemplate == null) { @@ -301,7 +182,18 @@ private static function getInstanceNameTemplate() return self::$instanceNameTemplate; } + private static function getPathTemplateList() + { + if (self::$pathTemplateList == null) { + self::$pathTemplateList = [ + self::getProjectNameTemplate(), + self::getInstanceConfigNameTemplate(), + self::getInstanceNameTemplate(), + ]; + } + return self::$pathTemplateList; + } private static function getPageStreamingDescriptors() { $listInstanceConfigsPageStreamingDescriptor = @@ -347,13 +239,92 @@ private static function getLongRunningDescriptors() private static function getGapicVersion() { - if (file_exists(__DIR__.'/../VERSION')) { - return trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - return \Google\Cloud\ServiceBuilder::VERSION; - } else { - return; + if (!self::$gapicVersionLoaded) { + if (file_exists(__DIR__.'/../VERSION')) { + self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } + self::$gapicVersionLoaded = true; + } + + return self::$gapicVersion; + } + + /** + * Formats a string containing the fully-qualified path to represent + * a project resource. + * + * @param string $project + * + * @return string The formatted project resource. + * @experimental + */ + public static function projectName($project) + { + return self::getProjectNameTemplate()->render([ + 'project' => $project, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a instance_config resource. + * + * @param string $project + * @param string $instanceConfig + * + * @return string The formatted instance_config resource. + * @experimental + */ + public static function instanceConfigName($project, $instanceConfig) + { + return self::getInstanceConfigNameTemplate()->render([ + 'project' => $project, + 'instance_config' => $instanceConfig, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a instance resource. + * + * @param string $project + * @param string $instance + * + * @return string The formatted instance resource. + * @experimental + */ + public static function instanceName($project, $instance) + { + return self::getInstanceNameTemplate()->render([ + 'project' => $project, + 'instance' => $instance, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * - projects/{project} + * - projects/{project}/instanceConfigs/{instance_config} + * - projects/{project}/instances/{instance}. + * + * @param string $formattedName The formatted name string + * + * @return array An associative array from name component IDs to component values. + * @experimental + */ + public static function parseName($formattedName) + { + foreach (self::getPathTemplateList() as $pathTemplate) { + try { + return $pathTemplate->match($formattedName); + } catch (ValidationException $ex) { + // Swallow the exception to continue trying other path templates + } } + throw new ValidationException("Input did not match any known format. Input: $formattedName"); } /** @@ -418,15 +389,18 @@ public function resumeOperation($operationName, $methodName = null) * A CredentialsLoader object created using the Google\Auth library. * @type array $scopes A string array of scopes to use when acquiring credentials. * Defaults to the scopes for the Cloud Spanner Instance Admin API. + * @type string $clientConfigPath + * Path to a JSON file containing client method configuration, including retry settings. + * Specify this setting to specify the retry behavior of all methods on the client. + * By default this settings points to the default client config file, which is provided + * in the resources folder. * @type array $retryingOverride - * An associative array of string => RetryOptions, where the keys - * are method names (e.g. 'createFoo'), that overrides default retrying - * settings. A value of null indicates that the method in question should - * not retry. - * @type int $timeoutMillis The timeout in milliseconds to use for calls - * that don't use retries. For calls that use retries, - * set the timeout in RetryOptions. - * Default: 30000 (30 seconds) + * An associative array in which the keys are method names (e.g. 'createFoo'), and + * the values are retry settings to use for that method. The retry settings for each + * method can be a {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} + * for example usage. Passing a value of null is equivalent to a value of + * ['retriesEnabled' => false]. * } * @experimental */ @@ -443,6 +417,7 @@ public function __construct($options = []) 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, + 'clientConfigPath' => __DIR__.'/../resources/instance_admin_client_config.json', ]; $options = array_merge($defaultOptions, $options); @@ -452,6 +427,7 @@ public function __construct($options = []) $operationsClientOptions = $options; unset($operationsClientOptions['timeoutMillis']); unset($operationsClientOptions['retryingOverride']); + unset($operationsClientOptions['clientConfigPath']); $this->operationsClient = new OperationsClient($operationsClientOptions); } @@ -485,15 +461,13 @@ public function __construct($options = []) $this->descriptors[$method]['longRunningDescriptor'] = $longRunningDescriptor + ['operationsClient' => $this->operationsClient]; } - $clientConfigJsonString = file_get_contents(__DIR__.'/../resources/instance_admin_client_config.json'); + $clientConfigJsonString = file_get_contents($options['clientConfigPath']); $clientConfig = json_decode($clientConfigJsonString, true); $this->defaultCallSettings = CallSettings::load( 'google.spanner.admin.instance.v1.InstanceAdmin', $clientConfig, - $options['retryingOverride'], - GrpcConstants::getStatusCodeNames(), - $options['timeoutMillis'] + $options['retryingOverride'] ); $this->scopes = $options['scopes']; @@ -520,7 +494,7 @@ public function __construct($options = []) * ``` * try { * $instanceAdminClient = new InstanceAdminClient(); - * $formattedParent = InstanceAdminClient::formatProjectName("[PROJECT]"); + * $formattedParent = $instanceAdminClient->projectName("[PROJECT]"); * // Iterate through all elements * $pagedResponse = $instanceAdminClient->listInstanceConfigs($formattedParent); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -554,12 +528,11 @@ public function __construct($options = []) * If no page token is specified (the default), the first page * of values will be returned. Any page token used here must have * been generated by a previous call to the API. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\PagedListResponse @@ -601,7 +574,7 @@ public function listInstanceConfigs($parent, $optionalArgs = []) * ``` * try { * $instanceAdminClient = new InstanceAdminClient(); - * $formattedName = InstanceAdminClient::formatInstanceConfigName("[PROJECT]", "[INSTANCE_CONFIG]"); + * $formattedName = $instanceAdminClient->instanceConfigName("[PROJECT]", "[INSTANCE_CONFIG]"); * $response = $instanceAdminClient->getInstanceConfig($formattedName); * } finally { * $instanceAdminClient->close(); @@ -613,12 +586,11 @@ public function listInstanceConfigs($parent, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Spanner\Admin\Instance\V1\InstanceConfig @@ -654,7 +626,7 @@ public function getInstanceConfig($name, $optionalArgs = []) * ``` * try { * $instanceAdminClient = new InstanceAdminClient(); - * $formattedParent = InstanceAdminClient::formatProjectName("[PROJECT]"); + * $formattedParent = $instanceAdminClient->projectName("[PROJECT]"); * // Iterate through all elements * $pagedResponse = $instanceAdminClient->listInstances($formattedParent); * foreach ($pagedResponse->iterateAllElements() as $element) { @@ -707,12 +679,11 @@ public function getInstanceConfig($name, $optionalArgs = []) * * name:howl labels.env:dev --> The instance's name contains "howl" and * it has the label "env" with its value * containing "dev". - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\PagedListResponse @@ -757,7 +728,7 @@ public function listInstances($parent, $optionalArgs = []) * ``` * try { * $instanceAdminClient = new InstanceAdminClient(); - * $formattedName = InstanceAdminClient::formatInstanceName("[PROJECT]", "[INSTANCE]"); + * $formattedName = $instanceAdminClient->instanceName("[PROJECT]", "[INSTANCE]"); * $response = $instanceAdminClient->getInstance($formattedName); * } finally { * $instanceAdminClient->close(); @@ -769,12 +740,11 @@ public function listInstances($parent, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Spanner\Admin\Instance\V1\Instance @@ -843,7 +813,7 @@ public function getInstance($name, $optionalArgs = []) * ``` * try { * $instanceAdminClient = new InstanceAdminClient(); - * $formattedParent = InstanceAdminClient::formatProjectName("[PROJECT]"); + * $formattedParent = $instanceAdminClient->projectName("[PROJECT]"); * $instanceId = ""; * $instance = new Instance(); * $operationResponse = $instanceAdminClient->createInstance($formattedParent, $instanceId, $instance); @@ -887,12 +857,11 @@ public function getInstance($name, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\OperationResponse @@ -1011,12 +980,11 @@ public function createInstance($parent, $instanceId, $instance, $optionalArgs = * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\OperationResponse @@ -1063,7 +1031,7 @@ public function updateInstance($instance, $fieldMask, $optionalArgs = []) * ``` * try { * $instanceAdminClient = new InstanceAdminClient(); - * $formattedName = InstanceAdminClient::formatInstanceName("[PROJECT]", "[INSTANCE]"); + * $formattedName = $instanceAdminClient->instanceName("[PROJECT]", "[INSTANCE]"); * $instanceAdminClient->deleteInstance($formattedName); * } finally { * $instanceAdminClient->close(); @@ -1075,12 +1043,11 @@ public function updateInstance($instance, $fieldMask, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @throws \Google\GAX\ApiException if the remote call fails @@ -1118,7 +1085,7 @@ public function deleteInstance($name, $optionalArgs = []) * ``` * try { * $instanceAdminClient = new InstanceAdminClient(); - * $formattedResource = InstanceAdminClient::formatInstanceName("[PROJECT]", "[INSTANCE]"); + * $formattedResource = $instanceAdminClient->instanceName("[PROJECT]", "[INSTANCE]"); * $policy = new Policy(); * $response = $instanceAdminClient->setIamPolicy($formattedResource, $policy); * } finally { @@ -1136,12 +1103,11 @@ public function deleteInstance($name, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Iam\V1\Policy @@ -1182,7 +1148,7 @@ public function setIamPolicy($resource, $policy, $optionalArgs = []) * ``` * try { * $instanceAdminClient = new InstanceAdminClient(); - * $formattedResource = InstanceAdminClient::formatInstanceName("[PROJECT]", "[INSTANCE]"); + * $formattedResource = $instanceAdminClient->instanceName("[PROJECT]", "[INSTANCE]"); * $response = $instanceAdminClient->getIamPolicy($formattedResource); * } finally { * $instanceAdminClient->close(); @@ -1195,12 +1161,11 @@ public function setIamPolicy($resource, $policy, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Iam\V1\Policy @@ -1241,7 +1206,7 @@ public function getIamPolicy($resource, $optionalArgs = []) * ``` * try { * $instanceAdminClient = new InstanceAdminClient(); - * $formattedResource = InstanceAdminClient::formatInstanceName("[PROJECT]", "[INSTANCE]"); + * $formattedResource = $instanceAdminClient->instanceName("[PROJECT]", "[INSTANCE]"); * $permissions = []; * $response = $instanceAdminClient->testIamPermissions($formattedResource, $permissions); * } finally { @@ -1259,12 +1224,11 @@ public function getIamPolicy($resource, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Iam\V1\TestIamPermissionsResponse diff --git a/src/Spanner/V1/Gapic/SpannerGapicClient.php b/src/Spanner/V1/Gapic/SpannerGapicClient.php index eabdc3d93e86..64e4248cb116 100644 --- a/src/Spanner/V1/Gapic/SpannerGapicClient.php +++ b/src/Spanner/V1/Gapic/SpannerGapicClient.php @@ -33,9 +33,9 @@ use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; -use Google\GAX\GrpcConstants; use Google\GAX\GrpcCredentialsHelper; use Google\GAX\PathTemplate; +use Google\GAX\ValidationException; use Google\Protobuf\Struct; use Google\Spanner\V1\BeginTransactionRequest; use Google\Spanner\V1\CommitRequest; @@ -68,7 +68,7 @@ * ``` * try { * $spannerClient = new SpannerClient(); - * $formattedDatabase = SpannerClient::formatDatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"); + * $formattedDatabase = $spannerClient->databaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"); * $response = $spannerClient->createSession($formattedDatabase); * } finally { * $spannerClient->close(); @@ -77,8 +77,8 @@ * * Many parameters require resource names to be formatted in a particular way. To assist * with these names, this class includes a format method for each type of name, and additionally - * a parse method to extract the individual identifiers contained within names that are - * returned. + * a parseName method to extract the individual identifiers contained within formatted names + * that are returned by the API. * * @experimental */ @@ -111,6 +111,9 @@ class SpannerGapicClient private static $databaseNameTemplate; private static $sessionNameTemplate; + private static $pathTemplateList = null; + private static $gapicVersion = null; + private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; protected $spannerStub; @@ -118,6 +121,61 @@ class SpannerGapicClient private $defaultCallSettings; private $descriptors; + private static function getDatabaseNameTemplate() + { + if (self::$databaseNameTemplate == null) { + self::$databaseNameTemplate = new PathTemplate('projects/{project}/instances/{instance}/databases/{database}'); + } + + return self::$databaseNameTemplate; + } + + private static function getSessionNameTemplate() + { + if (self::$sessionNameTemplate == null) { + self::$sessionNameTemplate = new PathTemplate('projects/{project}/instances/{instance}/databases/{database}/sessions/{session}'); + } + + return self::$sessionNameTemplate; + } + private static function getPathTemplateList() + { + if (self::$pathTemplateList == null) { + self::$pathTemplateList = [ + self::getDatabaseNameTemplate(), + self::getSessionNameTemplate(), + ]; + } + + return self::$pathTemplateList; + } + + private static function getGrpcStreamingDescriptors() + { + return [ + 'executeStreamingSql' => [ + 'grpcStreamingType' => 'ServerStreaming', + ], + 'streamingRead' => [ + 'grpcStreamingType' => 'ServerStreaming', + ], + ]; + } + + private static function getGapicVersion() + { + if (!self::$gapicVersionLoaded) { + if (file_exists(__DIR__.'/../VERSION')) { + self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } + self::$gapicVersionLoaded = true; + } + + return self::$gapicVersion; + } + /** * Formats a string containing the fully-qualified path to represent * a database resource. @@ -129,7 +187,7 @@ class SpannerGapicClient * @return string The formatted database resource. * @experimental */ - public static function formatDatabaseName($project, $instance, $database) + public static function databaseName($project, $instance, $database) { return self::getDatabaseNameTemplate()->render([ 'project' => $project, @@ -150,7 +208,7 @@ public static function formatDatabaseName($project, $instance, $database) * @return string The formatted session resource. * @experimental */ - public static function formatSessionName($project, $instance, $database, $session) + public static function sessionName($project, $instance, $database, $session) { return self::getSessionNameTemplate()->render([ 'project' => $project, @@ -161,142 +219,26 @@ public static function formatSessionName($project, $instance, $database, $sessio } /** - * Parses the project from the given fully-qualified path which - * represents a database resource. - * - * @param string $databaseName The fully-qualified database resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromDatabaseName($databaseName) - { - return self::getDatabaseNameTemplate()->match($databaseName)['project']; - } - - /** - * Parses the instance from the given fully-qualified path which - * represents a database resource. - * - * @param string $databaseName The fully-qualified database resource. - * - * @return string The extracted instance value. - * @experimental - */ - public static function parseInstanceFromDatabaseName($databaseName) - { - return self::getDatabaseNameTemplate()->match($databaseName)['instance']; - } - - /** - * Parses the database from the given fully-qualified path which - * represents a database resource. - * - * @param string $databaseName The fully-qualified database resource. - * - * @return string The extracted database value. - * @experimental - */ - public static function parseDatabaseFromDatabaseName($databaseName) - { - return self::getDatabaseNameTemplate()->match($databaseName)['database']; - } - - /** - * Parses the project from the given fully-qualified path which - * represents a session resource. - * - * @param string $sessionName The fully-qualified session resource. - * - * @return string The extracted project value. - * @experimental - */ - public static function parseProjectFromSessionName($sessionName) - { - return self::getSessionNameTemplate()->match($sessionName)['project']; - } - - /** - * Parses the instance from the given fully-qualified path which - * represents a session resource. - * - * @param string $sessionName The fully-qualified session resource. - * - * @return string The extracted instance value. - * @experimental - */ - public static function parseInstanceFromSessionName($sessionName) - { - return self::getSessionNameTemplate()->match($sessionName)['instance']; - } - - /** - * Parses the database from the given fully-qualified path which - * represents a session resource. - * - * @param string $sessionName The fully-qualified session resource. - * - * @return string The extracted database value. - * @experimental - */ - public static function parseDatabaseFromSessionName($sessionName) - { - return self::getSessionNameTemplate()->match($sessionName)['database']; - } - - /** - * Parses the session from the given fully-qualified path which - * represents a session resource. + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * - projects/{project}/instances/{instance}/databases/{database} + * - projects/{project}/instances/{instance}/databases/{database}/sessions/{session}. * - * @param string $sessionName The fully-qualified session resource. + * @param string $formattedName The formatted name string * - * @return string The extracted session value. + * @return array An associative array from name component IDs to component values. * @experimental */ - public static function parseSessionFromSessionName($sessionName) + public static function parseName($formattedName) { - return self::getSessionNameTemplate()->match($sessionName)['session']; - } - - private static function getDatabaseNameTemplate() - { - if (self::$databaseNameTemplate == null) { - self::$databaseNameTemplate = new PathTemplate('projects/{project}/instances/{instance}/databases/{database}'); - } - - return self::$databaseNameTemplate; - } - - private static function getSessionNameTemplate() - { - if (self::$sessionNameTemplate == null) { - self::$sessionNameTemplate = new PathTemplate('projects/{project}/instances/{instance}/databases/{database}/sessions/{session}'); - } - - return self::$sessionNameTemplate; - } - - private static function getGrpcStreamingDescriptors() - { - return [ - 'executeStreamingSql' => [ - 'grpcStreamingType' => 'ServerStreaming', - ], - 'streamingRead' => [ - 'grpcStreamingType' => 'ServerStreaming', - ], - ]; - } - - private static function getGapicVersion() - { - if (file_exists(__DIR__.'/../VERSION')) { - return trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - return \Google\Cloud\ServiceBuilder::VERSION; - } else { - return; + foreach (self::getPathTemplateList() as $pathTemplate) { + try { + return $pathTemplate->match($formattedName); + } catch (ValidationException $ex) { + // Swallow the exception to continue trying other path templates + } } + throw new ValidationException("Input did not match any known format. Input: $formattedName"); } /** @@ -323,15 +265,18 @@ private static function getGapicVersion() * A CredentialsLoader object created using the Google\Auth library. * @type array $scopes A string array of scopes to use when acquiring credentials. * Defaults to the scopes for the Cloud Spanner API. + * @type string $clientConfigPath + * Path to a JSON file containing client method configuration, including retry settings. + * Specify this setting to specify the retry behavior of all methods on the client. + * By default this settings points to the default client config file, which is provided + * in the resources folder. * @type array $retryingOverride - * An associative array of string => RetryOptions, where the keys - * are method names (e.g. 'createFoo'), that overrides default retrying - * settings. A value of null indicates that the method in question should - * not retry. - * @type int $timeoutMillis The timeout in milliseconds to use for calls - * that don't use retries. For calls that use retries, - * set the timeout in RetryOptions. - * Default: 30000 (30 seconds) + * An associative array in which the keys are method names (e.g. 'createFoo'), and + * the values are retry settings to use for that method. The retry settings for each + * method can be a {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} + * for example usage. Passing a value of null is equivalent to a value of + * ['retriesEnabled' => false]. * } * @experimental */ @@ -348,6 +293,7 @@ public function __construct($options = []) 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, + 'clientConfigPath' => __DIR__.'/../resources/spanner_client_config.json', ]; $options = array_merge($defaultOptions, $options); @@ -377,15 +323,13 @@ public function __construct($options = []) $this->descriptors[$method]['grpcStreamingDescriptor'] = $grpcStreamingDescriptor; } - $clientConfigJsonString = file_get_contents(__DIR__.'/../resources/spanner_client_config.json'); + $clientConfigJsonString = file_get_contents($options['clientConfigPath']); $clientConfig = json_decode($clientConfigJsonString, true); $this->defaultCallSettings = CallSettings::load( 'google.spanner.v1.Spanner', $clientConfig, - $options['retryingOverride'], - GrpcConstants::getStatusCodeNames(), - $options['timeoutMillis'] + $options['retryingOverride'] ); $this->scopes = $options['scopes']; @@ -430,7 +374,7 @@ public function __construct($options = []) * ``` * try { * $spannerClient = new SpannerClient(); - * $formattedDatabase = SpannerClient::formatDatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"); + * $formattedDatabase = $spannerClient->databaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"); * $response = $spannerClient->createSession($formattedDatabase); * } finally { * $spannerClient->close(); @@ -441,12 +385,11 @@ public function __construct($options = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Spanner\V1\Session @@ -484,7 +427,7 @@ public function createSession($database, $optionalArgs = []) * ``` * try { * $spannerClient = new SpannerClient(); - * $formattedName = SpannerClient::formatSessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); + * $formattedName = $spannerClient->sessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); * $response = $spannerClient->getSession($formattedName); * } finally { * $spannerClient->close(); @@ -495,12 +438,11 @@ public function createSession($database, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Spanner\V1\Session @@ -536,7 +478,7 @@ public function getSession($name, $optionalArgs = []) * ``` * try { * $spannerClient = new SpannerClient(); - * $formattedName = SpannerClient::formatSessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); + * $formattedName = $spannerClient->sessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); * $spannerClient->deleteSession($formattedName); * } finally { * $spannerClient->close(); @@ -547,12 +489,11 @@ public function getSession($name, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @throws \Google\GAX\ApiException if the remote call fails @@ -596,7 +537,7 @@ public function deleteSession($name, $optionalArgs = []) * ``` * try { * $spannerClient = new SpannerClient(); - * $formattedSession = SpannerClient::formatSessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); + * $formattedSession = $spannerClient->sessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); * $sql = ""; * $response = $spannerClient->executeSql($formattedSession, $sql); * } finally { @@ -647,12 +588,11 @@ public function deleteSession($name, $optionalArgs = []) * Used to control the amount of debugging information returned in * [ResultSetStats][google.spanner.v1.ResultSetStats]. * For allowed values, use constants defined on {@see \Google\Spanner\V1\ExecuteSqlRequest_QueryMode} - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Spanner\V1\ResultSet @@ -708,7 +648,7 @@ public function executeSql($session, $sql, $optionalArgs = []) * ``` * try { * $spannerClient = new SpannerClient(); - * $formattedSession = SpannerClient::formatSessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); + * $formattedSession = $spannerClient->sessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); * $sql = ""; * // Read all responses until the stream is complete * $stream = $spannerClient->executeStreamingSql($formattedSession, $sql); @@ -793,6 +733,13 @@ public function executeStreamingSql($session, $sql, $optionalArgs = []) $request->setQueryMode($optionalArgs['queryMode']); } + if (array_key_exists('timeoutMillis', $optionalArgs)) { + $optionalArgs['retrySettings'] = [ + 'retriesEnabled' => false, + 'noRetriesRpcTimeoutMillis' => $optionalArgs['timeoutMillis'], + ]; + } + $mergedSettings = $this->defaultCallSettings['executeStreamingSql']->merge( new CallSettings($optionalArgs) ); @@ -828,7 +775,7 @@ public function executeStreamingSql($session, $sql, $optionalArgs = []) * ``` * try { * $spannerClient = new SpannerClient(); - * $formattedSession = SpannerClient::formatSessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); + * $formattedSession = $spannerClient->sessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); * $table = ""; * $columns = []; * $keySet = new KeySet(); @@ -872,12 +819,11 @@ public function executeStreamingSql($session, $sql, $optionalArgs = []) * enables the new read to resume where the last read left off. The * rest of the request parameters must exactly match the request * that yielded this token. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Spanner\V1\ResultSet @@ -932,7 +878,7 @@ public function read($session, $table, $columns, $keySet, $optionalArgs = []) * ``` * try { * $spannerClient = new SpannerClient(); - * $formattedSession = SpannerClient::formatSessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); + * $formattedSession = $spannerClient->sessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); * $table = ""; * $columns = []; * $keySet = new KeySet(); @@ -1009,6 +955,13 @@ public function streamingRead($session, $table, $columns, $keySet, $optionalArgs $request->setResumeToken($optionalArgs['resumeToken']); } + if (array_key_exists('timeoutMillis', $optionalArgs)) { + $optionalArgs['retrySettings'] = [ + 'retriesEnabled' => false, + 'noRetriesRpcTimeoutMillis' => $optionalArgs['timeoutMillis'], + ]; + } + $mergedSettings = $this->defaultCallSettings['streamingRead']->merge( new CallSettings($optionalArgs) ); @@ -1035,7 +988,7 @@ public function streamingRead($session, $table, $columns, $keySet, $optionalArgs * ``` * try { * $spannerClient = new SpannerClient(); - * $formattedSession = SpannerClient::formatSessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); + * $formattedSession = $spannerClient->sessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); * $options = new TransactionOptions(); * $response = $spannerClient->beginTransaction($formattedSession, $options); * } finally { @@ -1048,12 +1001,11 @@ public function streamingRead($session, $table, $columns, $keySet, $optionalArgs * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Spanner\V1\Transaction @@ -1097,7 +1049,7 @@ public function beginTransaction($session, $options, $optionalArgs = []) * ``` * try { * $spannerClient = new SpannerClient(); - * $formattedSession = SpannerClient::formatSessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); + * $formattedSession = $spannerClient->sessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); * $mutations = []; * $response = $spannerClient->commit($formattedSession, $mutations); * } finally { @@ -1124,12 +1076,11 @@ public function beginTransaction($session, $options, $optionalArgs = []) * executed more than once. If this is undesirable, use * [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction] and * [Commit][google.spanner.v1.Spanner.Commit] instead. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Spanner\V1\CommitResponse @@ -1179,7 +1130,7 @@ public function commit($session, $mutations, $optionalArgs = []) * ``` * try { * $spannerClient = new SpannerClient(); - * $formattedSession = SpannerClient::formatSessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); + * $formattedSession = $spannerClient->sessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); * $transactionId = ""; * $spannerClient->rollback($formattedSession, $transactionId); * } finally { @@ -1192,12 +1143,11 @@ public function commit($session, $mutations, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @throws \Google\GAX\ApiException if the remote call fails diff --git a/src/Spanner/V1/SpannerClient.php b/src/Spanner/V1/SpannerClient.php index acf15f140c11..e078ad3ca308 100644 --- a/src/Spanner/V1/SpannerClient.php +++ b/src/Spanner/V1/SpannerClient.php @@ -31,35 +31,11 @@ namespace Google\Cloud\Spanner\V1; use Google\Cloud\Spanner\V1\Gapic\SpannerGapicClient; -use Google\GAX\GrpcCredentialsHelper; -use Google\Spanner\V1\SpannerGrpcClient; /** * {@inheritdoc} */ class SpannerClient extends SpannerGapicClient { - /** - * Returns the underlying stub. - * - * @access private - * @return SpannerGrpcClient - * @experimental - */ - public function getStub() - { - return $this->spannerStub; - } - - /** - * Returns the underlying gRPC credentials helper. - * - * @access private - * @return GrpcCredentialsHelper - * @experimental - */ - public function getCredentialsHelper() - { - return $this->grpcCredentialsHelper; - } + // This class is intentionally empty, and is intended to hold manual additions to the generated {@see SpannerClientImpl} class. } diff --git a/src/Speech/V1/Gapic/SpeechGapicClient.php b/src/Speech/V1/Gapic/SpeechGapicClient.php index 601f316b69db..08258748bf06 100644 --- a/src/Speech/V1/Gapic/SpeechGapicClient.php +++ b/src/Speech/V1/Gapic/SpeechGapicClient.php @@ -40,7 +40,6 @@ use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; -use Google\GAX\GrpcConstants; use Google\GAX\GrpcCredentialsHelper; use Google\GAX\LongRunning\OperationsClient; use Google\GAX\OperationResponse; @@ -103,6 +102,9 @@ class SpeechGapicClient */ const CODEGEN_VERSION = '0.0.5'; + private static $gapicVersion = null; + private static $gapicVersionLoaded = false; + protected $grpcCredentialsHelper; protected $speechStub; private $scopes; @@ -131,13 +133,16 @@ private static function getGrpcStreamingDescriptors() private static function getGapicVersion() { - if (file_exists(__DIR__.'/../VERSION')) { - return trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - return \Google\Cloud\ServiceBuilder::VERSION; - } else { - return; + if (!self::$gapicVersionLoaded) { + if (file_exists(__DIR__.'/../VERSION')) { + self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } + self::$gapicVersionLoaded = true; } + + return self::$gapicVersion; } /** @@ -202,15 +207,18 @@ public function resumeOperation($operationName, $methodName = null) * A CredentialsLoader object created using the Google\Auth library. * @type array $scopes A string array of scopes to use when acquiring credentials. * Defaults to the scopes for the Google Cloud Speech API. + * @type string $clientConfigPath + * Path to a JSON file containing client method configuration, including retry settings. + * Specify this setting to specify the retry behavior of all methods on the client. + * By default this settings points to the default client config file, which is provided + * in the resources folder. * @type array $retryingOverride - * An associative array of string => RetryOptions, where the keys - * are method names (e.g. 'createFoo'), that overrides default retrying - * settings. A value of null indicates that the method in question should - * not retry. - * @type int $timeoutMillis The timeout in milliseconds to use for calls - * that don't use retries. For calls that use retries, - * set the timeout in RetryOptions. - * Default: 30000 (30 seconds) + * An associative array in which the keys are method names (e.g. 'createFoo'), and + * the values are retry settings to use for that method. The retry settings for each + * method can be a {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} + * for example usage. Passing a value of null is equivalent to a value of + * ['retriesEnabled' => false]. * } * @experimental */ @@ -226,6 +234,7 @@ public function __construct($options = []) 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, + 'clientConfigPath' => __DIR__.'/../resources/speech_client_config.json', ]; $options = array_merge($defaultOptions, $options); @@ -235,6 +244,7 @@ public function __construct($options = []) $operationsClientOptions = $options; unset($operationsClientOptions['timeoutMillis']); unset($operationsClientOptions['retryingOverride']); + unset($operationsClientOptions['clientConfigPath']); $this->operationsClient = new OperationsClient($operationsClientOptions); } @@ -261,15 +271,13 @@ public function __construct($options = []) $this->descriptors[$method]['grpcStreamingDescriptor'] = $grpcStreamingDescriptor; } - $clientConfigJsonString = file_get_contents(__DIR__.'/../resources/speech_client_config.json'); + $clientConfigJsonString = file_get_contents($options['clientConfigPath']); $clientConfig = json_decode($clientConfigJsonString, true); $this->defaultCallSettings = CallSettings::load( 'google.cloud.speech.v1.Speech', $clientConfig, - $options['retryingOverride'], - GrpcConstants::getStatusCodeNames(), - $options['timeoutMillis'] + $options['retryingOverride'] ); $this->scopes = $options['scopes']; @@ -319,12 +327,11 @@ public function __construct($options = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Cloud\Speech\V1\RecognizeResponse @@ -411,12 +418,11 @@ public function recognize($config, $audio, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\OperationResponse @@ -500,6 +506,13 @@ public function longRunningRecognize($config, $audio, $optionalArgs = []) */ public function streamingRecognize($optionalArgs = []) { + if (array_key_exists('timeoutMillis', $optionalArgs)) { + $optionalArgs['retrySettings'] = [ + 'retriesEnabled' => false, + 'noRetriesRpcTimeoutMillis' => $optionalArgs['timeoutMillis'], + ]; + } + $mergedSettings = $this->defaultCallSettings['streamingRecognize']->merge( new CallSettings($optionalArgs) ); diff --git a/src/Speech/V1beta1/Gapic/SpeechGapicClient.php b/src/Speech/V1beta1/Gapic/SpeechGapicClient.php index 5111253a5503..384f8f2008f8 100644 --- a/src/Speech/V1beta1/Gapic/SpeechGapicClient.php +++ b/src/Speech/V1beta1/Gapic/SpeechGapicClient.php @@ -40,7 +40,6 @@ use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; -use Google\GAX\GrpcConstants; use Google\GAX\GrpcCredentialsHelper; use Google\GAX\LongRunning\OperationsClient; use Google\GAX\OperationResponse; @@ -101,6 +100,9 @@ class SpeechGapicClient */ const CODEGEN_VERSION = '0.0.5'; + private static $gapicVersion = null; + private static $gapicVersionLoaded = false; + protected $grpcCredentialsHelper; protected $speechStub; private $scopes; @@ -129,13 +131,16 @@ private static function getGrpcStreamingDescriptors() private static function getGapicVersion() { - if (file_exists(__DIR__.'/../VERSION')) { - return trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - return \Google\Cloud\ServiceBuilder::VERSION; - } else { - return; + if (!self::$gapicVersionLoaded) { + if (file_exists(__DIR__.'/../VERSION')) { + self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } + self::$gapicVersionLoaded = true; } + + return self::$gapicVersion; } /** @@ -200,15 +205,18 @@ public function resumeOperation($operationName, $methodName = null) * A CredentialsLoader object created using the Google\Auth library. * @type array $scopes A string array of scopes to use when acquiring credentials. * Defaults to the scopes for the Google Cloud Speech API. + * @type string $clientConfigPath + * Path to a JSON file containing client method configuration, including retry settings. + * Specify this setting to specify the retry behavior of all methods on the client. + * By default this settings points to the default client config file, which is provided + * in the resources folder. * @type array $retryingOverride - * An associative array of string => RetryOptions, where the keys - * are method names (e.g. 'createFoo'), that overrides default retrying - * settings. A value of null indicates that the method in question should - * not retry. - * @type int $timeoutMillis The timeout in milliseconds to use for calls - * that don't use retries. For calls that use retries, - * set the timeout in RetryOptions. - * Default: 30000 (30 seconds) + * An associative array in which the keys are method names (e.g. 'createFoo'), and + * the values are retry settings to use for that method. The retry settings for each + * method can be a {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} + * for example usage. Passing a value of null is equivalent to a value of + * ['retriesEnabled' => false]. * } * @experimental */ @@ -224,6 +232,7 @@ public function __construct($options = []) 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, + 'clientConfigPath' => __DIR__.'/../resources/speech_client_config.json', ]; $options = array_merge($defaultOptions, $options); @@ -233,6 +242,7 @@ public function __construct($options = []) $operationsClientOptions = $options; unset($operationsClientOptions['timeoutMillis']); unset($operationsClientOptions['retryingOverride']); + unset($operationsClientOptions['clientConfigPath']); $this->operationsClient = new OperationsClient($operationsClientOptions); } @@ -259,15 +269,13 @@ public function __construct($options = []) $this->descriptors[$method]['grpcStreamingDescriptor'] = $grpcStreamingDescriptor; } - $clientConfigJsonString = file_get_contents(__DIR__.'/../resources/speech_client_config.json'); + $clientConfigJsonString = file_get_contents($options['clientConfigPath']); $clientConfig = json_decode($clientConfigJsonString, true); $this->defaultCallSettings = CallSettings::load( 'google.cloud.speech.v1beta1.Speech', $clientConfig, - $options['retryingOverride'], - GrpcConstants::getStatusCodeNames(), - $options['timeoutMillis'] + $options['retryingOverride'] ); $this->scopes = $options['scopes']; @@ -315,12 +323,11 @@ public function __construct($options = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Cloud\Speech\V1beta1\SyncRecognizeResponse @@ -407,12 +414,11 @@ public function syncRecognize($config, $audio, $optionalArgs = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\OperationResponse @@ -496,6 +502,13 @@ public function asyncRecognize($config, $audio, $optionalArgs = []) */ public function streamingRecognize($optionalArgs = []) { + if (array_key_exists('timeoutMillis', $optionalArgs)) { + $optionalArgs['retrySettings'] = [ + 'retriesEnabled' => false, + 'noRetriesRpcTimeoutMillis' => $optionalArgs['timeoutMillis'], + ]; + } + $mergedSettings = $this->defaultCallSettings['streamingRecognize']->merge( new CallSettings($optionalArgs) ); diff --git a/src/VideoIntelligence/V1beta1/Gapic/VideoIntelligenceServiceGapicClient.php b/src/VideoIntelligence/V1beta1/Gapic/VideoIntelligenceServiceGapicClient.php index 2b204a75fae7..650785060207 100644 --- a/src/VideoIntelligence/V1beta1/Gapic/VideoIntelligenceServiceGapicClient.php +++ b/src/VideoIntelligence/V1beta1/Gapic/VideoIntelligenceServiceGapicClient.php @@ -39,7 +39,6 @@ use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; -use Google\GAX\GrpcConstants; use Google\GAX\GrpcCredentialsHelper; use Google\GAX\LongRunning\OperationsClient; use Google\GAX\OperationResponse; @@ -119,6 +118,9 @@ class VideoIntelligenceServiceGapicClient */ const CODEGEN_VERSION = '0.0.5'; + private static $gapicVersion = null; + private static $gapicVersionLoaded = false; + protected $grpcCredentialsHelper; protected $videoIntelligenceServiceStub; private $scopes; @@ -138,13 +140,16 @@ private static function getLongRunningDescriptors() private static function getGapicVersion() { - if (file_exists(__DIR__.'/../VERSION')) { - return trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - return \Google\Cloud\ServiceBuilder::VERSION; - } else { - return; + if (!self::$gapicVersionLoaded) { + if (file_exists(__DIR__.'/../VERSION')) { + self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } + self::$gapicVersionLoaded = true; } + + return self::$gapicVersion; } /** @@ -209,15 +214,18 @@ public function resumeOperation($operationName, $methodName = null) * A CredentialsLoader object created using the Google\Auth library. * @type array $scopes A string array of scopes to use when acquiring credentials. * Defaults to the scopes for the Google Cloud Video Intelligence API. + * @type string $clientConfigPath + * Path to a JSON file containing client method configuration, including retry settings. + * Specify this setting to specify the retry behavior of all methods on the client. + * By default this settings points to the default client config file, which is provided + * in the resources folder. * @type array $retryingOverride - * An associative array of string => RetryOptions, where the keys - * are method names (e.g. 'createFoo'), that overrides default retrying - * settings. A value of null indicates that the method in question should - * not retry. - * @type int $timeoutMillis The timeout in milliseconds to use for calls - * that don't use retries. For calls that use retries, - * set the timeout in RetryOptions. - * Default: 30000 (30 seconds) + * An associative array in which the keys are method names (e.g. 'createFoo'), and + * the values are retry settings to use for that method. The retry settings for each + * method can be a {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} + * for example usage. Passing a value of null is equivalent to a value of + * ['retriesEnabled' => false]. * } * @experimental */ @@ -233,6 +241,7 @@ public function __construct($options = []) 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, + 'clientConfigPath' => __DIR__.'/../resources/video_intelligence_service_client_config.json', ]; $options = array_merge($defaultOptions, $options); @@ -242,6 +251,7 @@ public function __construct($options = []) $operationsClientOptions = $options; unset($operationsClientOptions['timeoutMillis']); unset($operationsClientOptions['retryingOverride']); + unset($operationsClientOptions['clientConfigPath']); $this->operationsClient = new OperationsClient($operationsClientOptions); } @@ -262,15 +272,13 @@ public function __construct($options = []) $this->descriptors[$method]['longRunningDescriptor'] = $longRunningDescriptor + ['operationsClient' => $this->operationsClient]; } - $clientConfigJsonString = file_get_contents(__DIR__.'/../resources/video_intelligence_service_client_config.json'); + $clientConfigJsonString = file_get_contents($options['clientConfigPath']); $clientConfig = json_decode($clientConfigJsonString, true); $this->defaultCallSettings = CallSettings::load( 'google.cloud.videointelligence.v1beta1.VideoIntelligenceService', $clientConfig, - $options['retryingOverride'], - GrpcConstants::getStatusCodeNames(), - $options['timeoutMillis'] + $options['retryingOverride'] ); $this->scopes = $options['scopes']; @@ -364,12 +372,11 @@ public function __construct($options = []) * Optional cloud region where annotation should take place. Supported cloud * regions: `us-east1`, `us-west1`, `europe-west1`, `asia-east1`. If no region * is specified, a region will be determined based on video file location. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\OperationResponse diff --git a/src/VideoIntelligence/V1beta2/Gapic/VideoIntelligenceServiceGapicClient.php b/src/VideoIntelligence/V1beta2/Gapic/VideoIntelligenceServiceGapicClient.php index b831c93d8ca6..7337b930b682 100644 --- a/src/VideoIntelligence/V1beta2/Gapic/VideoIntelligenceServiceGapicClient.php +++ b/src/VideoIntelligence/V1beta2/Gapic/VideoIntelligenceServiceGapicClient.php @@ -39,7 +39,6 @@ use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; -use Google\GAX\GrpcConstants; use Google\GAX\GrpcCredentialsHelper; use Google\GAX\LongRunning\OperationsClient; use Google\GAX\OperationResponse; @@ -119,6 +118,9 @@ class VideoIntelligenceServiceGapicClient */ const CODEGEN_VERSION = '0.0.5'; + private static $gapicVersion = null; + private static $gapicVersionLoaded = false; + protected $grpcCredentialsHelper; protected $videoIntelligenceServiceStub; private $scopes; @@ -138,13 +140,16 @@ private static function getLongRunningDescriptors() private static function getGapicVersion() { - if (file_exists(__DIR__.'/../VERSION')) { - return trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - return \Google\Cloud\ServiceBuilder::VERSION; - } else { - return; + if (!self::$gapicVersionLoaded) { + if (file_exists(__DIR__.'/../VERSION')) { + self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } + self::$gapicVersionLoaded = true; } + + return self::$gapicVersion; } /** @@ -209,15 +214,18 @@ public function resumeOperation($operationName, $methodName = null) * A CredentialsLoader object created using the Google\Auth library. * @type array $scopes A string array of scopes to use when acquiring credentials. * Defaults to the scopes for the Google Cloud Video Intelligence API. + * @type string $clientConfigPath + * Path to a JSON file containing client method configuration, including retry settings. + * Specify this setting to specify the retry behavior of all methods on the client. + * By default this settings points to the default client config file, which is provided + * in the resources folder. * @type array $retryingOverride - * An associative array of string => RetryOptions, where the keys - * are method names (e.g. 'createFoo'), that overrides default retrying - * settings. A value of null indicates that the method in question should - * not retry. - * @type int $timeoutMillis The timeout in milliseconds to use for calls - * that don't use retries. For calls that use retries, - * set the timeout in RetryOptions. - * Default: 30000 (30 seconds) + * An associative array in which the keys are method names (e.g. 'createFoo'), and + * the values are retry settings to use for that method. The retry settings for each + * method can be a {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} + * for example usage. Passing a value of null is equivalent to a value of + * ['retriesEnabled' => false]. * } * @experimental */ @@ -233,6 +241,7 @@ public function __construct($options = []) 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, + 'clientConfigPath' => __DIR__.'/../resources/video_intelligence_service_client_config.json', ]; $options = array_merge($defaultOptions, $options); @@ -242,6 +251,7 @@ public function __construct($options = []) $operationsClientOptions = $options; unset($operationsClientOptions['timeoutMillis']); unset($operationsClientOptions['retryingOverride']); + unset($operationsClientOptions['clientConfigPath']); $this->operationsClient = new OperationsClient($operationsClientOptions); } @@ -262,15 +272,13 @@ public function __construct($options = []) $this->descriptors[$method]['longRunningDescriptor'] = $longRunningDescriptor + ['operationsClient' => $this->operationsClient]; } - $clientConfigJsonString = file_get_contents(__DIR__.'/../resources/video_intelligence_service_client_config.json'); + $clientConfigJsonString = file_get_contents($options['clientConfigPath']); $clientConfig = json_decode($clientConfigJsonString, true); $this->defaultCallSettings = CallSettings::load( 'google.cloud.videointelligence.v1beta2.VideoIntelligenceService', $clientConfig, - $options['retryingOverride'], - GrpcConstants::getStatusCodeNames(), - $options['timeoutMillis'] + $options['retryingOverride'] ); $this->scopes = $options['scopes']; @@ -364,12 +372,11 @@ public function __construct($options = []) * Optional cloud region where annotation should take place. Supported cloud * regions: `us-east1`, `us-west1`, `europe-west1`, `asia-east1`. If no region * is specified, a region will be determined based on video file location. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\GAX\OperationResponse diff --git a/src/Vision/V1/Gapic/ImageAnnotatorGapicClient.php b/src/Vision/V1/Gapic/ImageAnnotatorGapicClient.php index fbf97a0214dd..f4fd0175f9f6 100644 --- a/src/Vision/V1/Gapic/ImageAnnotatorGapicClient.php +++ b/src/Vision/V1/Gapic/ImageAnnotatorGapicClient.php @@ -36,7 +36,6 @@ use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; -use Google\GAX\GrpcConstants; use Google\GAX\GrpcCredentialsHelper; /** @@ -90,6 +89,9 @@ class ImageAnnotatorGapicClient */ const CODEGEN_VERSION = '0.0.5'; + private static $gapicVersion = null; + private static $gapicVersionLoaded = false; + protected $grpcCredentialsHelper; protected $imageAnnotatorStub; private $scopes; @@ -98,13 +100,16 @@ class ImageAnnotatorGapicClient private static function getGapicVersion() { - if (file_exists(__DIR__.'/../VERSION')) { - return trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - return \Google\Cloud\ServiceBuilder::VERSION; - } else { - return; + if (!self::$gapicVersionLoaded) { + if (file_exists(__DIR__.'/../VERSION')) { + self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } + self::$gapicVersionLoaded = true; } + + return self::$gapicVersion; } /** @@ -131,15 +136,18 @@ private static function getGapicVersion() * A CredentialsLoader object created using the Google\Auth library. * @type array $scopes A string array of scopes to use when acquiring credentials. * Defaults to the scopes for the Google Cloud Vision API. + * @type string $clientConfigPath + * Path to a JSON file containing client method configuration, including retry settings. + * Specify this setting to specify the retry behavior of all methods on the client. + * By default this settings points to the default client config file, which is provided + * in the resources folder. * @type array $retryingOverride - * An associative array of string => RetryOptions, where the keys - * are method names (e.g. 'createFoo'), that overrides default retrying - * settings. A value of null indicates that the method in question should - * not retry. - * @type int $timeoutMillis The timeout in milliseconds to use for calls - * that don't use retries. For calls that use retries, - * set the timeout in RetryOptions. - * Default: 30000 (30 seconds) + * An associative array in which the keys are method names (e.g. 'createFoo'), and + * the values are retry settings to use for that method. The retry settings for each + * method can be a {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} + * for example usage. Passing a value of null is equivalent to a value of + * ['retriesEnabled' => false]. * } * @experimental */ @@ -155,6 +163,7 @@ public function __construct($options = []) 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, + 'clientConfigPath' => __DIR__.'/../resources/image_annotator_client_config.json', ]; $options = array_merge($defaultOptions, $options); @@ -171,15 +180,13 @@ public function __construct($options = []) 'batchAnnotateImages' => $defaultDescriptors, ]; - $clientConfigJsonString = file_get_contents(__DIR__.'/../resources/image_annotator_client_config.json'); + $clientConfigJsonString = file_get_contents($options['clientConfigPath']); $clientConfig = json_decode($clientConfigJsonString, true); $this->defaultCallSettings = CallSettings::load( 'google.cloud.vision.v1.ImageAnnotator', $clientConfig, - $options['retryingOverride'], - GrpcConstants::getStatusCodeNames(), - $options['timeoutMillis'] + $options['retryingOverride'] ); $this->scopes = $options['scopes']; @@ -217,12 +224,11 @@ public function __construct($options = []) * @param array $optionalArgs { * Optional. * - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. * } * * @return \Google\Cloud\Vision\V1\BatchAnnotateImagesResponse From 6a0cfc62e6527baaaa8540cfbc95e5c3114bff66 Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Mon, 18 Sep 2017 15:26:05 -0700 Subject: [PATCH 03/17] Test updates --- composer.json | 4 ++-- src/Core/GrpcRequestWrapper.php | 12 +++++++----- tests/unit/Core/GrpcRequestWrapperTest.php | 11 ++++++++--- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 2c95b22145ee..d4d9090b09bc 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,7 @@ "psr/http-message": "1.0.*", "ramsey/uuid": "~3", "google/proto-client": "^0.23", - "google/gax": "^0.23" + "google/gax": "dev-master" }, "require-dev": { "phpunit/phpunit": "4.8.*", @@ -117,4 +117,4 @@ ] } } -} \ No newline at end of file +} diff --git a/src/Core/GrpcRequestWrapper.php b/src/Core/GrpcRequestWrapper.php index d1c56349ce63..e9246cd5c9cc 100644 --- a/src/Core/GrpcRequestWrapper.php +++ b/src/Core/GrpcRequestWrapper.php @@ -131,11 +131,13 @@ public function send(callable $request, array $args, array $options = []) }); if (!isset($grpcOptions['retrySettings'])) { - $grpcOptions['retrySettings'] = new RetrySettings(null, null); - } - - if ($timeout && !array_key_exists('timeoutMs', $grpcOptions)) { - $grpcOptions['timeoutMs'] = $timeout * 1000; + $retrySettings = [ + 'retriesEnabled' => false + ]; + if ($timeout && !array_key_exists('timeoutMs', $grpcOptions)) { + $retrySettings['noRetriesRpcTimeoutMillis'] = $timeout * 1000; + } + $grpcOptions['retrySettings'] = $retrySettings; } $optionalArgs = &$args[count($args) - 1]; diff --git a/tests/unit/Core/GrpcRequestWrapperTest.php b/tests/unit/Core/GrpcRequestWrapperTest.php index eff18c2fdd5a..3069d76cff63 100644 --- a/tests/unit/Core/GrpcRequestWrapperTest.php +++ b/tests/unit/Core/GrpcRequestWrapperTest.php @@ -24,6 +24,7 @@ use Google\Cloud\Tests\GrpcTestTrait; use Google\Cloud\Core\GrpcRequestWrapper; use Google\GAX\ApiException; +use Google\GAX\ApiStatus; use Google\GAX\Page; use Google\GAX\PagedListResponse; use Google\GAX\Serializer; @@ -65,7 +66,7 @@ public function testSuccessfullySendsRequest($response, $expectedMessage, $seria $actualResponse = $requestWrapper->send( function ($test, $options) use ($response, $requestOptions) { - $this->assertEquals($requestOptions['requestTimeout'] * 1000, $options['timeoutMs']); + $this->assertEquals($requestOptions['requestTimeout'] * 1000, $options['retrySettings']['noRetriesRpcTimeoutMillis']); return $response; }, ['test', []], @@ -104,7 +105,10 @@ public function testThrowsExceptionWhenRequestFails() $requestWrapper = new GrpcRequestWrapper(); $requestWrapper->send(function () { - throw new ApiException('message', 5); + throw new ApiException('message', + \Google\Rpc\Code::NOT_FOUND, + \Google\GAX\ApiStatus::NOT_FOUND + ); }, [[]]); } @@ -180,7 +184,8 @@ public function testCastsToProperException($code, $expectedException) try { $requestWrapper->send(function () use ($code) { - throw new ApiException('message', $code); + $status = ApiStatus::statusFromRpcCode($code); + throw new ApiException('message', $code, $status); }, [[]], ['retries' => 0]); } catch (\Exception $ex) { $this->assertInstanceOf($expectedException, $ex); From 76c0ec799b79230e5ef387de96acb2cb9c244c63 Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Mon, 18 Sep 2017 15:59:20 -0700 Subject: [PATCH 04/17] Remove updateSubscription --- src/PubSub/Connection/ConnectionInterface.php | 5 ----- src/PubSub/Connection/Grpc.php | 22 ------------------- src/PubSub/Connection/Rest.php | 8 ------- tests/unit/PubSub/Connection/GrpcTest.php | 5 ----- tests/unit/PubSub/Connection/RestTest.php | 1 - tests/unit/PubSub/SubscriptionTest.php | 22 ------------------- 6 files changed, 63 deletions(-) diff --git a/src/PubSub/Connection/ConnectionInterface.php b/src/PubSub/Connection/ConnectionInterface.php index da992fa31bd2..8cb8c2418e8c 100644 --- a/src/PubSub/Connection/ConnectionInterface.php +++ b/src/PubSub/Connection/ConnectionInterface.php @@ -73,11 +73,6 @@ public function testTopicIamPermissions(array $args); */ public function createSubscription(array $args); - /** - * @param array $args - */ - public function updateSubscription(array $args); - /** * @param array $args */ diff --git a/src/PubSub/Connection/Grpc.php b/src/PubSub/Connection/Grpc.php index 43a5e631035d..e0a1dd5a34df 100644 --- a/src/PubSub/Connection/Grpc.php +++ b/src/PubSub/Connection/Grpc.php @@ -180,28 +180,6 @@ public function createSubscription(array $args) ]); } - /** - * @param array $args - */ - public function updateSubscription(array $args) - { - // Get a list of keys used before building subscription, which modifies $args - $mask = array_keys($args); - - // Remove immutable properties. - $mask = array_values(array_diff($mask, ['name', 'topic'])); - - $fieldMask = $this->serializer->decodeMessage(new FieldMask(), ['paths' => $mask]); - - $subscriptionObject = $this->buildSubscription($args); - - return $this->send([$this->subscriberClient, 'updateSubscription'], [ - $subscriptionObject, - $fieldMask, - $args - ]); - } - /** * @param array $args */ diff --git a/src/PubSub/Connection/Rest.php b/src/PubSub/Connection/Rest.php index d45e9b4b2d15..86f723edd84c 100644 --- a/src/PubSub/Connection/Rest.php +++ b/src/PubSub/Connection/Rest.php @@ -145,14 +145,6 @@ public function createSubscription(array $args) return $this->send('subscriptions', 'create', $args); } - /** - * @param array $args - */ - public function updateSubscription(array $args) - { - return $this->send('subscriptions', 'patch', $args); - } - /** * @param array $args */ diff --git a/tests/unit/PubSub/Connection/GrpcTest.php b/tests/unit/PubSub/Connection/GrpcTest.php index 994a35c00810..c7b28a2cfab0 100644 --- a/tests/unit/PubSub/Connection/GrpcTest.php +++ b/tests/unit/PubSub/Connection/GrpcTest.php @@ -114,11 +114,6 @@ public function methodProvider() $timestamp = $serializer->decodeMessage(new Timestamp(), $this->formatTimestampForApi($time)); return [ - [ - 'updateSubscription', - ['name' => 'projects/foo/subscriptions/bar', 'retainAckedMessages' => true], - [$subscription, $fieldMask, []] - ], [ 'listSnapshots', ['project' => 'projectId'], diff --git a/tests/unit/PubSub/Connection/RestTest.php b/tests/unit/PubSub/Connection/RestTest.php index 49af5829bd68..5f1643ed4343 100644 --- a/tests/unit/PubSub/Connection/RestTest.php +++ b/tests/unit/PubSub/Connection/RestTest.php @@ -84,7 +84,6 @@ public function methodProvider() ['setTopicIamPolicy'], ['testTopicIamPermissions'], ['createSubscription'], - ['updateSubscription'], ['getSubscription'], ['listSubscriptions'], ['deleteSubscription'], diff --git a/tests/unit/PubSub/SubscriptionTest.php b/tests/unit/PubSub/SubscriptionTest.php index 85ea771796d0..1d67ebc52c1f 100644 --- a/tests/unit/PubSub/SubscriptionTest.php +++ b/tests/unit/PubSub/SubscriptionTest.php @@ -86,28 +86,6 @@ public function testCreateWithoutTopicName() $sub = $subscription->create(); } - public function testUpdate() - { - $args = [ - 'foo' => 'bar' - ]; - - $argsWithName = $args + [ - 'name' => $this->subscription->name() - ]; - - $this->connection->updateSubscription($argsWithName) - ->shouldBeCalled() - ->willReturn($argsWithName); - - $this->subscription->setConnection($this->connection->reveal()); - - $res = $this->subscription->update($args); - - $this->assertEquals($res, $argsWithName); - $this->assertEquals($this->subscription->info(), $argsWithName); - } - public function testDelete() { $this->connection->deleteSubscription(Argument::withEntry('foo', 'bar')) From 131c42d8b5d2b17da7b29e1f7703030dd47ad2fe Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Mon, 18 Sep 2017 16:00:53 -0700 Subject: [PATCH 05/17] Add SpannerClient partial veneer back --- src/Spanner/V1/SpannerClient.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Spanner/V1/SpannerClient.php b/src/Spanner/V1/SpannerClient.php index e078ad3ca308..acf15f140c11 100644 --- a/src/Spanner/V1/SpannerClient.php +++ b/src/Spanner/V1/SpannerClient.php @@ -31,11 +31,35 @@ namespace Google\Cloud\Spanner\V1; use Google\Cloud\Spanner\V1\Gapic\SpannerGapicClient; +use Google\GAX\GrpcCredentialsHelper; +use Google\Spanner\V1\SpannerGrpcClient; /** * {@inheritdoc} */ class SpannerClient extends SpannerGapicClient { - // This class is intentionally empty, and is intended to hold manual additions to the generated {@see SpannerClientImpl} class. + /** + * Returns the underlying stub. + * + * @access private + * @return SpannerGrpcClient + * @experimental + */ + public function getStub() + { + return $this->spannerStub; + } + + /** + * Returns the underlying gRPC credentials helper. + * + * @access private + * @return GrpcCredentialsHelper + * @experimental + */ + public function getCredentialsHelper() + { + return $this->grpcCredentialsHelper; + } } From 8147b068b31200eb5d4e61f1ad15ef52ff853e5b Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Mon, 18 Sep 2017 17:03:44 -0700 Subject: [PATCH 06/17] Refresh GAPICs --- src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php | 4 ++-- .../V1beta1/Gapic/ErrorGroupServiceGapicClient.php | 4 ++-- .../V1beta1/Gapic/ErrorStatsServiceGapicClient.php | 4 ++-- .../V1beta1/Gapic/ReportErrorsServiceGapicClient.php | 4 ++-- src/Language/V1beta2/Gapic/LanguageServiceGapicClient.php | 4 ++-- src/Logging/V2/Gapic/ConfigServiceV2GapicClient.php | 4 ++-- src/Logging/V2/Gapic/LoggingServiceV2GapicClient.php | 4 ++-- src/Logging/V2/Gapic/MetricsServiceV2GapicClient.php | 4 ++-- src/Monitoring/V3/Gapic/GroupServiceGapicClient.php | 4 ++-- src/Monitoring/V3/Gapic/MetricServiceGapicClient.php | 4 ++-- src/PubSub/V1/Gapic/PublisherGapicClient.php | 4 ++-- src/PubSub/V1/Gapic/SubscriberGapicClient.php | 4 ++-- .../Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php | 4 ++-- .../Admin/Instance/V1/Gapic/InstanceAdminGapicClient.php | 4 ++-- src/Spanner/V1/Gapic/SpannerGapicClient.php | 4 ++-- src/Speech/V1/Gapic/SpeechGapicClient.php | 4 ++-- src/Speech/V1beta1/Gapic/SpeechGapicClient.php | 4 ++-- .../V1beta1/Gapic/VideoIntelligenceServiceGapicClient.php | 4 ++-- .../V1beta2/Gapic/VideoIntelligenceServiceGapicClient.php | 4 ++-- src/Vision/V1/Gapic/ImageAnnotatorGapicClient.php | 4 ++-- 20 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php b/src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php index 6e68ff8fa541..d653a361e2c7 100644 --- a/src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php +++ b/src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php @@ -169,8 +169,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } elseif (class_exists('\Google\Cloud\Version')) { + self::$gapicVersion = \Google\Cloud\Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/ErrorReporting/V1beta1/Gapic/ErrorGroupServiceGapicClient.php b/src/ErrorReporting/V1beta1/Gapic/ErrorGroupServiceGapicClient.php index f2b980c6e8c2..cd527ec23661 100644 --- a/src/ErrorReporting/V1beta1/Gapic/ErrorGroupServiceGapicClient.php +++ b/src/ErrorReporting/V1beta1/Gapic/ErrorGroupServiceGapicClient.php @@ -130,8 +130,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } elseif (class_exists('\Google\Cloud\Version')) { + self::$gapicVersion = \Google\Cloud\Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/ErrorReporting/V1beta1/Gapic/ErrorStatsServiceGapicClient.php b/src/ErrorReporting/V1beta1/Gapic/ErrorStatsServiceGapicClient.php index dd7b6a5e6fc9..5e833bc5f004 100644 --- a/src/ErrorReporting/V1beta1/Gapic/ErrorStatsServiceGapicClient.php +++ b/src/ErrorReporting/V1beta1/Gapic/ErrorStatsServiceGapicClient.php @@ -177,8 +177,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } elseif (class_exists('\Google\Cloud\Version')) { + self::$gapicVersion = \Google\Cloud\Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/ErrorReporting/V1beta1/Gapic/ReportErrorsServiceGapicClient.php b/src/ErrorReporting/V1beta1/Gapic/ReportErrorsServiceGapicClient.php index 01f87b078ee0..93258f12101d 100644 --- a/src/ErrorReporting/V1beta1/Gapic/ReportErrorsServiceGapicClient.php +++ b/src/ErrorReporting/V1beta1/Gapic/ReportErrorsServiceGapicClient.php @@ -130,8 +130,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } elseif (class_exists('\Google\Cloud\Version')) { + self::$gapicVersion = \Google\Cloud\Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/Language/V1beta2/Gapic/LanguageServiceGapicClient.php b/src/Language/V1beta2/Gapic/LanguageServiceGapicClient.php index 2ccffa027f61..bab44de8f344 100644 --- a/src/Language/V1beta2/Gapic/LanguageServiceGapicClient.php +++ b/src/Language/V1beta2/Gapic/LanguageServiceGapicClient.php @@ -109,8 +109,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } elseif (class_exists('\Google\Cloud\Version')) { + self::$gapicVersion = \Google\Cloud\Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/Logging/V2/Gapic/ConfigServiceV2GapicClient.php b/src/Logging/V2/Gapic/ConfigServiceV2GapicClient.php index 354d6e7c5abb..26d5afca2b09 100644 --- a/src/Logging/V2/Gapic/ConfigServiceV2GapicClient.php +++ b/src/Logging/V2/Gapic/ConfigServiceV2GapicClient.php @@ -176,8 +176,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } elseif (class_exists('\Google\Cloud\Version')) { + self::$gapicVersion = \Google\Cloud\Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/Logging/V2/Gapic/LoggingServiceV2GapicClient.php b/src/Logging/V2/Gapic/LoggingServiceV2GapicClient.php index 20ce81b71f87..c96774d859e6 100644 --- a/src/Logging/V2/Gapic/LoggingServiceV2GapicClient.php +++ b/src/Logging/V2/Gapic/LoggingServiceV2GapicClient.php @@ -184,8 +184,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } elseif (class_exists('\Google\Cloud\Version')) { + self::$gapicVersion = \Google\Cloud\Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/Logging/V2/Gapic/MetricsServiceV2GapicClient.php b/src/Logging/V2/Gapic/MetricsServiceV2GapicClient.php index 482c8846b1d3..d71dc3ff6a8a 100644 --- a/src/Logging/V2/Gapic/MetricsServiceV2GapicClient.php +++ b/src/Logging/V2/Gapic/MetricsServiceV2GapicClient.php @@ -175,8 +175,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } elseif (class_exists('\Google\Cloud\Version')) { + self::$gapicVersion = \Google\Cloud\Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/Monitoring/V3/Gapic/GroupServiceGapicClient.php b/src/Monitoring/V3/Gapic/GroupServiceGapicClient.php index de9dd9476b96..7dc86adba3e5 100644 --- a/src/Monitoring/V3/Gapic/GroupServiceGapicClient.php +++ b/src/Monitoring/V3/Gapic/GroupServiceGapicClient.php @@ -198,8 +198,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } elseif (class_exists('\Google\Cloud\Version')) { + self::$gapicVersion = \Google\Cloud\Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/Monitoring/V3/Gapic/MetricServiceGapicClient.php b/src/Monitoring/V3/Gapic/MetricServiceGapicClient.php index aef92da27616..e016bd863013 100644 --- a/src/Monitoring/V3/Gapic/MetricServiceGapicClient.php +++ b/src/Monitoring/V3/Gapic/MetricServiceGapicClient.php @@ -214,8 +214,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } elseif (class_exists('\Google\Cloud\Version')) { + self::$gapicVersion = \Google\Cloud\Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/PubSub/V1/Gapic/PublisherGapicClient.php b/src/PubSub/V1/Gapic/PublisherGapicClient.php index c74acdd16611..010420957950 100644 --- a/src/PubSub/V1/Gapic/PublisherGapicClient.php +++ b/src/PubSub/V1/Gapic/PublisherGapicClient.php @@ -181,8 +181,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } elseif (class_exists('\Google\Cloud\Version')) { + self::$gapicVersion = \Google\Cloud\Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/PubSub/V1/Gapic/SubscriberGapicClient.php b/src/PubSub/V1/Gapic/SubscriberGapicClient.php index 1c8c172bf482..ceaa1ce25ac4 100644 --- a/src/PubSub/V1/Gapic/SubscriberGapicClient.php +++ b/src/PubSub/V1/Gapic/SubscriberGapicClient.php @@ -223,8 +223,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } elseif (class_exists('\Google\Cloud\Version')) { + self::$gapicVersion = \Google\Cloud\Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/Spanner/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php b/src/Spanner/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php index 0e0b65fae666..abe4eda648ac 100644 --- a/src/Spanner/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php +++ b/src/Spanner/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php @@ -203,8 +203,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } elseif (class_exists('\Google\Cloud\Version')) { + self::$gapicVersion = \Google\Cloud\Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/Spanner/Admin/Instance/V1/Gapic/InstanceAdminGapicClient.php b/src/Spanner/Admin/Instance/V1/Gapic/InstanceAdminGapicClient.php index 712248a3c5cf..57ed28957180 100644 --- a/src/Spanner/Admin/Instance/V1/Gapic/InstanceAdminGapicClient.php +++ b/src/Spanner/Admin/Instance/V1/Gapic/InstanceAdminGapicClient.php @@ -242,8 +242,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } elseif (class_exists('\Google\Cloud\Version')) { + self::$gapicVersion = \Google\Cloud\Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/Spanner/V1/Gapic/SpannerGapicClient.php b/src/Spanner/V1/Gapic/SpannerGapicClient.php index 64e4248cb116..6de78e9e9c24 100644 --- a/src/Spanner/V1/Gapic/SpannerGapicClient.php +++ b/src/Spanner/V1/Gapic/SpannerGapicClient.php @@ -167,8 +167,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } elseif (class_exists('\Google\Cloud\Version')) { + self::$gapicVersion = \Google\Cloud\Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/Speech/V1/Gapic/SpeechGapicClient.php b/src/Speech/V1/Gapic/SpeechGapicClient.php index 08258748bf06..34006c986a0d 100644 --- a/src/Speech/V1/Gapic/SpeechGapicClient.php +++ b/src/Speech/V1/Gapic/SpeechGapicClient.php @@ -136,8 +136,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } elseif (class_exists('\Google\Cloud\Version')) { + self::$gapicVersion = \Google\Cloud\Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/Speech/V1beta1/Gapic/SpeechGapicClient.php b/src/Speech/V1beta1/Gapic/SpeechGapicClient.php index 384f8f2008f8..7ea6915f5b91 100644 --- a/src/Speech/V1beta1/Gapic/SpeechGapicClient.php +++ b/src/Speech/V1beta1/Gapic/SpeechGapicClient.php @@ -134,8 +134,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } elseif (class_exists('\Google\Cloud\Version')) { + self::$gapicVersion = \Google\Cloud\Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/VideoIntelligence/V1beta1/Gapic/VideoIntelligenceServiceGapicClient.php b/src/VideoIntelligence/V1beta1/Gapic/VideoIntelligenceServiceGapicClient.php index 650785060207..831ff530a422 100644 --- a/src/VideoIntelligence/V1beta1/Gapic/VideoIntelligenceServiceGapicClient.php +++ b/src/VideoIntelligence/V1beta1/Gapic/VideoIntelligenceServiceGapicClient.php @@ -143,8 +143,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } elseif (class_exists('\Google\Cloud\Version')) { + self::$gapicVersion = \Google\Cloud\Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/VideoIntelligence/V1beta2/Gapic/VideoIntelligenceServiceGapicClient.php b/src/VideoIntelligence/V1beta2/Gapic/VideoIntelligenceServiceGapicClient.php index 7337b930b682..56e8390c517f 100644 --- a/src/VideoIntelligence/V1beta2/Gapic/VideoIntelligenceServiceGapicClient.php +++ b/src/VideoIntelligence/V1beta2/Gapic/VideoIntelligenceServiceGapicClient.php @@ -143,8 +143,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } elseif (class_exists('\Google\Cloud\Version')) { + self::$gapicVersion = \Google\Cloud\Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/Vision/V1/Gapic/ImageAnnotatorGapicClient.php b/src/Vision/V1/Gapic/ImageAnnotatorGapicClient.php index f4fd0175f9f6..6d84fcfe4775 100644 --- a/src/Vision/V1/Gapic/ImageAnnotatorGapicClient.php +++ b/src/Vision/V1/Gapic/ImageAnnotatorGapicClient.php @@ -103,8 +103,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - self::$gapicVersion = \Google\Cloud\ServiceBuilder::VERSION; + } elseif (class_exists('\Google\Cloud\Version')) { + self::$gapicVersion = \Google\Cloud\Version::VERSION; } self::$gapicVersionLoaded = true; } From 0e47dd405aa98beffec3c5d6dd3b31e4acecc089 Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Mon, 18 Sep 2017 17:08:53 -0700 Subject: [PATCH 07/17] Update snippets, remove updateSubscription method --- src/PubSub/Subscription.php | 46 ---------------------- tests/snippets/PubSub/SubscriptionTest.php | 13 ------ tests/snippets/Spanner/DatabaseTest.php | 2 +- 3 files changed, 1 insertion(+), 60 deletions(-) diff --git a/src/PubSub/Subscription.php b/src/PubSub/Subscription.php index 0b70412195b4..062c7431eb11 100644 --- a/src/PubSub/Subscription.php +++ b/src/PubSub/Subscription.php @@ -222,52 +222,6 @@ public function create(array $options = []) return $this->info; } - /** - * Update the subscription. - * - * Note that subscription name and topic are immutable properties and may - * not be modified. - * - * Example: - * ``` - * $subscription->update([ - * 'retainAckedMessages' => true - * ]); - * ``` - * - * @param array $subscription { - * The Subscription data. - * - * For information regarding the push configuration settings, see - * [PushConfig](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions#PushConfig). - * - * @type string $pushConfig.pushEndpoint A URL locating the endpoint to which - * messages should be pushed. For example, a Webhook endpoint - * might use "https://example.com/push". - * @type array $pushConfig.attributes Endpoint configuration attributes. - * @type int $ackDeadlineSeconds The maximum time after a subscriber - * receives a message before the subscriber should acknowledge the - * message. - * @type bool $retainAckedMessages Indicates whether to retain - * acknowledged messages. - * @type Duration $messageRetentionDuration How long to retain - * unacknowledged messages in the subscription's backlog, from the - * moment a message is published. If `$retainAckedMessages` is - * true, then this also configures the retention of acknowledged - * messages, and thus configures how far back in time a `Seek` - * can be done. Cannot be more than 7 days or less than 10 minutes. - * **Defaults to** 7 days. - * } - * @param array $options [optional] Configuration options. - * @return array The subscription info. - */ - public function update(array $subscription, array $options = []) - { - return $this->info = $this->connection->updateSubscription([ - 'name' => $this->name - ] + $options + $subscription); - } - /** * Delete a subscription * diff --git a/tests/snippets/PubSub/SubscriptionTest.php b/tests/snippets/PubSub/SubscriptionTest.php index df9c6e9f94de..90e02847641d 100644 --- a/tests/snippets/PubSub/SubscriptionTest.php +++ b/tests/snippets/PubSub/SubscriptionTest.php @@ -95,19 +95,6 @@ public function testCreate() $this->assertEquals($return, $res->returnVal()); } - public function testUpdate() - { - $snippet = $this->snippetFromMethod(Subscription::class, 'update'); - $snippet->addLocal('subscription', $this->subscription); - - $this->connection->updateSubscription(Argument::any()) - ->shouldBeCalled(); - - $this->subscription->___setProperty('connection', $this->connection->reveal()); - - $snippet->invoke(); - } - public function testDelete() { $snippet = $this->snippetFromMethod(Subscription::class, 'delete'); diff --git a/tests/snippets/Spanner/DatabaseTest.php b/tests/snippets/Spanner/DatabaseTest.php index 1e173dfe9afc..5218e566b56f 100644 --- a/tests/snippets/Spanner/DatabaseTest.php +++ b/tests/snippets/Spanner/DatabaseTest.php @@ -115,7 +115,7 @@ public function testName() $snippet = $this->snippetFromMethod(Database::class, 'name'); $snippet->addLocal('database', $this->database); $res = $snippet->invoke('name'); - $this->assertEquals(self::DATABASE, DatabaseAdminClient::parseName($res->returnVal()->name())['database']); + $this->assertEquals(self::DATABASE, DatabaseAdminClient::parseName($res->returnVal())['database']); } /** From 4d34a2638c16325512bc6a83208afe9ddbee2e3a Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Mon, 18 Sep 2017 17:12:21 -0700 Subject: [PATCH 08/17] Update gax and proto-client versions --- composer.json | 4 ++-- src/Dlp/composer.json | 4 ++-- src/ErrorReporting/composer.json | 4 ++-- src/Logging/composer.json | 4 ++-- src/Monitoring/composer.json | 4 ++-- src/PubSub/composer.json | 4 ++-- src/Spanner/composer.json | 4 ++-- src/VideoIntelligence/composer.json | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index d4d9090b09bc..e947486ee221 100644 --- a/composer.json +++ b/composer.json @@ -48,8 +48,8 @@ "monolog/monolog": "~1", "psr/http-message": "1.0.*", "ramsey/uuid": "~3", - "google/proto-client": "^0.23", - "google/gax": "dev-master" + "google/proto-client": "^0.24", + "google/gax": "^0.24" }, "require-dev": { "phpunit/phpunit": "4.8.*", diff --git a/src/Dlp/composer.json b/src/Dlp/composer.json index 2517284eeac5..9ca671c40c2e 100644 --- a/src/Dlp/composer.json +++ b/src/Dlp/composer.json @@ -5,8 +5,8 @@ "minimum-stability": "stable", "require": { "ext-grpc": "*", - "google/proto-client": "^0.23", - "google/gax": "^0.23" + "google/proto-client": "^0.24", + "google/gax": "^0.24" }, "extra": { "component": { diff --git a/src/ErrorReporting/composer.json b/src/ErrorReporting/composer.json index 49995e53f507..79f9eb403124 100644 --- a/src/ErrorReporting/composer.json +++ b/src/ErrorReporting/composer.json @@ -5,8 +5,8 @@ "minimum-stability": "stable", "require": { "ext-grpc": "*", - "google/proto-client": "^0.23", - "google/gax": "^0.23" + "google/proto-client": "^0.24", + "google/gax": "^0.24" }, "extra": { "component": { diff --git a/src/Logging/composer.json b/src/Logging/composer.json index 45139b96972e..765a167bb149 100644 --- a/src/Logging/composer.json +++ b/src/Logging/composer.json @@ -5,8 +5,8 @@ "minimum-stability": "stable", "require": { "google/cloud-core": "^1.0", - "google/proto-client": "^0.23", - "google/gax": "^0.23" + "google/proto-client": "^0.24", + "google/gax": "^0.24" }, "extra": { "component": { diff --git a/src/Monitoring/composer.json b/src/Monitoring/composer.json index af65f34c43ae..a645c0c3d240 100644 --- a/src/Monitoring/composer.json +++ b/src/Monitoring/composer.json @@ -5,8 +5,8 @@ "minimum-stability": "stable", "require": { "ext-grpc": "*", - "google/proto-client": "^0.23", - "google/gax": "^0.23" + "google/proto-client": "^0.24", + "google/gax": "^0.24" }, "extra": { "component": { diff --git a/src/PubSub/composer.json b/src/PubSub/composer.json index 2905183aceb6..141239d288f4 100644 --- a/src/PubSub/composer.json +++ b/src/PubSub/composer.json @@ -5,8 +5,8 @@ "minimum-stability": "stable", "require": { "google/cloud-core": "^1.0", - "google/proto-client": "^0.23", - "google/gax": "^0.23" + "google/proto-client": "^0.24", + "google/gax": "^0.24" }, "extra": { "component": { diff --git a/src/Spanner/composer.json b/src/Spanner/composer.json index 7feb40e19026..91449ee85829 100644 --- a/src/Spanner/composer.json +++ b/src/Spanner/composer.json @@ -6,8 +6,8 @@ "require": { "ext-grpc": "*", "google/cloud-core": "^1.5", - "google/gax": "^0.23", - "google/proto-client": "^0.23" + "google/gax": "^0.24", + "google/proto-client": "^0.24" }, "extra": { "component": { diff --git a/src/VideoIntelligence/composer.json b/src/VideoIntelligence/composer.json index 848c1328da1c..b6b1568b362b 100644 --- a/src/VideoIntelligence/composer.json +++ b/src/VideoIntelligence/composer.json @@ -5,8 +5,8 @@ "minimum-stability": "stable", "require": { "ext-grpc": "*", - "google/proto-client": "^0.23", - "google/gax": "^0.23" + "google/proto-client": "^0.24", + "google/gax": "^0.24" }, "extra": { "component": { From 7624c0844b969bde26973697813d233856413dd9 Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Mon, 18 Sep 2017 17:26:24 -0700 Subject: [PATCH 09/17] Manually edit resources files --- src/PubSub/V1/resources/publisher_client_config.json | 5 ----- src/PubSub/V1/resources/subscriber_client_config.json | 10 ---------- 2 files changed, 15 deletions(-) diff --git a/src/PubSub/V1/resources/publisher_client_config.json b/src/PubSub/V1/resources/publisher_client_config.json index b1e3be747fd0..9fb679cbad27 100644 --- a/src/PubSub/V1/resources/publisher_client_config.json +++ b/src/PubSub/V1/resources/publisher_client_config.json @@ -43,11 +43,6 @@ "retry_codes_name": "idempotent", "retry_params_name": "default" }, - "UpdateTopic": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "default" - }, "Publish": { "timeout_millis": 60000, "retry_codes_name": "one_plus_delivery", diff --git a/src/PubSub/V1/resources/subscriber_client_config.json b/src/PubSub/V1/resources/subscriber_client_config.json index 37a5f16fe8f7..7ff702e30ee5 100644 --- a/src/PubSub/V1/resources/subscriber_client_config.json +++ b/src/PubSub/V1/resources/subscriber_client_config.json @@ -55,11 +55,6 @@ "retry_codes_name": "idempotent", "retry_params_name": "default" }, - "UpdateSubscription": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "default" - }, "ListSubscriptions": { "timeout_millis": 60000, "retry_codes_name": "idempotent", @@ -103,11 +98,6 @@ "retry_codes_name": "idempotent", "retry_params_name": "default" }, - "UpdateSnapshot": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "default" - }, "DeleteSnapshot": { "timeout_millis": 60000, "retry_codes_name": "idempotent", From a89299c0a3df335b553f50636162eede5eae166d Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Tue, 19 Sep 2017 09:00:03 -0700 Subject: [PATCH 10/17] Address PR comments --- src/Core/GrpcRequestWrapper.php | 2 +- src/Spanner/Database.php | 6 ++---- src/Spanner/Instance.php | 3 +-- src/Spanner/SpannerClient.php | 9 +++------ 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/Core/GrpcRequestWrapper.php b/src/Core/GrpcRequestWrapper.php index e9246cd5c9cc..ddac1112ef39 100644 --- a/src/Core/GrpcRequestWrapper.php +++ b/src/Core/GrpcRequestWrapper.php @@ -134,7 +134,7 @@ public function send(callable $request, array $args, array $options = []) $retrySettings = [ 'retriesEnabled' => false ]; - if ($timeout && !array_key_exists('timeoutMs', $grpcOptions)) { + if ($timeout) { $retrySettings['noRetriesRpcTimeoutMillis'] = $timeout * 1000; } $grpcOptions['retrySettings'] = $retrySettings; diff --git a/src/Spanner/Database.php b/src/Spanner/Database.php index fd0b4ff6fff3..5ac65974bdf5 100644 --- a/src/Spanner/Database.php +++ b/src/Spanner/Database.php @@ -309,8 +309,7 @@ public function create(array $options = []) 'statements' => [], ]; - $databaseNameComponents = DatabaseAdminClient::parseName($this->name()); - $databaseName = $databaseNameComponents['database']; + $databaseName = DatabaseAdminClient::parseName($this->name())['database']; $statement = sprintf('CREATE DATABASE `%s`', $databaseName); $operation = $this->connection->createDatabase([ @@ -1529,8 +1528,7 @@ private function commitInSingleUseTransaction(array $mutations, array $options = */ private function fullyQualifiedDatabaseName($name) { - $instanceNameComponents = InstanceAdminClient::parseName($this->instance->name()); - $instance = $instanceNameComponents['instance']; + $instance = InstanceAdminClient::parseName($this->instance->name())['instance']; try { return GapicSpannerClient::databaseName( diff --git a/src/Spanner/Instance.php b/src/Spanner/Instance.php index 3b0293d7d93d..56f8f34499a9 100644 --- a/src/Spanner/Instance.php +++ b/src/Spanner/Instance.php @@ -268,8 +268,7 @@ public function reload(array $options = []) */ public function create(InstanceConfiguration $config, array $options = []) { - $instanceNameComponents = InstanceAdminClient::parseName($this->name); - $instanceId = $instanceNameComponents['instance']; + $instanceId = InstanceAdminClient::parseName($this->name)['instance']; $options += [ 'displayName' => $instanceId, 'nodeCount' => self::DEFAULT_NODE_COUNT, diff --git a/src/Spanner/SpannerClient.php b/src/Spanner/SpannerClient.php index eb61c0bcb27c..b322288ad556 100644 --- a/src/Spanner/SpannerClient.php +++ b/src/Spanner/SpannerClient.php @@ -127,8 +127,7 @@ public function __construct(array $config = []) [ 'typeUrl' => 'type.googleapis.com/google.spanner.admin.instance.v1.UpdateInstanceMetadata', 'callable' => function ($instance) { - $instanceNameComponents = InstanceAdminClient::parseName($instance['name']); - $name = $instanceNameComponents['instance']; + $name = InstanceAdminClient::parseName($instance['name'])['instance']; return $this->instance($name, $instance); } ], [ @@ -144,8 +143,7 @@ public function __construct(array $config = []) ], [ 'typeUrl' => 'type.googleapis.com/google.spanner.admin.instance.v1.CreateInstanceMetadata', 'callable' => function ($instance) { - $instanceNameComponents = InstanceAdminClient::parseName($instance['name']); - $name = $instanceNameComponents['instance']; + $name = InstanceAdminClient::parseName($instance['name'])['instance']; return $this->instance($name, $instance); } ] @@ -312,8 +310,7 @@ public function instances(array $options = []) return new ItemIterator( new PageIterator( function (array $instance) { - $instanceNameComponents = InstanceAdminClient::parseName($instance['name']); - $name = $instanceNameComponents['instance']; + $name = InstanceAdminClient::parseName($instance['name'])['instance']; return $this->instance($name, $instance); }, [$this->connection, 'listInstances'], From 72e62f1e6ccd63c0c975f5199d0b252248e4e200 Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Tue, 19 Sep 2017 09:03:21 -0700 Subject: [PATCH 11/17] Update GAPICs with changes to toolkit to address PR comments --- .../V2beta1/Gapic/DlpServiceGapicClient.php | 18 +-- .../Gapic/ErrorGroupServiceGapicClient.php | 17 +-- .../Gapic/ErrorStatsServiceGapicClient.php | 17 +-- .../Gapic/ReportErrorsServiceGapicClient.php | 17 +-- .../Gapic/LanguageServiceGapicClient.php | 14 +- .../V2/Gapic/ConfigServiceV2GapicClient.php | 17 +-- .../V2/Gapic/LoggingServiceV2GapicClient.php | 17 +-- .../V2/Gapic/MetricsServiceV2GapicClient.php | 17 +-- .../V3/Gapic/GroupServiceGapicClient.php | 17 +-- .../V3/Gapic/MetricServiceGapicClient.php | 17 +-- src/PubSub/V1/Gapic/PublisherGapicClient.php | 80 ++++++++-- src/PubSub/V1/Gapic/SubscriberGapicClient.php | 143 ++++++++++++++++-- .../V1/resources/publisher_client_config.json | 5 + .../resources/subscriber_client_config.json | 10 ++ .../V1/Gapic/DatabaseAdminGapicClient.php | 18 +-- .../V1/Gapic/InstanceAdminGapicClient.php | 18 +-- src/Spanner/V1/Gapic/SpannerGapicClient.php | 17 +-- src/Speech/V1/Gapic/SpeechGapicClient.php | 15 +- .../V1beta1/Gapic/SpeechGapicClient.php | 15 +- .../VideoIntelligenceServiceGapicClient.php | 15 +- .../VideoIntelligenceServiceGapicClient.php | 15 +- .../V1/Gapic/ImageAnnotatorGapicClient.php | 14 +- 22 files changed, 332 insertions(+), 201 deletions(-) diff --git a/src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php b/src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php index d653a361e2c7..d1c2b78a45dd 100644 --- a/src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php +++ b/src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php @@ -108,11 +108,6 @@ class DlpServiceGapicClient */ const DEFAULT_SERVICE_PORT = 443; - /** - * The default timeout for non-retrying methods. - */ - const DEFAULT_TIMEOUT_MILLIS = 30000; - /** * The name of the code generator, to be included in the agent header. */ @@ -124,8 +119,8 @@ class DlpServiceGapicClient const CODEGEN_VERSION = '0.0.5'; private static $resultNameTemplate; - private static $pathTemplateList = null; - private static $gapicVersion = null; + private static $pathTemplateList; + private static $gapicVersion; private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; @@ -143,6 +138,7 @@ private static function getResultNameTemplate() return self::$resultNameTemplate; } + private static function getPathTemplateList() { if (self::$pathTemplateList == null) { @@ -282,14 +278,16 @@ public function resumeOperation($operationName, $methodName = null) * Path to a JSON file containing client method configuration, including retry settings. * Specify this setting to specify the retry behavior of all methods on the client. * By default this settings points to the default client config file, which is provided - * in the resources folder. + * in the resources folder. The retry settings provided in this option can be overridden + * by settings in $retryingOverride * @type array $retryingOverride * An associative array in which the keys are method names (e.g. 'createFoo'), and * the values are retry settings to use for that method. The retry settings for each * method can be a {@see Google\GAX\RetrySettings} object, or an associative array * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} * for example usage. Passing a value of null is equivalent to a value of - * ['retriesEnabled' => false]. + * ['retriesEnabled' => false]. Retry settings provided in this setting override the + * settings in $clientConfigPath. * } * @experimental */ @@ -302,7 +300,6 @@ public function __construct($options = []) 'https://www.googleapis.com/auth/cloud-platform', ], 'retryingOverride' => null, - 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, 'clientConfigPath' => __DIR__.'/../resources/dlp_service_client_config.json', @@ -313,7 +310,6 @@ public function __construct($options = []) $this->operationsClient = $options['operationsClient']; } else { $operationsClientOptions = $options; - unset($operationsClientOptions['timeoutMillis']); unset($operationsClientOptions['retryingOverride']); unset($operationsClientOptions['clientConfigPath']); $this->operationsClient = new OperationsClient($operationsClientOptions); diff --git a/src/ErrorReporting/V1beta1/Gapic/ErrorGroupServiceGapicClient.php b/src/ErrorReporting/V1beta1/Gapic/ErrorGroupServiceGapicClient.php index cd527ec23661..3cf782e95af3 100644 --- a/src/ErrorReporting/V1beta1/Gapic/ErrorGroupServiceGapicClient.php +++ b/src/ErrorReporting/V1beta1/Gapic/ErrorGroupServiceGapicClient.php @@ -80,11 +80,6 @@ class ErrorGroupServiceGapicClient */ const DEFAULT_SERVICE_PORT = 443; - /** - * The default timeout for non-retrying methods. - */ - const DEFAULT_TIMEOUT_MILLIS = 30000; - /** * The name of the code generator, to be included in the agent header. */ @@ -96,8 +91,8 @@ class ErrorGroupServiceGapicClient const CODEGEN_VERSION = '0.0.5'; private static $groupNameTemplate; - private static $pathTemplateList = null; - private static $gapicVersion = null; + private static $pathTemplateList; + private static $gapicVersion; private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; @@ -114,6 +109,7 @@ private static function getGroupNameTemplate() return self::$groupNameTemplate; } + private static function getPathTemplateList() { if (self::$pathTemplateList == null) { @@ -207,14 +203,16 @@ public static function parseName($formattedName) * Path to a JSON file containing client method configuration, including retry settings. * Specify this setting to specify the retry behavior of all methods on the client. * By default this settings points to the default client config file, which is provided - * in the resources folder. + * in the resources folder. The retry settings provided in this option can be overridden + * by settings in $retryingOverride * @type array $retryingOverride * An associative array in which the keys are method names (e.g. 'createFoo'), and * the values are retry settings to use for that method. The retry settings for each * method can be a {@see Google\GAX\RetrySettings} object, or an associative array * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} * for example usage. Passing a value of null is equivalent to a value of - * ['retriesEnabled' => false]. + * ['retriesEnabled' => false]. Retry settings provided in this setting override the + * settings in $clientConfigPath. * } * @experimental */ @@ -227,7 +225,6 @@ public function __construct($options = []) 'https://www.googleapis.com/auth/cloud-platform', ], 'retryingOverride' => null, - 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, 'clientConfigPath' => __DIR__.'/../resources/error_group_service_client_config.json', diff --git a/src/ErrorReporting/V1beta1/Gapic/ErrorStatsServiceGapicClient.php b/src/ErrorReporting/V1beta1/Gapic/ErrorStatsServiceGapicClient.php index 5e833bc5f004..d8ab028be99a 100644 --- a/src/ErrorReporting/V1beta1/Gapic/ErrorStatsServiceGapicClient.php +++ b/src/ErrorReporting/V1beta1/Gapic/ErrorStatsServiceGapicClient.php @@ -99,11 +99,6 @@ class ErrorStatsServiceGapicClient */ const DEFAULT_SERVICE_PORT = 443; - /** - * The default timeout for non-retrying methods. - */ - const DEFAULT_TIMEOUT_MILLIS = 30000; - /** * The name of the code generator, to be included in the agent header. */ @@ -115,8 +110,8 @@ class ErrorStatsServiceGapicClient const CODEGEN_VERSION = '0.0.5'; private static $projectNameTemplate; - private static $pathTemplateList = null; - private static $gapicVersion = null; + private static $pathTemplateList; + private static $gapicVersion; private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; @@ -133,6 +128,7 @@ private static function getProjectNameTemplate() return self::$projectNameTemplate; } + private static function getPathTemplateList() { if (self::$pathTemplateList == null) { @@ -252,14 +248,16 @@ public static function parseName($formattedName) * Path to a JSON file containing client method configuration, including retry settings. * Specify this setting to specify the retry behavior of all methods on the client. * By default this settings points to the default client config file, which is provided - * in the resources folder. + * in the resources folder. The retry settings provided in this option can be overridden + * by settings in $retryingOverride * @type array $retryingOverride * An associative array in which the keys are method names (e.g. 'createFoo'), and * the values are retry settings to use for that method. The retry settings for each * method can be a {@see Google\GAX\RetrySettings} object, or an associative array * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} * for example usage. Passing a value of null is equivalent to a value of - * ['retriesEnabled' => false]. + * ['retriesEnabled' => false]. Retry settings provided in this setting override the + * settings in $clientConfigPath. * } * @experimental */ @@ -272,7 +270,6 @@ public function __construct($options = []) 'https://www.googleapis.com/auth/cloud-platform', ], 'retryingOverride' => null, - 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, 'clientConfigPath' => __DIR__.'/../resources/error_stats_service_client_config.json', diff --git a/src/ErrorReporting/V1beta1/Gapic/ReportErrorsServiceGapicClient.php b/src/ErrorReporting/V1beta1/Gapic/ReportErrorsServiceGapicClient.php index 93258f12101d..af271c5b70d5 100644 --- a/src/ErrorReporting/V1beta1/Gapic/ReportErrorsServiceGapicClient.php +++ b/src/ErrorReporting/V1beta1/Gapic/ReportErrorsServiceGapicClient.php @@ -80,11 +80,6 @@ class ReportErrorsServiceGapicClient */ const DEFAULT_SERVICE_PORT = 443; - /** - * The default timeout for non-retrying methods. - */ - const DEFAULT_TIMEOUT_MILLIS = 30000; - /** * The name of the code generator, to be included in the agent header. */ @@ -96,8 +91,8 @@ class ReportErrorsServiceGapicClient const CODEGEN_VERSION = '0.0.5'; private static $projectNameTemplate; - private static $pathTemplateList = null; - private static $gapicVersion = null; + private static $pathTemplateList; + private static $gapicVersion; private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; @@ -114,6 +109,7 @@ private static function getProjectNameTemplate() return self::$projectNameTemplate; } + private static function getPathTemplateList() { if (self::$pathTemplateList == null) { @@ -205,14 +201,16 @@ public static function parseName($formattedName) * Path to a JSON file containing client method configuration, including retry settings. * Specify this setting to specify the retry behavior of all methods on the client. * By default this settings points to the default client config file, which is provided - * in the resources folder. + * in the resources folder. The retry settings provided in this option can be overridden + * by settings in $retryingOverride * @type array $retryingOverride * An associative array in which the keys are method names (e.g. 'createFoo'), and * the values are retry settings to use for that method. The retry settings for each * method can be a {@see Google\GAX\RetrySettings} object, or an associative array * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} * for example usage. Passing a value of null is equivalent to a value of - * ['retriesEnabled' => false]. + * ['retriesEnabled' => false]. Retry settings provided in this setting override the + * settings in $clientConfigPath. * } * @experimental */ @@ -225,7 +223,6 @@ public function __construct($options = []) 'https://www.googleapis.com/auth/cloud-platform', ], 'retryingOverride' => null, - 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, 'clientConfigPath' => __DIR__.'/../resources/report_errors_service_client_config.json', diff --git a/src/Language/V1beta2/Gapic/LanguageServiceGapicClient.php b/src/Language/V1beta2/Gapic/LanguageServiceGapicClient.php index bab44de8f344..52694cbaf906 100644 --- a/src/Language/V1beta2/Gapic/LanguageServiceGapicClient.php +++ b/src/Language/V1beta2/Gapic/LanguageServiceGapicClient.php @@ -80,11 +80,6 @@ class LanguageServiceGapicClient */ const DEFAULT_SERVICE_PORT = 443; - /** - * The default timeout for non-retrying methods. - */ - const DEFAULT_TIMEOUT_MILLIS = 30000; - /** * The name of the code generator, to be included in the agent header. */ @@ -95,7 +90,7 @@ class LanguageServiceGapicClient */ const CODEGEN_VERSION = '0.0.5'; - private static $gapicVersion = null; + private static $gapicVersion; private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; @@ -146,14 +141,16 @@ private static function getGapicVersion() * Path to a JSON file containing client method configuration, including retry settings. * Specify this setting to specify the retry behavior of all methods on the client. * By default this settings points to the default client config file, which is provided - * in the resources folder. + * in the resources folder. The retry settings provided in this option can be overridden + * by settings in $retryingOverride * @type array $retryingOverride * An associative array in which the keys are method names (e.g. 'createFoo'), and * the values are retry settings to use for that method. The retry settings for each * method can be a {@see Google\GAX\RetrySettings} object, or an associative array * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} * for example usage. Passing a value of null is equivalent to a value of - * ['retriesEnabled' => false]. + * ['retriesEnabled' => false]. Retry settings provided in this setting override the + * settings in $clientConfigPath. * } * @experimental */ @@ -166,7 +163,6 @@ public function __construct($options = []) 'https://www.googleapis.com/auth/cloud-platform', ], 'retryingOverride' => null, - 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, 'clientConfigPath' => __DIR__.'/../resources/language_service_client_config.json', diff --git a/src/Logging/V2/Gapic/ConfigServiceV2GapicClient.php b/src/Logging/V2/Gapic/ConfigServiceV2GapicClient.php index 26d5afca2b09..adacb02dbeed 100644 --- a/src/Logging/V2/Gapic/ConfigServiceV2GapicClient.php +++ b/src/Logging/V2/Gapic/ConfigServiceV2GapicClient.php @@ -97,11 +97,6 @@ class ConfigServiceV2GapicClient */ const DEFAULT_SERVICE_PORT = 443; - /** - * The default timeout for non-retrying methods. - */ - const DEFAULT_TIMEOUT_MILLIS = 30000; - /** * The name of the code generator, to be included in the agent header. */ @@ -114,8 +109,8 @@ class ConfigServiceV2GapicClient private static $projectNameTemplate; private static $sinkNameTemplate; - private static $pathTemplateList = null; - private static $gapicVersion = null; + private static $pathTemplateList; + private static $gapicVersion; private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; @@ -141,6 +136,7 @@ private static function getSinkNameTemplate() return self::$sinkNameTemplate; } + private static function getPathTemplateList() { if (self::$pathTemplateList == null) { @@ -270,14 +266,16 @@ public static function parseName($formattedName) * Path to a JSON file containing client method configuration, including retry settings. * Specify this setting to specify the retry behavior of all methods on the client. * By default this settings points to the default client config file, which is provided - * in the resources folder. + * in the resources folder. The retry settings provided in this option can be overridden + * by settings in $retryingOverride * @type array $retryingOverride * An associative array in which the keys are method names (e.g. 'createFoo'), and * the values are retry settings to use for that method. The retry settings for each * method can be a {@see Google\GAX\RetrySettings} object, or an associative array * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} * for example usage. Passing a value of null is equivalent to a value of - * ['retriesEnabled' => false]. + * ['retriesEnabled' => false]. Retry settings provided in this setting override the + * settings in $clientConfigPath. * } * @experimental */ @@ -294,7 +292,6 @@ public function __construct($options = []) 'https://www.googleapis.com/auth/logging.write', ], 'retryingOverride' => null, - 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, 'clientConfigPath' => __DIR__.'/../resources/config_service_v2_client_config.json', diff --git a/src/Logging/V2/Gapic/LoggingServiceV2GapicClient.php b/src/Logging/V2/Gapic/LoggingServiceV2GapicClient.php index c96774d859e6..8ba5d9c0c794 100644 --- a/src/Logging/V2/Gapic/LoggingServiceV2GapicClient.php +++ b/src/Logging/V2/Gapic/LoggingServiceV2GapicClient.php @@ -85,11 +85,6 @@ class LoggingServiceV2GapicClient */ const DEFAULT_SERVICE_PORT = 443; - /** - * The default timeout for non-retrying methods. - */ - const DEFAULT_TIMEOUT_MILLIS = 30000; - /** * The name of the code generator, to be included in the agent header. */ @@ -102,8 +97,8 @@ class LoggingServiceV2GapicClient private static $projectNameTemplate; private static $logNameTemplate; - private static $pathTemplateList = null; - private static $gapicVersion = null; + private static $pathTemplateList; + private static $gapicVersion; private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; @@ -129,6 +124,7 @@ private static function getLogNameTemplate() return self::$logNameTemplate; } + private static function getPathTemplateList() { if (self::$pathTemplateList == null) { @@ -278,14 +274,16 @@ public static function parseName($formattedName) * Path to a JSON file containing client method configuration, including retry settings. * Specify this setting to specify the retry behavior of all methods on the client. * By default this settings points to the default client config file, which is provided - * in the resources folder. + * in the resources folder. The retry settings provided in this option can be overridden + * by settings in $retryingOverride * @type array $retryingOverride * An associative array in which the keys are method names (e.g. 'createFoo'), and * the values are retry settings to use for that method. The retry settings for each * method can be a {@see Google\GAX\RetrySettings} object, or an associative array * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} * for example usage. Passing a value of null is equivalent to a value of - * ['retriesEnabled' => false]. + * ['retriesEnabled' => false]. Retry settings provided in this setting override the + * settings in $clientConfigPath. * } * @experimental */ @@ -302,7 +300,6 @@ public function __construct($options = []) 'https://www.googleapis.com/auth/logging.write', ], 'retryingOverride' => null, - 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, 'clientConfigPath' => __DIR__.'/../resources/logging_service_v2_client_config.json', diff --git a/src/Logging/V2/Gapic/MetricsServiceV2GapicClient.php b/src/Logging/V2/Gapic/MetricsServiceV2GapicClient.php index d71dc3ff6a8a..5bdf02e4e0cb 100644 --- a/src/Logging/V2/Gapic/MetricsServiceV2GapicClient.php +++ b/src/Logging/V2/Gapic/MetricsServiceV2GapicClient.php @@ -96,11 +96,6 @@ class MetricsServiceV2GapicClient */ const DEFAULT_SERVICE_PORT = 443; - /** - * The default timeout for non-retrying methods. - */ - const DEFAULT_TIMEOUT_MILLIS = 30000; - /** * The name of the code generator, to be included in the agent header. */ @@ -113,8 +108,8 @@ class MetricsServiceV2GapicClient private static $projectNameTemplate; private static $metricNameTemplate; - private static $pathTemplateList = null; - private static $gapicVersion = null; + private static $pathTemplateList; + private static $gapicVersion; private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; @@ -140,6 +135,7 @@ private static function getMetricNameTemplate() return self::$metricNameTemplate; } + private static function getPathTemplateList() { if (self::$pathTemplateList == null) { @@ -269,14 +265,16 @@ public static function parseName($formattedName) * Path to a JSON file containing client method configuration, including retry settings. * Specify this setting to specify the retry behavior of all methods on the client. * By default this settings points to the default client config file, which is provided - * in the resources folder. + * in the resources folder. The retry settings provided in this option can be overridden + * by settings in $retryingOverride * @type array $retryingOverride * An associative array in which the keys are method names (e.g. 'createFoo'), and * the values are retry settings to use for that method. The retry settings for each * method can be a {@see Google\GAX\RetrySettings} object, or an associative array * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} * for example usage. Passing a value of null is equivalent to a value of - * ['retriesEnabled' => false]. + * ['retriesEnabled' => false]. Retry settings provided in this setting override the + * settings in $clientConfigPath. * } * @experimental */ @@ -293,7 +291,6 @@ public function __construct($options = []) 'https://www.googleapis.com/auth/logging.write', ], 'retryingOverride' => null, - 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, 'clientConfigPath' => __DIR__.'/../resources/metrics_service_v2_client_config.json', diff --git a/src/Monitoring/V3/Gapic/GroupServiceGapicClient.php b/src/Monitoring/V3/Gapic/GroupServiceGapicClient.php index 7dc86adba3e5..61eb25cd6c0f 100644 --- a/src/Monitoring/V3/Gapic/GroupServiceGapicClient.php +++ b/src/Monitoring/V3/Gapic/GroupServiceGapicClient.php @@ -109,11 +109,6 @@ class GroupServiceGapicClient */ const DEFAULT_SERVICE_PORT = 443; - /** - * The default timeout for non-retrying methods. - */ - const DEFAULT_TIMEOUT_MILLIS = 30000; - /** * The name of the code generator, to be included in the agent header. */ @@ -126,8 +121,8 @@ class GroupServiceGapicClient private static $projectNameTemplate; private static $groupNameTemplate; - private static $pathTemplateList = null; - private static $gapicVersion = null; + private static $pathTemplateList; + private static $gapicVersion; private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; @@ -153,6 +148,7 @@ private static function getGroupNameTemplate() return self::$groupNameTemplate; } + private static function getPathTemplateList() { if (self::$pathTemplateList == null) { @@ -292,14 +288,16 @@ public static function parseName($formattedName) * Path to a JSON file containing client method configuration, including retry settings. * Specify this setting to specify the retry behavior of all methods on the client. * By default this settings points to the default client config file, which is provided - * in the resources folder. + * in the resources folder. The retry settings provided in this option can be overridden + * by settings in $retryingOverride * @type array $retryingOverride * An associative array in which the keys are method names (e.g. 'createFoo'), and * the values are retry settings to use for that method. The retry settings for each * method can be a {@see Google\GAX\RetrySettings} object, or an associative array * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} * for example usage. Passing a value of null is equivalent to a value of - * ['retriesEnabled' => false]. + * ['retriesEnabled' => false]. Retry settings provided in this setting override the + * settings in $clientConfigPath. * } * @experimental */ @@ -315,7 +313,6 @@ public function __construct($options = []) 'https://www.googleapis.com/auth/monitoring.write', ], 'retryingOverride' => null, - 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, 'clientConfigPath' => __DIR__.'/../resources/group_service_client_config.json', diff --git a/src/Monitoring/V3/Gapic/MetricServiceGapicClient.php b/src/Monitoring/V3/Gapic/MetricServiceGapicClient.php index e016bd863013..e4b2d7d068e8 100644 --- a/src/Monitoring/V3/Gapic/MetricServiceGapicClient.php +++ b/src/Monitoring/V3/Gapic/MetricServiceGapicClient.php @@ -104,11 +104,6 @@ class MetricServiceGapicClient */ const DEFAULT_SERVICE_PORT = 443; - /** - * The default timeout for non-retrying methods. - */ - const DEFAULT_TIMEOUT_MILLIS = 30000; - /** * The name of the code generator, to be included in the agent header. */ @@ -122,8 +117,8 @@ class MetricServiceGapicClient private static $projectNameTemplate; private static $metricDescriptorNameTemplate; private static $monitoredResourceDescriptorNameTemplate; - private static $pathTemplateList = null; - private static $gapicVersion = null; + private static $pathTemplateList; + private static $gapicVersion; private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; @@ -158,6 +153,7 @@ private static function getMonitoredResourceDescriptorNameTemplate() return self::$monitoredResourceDescriptorNameTemplate; } + private static function getPathTemplateList() { if (self::$pathTemplateList == null) { @@ -327,14 +323,16 @@ public static function parseName($formattedName) * Path to a JSON file containing client method configuration, including retry settings. * Specify this setting to specify the retry behavior of all methods on the client. * By default this settings points to the default client config file, which is provided - * in the resources folder. + * in the resources folder. The retry settings provided in this option can be overridden + * by settings in $retryingOverride * @type array $retryingOverride * An associative array in which the keys are method names (e.g. 'createFoo'), and * the values are retry settings to use for that method. The retry settings for each * method can be a {@see Google\GAX\RetrySettings} object, or an associative array * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} * for example usage. Passing a value of null is equivalent to a value of - * ['retriesEnabled' => false]. + * ['retriesEnabled' => false]. Retry settings provided in this setting override the + * settings in $clientConfigPath. * } * @experimental */ @@ -350,7 +348,6 @@ public function __construct($options = []) 'https://www.googleapis.com/auth/monitoring.write', ], 'retryingOverride' => null, - 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, 'clientConfigPath' => __DIR__.'/../resources/metric_service_client_config.json', diff --git a/src/PubSub/V1/Gapic/PublisherGapicClient.php b/src/PubSub/V1/Gapic/PublisherGapicClient.php index 010420957950..cdc50ea83610 100644 --- a/src/PubSub/V1/Gapic/PublisherGapicClient.php +++ b/src/PubSub/V1/Gapic/PublisherGapicClient.php @@ -42,6 +42,7 @@ use Google\Iam\V1\Policy; use Google\Iam\V1\SetIamPolicyRequest; use Google\Iam\V1\TestIamPermissionsRequest; +use Google\Protobuf\FieldMask; use Google\Pubsub\V1\DeleteTopicRequest; use Google\Pubsub\V1\GetTopicRequest; use Google\Pubsub\V1\ListTopicSubscriptionsRequest; @@ -50,6 +51,7 @@ use Google\Pubsub\V1\PublisherGrpcClient; use Google\Pubsub\V1\PubsubMessage; use Google\Pubsub\V1\Topic; +use Google\Pubsub\V1\UpdateTopicRequest; /** * Service Description: The service that an application uses to manipulate topics, and to send @@ -91,11 +93,6 @@ class PublisherGapicClient */ const DEFAULT_SERVICE_PORT = 443; - /** - * The default timeout for non-retrying methods. - */ - const DEFAULT_TIMEOUT_MILLIS = 30000; - /** * The name of the code generator, to be included in the agent header. */ @@ -108,8 +105,8 @@ class PublisherGapicClient private static $projectNameTemplate; private static $topicNameTemplate; - private static $pathTemplateList = null; - private static $gapicVersion = null; + private static $pathTemplateList; + private static $gapicVersion; private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; @@ -136,6 +133,7 @@ private static function getTopicNameTemplate() return self::$topicNameTemplate; } + private static function getPathTemplateList() { if (self::$pathTemplateList == null) { @@ -275,14 +273,16 @@ public static function parseName($formattedName) * Path to a JSON file containing client method configuration, including retry settings. * Specify this setting to specify the retry behavior of all methods on the client. * By default this settings points to the default client config file, which is provided - * in the resources folder. + * in the resources folder. The retry settings provided in this option can be overridden + * by settings in $retryingOverride * @type array $retryingOverride * An associative array in which the keys are method names (e.g. 'createFoo'), and * the values are retry settings to use for that method. The retry settings for each * method can be a {@see Google\GAX\RetrySettings} object, or an associative array * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} * for example usage. Passing a value of null is equivalent to a value of - * ['retriesEnabled' => false]. + * ['retriesEnabled' => false]. Retry settings provided in this setting override the + * settings in $clientConfigPath. * } * @experimental */ @@ -296,7 +296,6 @@ public function __construct($options = []) 'https://www.googleapis.com/auth/pubsub', ], 'retryingOverride' => null, - 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, 'clientConfigPath' => __DIR__.'/../resources/publisher_client_config.json', @@ -314,6 +313,7 @@ public function __construct($options = []) $defaultDescriptors = ['headerDescriptor' => $headerDescriptor]; $this->descriptors = [ 'createTopic' => $defaultDescriptors, + 'updateTopic' => $defaultDescriptors, 'publish' => $defaultDescriptors, 'getTopic' => $defaultDescriptors, 'listTopics' => $defaultDescriptors, @@ -422,6 +422,66 @@ public function createTopic($name, $optionalArgs = []) ['call_credentials_callback' => $this->createCredentialsCallback()]); } + /** + * Updates an existing topic. Note that certain properties of a topic are not + * modifiable. Options settings follow the style guide: + * NOTE: The style guide requires body: "topic" instead of body: "*". + * Keeping the latter for internal consistency in V1, however it should be + * corrected in V2. See + * https://cloud.google.com/apis/design/standard_methods#update for details. + * + * Sample code: + * ``` + * try { + * $publisherClient = new PublisherClient(); + * $topic = new Topic(); + * $updateMask = new FieldMask(); + * $response = $publisherClient->updateTopic($topic, $updateMask); + * } finally { + * $publisherClient->close(); + * } + * ``` + * + * @param Topic $topic The topic to update. + * @param FieldMask $updateMask Indicates which fields in the provided topic to update. + * Must be specified and non-empty. + * @param array $optionalArgs { + * Optional. + * + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. + * } + * + * @return \Google\Pubsub\V1\Topic + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function updateTopic($topic, $updateMask, $optionalArgs = []) + { + $request = new UpdateTopicRequest(); + $request->setTopic($topic); + $request->setUpdateMask($updateMask); + + $mergedSettings = $this->defaultCallSettings['updateTopic']->merge( + new CallSettings($optionalArgs) + ); + $callable = ApiCallable::createApiCall( + $this->publisherStub, + 'UpdateTopic', + $mergedSettings, + $this->descriptors['updateTopic'] + ); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + /** * Adds one or more messages to the topic. Returns `NOT_FOUND` if the topic * does not exist. The message payload must not be empty; it must contain diff --git a/src/PubSub/V1/Gapic/SubscriberGapicClient.php b/src/PubSub/V1/Gapic/SubscriberGapicClient.php index ceaa1ce25ac4..8c562f4ef944 100644 --- a/src/PubSub/V1/Gapic/SubscriberGapicClient.php +++ b/src/PubSub/V1/Gapic/SubscriberGapicClient.php @@ -43,6 +43,7 @@ use Google\Iam\V1\SetIamPolicyRequest; use Google\Iam\V1\TestIamPermissionsRequest; use Google\Protobuf\Duration; +use Google\Protobuf\FieldMask; use Google\Protobuf\Timestamp; use Google\Pubsub\V1\AcknowledgeRequest; use Google\Pubsub\V1\CreateSnapshotRequest; @@ -56,9 +57,12 @@ use Google\Pubsub\V1\PullRequest; use Google\Pubsub\V1\PushConfig; use Google\Pubsub\V1\SeekRequest; +use Google\Pubsub\V1\Snapshot; use Google\Pubsub\V1\StreamingPullRequest; use Google\Pubsub\V1\SubscriberGrpcClient; use Google\Pubsub\V1\Subscription; +use Google\Pubsub\V1\UpdateSnapshotRequest; +use Google\Pubsub\V1\UpdateSubscriptionRequest; /** * Service Description: The service that an application uses to manipulate subscriptions and to @@ -101,11 +105,6 @@ class SubscriberGapicClient */ const DEFAULT_SERVICE_PORT = 443; - /** - * The default timeout for non-retrying methods. - */ - const DEFAULT_TIMEOUT_MILLIS = 30000; - /** * The name of the code generator, to be included in the agent header. */ @@ -120,8 +119,8 @@ class SubscriberGapicClient private static $snapshotNameTemplate; private static $subscriptionNameTemplate; private static $topicNameTemplate; - private static $pathTemplateList = null; - private static $gapicVersion = null; + private static $pathTemplateList; + private static $gapicVersion; private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; @@ -166,6 +165,7 @@ private static function getTopicNameTemplate() return self::$topicNameTemplate; } + private static function getPathTemplateList() { if (self::$pathTemplateList == null) { @@ -355,14 +355,16 @@ public static function parseName($formattedName) * Path to a JSON file containing client method configuration, including retry settings. * Specify this setting to specify the retry behavior of all methods on the client. * By default this settings points to the default client config file, which is provided - * in the resources folder. + * in the resources folder. The retry settings provided in this option can be overridden + * by settings in $retryingOverride * @type array $retryingOverride * An associative array in which the keys are method names (e.g. 'createFoo'), and * the values are retry settings to use for that method. The retry settings for each * method can be a {@see Google\GAX\RetrySettings} object, or an associative array * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} * for example usage. Passing a value of null is equivalent to a value of - * ['retriesEnabled' => false]. + * ['retriesEnabled' => false]. Retry settings provided in this setting override the + * settings in $clientConfigPath. * } * @experimental */ @@ -376,7 +378,6 @@ public function __construct($options = []) 'https://www.googleapis.com/auth/pubsub', ], 'retryingOverride' => null, - 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, 'clientConfigPath' => __DIR__.'/../resources/subscriber_client_config.json', @@ -395,6 +396,7 @@ public function __construct($options = []) $this->descriptors = [ 'createSubscription' => $defaultDescriptors, 'getSubscription' => $defaultDescriptors, + 'updateSubscription' => $defaultDescriptors, 'listSubscriptions' => $defaultDescriptors, 'deleteSubscription' => $defaultDescriptors, 'modifyAckDeadline' => $defaultDescriptors, @@ -404,6 +406,7 @@ public function __construct($options = []) 'modifyPushConfig' => $defaultDescriptors, 'listSnapshots' => $defaultDescriptors, 'createSnapshot' => $defaultDescriptors, + 'updateSnapshot' => $defaultDescriptors, 'deleteSnapshot' => $defaultDescriptors, 'seek' => $defaultDescriptors, 'setIamPolicy' => $defaultDescriptors, @@ -628,6 +631,66 @@ public function getSubscription($subscription, $optionalArgs = []) ['call_credentials_callback' => $this->createCredentialsCallback()]); } + /** + * Updates an existing subscription. Note that certain properties of a + * subscription, such as its topic, are not modifiable. + * NOTE: The style guide requires body: "subscription" instead of body: "*". + * Keeping the latter for internal consistency in V1, however it should be + * corrected in V2. See + * https://cloud.google.com/apis/design/standard_methods#update for details. + * + * Sample code: + * ``` + * try { + * $subscriberClient = new SubscriberClient(); + * $subscription = new Subscription(); + * $updateMask = new FieldMask(); + * $response = $subscriberClient->updateSubscription($subscription, $updateMask); + * } finally { + * $subscriberClient->close(); + * } + * ``` + * + * @param Subscription $subscription The updated subscription object. + * @param FieldMask $updateMask Indicates which fields in the provided subscription to update. + * Must be specified and non-empty. + * @param array $optionalArgs { + * Optional. + * + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. + * } + * + * @return \Google\Pubsub\V1\Subscription + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function updateSubscription($subscription, $updateMask, $optionalArgs = []) + { + $request = new UpdateSubscriptionRequest(); + $request->setSubscription($subscription); + $request->setUpdateMask($updateMask); + + $mergedSettings = $this->defaultCallSettings['updateSubscription']->merge( + new CallSettings($optionalArgs) + ); + $callable = ApiCallable::createApiCall( + $this->subscriberStub, + 'UpdateSubscription', + $mergedSettings, + $this->descriptors['updateSubscription'] + ); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + /** * Lists matching subscriptions. * @@ -1264,6 +1327,66 @@ public function createSnapshot($name, $subscription, $optionalArgs = []) ['call_credentials_callback' => $this->createCredentialsCallback()]); } + /** + * Updates an existing snapshot. Note that certain properties of a snapshot + * are not modifiable. + * NOTE: The style guide requires body: "snapshot" instead of body: "*". + * Keeping the latter for internal consistency in V1, however it should be + * corrected in V2. See + * https://cloud.google.com/apis/design/standard_methods#update for details. + * + * Sample code: + * ``` + * try { + * $subscriberClient = new SubscriberClient(); + * $snapshot = new Snapshot(); + * $updateMask = new FieldMask(); + * $response = $subscriberClient->updateSnapshot($snapshot, $updateMask); + * } finally { + * $subscriberClient->close(); + * } + * ``` + * + * @param Snapshot $snapshot The updated snpashot object. + * @param FieldMask $updateMask Indicates which fields in the provided snapshot to update. + * Must be specified and non-empty. + * @param array $optionalArgs { + * Optional. + * + * @type \Google\GAX\RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\GAX\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\GAX\RetrySettings} for example usage. + * } + * + * @return \Google\Pubsub\V1\Snapshot + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function updateSnapshot($snapshot, $updateMask, $optionalArgs = []) + { + $request = new UpdateSnapshotRequest(); + $request->setSnapshot($snapshot); + $request->setUpdateMask($updateMask); + + $mergedSettings = $this->defaultCallSettings['updateSnapshot']->merge( + new CallSettings($optionalArgs) + ); + $callable = ApiCallable::createApiCall( + $this->subscriberStub, + 'UpdateSnapshot', + $mergedSettings, + $this->descriptors['updateSnapshot'] + ); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + /** * Removes an existing snapshot. All messages retained in the snapshot * are immediately dropped. After a snapshot is deleted, a new one may be diff --git a/src/PubSub/V1/resources/publisher_client_config.json b/src/PubSub/V1/resources/publisher_client_config.json index 9fb679cbad27..b1e3be747fd0 100644 --- a/src/PubSub/V1/resources/publisher_client_config.json +++ b/src/PubSub/V1/resources/publisher_client_config.json @@ -43,6 +43,11 @@ "retry_codes_name": "idempotent", "retry_params_name": "default" }, + "UpdateTopic": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, "Publish": { "timeout_millis": 60000, "retry_codes_name": "one_plus_delivery", diff --git a/src/PubSub/V1/resources/subscriber_client_config.json b/src/PubSub/V1/resources/subscriber_client_config.json index 7ff702e30ee5..37a5f16fe8f7 100644 --- a/src/PubSub/V1/resources/subscriber_client_config.json +++ b/src/PubSub/V1/resources/subscriber_client_config.json @@ -55,6 +55,11 @@ "retry_codes_name": "idempotent", "retry_params_name": "default" }, + "UpdateSubscription": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, "ListSubscriptions": { "timeout_millis": 60000, "retry_codes_name": "idempotent", @@ -98,6 +103,11 @@ "retry_codes_name": "idempotent", "retry_params_name": "default" }, + "UpdateSnapshot": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, "DeleteSnapshot": { "timeout_millis": 60000, "retry_codes_name": "idempotent", diff --git a/src/Spanner/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php b/src/Spanner/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php index abe4eda648ac..26ea48e4a6fe 100644 --- a/src/Spanner/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php +++ b/src/Spanner/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php @@ -109,11 +109,6 @@ class DatabaseAdminGapicClient */ const DEFAULT_SERVICE_PORT = 443; - /** - * The default timeout for non-retrying methods. - */ - const DEFAULT_TIMEOUT_MILLIS = 30000; - /** * The name of the code generator, to be included in the agent header. */ @@ -126,8 +121,8 @@ class DatabaseAdminGapicClient private static $instanceNameTemplate; private static $databaseNameTemplate; - private static $pathTemplateList = null; - private static $gapicVersion = null; + private static $pathTemplateList; + private static $gapicVersion; private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; @@ -154,6 +149,7 @@ private static function getDatabaseNameTemplate() return self::$databaseNameTemplate; } + private static function getPathTemplateList() { if (self::$pathTemplateList == null) { @@ -339,14 +335,16 @@ public function resumeOperation($operationName, $methodName = null) * Path to a JSON file containing client method configuration, including retry settings. * Specify this setting to specify the retry behavior of all methods on the client. * By default this settings points to the default client config file, which is provided - * in the resources folder. + * in the resources folder. The retry settings provided in this option can be overridden + * by settings in $retryingOverride * @type array $retryingOverride * An associative array in which the keys are method names (e.g. 'createFoo'), and * the values are retry settings to use for that method. The retry settings for each * method can be a {@see Google\GAX\RetrySettings} object, or an associative array * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} * for example usage. Passing a value of null is equivalent to a value of - * ['retriesEnabled' => false]. + * ['retriesEnabled' => false]. Retry settings provided in this setting override the + * settings in $clientConfigPath. * } * @experimental */ @@ -360,7 +358,6 @@ public function __construct($options = []) 'https://www.googleapis.com/auth/spanner.admin', ], 'retryingOverride' => null, - 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, 'clientConfigPath' => __DIR__.'/../resources/database_admin_client_config.json', @@ -371,7 +368,6 @@ public function __construct($options = []) $this->operationsClient = $options['operationsClient']; } else { $operationsClientOptions = $options; - unset($operationsClientOptions['timeoutMillis']); unset($operationsClientOptions['retryingOverride']); unset($operationsClientOptions['clientConfigPath']); $this->operationsClient = new OperationsClient($operationsClientOptions); diff --git a/src/Spanner/Admin/Instance/V1/Gapic/InstanceAdminGapicClient.php b/src/Spanner/Admin/Instance/V1/Gapic/InstanceAdminGapicClient.php index 57ed28957180..389e6f6c5878 100644 --- a/src/Spanner/Admin/Instance/V1/Gapic/InstanceAdminGapicClient.php +++ b/src/Spanner/Admin/Instance/V1/Gapic/InstanceAdminGapicClient.php @@ -127,11 +127,6 @@ class InstanceAdminGapicClient */ const DEFAULT_SERVICE_PORT = 443; - /** - * The default timeout for non-retrying methods. - */ - const DEFAULT_TIMEOUT_MILLIS = 30000; - /** * The name of the code generator, to be included in the agent header. */ @@ -145,8 +140,8 @@ class InstanceAdminGapicClient private static $projectNameTemplate; private static $instanceConfigNameTemplate; private static $instanceNameTemplate; - private static $pathTemplateList = null; - private static $gapicVersion = null; + private static $pathTemplateList; + private static $gapicVersion; private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; @@ -182,6 +177,7 @@ private static function getInstanceNameTemplate() return self::$instanceNameTemplate; } + private static function getPathTemplateList() { if (self::$pathTemplateList == null) { @@ -393,14 +389,16 @@ public function resumeOperation($operationName, $methodName = null) * Path to a JSON file containing client method configuration, including retry settings. * Specify this setting to specify the retry behavior of all methods on the client. * By default this settings points to the default client config file, which is provided - * in the resources folder. + * in the resources folder. The retry settings provided in this option can be overridden + * by settings in $retryingOverride * @type array $retryingOverride * An associative array in which the keys are method names (e.g. 'createFoo'), and * the values are retry settings to use for that method. The retry settings for each * method can be a {@see Google\GAX\RetrySettings} object, or an associative array * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} * for example usage. Passing a value of null is equivalent to a value of - * ['retriesEnabled' => false]. + * ['retriesEnabled' => false]. Retry settings provided in this setting override the + * settings in $clientConfigPath. * } * @experimental */ @@ -414,7 +412,6 @@ public function __construct($options = []) 'https://www.googleapis.com/auth/spanner.admin', ], 'retryingOverride' => null, - 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, 'clientConfigPath' => __DIR__.'/../resources/instance_admin_client_config.json', @@ -425,7 +422,6 @@ public function __construct($options = []) $this->operationsClient = $options['operationsClient']; } else { $operationsClientOptions = $options; - unset($operationsClientOptions['timeoutMillis']); unset($operationsClientOptions['retryingOverride']); unset($operationsClientOptions['clientConfigPath']); $this->operationsClient = new OperationsClient($operationsClientOptions); diff --git a/src/Spanner/V1/Gapic/SpannerGapicClient.php b/src/Spanner/V1/Gapic/SpannerGapicClient.php index 6de78e9e9c24..7b983627884e 100644 --- a/src/Spanner/V1/Gapic/SpannerGapicClient.php +++ b/src/Spanner/V1/Gapic/SpannerGapicClient.php @@ -94,11 +94,6 @@ class SpannerGapicClient */ const DEFAULT_SERVICE_PORT = 443; - /** - * The default timeout for non-retrying methods. - */ - const DEFAULT_TIMEOUT_MILLIS = 30000; - /** * The name of the code generator, to be included in the agent header. */ @@ -111,8 +106,8 @@ class SpannerGapicClient private static $databaseNameTemplate; private static $sessionNameTemplate; - private static $pathTemplateList = null; - private static $gapicVersion = null; + private static $pathTemplateList; + private static $gapicVersion; private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; @@ -138,6 +133,7 @@ private static function getSessionNameTemplate() return self::$sessionNameTemplate; } + private static function getPathTemplateList() { if (self::$pathTemplateList == null) { @@ -269,14 +265,16 @@ public static function parseName($formattedName) * Path to a JSON file containing client method configuration, including retry settings. * Specify this setting to specify the retry behavior of all methods on the client. * By default this settings points to the default client config file, which is provided - * in the resources folder. + * in the resources folder. The retry settings provided in this option can be overridden + * by settings in $retryingOverride * @type array $retryingOverride * An associative array in which the keys are method names (e.g. 'createFoo'), and * the values are retry settings to use for that method. The retry settings for each * method can be a {@see Google\GAX\RetrySettings} object, or an associative array * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} * for example usage. Passing a value of null is equivalent to a value of - * ['retriesEnabled' => false]. + * ['retriesEnabled' => false]. Retry settings provided in this setting override the + * settings in $clientConfigPath. * } * @experimental */ @@ -290,7 +288,6 @@ public function __construct($options = []) 'https://www.googleapis.com/auth/spanner.data', ], 'retryingOverride' => null, - 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, 'clientConfigPath' => __DIR__.'/../resources/spanner_client_config.json', diff --git a/src/Speech/V1/Gapic/SpeechGapicClient.php b/src/Speech/V1/Gapic/SpeechGapicClient.php index 34006c986a0d..a99a445cebde 100644 --- a/src/Speech/V1/Gapic/SpeechGapicClient.php +++ b/src/Speech/V1/Gapic/SpeechGapicClient.php @@ -87,11 +87,6 @@ class SpeechGapicClient */ const DEFAULT_SERVICE_PORT = 443; - /** - * The default timeout for non-retrying methods. - */ - const DEFAULT_TIMEOUT_MILLIS = 30000; - /** * The name of the code generator, to be included in the agent header. */ @@ -102,7 +97,7 @@ class SpeechGapicClient */ const CODEGEN_VERSION = '0.0.5'; - private static $gapicVersion = null; + private static $gapicVersion; private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; @@ -211,14 +206,16 @@ public function resumeOperation($operationName, $methodName = null) * Path to a JSON file containing client method configuration, including retry settings. * Specify this setting to specify the retry behavior of all methods on the client. * By default this settings points to the default client config file, which is provided - * in the resources folder. + * in the resources folder. The retry settings provided in this option can be overridden + * by settings in $retryingOverride * @type array $retryingOverride * An associative array in which the keys are method names (e.g. 'createFoo'), and * the values are retry settings to use for that method. The retry settings for each * method can be a {@see Google\GAX\RetrySettings} object, or an associative array * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} * for example usage. Passing a value of null is equivalent to a value of - * ['retriesEnabled' => false]. + * ['retriesEnabled' => false]. Retry settings provided in this setting override the + * settings in $clientConfigPath. * } * @experimental */ @@ -231,7 +228,6 @@ public function __construct($options = []) 'https://www.googleapis.com/auth/cloud-platform', ], 'retryingOverride' => null, - 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, 'clientConfigPath' => __DIR__.'/../resources/speech_client_config.json', @@ -242,7 +238,6 @@ public function __construct($options = []) $this->operationsClient = $options['operationsClient']; } else { $operationsClientOptions = $options; - unset($operationsClientOptions['timeoutMillis']); unset($operationsClientOptions['retryingOverride']); unset($operationsClientOptions['clientConfigPath']); $this->operationsClient = new OperationsClient($operationsClientOptions); diff --git a/src/Speech/V1beta1/Gapic/SpeechGapicClient.php b/src/Speech/V1beta1/Gapic/SpeechGapicClient.php index 7ea6915f5b91..f4fd0b72652a 100644 --- a/src/Speech/V1beta1/Gapic/SpeechGapicClient.php +++ b/src/Speech/V1beta1/Gapic/SpeechGapicClient.php @@ -85,11 +85,6 @@ class SpeechGapicClient */ const DEFAULT_SERVICE_PORT = 443; - /** - * The default timeout for non-retrying methods. - */ - const DEFAULT_TIMEOUT_MILLIS = 30000; - /** * The name of the code generator, to be included in the agent header. */ @@ -100,7 +95,7 @@ class SpeechGapicClient */ const CODEGEN_VERSION = '0.0.5'; - private static $gapicVersion = null; + private static $gapicVersion; private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; @@ -209,14 +204,16 @@ public function resumeOperation($operationName, $methodName = null) * Path to a JSON file containing client method configuration, including retry settings. * Specify this setting to specify the retry behavior of all methods on the client. * By default this settings points to the default client config file, which is provided - * in the resources folder. + * in the resources folder. The retry settings provided in this option can be overridden + * by settings in $retryingOverride * @type array $retryingOverride * An associative array in which the keys are method names (e.g. 'createFoo'), and * the values are retry settings to use for that method. The retry settings for each * method can be a {@see Google\GAX\RetrySettings} object, or an associative array * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} * for example usage. Passing a value of null is equivalent to a value of - * ['retriesEnabled' => false]. + * ['retriesEnabled' => false]. Retry settings provided in this setting override the + * settings in $clientConfigPath. * } * @experimental */ @@ -229,7 +226,6 @@ public function __construct($options = []) 'https://www.googleapis.com/auth/cloud-platform', ], 'retryingOverride' => null, - 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, 'clientConfigPath' => __DIR__.'/../resources/speech_client_config.json', @@ -240,7 +236,6 @@ public function __construct($options = []) $this->operationsClient = $options['operationsClient']; } else { $operationsClientOptions = $options; - unset($operationsClientOptions['timeoutMillis']); unset($operationsClientOptions['retryingOverride']); unset($operationsClientOptions['clientConfigPath']); $this->operationsClient = new OperationsClient($operationsClientOptions); diff --git a/src/VideoIntelligence/V1beta1/Gapic/VideoIntelligenceServiceGapicClient.php b/src/VideoIntelligence/V1beta1/Gapic/VideoIntelligenceServiceGapicClient.php index 831ff530a422..8379a6d96cf2 100644 --- a/src/VideoIntelligence/V1beta1/Gapic/VideoIntelligenceServiceGapicClient.php +++ b/src/VideoIntelligence/V1beta1/Gapic/VideoIntelligenceServiceGapicClient.php @@ -103,11 +103,6 @@ class VideoIntelligenceServiceGapicClient */ const DEFAULT_SERVICE_PORT = 443; - /** - * The default timeout for non-retrying methods. - */ - const DEFAULT_TIMEOUT_MILLIS = 30000; - /** * The name of the code generator, to be included in the agent header. */ @@ -118,7 +113,7 @@ class VideoIntelligenceServiceGapicClient */ const CODEGEN_VERSION = '0.0.5'; - private static $gapicVersion = null; + private static $gapicVersion; private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; @@ -218,14 +213,16 @@ public function resumeOperation($operationName, $methodName = null) * Path to a JSON file containing client method configuration, including retry settings. * Specify this setting to specify the retry behavior of all methods on the client. * By default this settings points to the default client config file, which is provided - * in the resources folder. + * in the resources folder. The retry settings provided in this option can be overridden + * by settings in $retryingOverride * @type array $retryingOverride * An associative array in which the keys are method names (e.g. 'createFoo'), and * the values are retry settings to use for that method. The retry settings for each * method can be a {@see Google\GAX\RetrySettings} object, or an associative array * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} * for example usage. Passing a value of null is equivalent to a value of - * ['retriesEnabled' => false]. + * ['retriesEnabled' => false]. Retry settings provided in this setting override the + * settings in $clientConfigPath. * } * @experimental */ @@ -238,7 +235,6 @@ public function __construct($options = []) 'https://www.googleapis.com/auth/cloud-platform', ], 'retryingOverride' => null, - 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, 'clientConfigPath' => __DIR__.'/../resources/video_intelligence_service_client_config.json', @@ -249,7 +245,6 @@ public function __construct($options = []) $this->operationsClient = $options['operationsClient']; } else { $operationsClientOptions = $options; - unset($operationsClientOptions['timeoutMillis']); unset($operationsClientOptions['retryingOverride']); unset($operationsClientOptions['clientConfigPath']); $this->operationsClient = new OperationsClient($operationsClientOptions); diff --git a/src/VideoIntelligence/V1beta2/Gapic/VideoIntelligenceServiceGapicClient.php b/src/VideoIntelligence/V1beta2/Gapic/VideoIntelligenceServiceGapicClient.php index 56e8390c517f..770cba0c45bf 100644 --- a/src/VideoIntelligence/V1beta2/Gapic/VideoIntelligenceServiceGapicClient.php +++ b/src/VideoIntelligence/V1beta2/Gapic/VideoIntelligenceServiceGapicClient.php @@ -103,11 +103,6 @@ class VideoIntelligenceServiceGapicClient */ const DEFAULT_SERVICE_PORT = 443; - /** - * The default timeout for non-retrying methods. - */ - const DEFAULT_TIMEOUT_MILLIS = 30000; - /** * The name of the code generator, to be included in the agent header. */ @@ -118,7 +113,7 @@ class VideoIntelligenceServiceGapicClient */ const CODEGEN_VERSION = '0.0.5'; - private static $gapicVersion = null; + private static $gapicVersion; private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; @@ -218,14 +213,16 @@ public function resumeOperation($operationName, $methodName = null) * Path to a JSON file containing client method configuration, including retry settings. * Specify this setting to specify the retry behavior of all methods on the client. * By default this settings points to the default client config file, which is provided - * in the resources folder. + * in the resources folder. The retry settings provided in this option can be overridden + * by settings in $retryingOverride * @type array $retryingOverride * An associative array in which the keys are method names (e.g. 'createFoo'), and * the values are retry settings to use for that method. The retry settings for each * method can be a {@see Google\GAX\RetrySettings} object, or an associative array * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} * for example usage. Passing a value of null is equivalent to a value of - * ['retriesEnabled' => false]. + * ['retriesEnabled' => false]. Retry settings provided in this setting override the + * settings in $clientConfigPath. * } * @experimental */ @@ -238,7 +235,6 @@ public function __construct($options = []) 'https://www.googleapis.com/auth/cloud-platform', ], 'retryingOverride' => null, - 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, 'clientConfigPath' => __DIR__.'/../resources/video_intelligence_service_client_config.json', @@ -249,7 +245,6 @@ public function __construct($options = []) $this->operationsClient = $options['operationsClient']; } else { $operationsClientOptions = $options; - unset($operationsClientOptions['timeoutMillis']); unset($operationsClientOptions['retryingOverride']); unset($operationsClientOptions['clientConfigPath']); $this->operationsClient = new OperationsClient($operationsClientOptions); diff --git a/src/Vision/V1/Gapic/ImageAnnotatorGapicClient.php b/src/Vision/V1/Gapic/ImageAnnotatorGapicClient.php index 6d84fcfe4775..d311d45836b7 100644 --- a/src/Vision/V1/Gapic/ImageAnnotatorGapicClient.php +++ b/src/Vision/V1/Gapic/ImageAnnotatorGapicClient.php @@ -74,11 +74,6 @@ class ImageAnnotatorGapicClient */ const DEFAULT_SERVICE_PORT = 443; - /** - * The default timeout for non-retrying methods. - */ - const DEFAULT_TIMEOUT_MILLIS = 30000; - /** * The name of the code generator, to be included in the agent header. */ @@ -89,7 +84,7 @@ class ImageAnnotatorGapicClient */ const CODEGEN_VERSION = '0.0.5'; - private static $gapicVersion = null; + private static $gapicVersion; private static $gapicVersionLoaded = false; protected $grpcCredentialsHelper; @@ -140,14 +135,16 @@ private static function getGapicVersion() * Path to a JSON file containing client method configuration, including retry settings. * Specify this setting to specify the retry behavior of all methods on the client. * By default this settings points to the default client config file, which is provided - * in the resources folder. + * in the resources folder. The retry settings provided in this option can be overridden + * by settings in $retryingOverride * @type array $retryingOverride * An associative array in which the keys are method names (e.g. 'createFoo'), and * the values are retry settings to use for that method. The retry settings for each * method can be a {@see Google\GAX\RetrySettings} object, or an associative array * of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings} * for example usage. Passing a value of null is equivalent to a value of - * ['retriesEnabled' => false]. + * ['retriesEnabled' => false]. Retry settings provided in this setting override the + * settings in $clientConfigPath. * } * @experimental */ @@ -160,7 +157,6 @@ public function __construct($options = []) 'https://www.googleapis.com/auth/cloud-platform', ], 'retryingOverride' => null, - 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'libName' => null, 'libVersion' => null, 'clientConfigPath' => __DIR__.'/../resources/image_annotator_client_config.json', From d3b5b602bbff34030592d7f5202c5a8209b5753e Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Tue, 19 Sep 2017 10:36:02 -0700 Subject: [PATCH 12/17] Update gapics --- .../V2beta1/Gapic/DlpServiceGapicClient.php | 38 ++++++++++---- .../Gapic/ErrorGroupServiceGapicClient.php | 38 ++++++++++---- .../Gapic/ErrorStatsServiceGapicClient.php | 38 ++++++++++---- .../Gapic/ReportErrorsServiceGapicClient.php | 38 ++++++++++---- .../Gapic/LanguageServiceGapicClient.php | 5 +- .../V2/Gapic/ConfigServiceV2GapicClient.php | 42 +++++++++++----- .../V2/Gapic/LoggingServiceV2GapicClient.php | 42 +++++++++++----- .../V2/Gapic/MetricsServiceV2GapicClient.php | 42 +++++++++++----- .../V3/Gapic/GroupServiceGapicClient.php | 42 +++++++++++----- .../V3/Gapic/MetricServiceGapicClient.php | 46 +++++++++++------ src/PubSub/V1/Gapic/PublisherGapicClient.php | 42 +++++++++++----- src/PubSub/V1/Gapic/SubscriberGapicClient.php | 50 ++++++++++++------- .../V1/Gapic/DatabaseAdminGapicClient.php | 42 +++++++++++----- .../V1/Gapic/InstanceAdminGapicClient.php | 46 +++++++++++------ src/Spanner/V1/Gapic/SpannerGapicClient.php | 42 +++++++++++----- src/Speech/V1/Gapic/SpeechGapicClient.php | 5 +- .../V1beta1/Gapic/SpeechGapicClient.php | 5 +- .../VideoIntelligenceServiceGapicClient.php | 5 +- .../VideoIntelligenceServiceGapicClient.php | 5 +- .../V1/Gapic/ImageAnnotatorGapicClient.php | 5 +- 20 files changed, 424 insertions(+), 194 deletions(-) diff --git a/src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php b/src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php index d1c2b78a45dd..ed2ae16bc31c 100644 --- a/src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php +++ b/src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php @@ -30,6 +30,7 @@ namespace Google\Cloud\Dlp\V2beta1\Gapic; +use Google\Cloud\Version; use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; @@ -119,7 +120,7 @@ class DlpServiceGapicClient const CODEGEN_VERSION = '0.0.5'; private static $resultNameTemplate; - private static $pathTemplateList; + private static $pathTemplateMap; private static $gapicVersion; private static $gapicVersionLoaded = false; @@ -139,15 +140,15 @@ private static function getResultNameTemplate() return self::$resultNameTemplate; } - private static function getPathTemplateList() + private static function getPathTemplateMap() { - if (self::$pathTemplateList == null) { - self::$pathTemplateList = [ - self::getResultNameTemplate(), + if (self::$pathTemplateMap == null) { + self::$pathTemplateMap = [ + 'result' => self::getResultNameTemplate(), ]; } - return self::$pathTemplateList; + return self::$pathTemplateMap; } private static function getLongRunningDescriptors() @@ -165,8 +166,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\Version')) { - self::$gapicVersion = \Google\Cloud\Version::VERSION; + } elseif (class_exists(Version::class)) { + self::$gapicVersion = Version::VERSION; } self::$gapicVersionLoaded = true; } @@ -193,16 +194,31 @@ public static function resultName($result) /** * Parses a formatted name string and returns an associative array of the components in the name. * The following name formats are supported: - * - inspect/results/{result}. + * Template: Pattern + * - result: inspect/results/{result}. + * + * The optional $template argument can be supplied to specify a particular pattern, and must + * match one of the templates listed above. If no $template argument is provided, or if the + * $template argument does not match one of the templates listed, then parseName will check + * each of the supported templates, and return the first match. * * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match * * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. * @experimental */ - public static function parseName($formattedName) + public static function parseName($formattedName, $template = null) { - foreach (self::getPathTemplateList() as $pathTemplate) { + $templateMap = self::getPathTemplateMap(); + + if (isset($templateMap[$template])) { + return $templateMap[$template]->match($formattedName); + } + + foreach ($templateMap as $templateName => $pathTemplate) { try { return $pathTemplate->match($formattedName); } catch (ValidationException $ex) { diff --git a/src/ErrorReporting/V1beta1/Gapic/ErrorGroupServiceGapicClient.php b/src/ErrorReporting/V1beta1/Gapic/ErrorGroupServiceGapicClient.php index 3cf782e95af3..c3a2dce33d27 100644 --- a/src/ErrorReporting/V1beta1/Gapic/ErrorGroupServiceGapicClient.php +++ b/src/ErrorReporting/V1beta1/Gapic/ErrorGroupServiceGapicClient.php @@ -30,6 +30,7 @@ namespace Google\Cloud\ErrorReporting\V1beta1\Gapic; +use Google\Cloud\Version; use Google\Devtools\Clouderrorreporting\V1beta1\ErrorGroup; use Google\Devtools\Clouderrorreporting\V1beta1\ErrorGroupServiceGrpcClient; use Google\Devtools\Clouderrorreporting\V1beta1\GetGroupRequest; @@ -91,7 +92,7 @@ class ErrorGroupServiceGapicClient const CODEGEN_VERSION = '0.0.5'; private static $groupNameTemplate; - private static $pathTemplateList; + private static $pathTemplateMap; private static $gapicVersion; private static $gapicVersionLoaded = false; @@ -110,15 +111,15 @@ private static function getGroupNameTemplate() return self::$groupNameTemplate; } - private static function getPathTemplateList() + private static function getPathTemplateMap() { - if (self::$pathTemplateList == null) { - self::$pathTemplateList = [ - self::getGroupNameTemplate(), + if (self::$pathTemplateMap == null) { + self::$pathTemplateMap = [ + 'group' => self::getGroupNameTemplate(), ]; } - return self::$pathTemplateList; + return self::$pathTemplateMap; } private static function getGapicVersion() @@ -126,8 +127,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\Version')) { - self::$gapicVersion = \Google\Cloud\Version::VERSION; + } elseif (class_exists(Version::class)) { + self::$gapicVersion = Version::VERSION; } self::$gapicVersionLoaded = true; } @@ -156,16 +157,31 @@ public static function groupName($project, $group) /** * Parses a formatted name string and returns an associative array of the components in the name. * The following name formats are supported: - * - projects/{project}/groups/{group}. + * Template: Pattern + * - group: projects/{project}/groups/{group}. + * + * The optional $template argument can be supplied to specify a particular pattern, and must + * match one of the templates listed above. If no $template argument is provided, or if the + * $template argument does not match one of the templates listed, then parseName will check + * each of the supported templates, and return the first match. * * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match * * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. * @experimental */ - public static function parseName($formattedName) + public static function parseName($formattedName, $template = null) { - foreach (self::getPathTemplateList() as $pathTemplate) { + $templateMap = self::getPathTemplateMap(); + + if (isset($templateMap[$template])) { + return $templateMap[$template]->match($formattedName); + } + + foreach ($templateMap as $templateName => $pathTemplate) { try { return $pathTemplate->match($formattedName); } catch (ValidationException $ex) { diff --git a/src/ErrorReporting/V1beta1/Gapic/ErrorStatsServiceGapicClient.php b/src/ErrorReporting/V1beta1/Gapic/ErrorStatsServiceGapicClient.php index d8ab028be99a..45212bb27e4d 100644 --- a/src/ErrorReporting/V1beta1/Gapic/ErrorStatsServiceGapicClient.php +++ b/src/ErrorReporting/V1beta1/Gapic/ErrorStatsServiceGapicClient.php @@ -30,6 +30,7 @@ namespace Google\Cloud\ErrorReporting\V1beta1\Gapic; +use Google\Cloud\Version; use Google\Devtools\Clouderrorreporting\V1beta1\DeleteEventsRequest; use Google\Devtools\Clouderrorreporting\V1beta1\ErrorStatsServiceGrpcClient; use Google\Devtools\Clouderrorreporting\V1beta1\ListEventsRequest; @@ -110,7 +111,7 @@ class ErrorStatsServiceGapicClient const CODEGEN_VERSION = '0.0.5'; private static $projectNameTemplate; - private static $pathTemplateList; + private static $pathTemplateMap; private static $gapicVersion; private static $gapicVersionLoaded = false; @@ -129,15 +130,15 @@ private static function getProjectNameTemplate() return self::$projectNameTemplate; } - private static function getPathTemplateList() + private static function getPathTemplateMap() { - if (self::$pathTemplateList == null) { - self::$pathTemplateList = [ - self::getProjectNameTemplate(), + if (self::$pathTemplateMap == null) { + self::$pathTemplateMap = [ + 'project' => self::getProjectNameTemplate(), ]; } - return self::$pathTemplateList; + return self::$pathTemplateMap; } private static function getPageStreamingDescriptors() { @@ -173,8 +174,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\Version')) { - self::$gapicVersion = \Google\Cloud\Version::VERSION; + } elseif (class_exists(Version::class)) { + self::$gapicVersion = Version::VERSION; } self::$gapicVersionLoaded = true; } @@ -201,16 +202,31 @@ public static function projectName($project) /** * Parses a formatted name string and returns an associative array of the components in the name. * The following name formats are supported: - * - projects/{project}. + * Template: Pattern + * - project: projects/{project}. + * + * The optional $template argument can be supplied to specify a particular pattern, and must + * match one of the templates listed above. If no $template argument is provided, or if the + * $template argument does not match one of the templates listed, then parseName will check + * each of the supported templates, and return the first match. * * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match * * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. * @experimental */ - public static function parseName($formattedName) + public static function parseName($formattedName, $template = null) { - foreach (self::getPathTemplateList() as $pathTemplate) { + $templateMap = self::getPathTemplateMap(); + + if (isset($templateMap[$template])) { + return $templateMap[$template]->match($formattedName); + } + + foreach ($templateMap as $templateName => $pathTemplate) { try { return $pathTemplate->match($formattedName); } catch (ValidationException $ex) { diff --git a/src/ErrorReporting/V1beta1/Gapic/ReportErrorsServiceGapicClient.php b/src/ErrorReporting/V1beta1/Gapic/ReportErrorsServiceGapicClient.php index af271c5b70d5..2880f50f4153 100644 --- a/src/ErrorReporting/V1beta1/Gapic/ReportErrorsServiceGapicClient.php +++ b/src/ErrorReporting/V1beta1/Gapic/ReportErrorsServiceGapicClient.php @@ -30,6 +30,7 @@ namespace Google\Cloud\ErrorReporting\V1beta1\Gapic; +use Google\Cloud\Version; use Google\Devtools\Clouderrorreporting\V1beta1\ReportErrorEventRequest; use Google\Devtools\Clouderrorreporting\V1beta1\ReportErrorsServiceGrpcClient; use Google\Devtools\Clouderrorreporting\V1beta1\ReportedErrorEvent; @@ -91,7 +92,7 @@ class ReportErrorsServiceGapicClient const CODEGEN_VERSION = '0.0.5'; private static $projectNameTemplate; - private static $pathTemplateList; + private static $pathTemplateMap; private static $gapicVersion; private static $gapicVersionLoaded = false; @@ -110,15 +111,15 @@ private static function getProjectNameTemplate() return self::$projectNameTemplate; } - private static function getPathTemplateList() + private static function getPathTemplateMap() { - if (self::$pathTemplateList == null) { - self::$pathTemplateList = [ - self::getProjectNameTemplate(), + if (self::$pathTemplateMap == null) { + self::$pathTemplateMap = [ + 'project' => self::getProjectNameTemplate(), ]; } - return self::$pathTemplateList; + return self::$pathTemplateMap; } private static function getGapicVersion() @@ -126,8 +127,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\Version')) { - self::$gapicVersion = \Google\Cloud\Version::VERSION; + } elseif (class_exists(Version::class)) { + self::$gapicVersion = Version::VERSION; } self::$gapicVersionLoaded = true; } @@ -154,16 +155,31 @@ public static function projectName($project) /** * Parses a formatted name string and returns an associative array of the components in the name. * The following name formats are supported: - * - projects/{project}. + * Template: Pattern + * - project: projects/{project}. + * + * The optional $template argument can be supplied to specify a particular pattern, and must + * match one of the templates listed above. If no $template argument is provided, or if the + * $template argument does not match one of the templates listed, then parseName will check + * each of the supported templates, and return the first match. * * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match * * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. * @experimental */ - public static function parseName($formattedName) + public static function parseName($formattedName, $template = null) { - foreach (self::getPathTemplateList() as $pathTemplate) { + $templateMap = self::getPathTemplateMap(); + + if (isset($templateMap[$template])) { + return $templateMap[$template]->match($formattedName); + } + + foreach ($templateMap as $templateName => $pathTemplate) { try { return $pathTemplate->match($formattedName); } catch (ValidationException $ex) { diff --git a/src/Language/V1beta2/Gapic/LanguageServiceGapicClient.php b/src/Language/V1beta2/Gapic/LanguageServiceGapicClient.php index 52694cbaf906..af6600ca8e77 100644 --- a/src/Language/V1beta2/Gapic/LanguageServiceGapicClient.php +++ b/src/Language/V1beta2/Gapic/LanguageServiceGapicClient.php @@ -40,6 +40,7 @@ use Google\Cloud\Language\V1beta2\Document; use Google\Cloud\Language\V1beta2\EncodingType; use Google\Cloud\Language\V1beta2\LanguageServiceGrpcClient; +use Google\Cloud\Version; use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; @@ -104,8 +105,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\Version')) { - self::$gapicVersion = \Google\Cloud\Version::VERSION; + } elseif (class_exists(Version::class)) { + self::$gapicVersion = Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/Logging/V2/Gapic/ConfigServiceV2GapicClient.php b/src/Logging/V2/Gapic/ConfigServiceV2GapicClient.php index adacb02dbeed..08930e0e4a55 100644 --- a/src/Logging/V2/Gapic/ConfigServiceV2GapicClient.php +++ b/src/Logging/V2/Gapic/ConfigServiceV2GapicClient.php @@ -30,6 +30,7 @@ namespace Google\Cloud\Logging\V2\Gapic; +use Google\Cloud\Version; use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; @@ -109,7 +110,7 @@ class ConfigServiceV2GapicClient private static $projectNameTemplate; private static $sinkNameTemplate; - private static $pathTemplateList; + private static $pathTemplateMap; private static $gapicVersion; private static $gapicVersionLoaded = false; @@ -137,16 +138,16 @@ private static function getSinkNameTemplate() return self::$sinkNameTemplate; } - private static function getPathTemplateList() + private static function getPathTemplateMap() { - if (self::$pathTemplateList == null) { - self::$pathTemplateList = [ - self::getProjectNameTemplate(), - self::getSinkNameTemplate(), + if (self::$pathTemplateMap == null) { + self::$pathTemplateMap = [ + 'project' => self::getProjectNameTemplate(), + 'sink' => self::getSinkNameTemplate(), ]; } - return self::$pathTemplateList; + return self::$pathTemplateMap; } private static function getPageStreamingDescriptors() { @@ -172,8 +173,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\Version')) { - self::$gapicVersion = \Google\Cloud\Version::VERSION; + } elseif (class_exists(Version::class)) { + self::$gapicVersion = Version::VERSION; } self::$gapicVersionLoaded = true; } @@ -218,17 +219,32 @@ public static function sinkName($project, $sink) /** * Parses a formatted name string and returns an associative array of the components in the name. * The following name formats are supported: - * - projects/{project} - * - projects/{project}/sinks/{sink}. + * Template: Pattern + * - project: projects/{project} + * - sink: projects/{project}/sinks/{sink}. + * + * The optional $template argument can be supplied to specify a particular pattern, and must + * match one of the templates listed above. If no $template argument is provided, or if the + * $template argument does not match one of the templates listed, then parseName will check + * each of the supported templates, and return the first match. * * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match * * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. * @experimental */ - public static function parseName($formattedName) + public static function parseName($formattedName, $template = null) { - foreach (self::getPathTemplateList() as $pathTemplate) { + $templateMap = self::getPathTemplateMap(); + + if (isset($templateMap[$template])) { + return $templateMap[$template]->match($formattedName); + } + + foreach ($templateMap as $templateName => $pathTemplate) { try { return $pathTemplate->match($formattedName); } catch (ValidationException $ex) { diff --git a/src/Logging/V2/Gapic/LoggingServiceV2GapicClient.php b/src/Logging/V2/Gapic/LoggingServiceV2GapicClient.php index 8ba5d9c0c794..8f968dc90706 100644 --- a/src/Logging/V2/Gapic/LoggingServiceV2GapicClient.php +++ b/src/Logging/V2/Gapic/LoggingServiceV2GapicClient.php @@ -31,6 +31,7 @@ namespace Google\Cloud\Logging\V2\Gapic; use Google\Api\MonitoredResource; +use Google\Cloud\Version; use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; @@ -97,7 +98,7 @@ class LoggingServiceV2GapicClient private static $projectNameTemplate; private static $logNameTemplate; - private static $pathTemplateList; + private static $pathTemplateMap; private static $gapicVersion; private static $gapicVersionLoaded = false; @@ -125,16 +126,16 @@ private static function getLogNameTemplate() return self::$logNameTemplate; } - private static function getPathTemplateList() + private static function getPathTemplateMap() { - if (self::$pathTemplateList == null) { - self::$pathTemplateList = [ - self::getProjectNameTemplate(), - self::getLogNameTemplate(), + if (self::$pathTemplateMap == null) { + self::$pathTemplateMap = [ + 'project' => self::getProjectNameTemplate(), + 'log' => self::getLogNameTemplate(), ]; } - return self::$pathTemplateList; + return self::$pathTemplateMap; } private static function getPageStreamingDescriptors() { @@ -180,8 +181,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\Version')) { - self::$gapicVersion = \Google\Cloud\Version::VERSION; + } elseif (class_exists(Version::class)) { + self::$gapicVersion = Version::VERSION; } self::$gapicVersionLoaded = true; } @@ -226,17 +227,32 @@ public static function logName($project, $log) /** * Parses a formatted name string and returns an associative array of the components in the name. * The following name formats are supported: - * - projects/{project} - * - projects/{project}/logs/{log}. + * Template: Pattern + * - project: projects/{project} + * - log: projects/{project}/logs/{log}. + * + * The optional $template argument can be supplied to specify a particular pattern, and must + * match one of the templates listed above. If no $template argument is provided, or if the + * $template argument does not match one of the templates listed, then parseName will check + * each of the supported templates, and return the first match. * * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match * * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. * @experimental */ - public static function parseName($formattedName) + public static function parseName($formattedName, $template = null) { - foreach (self::getPathTemplateList() as $pathTemplate) { + $templateMap = self::getPathTemplateMap(); + + if (isset($templateMap[$template])) { + return $templateMap[$template]->match($formattedName); + } + + foreach ($templateMap as $templateName => $pathTemplate) { try { return $pathTemplate->match($formattedName); } catch (ValidationException $ex) { diff --git a/src/Logging/V2/Gapic/MetricsServiceV2GapicClient.php b/src/Logging/V2/Gapic/MetricsServiceV2GapicClient.php index 5bdf02e4e0cb..fb4fe265173d 100644 --- a/src/Logging/V2/Gapic/MetricsServiceV2GapicClient.php +++ b/src/Logging/V2/Gapic/MetricsServiceV2GapicClient.php @@ -30,6 +30,7 @@ namespace Google\Cloud\Logging\V2\Gapic; +use Google\Cloud\Version; use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; @@ -108,7 +109,7 @@ class MetricsServiceV2GapicClient private static $projectNameTemplate; private static $metricNameTemplate; - private static $pathTemplateList; + private static $pathTemplateMap; private static $gapicVersion; private static $gapicVersionLoaded = false; @@ -136,16 +137,16 @@ private static function getMetricNameTemplate() return self::$metricNameTemplate; } - private static function getPathTemplateList() + private static function getPathTemplateMap() { - if (self::$pathTemplateList == null) { - self::$pathTemplateList = [ - self::getProjectNameTemplate(), - self::getMetricNameTemplate(), + if (self::$pathTemplateMap == null) { + self::$pathTemplateMap = [ + 'project' => self::getProjectNameTemplate(), + 'metric' => self::getMetricNameTemplate(), ]; } - return self::$pathTemplateList; + return self::$pathTemplateMap; } private static function getPageStreamingDescriptors() { @@ -171,8 +172,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\Version')) { - self::$gapicVersion = \Google\Cloud\Version::VERSION; + } elseif (class_exists(Version::class)) { + self::$gapicVersion = Version::VERSION; } self::$gapicVersionLoaded = true; } @@ -217,17 +218,32 @@ public static function metricName($project, $metric) /** * Parses a formatted name string and returns an associative array of the components in the name. * The following name formats are supported: - * - projects/{project} - * - projects/{project}/metrics/{metric}. + * Template: Pattern + * - project: projects/{project} + * - metric: projects/{project}/metrics/{metric}. + * + * The optional $template argument can be supplied to specify a particular pattern, and must + * match one of the templates listed above. If no $template argument is provided, or if the + * $template argument does not match one of the templates listed, then parseName will check + * each of the supported templates, and return the first match. * * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match * * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. * @experimental */ - public static function parseName($formattedName) + public static function parseName($formattedName, $template = null) { - foreach (self::getPathTemplateList() as $pathTemplate) { + $templateMap = self::getPathTemplateMap(); + + if (isset($templateMap[$template])) { + return $templateMap[$template]->match($formattedName); + } + + foreach ($templateMap as $templateName => $pathTemplate) { try { return $pathTemplate->match($formattedName); } catch (ValidationException $ex) { diff --git a/src/Monitoring/V3/Gapic/GroupServiceGapicClient.php b/src/Monitoring/V3/Gapic/GroupServiceGapicClient.php index 61eb25cd6c0f..a5c9afa299e5 100644 --- a/src/Monitoring/V3/Gapic/GroupServiceGapicClient.php +++ b/src/Monitoring/V3/Gapic/GroupServiceGapicClient.php @@ -30,6 +30,7 @@ namespace Google\Cloud\Monitoring\V3\Gapic; +use Google\Cloud\Version; use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; @@ -121,7 +122,7 @@ class GroupServiceGapicClient private static $projectNameTemplate; private static $groupNameTemplate; - private static $pathTemplateList; + private static $pathTemplateMap; private static $gapicVersion; private static $gapicVersionLoaded = false; @@ -149,16 +150,16 @@ private static function getGroupNameTemplate() return self::$groupNameTemplate; } - private static function getPathTemplateList() + private static function getPathTemplateMap() { - if (self::$pathTemplateList == null) { - self::$pathTemplateList = [ - self::getProjectNameTemplate(), - self::getGroupNameTemplate(), + if (self::$pathTemplateMap == null) { + self::$pathTemplateMap = [ + 'project' => self::getProjectNameTemplate(), + 'group' => self::getGroupNameTemplate(), ]; } - return self::$pathTemplateList; + return self::$pathTemplateMap; } private static function getPageStreamingDescriptors() { @@ -194,8 +195,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\Version')) { - self::$gapicVersion = \Google\Cloud\Version::VERSION; + } elseif (class_exists(Version::class)) { + self::$gapicVersion = Version::VERSION; } self::$gapicVersionLoaded = true; } @@ -240,17 +241,32 @@ public static function groupName($project, $group) /** * Parses a formatted name string and returns an associative array of the components in the name. * The following name formats are supported: - * - projects/{project} - * - projects/{project}/groups/{group}. + * Template: Pattern + * - project: projects/{project} + * - group: projects/{project}/groups/{group}. + * + * The optional $template argument can be supplied to specify a particular pattern, and must + * match one of the templates listed above. If no $template argument is provided, or if the + * $template argument does not match one of the templates listed, then parseName will check + * each of the supported templates, and return the first match. * * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match * * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. * @experimental */ - public static function parseName($formattedName) + public static function parseName($formattedName, $template = null) { - foreach (self::getPathTemplateList() as $pathTemplate) { + $templateMap = self::getPathTemplateMap(); + + if (isset($templateMap[$template])) { + return $templateMap[$template]->match($formattedName); + } + + foreach ($templateMap as $templateName => $pathTemplate) { try { return $pathTemplate->match($formattedName); } catch (ValidationException $ex) { diff --git a/src/Monitoring/V3/Gapic/MetricServiceGapicClient.php b/src/Monitoring/V3/Gapic/MetricServiceGapicClient.php index e4b2d7d068e8..07c331cda959 100644 --- a/src/Monitoring/V3/Gapic/MetricServiceGapicClient.php +++ b/src/Monitoring/V3/Gapic/MetricServiceGapicClient.php @@ -31,6 +31,7 @@ namespace Google\Cloud\Monitoring\V3\Gapic; use Google\Api\MetricDescriptor; +use Google\Cloud\Version; use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; @@ -117,7 +118,7 @@ class MetricServiceGapicClient private static $projectNameTemplate; private static $metricDescriptorNameTemplate; private static $monitoredResourceDescriptorNameTemplate; - private static $pathTemplateList; + private static $pathTemplateMap; private static $gapicVersion; private static $gapicVersionLoaded = false; @@ -154,17 +155,17 @@ private static function getMonitoredResourceDescriptorNameTemplate() return self::$monitoredResourceDescriptorNameTemplate; } - private static function getPathTemplateList() + private static function getPathTemplateMap() { - if (self::$pathTemplateList == null) { - self::$pathTemplateList = [ - self::getProjectNameTemplate(), - self::getMetricDescriptorNameTemplate(), - self::getMonitoredResourceDescriptorNameTemplate(), + if (self::$pathTemplateMap == null) { + self::$pathTemplateMap = [ + 'project' => self::getProjectNameTemplate(), + 'metricDescriptor' => self::getMetricDescriptorNameTemplate(), + 'monitoredResourceDescriptor' => self::getMonitoredResourceDescriptorNameTemplate(), ]; } - return self::$pathTemplateList; + return self::$pathTemplateMap; } private static function getPageStreamingDescriptors() { @@ -210,8 +211,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\Version')) { - self::$gapicVersion = \Google\Cloud\Version::VERSION; + } elseif (class_exists(Version::class)) { + self::$gapicVersion = Version::VERSION; } self::$gapicVersionLoaded = true; } @@ -274,18 +275,33 @@ public static function monitoredResourceDescriptorName($project, $monitoredResou /** * Parses a formatted name string and returns an associative array of the components in the name. * The following name formats are supported: - * - projects/{project} - * - projects/{project}/metricDescriptors/{metric_descriptor=**} - * - projects/{project}/monitoredResourceDescriptors/{monitored_resource_descriptor}. + * Template: Pattern + * - project: projects/{project} + * - metricDescriptor: projects/{project}/metricDescriptors/{metric_descriptor=**} + * - monitoredResourceDescriptor: projects/{project}/monitoredResourceDescriptors/{monitored_resource_descriptor}. + * + * The optional $template argument can be supplied to specify a particular pattern, and must + * match one of the templates listed above. If no $template argument is provided, or if the + * $template argument does not match one of the templates listed, then parseName will check + * each of the supported templates, and return the first match. * * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match * * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. * @experimental */ - public static function parseName($formattedName) + public static function parseName($formattedName, $template = null) { - foreach (self::getPathTemplateList() as $pathTemplate) { + $templateMap = self::getPathTemplateMap(); + + if (isset($templateMap[$template])) { + return $templateMap[$template]->match($formattedName); + } + + foreach ($templateMap as $templateName => $pathTemplate) { try { return $pathTemplate->match($formattedName); } catch (ValidationException $ex) { diff --git a/src/PubSub/V1/Gapic/PublisherGapicClient.php b/src/PubSub/V1/Gapic/PublisherGapicClient.php index cdc50ea83610..e818b2b5f638 100644 --- a/src/PubSub/V1/Gapic/PublisherGapicClient.php +++ b/src/PubSub/V1/Gapic/PublisherGapicClient.php @@ -30,6 +30,7 @@ namespace Google\Cloud\PubSub\V1\Gapic; +use Google\Cloud\Version; use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; @@ -105,7 +106,7 @@ class PublisherGapicClient private static $projectNameTemplate; private static $topicNameTemplate; - private static $pathTemplateList; + private static $pathTemplateMap; private static $gapicVersion; private static $gapicVersionLoaded = false; @@ -134,16 +135,16 @@ private static function getTopicNameTemplate() return self::$topicNameTemplate; } - private static function getPathTemplateList() + private static function getPathTemplateMap() { - if (self::$pathTemplateList == null) { - self::$pathTemplateList = [ - self::getProjectNameTemplate(), - self::getTopicNameTemplate(), + if (self::$pathTemplateMap == null) { + self::$pathTemplateMap = [ + 'project' => self::getProjectNameTemplate(), + 'topic' => self::getTopicNameTemplate(), ]; } - return self::$pathTemplateList; + return self::$pathTemplateMap; } private static function getPageStreamingDescriptors() { @@ -179,8 +180,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\Version')) { - self::$gapicVersion = \Google\Cloud\Version::VERSION; + } elseif (class_exists(Version::class)) { + self::$gapicVersion = Version::VERSION; } self::$gapicVersionLoaded = true; } @@ -225,17 +226,32 @@ public static function topicName($project, $topic) /** * Parses a formatted name string and returns an associative array of the components in the name. * The following name formats are supported: - * - projects/{project} - * - projects/{project}/topics/{topic}. + * Template: Pattern + * - project: projects/{project} + * - topic: projects/{project}/topics/{topic}. + * + * The optional $template argument can be supplied to specify a particular pattern, and must + * match one of the templates listed above. If no $template argument is provided, or if the + * $template argument does not match one of the templates listed, then parseName will check + * each of the supported templates, and return the first match. * * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match * * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. * @experimental */ - public static function parseName($formattedName) + public static function parseName($formattedName, $template = null) { - foreach (self::getPathTemplateList() as $pathTemplate) { + $templateMap = self::getPathTemplateMap(); + + if (isset($templateMap[$template])) { + return $templateMap[$template]->match($formattedName); + } + + foreach ($templateMap as $templateName => $pathTemplate) { try { return $pathTemplate->match($formattedName); } catch (ValidationException $ex) { diff --git a/src/PubSub/V1/Gapic/SubscriberGapicClient.php b/src/PubSub/V1/Gapic/SubscriberGapicClient.php index 8c562f4ef944..8709bf63af3e 100644 --- a/src/PubSub/V1/Gapic/SubscriberGapicClient.php +++ b/src/PubSub/V1/Gapic/SubscriberGapicClient.php @@ -30,6 +30,7 @@ namespace Google\Cloud\PubSub\V1\Gapic; +use Google\Cloud\Version; use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; @@ -119,7 +120,7 @@ class SubscriberGapicClient private static $snapshotNameTemplate; private static $subscriptionNameTemplate; private static $topicNameTemplate; - private static $pathTemplateList; + private static $pathTemplateMap; private static $gapicVersion; private static $gapicVersionLoaded = false; @@ -166,18 +167,18 @@ private static function getTopicNameTemplate() return self::$topicNameTemplate; } - private static function getPathTemplateList() + private static function getPathTemplateMap() { - if (self::$pathTemplateList == null) { - self::$pathTemplateList = [ - self::getProjectNameTemplate(), - self::getSnapshotNameTemplate(), - self::getSubscriptionNameTemplate(), - self::getTopicNameTemplate(), + if (self::$pathTemplateMap == null) { + self::$pathTemplateMap = [ + 'project' => self::getProjectNameTemplate(), + 'snapshot' => self::getSnapshotNameTemplate(), + 'subscription' => self::getSubscriptionNameTemplate(), + 'topic' => self::getTopicNameTemplate(), ]; } - return self::$pathTemplateList; + return self::$pathTemplateMap; } private static function getPageStreamingDescriptors() { @@ -223,8 +224,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\Version')) { - self::$gapicVersion = \Google\Cloud\Version::VERSION; + } elseif (class_exists(Version::class)) { + self::$gapicVersion = Version::VERSION; } self::$gapicVersionLoaded = true; } @@ -305,19 +306,34 @@ public static function topicName($project, $topic) /** * Parses a formatted name string and returns an associative array of the components in the name. * The following name formats are supported: - * - projects/{project} - * - projects/{project}/snapshots/{snapshot} - * - projects/{project}/subscriptions/{subscription} - * - projects/{project}/topics/{topic}. + * Template: Pattern + * - project: projects/{project} + * - snapshot: projects/{project}/snapshots/{snapshot} + * - subscription: projects/{project}/subscriptions/{subscription} + * - topic: projects/{project}/topics/{topic}. + * + * The optional $template argument can be supplied to specify a particular pattern, and must + * match one of the templates listed above. If no $template argument is provided, or if the + * $template argument does not match one of the templates listed, then parseName will check + * each of the supported templates, and return the first match. * * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match * * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. * @experimental */ - public static function parseName($formattedName) + public static function parseName($formattedName, $template = null) { - foreach (self::getPathTemplateList() as $pathTemplate) { + $templateMap = self::getPathTemplateMap(); + + if (isset($templateMap[$template])) { + return $templateMap[$template]->match($formattedName); + } + + foreach ($templateMap as $templateName => $pathTemplate) { try { return $pathTemplate->match($formattedName); } catch (ValidationException $ex) { diff --git a/src/Spanner/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php b/src/Spanner/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php index 26ea48e4a6fe..2fa48bbe55cd 100644 --- a/src/Spanner/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php +++ b/src/Spanner/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php @@ -30,6 +30,7 @@ namespace Google\Cloud\Spanner\Admin\Database\V1\Gapic; +use Google\Cloud\Version; use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; @@ -121,7 +122,7 @@ class DatabaseAdminGapicClient private static $instanceNameTemplate; private static $databaseNameTemplate; - private static $pathTemplateList; + private static $pathTemplateMap; private static $gapicVersion; private static $gapicVersionLoaded = false; @@ -150,16 +151,16 @@ private static function getDatabaseNameTemplate() return self::$databaseNameTemplate; } - private static function getPathTemplateList() + private static function getPathTemplateMap() { - if (self::$pathTemplateList == null) { - self::$pathTemplateList = [ - self::getInstanceNameTemplate(), - self::getDatabaseNameTemplate(), + if (self::$pathTemplateMap == null) { + self::$pathTemplateMap = [ + 'instance' => self::getInstanceNameTemplate(), + 'database' => self::getDatabaseNameTemplate(), ]; } - return self::$pathTemplateList; + return self::$pathTemplateMap; } private static function getPageStreamingDescriptors() { @@ -199,8 +200,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\Version')) { - self::$gapicVersion = \Google\Cloud\Version::VERSION; + } elseif (class_exists(Version::class)) { + self::$gapicVersion = Version::VERSION; } self::$gapicVersionLoaded = true; } @@ -249,17 +250,32 @@ public static function databaseName($project, $instance, $database) /** * Parses a formatted name string and returns an associative array of the components in the name. * The following name formats are supported: - * - projects/{project}/instances/{instance} - * - projects/{project}/instances/{instance}/databases/{database}. + * Template: Pattern + * - instance: projects/{project}/instances/{instance} + * - database: projects/{project}/instances/{instance}/databases/{database}. + * + * The optional $template argument can be supplied to specify a particular pattern, and must + * match one of the templates listed above. If no $template argument is provided, or if the + * $template argument does not match one of the templates listed, then parseName will check + * each of the supported templates, and return the first match. * * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match * * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. * @experimental */ - public static function parseName($formattedName) + public static function parseName($formattedName, $template = null) { - foreach (self::getPathTemplateList() as $pathTemplate) { + $templateMap = self::getPathTemplateMap(); + + if (isset($templateMap[$template])) { + return $templateMap[$template]->match($formattedName); + } + + foreach ($templateMap as $templateName => $pathTemplate) { try { return $pathTemplate->match($formattedName); } catch (ValidationException $ex) { diff --git a/src/Spanner/Admin/Instance/V1/Gapic/InstanceAdminGapicClient.php b/src/Spanner/Admin/Instance/V1/Gapic/InstanceAdminGapicClient.php index 389e6f6c5878..6f133c98538e 100644 --- a/src/Spanner/Admin/Instance/V1/Gapic/InstanceAdminGapicClient.php +++ b/src/Spanner/Admin/Instance/V1/Gapic/InstanceAdminGapicClient.php @@ -30,6 +30,7 @@ namespace Google\Cloud\Spanner\Admin\Instance\V1\Gapic; +use Google\Cloud\Version; use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; @@ -140,7 +141,7 @@ class InstanceAdminGapicClient private static $projectNameTemplate; private static $instanceConfigNameTemplate; private static $instanceNameTemplate; - private static $pathTemplateList; + private static $pathTemplateMap; private static $gapicVersion; private static $gapicVersionLoaded = false; @@ -178,17 +179,17 @@ private static function getInstanceNameTemplate() return self::$instanceNameTemplate; } - private static function getPathTemplateList() + private static function getPathTemplateMap() { - if (self::$pathTemplateList == null) { - self::$pathTemplateList = [ - self::getProjectNameTemplate(), - self::getInstanceConfigNameTemplate(), - self::getInstanceNameTemplate(), + if (self::$pathTemplateMap == null) { + self::$pathTemplateMap = [ + 'project' => self::getProjectNameTemplate(), + 'instanceConfig' => self::getInstanceConfigNameTemplate(), + 'instance' => self::getInstanceNameTemplate(), ]; } - return self::$pathTemplateList; + return self::$pathTemplateMap; } private static function getPageStreamingDescriptors() { @@ -238,8 +239,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\Version')) { - self::$gapicVersion = \Google\Cloud\Version::VERSION; + } elseif (class_exists(Version::class)) { + self::$gapicVersion = Version::VERSION; } self::$gapicVersionLoaded = true; } @@ -302,18 +303,33 @@ public static function instanceName($project, $instance) /** * Parses a formatted name string and returns an associative array of the components in the name. * The following name formats are supported: - * - projects/{project} - * - projects/{project}/instanceConfigs/{instance_config} - * - projects/{project}/instances/{instance}. + * Template: Pattern + * - project: projects/{project} + * - instanceConfig: projects/{project}/instanceConfigs/{instance_config} + * - instance: projects/{project}/instances/{instance}. + * + * The optional $template argument can be supplied to specify a particular pattern, and must + * match one of the templates listed above. If no $template argument is provided, or if the + * $template argument does not match one of the templates listed, then parseName will check + * each of the supported templates, and return the first match. * * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match * * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. * @experimental */ - public static function parseName($formattedName) + public static function parseName($formattedName, $template = null) { - foreach (self::getPathTemplateList() as $pathTemplate) { + $templateMap = self::getPathTemplateMap(); + + if (isset($templateMap[$template])) { + return $templateMap[$template]->match($formattedName); + } + + foreach ($templateMap as $templateName => $pathTemplate) { try { return $pathTemplate->match($formattedName); } catch (ValidationException $ex) { diff --git a/src/Spanner/V1/Gapic/SpannerGapicClient.php b/src/Spanner/V1/Gapic/SpannerGapicClient.php index 7b983627884e..985659b56275 100644 --- a/src/Spanner/V1/Gapic/SpannerGapicClient.php +++ b/src/Spanner/V1/Gapic/SpannerGapicClient.php @@ -30,6 +30,7 @@ namespace Google\Cloud\Spanner\V1\Gapic; +use Google\Cloud\Version; use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; @@ -106,7 +107,7 @@ class SpannerGapicClient private static $databaseNameTemplate; private static $sessionNameTemplate; - private static $pathTemplateList; + private static $pathTemplateMap; private static $gapicVersion; private static $gapicVersionLoaded = false; @@ -134,16 +135,16 @@ private static function getSessionNameTemplate() return self::$sessionNameTemplate; } - private static function getPathTemplateList() + private static function getPathTemplateMap() { - if (self::$pathTemplateList == null) { - self::$pathTemplateList = [ - self::getDatabaseNameTemplate(), - self::getSessionNameTemplate(), + if (self::$pathTemplateMap == null) { + self::$pathTemplateMap = [ + 'database' => self::getDatabaseNameTemplate(), + 'session' => self::getSessionNameTemplate(), ]; } - return self::$pathTemplateList; + return self::$pathTemplateMap; } private static function getGrpcStreamingDescriptors() @@ -163,8 +164,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\Version')) { - self::$gapicVersion = \Google\Cloud\Version::VERSION; + } elseif (class_exists(Version::class)) { + self::$gapicVersion = Version::VERSION; } self::$gapicVersionLoaded = true; } @@ -217,17 +218,32 @@ public static function sessionName($project, $instance, $database, $session) /** * Parses a formatted name string and returns an associative array of the components in the name. * The following name formats are supported: - * - projects/{project}/instances/{instance}/databases/{database} - * - projects/{project}/instances/{instance}/databases/{database}/sessions/{session}. + * Template: Pattern + * - database: projects/{project}/instances/{instance}/databases/{database} + * - session: projects/{project}/instances/{instance}/databases/{database}/sessions/{session}. + * + * The optional $template argument can be supplied to specify a particular pattern, and must + * match one of the templates listed above. If no $template argument is provided, or if the + * $template argument does not match one of the templates listed, then parseName will check + * each of the supported templates, and return the first match. * * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match * * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. * @experimental */ - public static function parseName($formattedName) + public static function parseName($formattedName, $template = null) { - foreach (self::getPathTemplateList() as $pathTemplate) { + $templateMap = self::getPathTemplateMap(); + + if (isset($templateMap[$template])) { + return $templateMap[$template]->match($formattedName); + } + + foreach ($templateMap as $templateName => $pathTemplate) { try { return $pathTemplate->match($formattedName); } catch (ValidationException $ex) { diff --git a/src/Speech/V1/Gapic/SpeechGapicClient.php b/src/Speech/V1/Gapic/SpeechGapicClient.php index a99a445cebde..d0142b745d9b 100644 --- a/src/Speech/V1/Gapic/SpeechGapicClient.php +++ b/src/Speech/V1/Gapic/SpeechGapicClient.php @@ -37,6 +37,7 @@ use Google\Cloud\Speech\V1\RecognizeRequest; use Google\Cloud\Speech\V1\SpeechGrpcClient; use Google\Cloud\Speech\V1\StreamingRecognizeRequest; +use Google\Cloud\Version; use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; @@ -131,8 +132,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\Version')) { - self::$gapicVersion = \Google\Cloud\Version::VERSION; + } elseif (class_exists(Version::class)) { + self::$gapicVersion = Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/Speech/V1beta1/Gapic/SpeechGapicClient.php b/src/Speech/V1beta1/Gapic/SpeechGapicClient.php index f4fd0b72652a..92e60f318eb4 100644 --- a/src/Speech/V1beta1/Gapic/SpeechGapicClient.php +++ b/src/Speech/V1beta1/Gapic/SpeechGapicClient.php @@ -37,6 +37,7 @@ use Google\Cloud\Speech\V1beta1\SpeechGrpcClient; use Google\Cloud\Speech\V1beta1\StreamingRecognizeRequest; use Google\Cloud\Speech\V1beta1\SyncRecognizeRequest; +use Google\Cloud\Version; use Google\GAX\AgentHeaderDescriptor; use Google\GAX\ApiCallable; use Google\GAX\CallSettings; @@ -129,8 +130,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\Version')) { - self::$gapicVersion = \Google\Cloud\Version::VERSION; + } elseif (class_exists(Version::class)) { + self::$gapicVersion = Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/VideoIntelligence/V1beta1/Gapic/VideoIntelligenceServiceGapicClient.php b/src/VideoIntelligence/V1beta1/Gapic/VideoIntelligenceServiceGapicClient.php index 8379a6d96cf2..65b57551e6a4 100644 --- a/src/VideoIntelligence/V1beta1/Gapic/VideoIntelligenceServiceGapicClient.php +++ b/src/VideoIntelligence/V1beta1/Gapic/VideoIntelligenceServiceGapicClient.php @@ -30,6 +30,7 @@ namespace Google\Cloud\VideoIntelligence\V1beta1\Gapic; +use Google\Cloud\Version; use Google\Cloud\Videointelligence\V1beta1\AnnotateVideoProgress; use Google\Cloud\Videointelligence\V1beta1\AnnotateVideoRequest; use Google\Cloud\Videointelligence\V1beta1\AnnotateVideoResponse; @@ -138,8 +139,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\Version')) { - self::$gapicVersion = \Google\Cloud\Version::VERSION; + } elseif (class_exists(Version::class)) { + self::$gapicVersion = Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/VideoIntelligence/V1beta2/Gapic/VideoIntelligenceServiceGapicClient.php b/src/VideoIntelligence/V1beta2/Gapic/VideoIntelligenceServiceGapicClient.php index 770cba0c45bf..89bb2745d507 100644 --- a/src/VideoIntelligence/V1beta2/Gapic/VideoIntelligenceServiceGapicClient.php +++ b/src/VideoIntelligence/V1beta2/Gapic/VideoIntelligenceServiceGapicClient.php @@ -30,6 +30,7 @@ namespace Google\Cloud\VideoIntelligence\V1beta2\Gapic; +use Google\Cloud\Version; use Google\Cloud\Videointelligence\V1beta2\AnnotateVideoProgress; use Google\Cloud\Videointelligence\V1beta2\AnnotateVideoRequest; use Google\Cloud\Videointelligence\V1beta2\AnnotateVideoResponse; @@ -138,8 +139,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\Version')) { - self::$gapicVersion = \Google\Cloud\Version::VERSION; + } elseif (class_exists(Version::class)) { + self::$gapicVersion = Version::VERSION; } self::$gapicVersionLoaded = true; } diff --git a/src/Vision/V1/Gapic/ImageAnnotatorGapicClient.php b/src/Vision/V1/Gapic/ImageAnnotatorGapicClient.php index d311d45836b7..37859d76975b 100644 --- a/src/Vision/V1/Gapic/ImageAnnotatorGapicClient.php +++ b/src/Vision/V1/Gapic/ImageAnnotatorGapicClient.php @@ -30,6 +30,7 @@ namespace Google\Cloud\Vision\V1\Gapic; +use Google\Cloud\Version; use Google\Cloud\Vision\V1\AnnotateImageRequest; use Google\Cloud\Vision\V1\BatchAnnotateImagesRequest; use Google\Cloud\Vision\V1\ImageAnnotatorGrpcClient; @@ -98,8 +99,8 @@ private static function getGapicVersion() if (!self::$gapicVersionLoaded) { if (file_exists(__DIR__.'/../VERSION')) { self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION')); - } elseif (class_exists('\Google\Cloud\Version')) { - self::$gapicVersion = \Google\Cloud\Version::VERSION; + } elseif (class_exists(Version::class)) { + self::$gapicVersion = Version::VERSION; } self::$gapicVersionLoaded = true; } From 8edf5c4b25b1e1ce41567ec2e88eaa62dd5d59e1 Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Tue, 19 Sep 2017 10:36:11 -0700 Subject: [PATCH 13/17] Switch use of parse method --- src/Spanner/SpannerClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Spanner/SpannerClient.php b/src/Spanner/SpannerClient.php index b322288ad556..0453fc26f395 100644 --- a/src/Spanner/SpannerClient.php +++ b/src/Spanner/SpannerClient.php @@ -133,7 +133,7 @@ public function __construct(array $config = []) ], [ 'typeUrl' => 'type.googleapis.com/google.spanner.admin.database.v1.CreateDatabaseMetadata', 'callable' => function ($database) { - $databaseNameComponents = InstanceAdminClient::parseName($database['name']); + $databaseNameComponents = DatabaseAdminClient::parseName($database['name']); $instanceName = $databaseNameComponents['instance']; $databaseName = $databaseNameComponents['database']; From 5077117065331176b05397c48678072809ba9419 Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Tue, 19 Sep 2017 11:28:52 -0700 Subject: [PATCH 14/17] Refresh with toolkit changes --- .../V2beta1/Gapic/DlpServiceGapicClient.php | 66 +++++-- .../Gapic/ErrorGroupServiceGapicClient.php | 26 ++- .../Gapic/ErrorStatsServiceGapicClient.php | 36 +++- .../Gapic/ReportErrorsServiceGapicClient.php | 16 +- .../Gapic/LanguageServiceGapicClient.php | 60 ++++-- .../V2/Gapic/ConfigServiceV2GapicClient.php | 56 ++++-- .../V2/Gapic/LoggingServiceV2GapicClient.php | 56 ++++-- .../V2/Gapic/MetricsServiceV2GapicClient.php | 56 ++++-- .../V3/Gapic/GroupServiceGapicClient.php | 66 +++++-- .../V3/Gapic/MetricServiceGapicClient.php | 86 +++++--- src/PubSub/V1/Gapic/PublisherGapicClient.php | 106 +++++++--- src/PubSub/V1/Gapic/SubscriberGapicClient.php | 186 ++++++++++++------ .../V1/Gapic/DatabaseAdminGapicClient.php | 96 ++++++--- .../V1/Gapic/InstanceAdminGapicClient.php | 106 +++++++--- src/Spanner/V1/Gapic/SpannerGapicClient.php | 106 +++++++--- src/Speech/V1/Gapic/SpeechGapicClient.php | 30 ++- .../V1beta1/Gapic/SpeechGapicClient.php | 30 ++- .../VideoIntelligenceServiceGapicClient.php | 10 +- .../VideoIntelligenceServiceGapicClient.php | 10 +- .../V1/Gapic/ImageAnnotatorGapicClient.php | 10 +- 20 files changed, 861 insertions(+), 353 deletions(-) diff --git a/src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php b/src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php index ed2ae16bc31c..ee0fc733829b 100644 --- a/src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php +++ b/src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php @@ -214,7 +214,11 @@ public static function parseName($formattedName, $template = null) { $templateMap = self::getPathTemplateMap(); - if (isset($templateMap[$template])) { + if ($template) { + if (!isset($templateMap[$template])) { + throw new ValidationException("Template name $template does not exist"); + } + return $templateMap[$template]->match($formattedName); } @@ -430,9 +434,13 @@ public function inspectContent($inspectConfig, $items, $optionalArgs = []) $request->setInspectConfig($inspectConfig); $request->setItems($items); - $mergedSettings = $this->defaultCallSettings['inspectContent']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['inspectContent']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->dlpServiceStub, 'InspectContent', @@ -511,9 +519,13 @@ public function redactContent($inspectConfig, $items, $replaceConfigs, $optional $request->setImageRedactionConfigs($optionalArgs['imageRedactionConfigs']); } - $mergedSettings = $this->defaultCallSettings['redactContent']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['redactContent']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->dlpServiceStub, 'RedactContent', @@ -625,9 +637,13 @@ public function createInspectOperation($inspectConfig, $storageConfig, $outputCo $request->setOperationConfig($optionalArgs['operationConfig']); } - $mergedSettings = $this->defaultCallSettings['createInspectOperation']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['createInspectOperation']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->dlpServiceStub, 'CreateInspectOperation', @@ -702,9 +718,13 @@ public function listInspectFindings($name, $optionalArgs = []) $request->setFilter($optionalArgs['filter']); } - $mergedSettings = $this->defaultCallSettings['listInspectFindings']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listInspectFindings']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->dlpServiceStub, 'ListInspectFindings', @@ -758,9 +778,13 @@ public function listInfoTypes($category, $languageCode, $optionalArgs = []) $request->setCategory($category); $request->setLanguageCode($languageCode); - $mergedSettings = $this->defaultCallSettings['listInfoTypes']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listInfoTypes']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->dlpServiceStub, 'ListInfoTypes', @@ -811,9 +835,13 @@ public function listRootCategories($languageCode, $optionalArgs = []) $request = new ListRootCategoriesRequest(); $request->setLanguageCode($languageCode); - $mergedSettings = $this->defaultCallSettings['listRootCategories']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listRootCategories']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->dlpServiceStub, 'ListRootCategories', diff --git a/src/ErrorReporting/V1beta1/Gapic/ErrorGroupServiceGapicClient.php b/src/ErrorReporting/V1beta1/Gapic/ErrorGroupServiceGapicClient.php index c3a2dce33d27..191a4091a666 100644 --- a/src/ErrorReporting/V1beta1/Gapic/ErrorGroupServiceGapicClient.php +++ b/src/ErrorReporting/V1beta1/Gapic/ErrorGroupServiceGapicClient.php @@ -177,7 +177,11 @@ public static function parseName($formattedName, $template = null) { $templateMap = self::getPathTemplateMap(); - if (isset($templateMap[$template])) { + if ($template) { + if (!isset($templateMap[$template])) { + throw new ValidationException("Template name $template does not exist"); + } + return $templateMap[$template]->match($formattedName); } @@ -329,9 +333,13 @@ public function getGroup($groupName, $optionalArgs = []) $request = new GetGroupRequest(); $request->setGroupName($groupName); - $mergedSettings = $this->defaultCallSettings['getGroup']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['getGroup']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->errorGroupServiceStub, 'GetGroup', @@ -381,9 +389,13 @@ public function updateGroup($group, $optionalArgs = []) $request = new UpdateGroupRequest(); $request->setGroup($group); - $mergedSettings = $this->defaultCallSettings['updateGroup']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['updateGroup']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->errorGroupServiceStub, 'UpdateGroup', diff --git a/src/ErrorReporting/V1beta1/Gapic/ErrorStatsServiceGapicClient.php b/src/ErrorReporting/V1beta1/Gapic/ErrorStatsServiceGapicClient.php index 45212bb27e4d..f42d6c076b8e 100644 --- a/src/ErrorReporting/V1beta1/Gapic/ErrorStatsServiceGapicClient.php +++ b/src/ErrorReporting/V1beta1/Gapic/ErrorStatsServiceGapicClient.php @@ -222,7 +222,11 @@ public static function parseName($formattedName, $template = null) { $templateMap = self::getPathTemplateMap(); - if (isset($templateMap[$template])) { + if ($template) { + if (!isset($templateMap[$template])) { + throw new ValidationException("Template name $template does not exist"); + } + return $templateMap[$template]->match($formattedName); } @@ -451,9 +455,13 @@ public function listGroupStats($projectName, $timeRange, $optionalArgs = []) $request->setPageToken($optionalArgs['pageToken']); } - $mergedSettings = $this->defaultCallSettings['listGroupStats']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listGroupStats']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->errorStatsServiceStub, 'ListGroupStats', @@ -550,9 +558,13 @@ public function listEvents($projectName, $groupId, $optionalArgs = []) $request->setPageToken($optionalArgs['pageToken']); } - $mergedSettings = $this->defaultCallSettings['listEvents']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listEvents']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->errorStatsServiceStub, 'ListEvents', @@ -605,9 +617,13 @@ public function deleteEvents($projectName, $optionalArgs = []) $request = new DeleteEventsRequest(); $request->setProjectName($projectName); - $mergedSettings = $this->defaultCallSettings['deleteEvents']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['deleteEvents']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->errorStatsServiceStub, 'DeleteEvents', diff --git a/src/ErrorReporting/V1beta1/Gapic/ReportErrorsServiceGapicClient.php b/src/ErrorReporting/V1beta1/Gapic/ReportErrorsServiceGapicClient.php index 2880f50f4153..871d95617f8b 100644 --- a/src/ErrorReporting/V1beta1/Gapic/ReportErrorsServiceGapicClient.php +++ b/src/ErrorReporting/V1beta1/Gapic/ReportErrorsServiceGapicClient.php @@ -175,7 +175,11 @@ public static function parseName($formattedName, $template = null) { $templateMap = self::getPathTemplateMap(); - if (isset($templateMap[$template])) { + if ($template) { + if (!isset($templateMap[$template])) { + throw new ValidationException("Template name $template does not exist"); + } + return $templateMap[$template]->match($formattedName); } @@ -332,9 +336,13 @@ public function reportErrorEvent($projectName, $event, $optionalArgs = []) $request->setProjectName($projectName); $request->setEvent($event); - $mergedSettings = $this->defaultCallSettings['reportErrorEvent']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['reportErrorEvent']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->reportErrorsServiceStub, 'ReportErrorEvent', diff --git a/src/Language/V1beta2/Gapic/LanguageServiceGapicClient.php b/src/Language/V1beta2/Gapic/LanguageServiceGapicClient.php index af6600ca8e77..cac6b6dca6f6 100644 --- a/src/Language/V1beta2/Gapic/LanguageServiceGapicClient.php +++ b/src/Language/V1beta2/Gapic/LanguageServiceGapicClient.php @@ -256,9 +256,13 @@ public function analyzeSentiment($document, $optionalArgs = []) $request->setEncodingType($optionalArgs['encodingType']); } - $mergedSettings = $this->defaultCallSettings['analyzeSentiment']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['analyzeSentiment']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->languageServiceStub, 'AnalyzeSentiment', @@ -315,9 +319,13 @@ public function analyzeEntities($document, $optionalArgs = []) $request->setEncodingType($optionalArgs['encodingType']); } - $mergedSettings = $this->defaultCallSettings['analyzeEntities']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['analyzeEntities']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->languageServiceStub, 'AnalyzeEntities', @@ -373,9 +381,13 @@ public function analyzeEntitySentiment($document, $optionalArgs = []) $request->setEncodingType($optionalArgs['encodingType']); } - $mergedSettings = $this->defaultCallSettings['analyzeEntitySentiment']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['analyzeEntitySentiment']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->languageServiceStub, 'AnalyzeEntitySentiment', @@ -432,9 +444,13 @@ public function analyzeSyntax($document, $optionalArgs = []) $request->setEncodingType($optionalArgs['encodingType']); } - $mergedSettings = $this->defaultCallSettings['analyzeSyntax']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['analyzeSyntax']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->languageServiceStub, 'AnalyzeSyntax', @@ -483,9 +499,13 @@ public function classifyText($document, $optionalArgs = []) $request = new ClassifyTextRequest(); $request->setDocument($document); - $mergedSettings = $this->defaultCallSettings['classifyText']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['classifyText']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->languageServiceStub, 'ClassifyText', @@ -544,9 +564,13 @@ public function annotateText($document, $features, $optionalArgs = []) $request->setEncodingType($optionalArgs['encodingType']); } - $mergedSettings = $this->defaultCallSettings['annotateText']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['annotateText']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->languageServiceStub, 'AnnotateText', diff --git a/src/Logging/V2/Gapic/ConfigServiceV2GapicClient.php b/src/Logging/V2/Gapic/ConfigServiceV2GapicClient.php index 08930e0e4a55..a8c746994d56 100644 --- a/src/Logging/V2/Gapic/ConfigServiceV2GapicClient.php +++ b/src/Logging/V2/Gapic/ConfigServiceV2GapicClient.php @@ -240,7 +240,11 @@ public static function parseName($formattedName, $template = null) { $templateMap = self::getPathTemplateMap(); - if (isset($templateMap[$template])) { + if ($template) { + if (!isset($templateMap[$template])) { + throw new ValidationException("Template name $template does not exist"); + } + return $templateMap[$template]->match($formattedName); } @@ -428,9 +432,13 @@ public function listSinks($parent, $optionalArgs = []) $request->setPageSize($optionalArgs['pageSize']); } - $mergedSettings = $this->defaultCallSettings['listSinks']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listSinks']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->configServiceV2Stub, 'ListSinks', @@ -486,9 +494,13 @@ public function getSink($sinkName, $optionalArgs = []) $request = new GetSinkRequest(); $request->setSinkName($sinkName); - $mergedSettings = $this->defaultCallSettings['getSink']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['getSink']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->configServiceV2Stub, 'GetSink', @@ -567,9 +579,13 @@ public function createSink($parent, $sink, $optionalArgs = []) $request->setUniqueWriterIdentity($optionalArgs['uniqueWriterIdentity']); } - $mergedSettings = $this->defaultCallSettings['createSink']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['createSink']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->configServiceV2Stub, 'CreateSink', @@ -650,9 +666,13 @@ public function updateSink($sinkName, $sink, $optionalArgs = []) $request->setUniqueWriterIdentity($optionalArgs['uniqueWriterIdentity']); } - $mergedSettings = $this->defaultCallSettings['updateSink']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['updateSink']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->configServiceV2Stub, 'UpdateSink', @@ -708,9 +728,13 @@ public function deleteSink($sinkName, $optionalArgs = []) $request = new DeleteSinkRequest(); $request->setSinkName($sinkName); - $mergedSettings = $this->defaultCallSettings['deleteSink']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['deleteSink']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->configServiceV2Stub, 'DeleteSink', diff --git a/src/Logging/V2/Gapic/LoggingServiceV2GapicClient.php b/src/Logging/V2/Gapic/LoggingServiceV2GapicClient.php index 8f968dc90706..afcc13483bdc 100644 --- a/src/Logging/V2/Gapic/LoggingServiceV2GapicClient.php +++ b/src/Logging/V2/Gapic/LoggingServiceV2GapicClient.php @@ -248,7 +248,11 @@ public static function parseName($formattedName, $template = null) { $templateMap = self::getPathTemplateMap(); - if (isset($templateMap[$template])) { + if ($template) { + if (!isset($templateMap[$template])) { + throw new ValidationException("Template name $template does not exist"); + } + return $templateMap[$template]->match($formattedName); } @@ -416,9 +420,13 @@ public function deleteLog($logName, $optionalArgs = []) $request = new DeleteLogRequest(); $request->setLogName($logName); - $mergedSettings = $this->defaultCallSettings['deleteLog']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['deleteLog']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->loggingServiceV2Stub, 'DeleteLog', @@ -539,9 +547,13 @@ public function writeLogEntries($entries, $optionalArgs = []) $request->setPartialSuccess($optionalArgs['partialSuccess']); } - $mergedSettings = $this->defaultCallSettings['writeLogEntries']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['writeLogEntries']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->loggingServiceV2Stub, 'WriteLogEntries', @@ -657,9 +669,13 @@ public function listLogEntries($resourceNames, $optionalArgs = []) $request->setPageToken($optionalArgs['pageToken']); } - $mergedSettings = $this->defaultCallSettings['listLogEntries']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listLogEntries']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->loggingServiceV2Stub, 'ListLogEntries', @@ -734,9 +750,13 @@ public function listMonitoredResourceDescriptors($optionalArgs = []) $request->setPageToken($optionalArgs['pageToken']); } - $mergedSettings = $this->defaultCallSettings['listMonitoredResourceDescriptors']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listMonitoredResourceDescriptors']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->loggingServiceV2Stub, 'ListMonitoredResourceDescriptors', @@ -818,9 +838,13 @@ public function listLogs($parent, $optionalArgs = []) $request->setPageToken($optionalArgs['pageToken']); } - $mergedSettings = $this->defaultCallSettings['listLogs']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listLogs']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->loggingServiceV2Stub, 'ListLogs', diff --git a/src/Logging/V2/Gapic/MetricsServiceV2GapicClient.php b/src/Logging/V2/Gapic/MetricsServiceV2GapicClient.php index fb4fe265173d..f1ccaf9d5667 100644 --- a/src/Logging/V2/Gapic/MetricsServiceV2GapicClient.php +++ b/src/Logging/V2/Gapic/MetricsServiceV2GapicClient.php @@ -239,7 +239,11 @@ public static function parseName($formattedName, $template = null) { $templateMap = self::getPathTemplateMap(); - if (isset($templateMap[$template])) { + if ($template) { + if (!isset($templateMap[$template])) { + throw new ValidationException("Template name $template does not exist"); + } + return $templateMap[$template]->match($formattedName); } @@ -424,9 +428,13 @@ public function listLogMetrics($parent, $optionalArgs = []) $request->setPageSize($optionalArgs['pageSize']); } - $mergedSettings = $this->defaultCallSettings['listLogMetrics']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listLogMetrics']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->metricsServiceV2Stub, 'ListLogMetrics', @@ -477,9 +485,13 @@ public function getLogMetric($metricName, $optionalArgs = []) $request = new GetLogMetricRequest(); $request->setMetricName($metricName); - $mergedSettings = $this->defaultCallSettings['getLogMetric']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['getLogMetric']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->metricsServiceV2Stub, 'GetLogMetric', @@ -536,9 +548,13 @@ public function createLogMetric($parent, $metric, $optionalArgs = []) $request->setParent($parent); $request->setMetric($metric); - $mergedSettings = $this->defaultCallSettings['createLogMetric']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['createLogMetric']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->metricsServiceV2Stub, 'CreateLogMetric', @@ -596,9 +612,13 @@ public function updateLogMetric($metricName, $metric, $optionalArgs = []) $request->setMetricName($metricName); $request->setMetric($metric); - $mergedSettings = $this->defaultCallSettings['updateLogMetric']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['updateLogMetric']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->metricsServiceV2Stub, 'UpdateLogMetric', @@ -647,9 +667,13 @@ public function deleteLogMetric($metricName, $optionalArgs = []) $request = new DeleteLogMetricRequest(); $request->setMetricName($metricName); - $mergedSettings = $this->defaultCallSettings['deleteLogMetric']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['deleteLogMetric']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->metricsServiceV2Stub, 'DeleteLogMetric', diff --git a/src/Monitoring/V3/Gapic/GroupServiceGapicClient.php b/src/Monitoring/V3/Gapic/GroupServiceGapicClient.php index a5c9afa299e5..df660abb679b 100644 --- a/src/Monitoring/V3/Gapic/GroupServiceGapicClient.php +++ b/src/Monitoring/V3/Gapic/GroupServiceGapicClient.php @@ -262,7 +262,11 @@ public static function parseName($formattedName, $template = null) { $templateMap = self::getPathTemplateMap(); - if (isset($templateMap[$template])) { + if ($template) { + if (!isset($templateMap[$template])) { + throw new ValidationException("Template name $template does not exist"); + } + return $templateMap[$template]->match($formattedName); } @@ -470,9 +474,13 @@ public function listGroups($name, $optionalArgs = []) $request->setPageToken($optionalArgs['pageToken']); } - $mergedSettings = $this->defaultCallSettings['listGroups']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listGroups']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->groupServiceStub, 'ListGroups', @@ -522,9 +530,13 @@ public function getGroup($name, $optionalArgs = []) $request = new GetGroupRequest(); $request->setName($name); - $mergedSettings = $this->defaultCallSettings['getGroup']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['getGroup']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->groupServiceStub, 'GetGroup', @@ -583,9 +595,13 @@ public function createGroup($name, $group, $optionalArgs = []) $request->setValidateOnly($optionalArgs['validateOnly']); } - $mergedSettings = $this->defaultCallSettings['createGroup']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['createGroup']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->groupServiceStub, 'CreateGroup', @@ -641,9 +657,13 @@ public function updateGroup($group, $optionalArgs = []) $request->setValidateOnly($optionalArgs['validateOnly']); } - $mergedSettings = $this->defaultCallSettings['updateGroup']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['updateGroup']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->groupServiceStub, 'UpdateGroup', @@ -691,9 +711,13 @@ public function deleteGroup($name, $optionalArgs = []) $request = new DeleteGroupRequest(); $request->setName($name); - $mergedSettings = $this->defaultCallSettings['deleteGroup']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['deleteGroup']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->groupServiceStub, 'DeleteGroup', @@ -789,9 +813,13 @@ public function listGroupMembers($name, $optionalArgs = []) $request->setInterval($optionalArgs['interval']); } - $mergedSettings = $this->defaultCallSettings['listGroupMembers']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listGroupMembers']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->groupServiceStub, 'ListGroupMembers', diff --git a/src/Monitoring/V3/Gapic/MetricServiceGapicClient.php b/src/Monitoring/V3/Gapic/MetricServiceGapicClient.php index 07c331cda959..c0f82ad77984 100644 --- a/src/Monitoring/V3/Gapic/MetricServiceGapicClient.php +++ b/src/Monitoring/V3/Gapic/MetricServiceGapicClient.php @@ -297,7 +297,11 @@ public static function parseName($formattedName, $template = null) { $templateMap = self::getPathTemplateMap(); - if (isset($templateMap[$template])) { + if ($template) { + if (!isset($templateMap[$template])) { + throw new ValidationException("Template name $template does not exist"); + } + return $templateMap[$template]->match($formattedName); } @@ -494,9 +498,13 @@ public function listMonitoredResourceDescriptors($name, $optionalArgs = []) $request->setPageToken($optionalArgs['pageToken']); } - $mergedSettings = $this->defaultCallSettings['listMonitoredResourceDescriptors']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listMonitoredResourceDescriptors']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->metricServiceStub, 'ListMonitoredResourceDescriptors', @@ -548,9 +556,13 @@ public function getMonitoredResourceDescriptor($name, $optionalArgs = []) $request = new GetMonitoredResourceDescriptorRequest(); $request->setName($name); - $mergedSettings = $this->defaultCallSettings['getMonitoredResourceDescriptor']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['getMonitoredResourceDescriptor']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->metricServiceStub, 'GetMonitoredResourceDescriptor', @@ -639,9 +651,13 @@ public function listMetricDescriptors($name, $optionalArgs = []) $request->setPageToken($optionalArgs['pageToken']); } - $mergedSettings = $this->defaultCallSettings['listMetricDescriptors']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listMetricDescriptors']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->metricServiceStub, 'ListMetricDescriptors', @@ -693,9 +709,13 @@ public function getMetricDescriptor($name, $optionalArgs = []) $request = new GetMetricDescriptorRequest(); $request->setName($name); - $mergedSettings = $this->defaultCallSettings['getMetricDescriptor']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['getMetricDescriptor']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->metricServiceStub, 'GetMetricDescriptor', @@ -751,9 +771,13 @@ public function createMetricDescriptor($name, $metricDescriptor, $optionalArgs = $request->setName($name); $request->setMetricDescriptor($metricDescriptor); - $mergedSettings = $this->defaultCallSettings['createMetricDescriptor']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['createMetricDescriptor']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->metricServiceStub, 'CreateMetricDescriptor', @@ -804,9 +828,13 @@ public function deleteMetricDescriptor($name, $optionalArgs = []) $request = new DeleteMetricDescriptorRequest(); $request->setName($name); - $mergedSettings = $this->defaultCallSettings['deleteMetricDescriptor']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['deleteMetricDescriptor']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->metricServiceStub, 'DeleteMetricDescriptor', @@ -915,9 +943,13 @@ public function listTimeSeries($name, $filter, $interval, $view, $optionalArgs = $request->setPageToken($optionalArgs['pageToken']); } - $mergedSettings = $this->defaultCallSettings['listTimeSeries']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listTimeSeries']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->metricServiceStub, 'ListTimeSeries', @@ -975,9 +1007,13 @@ public function createTimeSeries($name, $timeSeries, $optionalArgs = []) $request->setName($name); $request->setTimeSeries($timeSeries); - $mergedSettings = $this->defaultCallSettings['createTimeSeries']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['createTimeSeries']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->metricServiceStub, 'CreateTimeSeries', diff --git a/src/PubSub/V1/Gapic/PublisherGapicClient.php b/src/PubSub/V1/Gapic/PublisherGapicClient.php index e818b2b5f638..7a079f9540e1 100644 --- a/src/PubSub/V1/Gapic/PublisherGapicClient.php +++ b/src/PubSub/V1/Gapic/PublisherGapicClient.php @@ -247,7 +247,11 @@ public static function parseName($formattedName, $template = null) { $templateMap = self::getPathTemplateMap(); - if (isset($templateMap[$template])) { + if ($template) { + if (!isset($templateMap[$template])) { + throw new ValidationException("Template name $template does not exist"); + } + return $templateMap[$template]->match($formattedName); } @@ -422,9 +426,13 @@ public function createTopic($name, $optionalArgs = []) $request->setLabels($optionalArgs['labels']); } - $mergedSettings = $this->defaultCallSettings['createTopic']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['createTopic']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->publisherStub, 'CreateTopic', @@ -482,9 +490,13 @@ public function updateTopic($topic, $updateMask, $optionalArgs = []) $request->setTopic($topic); $request->setUpdateMask($updateMask); - $mergedSettings = $this->defaultCallSettings['updateTopic']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['updateTopic']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->publisherStub, 'UpdateTopic', @@ -542,9 +554,13 @@ public function publish($topic, $messages, $optionalArgs = []) $request->setTopic($topic); $request->setMessages($messages); - $mergedSettings = $this->defaultCallSettings['publish']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['publish']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->publisherStub, 'Publish', @@ -594,9 +610,13 @@ public function getTopic($topic, $optionalArgs = []) $request = new GetTopicRequest(); $request->setTopic($topic); - $mergedSettings = $this->defaultCallSettings['getTopic']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['getTopic']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->publisherStub, 'GetTopic', @@ -673,9 +693,13 @@ public function listTopics($project, $optionalArgs = []) $request->setPageToken($optionalArgs['pageToken']); } - $mergedSettings = $this->defaultCallSettings['listTopics']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listTopics']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->publisherStub, 'ListTopics', @@ -752,9 +776,13 @@ public function listTopicSubscriptions($topic, $optionalArgs = []) $request->setPageToken($optionalArgs['pageToken']); } - $mergedSettings = $this->defaultCallSettings['listTopicSubscriptions']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listTopicSubscriptions']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->publisherStub, 'ListTopicSubscriptions', @@ -806,9 +834,13 @@ public function deleteTopic($topic, $optionalArgs = []) $request = new DeleteTopicRequest(); $request->setTopic($topic); - $mergedSettings = $this->defaultCallSettings['deleteTopic']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['deleteTopic']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->publisherStub, 'DeleteTopic', @@ -866,9 +898,13 @@ public function setIamPolicy($resource, $policy, $optionalArgs = []) $request->setResource($resource); $request->setPolicy($policy); - $mergedSettings = $this->defaultCallSettings['setIamPolicy']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['setIamPolicy']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->iamPolicyStub, 'SetIamPolicy', @@ -921,9 +957,13 @@ public function getIamPolicy($resource, $optionalArgs = []) $request = new GetIamPolicyRequest(); $request->setResource($resource); - $mergedSettings = $this->defaultCallSettings['getIamPolicy']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['getIamPolicy']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->iamPolicyStub, 'GetIamPolicy', @@ -982,9 +1022,13 @@ public function testIamPermissions($resource, $permissions, $optionalArgs = []) $request->setResource($resource); $request->setPermissions($permissions); - $mergedSettings = $this->defaultCallSettings['testIamPermissions']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['testIamPermissions']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->iamPolicyStub, 'TestIamPermissions', diff --git a/src/PubSub/V1/Gapic/SubscriberGapicClient.php b/src/PubSub/V1/Gapic/SubscriberGapicClient.php index 8709bf63af3e..4570c1ada8da 100644 --- a/src/PubSub/V1/Gapic/SubscriberGapicClient.php +++ b/src/PubSub/V1/Gapic/SubscriberGapicClient.php @@ -329,7 +329,11 @@ public static function parseName($formattedName, $template = null) { $templateMap = self::getPathTemplateMap(); - if (isset($templateMap[$template])) { + if ($template) { + if (!isset($templateMap[$template])) { + throw new ValidationException("Template name $template does not exist"); + } + return $templateMap[$template]->match($formattedName); } @@ -579,9 +583,13 @@ public function createSubscription($name, $topic, $optionalArgs = []) $request->setLabels($optionalArgs['labels']); } - $mergedSettings = $this->defaultCallSettings['createSubscription']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['createSubscription']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->subscriberStub, 'CreateSubscription', @@ -631,9 +639,13 @@ public function getSubscription($subscription, $optionalArgs = []) $request = new GetSubscriptionRequest(); $request->setSubscription($subscription); - $mergedSettings = $this->defaultCallSettings['getSubscription']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['getSubscription']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->subscriberStub, 'GetSubscription', @@ -691,9 +703,13 @@ public function updateSubscription($subscription, $updateMask, $optionalArgs = [ $request->setSubscription($subscription); $request->setUpdateMask($updateMask); - $mergedSettings = $this->defaultCallSettings['updateSubscription']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['updateSubscription']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->subscriberStub, 'UpdateSubscription', @@ -770,9 +786,13 @@ public function listSubscriptions($project, $optionalArgs = []) $request->setPageToken($optionalArgs['pageToken']); } - $mergedSettings = $this->defaultCallSettings['listSubscriptions']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listSubscriptions']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->subscriberStub, 'ListSubscriptions', @@ -824,9 +844,13 @@ public function deleteSubscription($subscription, $optionalArgs = []) $request = new DeleteSubscriptionRequest(); $request->setSubscription($subscription); - $mergedSettings = $this->defaultCallSettings['deleteSubscription']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['deleteSubscription']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->subscriberStub, 'DeleteSubscription', @@ -890,9 +914,13 @@ public function modifyAckDeadline($subscription, $ackIds, $ackDeadlineSeconds, $ $request->setAckIds($ackIds); $request->setAckDeadlineSeconds($ackDeadlineSeconds); - $mergedSettings = $this->defaultCallSettings['modifyAckDeadline']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['modifyAckDeadline']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->subscriberStub, 'ModifyAckDeadline', @@ -950,9 +978,13 @@ public function acknowledge($subscription, $ackIds, $optionalArgs = []) $request->setSubscription($subscription); $request->setAckIds($ackIds); - $mergedSettings = $this->defaultCallSettings['acknowledge']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['acknowledge']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->subscriberStub, 'Acknowledge', @@ -1019,9 +1051,13 @@ public function pull($subscription, $maxMessages, $optionalArgs = []) $request->setReturnImmediately($optionalArgs['returnImmediately']); } - $mergedSettings = $this->defaultCallSettings['pull']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['pull']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->subscriberStub, 'Pull', @@ -1110,9 +1146,13 @@ public function streamingPull($optionalArgs = []) ]; } - $mergedSettings = $this->defaultCallSettings['streamingPull']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['streamingPull']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->subscriberStub, 'StreamingPull', @@ -1173,9 +1213,13 @@ public function modifyPushConfig($subscription, $pushConfig, $optionalArgs = []) $request->setSubscription($subscription); $request->setPushConfig($pushConfig); - $mergedSettings = $this->defaultCallSettings['modifyPushConfig']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['modifyPushConfig']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->subscriberStub, 'ModifyPushConfig', @@ -1252,9 +1296,13 @@ public function listSnapshots($project, $optionalArgs = []) $request->setPageToken($optionalArgs['pageToken']); } - $mergedSettings = $this->defaultCallSettings['listSnapshots']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listSnapshots']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->subscriberStub, 'ListSnapshots', @@ -1327,9 +1375,13 @@ public function createSnapshot($name, $subscription, $optionalArgs = []) $request->setName($name); $request->setSubscription($subscription); - $mergedSettings = $this->defaultCallSettings['createSnapshot']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['createSnapshot']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->subscriberStub, 'CreateSnapshot', @@ -1387,9 +1439,13 @@ public function updateSnapshot($snapshot, $updateMask, $optionalArgs = []) $request->setSnapshot($snapshot); $request->setUpdateMask($updateMask); - $mergedSettings = $this->defaultCallSettings['updateSnapshot']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['updateSnapshot']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->subscriberStub, 'UpdateSnapshot', @@ -1440,9 +1496,13 @@ public function deleteSnapshot($snapshot, $optionalArgs = []) $request = new DeleteSnapshotRequest(); $request->setSnapshot($snapshot); - $mergedSettings = $this->defaultCallSettings['deleteSnapshot']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['deleteSnapshot']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->subscriberStub, 'DeleteSnapshot', @@ -1514,9 +1574,13 @@ public function seek($subscription, $optionalArgs = []) $request->setSnapshot($optionalArgs['snapshot']); } - $mergedSettings = $this->defaultCallSettings['seek']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['seek']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->subscriberStub, 'Seek', @@ -1574,9 +1638,13 @@ public function setIamPolicy($resource, $policy, $optionalArgs = []) $request->setResource($resource); $request->setPolicy($policy); - $mergedSettings = $this->defaultCallSettings['setIamPolicy']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['setIamPolicy']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->iamPolicyStub, 'SetIamPolicy', @@ -1629,9 +1697,13 @@ public function getIamPolicy($resource, $optionalArgs = []) $request = new GetIamPolicyRequest(); $request->setResource($resource); - $mergedSettings = $this->defaultCallSettings['getIamPolicy']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['getIamPolicy']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->iamPolicyStub, 'GetIamPolicy', @@ -1690,9 +1762,13 @@ public function testIamPermissions($resource, $permissions, $optionalArgs = []) $request->setResource($resource); $request->setPermissions($permissions); - $mergedSettings = $this->defaultCallSettings['testIamPermissions']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['testIamPermissions']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->iamPolicyStub, 'TestIamPermissions', diff --git a/src/Spanner/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php b/src/Spanner/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php index 2fa48bbe55cd..38c4f0603ea9 100644 --- a/src/Spanner/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php +++ b/src/Spanner/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php @@ -271,7 +271,11 @@ public static function parseName($formattedName, $template = null) { $templateMap = self::getPathTemplateMap(); - if (isset($templateMap[$template])) { + if ($template) { + if (!isset($templateMap[$template])) { + throw new ValidationException("Template name $template does not exist"); + } + return $templateMap[$template]->match($formattedName); } @@ -507,9 +511,13 @@ public function listDatabases($parent, $optionalArgs = []) $request->setPageToken($optionalArgs['pageToken']); } - $mergedSettings = $this->defaultCallSettings['listDatabases']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listDatabases']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->databaseAdminStub, 'ListDatabases', @@ -604,9 +612,13 @@ public function createDatabase($parent, $createStatement, $optionalArgs = []) $request->setExtraStatements($optionalArgs['extraStatements']); } - $mergedSettings = $this->defaultCallSettings['createDatabase']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['createDatabase']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->databaseAdminStub, 'CreateDatabase', @@ -656,9 +668,13 @@ public function getDatabase($name, $optionalArgs = []) $request = new GetDatabaseRequest(); $request->setName($name); - $mergedSettings = $this->defaultCallSettings['getDatabase']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['getDatabase']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->databaseAdminStub, 'GetDatabase', @@ -762,9 +778,13 @@ public function updateDatabaseDdl($database, $statements, $optionalArgs = []) $request->setOperationId($optionalArgs['operationId']); } - $mergedSettings = $this->defaultCallSettings['updateDatabaseDdl']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['updateDatabaseDdl']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->databaseAdminStub, 'UpdateDatabaseDdl', @@ -811,9 +831,13 @@ public function dropDatabase($database, $optionalArgs = []) $request = new DropDatabaseRequest(); $request->setDatabase($database); - $mergedSettings = $this->defaultCallSettings['dropDatabase']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['dropDatabase']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->databaseAdminStub, 'DropDatabase', @@ -864,9 +888,13 @@ public function getDatabaseDdl($database, $optionalArgs = []) $request = new GetDatabaseDdlRequest(); $request->setDatabase($database); - $mergedSettings = $this->defaultCallSettings['getDatabaseDdl']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['getDatabaseDdl']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->databaseAdminStub, 'GetDatabaseDdl', @@ -927,9 +955,13 @@ public function setIamPolicy($resource, $policy, $optionalArgs = []) $request->setResource($resource); $request->setPolicy($policy); - $mergedSettings = $this->defaultCallSettings['setIamPolicy']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['setIamPolicy']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->databaseAdminStub, 'SetIamPolicy', @@ -984,9 +1016,13 @@ public function getIamPolicy($resource, $optionalArgs = []) $request = new GetIamPolicyRequest(); $request->setResource($resource); - $mergedSettings = $this->defaultCallSettings['getIamPolicy']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['getIamPolicy']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->databaseAdminStub, 'GetIamPolicy', @@ -1048,9 +1084,13 @@ public function testIamPermissions($resource, $permissions, $optionalArgs = []) $request->setResource($resource); $request->setPermissions($permissions); - $mergedSettings = $this->defaultCallSettings['testIamPermissions']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['testIamPermissions']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->databaseAdminStub, 'TestIamPermissions', diff --git a/src/Spanner/Admin/Instance/V1/Gapic/InstanceAdminGapicClient.php b/src/Spanner/Admin/Instance/V1/Gapic/InstanceAdminGapicClient.php index 6f133c98538e..3160533a1b7f 100644 --- a/src/Spanner/Admin/Instance/V1/Gapic/InstanceAdminGapicClient.php +++ b/src/Spanner/Admin/Instance/V1/Gapic/InstanceAdminGapicClient.php @@ -325,7 +325,11 @@ public static function parseName($formattedName, $template = null) { $templateMap = self::getPathTemplateMap(); - if (isset($templateMap[$template])) { + if ($template) { + if (!isset($templateMap[$template])) { + throw new ValidationException("Template name $template does not exist"); + } + return $templateMap[$template]->match($formattedName); } @@ -563,9 +567,13 @@ public function listInstanceConfigs($parent, $optionalArgs = []) $request->setPageToken($optionalArgs['pageToken']); } - $mergedSettings = $this->defaultCallSettings['listInstanceConfigs']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listInstanceConfigs']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->instanceAdminStub, 'ListInstanceConfigs', @@ -615,9 +623,13 @@ public function getInstanceConfig($name, $optionalArgs = []) $request = new GetInstanceConfigRequest(); $request->setName($name); - $mergedSettings = $this->defaultCallSettings['getInstanceConfig']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['getInstanceConfig']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->instanceAdminStub, 'GetInstanceConfig', @@ -717,9 +729,13 @@ public function listInstances($parent, $optionalArgs = []) $request->setFilter($optionalArgs['filter']); } - $mergedSettings = $this->defaultCallSettings['listInstances']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['listInstances']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->instanceAdminStub, 'ListInstances', @@ -769,9 +785,13 @@ public function getInstance($name, $optionalArgs = []) $request = new GetInstanceRequest(); $request->setName($name); - $mergedSettings = $this->defaultCallSettings['getInstance']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['getInstance']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->instanceAdminStub, 'GetInstance', @@ -888,9 +908,13 @@ public function createInstance($parent, $instanceId, $instance, $optionalArgs = $request->setInstanceId($instanceId); $request->setInstance($instance); - $mergedSettings = $this->defaultCallSettings['createInstance']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['createInstance']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->instanceAdminStub, 'CreateInstance', @@ -1010,9 +1034,13 @@ public function updateInstance($instance, $fieldMask, $optionalArgs = []) $request->setInstance($instance); $request->setFieldMask($fieldMask); - $mergedSettings = $this->defaultCallSettings['updateInstance']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['updateInstance']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->instanceAdminStub, 'UpdateInstance', @@ -1070,9 +1098,13 @@ public function deleteInstance($name, $optionalArgs = []) $request = new DeleteInstanceRequest(); $request->setName($name); - $mergedSettings = $this->defaultCallSettings['deleteInstance']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['deleteInstance']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->instanceAdminStub, 'DeleteInstance', @@ -1133,9 +1165,13 @@ public function setIamPolicy($resource, $policy, $optionalArgs = []) $request->setResource($resource); $request->setPolicy($policy); - $mergedSettings = $this->defaultCallSettings['setIamPolicy']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['setIamPolicy']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->instanceAdminStub, 'SetIamPolicy', @@ -1190,9 +1226,13 @@ public function getIamPolicy($resource, $optionalArgs = []) $request = new GetIamPolicyRequest(); $request->setResource($resource); - $mergedSettings = $this->defaultCallSettings['getIamPolicy']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['getIamPolicy']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->instanceAdminStub, 'GetIamPolicy', @@ -1254,9 +1294,13 @@ public function testIamPermissions($resource, $permissions, $optionalArgs = []) $request->setResource($resource); $request->setPermissions($permissions); - $mergedSettings = $this->defaultCallSettings['testIamPermissions']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['testIamPermissions']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->instanceAdminStub, 'TestIamPermissions', diff --git a/src/Spanner/V1/Gapic/SpannerGapicClient.php b/src/Spanner/V1/Gapic/SpannerGapicClient.php index 985659b56275..c10f47559dd6 100644 --- a/src/Spanner/V1/Gapic/SpannerGapicClient.php +++ b/src/Spanner/V1/Gapic/SpannerGapicClient.php @@ -239,7 +239,11 @@ public static function parseName($formattedName, $template = null) { $templateMap = self::getPathTemplateMap(); - if (isset($templateMap[$template])) { + if ($template) { + if (!isset($templateMap[$template])) { + throw new ValidationException("Template name $template does not exist"); + } + return $templateMap[$template]->match($formattedName); } @@ -415,9 +419,13 @@ public function createSession($database, $optionalArgs = []) $request = new CreateSessionRequest(); $request->setDatabase($database); - $mergedSettings = $this->defaultCallSettings['createSession']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['createSession']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->spannerStub, 'CreateSession', @@ -468,9 +476,13 @@ public function getSession($name, $optionalArgs = []) $request = new GetSessionRequest(); $request->setName($name); - $mergedSettings = $this->defaultCallSettings['getSession']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['getSession']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->spannerStub, 'GetSession', @@ -517,9 +529,13 @@ public function deleteSession($name, $optionalArgs = []) $request = new DeleteSessionRequest(); $request->setName($name); - $mergedSettings = $this->defaultCallSettings['deleteSession']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['deleteSession']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->spannerStub, 'DeleteSession', @@ -634,9 +650,13 @@ public function executeSql($session, $sql, $optionalArgs = []) $request->setQueryMode($optionalArgs['queryMode']); } - $mergedSettings = $this->defaultCallSettings['executeSql']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['executeSql']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->spannerStub, 'ExecuteSql', @@ -753,9 +773,13 @@ public function executeStreamingSql($session, $sql, $optionalArgs = []) ]; } - $mergedSettings = $this->defaultCallSettings['executeStreamingSql']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['executeStreamingSql']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->spannerStub, 'ExecuteStreamingSql', @@ -864,9 +888,13 @@ public function read($session, $table, $columns, $keySet, $optionalArgs = []) $request->setResumeToken($optionalArgs['resumeToken']); } - $mergedSettings = $this->defaultCallSettings['read']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['read']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->spannerStub, 'Read', @@ -975,9 +1003,13 @@ public function streamingRead($session, $table, $columns, $keySet, $optionalArgs ]; } - $mergedSettings = $this->defaultCallSettings['streamingRead']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['streamingRead']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->spannerStub, 'StreamingRead', @@ -1032,9 +1064,13 @@ public function beginTransaction($session, $options, $optionalArgs = []) $request->setSession($session); $request->setOptions($options); - $mergedSettings = $this->defaultCallSettings['beginTransaction']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['beginTransaction']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->spannerStub, 'BeginTransaction', @@ -1113,9 +1149,13 @@ public function commit($session, $mutations, $optionalArgs = []) $request->setSingleUseTransaction($optionalArgs['singleUseTransaction']); } - $mergedSettings = $this->defaultCallSettings['commit']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['commit']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->spannerStub, 'Commit', @@ -1172,9 +1212,13 @@ public function rollback($session, $transactionId, $optionalArgs = []) $request->setSession($session); $request->setTransactionId($transactionId); - $mergedSettings = $this->defaultCallSettings['rollback']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['rollback']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->spannerStub, 'Rollback', diff --git a/src/Speech/V1/Gapic/SpeechGapicClient.php b/src/Speech/V1/Gapic/SpeechGapicClient.php index d0142b745d9b..6151aaa71b6a 100644 --- a/src/Speech/V1/Gapic/SpeechGapicClient.php +++ b/src/Speech/V1/Gapic/SpeechGapicClient.php @@ -341,9 +341,13 @@ public function recognize($config, $audio, $optionalArgs = []) $request->setConfig($config); $request->setAudio($audio); - $mergedSettings = $this->defaultCallSettings['recognize']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['recognize']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->speechStub, 'Recognize', @@ -432,9 +436,13 @@ public function longRunningRecognize($config, $audio, $optionalArgs = []) $request->setConfig($config); $request->setAudio($audio); - $mergedSettings = $this->defaultCallSettings['longRunningRecognize']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['longRunningRecognize']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->speechStub, 'LongRunningRecognize', @@ -509,9 +517,13 @@ public function streamingRecognize($optionalArgs = []) ]; } - $mergedSettings = $this->defaultCallSettings['streamingRecognize']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['streamingRecognize']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->speechStub, 'StreamingRecognize', diff --git a/src/Speech/V1beta1/Gapic/SpeechGapicClient.php b/src/Speech/V1beta1/Gapic/SpeechGapicClient.php index 92e60f318eb4..9d3071a1a5ae 100644 --- a/src/Speech/V1beta1/Gapic/SpeechGapicClient.php +++ b/src/Speech/V1beta1/Gapic/SpeechGapicClient.php @@ -337,9 +337,13 @@ public function syncRecognize($config, $audio, $optionalArgs = []) $request->setConfig($config); $request->setAudio($audio); - $mergedSettings = $this->defaultCallSettings['syncRecognize']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['syncRecognize']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->speechStub, 'SyncRecognize', @@ -428,9 +432,13 @@ public function asyncRecognize($config, $audio, $optionalArgs = []) $request->setConfig($config); $request->setAudio($audio); - $mergedSettings = $this->defaultCallSettings['asyncRecognize']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['asyncRecognize']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->speechStub, 'AsyncRecognize', @@ -505,9 +513,13 @@ public function streamingRecognize($optionalArgs = []) ]; } - $mergedSettings = $this->defaultCallSettings['streamingRecognize']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['streamingRecognize']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->speechStub, 'StreamingRecognize', diff --git a/src/VideoIntelligence/V1beta1/Gapic/VideoIntelligenceServiceGapicClient.php b/src/VideoIntelligence/V1beta1/Gapic/VideoIntelligenceServiceGapicClient.php index 65b57551e6a4..6cb416296c74 100644 --- a/src/VideoIntelligence/V1beta1/Gapic/VideoIntelligenceServiceGapicClient.php +++ b/src/VideoIntelligence/V1beta1/Gapic/VideoIntelligenceServiceGapicClient.php @@ -398,9 +398,13 @@ public function annotateVideo($inputUri, $features, $optionalArgs = []) $request->setLocationId($optionalArgs['locationId']); } - $mergedSettings = $this->defaultCallSettings['annotateVideo']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['annotateVideo']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->videoIntelligenceServiceStub, 'AnnotateVideo', diff --git a/src/VideoIntelligence/V1beta2/Gapic/VideoIntelligenceServiceGapicClient.php b/src/VideoIntelligence/V1beta2/Gapic/VideoIntelligenceServiceGapicClient.php index 89bb2745d507..691ec2bf34dd 100644 --- a/src/VideoIntelligence/V1beta2/Gapic/VideoIntelligenceServiceGapicClient.php +++ b/src/VideoIntelligence/V1beta2/Gapic/VideoIntelligenceServiceGapicClient.php @@ -398,9 +398,13 @@ public function annotateVideo($inputUri, $features, $optionalArgs = []) $request->setLocationId($optionalArgs['locationId']); } - $mergedSettings = $this->defaultCallSettings['annotateVideo']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['annotateVideo']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->videoIntelligenceServiceStub, 'AnnotateVideo', diff --git a/src/Vision/V1/Gapic/ImageAnnotatorGapicClient.php b/src/Vision/V1/Gapic/ImageAnnotatorGapicClient.php index 37859d76975b..c98e572bdee9 100644 --- a/src/Vision/V1/Gapic/ImageAnnotatorGapicClient.php +++ b/src/Vision/V1/Gapic/ImageAnnotatorGapicClient.php @@ -238,9 +238,13 @@ public function batchAnnotateImages($requests, $optionalArgs = []) $request = new BatchAnnotateImagesRequest(); $request->setRequests($requests); - $mergedSettings = $this->defaultCallSettings['batchAnnotateImages']->merge( - new CallSettings($optionalArgs) - ); + $defaultCallSettings = $this->defaultCallSettings['batchAnnotateImages']; + if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) { + $optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with( + $optionalArgs['retrySettings'] + ); + } + $mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs)); $callable = ApiCallable::createApiCall( $this->imageAnnotatorStub, 'BatchAnnotateImages', From 1389b88c4761d7bf949a45b82bc944a5027a0247 Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Tue, 19 Sep 2017 12:27:41 -0700 Subject: [PATCH 15/17] Restore UpdateSubsciption --- src/PubSub/Connection/ConnectionInterface.php | 5 ++ src/PubSub/Connection/Grpc.php | 22 +++++++++ src/PubSub/Connection/Rest.php | 8 ++++ src/PubSub/Subscription.php | 46 +++++++++++++++++++ tests/snippets/PubSub/SubscriptionTest.php | 13 ++++++ 5 files changed, 94 insertions(+) diff --git a/src/PubSub/Connection/ConnectionInterface.php b/src/PubSub/Connection/ConnectionInterface.php index 8cb8c2418e8c..da992fa31bd2 100644 --- a/src/PubSub/Connection/ConnectionInterface.php +++ b/src/PubSub/Connection/ConnectionInterface.php @@ -73,6 +73,11 @@ public function testTopicIamPermissions(array $args); */ public function createSubscription(array $args); + /** + * @param array $args + */ + public function updateSubscription(array $args); + /** * @param array $args */ diff --git a/src/PubSub/Connection/Grpc.php b/src/PubSub/Connection/Grpc.php index e0a1dd5a34df..43a5e631035d 100644 --- a/src/PubSub/Connection/Grpc.php +++ b/src/PubSub/Connection/Grpc.php @@ -180,6 +180,28 @@ public function createSubscription(array $args) ]); } + /** + * @param array $args + */ + public function updateSubscription(array $args) + { + // Get a list of keys used before building subscription, which modifies $args + $mask = array_keys($args); + + // Remove immutable properties. + $mask = array_values(array_diff($mask, ['name', 'topic'])); + + $fieldMask = $this->serializer->decodeMessage(new FieldMask(), ['paths' => $mask]); + + $subscriptionObject = $this->buildSubscription($args); + + return $this->send([$this->subscriberClient, 'updateSubscription'], [ + $subscriptionObject, + $fieldMask, + $args + ]); + } + /** * @param array $args */ diff --git a/src/PubSub/Connection/Rest.php b/src/PubSub/Connection/Rest.php index 86f723edd84c..d45e9b4b2d15 100644 --- a/src/PubSub/Connection/Rest.php +++ b/src/PubSub/Connection/Rest.php @@ -145,6 +145,14 @@ public function createSubscription(array $args) return $this->send('subscriptions', 'create', $args); } + /** + * @param array $args + */ + public function updateSubscription(array $args) + { + return $this->send('subscriptions', 'patch', $args); + } + /** * @param array $args */ diff --git a/src/PubSub/Subscription.php b/src/PubSub/Subscription.php index 062c7431eb11..0b70412195b4 100644 --- a/src/PubSub/Subscription.php +++ b/src/PubSub/Subscription.php @@ -222,6 +222,52 @@ public function create(array $options = []) return $this->info; } + /** + * Update the subscription. + * + * Note that subscription name and topic are immutable properties and may + * not be modified. + * + * Example: + * ``` + * $subscription->update([ + * 'retainAckedMessages' => true + * ]); + * ``` + * + * @param array $subscription { + * The Subscription data. + * + * For information regarding the push configuration settings, see + * [PushConfig](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions#PushConfig). + * + * @type string $pushConfig.pushEndpoint A URL locating the endpoint to which + * messages should be pushed. For example, a Webhook endpoint + * might use "https://example.com/push". + * @type array $pushConfig.attributes Endpoint configuration attributes. + * @type int $ackDeadlineSeconds The maximum time after a subscriber + * receives a message before the subscriber should acknowledge the + * message. + * @type bool $retainAckedMessages Indicates whether to retain + * acknowledged messages. + * @type Duration $messageRetentionDuration How long to retain + * unacknowledged messages in the subscription's backlog, from the + * moment a message is published. If `$retainAckedMessages` is + * true, then this also configures the retention of acknowledged + * messages, and thus configures how far back in time a `Seek` + * can be done. Cannot be more than 7 days or less than 10 minutes. + * **Defaults to** 7 days. + * } + * @param array $options [optional] Configuration options. + * @return array The subscription info. + */ + public function update(array $subscription, array $options = []) + { + return $this->info = $this->connection->updateSubscription([ + 'name' => $this->name + ] + $options + $subscription); + } + /** * Delete a subscription * diff --git a/tests/snippets/PubSub/SubscriptionTest.php b/tests/snippets/PubSub/SubscriptionTest.php index 90e02847641d..df9c6e9f94de 100644 --- a/tests/snippets/PubSub/SubscriptionTest.php +++ b/tests/snippets/PubSub/SubscriptionTest.php @@ -95,6 +95,19 @@ public function testCreate() $this->assertEquals($return, $res->returnVal()); } + public function testUpdate() + { + $snippet = $this->snippetFromMethod(Subscription::class, 'update'); + $snippet->addLocal('subscription', $this->subscription); + + $this->connection->updateSubscription(Argument::any()) + ->shouldBeCalled(); + + $this->subscription->___setProperty('connection', $this->connection->reveal()); + + $snippet->invoke(); + } + public function testDelete() { $snippet = $this->snippetFromMethod(Subscription::class, 'delete'); From 8408e9f8af22267784ce072ba3fb8d7ede13d53e Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Tue, 19 Sep 2017 13:19:35 -0700 Subject: [PATCH 16/17] Trigger CI From ade1a7126bc7555d6abea0bd4518eb4d4e84827c Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Tue, 19 Sep 2017 13:20:42 -0700 Subject: [PATCH 17/17] Empty commit to trigger CI