Skip to content

Commit e909827

Browse files
authored
Merge branch 'main' into renovate/all
2 parents e6d5591 + 68c11ef commit e909827

33 files changed

+2197
-27
lines changed

.github/workflows/tpu.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: tpu
16+
on:
17+
push:
18+
branches:
19+
- main
20+
paths:
21+
- 'tpu/**'
22+
- '.github/workflows/tpu.yaml'
23+
- '.github/workflows/test.yaml'
24+
pull_request:
25+
types:
26+
- opened
27+
- reopened
28+
- synchronize
29+
- labeled
30+
paths:
31+
- 'tpu/**'
32+
- '.github/workflows/tpu.yaml'
33+
- '.github/workflows/test.yaml'
34+
schedule:
35+
- cron: '0 0 * * 0'
36+
jobs:
37+
test:
38+
# Ref: https://github.com/google-github-actions/auth#usage
39+
permissions:
40+
contents: 'read'
41+
id-token: 'write'
42+
if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run'
43+
uses: ./.github/workflows/test.yaml
44+
with:
45+
name: 'tpu'
46+
path: 'tpu'
47+
flakybot:
48+
# Ref: https://github.com/google-github-actions/auth#usage
49+
permissions:
50+
contents: 'read'
51+
id-token: 'write'
52+
if: github.event_name == 'schedule' && always() # always() submits logs even if tests fail
53+
uses: ./.github/workflows/flakybot.yaml
54+
needs: [test]

.github/workflows/utils/workflows.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"speech",
9191
"talent",
9292
"texttospeech",
93+
"tpu",
9394
"translate",
9495
"video-intelligence",
9596
"vision/productSearch",

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ recaptcha_enterprise @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-
2424
recaptcha_enterprise/demosite @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/recaptcha-customer-obsession-reviewers @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
2525
secret-manager @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers @GoogleCloudPlatform/cloud-secrets-team
2626
service-directory @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
27+
tpu @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
2728
webrisk @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
2829

2930
# SoDa teams
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
async function main(
20+
consistencyGroupName,
21+
consistencyGroupLocation,
22+
diskName,
23+
diskLocation
24+
) {
25+
// [START compute_consistency_group_add_disk]
26+
// Import the Compute library
27+
const computeLib = require('@google-cloud/compute');
28+
const compute = computeLib.protos.google.cloud.compute.v1;
29+
30+
// If you want to add regional disk,
31+
// you should use: RegionDisksClient and RegionOperationsClient.
32+
// Instantiate a disksClient
33+
const disksClient = new computeLib.DisksClient();
34+
// Instantiate a zone
35+
const zoneOperationsClient = new computeLib.ZoneOperationsClient();
36+
37+
/**
38+
* TODO(developer): Update/uncomment these variables before running the sample.
39+
*/
40+
// The project that contains the disk.
41+
const projectId = await disksClient.getProjectId();
42+
43+
// The name of the disk.
44+
// diskName = 'disk-name';
45+
46+
// If you use RegionDisksClient- define region, if DisksClient- define zone.
47+
// The zone or region of the disk.
48+
// diskLocation = 'europe-central2-a';
49+
50+
// The name of the consistency group.
51+
// consistencyGroupName = 'consistency-group-name';
52+
53+
// The region of the consistency group.
54+
// consistencyGroupLocation = 'europe-central2';
55+
56+
async function callAddDiskToConsistencyGroup() {
57+
const [response] = await disksClient.addResourcePolicies({
58+
disk: diskName,
59+
project: projectId,
60+
// If you use RegionDisksClient, pass region as an argument instead of zone.
61+
zone: diskLocation,
62+
disksAddResourcePoliciesRequestResource:
63+
new compute.DisksAddResourcePoliciesRequest({
64+
resourcePolicies: [
65+
`https://www.googleapis.com/compute/v1/projects/${projectId}/regions/${consistencyGroupLocation}/resourcePolicies/${consistencyGroupName}`,
66+
],
67+
}),
68+
});
69+
70+
let operation = response.latestResponse;
71+
72+
// Wait for the add disk operation to complete.
73+
while (operation.status !== 'DONE') {
74+
[operation] = await zoneOperationsClient.wait({
75+
operation: operation.name,
76+
project: projectId,
77+
// If you use RegionDisksClient, pass region as an argument instead of zone.
78+
zone: operation.zone.split('/').pop(),
79+
});
80+
}
81+
82+
console.log(
83+
`Disk: ${diskName} added to consistency group: ${consistencyGroupName}.`
84+
);
85+
}
86+
87+
await callAddDiskToConsistencyGroup();
88+
// [END compute_consistency_group_add_disk]
89+
}
90+
91+
main(...process.argv.slice(2)).catch(err => {
92+
console.error(err);
93+
process.exitCode = 1;
94+
});
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
async function main(disksClient, zoneOperationsClient) {
20+
// [START compute_consistency_group_clone]
21+
// Import the Compute library
22+
const computeLib = require('@google-cloud/compute');
23+
const compute = computeLib.protos.google.cloud.compute.v1;
24+
25+
// If you want to clone regional disks,
26+
// you should use: RegionDisksClient and RegionOperationsClient.
27+
// TODO(developer): Uncomment disksClient and zoneOperationsClient before running the sample.
28+
// Instantiate a disksClient
29+
// disksClient = new computeLib.DisksClient();
30+
// Instantiate a zone
31+
// zoneOperationsClient = new computeLib.ZoneOperationsClient();
32+
33+
/**
34+
* TODO(developer): Update/uncomment these variables before running the sample.
35+
*/
36+
// The project that contains the disks.
37+
const projectId = await disksClient.getProjectId();
38+
39+
// If you use RegionDisksClient- define region, if DisksClient- define zone.
40+
// The zone or region that the disks in the consistency group are located in. The clones are created in this location.
41+
// diskLocation = 'europe-central2-a';
42+
const disksLocation = 'europe-north1-a';
43+
44+
// The name of the consistency group, that contains secondary disks to clone.
45+
// consistencyGroupName = 'consistency-group-name';
46+
const consistencyGroupName = 'consistency-group-1';
47+
48+
// The region of the consistency group.
49+
const consistencyGroupLocation = 'europe-north1';
50+
51+
async function callConsistencyGroupClone() {
52+
const [response] = await disksClient.bulkInsert({
53+
project: projectId,
54+
// If you use RegionDisksClient, pass region as an argument instead of zone.
55+
zone: disksLocation,
56+
bulkInsertDiskResourceResource: new compute.BulkInsertDiskResource({
57+
sourceConsistencyGroupPolicy: [
58+
`https://www.googleapis.com/compute/v1/projects/${projectId}/regions/${consistencyGroupLocation}/resourcePolicies/${consistencyGroupName}`,
59+
],
60+
}),
61+
});
62+
63+
let operation = response.latestResponse;
64+
65+
// Wait for the clone operation to complete.
66+
while (operation.status !== 'DONE') {
67+
[operation] = await zoneOperationsClient.wait({
68+
operation: operation.name,
69+
project: projectId,
70+
// If you use RegionDisksClient, pass region as an argument instead of zone.
71+
zone: operation.zone.split('/').pop(),
72+
});
73+
}
74+
75+
const message = `Disks cloned from consistency group: ${consistencyGroupName}.`;
76+
console.log(message);
77+
return message;
78+
}
79+
80+
return await callConsistencyGroupClone();
81+
// [END compute_consistency_group_clone]
82+
}
83+
84+
module.exports = main;
85+
86+
// TODO(developer): Uncomment below lines before running the sample.
87+
// main(...process.argv.slice(2)).catch(err => {
88+
// console.error(err);
89+
// process.exitCode = 1;
90+
// });
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
async function main(
20+
consistencyGroupName,
21+
consistencyGroupLocation,
22+
disksLocation
23+
) {
24+
// [START compute_consistency_group_disks_list]
25+
// Import the Compute library
26+
const computeLib = require('@google-cloud/compute');
27+
28+
// If you want to get regional disks, you should use: RegionDisksClient.
29+
// Instantiate a disksClient
30+
const disksClient = new computeLib.DisksClient();
31+
32+
/**
33+
* TODO(developer): Update/uncomment these variables before running the sample.
34+
*/
35+
// The project that contains the disks.
36+
const projectId = await disksClient.getProjectId();
37+
38+
// If you use RegionDisksClient- define region, if DisksClient- define zone.
39+
// The zone or region of the disks.
40+
// disksLocation = 'europe-central2-a';
41+
42+
// The name of the consistency group.
43+
// consistencyGroupName = 'consistency-group-name';
44+
45+
// The region of the consistency group.
46+
// consistencyGroupLocation = 'europe-central2';
47+
48+
async function callConsistencyGroupDisksList() {
49+
const filter = `https://www.googleapis.com/compute/v1/projects/${projectId}/regions/${consistencyGroupLocation}/resourcePolicies/${consistencyGroupName}`;
50+
51+
const [response] = await disksClient.list({
52+
project: projectId,
53+
// If you use RegionDisksClient, pass region as an argument instead of zone.
54+
zone: disksLocation,
55+
});
56+
57+
// Filtering must be done manually for now, since list filtering inside disksClient.list is not supported yet.
58+
const filteredDisks = response.filter(disk =>
59+
disk.resourcePolicies.includes(filter)
60+
);
61+
62+
console.log(JSON.stringify(filteredDisks));
63+
}
64+
65+
await callConsistencyGroupDisksList();
66+
// [END compute_consistency_group_disks_list]
67+
}
68+
69+
main(...process.argv.slice(2)).catch(err => {
70+
console.error(err);
71+
process.exitCode = 1;
72+
});

0 commit comments

Comments
 (0)