diff --git a/SqlAdmin/metadata/V1/CloudSqlInstances.php b/SqlAdmin/metadata/V1/CloudSqlInstances.php index 5fac3ce6066f..3f23d30e7ff3 100644 Binary files a/SqlAdmin/metadata/V1/CloudSqlInstances.php and b/SqlAdmin/metadata/V1/CloudSqlInstances.php differ diff --git a/SqlAdmin/metadata/V1Beta4/CloudSql.php b/SqlAdmin/metadata/V1Beta4/CloudSql.php index 1e5d7d5df7e4..1454c8bf840f 100644 Binary files a/SqlAdmin/metadata/V1Beta4/CloudSql.php and b/SqlAdmin/metadata/V1Beta4/CloudSql.php differ diff --git a/SqlAdmin/metadata/V1Beta4/CloudSqlResources.php b/SqlAdmin/metadata/V1Beta4/CloudSqlResources.php index a735059cdf76..89379198704b 100644 Binary files a/SqlAdmin/metadata/V1Beta4/CloudSqlResources.php and b/SqlAdmin/metadata/V1Beta4/CloudSqlResources.php differ diff --git a/SqlAdmin/samples/V1/SqlInstancesServiceClient/demote.php b/SqlAdmin/samples/V1/SqlInstancesServiceClient/demote.php new file mode 100644 index 000000000000..68768ffa512a --- /dev/null +++ b/SqlAdmin/samples/V1/SqlInstancesServiceClient/demote.php @@ -0,0 +1,87 @@ +setSourceRepresentativeInstanceName($bodyDemoteContextSourceRepresentativeInstanceName); + $body = (new InstancesDemoteRequest()) + ->setDemoteContext($bodyDemoteContext); + $request = (new SqlInstancesDemoteRequest()) + ->setInstance($instance) + ->setProject($project) + ->setBody($body); + + // Call the API and handle any network failures. + try { + /** @var Operation $response */ + $response = $sqlInstancesServiceClient->demote($request); + 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 +{ + $instance = '[INSTANCE]'; + $project = '[PROJECT]'; + $bodyDemoteContextSourceRepresentativeInstanceName = '[SOURCE_REPRESENTATIVE_INSTANCE_NAME]'; + + demote_sample($instance, $project, $bodyDemoteContextSourceRepresentativeInstanceName); +} +// [END sqladmin_v1_generated_SqlInstancesService_Demote_sync] diff --git a/SqlAdmin/samples/V1beta4/SqlInstancesServiceClient/demote.php b/SqlAdmin/samples/V1beta4/SqlInstancesServiceClient/demote.php new file mode 100644 index 000000000000..652f7738fe54 --- /dev/null +++ b/SqlAdmin/samples/V1beta4/SqlInstancesServiceClient/demote.php @@ -0,0 +1,68 @@ +demote($instance, $project); + 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 +{ + $instance = '[INSTANCE]'; + $project = '[PROJECT]'; + + demote_sample($instance, $project); +} +// [END sqladmin_v1beta4_generated_SqlInstancesService_Demote_sync] diff --git a/SqlAdmin/src/V1/Client/SqlInstancesServiceClient.php b/SqlAdmin/src/V1/Client/SqlInstancesServiceClient.php index 785091b88d4b..755670425ecb 100644 --- a/SqlAdmin/src/V1/Client/SqlInstancesServiceClient.php +++ b/SqlAdmin/src/V1/Client/SqlInstancesServiceClient.php @@ -40,6 +40,7 @@ use Google\Cloud\Sql\V1\SqlInstancesCreateEphemeralCertRequest; use Google\Cloud\Sql\V1\SqlInstancesDeleteRequest; use Google\Cloud\Sql\V1\SqlInstancesDemoteMasterRequest; +use Google\Cloud\Sql\V1\SqlInstancesDemoteRequest; use Google\Cloud\Sql\V1\SqlInstancesExportRequest; use Google\Cloud\Sql\V1\SqlInstancesFailoverRequest; use Google\Cloud\Sql\V1\SqlInstancesGetDiskShrinkConfigRequest; @@ -86,6 +87,7 @@ * @method PromiseInterface cloneAsync(SqlInstancesCloneRequest $request, array $optionalArgs = []) * @method PromiseInterface createEphemeralAsync(SqlInstancesCreateEphemeralCertRequest $request, array $optionalArgs = []) * @method PromiseInterface deleteAsync(SqlInstancesDeleteRequest $request, array $optionalArgs = []) + * @method PromiseInterface demoteAsync(SqlInstancesDemoteRequest $request, array $optionalArgs = []) * @method PromiseInterface demoteMasterAsync(SqlInstancesDemoteMasterRequest $request, array $optionalArgs = []) * @method PromiseInterface exportAsync(SqlInstancesExportRequest $request, array $optionalArgs = []) * @method PromiseInterface failoverAsync(SqlInstancesFailoverRequest $request, array $optionalArgs = []) @@ -338,6 +340,33 @@ public function delete(SqlInstancesDeleteRequest $request, array $callOptions = return $this->startApiCall('Delete', $request, $callOptions)->wait(); } + /** + * Demotes an existing standalone instance to be a Cloud SQL read replica + * for an external database server. + * + * The async variant is {@see SqlInstancesServiceClient::demoteAsync()} . + * + * @example samples/V1/SqlInstancesServiceClient/demote.php + * + * @param SqlInstancesDemoteRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Operation + * + * @throws ApiException Thrown if the API call fails. + */ + public function demote(SqlInstancesDemoteRequest $request, array $callOptions = []): Operation + { + return $this->startApiCall('Demote', $request, $callOptions)->wait(); + } + /** * Demotes the stand-alone instance to be a Cloud SQL read replica for an * external database server. diff --git a/SqlAdmin/src/V1/DemoteContext.php b/SqlAdmin/src/V1/DemoteContext.php new file mode 100644 index 000000000000..d89e3bf58b1b --- /dev/null +++ b/SqlAdmin/src/V1/DemoteContext.php @@ -0,0 +1,106 @@ +google.cloud.sql.v1.DemoteContext + */ +class DemoteContext extends \Google\Protobuf\Internal\Message +{ + /** + * This is always `sql#demoteContext`. + * + * Generated from protobuf field string kind = 1; + */ + private $kind = ''; + /** + * Required. The name of the instance which acts as the on-premises primary + * instance in the replication setup. + * + * Generated from protobuf field string source_representative_instance_name = 2 [(.google.api.field_behavior) = REQUIRED]; + */ + private $source_representative_instance_name = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $kind + * This is always `sql#demoteContext`. + * @type string $source_representative_instance_name + * Required. The name of the instance which acts as the on-premises primary + * instance in the replication setup. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Sql\V1\CloudSqlInstances::initOnce(); + parent::__construct($data); + } + + /** + * This is always `sql#demoteContext`. + * + * Generated from protobuf field string kind = 1; + * @return string + */ + public function getKind() + { + return $this->kind; + } + + /** + * This is always `sql#demoteContext`. + * + * Generated from protobuf field string kind = 1; + * @param string $var + * @return $this + */ + public function setKind($var) + { + GPBUtil::checkString($var, True); + $this->kind = $var; + + return $this; + } + + /** + * Required. The name of the instance which acts as the on-premises primary + * instance in the replication setup. + * + * Generated from protobuf field string source_representative_instance_name = 2 [(.google.api.field_behavior) = REQUIRED]; + * @return string + */ + public function getSourceRepresentativeInstanceName() + { + return $this->source_representative_instance_name; + } + + /** + * Required. The name of the instance which acts as the on-premises primary + * instance in the replication setup. + * + * Generated from protobuf field string source_representative_instance_name = 2 [(.google.api.field_behavior) = REQUIRED]; + * @param string $var + * @return $this + */ + public function setSourceRepresentativeInstanceName($var) + { + GPBUtil::checkString($var, True); + $this->source_representative_instance_name = $var; + + return $this; + } + +} + diff --git a/SqlAdmin/src/V1/InstancesDemoteRequest.php b/SqlAdmin/src/V1/InstancesDemoteRequest.php new file mode 100644 index 000000000000..838c36adaab5 --- /dev/null +++ b/SqlAdmin/src/V1/InstancesDemoteRequest.php @@ -0,0 +1,78 @@ +google.cloud.sql.v1.InstancesDemoteRequest + */ +class InstancesDemoteRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. Contains details about the demote operation. + * + * Generated from protobuf field .google.cloud.sql.v1.DemoteContext demote_context = 1 [(.google.api.field_behavior) = REQUIRED]; + */ + private $demote_context = null; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Cloud\Sql\V1\DemoteContext $demote_context + * Required. Contains details about the demote operation. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Sql\V1\CloudSqlInstances::initOnce(); + parent::__construct($data); + } + + /** + * Required. Contains details about the demote operation. + * + * Generated from protobuf field .google.cloud.sql.v1.DemoteContext demote_context = 1 [(.google.api.field_behavior) = REQUIRED]; + * @return \Google\Cloud\Sql\V1\DemoteContext|null + */ + public function getDemoteContext() + { + return $this->demote_context; + } + + public function hasDemoteContext() + { + return isset($this->demote_context); + } + + public function clearDemoteContext() + { + unset($this->demote_context); + } + + /** + * Required. Contains details about the demote operation. + * + * Generated from protobuf field .google.cloud.sql.v1.DemoteContext demote_context = 1 [(.google.api.field_behavior) = REQUIRED]; + * @param \Google\Cloud\Sql\V1\DemoteContext $var + * @return $this + */ + public function setDemoteContext($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\Sql\V1\DemoteContext::class); + $this->demote_context = $var; + + return $this; + } + +} + diff --git a/SqlAdmin/src/V1/SqlInstancesDemoteRequest.php b/SqlAdmin/src/V1/SqlInstancesDemoteRequest.php new file mode 100644 index 000000000000..4169ceffa6b3 --- /dev/null +++ b/SqlAdmin/src/V1/SqlInstancesDemoteRequest.php @@ -0,0 +1,145 @@ +google.cloud.sql.v1.SqlInstancesDemoteRequest + */ +class SqlInstancesDemoteRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. Cloud SQL instance name. + * + * Generated from protobuf field string instance = 1 [(.google.api.field_behavior) = REQUIRED]; + */ + private $instance = ''; + /** + * Required. ID of the project that contains the instance. + * + * Generated from protobuf field string project = 2 [(.google.api.field_behavior) = REQUIRED]; + */ + private $project = ''; + /** + * Required. The request body. + * + * Generated from protobuf field .google.cloud.sql.v1.InstancesDemoteRequest body = 100 [(.google.api.field_behavior) = REQUIRED]; + */ + private $body = null; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $instance + * Required. Cloud SQL instance name. + * @type string $project + * Required. ID of the project that contains the instance. + * @type \Google\Cloud\Sql\V1\InstancesDemoteRequest $body + * Required. The request body. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Sql\V1\CloudSqlInstances::initOnce(); + parent::__construct($data); + } + + /** + * Required. Cloud SQL instance name. + * + * Generated from protobuf field string instance = 1 [(.google.api.field_behavior) = REQUIRED]; + * @return string + */ + public function getInstance() + { + return $this->instance; + } + + /** + * Required. Cloud SQL instance name. + * + * Generated from protobuf field string instance = 1 [(.google.api.field_behavior) = REQUIRED]; + * @param string $var + * @return $this + */ + public function setInstance($var) + { + GPBUtil::checkString($var, True); + $this->instance = $var; + + return $this; + } + + /** + * Required. ID of the project that contains the instance. + * + * Generated from protobuf field string project = 2 [(.google.api.field_behavior) = REQUIRED]; + * @return string + */ + public function getProject() + { + return $this->project; + } + + /** + * Required. ID of the project that contains the instance. + * + * Generated from protobuf field string project = 2 [(.google.api.field_behavior) = REQUIRED]; + * @param string $var + * @return $this + */ + public function setProject($var) + { + GPBUtil::checkString($var, True); + $this->project = $var; + + return $this; + } + + /** + * Required. The request body. + * + * Generated from protobuf field .google.cloud.sql.v1.InstancesDemoteRequest body = 100 [(.google.api.field_behavior) = REQUIRED]; + * @return \Google\Cloud\Sql\V1\InstancesDemoteRequest|null + */ + public function getBody() + { + return $this->body; + } + + public function hasBody() + { + return isset($this->body); + } + + public function clearBody() + { + unset($this->body); + } + + /** + * Required. The request body. + * + * Generated from protobuf field .google.cloud.sql.v1.InstancesDemoteRequest body = 100 [(.google.api.field_behavior) = REQUIRED]; + * @param \Google\Cloud\Sql\V1\InstancesDemoteRequest $var + * @return $this + */ + public function setBody($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\Sql\V1\InstancesDemoteRequest::class); + $this->body = $var; + + return $this; + } + +} + diff --git a/SqlAdmin/src/V1/gapic_metadata.json b/SqlAdmin/src/V1/gapic_metadata.json index b30cedadc083..82bcd33fb50f 100644 --- a/SqlAdmin/src/V1/gapic_metadata.json +++ b/SqlAdmin/src/V1/gapic_metadata.json @@ -159,6 +159,11 @@ "delete" ] }, + "Demote": { + "methods": [ + "demote" + ] + }, "DemoteMaster": { "methods": [ "demoteMaster" diff --git a/SqlAdmin/src/V1/resources/sql_instances_service_client_config.json b/SqlAdmin/src/V1/resources/sql_instances_service_client_config.json index 6eb9422fe4a5..31b90aad90a8 100644 --- a/SqlAdmin/src/V1/resources/sql_instances_service_client_config.json +++ b/SqlAdmin/src/V1/resources/sql_instances_service_client_config.json @@ -46,6 +46,11 @@ "retry_codes_name": "no_retry_1_codes", "retry_params_name": "no_retry_1_params" }, + "Demote": { + "timeout_millis": 60000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, "DemoteMaster": { "timeout_millis": 60000, "retry_codes_name": "no_retry_1_codes", diff --git a/SqlAdmin/src/V1/resources/sql_instances_service_descriptor_config.php b/SqlAdmin/src/V1/resources/sql_instances_service_descriptor_config.php index 0c1f10892a11..1fb9571ffc36 100644 --- a/SqlAdmin/src/V1/resources/sql_instances_service_descriptor_config.php +++ b/SqlAdmin/src/V1/resources/sql_instances_service_descriptor_config.php @@ -75,6 +75,24 @@ ], ], ], + 'Demote' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Sql\V1\Operation', + 'headerParams' => [ + [ + 'keyName' => 'project', + 'fieldAccessors' => [ + 'getProject', + ], + ], + [ + 'keyName' => 'instance', + 'fieldAccessors' => [ + 'getInstance', + ], + ], + ], + ], 'DemoteMaster' => [ 'callType' => \Google\ApiCore\Call::UNARY_CALL, 'responseType' => 'Google\Cloud\Sql\V1\Operation', diff --git a/SqlAdmin/src/V1/resources/sql_instances_service_rest_client_config.php b/SqlAdmin/src/V1/resources/sql_instances_service_rest_client_config.php index 8d5721e5ee57..b1b85ad0cb76 100644 --- a/SqlAdmin/src/V1/resources/sql_instances_service_rest_client_config.php +++ b/SqlAdmin/src/V1/resources/sql_instances_service_rest_client_config.php @@ -69,6 +69,23 @@ ], ], ], + 'Demote' => [ + 'method' => 'post', + 'uriTemplate' => '/v1/projects/{project}/instances/{instance}/demote', + 'body' => 'body', + 'placeholders' => [ + 'instance' => [ + 'getters' => [ + 'getInstance', + ], + ], + 'project' => [ + 'getters' => [ + 'getProject', + ], + ], + ], + ], 'DemoteMaster' => [ 'method' => 'post', 'uriTemplate' => '/v1/projects/{project}/instances/{instance}/demoteMaster', diff --git a/SqlAdmin/src/V1beta4/DemoteContext.php b/SqlAdmin/src/V1beta4/DemoteContext.php new file mode 100644 index 000000000000..d50722459d7b --- /dev/null +++ b/SqlAdmin/src/V1beta4/DemoteContext.php @@ -0,0 +1,106 @@ +google.cloud.sql.v1beta4.DemoteContext + */ +class DemoteContext extends \Google\Protobuf\Internal\Message +{ + /** + * This is always `sql#demoteContext`. + * + * Generated from protobuf field string kind = 1; + */ + private $kind = ''; + /** + * Required. The name of the instance which acts as an on-premises primary + * instance in the replication setup. + * + * Generated from protobuf field string source_representative_instance_name = 2 [(.google.api.field_behavior) = REQUIRED]; + */ + private $source_representative_instance_name = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $kind + * This is always `sql#demoteContext`. + * @type string $source_representative_instance_name + * Required. The name of the instance which acts as an on-premises primary + * instance in the replication setup. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Sql\V1Beta4\CloudSqlResources::initOnce(); + parent::__construct($data); + } + + /** + * This is always `sql#demoteContext`. + * + * Generated from protobuf field string kind = 1; + * @return string + */ + public function getKind() + { + return $this->kind; + } + + /** + * This is always `sql#demoteContext`. + * + * Generated from protobuf field string kind = 1; + * @param string $var + * @return $this + */ + public function setKind($var) + { + GPBUtil::checkString($var, True); + $this->kind = $var; + + return $this; + } + + /** + * Required. The name of the instance which acts as an on-premises primary + * instance in the replication setup. + * + * Generated from protobuf field string source_representative_instance_name = 2 [(.google.api.field_behavior) = REQUIRED]; + * @return string + */ + public function getSourceRepresentativeInstanceName() + { + return $this->source_representative_instance_name; + } + + /** + * Required. The name of the instance which acts as an on-premises primary + * instance in the replication setup. + * + * Generated from protobuf field string source_representative_instance_name = 2 [(.google.api.field_behavior) = REQUIRED]; + * @param string $var + * @return $this + */ + public function setSourceRepresentativeInstanceName($var) + { + GPBUtil::checkString($var, True); + $this->source_representative_instance_name = $var; + + return $this; + } + +} + diff --git a/SqlAdmin/src/V1beta4/Gapic/SqlInstancesServiceGapicClient.php b/SqlAdmin/src/V1beta4/Gapic/SqlInstancesServiceGapicClient.php index d776687c4733..d5a5efd9e266 100644 --- a/SqlAdmin/src/V1beta4/Gapic/SqlInstancesServiceGapicClient.php +++ b/SqlAdmin/src/V1beta4/Gapic/SqlInstancesServiceGapicClient.php @@ -37,6 +37,7 @@ use Google\Cloud\Sql\V1beta4\DatabaseInstance; use Google\Cloud\Sql\V1beta4\InstancesCloneRequest; use Google\Cloud\Sql\V1beta4\InstancesDemoteMasterRequest; +use Google\Cloud\Sql\V1beta4\InstancesDemoteRequest; use Google\Cloud\Sql\V1beta4\InstancesExportRequest; use Google\Cloud\Sql\V1beta4\InstancesFailoverRequest; use Google\Cloud\Sql\V1beta4\InstancesImportRequest; @@ -54,6 +55,7 @@ use Google\Cloud\Sql\V1beta4\SqlInstancesCreateEphemeralCertRequest; use Google\Cloud\Sql\V1beta4\SqlInstancesDeleteRequest; use Google\Cloud\Sql\V1beta4\SqlInstancesDemoteMasterRequest; +use Google\Cloud\Sql\V1beta4\SqlInstancesDemoteRequest; use Google\Cloud\Sql\V1beta4\SqlInstancesExportRequest; use Google\Cloud\Sql\V1beta4\SqlInstancesFailoverRequest; use Google\Cloud\Sql\V1beta4\SqlInstancesGetDiskShrinkConfigRequest; @@ -476,6 +478,67 @@ public function delete(array $optionalArgs = []) )->wait(); } + /** + * Demotes an existing standalone instance to be a Cloud SQL read replica + * for an external database server. + * + * Sample code: + * ``` + * $sqlInstancesServiceClient = new SqlInstancesServiceClient(); + * try { + * $instance = 'instance'; + * $project = 'project'; + * $response = $sqlInstancesServiceClient->demote($instance, $project); + * } finally { + * $sqlInstancesServiceClient->close(); + * } + * ``` + * + * @param string $instance Required. The name of the Cloud SQL instance. + * @param string $project Required. The project ID of the project that contains the instance. + * @param array $optionalArgs { + * Optional. + * + * @type InstancesDemoteRequest $body + * The request body. + * @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\Sql\V1beta4\Operation + * + * @throws ApiException if the remote call fails + * + * @experimental + */ + public function demote($instance, $project, array $optionalArgs = []) + { + $request = new SqlInstancesDemoteRequest(); + $requestParamHeaders = []; + $request->setInstance($instance); + $request->setProject($project); + $requestParamHeaders['instance'] = $instance; + $requestParamHeaders['project'] = $project; + if (isset($optionalArgs['body'])) { + $request->setBody($optionalArgs['body']); + } + + $requestParams = new RequestParamsHeaderDescriptor( + $requestParamHeaders + ); + $optionalArgs['headers'] = isset($optionalArgs['headers']) + ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) + : $requestParams->getHeader(); + return $this->startCall( + 'Demote', + Operation::class, + $optionalArgs, + $request + )->wait(); + } + /** * Demotes the stand-alone instance to be a Cloud SQL read replica for an * external database server. diff --git a/SqlAdmin/src/V1beta4/InstancesDemoteRequest.php b/SqlAdmin/src/V1beta4/InstancesDemoteRequest.php new file mode 100644 index 000000000000..a9456886524e --- /dev/null +++ b/SqlAdmin/src/V1beta4/InstancesDemoteRequest.php @@ -0,0 +1,82 @@ +google.cloud.sql.v1beta4.InstancesDemoteRequest + */ +class InstancesDemoteRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. This context is used to demote an existing standalone instance to + * be a Cloud SQL read replica for an external database server. + * + * Generated from protobuf field .google.cloud.sql.v1beta4.DemoteContext demote_context = 1 [(.google.api.field_behavior) = REQUIRED]; + */ + private $demote_context = null; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Cloud\Sql\V1beta4\DemoteContext $demote_context + * Required. This context is used to demote an existing standalone instance to + * be a Cloud SQL read replica for an external database server. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Sql\V1Beta4\CloudSqlResources::initOnce(); + parent::__construct($data); + } + + /** + * Required. This context is used to demote an existing standalone instance to + * be a Cloud SQL read replica for an external database server. + * + * Generated from protobuf field .google.cloud.sql.v1beta4.DemoteContext demote_context = 1 [(.google.api.field_behavior) = REQUIRED]; + * @return \Google\Cloud\Sql\V1beta4\DemoteContext|null + */ + public function getDemoteContext() + { + return $this->demote_context; + } + + public function hasDemoteContext() + { + return isset($this->demote_context); + } + + public function clearDemoteContext() + { + unset($this->demote_context); + } + + /** + * Required. This context is used to demote an existing standalone instance to + * be a Cloud SQL read replica for an external database server. + * + * Generated from protobuf field .google.cloud.sql.v1beta4.DemoteContext demote_context = 1 [(.google.api.field_behavior) = REQUIRED]; + * @param \Google\Cloud\Sql\V1beta4\DemoteContext $var + * @return $this + */ + public function setDemoteContext($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\Sql\V1beta4\DemoteContext::class); + $this->demote_context = $var; + + return $this; + } + +} + diff --git a/SqlAdmin/src/V1beta4/SqlInstancesDemoteRequest.php b/SqlAdmin/src/V1beta4/SqlInstancesDemoteRequest.php new file mode 100644 index 000000000000..34ed4f29def8 --- /dev/null +++ b/SqlAdmin/src/V1beta4/SqlInstancesDemoteRequest.php @@ -0,0 +1,145 @@ +google.cloud.sql.v1beta4.SqlInstancesDemoteRequest + */ +class SqlInstancesDemoteRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The name of the Cloud SQL instance. + * + * Generated from protobuf field string instance = 1 [(.google.api.field_behavior) = REQUIRED]; + */ + private $instance = ''; + /** + * Required. The project ID of the project that contains the instance. + * + * Generated from protobuf field string project = 2 [(.google.api.field_behavior) = REQUIRED]; + */ + private $project = ''; + /** + * The request body. + * + * Generated from protobuf field .google.cloud.sql.v1beta4.InstancesDemoteRequest body = 100; + */ + private $body = null; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $instance + * Required. The name of the Cloud SQL instance. + * @type string $project + * Required. The project ID of the project that contains the instance. + * @type \Google\Cloud\Sql\V1beta4\InstancesDemoteRequest $body + * The request body. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Sql\V1Beta4\CloudSql::initOnce(); + parent::__construct($data); + } + + /** + * Required. The name of the Cloud SQL instance. + * + * Generated from protobuf field string instance = 1 [(.google.api.field_behavior) = REQUIRED]; + * @return string + */ + public function getInstance() + { + return $this->instance; + } + + /** + * Required. The name of the Cloud SQL instance. + * + * Generated from protobuf field string instance = 1 [(.google.api.field_behavior) = REQUIRED]; + * @param string $var + * @return $this + */ + public function setInstance($var) + { + GPBUtil::checkString($var, True); + $this->instance = $var; + + return $this; + } + + /** + * Required. The project ID of the project that contains the instance. + * + * Generated from protobuf field string project = 2 [(.google.api.field_behavior) = REQUIRED]; + * @return string + */ + public function getProject() + { + return $this->project; + } + + /** + * Required. The project ID of the project that contains the instance. + * + * Generated from protobuf field string project = 2 [(.google.api.field_behavior) = REQUIRED]; + * @param string $var + * @return $this + */ + public function setProject($var) + { + GPBUtil::checkString($var, True); + $this->project = $var; + + return $this; + } + + /** + * The request body. + * + * Generated from protobuf field .google.cloud.sql.v1beta4.InstancesDemoteRequest body = 100; + * @return \Google\Cloud\Sql\V1beta4\InstancesDemoteRequest|null + */ + public function getBody() + { + return $this->body; + } + + public function hasBody() + { + return isset($this->body); + } + + public function clearBody() + { + unset($this->body); + } + + /** + * The request body. + * + * Generated from protobuf field .google.cloud.sql.v1beta4.InstancesDemoteRequest body = 100; + * @param \Google\Cloud\Sql\V1beta4\InstancesDemoteRequest $var + * @return $this + */ + public function setBody($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\Sql\V1beta4\InstancesDemoteRequest::class); + $this->body = $var; + + return $this; + } + +} + diff --git a/SqlAdmin/src/V1beta4/gapic_metadata.json b/SqlAdmin/src/V1beta4/gapic_metadata.json index a273c968e154..653c830da22b 100644 --- a/SqlAdmin/src/V1beta4/gapic_metadata.json +++ b/SqlAdmin/src/V1beta4/gapic_metadata.json @@ -112,6 +112,11 @@ "delete" ] }, + "Demote": { + "methods": [ + "demote" + ] + }, "DemoteMaster": { "methods": [ "demoteMaster" diff --git a/SqlAdmin/src/V1beta4/resources/sql_instances_service_client_config.json b/SqlAdmin/src/V1beta4/resources/sql_instances_service_client_config.json index 934180d716f3..bbf1ebe22bca 100644 --- a/SqlAdmin/src/V1beta4/resources/sql_instances_service_client_config.json +++ b/SqlAdmin/src/V1beta4/resources/sql_instances_service_client_config.json @@ -46,6 +46,11 @@ "retry_codes_name": "no_retry_1_codes", "retry_params_name": "no_retry_1_params" }, + "Demote": { + "timeout_millis": 60000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, "DemoteMaster": { "timeout_millis": 60000, "retry_codes_name": "no_retry_1_codes", diff --git a/SqlAdmin/src/V1beta4/resources/sql_instances_service_rest_client_config.php b/SqlAdmin/src/V1beta4/resources/sql_instances_service_rest_client_config.php index ed3c3a34041e..506f0d5450a6 100644 --- a/SqlAdmin/src/V1beta4/resources/sql_instances_service_rest_client_config.php +++ b/SqlAdmin/src/V1beta4/resources/sql_instances_service_rest_client_config.php @@ -69,6 +69,23 @@ ], ], ], + 'Demote' => [ + 'method' => 'post', + 'uriTemplate' => '/sql/v1beta4/projects/{project}/instances/{instance}/demote', + 'body' => 'body', + 'placeholders' => [ + 'instance' => [ + 'getters' => [ + 'getInstance', + ], + ], + 'project' => [ + 'getters' => [ + 'getProject', + ], + ], + ], + ], 'DemoteMaster' => [ 'method' => 'post', 'uriTemplate' => '/sql/v1beta4/projects/{project}/instances/{instance}/demoteMaster', diff --git a/SqlAdmin/tests/Unit/V1/Client/SqlInstancesServiceClientTest.php b/SqlAdmin/tests/Unit/V1/Client/SqlInstancesServiceClientTest.php index 01d89b74694f..54c3251d0c6f 100644 --- a/SqlAdmin/tests/Unit/V1/Client/SqlInstancesServiceClientTest.php +++ b/SqlAdmin/tests/Unit/V1/Client/SqlInstancesServiceClientTest.php @@ -28,6 +28,8 @@ use Google\ApiCore\Testing\MockTransport; use Google\Cloud\Sql\V1\Client\SqlInstancesServiceClient; use Google\Cloud\Sql\V1\DatabaseInstance; +use Google\Cloud\Sql\V1\DemoteContext; +use Google\Cloud\Sql\V1\InstancesDemoteRequest; use Google\Cloud\Sql\V1\InstancesListResponse; use Google\Cloud\Sql\V1\InstancesListServerCasResponse; use Google\Cloud\Sql\V1\Operation; @@ -36,6 +38,7 @@ use Google\Cloud\Sql\V1\SqlInstancesCreateEphemeralCertRequest; use Google\Cloud\Sql\V1\SqlInstancesDeleteRequest; use Google\Cloud\Sql\V1\SqlInstancesDemoteMasterRequest; +use Google\Cloud\Sql\V1\SqlInstancesDemoteRequest; use Google\Cloud\Sql\V1\SqlInstancesExportRequest; use Google\Cloud\Sql\V1\SqlInstancesFailoverRequest; use Google\Cloud\Sql\V1\SqlInstancesGetDiskShrinkConfigRequest; @@ -369,6 +372,102 @@ public function deleteExceptionTest() $this->assertTrue($transport->isExhausted()); } + /** @test */ + public function demoteTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $kind = 'kind3292052'; + $targetLink = 'targetLink-2084812312'; + $user = 'user3599307'; + $name = 'name3373707'; + $targetId = 'targetId-815576439'; + $selfLink = 'selfLink-1691268851'; + $targetProject = 'targetProject392184427'; + $expectedResponse = new Operation(); + $expectedResponse->setKind($kind); + $expectedResponse->setTargetLink($targetLink); + $expectedResponse->setUser($user); + $expectedResponse->setName($name); + $expectedResponse->setTargetId($targetId); + $expectedResponse->setSelfLink($selfLink); + $expectedResponse->setTargetProject($targetProject); + $transport->addResponse($expectedResponse); + // Mock request + $instance = 'instance555127957'; + $project = 'project-309310695'; + $body = new InstancesDemoteRequest(); + $bodyDemoteContext = new DemoteContext(); + $demoteContextSourceRepresentativeInstanceName = 'demoteContextSourceRepresentativeInstanceName1566063379'; + $bodyDemoteContext->setSourceRepresentativeInstanceName($demoteContextSourceRepresentativeInstanceName); + $body->setDemoteContext($bodyDemoteContext); + $request = (new SqlInstancesDemoteRequest()) + ->setInstance($instance) + ->setProject($project) + ->setBody($body); + $response = $gapicClient->demote($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.sql.v1.SqlInstancesService/Demote', $actualFuncCall); + $actualValue = $actualRequestObject->getInstance(); + $this->assertProtobufEquals($instance, $actualValue); + $actualValue = $actualRequestObject->getProject(); + $this->assertProtobufEquals($project, $actualValue); + $actualValue = $actualRequestObject->getBody(); + $this->assertProtobufEquals($body, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function demoteExceptionTest() + { + $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 + $instance = 'instance555127957'; + $project = 'project-309310695'; + $body = new InstancesDemoteRequest(); + $bodyDemoteContext = new DemoteContext(); + $demoteContextSourceRepresentativeInstanceName = 'demoteContextSourceRepresentativeInstanceName1566063379'; + $bodyDemoteContext->setSourceRepresentativeInstanceName($demoteContextSourceRepresentativeInstanceName); + $body->setDemoteContext($bodyDemoteContext); + $request = (new SqlInstancesDemoteRequest()) + ->setInstance($instance) + ->setProject($project) + ->setBody($body); + try { + $gapicClient->demote($request); + // 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 demoteMasterTest() { diff --git a/SqlAdmin/tests/Unit/V1beta4/SqlInstancesServiceClientTest.php b/SqlAdmin/tests/Unit/V1beta4/SqlInstancesServiceClientTest.php index a6809176afdc..74d6d5426a6a 100644 --- a/SqlAdmin/tests/Unit/V1beta4/SqlInstancesServiceClientTest.php +++ b/SqlAdmin/tests/Unit/V1beta4/SqlInstancesServiceClientTest.php @@ -330,6 +330,82 @@ public function deleteExceptionTest() $this->assertTrue($transport->isExhausted()); } + /** @test */ + public function demoteTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $kind = 'kind3292052'; + $targetLink = 'targetLink-2084812312'; + $user = 'user3599307'; + $name = 'name3373707'; + $targetId = 'targetId-815576439'; + $selfLink = 'selfLink-1691268851'; + $targetProject = 'targetProject392184427'; + $expectedResponse = new Operation(); + $expectedResponse->setKind($kind); + $expectedResponse->setTargetLink($targetLink); + $expectedResponse->setUser($user); + $expectedResponse->setName($name); + $expectedResponse->setTargetId($targetId); + $expectedResponse->setSelfLink($selfLink); + $expectedResponse->setTargetProject($targetProject); + $transport->addResponse($expectedResponse); + // Mock request + $instance = 'instance555127957'; + $project = 'project-309310695'; + $response = $gapicClient->demote($instance, $project); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.sql.v1beta4.SqlInstancesService/Demote', $actualFuncCall); + $actualValue = $actualRequestObject->getInstance(); + $this->assertProtobufEquals($instance, $actualValue); + $actualValue = $actualRequestObject->getProject(); + $this->assertProtobufEquals($project, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function demoteExceptionTest() + { + $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 + $instance = 'instance555127957'; + $project = 'project-309310695'; + try { + $gapicClient->demote($instance, $project); + // 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 demoteMasterTest() {