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
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:
- 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:
Parameter | Description | Example |
---|---|---|
<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. |
Using it, you can start Automation Process in debug mode, f.e.:
|
<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: