Running concurrent API Connect CLI tasks within a DevOps environment

Share this post:

We need to deploy multiple products in parallel

When we deploy APIs and products as part of a DevOps process, we often want to be able to configure multiple APIs and products at once.

Often, our process for configuration will look similar to this:

## Log in to APIC
apic login --server ${apic_server} --username ${apic_user} --password ${apic_password}

## Do some APIC actions
# APIC actions go here!

## Log out of APIC
apic logout --server ${apic_server}

When we run many of these processes in parallel, they can interfere with each other. Particularly, if one process A’s “logout” stage executes before another process B’s “APIC actions” are finished, then process B’s actions will be interrupted. This makes for unpredictable APIC deployments.

Isolating processes to enable parallelism

The cause of this lies in where the APIC CLI keeps its runtime information. By default, this is placed in ~/.apiconnect, and all APIC processes expect it to be here. In our example case, process A’s APIC logout will delete critical information from this directory that process B requires.

We need to isolate the processes from one another. We do this by setting the APIC_CONFIG_PATH environment variable to a unique value per process.

Avoiding prompts

We also need to account for the fact that APIC license acceptance is stored in the runtime information directory. If we haven’t used this directory beforehand, the APIC CLI will prompt the user to accept a licence and disable/enable analytics gathering.

Prompts won’t work for us in a DevOps environment. Fortunately, the APIC CLI allows us to accept the licence and disable analytics gathering on the command line. We do this by providing the --accept-license and --disable-analytics arguments to apic login.

The adjusted process

We adjust our process like this:

## If UCD has given us a unique directory, use a subdirectory of it to store this process's APIC runtime information
# ... Given a UCD property like /opt/ibm-ucd/agent/var/temp/logs1234/input.props
# ... Use a directory called "/opt/ibm-ucd/agent/var/temp/logs1234/apic-config" for APIC runtime information
[[ ! -z "${PLUGIN_INPUT_PROPS}" ]] && export APIC_CONFIG_PATH=`dirname ${PLUGIN_INPUT_PROPS}`/apic-config

## Log in to APIC
apic login --accept-license --disable-analytics --server ${apic_server} --username ${apic_user} --password ${apic_password}

## Do some APIC actions
# APIC actions go here!

## Log out of APIC
apic logout --server ${apic_server}

Now we can run many of these processes in parallel without interference issues.

IBM MobileFirst and Bluemix Consultant

More How-tos stories
May 1, 2019

What’s Included in the IBM Cloud Developer Tools Version 2.2.0

I’m pleased to announce the latest version of IBM Cloud Developer Tools CLI, which contains some exciting new features.

Continue reading

April 26, 2019

Help Shape the Future of Cloud Foundry

Are you a Cloud Foundry user? If so, here's your opportunity to influence the future of Cloud Foundry with the 2019 user survey.

Continue reading

April 25, 2019

Develop in Public Cloud, Deploy Anywhere with IBM Cloud DevOps

In this article, we explore how to deploy multicloud apps developed with IBM Cloud Continuous Delivery to a network-accessible IBM Cloud Private installation.

Continue reading