Converting Post Ingestion Hook Script to Bash Node script

Overview

This article walks you through the steps to convert an existing Post Ingestion hook script to a workflow Bash Script.

Post Ingestion Hook

The Post Ingestion Hook feature allows you to run a script for specific tables/all tables in a table group after an ingestion job is completed. This functionality has been deprecated in the DataFoundry on Databricks product, in favour of Bash Script functionality in Orchestrator.

Bash Script

The Bash Script node in a workflow is a general purpose script executor and gives users more power to control the overall execution and orchestration of any DataFoundry workload.

Procedure

Post Ingestion Hook scripts can be executed at a table level but workflow Bash scripts can be executed only at a workflow level. Following are the steps that you can add to the script to make it work with Bash node:

Obtaining Job ID from the Ingest Source node of the Workflow

Obtain the job ID from the Ingest Source node of the workflow, that was part of the particular workflow run, so that it can be used to fetch and iterate through the list of tables, and obtain metadata like status, row count, etc.

Inputs

  • workflow_id: The ID of the workflow where the script will be run. This ID can be obtained from the Settings page for the workflow in the User Interface.


  • run_id: The run_id of the workflow can be accessed from the IW_WF_RUN_ID environment variable ( os.getenv(‘IW_WF_RUN_ID’) or $IW_WF_RUN_ID in Bash) in Python).

  • task_id: The task ID of the Ingestion Source task required to identify the workflow. This ID can be obtained by double-clicking on the task node in the User Interface.


API

Refer the following link for the workflow run variables: http://archiveddocs.infoworks.io/versions/3.2/infoworks_rest_api/workflow.html#get--v1.1-workflow-run-variables.json

Example Run

GET /run/variables.json?workflow_id=add7cd797ccb92a7934f3352&run_id=add7cd797ccb92a7934f3352&auth_token=xxxx HTTP/host/v1.1 Host: host_ip:rest_api_port

Output

HTTP/1.1 200 OK
Vary: Accept
Content-Type: text/javascript
{
"error": null,
"result": [
{
"task_id": “INGESTION_TASK_ID”, // Find the task id of the ingestion task node
"task_type": "bash_command_run",
"task_title": "Bash task 1",
"task_description": "Bash task 1",
"variables": [
"job_id": "JOB_ID_1",
"key2": "value2",
]
},
{
"task_id": "TASK_ID2",
"task_type": "bash_command_run",
"title": "Bash task 2",
"description": "Bash task 2",
"workflow_variables": [
"job_id": "JOB_ID_2",
"key2": "value2",
]
}

In the response for the API, you can obtain the job_id in the variables section for the Ingest Source Node task ( the task_id will remain constant and can be obtained from the UI).

Obtaining List of Tables and Status for Jobs

Obtain the list of tables and status for the jobs. Once you obtain the job ID, you can use the ingestion metrics API to get additional metadata to make decisions/perform required actions.

API

You can use the following API: http://archiveddocs.infoworks.io/versions/3.2/infoworks_rest_api/source.html#get--v1.1-source-ingestion-metrics.json

Example

GET /source/ingestion/metrics.json?job_id=add7cd797ccb92a7934f3352&auth_token=xxxx HTTP/host/v1.1

Output

{
"result": [
{
"_id": {
"$type": "oid",
"$value": "59dc9f354b7d1e4474d27d4f"
},
"full_load_end_time": {
"$date": 1507630952000
},
"full_load_start_time": {
"$date": 1507630900000
},
"ingest_duration": 51,
"ingest_status": true,
"ingest_type": "full-load",
“job_id": {
"$type": "oid",
"$value": "75a6a3c6680f8616ebbd50d3"
},
"records_inserted": 6979,
"source_id": {
"$type": "oid",
"$value": "705878411a4476a4149cc82d"
},
"table_id": {
"$type": "oid",
"$value": "add7cd797ccb92a7934f3352"

In this particular API, you can iterate through the result and obtain the table_id of each table in the job and obtain the desired metadata. For example, the status of ingestion can be determined by reading the ingest_status flag. By reading this flag, you can perform any action based on the previous job success or failure.