Skip to content

Commit 0022585

Browse files
authored
fix(Bigtable): ensure samples are generated for admin clients (#9045)
1 parent 7699f2a commit 0022585

67 files changed

Lines changed: 5385 additions & 1 deletion

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Bigtable/owlbot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@
4545
# First copy the Bigtable Admin
4646
admin_library = Path(f"../{php.STAGING_DIR}/Bigtable/v2/Admin").resolve()
4747

48-
# copy gapic src and tests
48+
# copy gapic src, samples, and tests
4949
s.move(admin_library / f'src', 'src/Admin', merge=preserve_copyright_year)
5050
s.move(admin_library / f'tests/Unit', 'tests/Unit/Admin', merge=preserve_copyright_year)
51+
s.move(admin_library / f'samples', 'samples/', merge=preserve_copyright_year)
5152

5253
# copy proto and metadata files
5354
s.move(admin_library / f'proto/src/Google/Cloud/Bigtable', f'src/', merge=preserve_copyright_year)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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 bigtableadmin_v2_generated_BigtableInstanceAdmin_CreateAppProfile_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\Cloud\Bigtable\Admin\V2\AppProfile;
28+
use Google\Cloud\Bigtable\Admin\V2\Client\BigtableInstanceAdminClient;
29+
use Google\Cloud\Bigtable\Admin\V2\CreateAppProfileRequest;
30+
31+
/**
32+
* Creates an app profile within an instance.
33+
*
34+
* @param string $formattedParent The unique name of the instance in which to create the new app
35+
* profile. Values are of the form `projects/{project}/instances/{instance}`. Please see
36+
* {@see BigtableInstanceAdminClient::instanceName()} for help formatting this field.
37+
* @param string $appProfileId The ID to be used when referring to the new app profile within
38+
* its instance, e.g., just `myprofile` rather than
39+
* `projects/myproject/instances/myinstance/appProfiles/myprofile`.
40+
*/
41+
function create_app_profile_sample(string $formattedParent, string $appProfileId): void
42+
{
43+
// Create a client.
44+
$bigtableInstanceAdminClient = new BigtableInstanceAdminClient();
45+
46+
// Prepare the request message.
47+
$appProfile = new AppProfile();
48+
$request = (new CreateAppProfileRequest())
49+
->setParent($formattedParent)
50+
->setAppProfileId($appProfileId)
51+
->setAppProfile($appProfile);
52+
53+
// Call the API and handle any network failures.
54+
try {
55+
/** @var AppProfile $response */
56+
$response = $bigtableInstanceAdminClient->createAppProfile($request);
57+
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
58+
} catch (ApiException $ex) {
59+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
60+
}
61+
}
62+
63+
/**
64+
* Helper to execute the sample.
65+
*
66+
* This sample has been automatically generated and should be regarded as a code
67+
* template only. It will require modifications to work:
68+
* - It may require correct/in-range values for request initialization.
69+
* - It may require specifying regional endpoints when creating the service client,
70+
* please see the apiEndpoint client configuration option for more details.
71+
*/
72+
function callSample(): void
73+
{
74+
$formattedParent = BigtableInstanceAdminClient::instanceName('[PROJECT]', '[INSTANCE]');
75+
$appProfileId = '[APP_PROFILE_ID]';
76+
77+
create_app_profile_sample($formattedParent, $appProfileId);
78+
}
79+
// [END bigtableadmin_v2_generated_BigtableInstanceAdmin_CreateAppProfile_sync]
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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 bigtableadmin_v2_generated_BigtableInstanceAdmin_CreateCluster_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\OperationResponse;
28+
use Google\Cloud\Bigtable\Admin\V2\Client\BigtableInstanceAdminClient;
29+
use Google\Cloud\Bigtable\Admin\V2\Cluster;
30+
use Google\Cloud\Bigtable\Admin\V2\CreateClusterRequest;
31+
use Google\Rpc\Status;
32+
33+
/**
34+
* Creates a cluster within an instance.
35+
*
36+
* Note that exactly one of Cluster.serve_nodes and
37+
* Cluster.cluster_config.cluster_autoscaling_config can be set. If
38+
* serve_nodes is set to non-zero, then the cluster is manually scaled. If
39+
* cluster_config.cluster_autoscaling_config is non-empty, then autoscaling is
40+
* enabled.
41+
*
42+
* @param string $formattedParent The unique name of the instance in which to create the new
43+
* cluster. Values are of the form `projects/{project}/instances/{instance}`. Please see
44+
* {@see BigtableInstanceAdminClient::instanceName()} for help formatting this field.
45+
* @param string $clusterId The ID to be used when referring to the new cluster within its
46+
* instance, e.g., just `mycluster` rather than
47+
* `projects/myproject/instances/myinstance/clusters/mycluster`.
48+
*/
49+
function create_cluster_sample(string $formattedParent, string $clusterId): void
50+
{
51+
// Create a client.
52+
$bigtableInstanceAdminClient = new BigtableInstanceAdminClient();
53+
54+
// Prepare the request message.
55+
$cluster = new Cluster();
56+
$request = (new CreateClusterRequest())
57+
->setParent($formattedParent)
58+
->setClusterId($clusterId)
59+
->setCluster($cluster);
60+
61+
// Call the API and handle any network failures.
62+
try {
63+
/** @var OperationResponse $response */
64+
$response = $bigtableInstanceAdminClient->createCluster($request);
65+
$response->pollUntilComplete();
66+
67+
if ($response->operationSucceeded()) {
68+
/** @var Cluster $result */
69+
$result = $response->getResult();
70+
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
71+
} else {
72+
/** @var Status $error */
73+
$error = $response->getError();
74+
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
75+
}
76+
} catch (ApiException $ex) {
77+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
78+
}
79+
}
80+
81+
/**
82+
* Helper to execute the sample.
83+
*
84+
* This sample has been automatically generated and should be regarded as a code
85+
* template only. It will require modifications to work:
86+
* - It may require correct/in-range values for request initialization.
87+
* - It may require specifying regional endpoints when creating the service client,
88+
* please see the apiEndpoint client configuration option for more details.
89+
*/
90+
function callSample(): void
91+
{
92+
$formattedParent = BigtableInstanceAdminClient::instanceName('[PROJECT]', '[INSTANCE]');
93+
$clusterId = '[CLUSTER_ID]';
94+
95+
create_cluster_sample($formattedParent, $clusterId);
96+
}
97+
// [END bigtableadmin_v2_generated_BigtableInstanceAdmin_CreateCluster_sync]
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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 bigtableadmin_v2_generated_BigtableInstanceAdmin_CreateInstance_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\OperationResponse;
28+
use Google\Cloud\Bigtable\Admin\V2\Client\BigtableInstanceAdminClient;
29+
use Google\Cloud\Bigtable\Admin\V2\CreateInstanceRequest;
30+
use Google\Cloud\Bigtable\Admin\V2\Instance;
31+
use Google\Rpc\Status;
32+
33+
/**
34+
* Create an instance within a project.
35+
*
36+
* Note that exactly one of Cluster.serve_nodes and
37+
* Cluster.cluster_config.cluster_autoscaling_config can be set. If
38+
* serve_nodes is set to non-zero, then the cluster is manually scaled. If
39+
* cluster_config.cluster_autoscaling_config is non-empty, then autoscaling is
40+
* enabled.
41+
*
42+
* @param string $formattedParent The unique name of the project in which to create the new
43+
* instance. Values are of the form `projects/{project}`. Please see
44+
* {@see BigtableInstanceAdminClient::projectName()} for help formatting this field.
45+
* @param string $instanceId The ID to be used when referring to the new instance within its
46+
* project, e.g., just `myinstance` rather than
47+
* `projects/myproject/instances/myinstance`.
48+
* @param string $instanceDisplayName The descriptive name for this instance as it appears in UIs.
49+
* Can be changed at any time, but should be kept globally unique
50+
* to avoid confusion.
51+
*/
52+
function create_instance_sample(
53+
string $formattedParent,
54+
string $instanceId,
55+
string $instanceDisplayName
56+
): void {
57+
// Create a client.
58+
$bigtableInstanceAdminClient = new BigtableInstanceAdminClient();
59+
60+
// Prepare the request message.
61+
$instance = (new Instance())
62+
->setDisplayName($instanceDisplayName);
63+
$clusters = [];
64+
$request = (new CreateInstanceRequest())
65+
->setParent($formattedParent)
66+
->setInstanceId($instanceId)
67+
->setInstance($instance)
68+
->setClusters($clusters);
69+
70+
// Call the API and handle any network failures.
71+
try {
72+
/** @var OperationResponse $response */
73+
$response = $bigtableInstanceAdminClient->createInstance($request);
74+
$response->pollUntilComplete();
75+
76+
if ($response->operationSucceeded()) {
77+
/** @var Instance $result */
78+
$result = $response->getResult();
79+
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
80+
} else {
81+
/** @var Status $error */
82+
$error = $response->getError();
83+
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
84+
}
85+
} catch (ApiException $ex) {
86+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
87+
}
88+
}
89+
90+
/**
91+
* Helper to execute the sample.
92+
*
93+
* This sample has been automatically generated and should be regarded as a code
94+
* template only. It will require modifications to work:
95+
* - It may require correct/in-range values for request initialization.
96+
* - It may require specifying regional endpoints when creating the service client,
97+
* please see the apiEndpoint client configuration option for more details.
98+
*/
99+
function callSample(): void
100+
{
101+
$formattedParent = BigtableInstanceAdminClient::projectName('[PROJECT]');
102+
$instanceId = '[INSTANCE_ID]';
103+
$instanceDisplayName = '[DISPLAY_NAME]';
104+
105+
create_instance_sample($formattedParent, $instanceId, $instanceDisplayName);
106+
}
107+
// [END bigtableadmin_v2_generated_BigtableInstanceAdmin_CreateInstance_sync]
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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 bigtableadmin_v2_generated_BigtableInstanceAdmin_CreateLogicalView_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\OperationResponse;
28+
use Google\Cloud\Bigtable\Admin\V2\Client\BigtableInstanceAdminClient;
29+
use Google\Cloud\Bigtable\Admin\V2\CreateLogicalViewRequest;
30+
use Google\Cloud\Bigtable\Admin\V2\LogicalView;
31+
use Google\Rpc\Status;
32+
33+
/**
34+
* Creates a logical view within an instance.
35+
*
36+
* @param string $formattedParent The parent instance where this logical view will be created.
37+
* Format: `projects/{project}/instances/{instance}`. Please see
38+
* {@see BigtableInstanceAdminClient::instanceName()} for help formatting this field.
39+
* @param string $logicalViewId The ID to use for the logical view, which will become the final
40+
* component of the logical view's resource name.
41+
* @param string $logicalViewQuery The logical view's select query.
42+
*/
43+
function create_logical_view_sample(
44+
string $formattedParent,
45+
string $logicalViewId,
46+
string $logicalViewQuery
47+
): void {
48+
// Create a client.
49+
$bigtableInstanceAdminClient = new BigtableInstanceAdminClient();
50+
51+
// Prepare the request message.
52+
$logicalView = (new LogicalView())
53+
->setQuery($logicalViewQuery);
54+
$request = (new CreateLogicalViewRequest())
55+
->setParent($formattedParent)
56+
->setLogicalViewId($logicalViewId)
57+
->setLogicalView($logicalView);
58+
59+
// Call the API and handle any network failures.
60+
try {
61+
/** @var OperationResponse $response */
62+
$response = $bigtableInstanceAdminClient->createLogicalView($request);
63+
$response->pollUntilComplete();
64+
65+
if ($response->operationSucceeded()) {
66+
/** @var LogicalView $result */
67+
$result = $response->getResult();
68+
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
69+
} else {
70+
/** @var Status $error */
71+
$error = $response->getError();
72+
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
73+
}
74+
} catch (ApiException $ex) {
75+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
76+
}
77+
}
78+
79+
/**
80+
* Helper to execute the sample.
81+
*
82+
* This sample has been automatically generated and should be regarded as a code
83+
* template only. It will require modifications to work:
84+
* - It may require correct/in-range values for request initialization.
85+
* - It may require specifying regional endpoints when creating the service client,
86+
* please see the apiEndpoint client configuration option for more details.
87+
*/
88+
function callSample(): void
89+
{
90+
$formattedParent = BigtableInstanceAdminClient::instanceName('[PROJECT]', '[INSTANCE]');
91+
$logicalViewId = '[LOGICAL_VIEW_ID]';
92+
$logicalViewQuery = '[QUERY]';
93+
94+
create_logical_view_sample($formattedParent, $logicalViewId, $logicalViewQuery);
95+
}
96+
// [END bigtableadmin_v2_generated_BigtableInstanceAdmin_CreateLogicalView_sync]

0 commit comments

Comments
 (0)