Skip to content

Commit 0703917

Browse files
authored
Merge branch 'main' into renovate/all
2 parents 8606b70 + 620fb04 commit 0703917

File tree

74 files changed

+2412
-318
lines changed

Some content is hidden

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

74 files changed

+2412
-318
lines changed

.github/blunderbuss.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ assign_issues_by:
5050
- 'api: documentai'
5151
to:
5252
- GoogleCloudPlatform/document-ai-samples-contributors
53+
- labels:
54+
- "api: routeoptimization"
55+
to:
56+
- GoogleCloudPlatform/geo-routeoptimization
5357

5458
assign_prs_by:
5559
- labels:
@@ -89,3 +93,7 @@ assign_prs_by:
8993
- 'api: documentai'
9094
to:
9195
- GoogleCloudPlatform/document-ai-samples-contributors
96+
- labels:
97+
- "api: routeoptimization"
98+
to:
99+
- GoogleCloudPlatform/geo-routeoptimization

.github/workflows/functions-slack.yaml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,22 @@ jobs:
4141
timeout-minutes: 120
4242
steps:
4343
- uses: actions/[email protected]
44-
with:
45-
ref: ${{github.event.pull_request.head.sha}}
44+
with:
45+
ref: ${{github.event.pull_request.head.sha}}
4646
- uses: 'google-github-actions/[email protected]'
47-
with:
48-
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
49-
service_account: '[email protected]'
50-
create_credentials_file: 'true'
51-
access_token_lifetime: 600s
47+
with:
48+
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
49+
service_account: '[email protected]'
50+
create_credentials_file: 'true'
51+
access_token_lifetime: 600s
5252
- id: secrets
5353
uses: 'google-github-actions/get-secretmanager-secrets@v2'
5454
with:
5555
secrets: |-
5656
slack_secret:nodejs-docs-samples-tests/nodejs-docs-samples-slack-secret
5757
kg_api_key:nodejs-docs-samples-tests/nodejs-docs-samples-kg-api-key
5858
- uses: actions/[email protected]
59-
with:
59+
with:
6060
node-version: 16
6161
- name: Get npm cache directory
6262
id: npm-cache-dir
@@ -70,23 +70,23 @@ jobs:
7070
restore-keys: |
7171
${{ runner.os }}-node-
7272
- name: set env vars for scheduled run
73-
if: github.event.action == 'schedule'
74-
run: |
73+
if: github.event.action == 'schedule'
74+
run: |
7575
echo "MOCHA_REPORTER_SUITENAME=functions-slack" >> $GITHUB_ENV
7676
echo "MOCHA_REPORTER_OUTPUT=${{github.run_id}}_sponge_log.xml" >> $GITHUB_ENV
7777
echo "MOCHA_REPORTER=xunit" >> $GITHUB_ENV
7878
- name: Run Tests
79-
run: make test dir=functions/slack
80-
env:
79+
run: make test dir=functions/slack
80+
env:
8181
GOOGLE_SAMPLES_PROJECT: "long-door-651"
8282
SLACK_SECRET: ${{ steps.secrets.outputs.slack_secret }}
8383
KG_API_KEY: ${{ steps.secrets.outputs.kg_api_key }}
8484
- name: upload test results for FlakyBot workflow
85-
if: github.event.action == 'schedule' && always()
86-
uses: actions/upload-artifact@v3
87-
env:
85+
if: github.event.action == 'schedule' && always()
86+
uses: actions/upload-artifact@v3
87+
env:
8888
MOCHA_REPORTER_OUTPUT: "${{github.run_id}}_sponge_log.xml"
89-
with:
89+
with:
9090
name: test-results
9191
path: functions/slack/${{ env.MOCHA_REPORTER_OUTPUT }}
9292
retention-days: 1

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,4 @@ security-center @GoogleCloudPlatform/gcp-security-command-center @GoogleCloudPla
6969
retail @GoogleCloudPlatform/cloud-retail-team @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
7070
media @GoogleCloudPlatform/cloud-media-team @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
7171
healthcare @GoogleCloudPlatform/healthcare-life-sciences @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
72+
routeoptimization @GoogleCloudPlatform/geo-routeoptimization @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers

