Skip to content

Commit

Permalink
feat: tpu_queued_resources_list
Browse files Browse the repository at this point in the history
  • Loading branch information
gryczj committed Oct 23, 2024
1 parent 1b48263 commit 309f877
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ async function main(
// Wait for the create operation to complete.
await operation.promise();

// If you also want to wait for create operation of TPU Node,
// you can use `tpu_vm_get` sample to check current status of the node
// and wait until it is READY.
// You can wait until TPU Node is READY,
// and check its status using getTpuVm() from `tpu_vm_get` sample.
console.log(`Queued resource ${queuedResourceName} created.`);
}
await callCreateQueuedResource();
Expand Down
File renamed without changes.
File renamed without changes.
52 changes: 52 additions & 0 deletions tpu/queuedResources/getQueuedResourcesList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

async function main(zone) {
// [START tpu_queued_resources_list]
// Import the TPU library
const {TpuClient} = require('@google-cloud/tpu').v2alpha1;

// Instantiate a tpuClient
const tpuClient = new TpuClient();

/**
* TODO(developer): Update/uncomment these variables before running the sample.
*/
// Project ID or project number of the Google Cloud project, where you want to retrive the list of Queued Resources.
const projectId = await tpuClient.getProjectId();

// The zone from which the Queued Resources are retrived.
// zone = 'europe-west4-a';

async function callGetQueuedResourcesList() {
const request = {
parent: `projects/${projectId}/locations/${zone}`,
};

const [response] = await tpuClient.listQueuedResources(request);

console.log(JSON.stringify(response));
}
await callGetQueuedResourcesList();
// [END tpu_queued_resources_list]
}

main(...process.argv.slice(2)).catch(err => {
console.error(err);
process.exitCode = 1;
});
4 changes: 2 additions & 2 deletions tpu/test/forceDeleteQueuedResource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ describe('TPU queued resource force deletion', async () => {
it('should force queued resource deletion', () => {
// Create queued resource
execSync(
`node ./queuedResource/createQueuedResource.js ${nodeName} ${queuedResourceName} ${zone} ${tpuType} ${tpuSoftwareVersion}`,
`node ./queuedResources/createQueuedResource.js ${nodeName} ${queuedResourceName} ${zone} ${tpuType} ${tpuSoftwareVersion}`,
{
cwd,
}
);

const response = execSync(
`node ./queuedResource/forceDeleteQueuedResource.js ${queuedResourceName} ${zone}`,
`node ./queuedResources/forceDeleteQueuedResource.js ${queuedResourceName} ${zone}`,
{
cwd,
}
Expand Down
17 changes: 14 additions & 3 deletions tpu/test/queuedResource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('TPU queued resource', () => {

it('should create a new queued resource', async () => {
const response = execSync(
`node ./queuedResource/createQueuedResource.js ${nodeName} ${queuedResourceName} ${zone} ${tpuType} ${tpuSoftwareVersion}`,
`node ./queuedResources/createQueuedResource.js ${nodeName} ${queuedResourceName} ${zone} ${tpuType} ${tpuSoftwareVersion}`,
{
cwd,
}
Expand All @@ -73,21 +73,32 @@ describe('TPU queued resource', () => {

it('should return requested queued resource', () => {
const response = execSync(
`node ./queuedResource/getQueuedResource.js ${queuedResourceName} ${zone}`,
`node ./queuedResources/getQueuedResource.js ${queuedResourceName} ${zone}`,
{
cwd,
}
);

assert(
response.includes(`Queued resource ${queuedResourceName} retrived.`)
);
});

it('should return list of queued resources', () => {
const response = JSON.parse(
execSync(`node ./queuedResources/getQueuedResourcesList.js ${zone}`, {
cwd,
})
);

assert(Array.isArray(response));
});

it('should delete queued resource', async () => {
// Wait until queued resource is ready to delete.
await waitForTPUCreation(nodeName, zone);
const response = execSync(
`node ./queuedResource/deleteQueuedResource.js ${queuedResourceName} ${zone}`,
`node ./queuedResources/deleteQueuedResource.js ${queuedResourceName} ${zone}`,
{
cwd,
}
Expand Down

0 comments on commit 309f877

Please sign in to comment.