Skip to content

Commit

Permalink
feat: added Demote RPC (#6825)
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 586089229
Source-Link: googleapis/googleapis@f5d61d7
Source-Link: googleapis/googleapis-gen@6236bbe
Copy-Tag: eyJwIjoiU3FsQWRtaW4vLk93bEJvdC55YW1sIiwiaCI6IjYyMzZiYmU3NDdhOWY4OTRlNDFlNGJlZmVmZGQ2MjliMjY2MTgzNTEifQ==

* feat: added Demote RPC
PiperOrigin-RevId: 586090177
Source-Link: googleapis/googleapis@f10a004
Source-Link: googleapis/googleapis-gen@5e21cf0
Copy-Tag: eyJwIjoiU3FsQWRtaW4vLk93bEJvdC55YW1sIiwiaCI6IjVlMjFjZjAxMTY3Y2VkNzhjN2FkYjJjYjZmZjQ0YzkyYTM1MWQ3MWYifQ==
  • Loading branch information
gcf-owl-bot[bot] authored Dec 1, 2023
1 parent 8a35600 commit 7c9fc72
Show file tree
Hide file tree
Showing 22 changed files with 1,156 additions and 0 deletions.
Binary file modified SqlAdmin/metadata/V1/CloudSqlInstances.php
Binary file not shown.
Binary file modified SqlAdmin/metadata/V1Beta4/CloudSql.php
Binary file not shown.
Binary file modified SqlAdmin/metadata/V1Beta4/CloudSqlResources.php
Binary file not shown.
87 changes: 87 additions & 0 deletions SqlAdmin/samples/V1/SqlInstancesServiceClient/demote.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START sqladmin_v1_generated_SqlInstancesService_Demote_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\Sql\V1\Client\SqlInstancesServiceClient;
use Google\Cloud\Sql\V1\DemoteContext;
use Google\Cloud\Sql\V1\InstancesDemoteRequest;
use Google\Cloud\Sql\V1\Operation;
use Google\Cloud\Sql\V1\SqlInstancesDemoteRequest;

/**
* Demotes an existing standalone instance to be a Cloud SQL read replica
* for an external database server.
*
* @param string $instance Cloud SQL instance name.
* @param string $project ID of the project that contains the instance.
* @param string $bodyDemoteContextSourceRepresentativeInstanceName The name of the instance which acts as the on-premises primary
* instance in the replication setup.
*/
function demote_sample(
string $instance,
string $project,
string $bodyDemoteContextSourceRepresentativeInstanceName
): void {
// Create a client.
$sqlInstancesServiceClient = new SqlInstancesServiceClient();

// Prepare the request message.
$bodyDemoteContext = (new DemoteContext())
->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]
68 changes: 68 additions & 0 deletions SqlAdmin/samples/V1beta4/SqlInstancesServiceClient/demote.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START sqladmin_v1beta4_generated_SqlInstancesService_Demote_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\Sql\V1beta4\Operation;
use Google\Cloud\Sql\V1beta4\SqlInstancesServiceClient;

/**
* Demotes an existing standalone instance to be a Cloud SQL read replica
* for an external database server.
*
* @param string $instance The name of the Cloud SQL instance.
* @param string $project The project ID of the project that contains the instance.
*/
function demote_sample(string $instance, string $project): void
{
// Create a client.
$sqlInstancesServiceClient = new SqlInstancesServiceClient();

// Call the API and handle any network failures.
try {
/** @var Operation $response */
$response = $sqlInstancesServiceClient->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]
29 changes: 29 additions & 0 deletions SqlAdmin/src/V1/Client/SqlInstancesServiceClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [])
Expand Down Expand Up @@ -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.
Expand Down
106 changes: 106 additions & 0 deletions SqlAdmin/src/V1/DemoteContext.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 78 additions & 0 deletions SqlAdmin/src/V1/InstancesDemoteRequest.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7c9fc72

Please sign in to comment.