From 8685df08a47559cb417b869558334e6e3d7507de Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Wed, 11 Jan 2023 18:45:51 -0800 Subject: [PATCH] feat: [PubSub] add schema evolution methods and fields (#5722) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(pubsub): remove extraneous ctype field annotations PiperOrigin-RevId: 496666857 Source-Link: https://github.com/googleapis/googleapis/commit/bc27df2b63e5fd03e85dbcdc3480fed38bea6d36 Source-Link: https://github.com/googleapis/googleapis-gen/commit/941b568027b145bfb540e8ee1df4d4ccd44977fc Copy-Tag: eyJwIjoiUHViU3ViLy5Pd2xCb3QueWFtbCIsImgiOiI5NDFiNTY4MDI3YjE0NWJmYjU0MGU4ZWUxZGY0ZDRjY2Q0NDk3N2ZjIn0= * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * feat: Add location methods PiperOrigin-RevId: 499263614 Source-Link: https://github.com/googleapis/googleapis/commit/ba2db0d89a145c14ef11c0ec2eda0c80fe16f17e Source-Link: https://github.com/googleapis/googleapis-gen/commit/503d1e8eff04535fc5d4b74fe1c894e67fd596b2 Copy-Tag: eyJwIjoiUHViU3ViLy5Pd2xCb3QueWFtbCIsImgiOiI1MDNkMWU4ZWZmMDQ1MzVmYzVkNGI3NGZlMWM4OTRlNjdmZDU5NmIyIn0= * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore(bazel): update gapic-generator-php to v1.6.4 PiperOrigin-RevId: 499941754 Source-Link: https://github.com/googleapis/googleapis/commit/71b5bbcb2e8343bf08de56ccd239d308327a114f Source-Link: https://github.com/googleapis/googleapis-gen/commit/113c51b303b47fe8315c536260da50a92c277b39 Copy-Tag: eyJwIjoiUHViU3ViLy5Pd2xCb3QueWFtbCIsImgiOiIxMTNjNTFiMzAzYjQ3ZmU4MzE1YzUzNjI2MGRhNTBhOTJjMjc3YjM5In0= * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * feat: add schema evolution methods and fields PiperOrigin-RevId: 500819578 Source-Link: https://github.com/googleapis/googleapis/commit/05a375f20b0e76e0106990aa9fadab98498dbea0 Source-Link: https://github.com/googleapis/googleapis-gen/commit/303c9592c498dc02432daa29acb46d67decfb0c2 Copy-Tag: eyJwIjoiUHViU3ViLy5Pd2xCb3QueWFtbCIsImgiOiIzMDNjOTU5MmM0OThkYzAyNDMyZGFhMjlhY2I0NmQ2N2RlY2ZiMGMyIn0= * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- PubSub/metadata/V1/Pubsub.php | Bin 13253 -> 13287 bytes PubSub/metadata/V1/Schema.php | Bin 3594 -> 5036 bytes .../V1/SchemaServiceClient/commit_schema.php | 74 +++++ .../delete_schema_revision.php | 74 +++++ .../list_schema_revisions.php | 71 +++++ .../SchemaServiceClient/rollback_schema.php | 71 +++++ PubSub/src/V1/BigQueryConfig.php | 16 +- PubSub/src/V1/CommitSchemaRequest.php | 115 +++++++ PubSub/src/V1/DeleteSchemaRevisionRequest.php | 117 ++++++++ .../src/V1/Gapic/SchemaServiceGapicClient.php | 225 +++++++++++++- PubSub/src/V1/Gapic/SubscriberGapicClient.php | 4 +- PubSub/src/V1/GetSchemaRequest.php | 12 +- PubSub/src/V1/ListSchemaRevisionsRequest.php | 181 +++++++++++ PubSub/src/V1/ListSchemaRevisionsResponse.php | 105 +++++++ PubSub/src/V1/RollbackSchemaRequest.php | 109 +++++++ PubSub/src/V1/Schema.php | 78 +++++ PubSub/src/V1/SchemaServiceGrpcClient.php | 60 ++++ PubSub/src/V1/SchemaSettings.php | 84 ++++++ .../AcknowledgeConfirmation.php | 18 +- .../ModifyAckDeadlineConfirmation.php | 12 +- PubSub/src/V1/Subscription.php | 16 +- PubSub/src/V1/gapic_metadata.json | 20 ++ .../publisher_rest_client_config.php | 1 + .../schema_service_client_config.json | 20 ++ .../schema_service_descriptor_config.php | 10 + .../schema_service_rest_client_config.php | 47 +++ .../subscriber_rest_client_config.php | 1 + .../tests/Unit/V1/SchemaServiceClientTest.php | 281 ++++++++++++++++++ 28 files changed, 1777 insertions(+), 45 deletions(-) create mode 100644 PubSub/samples/V1/SchemaServiceClient/commit_schema.php create mode 100644 PubSub/samples/V1/SchemaServiceClient/delete_schema_revision.php create mode 100644 PubSub/samples/V1/SchemaServiceClient/list_schema_revisions.php create mode 100644 PubSub/samples/V1/SchemaServiceClient/rollback_schema.php create mode 100644 PubSub/src/V1/CommitSchemaRequest.php create mode 100644 PubSub/src/V1/DeleteSchemaRevisionRequest.php create mode 100644 PubSub/src/V1/ListSchemaRevisionsRequest.php create mode 100644 PubSub/src/V1/ListSchemaRevisionsResponse.php create mode 100644 PubSub/src/V1/RollbackSchemaRequest.php diff --git a/PubSub/metadata/V1/Pubsub.php b/PubSub/metadata/V1/Pubsub.php index 509dd54c1fcbb3c1747a792c54addea29db37eae..5937953f483924626e2c024ac0e824f9e80831f7 100644 GIT binary patch delta 257 zcmX?_{ycrdS!Twgo6j+)Ffy%VoNUZmVk#ubC7703R9q5YlvO5_roEGHwjnOAm)7y$A)N=pC$ delta 126 zcmaE!el&f9ZVB;F6u_EjyW! zxkW`vK0QA_JttMa0IFWU1g2gOETpuTX>td1OpK5;7k5!=S!Qu&eqMZLiUf-SqXwrF z+XF||2ae1_wp=1`$>gHc#FEr_kU0`;KvmpEQhE?eASMDGr3ZJE6Ejfz<|oWkn8X(| za!L7Q7MBDkXQbvP20`sAp4`r6J=u{}XYyB84bem{X-p-Pwb=YPE4YN6^K)}EOC~q6 zIZocrqR*q0$|V|yQJo%mZYLu4zgPcx3>UC`KI~Nu^1}rAc~ahI%k1lOJ+waJqqw z)>YB~8Es`%1PxiR;R0a8ix9~}XcZ%u2(}Ofdg~^a0vjY9O%CMLU^dXw1DU8~l>&|c Qm|t%>Vi>ylIF~as0Cp|;7ytkO delta 49 zcmV-10M7rcCyE@fu>zCr0xtsJ6_XwVqXQ!00h8qeT(g}7lmfGe36}x__Xo2f47UNZ HY7jyL&@vH< diff --git a/PubSub/samples/V1/SchemaServiceClient/commit_schema.php b/PubSub/samples/V1/SchemaServiceClient/commit_schema.php new file mode 100644 index 000000000000..e9f7e256a52d --- /dev/null +++ b/PubSub/samples/V1/SchemaServiceClient/commit_schema.php @@ -0,0 +1,74 @@ +setName($schemaName); + + // Call the API and handle any network failures. + try { + /** @var Schema $response */ + $response = $schemaServiceClient->commitSchema($formattedName, $schema); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} + +/** + * Helper to execute the sample. + * + * This sample has been automatically generated and should be regarded as a code + * template only. It will require modifications to work: + * - It may require correct/in-range values for request initialization. + * - It may require specifying regional endpoints when creating the service client, + * please see the apiEndpoint client configuration option for more details. + */ +function callSample(): void +{ + $formattedName = SchemaServiceClient::schemaName('[PROJECT]', '[SCHEMA]'); + $schemaName = '[NAME]'; + + commit_schema_sample($formattedName, $schemaName); +} +// [END pubsub_v1_generated_SchemaService_CommitSchema_sync] diff --git a/PubSub/samples/V1/SchemaServiceClient/delete_schema_revision.php b/PubSub/samples/V1/SchemaServiceClient/delete_schema_revision.php new file mode 100644 index 000000000000..d0dbe2c1c32f --- /dev/null +++ b/PubSub/samples/V1/SchemaServiceClient/delete_schema_revision.php @@ -0,0 +1,74 @@ +deleteSchemaRevision($formattedName, $revisionId); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} + +/** + * Helper to execute the sample. + * + * This sample has been automatically generated and should be regarded as a code + * template only. It will require modifications to work: + * - It may require correct/in-range values for request initialization. + * - It may require specifying regional endpoints when creating the service client, + * please see the apiEndpoint client configuration option for more details. + */ +function callSample(): void +{ + $formattedName = SchemaServiceClient::schemaName('[PROJECT]', '[SCHEMA]'); + $revisionId = '[REVISION_ID]'; + + delete_schema_revision_sample($formattedName, $revisionId); +} +// [END pubsub_v1_generated_SchemaService_DeleteSchemaRevision_sync] diff --git a/PubSub/samples/V1/SchemaServiceClient/list_schema_revisions.php b/PubSub/samples/V1/SchemaServiceClient/list_schema_revisions.php new file mode 100644 index 000000000000..910003c66ecc --- /dev/null +++ b/PubSub/samples/V1/SchemaServiceClient/list_schema_revisions.php @@ -0,0 +1,71 @@ +listSchemaRevisions($formattedName); + + /** @var Schema $element */ + foreach ($response as $element) { + printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString()); + } + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} + +/** + * Helper to execute the sample. + * + * This sample has been automatically generated and should be regarded as a code + * template only. It will require modifications to work: + * - It may require correct/in-range values for request initialization. + * - It may require specifying regional endpoints when creating the service client, + * please see the apiEndpoint client configuration option for more details. + */ +function callSample(): void +{ + $formattedName = SchemaServiceClient::schemaName('[PROJECT]', '[SCHEMA]'); + + list_schema_revisions_sample($formattedName); +} +// [END pubsub_v1_generated_SchemaService_ListSchemaRevisions_sync] diff --git a/PubSub/samples/V1/SchemaServiceClient/rollback_schema.php b/PubSub/samples/V1/SchemaServiceClient/rollback_schema.php new file mode 100644 index 000000000000..412f943708ba --- /dev/null +++ b/PubSub/samples/V1/SchemaServiceClient/rollback_schema.php @@ -0,0 +1,71 @@ +rollbackSchema($formattedName, $revisionId); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} + +/** + * Helper to execute the sample. + * + * This sample has been automatically generated and should be regarded as a code + * template only. It will require modifications to work: + * - It may require correct/in-range values for request initialization. + * - It may require specifying regional endpoints when creating the service client, + * please see the apiEndpoint client configuration option for more details. + */ +function callSample(): void +{ + $formattedName = SchemaServiceClient::schemaName('[PROJECT]', '[SCHEMA]'); + $revisionId = '[REVISION_ID]'; + + rollback_schema_sample($formattedName, $revisionId); +} +// [END pubsub_v1_generated_SchemaService_RollbackSchema_sync] diff --git a/PubSub/src/V1/BigQueryConfig.php b/PubSub/src/V1/BigQueryConfig.php index e5851605fcea..a3662721cb00 100644 --- a/PubSub/src/V1/BigQueryConfig.php +++ b/PubSub/src/V1/BigQueryConfig.php @@ -50,8 +50,8 @@ class BigQueryConfig extends \Google\Protobuf\Internal\Message */ private $drop_unknown_fields = false; /** - * Output only. An output-only field that indicates whether or not the subscription can - * receive messages. + * Output only. An output-only field that indicates whether or not the + * subscription can receive messages. * * Generated from protobuf field .google.pubsub.v1.BigQueryConfig.State state = 5 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ @@ -82,8 +82,8 @@ class BigQueryConfig extends \Google\Protobuf\Internal\Message * any messages with extra fields are not written and remain in the * subscription's backlog. * @type int $state - * Output only. An output-only field that indicates whether or not the subscription can - * receive messages. + * Output only. An output-only field that indicates whether or not the + * subscription can receive messages. * } */ public function __construct($data = NULL) { @@ -216,8 +216,8 @@ public function setDropUnknownFields($var) } /** - * Output only. An output-only field that indicates whether or not the subscription can - * receive messages. + * Output only. An output-only field that indicates whether or not the + * subscription can receive messages. * * Generated from protobuf field .google.pubsub.v1.BigQueryConfig.State state = 5 [(.google.api.field_behavior) = OUTPUT_ONLY]; * @return int @@ -228,8 +228,8 @@ public function getState() } /** - * Output only. An output-only field that indicates whether or not the subscription can - * receive messages. + * Output only. An output-only field that indicates whether or not the + * subscription can receive messages. * * Generated from protobuf field .google.pubsub.v1.BigQueryConfig.State state = 5 [(.google.api.field_behavior) = OUTPUT_ONLY]; * @param int $var diff --git a/PubSub/src/V1/CommitSchemaRequest.php b/PubSub/src/V1/CommitSchemaRequest.php new file mode 100644 index 000000000000..fb07fcfd0eda --- /dev/null +++ b/PubSub/src/V1/CommitSchemaRequest.php @@ -0,0 +1,115 @@ +google.pubsub.v1.CommitSchemaRequest + */ +class CommitSchemaRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The name of the schema we are revising. + * Format is `projects/{project}/schemas/{schema}`. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + private $name = ''; + /** + * Required. The schema revision to commit. + * + * Generated from protobuf field .google.pubsub.v1.Schema schema = 2 [(.google.api.field_behavior) = REQUIRED]; + */ + private $schema = null; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Required. The name of the schema we are revising. + * Format is `projects/{project}/schemas/{schema}`. + * @type \Google\Cloud\PubSub\V1\Schema $schema + * Required. The schema revision to commit. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Pubsub\V1\Schema::initOnce(); + parent::__construct($data); + } + + /** + * Required. The name of the schema we are revising. + * Format is `projects/{project}/schemas/{schema}`. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Required. The name of the schema we are revising. + * Format is `projects/{project}/schemas/{schema}`. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * Required. The schema revision to commit. + * + * Generated from protobuf field .google.pubsub.v1.Schema schema = 2 [(.google.api.field_behavior) = REQUIRED]; + * @return \Google\Cloud\PubSub\V1\Schema|null + */ + public function getSchema() + { + return $this->schema; + } + + public function hasSchema() + { + return isset($this->schema); + } + + public function clearSchema() + { + unset($this->schema); + } + + /** + * Required. The schema revision to commit. + * + * Generated from protobuf field .google.pubsub.v1.Schema schema = 2 [(.google.api.field_behavior) = REQUIRED]; + * @param \Google\Cloud\PubSub\V1\Schema $var + * @return $this + */ + public function setSchema($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\PubSub\V1\Schema::class); + $this->schema = $var; + + return $this; + } + +} + diff --git a/PubSub/src/V1/DeleteSchemaRevisionRequest.php b/PubSub/src/V1/DeleteSchemaRevisionRequest.php new file mode 100644 index 000000000000..01166ca79903 --- /dev/null +++ b/PubSub/src/V1/DeleteSchemaRevisionRequest.php @@ -0,0 +1,117 @@ +google.pubsub.v1.DeleteSchemaRevisionRequest + */ +class DeleteSchemaRevisionRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The name of the schema revision to be deleted, with a revision ID + * explicitly included. + * Example: projects/123/schemas/my-schema@c7cfa2a8 + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + private $name = ''; + /** + * Required. The revision ID to roll back to. + * It must be a revision of the same schema. + * Example: c7cfa2a8 + * + * Generated from protobuf field string revision_id = 2 [(.google.api.field_behavior) = REQUIRED]; + */ + private $revision_id = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Required. The name of the schema revision to be deleted, with a revision ID + * explicitly included. + * Example: projects/123/schemas/my-schema@c7cfa2a8 + * @type string $revision_id + * Required. The revision ID to roll back to. + * It must be a revision of the same schema. + * Example: c7cfa2a8 + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Pubsub\V1\Schema::initOnce(); + parent::__construct($data); + } + + /** + * Required. The name of the schema revision to be deleted, with a revision ID + * explicitly included. + * Example: projects/123/schemas/my-schema@c7cfa2a8 + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Required. The name of the schema revision to be deleted, with a revision ID + * explicitly included. + * Example: projects/123/schemas/my-schema@c7cfa2a8 + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * Required. The revision ID to roll back to. + * It must be a revision of the same schema. + * Example: c7cfa2a8 + * + * Generated from protobuf field string revision_id = 2 [(.google.api.field_behavior) = REQUIRED]; + * @return string + */ + public function getRevisionId() + { + return $this->revision_id; + } + + /** + * Required. The revision ID to roll back to. + * It must be a revision of the same schema. + * Example: c7cfa2a8 + * + * Generated from protobuf field string revision_id = 2 [(.google.api.field_behavior) = REQUIRED]; + * @param string $var + * @return $this + */ + public function setRevisionId($var) + { + GPBUtil::checkString($var, True); + $this->revision_id = $var; + + return $this; + } + +} + diff --git a/PubSub/src/V1/Gapic/SchemaServiceGapicClient.php b/PubSub/src/V1/Gapic/SchemaServiceGapicClient.php index 7502df8ab253..141652aff048 100644 --- a/PubSub/src/V1/Gapic/SchemaServiceGapicClient.php +++ b/PubSub/src/V1/Gapic/SchemaServiceGapicClient.php @@ -40,12 +40,17 @@ use Google\Cloud\Iam\V1\SetIamPolicyRequest; use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; +use Google\Cloud\PubSub\V1\CommitSchemaRequest; use Google\Cloud\PubSub\V1\CreateSchemaRequest; use Google\Cloud\PubSub\V1\DeleteSchemaRequest; +use Google\Cloud\PubSub\V1\DeleteSchemaRevisionRequest; use Google\Cloud\PubSub\V1\Encoding; use Google\Cloud\PubSub\V1\GetSchemaRequest; +use Google\Cloud\PubSub\V1\ListSchemaRevisionsRequest; +use Google\Cloud\PubSub\V1\ListSchemaRevisionsResponse; use Google\Cloud\PubSub\V1\ListSchemasRequest; use Google\Cloud\PubSub\V1\ListSchemasResponse; +use Google\Cloud\PubSub\V1\RollbackSchemaRequest; use Google\Cloud\PubSub\V1\Schema; use Google\Cloud\PubSub\V1\ValidateMessageRequest; use Google\Cloud\PubSub\V1\ValidateMessageResponse; @@ -63,9 +68,9 @@ * ``` * $schemaServiceClient = new SchemaServiceClient(); * try { - * $formattedParent = $schemaServiceClient->projectName('[PROJECT]'); + * $formattedName = $schemaServiceClient->schemaName('[PROJECT]', '[SCHEMA]'); * $schema = new Schema(); - * $response = $schemaServiceClient->createSchema($formattedParent, $schema); + * $response = $schemaServiceClient->commitSchema($formattedName, $schema); * } finally { * $schemaServiceClient->close(); * } @@ -287,6 +292,49 @@ public function __construct(array $options = []) $this->setClientOptions($clientOptions); } + /** + * Commits a new schema revision to an existing schema. + * + * Sample code: + * ``` + * $schemaServiceClient = new SchemaServiceClient(); + * try { + * $formattedName = $schemaServiceClient->schemaName('[PROJECT]', '[SCHEMA]'); + * $schema = new Schema(); + * $response = $schemaServiceClient->commitSchema($formattedName, $schema); + * } finally { + * $schemaServiceClient->close(); + * } + * ``` + * + * @param string $name Required. The name of the schema we are revising. + * Format is `projects/{project}/schemas/{schema}`. + * @param Schema $schema Required. The schema revision to commit. + * @param array $optionalArgs { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return \Google\Cloud\PubSub\V1\Schema + * + * @throws ApiException if the remote call fails + */ + public function commitSchema($name, $schema, array $optionalArgs = []) + { + $request = new CommitSchemaRequest(); + $requestParamHeaders = []; + $request->setName($name); + $request->setSchema($schema); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('CommitSchema', Schema::class, $optionalArgs, $request)->wait(); + } + /** * Creates a schema. * @@ -382,6 +430,54 @@ public function deleteSchema($name, array $optionalArgs = []) return $this->startCall('DeleteSchema', GPBEmpty::class, $optionalArgs, $request)->wait(); } + /** + * Deletes a specific schema revision. + * + * Sample code: + * ``` + * $schemaServiceClient = new SchemaServiceClient(); + * try { + * $formattedName = $schemaServiceClient->schemaName('[PROJECT]', '[SCHEMA]'); + * $revisionId = 'revision_id'; + * $response = $schemaServiceClient->deleteSchemaRevision($formattedName, $revisionId); + * } finally { + * $schemaServiceClient->close(); + * } + * ``` + * + * @param string $name Required. The name of the schema revision to be deleted, with a revision ID + * explicitly included. + * + * Example: projects/123/schemas/my-schema@c7cfa2a8 + * @param string $revisionId Required. The revision ID to roll back to. + * It must be a revision of the same schema. + * + * Example: c7cfa2a8 + * @param array $optionalArgs { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return \Google\Cloud\PubSub\V1\Schema + * + * @throws ApiException if the remote call fails + */ + public function deleteSchemaRevision($name, $revisionId, array $optionalArgs = []) + { + $request = new DeleteSchemaRevisionRequest(); + $requestParamHeaders = []; + $request->setName($name); + $request->setRevisionId($revisionId); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('DeleteSchemaRevision', Schema::class, $optionalArgs, $request)->wait(); + } + /** * Gets a schema. * @@ -403,8 +499,7 @@ public function deleteSchema($name, array $optionalArgs = []) * * @type int $view * The set of fields to return in the response. If not set, returns a Schema - * with `name` and `type`, but not `definition`. Set to `FULL` to retrieve all - * fields. + * with all fields filled out. Set to `BASIC` to omit the `definition`. * For allowed values, use constants defined on {@see \Google\Cloud\PubSub\V1\SchemaView} * @type RetrySettings|array $retrySettings * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an @@ -431,6 +526,83 @@ public function getSchema($name, array $optionalArgs = []) return $this->startCall('GetSchema', Schema::class, $optionalArgs, $request)->wait(); } + /** + * Lists all schema revisions for the named schema. + * + * Sample code: + * ``` + * $schemaServiceClient = new SchemaServiceClient(); + * try { + * $formattedName = $schemaServiceClient->schemaName('[PROJECT]', '[SCHEMA]'); + * // Iterate over pages of elements + * $pagedResponse = $schemaServiceClient->listSchemaRevisions($formattedName); + * foreach ($pagedResponse->iteratePages() as $page) { + * foreach ($page as $element) { + * // doSomethingWith($element); + * } + * } + * // Alternatively: + * // Iterate through all elements + * $pagedResponse = $schemaServiceClient->listSchemaRevisions($formattedName); + * foreach ($pagedResponse->iterateAllElements() as $element) { + * // doSomethingWith($element); + * } + * } finally { + * $schemaServiceClient->close(); + * } + * ``` + * + * @param string $name Required. The name of the schema to list revisions for. + * @param array $optionalArgs { + * Optional. + * + * @type int $view + * The set of Schema fields to return in the response. If not set, returns + * Schemas with `name` and `type`, but not `definition`. Set to `FULL` to + * retrieve all fields. + * For allowed values, use constants defined on {@see \Google\Cloud\PubSub\V1\SchemaView} + * @type int $pageSize + * 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 string $pageToken + * A page token is used to specify a page of values to be returned. + * 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 RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return \Google\ApiCore\PagedListResponse + * + * @throws ApiException if the remote call fails + */ + public function listSchemaRevisions($name, array $optionalArgs = []) + { + $request = new ListSchemaRevisionsRequest(); + $requestParamHeaders = []; + $request->setName($name); + $requestParamHeaders['name'] = $name; + if (isset($optionalArgs['view'])) { + $request->setView($optionalArgs['view']); + } + + if (isset($optionalArgs['pageSize'])) { + $request->setPageSize($optionalArgs['pageSize']); + } + + if (isset($optionalArgs['pageToken'])) { + $request->setPageToken($optionalArgs['pageToken']); + } + + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->getPagedListResponse('ListSchemaRevisions', $optionalArgs, ListSchemaRevisionsResponse::class, $request); + } + /** * Lists schemas in a project. * @@ -509,6 +681,51 @@ public function listSchemas($parent, array $optionalArgs = []) return $this->getPagedListResponse('ListSchemas', $optionalArgs, ListSchemasResponse::class, $request); } + /** + * Creates a new schema revision that is a copy of the provided revision_id. + * + * Sample code: + * ``` + * $schemaServiceClient = new SchemaServiceClient(); + * try { + * $formattedName = $schemaServiceClient->schemaName('[PROJECT]', '[SCHEMA]'); + * $revisionId = 'revision_id'; + * $response = $schemaServiceClient->rollbackSchema($formattedName, $revisionId); + * } finally { + * $schemaServiceClient->close(); + * } + * ``` + * + * @param string $name Required. The schema being rolled back with revision id. + * @param string $revisionId Required. The revision ID to roll back to. + * It must be a revision of the same schema. + * + * Example: c7cfa2a8 + * @param array $optionalArgs { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return \Google\Cloud\PubSub\V1\Schema + * + * @throws ApiException if the remote call fails + */ + public function rollbackSchema($name, $revisionId, array $optionalArgs = []) + { + $request = new RollbackSchemaRequest(); + $requestParamHeaders = []; + $request->setName($name); + $request->setRevisionId($revisionId); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('RollbackSchema', Schema::class, $optionalArgs, $request)->wait(); + } + /** * Validates a message against a schema. * diff --git a/PubSub/src/V1/Gapic/SubscriberGapicClient.php b/PubSub/src/V1/Gapic/SubscriberGapicClient.php index bd1ce7765fdf..87d4832123b4 100644 --- a/PubSub/src/V1/Gapic/SubscriberGapicClient.php +++ b/PubSub/src/V1/Gapic/SubscriberGapicClient.php @@ -694,8 +694,8 @@ public function createSnapshot($name, $subscription, array $optionalArgs = []) * the `message_retention_duration` field in `Topic`. This field is set only * in responses from the server; it is ignored if it is set in any requests. * @type int $state - * Output only. An output-only field indicating whether or not the subscription can receive - * messages. + * Output only. An output-only field indicating whether or not the + * subscription can receive messages. * For allowed values, use constants defined on {@see \Google\Cloud\PubSub\V1\Subscription\State} * @type RetrySettings|array $retrySettings * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an diff --git a/PubSub/src/V1/GetSchemaRequest.php b/PubSub/src/V1/GetSchemaRequest.php index 37b69a5ce465..c2af0c7be000 100644 --- a/PubSub/src/V1/GetSchemaRequest.php +++ b/PubSub/src/V1/GetSchemaRequest.php @@ -24,8 +24,7 @@ class GetSchemaRequest extends \Google\Protobuf\Internal\Message private $name = ''; /** * The set of fields to return in the response. If not set, returns a Schema - * with `name` and `type`, but not `definition`. Set to `FULL` to retrieve all - * fields. + * with all fields filled out. Set to `BASIC` to omit the `definition`. * * Generated from protobuf field .google.pubsub.v1.SchemaView view = 2; */ @@ -42,8 +41,7 @@ class GetSchemaRequest extends \Google\Protobuf\Internal\Message * Format is `projects/{project}/schemas/{schema}`. * @type int $view * The set of fields to return in the response. If not set, returns a Schema - * with `name` and `type`, but not `definition`. Set to `FULL` to retrieve all - * fields. + * with all fields filled out. Set to `BASIC` to omit the `definition`. * } */ public function __construct($data = NULL) { @@ -81,8 +79,7 @@ public function setName($var) /** * The set of fields to return in the response. If not set, returns a Schema - * with `name` and `type`, but not `definition`. Set to `FULL` to retrieve all - * fields. + * with all fields filled out. Set to `BASIC` to omit the `definition`. * * Generated from protobuf field .google.pubsub.v1.SchemaView view = 2; * @return int @@ -94,8 +91,7 @@ public function getView() /** * The set of fields to return in the response. If not set, returns a Schema - * with `name` and `type`, but not `definition`. Set to `FULL` to retrieve all - * fields. + * with all fields filled out. Set to `BASIC` to omit the `definition`. * * Generated from protobuf field .google.pubsub.v1.SchemaView view = 2; * @param int $var diff --git a/PubSub/src/V1/ListSchemaRevisionsRequest.php b/PubSub/src/V1/ListSchemaRevisionsRequest.php new file mode 100644 index 000000000000..d8ebba032a2b --- /dev/null +++ b/PubSub/src/V1/ListSchemaRevisionsRequest.php @@ -0,0 +1,181 @@ +google.pubsub.v1.ListSchemaRevisionsRequest + */ +class ListSchemaRevisionsRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The name of the schema to list revisions for. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + private $name = ''; + /** + * The set of Schema fields to return in the response. If not set, returns + * Schemas with `name` and `type`, but not `definition`. Set to `FULL` to + * retrieve all fields. + * + * Generated from protobuf field .google.pubsub.v1.SchemaView view = 2; + */ + private $view = 0; + /** + * The maximum number of revisions to return per page. + * + * Generated from protobuf field int32 page_size = 3; + */ + private $page_size = 0; + /** + * The page token, received from a previous ListSchemaRevisions call. + * Provide this to retrieve the subsequent page. + * + * Generated from protobuf field string page_token = 4; + */ + private $page_token = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Required. The name of the schema to list revisions for. + * @type int $view + * The set of Schema fields to return in the response. If not set, returns + * Schemas with `name` and `type`, but not `definition`. Set to `FULL` to + * retrieve all fields. + * @type int $page_size + * The maximum number of revisions to return per page. + * @type string $page_token + * The page token, received from a previous ListSchemaRevisions call. + * Provide this to retrieve the subsequent page. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Pubsub\V1\Schema::initOnce(); + parent::__construct($data); + } + + /** + * Required. The name of the schema to list revisions for. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Required. The name of the schema to list revisions for. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * The set of Schema fields to return in the response. If not set, returns + * Schemas with `name` and `type`, but not `definition`. Set to `FULL` to + * retrieve all fields. + * + * Generated from protobuf field .google.pubsub.v1.SchemaView view = 2; + * @return int + */ + public function getView() + { + return $this->view; + } + + /** + * The set of Schema fields to return in the response. If not set, returns + * Schemas with `name` and `type`, but not `definition`. Set to `FULL` to + * retrieve all fields. + * + * Generated from protobuf field .google.pubsub.v1.SchemaView view = 2; + * @param int $var + * @return $this + */ + public function setView($var) + { + GPBUtil::checkEnum($var, \Google\Cloud\PubSub\V1\SchemaView::class); + $this->view = $var; + + return $this; + } + + /** + * The maximum number of revisions to return per page. + * + * Generated from protobuf field int32 page_size = 3; + * @return int + */ + public function getPageSize() + { + return $this->page_size; + } + + /** + * The maximum number of revisions to return per page. + * + * Generated from protobuf field int32 page_size = 3; + * @param int $var + * @return $this + */ + public function setPageSize($var) + { + GPBUtil::checkInt32($var); + $this->page_size = $var; + + return $this; + } + + /** + * The page token, received from a previous ListSchemaRevisions call. + * Provide this to retrieve the subsequent page. + * + * Generated from protobuf field string page_token = 4; + * @return string + */ + public function getPageToken() + { + return $this->page_token; + } + + /** + * The page token, received from a previous ListSchemaRevisions call. + * Provide this to retrieve the subsequent page. + * + * Generated from protobuf field string page_token = 4; + * @param string $var + * @return $this + */ + public function setPageToken($var) + { + GPBUtil::checkString($var, True); + $this->page_token = $var; + + return $this; + } + +} + diff --git a/PubSub/src/V1/ListSchemaRevisionsResponse.php b/PubSub/src/V1/ListSchemaRevisionsResponse.php new file mode 100644 index 000000000000..b264f301f6b0 --- /dev/null +++ b/PubSub/src/V1/ListSchemaRevisionsResponse.php @@ -0,0 +1,105 @@ +google.pubsub.v1.ListSchemaRevisionsResponse + */ +class ListSchemaRevisionsResponse extends \Google\Protobuf\Internal\Message +{ + /** + * The revisions of the schema. + * + * Generated from protobuf field repeated .google.pubsub.v1.Schema schemas = 1; + */ + private $schemas; + /** + * A token that can be sent as `page_token` to retrieve the next page. + * If this field is empty, there are no subsequent pages. + * + * Generated from protobuf field string next_page_token = 2; + */ + private $next_page_token = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type array<\Google\Cloud\PubSub\V1\Schema>|\Google\Protobuf\Internal\RepeatedField $schemas + * The revisions of the schema. + * @type string $next_page_token + * A token that can be sent as `page_token` to retrieve the next page. + * If this field is empty, there are no subsequent pages. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Pubsub\V1\Schema::initOnce(); + parent::__construct($data); + } + + /** + * The revisions of the schema. + * + * Generated from protobuf field repeated .google.pubsub.v1.Schema schemas = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getSchemas() + { + return $this->schemas; + } + + /** + * The revisions of the schema. + * + * Generated from protobuf field repeated .google.pubsub.v1.Schema schemas = 1; + * @param array<\Google\Cloud\PubSub\V1\Schema>|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setSchemas($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\PubSub\V1\Schema::class); + $this->schemas = $arr; + + return $this; + } + + /** + * A token that can be sent as `page_token` to retrieve the next page. + * If this field is empty, there are no subsequent pages. + * + * Generated from protobuf field string next_page_token = 2; + * @return string + */ + public function getNextPageToken() + { + return $this->next_page_token; + } + + /** + * A token that can be sent as `page_token` to retrieve the next page. + * If this field is empty, there are no subsequent pages. + * + * Generated from protobuf field string next_page_token = 2; + * @param string $var + * @return $this + */ + public function setNextPageToken($var) + { + GPBUtil::checkString($var, True); + $this->next_page_token = $var; + + return $this; + } + +} + diff --git a/PubSub/src/V1/RollbackSchemaRequest.php b/PubSub/src/V1/RollbackSchemaRequest.php new file mode 100644 index 000000000000..0ab3404e3a21 --- /dev/null +++ b/PubSub/src/V1/RollbackSchemaRequest.php @@ -0,0 +1,109 @@ +google.pubsub.v1.RollbackSchemaRequest + */ +class RollbackSchemaRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The schema being rolled back with revision id. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + private $name = ''; + /** + * Required. The revision ID to roll back to. + * It must be a revision of the same schema. + * Example: c7cfa2a8 + * + * Generated from protobuf field string revision_id = 2 [(.google.api.field_behavior) = REQUIRED]; + */ + private $revision_id = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Required. The schema being rolled back with revision id. + * @type string $revision_id + * Required. The revision ID to roll back to. + * It must be a revision of the same schema. + * Example: c7cfa2a8 + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Pubsub\V1\Schema::initOnce(); + parent::__construct($data); + } + + /** + * Required. The schema being rolled back with revision id. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Required. The schema being rolled back with revision id. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * Required. The revision ID to roll back to. + * It must be a revision of the same schema. + * Example: c7cfa2a8 + * + * Generated from protobuf field string revision_id = 2 [(.google.api.field_behavior) = REQUIRED]; + * @return string + */ + public function getRevisionId() + { + return $this->revision_id; + } + + /** + * Required. The revision ID to roll back to. + * It must be a revision of the same schema. + * Example: c7cfa2a8 + * + * Generated from protobuf field string revision_id = 2 [(.google.api.field_behavior) = REQUIRED]; + * @param string $var + * @return $this + */ + public function setRevisionId($var) + { + GPBUtil::checkString($var, True); + $this->revision_id = $var; + + return $this; + } + +} + diff --git a/PubSub/src/V1/Schema.php b/PubSub/src/V1/Schema.php index 925d16137dbc..9d453147d159 100644 --- a/PubSub/src/V1/Schema.php +++ b/PubSub/src/V1/Schema.php @@ -36,6 +36,18 @@ class Schema extends \Google\Protobuf\Internal\Message * Generated from protobuf field string definition = 3; */ private $definition = ''; + /** + * Output only. Immutable. The revision ID of the schema. + * + * Generated from protobuf field string revision_id = 4 [(.google.api.field_behavior) = IMMUTABLE, (.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $revision_id = ''; + /** + * Output only. The timestamp that the revision was created. + * + * Generated from protobuf field .google.protobuf.Timestamp revision_create_time = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $revision_create_time = null; /** * Constructor. @@ -52,6 +64,10 @@ class Schema extends \Google\Protobuf\Internal\Message * The definition of the schema. This should contain a string representing * the full definition of the schema that is a valid schema definition of * the type specified in `type`. + * @type string $revision_id + * Output only. Immutable. The revision ID of the schema. + * @type \Google\Protobuf\Timestamp $revision_create_time + * Output only. The timestamp that the revision was created. * } */ public function __construct($data = NULL) { @@ -143,5 +159,67 @@ public function setDefinition($var) return $this; } + /** + * Output only. Immutable. The revision ID of the schema. + * + * Generated from protobuf field string revision_id = 4 [(.google.api.field_behavior) = IMMUTABLE, (.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getRevisionId() + { + return $this->revision_id; + } + + /** + * Output only. Immutable. The revision ID of the schema. + * + * Generated from protobuf field string revision_id = 4 [(.google.api.field_behavior) = IMMUTABLE, (.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setRevisionId($var) + { + GPBUtil::checkString($var, True); + $this->revision_id = $var; + + return $this; + } + + /** + * Output only. The timestamp that the revision was created. + * + * Generated from protobuf field .google.protobuf.Timestamp revision_create_time = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return \Google\Protobuf\Timestamp|null + */ + public function getRevisionCreateTime() + { + return $this->revision_create_time; + } + + public function hasRevisionCreateTime() + { + return isset($this->revision_create_time); + } + + public function clearRevisionCreateTime() + { + unset($this->revision_create_time); + } + + /** + * Output only. The timestamp that the revision was created. + * + * Generated from protobuf field .google.protobuf.Timestamp revision_create_time = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param \Google\Protobuf\Timestamp $var + * @return $this + */ + public function setRevisionCreateTime($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Timestamp::class); + $this->revision_create_time = $var; + + return $this; + } + } diff --git a/PubSub/src/V1/SchemaServiceGrpcClient.php b/PubSub/src/V1/SchemaServiceGrpcClient.php index ee4a90a125f9..5801c22fc83d 100644 --- a/PubSub/src/V1/SchemaServiceGrpcClient.php +++ b/PubSub/src/V1/SchemaServiceGrpcClient.php @@ -77,6 +77,66 @@ public function ListSchemas(\Google\Cloud\PubSub\V1\ListSchemasRequest $argument $metadata, $options); } + /** + * Lists all schema revisions for the named schema. + * @param \Google\Cloud\PubSub\V1\ListSchemaRevisionsRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function ListSchemaRevisions(\Google\Cloud\PubSub\V1\ListSchemaRevisionsRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/google.pubsub.v1.SchemaService/ListSchemaRevisions', + $argument, + ['\Google\Cloud\PubSub\V1\ListSchemaRevisionsResponse', 'decode'], + $metadata, $options); + } + + /** + * Commits a new schema revision to an existing schema. + * @param \Google\Cloud\PubSub\V1\CommitSchemaRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function CommitSchema(\Google\Cloud\PubSub\V1\CommitSchemaRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/google.pubsub.v1.SchemaService/CommitSchema', + $argument, + ['\Google\Cloud\PubSub\V1\Schema', 'decode'], + $metadata, $options); + } + + /** + * Creates a new schema revision that is a copy of the provided revision_id. + * @param \Google\Cloud\PubSub\V1\RollbackSchemaRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function RollbackSchema(\Google\Cloud\PubSub\V1\RollbackSchemaRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/google.pubsub.v1.SchemaService/RollbackSchema', + $argument, + ['\Google\Cloud\PubSub\V1\Schema', 'decode'], + $metadata, $options); + } + + /** + * Deletes a specific schema revision. + * @param \Google\Cloud\PubSub\V1\DeleteSchemaRevisionRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function DeleteSchemaRevision(\Google\Cloud\PubSub\V1\DeleteSchemaRevisionRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/google.pubsub.v1.SchemaService/DeleteSchemaRevision', + $argument, + ['\Google\Cloud\PubSub\V1\Schema', 'decode'], + $metadata, $options); + } + /** * Deletes a schema. * @param \Google\Cloud\PubSub\V1\DeleteSchemaRequest $argument input argument diff --git a/PubSub/src/V1/SchemaSettings.php b/PubSub/src/V1/SchemaSettings.php index c1739aa60161..8a276b3698ec 100644 --- a/PubSub/src/V1/SchemaSettings.php +++ b/PubSub/src/V1/SchemaSettings.php @@ -30,6 +30,22 @@ class SchemaSettings extends \Google\Protobuf\Internal\Message * Generated from protobuf field .google.pubsub.v1.Encoding encoding = 2; */ private $encoding = 0; + /** + * The minimum (inclusive) revision allowed for validating messages. If empty + * or not present, allow any revision to be validated against last_revision or + * any revision created before. + * + * Generated from protobuf field string first_revision_id = 3; + */ + private $first_revision_id = ''; + /** + * The maximum (inclusive) revision allowed for validating messages. If empty + * or not present, allow any revision to be validated against first_revision + * or any revision created after. + * + * Generated from protobuf field string last_revision_id = 4; + */ + private $last_revision_id = ''; /** * Constructor. @@ -44,6 +60,14 @@ class SchemaSettings extends \Google\Protobuf\Internal\Message * deleted. * @type int $encoding * The encoding of messages validated against `schema`. + * @type string $first_revision_id + * The minimum (inclusive) revision allowed for validating messages. If empty + * or not present, allow any revision to be validated against last_revision or + * any revision created before. + * @type string $last_revision_id + * The maximum (inclusive) revision allowed for validating messages. If empty + * or not present, allow any revision to be validated against first_revision + * or any revision created after. * } */ public function __construct($data = NULL) { @@ -109,5 +133,65 @@ public function setEncoding($var) return $this; } + /** + * The minimum (inclusive) revision allowed for validating messages. If empty + * or not present, allow any revision to be validated against last_revision or + * any revision created before. + * + * Generated from protobuf field string first_revision_id = 3; + * @return string + */ + public function getFirstRevisionId() + { + return $this->first_revision_id; + } + + /** + * The minimum (inclusive) revision allowed for validating messages. If empty + * or not present, allow any revision to be validated against last_revision or + * any revision created before. + * + * Generated from protobuf field string first_revision_id = 3; + * @param string $var + * @return $this + */ + public function setFirstRevisionId($var) + { + GPBUtil::checkString($var, True); + $this->first_revision_id = $var; + + return $this; + } + + /** + * The maximum (inclusive) revision allowed for validating messages. If empty + * or not present, allow any revision to be validated against first_revision + * or any revision created after. + * + * Generated from protobuf field string last_revision_id = 4; + * @return string + */ + public function getLastRevisionId() + { + return $this->last_revision_id; + } + + /** + * The maximum (inclusive) revision allowed for validating messages. If empty + * or not present, allow any revision to be validated against first_revision + * or any revision created after. + * + * Generated from protobuf field string last_revision_id = 4; + * @param string $var + * @return $this + */ + public function setLastRevisionId($var) + { + GPBUtil::checkString($var, True); + $this->last_revision_id = $var; + + return $this; + } + } diff --git a/PubSub/src/V1/StreamingPullResponse/AcknowledgeConfirmation.php b/PubSub/src/V1/StreamingPullResponse/AcknowledgeConfirmation.php index 74b00148519e..81b61970d711 100644 --- a/PubSub/src/V1/StreamingPullResponse/AcknowledgeConfirmation.php +++ b/PubSub/src/V1/StreamingPullResponse/AcknowledgeConfirmation.php @@ -19,20 +19,20 @@ class AcknowledgeConfirmation extends \Google\Protobuf\Internal\Message /** * Successfully processed acknowledgement IDs. * - * Generated from protobuf field repeated string ack_ids = 1 [ctype = CORD]; + * Generated from protobuf field repeated string ack_ids = 1; */ private $ack_ids; /** * List of acknowledgement IDs that were malformed or whose acknowledgement * deadline has expired. * - * Generated from protobuf field repeated string invalid_ack_ids = 2 [ctype = CORD]; + * Generated from protobuf field repeated string invalid_ack_ids = 2; */ private $invalid_ack_ids; /** * List of acknowledgement IDs that were out of order. * - * Generated from protobuf field repeated string unordered_ack_ids = 3 [ctype = CORD]; + * Generated from protobuf field repeated string unordered_ack_ids = 3; */ private $unordered_ack_ids; @@ -59,7 +59,7 @@ public function __construct($data = NULL) { /** * Successfully processed acknowledgement IDs. * - * Generated from protobuf field repeated string ack_ids = 1 [ctype = CORD]; + * Generated from protobuf field repeated string ack_ids = 1; * @return \Google\Protobuf\Internal\RepeatedField */ public function getAckIds() @@ -70,7 +70,7 @@ public function getAckIds() /** * Successfully processed acknowledgement IDs. * - * Generated from protobuf field repeated string ack_ids = 1 [ctype = CORD]; + * Generated from protobuf field repeated string ack_ids = 1; * @param array|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ @@ -86,7 +86,7 @@ public function setAckIds($var) * List of acknowledgement IDs that were malformed or whose acknowledgement * deadline has expired. * - * Generated from protobuf field repeated string invalid_ack_ids = 2 [ctype = CORD]; + * Generated from protobuf field repeated string invalid_ack_ids = 2; * @return \Google\Protobuf\Internal\RepeatedField */ public function getInvalidAckIds() @@ -98,7 +98,7 @@ public function getInvalidAckIds() * List of acknowledgement IDs that were malformed or whose acknowledgement * deadline has expired. * - * Generated from protobuf field repeated string invalid_ack_ids = 2 [ctype = CORD]; + * Generated from protobuf field repeated string invalid_ack_ids = 2; * @param array|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ @@ -113,7 +113,7 @@ public function setInvalidAckIds($var) /** * List of acknowledgement IDs that were out of order. * - * Generated from protobuf field repeated string unordered_ack_ids = 3 [ctype = CORD]; + * Generated from protobuf field repeated string unordered_ack_ids = 3; * @return \Google\Protobuf\Internal\RepeatedField */ public function getUnorderedAckIds() @@ -124,7 +124,7 @@ public function getUnorderedAckIds() /** * List of acknowledgement IDs that were out of order. * - * Generated from protobuf field repeated string unordered_ack_ids = 3 [ctype = CORD]; + * Generated from protobuf field repeated string unordered_ack_ids = 3; * @param array|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ diff --git a/PubSub/src/V1/StreamingPullResponse/ModifyAckDeadlineConfirmation.php b/PubSub/src/V1/StreamingPullResponse/ModifyAckDeadlineConfirmation.php index aab7f05ad854..b1abdb6123dd 100644 --- a/PubSub/src/V1/StreamingPullResponse/ModifyAckDeadlineConfirmation.php +++ b/PubSub/src/V1/StreamingPullResponse/ModifyAckDeadlineConfirmation.php @@ -19,14 +19,14 @@ class ModifyAckDeadlineConfirmation extends \Google\Protobuf\Internal\Message /** * Successfully processed acknowledgement IDs. * - * Generated from protobuf field repeated string ack_ids = 1 [ctype = CORD]; + * Generated from protobuf field repeated string ack_ids = 1; */ private $ack_ids; /** * List of acknowledgement IDs that were malformed or whose acknowledgement * deadline has expired. * - * Generated from protobuf field repeated string invalid_ack_ids = 2 [ctype = CORD]; + * Generated from protobuf field repeated string invalid_ack_ids = 2; */ private $invalid_ack_ids; @@ -51,7 +51,7 @@ public function __construct($data = NULL) { /** * Successfully processed acknowledgement IDs. * - * Generated from protobuf field repeated string ack_ids = 1 [ctype = CORD]; + * Generated from protobuf field repeated string ack_ids = 1; * @return \Google\Protobuf\Internal\RepeatedField */ public function getAckIds() @@ -62,7 +62,7 @@ public function getAckIds() /** * Successfully processed acknowledgement IDs. * - * Generated from protobuf field repeated string ack_ids = 1 [ctype = CORD]; + * Generated from protobuf field repeated string ack_ids = 1; * @param array|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ @@ -78,7 +78,7 @@ public function setAckIds($var) * List of acknowledgement IDs that were malformed or whose acknowledgement * deadline has expired. * - * Generated from protobuf field repeated string invalid_ack_ids = 2 [ctype = CORD]; + * Generated from protobuf field repeated string invalid_ack_ids = 2; * @return \Google\Protobuf\Internal\RepeatedField */ public function getInvalidAckIds() @@ -90,7 +90,7 @@ public function getInvalidAckIds() * List of acknowledgement IDs that were malformed or whose acknowledgement * deadline has expired. * - * Generated from protobuf field repeated string invalid_ack_ids = 2 [ctype = CORD]; + * Generated from protobuf field repeated string invalid_ack_ids = 2; * @param array|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ diff --git a/PubSub/src/V1/Subscription.php b/PubSub/src/V1/Subscription.php index da874bf97147..ed803bb21acf 100644 --- a/PubSub/src/V1/Subscription.php +++ b/PubSub/src/V1/Subscription.php @@ -192,8 +192,8 @@ class Subscription extends \Google\Protobuf\Internal\Message */ private $topic_message_retention_duration = null; /** - * Output only. An output-only field indicating whether or not the subscription can receive - * messages. + * Output only. An output-only field indicating whether or not the + * subscription can receive messages. * * Generated from protobuf field .google.pubsub.v1.Subscription.State state = 19 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ @@ -318,8 +318,8 @@ class Subscription extends \Google\Protobuf\Internal\Message * the `message_retention_duration` field in `Topic`. This field is set only * in responses from the server; it is ignored if it is set in any requests. * @type int $state - * Output only. An output-only field indicating whether or not the subscription can receive - * messages. + * Output only. An output-only field indicating whether or not the + * subscription can receive messages. * } */ public function __construct($data = NULL) { @@ -974,8 +974,8 @@ public function setTopicMessageRetentionDuration($var) } /** - * Output only. An output-only field indicating whether or not the subscription can receive - * messages. + * Output only. An output-only field indicating whether or not the + * subscription can receive messages. * * Generated from protobuf field .google.pubsub.v1.Subscription.State state = 19 [(.google.api.field_behavior) = OUTPUT_ONLY]; * @return int @@ -986,8 +986,8 @@ public function getState() } /** - * Output only. An output-only field indicating whether or not the subscription can receive - * messages. + * Output only. An output-only field indicating whether or not the + * subscription can receive messages. * * Generated from protobuf field .google.pubsub.v1.Subscription.State state = 19 [(.google.api.field_behavior) = OUTPUT_ONLY]; * @param int $var diff --git a/PubSub/src/V1/gapic_metadata.json b/PubSub/src/V1/gapic_metadata.json index c0171c97fc0f..3c57bdf7d8ed 100644 --- a/PubSub/src/V1/gapic_metadata.json +++ b/PubSub/src/V1/gapic_metadata.json @@ -10,6 +10,11 @@ "grpc": { "libraryClient": "SchemaServiceGapicClient", "rpcs": { + "CommitSchema": { + "methods": [ + "commitSchema" + ] + }, "CreateSchema": { "methods": [ "createSchema" @@ -20,16 +25,31 @@ "deleteSchema" ] }, + "DeleteSchemaRevision": { + "methods": [ + "deleteSchemaRevision" + ] + }, "GetSchema": { "methods": [ "getSchema" ] }, + "ListSchemaRevisions": { + "methods": [ + "listSchemaRevisions" + ] + }, "ListSchemas": { "methods": [ "listSchemas" ] }, + "RollbackSchema": { + "methods": [ + "rollbackSchema" + ] + }, "ValidateMessage": { "methods": [ "validateMessage" diff --git a/PubSub/src/V1/resources/publisher_rest_client_config.php b/PubSub/src/V1/resources/publisher_rest_client_config.php index c2b4d293770f..fbf6fd4b9f2e 100644 --- a/PubSub/src/V1/resources/publisher_rest_client_config.php +++ b/PubSub/src/V1/resources/publisher_rest_client_config.php @@ -193,4 +193,5 @@ ], ], ], + 'numericEnums' => true, ]; diff --git a/PubSub/src/V1/resources/schema_service_client_config.json b/PubSub/src/V1/resources/schema_service_client_config.json index 52cbd10abe50..80bef10d86e5 100644 --- a/PubSub/src/V1/resources/schema_service_client_config.json +++ b/PubSub/src/V1/resources/schema_service_client_config.json @@ -16,6 +16,11 @@ } }, "methods": { + "CommitSchema": { + "timeout_millis": 60000, + "retry_codes_name": "no_retry_codes", + "retry_params_name": "no_retry_params" + }, "CreateSchema": { "timeout_millis": 60000, "retry_codes_name": "no_retry_codes", @@ -26,16 +31,31 @@ "retry_codes_name": "no_retry_codes", "retry_params_name": "no_retry_params" }, + "DeleteSchemaRevision": { + "timeout_millis": 60000, + "retry_codes_name": "no_retry_codes", + "retry_params_name": "no_retry_params" + }, "GetSchema": { "timeout_millis": 60000, "retry_codes_name": "no_retry_codes", "retry_params_name": "no_retry_params" }, + "ListSchemaRevisions": { + "timeout_millis": 60000, + "retry_codes_name": "no_retry_codes", + "retry_params_name": "no_retry_params" + }, "ListSchemas": { "timeout_millis": 60000, "retry_codes_name": "no_retry_codes", "retry_params_name": "no_retry_params" }, + "RollbackSchema": { + "timeout_millis": 60000, + "retry_codes_name": "no_retry_codes", + "retry_params_name": "no_retry_params" + }, "ValidateMessage": { "timeout_millis": 60000, "retry_codes_name": "no_retry_codes", diff --git a/PubSub/src/V1/resources/schema_service_descriptor_config.php b/PubSub/src/V1/resources/schema_service_descriptor_config.php index 4e9648f659f6..c0c17faf03e3 100644 --- a/PubSub/src/V1/resources/schema_service_descriptor_config.php +++ b/PubSub/src/V1/resources/schema_service_descriptor_config.php @@ -3,6 +3,16 @@ return [ 'interfaces' => [ 'google.pubsub.v1.SchemaService' => [ + 'ListSchemaRevisions' => [ + 'pageStreaming' => [ + 'requestPageTokenGetMethod' => 'getPageToken', + 'requestPageTokenSetMethod' => 'setPageToken', + 'requestPageSizeGetMethod' => 'getPageSize', + 'requestPageSizeSetMethod' => 'setPageSize', + 'responsePageTokenGetMethod' => 'getNextPageToken', + 'resourcesGetMethod' => 'getSchemas', + ], + ], 'ListSchemas' => [ 'pageStreaming' => [ 'requestPageTokenGetMethod' => 'getPageToken', diff --git a/PubSub/src/V1/resources/schema_service_rest_client_config.php b/PubSub/src/V1/resources/schema_service_rest_client_config.php index 77c7b5212a84..f91306680604 100644 --- a/PubSub/src/V1/resources/schema_service_rest_client_config.php +++ b/PubSub/src/V1/resources/schema_service_rest_client_config.php @@ -88,6 +88,18 @@ ], ], 'google.pubsub.v1.SchemaService' => [ + 'CommitSchema' => [ + 'method' => 'post', + 'uriTemplate' => '/v1/{name=projects/*/schemas/*}:commit', + 'body' => '*', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], 'CreateSchema' => [ 'method' => 'post', 'uriTemplate' => '/v1/{parent=projects/*}/schemas', @@ -111,6 +123,17 @@ ], ], ], + 'DeleteSchemaRevision' => [ + 'method' => 'delete', + 'uriTemplate' => '/v1/{name=projects/*/schemas/*}:deleteRevision', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], 'GetSchema' => [ 'method' => 'get', 'uriTemplate' => '/v1/{name=projects/*/schemas/*}', @@ -122,6 +145,17 @@ ], ], ], + 'ListSchemaRevisions' => [ + 'method' => 'get', + 'uriTemplate' => '/v1/{name=projects/*/schemas/*}:listRevisions', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], 'ListSchemas' => [ 'method' => 'get', 'uriTemplate' => '/v1/{parent=projects/*}/schemas', @@ -133,6 +167,18 @@ ], ], ], + 'RollbackSchema' => [ + 'method' => 'post', + 'uriTemplate' => '/v1/{name=projects/*/schemas/*}:rollback', + 'body' => '*', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], 'ValidateMessage' => [ 'method' => 'post', 'uriTemplate' => '/v1/{parent=projects/*}/schemas:validateMessage', @@ -159,4 +205,5 @@ ], ], ], + 'numericEnums' => true, ]; diff --git a/PubSub/src/V1/resources/subscriber_rest_client_config.php b/PubSub/src/V1/resources/subscriber_rest_client_config.php index f4c3878dcc6d..3643254a4cf1 100644 --- a/PubSub/src/V1/resources/subscriber_rest_client_config.php +++ b/PubSub/src/V1/resources/subscriber_rest_client_config.php @@ -266,4 +266,5 @@ ], ], ], + 'numericEnums' => true, ]; diff --git a/PubSub/tests/Unit/V1/SchemaServiceClientTest.php b/PubSub/tests/Unit/V1/SchemaServiceClientTest.php index 8f37a668d0f7..f9cebd908677 100644 --- a/PubSub/tests/Unit/V1/SchemaServiceClientTest.php +++ b/PubSub/tests/Unit/V1/SchemaServiceClientTest.php @@ -28,6 +28,7 @@ use Google\ApiCore\Testing\MockTransport; use Google\Cloud\Iam\V1\Policy; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; +use Google\Cloud\PubSub\V1\ListSchemaRevisionsResponse; use Google\Cloud\PubSub\V1\ListSchemasResponse; use Google\Cloud\PubSub\V1\Schema; use Google\Cloud\PubSub\V1\SchemaServiceClient; @@ -65,6 +66,78 @@ private function createClient(array $options = []) return new SchemaServiceClient($options); } + /** @test */ + public function commitSchemaTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $definition = 'definition-1014418093'; + $revisionId = 'revisionId513861631'; + $expectedResponse = new Schema(); + $expectedResponse->setName($name2); + $expectedResponse->setDefinition($definition); + $expectedResponse->setRevisionId($revisionId); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); + $schema = new Schema(); + $schemaName = 'schemaName-448762932'; + $schema->setName($schemaName); + $response = $gapicClient->commitSchema($formattedName, $schema); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.SchemaService/CommitSchema', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualRequestObject->getSchema(); + $this->assertProtobufEquals($schema, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function commitSchemaExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); + $schema = new Schema(); + $schemaName = 'schemaName-448762932'; + $schema->setName($schemaName); + try { + $gapicClient->commitSchema($formattedName, $schema); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + /** @test */ public function createSchemaTest() { @@ -76,9 +149,11 @@ public function createSchemaTest() // Mock response $name = 'name3373707'; $definition = 'definition-1014418093'; + $revisionId = 'revisionId513861631'; $expectedResponse = new Schema(); $expectedResponse->setName($name); $expectedResponse->setDefinition($definition); + $expectedResponse->setRevisionId($revisionId); $transport->addResponse($expectedResponse); // Mock request $formattedParent = $gapicClient->projectName('[PROJECT]'); @@ -192,6 +267,74 @@ public function deleteSchemaExceptionTest() $this->assertTrue($transport->isExhausted()); } + /** @test */ + public function deleteSchemaRevisionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $definition = 'definition-1014418093'; + $revisionId2 = 'revisionId2-100208654'; + $expectedResponse = new Schema(); + $expectedResponse->setName($name2); + $expectedResponse->setDefinition($definition); + $expectedResponse->setRevisionId($revisionId2); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); + $revisionId = 'revisionId513861631'; + $response = $gapicClient->deleteSchemaRevision($formattedName, $revisionId); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.SchemaService/DeleteSchemaRevision', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualRequestObject->getRevisionId(); + $this->assertProtobufEquals($revisionId, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteSchemaRevisionExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); + $revisionId = 'revisionId513861631'; + try { + $gapicClient->deleteSchemaRevision($formattedName, $revisionId); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + /** @test */ public function getSchemaTest() { @@ -203,9 +346,11 @@ public function getSchemaTest() // Mock response $name2 = 'name2-1052831874'; $definition = 'definition-1014418093'; + $revisionId = 'revisionId513861631'; $expectedResponse = new Schema(); $expectedResponse->setName($name2); $expectedResponse->setDefinition($definition); + $expectedResponse->setRevisionId($revisionId); $transport->addResponse($expectedResponse); // Mock request $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); @@ -254,6 +399,74 @@ public function getSchemaExceptionTest() $this->assertTrue($transport->isExhausted()); } + /** @test */ + public function listSchemaRevisionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $schemasElement = new Schema(); + $schemas = [ + $schemasElement, + ]; + $expectedResponse = new ListSchemaRevisionsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setSchemas($schemas); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); + $response = $gapicClient->listSchemaRevisions($formattedName); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getSchemas()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.SchemaService/ListSchemaRevisions', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listSchemaRevisionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); + try { + $gapicClient->listSchemaRevisions($formattedName); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + /** @test */ public function listSchemasTest() { @@ -322,6 +535,74 @@ public function listSchemasExceptionTest() $this->assertTrue($transport->isExhausted()); } + /** @test */ + public function rollbackSchemaTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $definition = 'definition-1014418093'; + $revisionId2 = 'revisionId2-100208654'; + $expectedResponse = new Schema(); + $expectedResponse->setName($name2); + $expectedResponse->setDefinition($definition); + $expectedResponse->setRevisionId($revisionId2); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); + $revisionId = 'revisionId513861631'; + $response = $gapicClient->rollbackSchema($formattedName, $revisionId); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.SchemaService/RollbackSchema', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualRequestObject->getRevisionId(); + $this->assertProtobufEquals($revisionId, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function rollbackSchemaExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); + $revisionId = 'revisionId513861631'; + try { + $gapicClient->rollbackSchema($formattedName, $revisionId); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + /** @test */ public function validateMessageTest() {