batch/create/create_batch_notifications.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 Google LLC
2+
* Copyright 2024 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -55,14 +55,6 @@ async function main() {
5555
group.taskCount = 3;
5656
group.taskSpec = task;
5757

58-
const job = new batch.Job();
59-
job.name = JOB_NAME;
60-
job.taskGroups = [group];
61-
job.labels = {env: 'testing', type: 'script'};
62-
// We use Cloud Logging as it's an option available out of the box
63-
job.logsPolicy = new batch.LogsPolicy();
64-
job.logsPolicy.destination = batch.LogsPolicy.Destination.CLOUD_LOGGING;
65-
6658
// Create batch notification when job state changed
6759
const notification1 = new batch.JobNotification();
6860
notification1.pubsubTopic = `projects/${PROJECT_ID}/topics/${TOPIC_ID}`;
@@ -78,6 +70,7 @@ async function main() {
7870
newTaskState: 'FAILED',
7971
};
8072

73+
const job = new batch.Job();
8174
job.name = JOB_NAME;
8275
job.taskGroups = [group];
8376
job.notifications = [notification1, notification2];
@@ -101,13 +94,11 @@ async function main() {
10194
console.log(JSON.stringify(response));
10295
}
10396

104-
callCreateBatchNotifications();
97+
await callCreateBatchNotifications();
10598
// [END batch_notifications]
10699
}
107100

108-
process.on('unhandledRejection', err => {
101+
main().catch(err => {
109102
console.error(err.message);
110103
process.exitCode = 1;
111104
});
112-
113-
main();
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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+
// [START batch_create_custom_service_account]
20+
// Imports the Batch library
21+
const batchLib = require('@google-cloud/batch');
22+
const batch = batchLib.protos.google.cloud.batch.v1;
23+
// Instantiates a client
24+
const batchClient = new batchLib.v1.BatchServiceClient();
25+
26+
async function main() {
27+
/**
28+
* TODO(developer): Update these variables before running the sample.
29+
*/
30+
// Project ID or project number of the Google Cloud project you want to use.
31+
const projectId = await batchClient.getProjectId();
32+
// Name of the region you want to use to run the job. Regions that are
33+
// available for Batch are listed on: https://cloud.google.com/batch/docs/get-started#locations
34+
const region = 'europe-central2';
35+
// The name of the job that will be created.
36+
// It needs to be unique for each project and region pair.
37+
const jobName = 'batch-service-account-job';
38+
/**
39+
* TODO(developer): Uncomment and update serviceAccountEmail if you do not want to use default Compute Engine service account.
40+
*/
41+
// The email address of your service account.
42+
// const serviceAccountEmail = 'email';
43+
let serviceAccountEmail;
44+
45+
// Define what will be done as part of the job.
46+
const runnable = new batch.Runnable({
47+
script: new batch.Runnable.Script({
48+
commands: ['-c', 'echo Hello world! This is task ${BATCH_TASK_INDEX}.'],
49+
}),
50+
});
51+
52+
const task = new batch.TaskSpec({
53+
runnables: [runnable],
54+
maxRetryCount: 2,
55+
maxRunDuration: {seconds: 3600},
56+
});
57+
58+
// Tasks are grouped inside a job using TaskGroups.
59+
const group = new batch.TaskGroup({
60+
taskCount: 3,
61+
taskSpec: task,
62+
});
63+
64+
const serviceAccount = new batch.ServiceAccount();
65+
66+
if (serviceAccountEmail) {
67+
serviceAccount.email = serviceAccountEmail;
68+
}
69+
70+
const allocationPolicy = new batch.AllocationPolicy({
71+
// If the serviceAccount field is not specified, the value is set to the default Compute Engine service account.
72+
serviceAccount,
73+
});
74+
75+
const job = new batch.Job({
76+
name: jobName,
77+
taskGroups: [group],
78+
labels: {env: 'testing', type: 'script'},
79+
allocationPolicy,
80+
// We use Cloud Logging as it's an option available out of the box
81+
logsPolicy: new batch.LogsPolicy({
82+
destination: batch.LogsPolicy.Destination.CLOUD_LOGGING,
83+
}),
84+
});
85+
86+
// The job's parent is the project and region in which the job will run
87+
const parent = `projects/${projectId}/locations/${region}`;
88+
89+
async function callCreateBatchServiceAccountJob() {
90+
// Construct request
91+
const request = {
92+
parent,
93+
jobId: jobName,
94+
job,
95+
};
96+
97+
// Run request
98+
const [response] = await batchClient.createJob(request);
99+
console.log(JSON.stringify(response));
100+
}
101+
await callCreateBatchServiceAccountJob();
102+
// [END batch_create_custom_service_account]
103+
}
104+
105+
main().catch(err => {
106+
console.error(err);
107+
process.exitCode = 1;
108+
});

batch/create/create_gpu_job.js

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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+
// [START batch_create_gpu_job]
21+
// Imports the Batch library
22+
const batchLib = require('@google-cloud/batch');
23+
const batch = batchLib.protos.google.cloud.batch.v1;
24+
25+
// Instantiates a client
26+
const batchClient = new batchLib.v1.BatchServiceClient();
27+
28+
/**
29+
* TODO(developer): Update these variables before running the sample.
30+
*/
31+
const projectId = await batchClient.getProjectId();
32+
// Name of the region you want to use to run the job. Regions that are
33+
// available for Batch are listed on: https://cloud.google.com/batch/docs/get-started#locations
34+
const region = 'europe-central2';
35+
// The name of the job that will be created.
36+
// It needs to be unique for each project and region pair.
37+
const jobName = 'batch-gpu-job';
38+
// The GPU type. You can view a list of the available GPU types
39+
// by using the `gcloud compute accelerator-types list` command.
40+
const gpuType = 'nvidia-l4';
41+
// The number of GPUs of the specified type.
42+
const gpuCount = 1;
43+
// Optional. When set to true, Batch fetches the drivers required for the GPU type
44+
// that you specify in the policy field from a third-party location,
45+
// and Batch installs them on your behalf. If you set this field to false (default),
46+
// you need to install GPU drivers manually to use any GPUs for this job.
47+
const installGpuDrivers = false;
48+
// Accelerator-optimized machine types are available to Batch jobs. See the list
49+
// of available types on: https://cloud.google.com/compute/docs/accelerator-optimized-machines
50+
const machineType = 'g2-standard-4';
51+
52+
// Define what will be done as part of the job.
53+
const runnable = new batch.Runnable({
54+
script: new batch.Runnable.Script({
55+
commands: ['-c', 'echo Hello world! This is task ${BATCH_TASK_INDEX}.'],
56+
}),
57+
});
58+
59+
const task = new batch.TaskSpec({
60+
runnables: [runnable],
61+
maxRetryCount: 2,
62+
maxRunDuration: {seconds: 3600},
63+
});
64+
65+
// Tasks are grouped inside a job using TaskGroups.
66+
const group = new batch.TaskGroup({
67+
taskCount: 3,
68+
taskSpec: task,
69+
});
70+
71+
// Policies are used to define on what kind of virtual machines the tasks will run on.
72+
// In this case, we tell the system to use "g2-standard-4" machine type.
73+
// Read more about machine types here: https://cloud.google.com/compute/docs/machine-types
74+
const instancePolicy = new batch.AllocationPolicy.InstancePolicy({
75+
machineType,
76+
// Accelerator describes Compute Engine accelerators to be attached to the VM
77+
accelerators: [
78+
new batch.AllocationPolicy.Accelerator({
79+
type: gpuType,
80+
count: gpuCount,
81+
installGpuDrivers,
82+
}),
83+
],
84+
});
85+
86+
const allocationPolicy = new batch.AllocationPolicy.InstancePolicyOrTemplate({
87+
instances: [{installGpuDrivers, policy: instancePolicy}],
88+
});
89+
90+
const job = new batch.Job({
91+
name: jobName,
92+
taskGroups: [group],
93+
labels: {env: 'testing', type: 'script'},
94+
allocationPolicy,
95+
// We use Cloud Logging as it's an option available out of the box
96+
logsPolicy: new batch.LogsPolicy({
97+
destination: batch.LogsPolicy.Destination.CLOUD_LOGGING,
98+
}),
99+
});
100+
// The job's parent is the project and region in which the job will run
101+
const parent = `projects/${projectId}/locations/${region}`;
102+
103+
async function callCreateBatchGPUJob() {
104+
// Construct request
105+
const request = {
106+
parent,
107+
jobId: jobName,
108+
job,
109+
};
110+
111+
// Run request
112+
const [response] = await batchClient.createJob(request);
113+
console.log(JSON.stringify(response));
114+
}
115+
116+
await callCreateBatchGPUJob();
117+
// [END batch_create_gpu_job]
118+
}
119+
120+
main().catch(err => {
121+
console.error(err.message);
122+
process.exitCode = 1;
123+
});

0 commit comments

Comments
 (0)