Running Blueprints Processor Microservice in an IDE

Objective

Run the blueprint processor locally in an IDE, while having the database running in a container. This way, code changes can be conveniently tested and debugged.

Check out the code

Check out the code from Gerrit: https://gerrit.onap.org/r/#/admin/projects/ccsdk/cds

Build it locally

In the checked out directory, type

mvn clean install -Pq -Dadditionalparam=-Xdoclint:none

Note

If an error invalid flag: --release appears when executing the maven install command, you need to upgrade Java version of your local Maven installation. Use something like export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64.

Wait for the maven install command to finish until you go further.

Spin up a Docker container with the database

The Blueprints Processor project uses a database to store information about the blueprints and therefore it needs to be online before attempting to run it.

One way to create the database is by using the docker-compose.yaml file. This database will require a local directory to mount a volume, therefore before running docker-compose create following directory:

mkdir -p -m 755 /opt/app/cds/mysql/data

Navigate to the docker-compose file in the distribution module:

cd ms/blueprintsprocessor/application/src/main/dc

And run docker-composer:

docker-compose up -d db

This should spin up a container of the MariaDB image in the background. To check if it has worked, this command can be used:

docker-compose logs -f

The phrase mysqld: ready for connections indicates that the database was started correctly.

From now on, the Docker container will be available on the computer; if it ever gets stopped, it can be started again by the command:

docker start <id of mariadb container>

Set permissions on the local file system

Blueprints processor uses the local file system for some operations and, therefore, need some existing and accessible paths to run properly.

Execute the following commands to create the needed directories, and grant access to the current user to modify them:

mkdir -p -m 755 /opt/app/onap/blueprints/archive
mkdir -p -m 755 /opt/app/onap/blueprints/deploy
mkdir -p -m 755 /opt/app/onap/scripts
sudo chown -R $(id -u):$(id -g) /opt/app/onap/

Import the project into the IDE

Note

This is the recommended IDE for running CDS blueprint processor.

Go to File | Open and choose the pom.xml file of the cds/ms/blueprintprocessor directory:

imageImportProject

Import as a project. Sometimes it may be necessary to reimport Maven project, e.g. if some dependencies can’t be found:

imageReimportMaven

Override some application properties:

Next steps will create a run configuration profile overriding some application properties with custom values, to reflect the local environment characteristics.

Navigate to the main class of the Blueprints Processor, the BlueprintProcessorApplication class:

ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt.

After dependencies are imported and indexes are set up you will see a green arrow next to main function of BlueprintProcessorApplication class, indicating that the run configuration can now be created. Right-click inside the class at any point to load the context menu and select create a run configuration from context:

imageCreateRunConfigKt

The following window will open:

imageRunConfigKt

Add the following in the field `VM Options`:

Custom values for properties
-Dspring.profiles.active=dev

Optional: You can override any value from application-dev.properties file here. In this case use the following pattern:

-D<application-dev.properties key>=<application-dev.properties value>

In the field ‘Working Directory’ browse to your application path .../cds/ms/blueprintsprocessor/application if path is not already specified correctly.

Run configuration should now look something like this:

imageRunConfigSetUp

Add/replace the following in Blueprint’s application-dev.properties file.

blueprintsprocessor.grpcclient.remote-python.type=token-auth
blueprintsprocessor.grpcclient.remote-python.host=localhost
blueprintsprocessor.grpcclient.remote-python.port=50051
blueprintsprocessor.grpcclient.remote-python.token=Basic Y2NzZGthcHBzOmNjc2RrYXBwcw==

blueprintprocessor.remoteScriptCommand.enabled=true

Take care that if a parameter already exist you need to change the value of the existing parameter to avoid duplicates.

Run the application:

Before running Blueprint Processor check that you use the correct Java version in IntelliJ. Select either run or debug for the created Run Configuration to start the Blueprints Processor:

imageRunDebug

imageBuildLogs

Testing the application

There are two main features of the Blueprints Processor that can be of interest of a developer: blueprint publish and blueprint process.

To upload custom blueprints, the endpoint api/v1/execution-service/publish is used.

To process, the endpoint is api/v1/execution-service/process.

Postman is a software that can be used to send these request, and an example of them is present on https://www.getpostman.com/collections/b99863b0cde7565a32fc.

A detailed description of the usage of different APIs of CDS will follow.

Possible Fixes

Imported packages or annotiations are not found, Run Config not available?

  1. Rebuild with maven install ... (see above)

  2. Potentially change Maven home directory in Settings

  3. Maven reimport in IDE

Compilation error?

  • Change Java Version to 11