Delete Collection Job
Scenario Overview
Deleting a collection job removes sensor configurations associated with a specific ApplicationContext from the CNC Collection Service. This operation is useful for cleaning up unused jobs or replacing existing jobs with updated configurations.
The DeleteCollectionJob API is used to mark a collection job for deletion based on its ApplicationContext. The Collection Service will asynchronously clean up the associated sensor configurations on collectors or devices.
You can use the GetCollectionJobSummary
API to track the progress of the deletion, as the job transitions through the following phases:
ACTIVE
: The job is currently active.
TERMINATING
: The job is being terminated.
TERMINATION_FAILED
: The deletion has failed.
On successful termination, the ApplicationContext
will be deleted from the Collection Service.
Note: If the deletion fails and the job enters the TERMINATION_FAILED
phase, you can retry the deletion. The job will transition from TERMINATION_FAILED
to TERMINATING
and attempt deletion again.
The operations in the following API references are used in this example.
Prerequisites
Before running this example, ensure that you have obtained an access token. Refer to the 'Getting Started' section for instructions.
Delete Collection Job
To delete a collection job, update the delete_collection_job.json
input file with the required job details (e.g., ApplicationContext), then run the delete_collection_job.sh
script from the example directory.
Navigate to the cnc-collections-api-examples
directory and run the delete_collection_job.sh
script using the following command:
cd cnc-collections-api-examples;./delete_collection_job.sh
Script Details
#!/bin/bash
# Import common API functions and environment variables
# This script reads input from the .json file located in the input directory.
# Upon successful execution, the output is saved to the .json file in the output directory.
. ./cnc-api-common.sh
delete_collection_job() {
# Step 1: Ensure the CNC JWT is obtained by running the get-cnc-jwt.sh script.
# Read the JWT from the file and export it as the AUTH_TOKEN_HDR environment variable.
export_jwt
# STEP 2 : Update the input json with details of job to be deleted in the file CNC_API_INPUT
# STEP 3 : Trigger deleteCollectionJob API
# STEP 4 : Store the output in CNC_API_OUTPUT file
CNC_COLLECTION_API=$CNC_COLLECTION_API_CTX/collectionjob
CNC_API_INPUT="@$PRJ/input/delete_collection_job.json"
CNC_API_OUTPUT="$PRJ/output/delete_collection_job.json"
# Step 5: Send a DELETE request to delete the collection job and store the response in the output file.
http_delete $CNC_COLLECTION_API $CNC_API_OUTPUT $CNC_API_INPUT
}
delete_collection_job