Skip to main content

Configuration Service

Configuration Service

Overview

ConfigurationService provides read access to key-value properties (e.g. URL to resource, Vault alias, Datastore name etc.) which can be used in AP execution and can be changed at any time without redeploy AP.

Define properties in standalone and developer configurations

For those run configurations, properties can be stored in resources/apm_run.properties file as key-value pairs

Example of apm_run.properties

apm_run.properties
hello=Hello property
boolean.value=true
url.value=https://172.20.194.57:8444
number.value=123
long.value=9223372036854775807

Define properties for Control Server run

There are 3 points, where you can define configuration properties:

  1. Control Server Configuration properties - are visible across all Automation Processes defined in Control Server

2. Automation Process Configuration properties - are visible only for runs of the Automation Process and overrides properties defined on Control Server Level

3. Node Configuration properties - are applying for runs that is running on the node and overrides properties defined on levels above

4. Feature related properties on node - will be only injected by feature if there is no properties defined on the level above. This properties are related to driver endpoints, like SELENIUM_HUB_URL


When you deploy Automation Process on node, you should define all your required properties in the Control Server properties, the resources/apm_run.properties is not avalible during runs on node.

Node configuration Properties

There are some parameters, specifying which for node you can effect JVM for Automation Process:

ParameterDescriptionExample
<span style="color: rgb(0,128,0);">JAVA_HOME</span>
Change JVM that will be using for Automation Processes run.c:Program FilesJavajdk-11.0.8
<span style="color: rgb(0,128,0);">JAVA_OPTS</span>

JVM options that will be passed to Automation Process run.


-DmyProperty1=123 -DmyProperty2=123

Using it, you can start Automation Process in debug mode, f.e.:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

<span style="color: rgb(6,125,23);">JAVA_ADDITIONAL_CLASSPATH</span>

Additional classpath parameters.


Configuration Service API

First, you need to Inject ConfigurationService in your Task class:

@ApTaskEntry(name = "ConfigurationService Example Task")
@Slf4j
public class ConfigurationExample extends ApTask {
	@Inject
	private ConfigurationService cfg;
}

Retrieving string using ConfigurationService :

String testProperty = this.cfg.get("hello");

You can set default value if key does not exist in service:

String property2 = this.cfg.get("no.value", "Default value");

You can also use predefined formatters to format values:

Boolean booleanFromCfg = this.cfg.get("boolean", ConfigurationService.Formatter.BOOLEAN);
Integer number = this.cfg.get("number", ConfigurationService.Formatter.INT);
Long longNumber = this.cfg.get("long.number", ConfigurationService.Formatter.LONG);
URL url = this.cfg.get("url", ConfigurationService.Formatter.URL);

Full example:

ConfigurationExample.java
package eu.ibagroup.easyrpa.configuration.task;

import eu.ibagroup.easyrpa.engine.annotation.ApTaskEntry;
import eu.ibagroup.easyrpa.engine.apflow.ApTask;
import eu.ibagroup.easyrpa.engine.service.ConfigurationService;
import lombok.extern.slf4j.Slf4j;

import javax.inject.Inject;
import java.net.URL;

@ApTaskEntry(name = "Configuration Service Example")
@Slf4j
public class ConfigurationExample extends ApTask {

	@Inject
	private ConfigurationService cfg;

	@Override
	public void execute() {
		String testProperty = this.cfg.get("hello");
		log.info("hello = {}", testProperty);

		String property2 = this.cfg.get("no.value", "Default value");
		log.info("no.value = {}", property2);

		Boolean booleanFromCfg = this.cfg.get("boolean.value", ConfigurationService.Formatter.BOOLEAN);
		Integer number = this.cfg.get("number.value", ConfigurationService.Formatter.INT);
		Long longNumber = this.cfg.get("long.value", ConfigurationService.Formatter.LONG);
		URL url = this.cfg.get("url.value", ConfigurationService.Formatter.URL);
		log.info("boolean.value = {}", booleanFromCfg);
		log.info("number.value = {}", number);
		log.info("long.value = {}", longNumber);
		log.info("url.value = {}", url);
	}
}

ConfigurationExampleAp.java
package eu.ibagroup.easyrpa.configuration;

import eu.ibagroup.easyrpa.configuration.task.ConfigurationExample;
import eu.ibagroup.easyrpa.engine.annotation.ApTaskEntry;
import eu.ibagroup.easyrpa.engine.apflow.ApModuleBase;
import eu.ibagroup.easyrpa.engine.apflow.TaskOutput;
import eu.ibagroup.easyrpa.engine.boot.ApModuleRunner;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@ApTaskEntry(name = "Configuration Service Example")
public class ConfigurationExampleAp extends ApModuleBase {

	public TaskOutput run() {
		return execute(getInput(), ConfigurationExample.class).get();
	}

	public static void main(String[] args) {
		ApModuleRunner.localLaunch(ConfigurationExampleAp.class);
	}
}