How to use Central Configuration util on your application?

In versions prior to 2.3.0 this functionality is available in the Administration > Configuration Management menu and is only available for Administrators roles.

Onesait Platform has a Centralized Configuration System for many purposes. Users can define in a visual way configurations for their needs, including Deployment (Rancher & OpenShift configurations), Social networks (Twitter), Scheduled Processes, Endpoint registrations, etc. 

With this module users can define in a simple way configurations, platform uses YAML or JSON as base.

Control Panel UI

In order to create and modify Configurations, Administrator can go to menu DEV TOOLS > Configuration Management.


As you can see in the table a Configuration is related to an environment(typically default or docker), an identification and a type:

When you create a new Configuration the user fill in:

It must be taken into account that for non-administrator users (as of Platform version 2.3.0), only EXTERNAL_CONFIG configurations can be created.

For example, you can modify the Configuration for service endpoints, which is processed when the platform launches:

REST API

You can also make the operations through an existing REST API, whose endpoints start with '/controlpanel/api/configurations'

NOTE: As these Configurations use Yaml, the response from this REST service is not human-friendly

Using the Java client for configuration management

Java Client offers a Configuration Wrapper class.

Config Dependency

To use this API, you have to add the following repository to the project pom.xml

<repositories> <repository> <id>onesait platform releases</id> <url>https://nexus.onesaitplatform.com/nexus/content/repositories/releases/</url> </repository> </repositories>

And then add the following dependency:

We are going to make use of the Client ConfigurationManager, so import the class.

<dependency> <groupId>com.minsait.onesait.platform</groupId> <artifactId>onesaitplatform-java-client</artifactId> <version>2.1.0-RELEASE</version> </dependency>

Initialization

The first case is to create a ConfigurationManager object, in order to use the client you must enter the user, password and URL server as arguments:

private static ConfigurationManager manager; @PostConstruct public void init() throws ConfigurationManagerException, IOException { manager = new ConfigurationManager("developer", "changeIt2020!", "https://hyperblast.onesaitplatform.com"); }

Once the object is initialized, it can be used to operate with the Platform Settings.

Create a Configuration

To create a configuration, it is necessary to first create an Object of type Configuration:

Once the configuration has been created, a call must be made to the ClientManager, to the createConfiguration method:

This method, if successful, will return the id of the configuration that was just created. With this identifier the configuration can be recovered in the future, deleted or updated.

Get Configuration

There are two methods to retrieve a configuration:

  • getConfigurationById(id) 

With this one, you can retrieve a configuration by its id.

  • getConfiguration(identification, type, environment)

If you don't know the id, you can try to retrieve the configuration by parameters. These two methods will return an instance of Configuration, if it exists.

Get all Configurations

You can also retrieve a List of Configurations by user by calling the method getConfigurations:

Edit a Configuration

To edit a configuration, you have to know its id.

The best way to edit a configuration is to retrieve it, then make changes, and finally call method updateConfiguration:

Delete a Configuration

To delete a configuration, you call the method deleteConfiguration passing it the id of the configuration.

Test

There is a test inside the library to serve as an example. It tests all basic operations that are described in this tutorial. Take a look at it if you have any doubts.

Test Class