Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
dfad2cf
feat: add storage batch operations samples
thiyaguk09 Sep 11, 2025
8b9d2a2
bug fix
thiyaguk09 Sep 11, 2025
3ea4225
added test case
thiyaguk09 Sep 12, 2025
7b85f34
lint fix
thiyaguk09 Sep 12, 2025
7dceecc
feat(storage-batch): Improve Batch Operation API samples (Documentati…
thiyaguk09 Oct 17, 2025
a2f6598
Incorporated feedback from review comments
thiyaguk09 Oct 24, 2025
07bc988
Merge branch 'main' into storagebatchoperations-samples
ddelgrosso1 Oct 27, 2025
fcf02df
Merge branch 'main' into storagebatchoperations-samples
thiyaguk09 Oct 30, 2025
bf44b8e
Merge branch 'main' into storagebatchoperations-samples
thiyaguk09 Nov 18, 2025
8cd034b
Merge branch 'main' into storagebatchoperations-samples
thiyaguk09 Dec 10, 2025
affdd1f
Merge branch 'main' into storagebatchoperations-samples
chandra-siri Mar 12, 2026
6bf5c54
Merge branch 'main' into storagebatchoperations-samples
thiyaguk09 Mar 30, 2026
f664754
Merge branch 'main' into storagebatchoperations-samples
pearigee Apr 3, 2026
7011508
Merge branch 'main' into storagebatchoperations-samples
thiyaguk09 Apr 7, 2026
a930c35
Merge branch 'main' into storagebatchoperations-samples
cpriti-os Apr 23, 2026
29ec49e
Merge branch 'main' into storagebatchoperations-samples
thiyaguk09 May 15, 2026
a11eae8
Merge branch 'main' into storagebatchoperations-samples
thiyaguk09 Jun 4, 2026
c94aafb
Merge branch 'main' into storagebatchoperations-samples
thiyaguk09 Jun 10, 2026
638f60d
Merge branch 'main' into storagebatchoperations-samples
thiyaguk09 Jun 23, 2026
e156f08
Merge branch 'main' into storagebatchoperations-samples
thiyaguk09 Jun 24, 2026
99de4de
chore(vertexai/grounding): Decommission region tags (#4363)
angelcaamal Jun 25, 2026
739cd5a
remove decommission count token region tags (#4362)
angelcaamal Jun 25, 2026
19dfa54
Merge branch 'main' into storagebatchoperations-samples
thiyaguk09 Jun 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions generative-ai/snippets/count-tokens/countTokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// [START generativeaionvertexai_gemini_token_count]
const {GoogleGenAI} = require('@google/genai');

/**
Expand Down Expand Up @@ -51,7 +50,6 @@ async function countTokens(
const usageMetadata = result.usageMetadata;
console.log('Response tokens count: ', usageMetadata);
}
// [END generativeaionvertexai_gemini_token_count]

countTokens(...process.argv.slice(2)).catch(err => {
console.error(err.message);
Expand Down
2 changes: 0 additions & 2 deletions generative-ai/snippets/count-tokens/countTokensAdvanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// [START generativeaionvertexai_gemini_token_count_advanced]
const {GoogleGenAI} = require('@google/genai');
/**
* TODO(developer): Update these variables before running the sample.
Expand Down Expand Up @@ -63,7 +62,6 @@ async function countTokens(
console.log('Candidates Token Count:', usageMetadata.candidatesTokenCount);
console.log('Total Token Count:', usageMetadata.totalTokenCount);
}
// [END generativeaionvertexai_gemini_token_count_advanced]

countTokens(...process.argv.slice(2)).catch(err => {
console.error(err.message);
Expand Down
2 changes: 0 additions & 2 deletions generative-ai/snippets/grounding/groundingPrivateDataBasic.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// [START generativeaionvertexai_grounding_private_data_basic]
const {GoogleGenAI} = require('@google/genai');

/**
Expand Down Expand Up @@ -62,7 +61,6 @@ async function generateContentWithVertexAISearchGrounding(
JSON.stringify(result.candidates[0].groundingMetadata)
);
}
// [END generativeaionvertexai_grounding_private_data_basic]

generateContentWithVertexAISearchGrounding(...process.argv.slice(2)).catch(
err => {
Expand Down
2 changes: 0 additions & 2 deletions generative-ai/snippets/grounding/groundingPublicDataBasic.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// [START generativeaionvertexai_grounding_public_data_basic]
const {GoogleGenAI} = require('@google/genai');

/**
Expand Down Expand Up @@ -48,7 +47,6 @@ async function generateContentWithGoogleSearchGrounding(
JSON.stringify(result.candidates[0].groundingMetadata)
);
}
// [END generativeaionvertexai_grounding_public_data_basic]

generateContentWithGoogleSearchGrounding(...process.argv.slice(2)).catch(
err => {
Expand Down
89 changes: 89 additions & 0 deletions storagebatchoperations/cancelJob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright 2025 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';

/**
* This application demonstrates how to perform basic operations on an Batch Operations
* instance with the Google Cloud Storage API.
*
* For more information, see the documentation at https://cloud.google.com/storage/docs/batch-operations/overview.
*/

function main(projectId, jobId) {
Comment thread
thiyaguk09 marked this conversation as resolved.
// [START storage_batch_cancel_job]

/**
* Cancel a batch job instance.
*
* The operation to cancel a batch job instance in Google Cloud Storage (GCS) is used to stop
* a running or queued asynchronous task that is currently processing a large number of GCS objects.
*
* @param {string} projectId The Google Cloud project ID.
* Example: 'my-project-id'
* @param {string} jobId A unique identifier for this job.
* Example: '94d60cc1-2d95-41c5-b6e3-ff66cd3532d5'
*/

// Imports the Control library
const {StorageBatchOperationsClient} =
require('@google-cloud/storagebatchoperations').v1;

// Instantiates a client
const client = new StorageBatchOperationsClient();

async function cancelJob() {
const name = client.jobPath(projectId, 'global', jobId);

// Create the request
const request = {
name,
};

// Run request
try {
await client.cancelJob(request);
console.log(`Cancelled job: ${name}`);
} catch (error) {
// This might be expected if the job completed quickly or failed creation
console.error(
`Error canceling batch jobs for jobId ${jobId}:`,
error.message
);

if (error.code === 5) {
// NOT_FOUND (gRPC code 5) error can occur if the batch job does not exist.
console.error(
`Ensure the job '${jobId}' exists in project '${projectId}'.`
);
} else if (error.code === 9) {
// FAILED_PRECONDITION (gRPC code 9) can occur if the job is already being cancelled
// or is not in a RUNNING state that allows the cancel operation.
console.error(
`Batch job '${jobId}' may not be in a state that allows canceling (e.g., must be RUNNING).`
);
}
throw error;
}
}

cancelJob();
// [END storage_batch_cancel_job]
}

process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
Comment thread
thiyaguk09 marked this conversation as resolved.
93 changes: 93 additions & 0 deletions storagebatchoperations/createJob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright 2025 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';

/**
* This application demonstrates how to perform basic operations on an Batch Operations
* instance with the Google Cloud Storage API.
*
* For more information, see the documentation at https://cloud.google.com/storage/docs/batch-operations/overview.
*/

function main(projectId, jobId, bucketName, objectPrefix) {
Comment thread
thiyaguk09 marked this conversation as resolved.
// [START storage_batch_create_job]

/**
* Create a new batch job instance.
*
* @param {string} projectId Your Google Cloud project ID.
* Example: 'my-project-id'
* @param {string} bucketName The name of your GCS bucket.
* Example: 'your-gcp-bucket-name'
* @param {string} jobId A unique identifier for this job.
* Example: '94d60cc1-2d95-41c5-b6e3-ff66cd3532d5'
* @param {string} objectPrefix The prefix of objects to include in the operation.
* Example: 'prefix1'
*/

// Imports the Control library
const {StorageBatchOperationsClient} =
require('@google-cloud/storagebatchoperations').v1;

// Instantiates a client
const client = new StorageBatchOperationsClient();

async function createJob() {
const parent = await client.locationPath(projectId, 'global');

// Create the request
const request = {
parent,
jobId,
job: {
bucketList: {
buckets: [
{
bucket: bucketName,
prefixList: {
includedObjectPrefixes: [objectPrefix],
},
},
],
},
deleteObject: {
permanentObjectDeletionEnabled: false,
},
},
};

try {
// Run the request, which returns an Operation object
const [operation] = await client.createJob(request);
console.log(`Waiting for operation ${operation.name} to complete...`);

// Wait for the operation to complete and get the final resource
const [response] = await operation.promise();
console.log(`Created job: ${response.name}`);
} catch (error) {
console.error('Failed to create batch job:', error.message);
throw error;
}
}

createJob();
Comment thread
thiyaguk09 marked this conversation as resolved.
// [END storage_batch_create_job]
}

process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
Comment thread
thiyaguk09 marked this conversation as resolved.
81 changes: 81 additions & 0 deletions storagebatchoperations/deleteJob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2025 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';

/**
* This application demonstrates how to perform basic operations on an Batch Operations
* instance with the Google Cloud Storage API.
*
* For more information, see the documentation at https://cloud.google.com/storage/docs/batch-operations/overview.
*/

function main(projectId, jobId) {
Comment thread
thiyaguk09 marked this conversation as resolved.
// [START storage_batch_delete_job]
/**
* Delete a batch job instance.
*
* This operation is used to remove a completed, failed, or cancelled Batch Operation
* job from the system's list. It is essentially a cleanup action.
*
* @param {string} projectId Your Google Cloud project ID.
* Example: 'my-project-id'
* @param {string} jobId A unique identifier for this job.
* Example: '94d60cc1-2d95-41c5-b6e3-ff66cd3532d5'
*/

// Imports the Control library
const {StorageBatchOperationsClient} =
require('@google-cloud/storagebatchoperations').v1;

// Instantiates a client
const client = new StorageBatchOperationsClient();

async function deleteJob() {
const name = client.jobPath(projectId, 'global', jobId);

// Create the request
const request = {
name,
};

try {
// Run request
await client.deleteJob(request);
console.log(`Deleted job: ${name}`);
} catch (error) {
console.error(
`Error deleting batch jobs for jobId ${jobId}:`,
error.message
);

if (error.code === 5) {
// NOT_FOUND (gRPC code 5) error can occur if the batch job does not exist.
console.error(
`Ensure the job '${jobId}' exists in project '${projectId}'.`
);
}
throw error;
}
}

deleteJob();
Comment thread
thiyaguk09 marked this conversation as resolved.
// [END storage_batch_delete_job]
}

process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
Comment thread
thiyaguk09 marked this conversation as resolved.
Loading