How to create a new Application variable managed by the central configuration of the platform.


Introduction 


In this guide, we are going to explain how the centralized global configuration works, and how to make new configurable global variables.


What is the Global Centralized Configuration of the onesait Platform?


There is a module within the platform that is in charge of managing the global configuration parameters. Its name is onesaitplatform-config-resources.


Its main features are:


  • Centralized endpoints configuration: every module of the platform that operates with endpoints, asks this service/module to retrieve them. For example, the communication between the Digital Broker and the Router is made via REST, so the Router Client in the Digital broker side asks for the Router Server endpoint:



  • Centralized swagger-ui endpoints: This service also centralizes all modules swagger-ui endpoints, which are loaded by the Controlpanel when you log in, and which you can see under 'APIs' at the top menu:



  • Centralized Global Configuration: There are some cases where you need global variables to be configurable by an Administrator and thus being hot-reloaded without the need to restart the modules. An example of this use is the following variable: 

The Quasar connector has a global variable for the operation timeout, which is configurable and managed by config-resources service.



The global configuration is stored as a JPA entity. It is a Configuration of the type 'OpenPlatform':

You can have several global configurations, as many as application profiles. For example, we have two configurations, one for 'default' (localhost), and one for 'docker' .


The same applies to Endpoints Configuration, but instead we will use Type EndpointModules.

The config-resources service loads at star-tup the Global and Endpoints configurations with the active profile as environment.

NOTE: Remember that you need at least the 'default' Global OpenPlatform configuration in order for the Platform to start up, otherwise it will not start up. Anyway, do not worry, because basic configurations for default and docker profiles are created when you run the SystemConfigInit app.



How to use the GlobalConfiguration in your spring Components?




Despite being only used for a few variables, you can extend it by following these steps:


  • Step 1: Edit yaml configuration. Go to Configuration management inside the Control panel (/controlpanel/configurations/list) and edit you Global Configuration with profile you want.

  • Step 2: Edit Java mapping class. If it is a new child of 'env' level, like in the example, you will have to do this step, otherwise skip to step 3. Open the project 'onesaitplatform-config-model' and go to the package 'com.minsait.onesait.platform.config.components'. In this package, we store the Java Classes to map with the yaml configuration. Inside GlobalConfiguration.java, you can find the EnvVariables attribute, which maps with 'env' node of the yaml. If you added a child node of 'env' like in the example above, you have to edit the Class EnvVariables as follows:

  • Step 3: Inject IntegrationResourceService and the global parameter. Now that you have set up the yaml and the Java mapper class, go to the Component/Service that will make use of this parameter/variable.

Inject with @Autowired the IntegrationResourceService. Assign the value to your variable by accessing the GlobalConfiguration of the platform:

Hot-reloading the Global Configurations


If you want to change any existing variable held by the Global Configuration without restarting the modules/containers, you want to go to '/controlpanel/configurations/list' and click on the 'Reload OP configurations'. Doing this, Endpoints and Global Configuration values will be reloaded and updated.




How to use the EndpointsConfiguration in your spring Components?


In the same way, you can change the Endpoints configuration. There is also one for each application profile. The main difference with the GlobalConfiguration is that the yaml tree is fully mapped in the Java domain, so if you want to add endpoints to the Configuration, you will have to create/update all Java classes. For example, having this configuration:



If you want to add 'advice' to 'domain' node (which actually would not make sense), you will have to update the Domain class in 'com.minsait.onesait.platform.config.components', and add the 'advice' attribute:



On the other hand, if you want to add a child node to 'urls', you will have to create a new Java Class and reference it in Urls.java. For example, if you want to add module 'rtdbmaintainer' to the Endpoints configuration you will have to:


  • Edit yaml Configuration:

  • Create Java classes in onesaitplatform-config-model > components:

  • Add the new module to Enum Modules in IntegrationResourcesServiceImpl at onesaitplatform-config-resources (and ServiceUrl in case it is different from base, advice, etc.):

  • Inject IntegrationsResourceService and ask for base url of Rtdbmaintainer:










(c) 2020 Indra Soluciones Tecnologías de la Información, S.L.U.