Skip to content

Commit 266495c

Browse files
feat: [Memorystore] Add support for self managed migrations feature to Memorystore for Valkey (#9326)
* feat: Add support for self managed migrations feature to Memorystore for Valkey PiperOrigin-RevId: 944072201 Source-Link: googleapis/googleapis@ea20a7c Source-Link: googleapis/googleapis-gen@aec2255 Copy-Tag: eyJwIjoiTWVtb3J5c3RvcmUvLk93bEJvdC55YW1sIiwiaCI6ImFlYzIyNTUzOTI1YTQwY2UzN2ZiMjMwYWE2M2VmNDQ3ZmEzZjA5N2UifQ== * 🦉 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 <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 9902096 commit 266495c

33 files changed

Lines changed: 1536 additions & 51 deletions

Memorystore/metadata/V1/Memorystore.php

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/*
3+
* Copyright 2026 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START memorystore_v1_generated_Memorystore_FinishMigration_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\OperationResponse;
28+
use Google\Cloud\Memorystore\V1\Client\MemorystoreClient;
29+
use Google\Cloud\Memorystore\V1\FinishMigrationRequest;
30+
use Google\Cloud\Memorystore\V1\Instance;
31+
use Google\Rpc\Status;
32+
33+
/**
34+
* Finalizes the migration process.
35+
*
36+
* After the successful completion of this operation, the target instance
37+
* will:
38+
* 1. Stop replicating from the source instance.
39+
* 2. Allow both reads and writes.
40+
*
41+
* @param string $formattedName The resource name of the instance to finalize migration on.
42+
* Format: projects/{project}/locations/{location}/instances/{instance}
43+
* Please see {@see MemorystoreClient::instanceName()} for help formatting this field.
44+
*/
45+
function finish_migration_sample(string $formattedName): void
46+
{
47+
// Create a client.
48+
$memorystoreClient = new MemorystoreClient();
49+
50+
// Prepare the request message.
51+
$request = (new FinishMigrationRequest())
52+
->setName($formattedName);
53+
54+
// Call the API and handle any network failures.
55+
try {
56+
/** @var OperationResponse $response */
57+
$response = $memorystoreClient->finishMigration($request);
58+
$response->pollUntilComplete();
59+
60+
if ($response->operationSucceeded()) {
61+
/** @var Instance $result */
62+
$result = $response->getResult();
63+
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
64+
} else {
65+
/** @var Status $error */
66+
$error = $response->getError();
67+
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
68+
}
69+
} catch (ApiException $ex) {
70+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
71+
}
72+
}
73+
74+
/**
75+
* Helper to execute the sample.
76+
*
77+
* This sample has been automatically generated and should be regarded as a code
78+
* template only. It will require modifications to work:
79+
* - It may require correct/in-range values for request initialization.
80+
* - It may require specifying regional endpoints when creating the service client,
81+
* please see the apiEndpoint client configuration option for more details.
82+
*/
83+
function callSample(): void
84+
{
85+
$formattedName = MemorystoreClient::instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]');
86+
87+
finish_migration_sample($formattedName);
88+
}
89+
// [END memorystore_v1_generated_Memorystore_FinishMigration_sync]

