Scripting Tips

You can write scripts to run a batch of commands using the OLP CLI. The following sections provide some hints and tips to help you.

Process JSON Output

When you use the OLP CLI within scripts, you may have to pass a parameter from the output of a previous command, as an argument to the next command.

Many OLP CLI commands support the --json option to display the command's result in JSON format. There are lots of ways to process a JSON in the command line, such as jq, which is a lightweight and flexible JSON command-line processor.

To create a pipeline and pass the resulting id as an argument to the next command, subsequently to create a pipeline version, use the following code snippet:

Linux
Windows
pipeline_id=$(olp pipeline create "My Example Pipeline" GROUP-848311d0-baef-4ec9-b499-cb8b88595515  \
   --description "This pipeline analyzes data" --json | jq -r .id)
olp pipeline version create version-name $pipeline_id example-pipeline-template-id \
   /user/data/pipeline-config.conf
for /f %i in ('olp pipeline create "My Example Pipeline" GROUP-848311d0-baef-4ec9-b499-cb8b88595515 ^
   --description "This pipeline analyzes data" --json ^| jq-win64 -r .id') do set pipeline_id=%i
olp pipeline version create version-name %pipeline_id% example-pipeline-template-id ^
   /user/data/pipeline-config.conf

To display pipeline version jobs for all pipeline versions in the target pipeline, currently in the ready state, use the following code snippet:

Linux
Windows
pipeline_version_ids=$(olp pipeline version list d77f288e-2c89-4c94-b4ba-79fbd1e26e79 --json \
   | jq -r '.pipelineVersions[] | select(.state | contains("ready")) | .id')
   while read -r pipeline_version_id; do
       echo "Pipeline version id: $pipeline_version_id"
       olp pipeline version job list d77f288e-2c89-4c94-b4ba-79fbd1e26e79 $pipeline_version_id
       echo
   done <<< "$pipeline_version_ids"
for /f %i in ('olp pipeline version list d77f288e-2c89-4c94-b4ba-79fbd1e26e79 --json 
   ^| jq-win64 -r ".pipelineVersions[] | select(.state | contains(\"ready\")) | .id"')
   do set pipeline_version_ids=%i
   for %i in (%pipeline_version_ids%) do (
       set pipeline_version_id=%i
       echo Pipeline version id: %pipeline_version_id%
       olp pipeline version job list d77f288e-2c89-4c94-b4ba-79fbd1e26e79 %pipeline_version_id%
   )

Prepare a Catalog

Use the following code snippet to create a catalog and upload partitions to it from another catalog:

Linux
Windows
partitions_folder="/user/data/partitions"
layer_id="advanced-navigation-attributes"
catalog_config="/user/data/catalog_config.json"
olp catalog show hrn:here:data:::rib-2 \
   --json | jq "del (.layers[] | select (.name != \"advanced-navigation-attributes\") )" > $catalog_config
catalog_id=$(olp catalog create first-catalog-example-id first-catalog-example --config $catalog_config \
   --summary "This catalog contains navigation attributes" --json | jq -r .hrn)
olp catalog layer add $catalog_id $layer_id "Advanced Navigation Attributes" --versioned \
   --summary "This layer contains navigation attributes cloned from RIB"
olp catalog layer partition get hrn:here:data:::rib-2 advanced-navigation-attributes \
   --partitions 17302684 17302686 17302687 --output $partitions_folder
olp catalog layer partition put $catalog_id $layer_id --input $partitions_folder
SETLOCAL
set partitions_folder="D:\data\partitions"
set layer_id="advanced-navigation-attributes"
set catalog_config="D:\data\catalog_config.json"
olp catalog show hrn:here:data:::rib-2 ^
   --json | jq-win64 "del (.layers[] | select (.name != \"advanced-navigation-attributes\") )" > %catalog_config%
for /f %i in ('olp catalog create first-catalog-example-id first-catalog-example --config %catalog_config% ^
   --summary "This catalog contains navigation attributes" --json ^| jq-win64 -r .hrn') do set catalog_id=%i
olp catalog layer add %catalog_id% %layer_id% "Advanced Navigation Attributes" --versioned ^
   --summary "This layer contains navigation attributes cloned from RIB"
olp catalog layer partition get hrn:here:data:::rib-2 advanced-navigation-attributes ^
   --partitions 17302684 17302686 17302687 --output %partitions_folder%
olp catalog layer partition put %catalog_id% %layer_id% --input %partitions_folder%

results matching ""

    No results matching ""