Skip to content

Commit 8c8311e

Browse files
author
Joanna Grycz
committed
feat: tpu_queued_resources_get
1 parent 21186ec commit 8c8311e

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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(queuedResourceName, zone) {
20+
// [START tpu_queued_resources_get]
21+
// Import the TPU library
22+
const {TpuClient} = require('@google-cloud/tpu').v2alpha1;
23+
24+
// Instantiate a tpuClient
25+
const tpuClient = new TpuClient();
26+
27+
/**
28+
* TODO(developer): Update/uncomment these variables before running the sample.
29+
*/
30+
// Project ID or project number of the Google Cloud project, where you want to retrive node.
31+
const projectId = await tpuClient.getProjectId();
32+
33+
// The name of queued resource.
34+
// queuedResourceName = 'queued-resource-1';
35+
36+
// The zone of your queued resource.
37+
// zone = 'europe-west4-a';
38+
39+
async function callGetQueuedResource() {
40+
const request = {
41+
name: `projects/${projectId}/locations/${zone}/queuedResources/${queuedResourceName}`,
42+
};
43+
44+
const [response] = await tpuClient.getQueuedResource(request);
45+
46+
console.log(JSON.stringify(response));
47+
console.log(`Queued resource ${queuedResourceName} retrived.`);
48+
}
49+
await callGetQueuedResource();
50+
// [END tpu_queued_resources_get]
51+
}
52+
53+
main(...process.argv.slice(2)).catch(err => {
54+
console.error(err);
55+
process.exitCode = 1;
56+
});

tpu/test/queuedResource.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,23 @@ describe('TPU queued resource', async () => {
3939
cwd,
4040
}
4141
);
42+
4243
assert(response.includes(`Queued resource ${queuedResourceName} created.`));
4344
});
4445

46+
it('should return requested queued resource', () => {
47+
const response = execSync(
48+
`node ./queuedResource/getQueuedResource.js ${queuedResourceName} ${zone}`,
49+
{
50+
cwd,
51+
}
52+
);
53+
54+
assert(
55+
response.includes(`Queued resource ${queuedResourceName} retrived.`)
56+
);
57+
});
58+
4559
it('should force queued resource deletion', () => {
4660
const response = execSync(
4761
`node ./queuedResource/forceDeleteQueuedResource.js ${queuedResourceName} ${zone}`,

0 commit comments

Comments
 (0)