Memorystore/samples/V1/MemorystoreClient/list_locations.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@
3232
/**
3333
* Lists information about the supported locations for this service.
3434
*
35+
* This method lists locations based on the resource scope provided in
36+
* the [ListLocationsRequest.name][google.cloud.location.ListLocationsRequest.name] field: *
37+
* **Global locations**: If `name` is empty, the method lists the
38+
* public locations available to all projects. * **Project-specific
39+
* locations**: If `name` follows the format
40+
* `projects/{project}`, the method lists locations visible to that
41+
* specific project. This includes public, private, or other
42+
* project-specific locations enabled for the project.
43+
*
44+
* For gRPC and client library implementations, the resource name is
45+
* passed as the `name` field. For direct service calls, the resource
46+
* name is
47+
* incorporated into the request path based on the specific service
48+
* implementation and version.
49+
*
3550
* This sample has been automatically generated and should be regarded as a code
3651
* template only. It will require modifications to work:
3752
* - It may require correct/in-range values for request initialization.
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
/*
3+
* Copyright 2026 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START memorystore_v1_generated_Memorystore_StartMigration_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\OperationResponse;
28+
use Google\Cloud\Memorystore\V1\Client\MemorystoreClient;
29+
use Google\Cloud\Memorystore\V1\Instance;
30+
use Google\Cloud\Memorystore\V1\SelfManagedSource;
31+
use Google\Cloud\Memorystore\V1\StartMigrationRequest;
32+
use Google\Rpc\Status;
33+
34+
/**
35+
* Initiates the migration of a source instance to the target Memorystore
36+
* instance.
37+
*
38+
* After the successful completion of this operation, the target instance
39+
* will:
40+
* 1. Set up replication with the source instance and replicate any writes to
41+
* the source instance.
42+
* 2. Only allow reads.
43+
*
44+
* @param string $selfManagedSourceIpAddress The IP address of the source instance.
45+
* This IP address should be a stable IP address that can be accessed by the
46+
* Memorystore instance throughout the migration process.
47+
* @param int $selfManagedSourcePort The port of the source instance.
48+
* This port should be a stable port that can be accessed by the Memorystore
49+
* instance throughout the migration process.
50+
* @param string $formattedSelfManagedSourceNetworkAttachment The resource name of the Private Service Connect Network
51+
* Attachment used to establish connectivity to the source instance. This
52+
* network attachment has the following requirements:
53+
* 1. It must be in the same project as the Memorystore instance.
54+
* 2. It must be in the same region as the Memorystore instance.
55+
* 3. The subnet attached to the network attachment must be in the same VPC
56+
* network as the source instance nodes.
57+
*
58+
* Format:
59+
* projects/{project}/regions/{region}/networkAttachments/{network_attachment}
60+
* Please see {@see MemorystoreClient::networkAttachmentName()} for help formatting this field.
61+
* @param string $formattedName The resource name of the instance to start migration on.
62+
* Format: projects/{project}/locations/{location}/instances/{instance}
63+
* Please see {@see MemorystoreClient::instanceName()} for help formatting this field.
64+
*/
65+
function start_migration_sample(
66+
string $selfManagedSourceIpAddress,
67+
int $selfManagedSourcePort,
68+
string $formattedSelfManagedSourceNetworkAttachment,
69+
string $formattedName
70+
): void {
71+
// Create a client.
72+
$memorystoreClient = new MemorystoreClient();
73+
74+
// Prepare the request message.
75+
$selfManagedSource = (new SelfManagedSource())
76+
->setIpAddress($selfManagedSourceIpAddress)
77+
->setPort($selfManagedSourcePort)
78+
->setNetworkAttachment($formattedSelfManagedSourceNetworkAttachment);
79+
$request = (new StartMigrationRequest())
80+
->setSelfManagedSource($selfManagedSource)
81+
->setName($formattedName);
82+
83+
// Call the API and handle any network failures.
84+
try {
85+
/** @var OperationResponse $response */
86+
$response = $memorystoreClient->startMigration($request);
87+
$response->pollUntilComplete();
88+
89+
if ($response->operationSucceeded()) {
90+
/** @var Instance $result */
91+
$result = $response->getResult();
92+
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
93+
} else {
94+
/** @var Status $error */
95+
$error = $response->getError();
96+
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
97+
}
98+
} catch (ApiException $ex) {
99+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
100+
}
101+
}
102+
103+
/**
104+
* Helper to execute the sample.
105+
*
106+
* This sample has been automatically generated and should be regarded as a code
107+
* template only. It will require modifications to work:
108+
* - It may require correct/in-range values for request initialization.
109+
* - It may require specifying regional endpoints when creating the service client,
110+
* please see the apiEndpoint client configuration option for more details.
111+
*/
112+
function callSample(): void
113+
{
114+
$selfManagedSourceIpAddress = '[IP_ADDRESS]';
115+
$selfManagedSourcePort = 0;
116+
$formattedSelfManagedSourceNetworkAttachment = MemorystoreClient::networkAttachmentName(
117+
'[PROJECT]',
118+
'[REGION]',
119+
'[NETWORK_ATTACHMENT]'
120+
);
121+
$formattedName = MemorystoreClient::instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]');
122+
123+
start_migration_sample(
124+
$selfManagedSourceIpAddress,
125+
$selfManagedSourcePort,
126+
$formattedSelfManagedSourceNetworkAttachment,
127+
$formattedName
128+
);
129+
}
130+
// [END memorystore_v1_generated_Memorystore_StartMigration_sync]

Memorystore/src/V1/BackupInstanceRequest.php

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)