What is Centralized Configuration?
Available from Release 2.3.0-immortal
Introduction
In Q4 the Centralized Configuration has been remodeled, starting with version 2.3.0 we will find the various changes.
Changes introduced
New location
The location of this functionality within the Controlpanel menu will be changed, as it will now be available to all users, not just administrators.
From the next version of the Platform you will find this functionality in DEV TOOLS
Named and APIs
As of this version, a readable identifier can be assigned to each configuration, which will allow to operate with the configurations more easily. For this, a new API has also been created within the control panel's APIs to be able to obtain a Configuration according to its identifier, type and environment:
Integration with microservices
In addition, a new type of Configuration is added for the case of non-administrator users "EXTERNAL_CONFIGURATION".
This new type of configuration will allow users to simply load it into microservices. To do this, it is enough to create a Configuration object with the connection data against the environment where the desired configuration is located, then this object can be used to obtain the desired Configuration.
Â
ConfigurationManager manager = new ConfigurationManager("developer", "changeIt2020!", "https://hyperblast.onesaitplatform.com");
Configuration configuration = manager.getConfigurationById(configurationId);
For more details consult this tutorial.
Below is a complete example of how to operate with the Platform's Java Client:
Â
/**
* Copyright Indra Soluciones TecnologÃas de la Información, S.L.U.
* 2013-2021 SPAIN
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.minsait.onesait.platform.client;
import java.io.IOException;
import java.util.List;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import com.minsait.onesait.platform.client.enums.ConfigurationType;
import com.minsait.onesait.platform.client.exception.ConfigurationManagerException;
import com.minsait.onesait.platform.client.model.Configuration;
import com.minsait.onesait.platform.testing.IntegrationTest;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Category(IntegrationTest.class)
public class TestConfigurationManager {
private final static String USERNAME = "developer";
private final static String PASSWORD = "Changed2019!";
private final static String SERVER = "http://localhost:18000";
private final static String IDENTIFICATION = "testing_01";
private final static String ENVIRONMENT = "default";
private final static String YML_SAMPLE = "rancher:\r\n url: https://rancher.sofia4cities.com/\r\n accessKey: 471D90A16431C2CE7158\r\n secretKey: VSoq31eGBqaFsG4vUcuvdpkQL1T64FypVPVckaDx";
private final static ConfigurationType TYPE = ConfigurationType.EXTERNAL_CONFIG;
private static ConfigurationManager manager;
@BeforeClass
public static void startUp() throws ConfigurationManagerException {
log.info("Initializing Manager");
manager = new ConfigurationManager(USERNAME, PASSWORD, SERVER);
}
@Test
public void getAllConfigurations() throws IOException, ConfigurationManagerException {
log.info("Getting Configurations from open platform");
final List<Configuration> configurations = manager.getConfigurations();
Assert.assertTrue(configurations.size() > 0);
}
@Test
public void configurationCRUD() throws IOException, ConfigurationManagerException {
@SuppressWarnings("unchecked")
final Configuration configuration = Configuration.builder().description("Rancher config sample")
.environment(ENVIRONMENT).identification(IDENTIFICATION).username(USERNAME).type(TYPE).yml(YML_SAMPLE)
.build();
Configuration retrievedConfig = manager.getConfiguration(IDENTIFICATION, ConfigurationType.EXTERNAL_CONFIG,
ENVIRONMENT);
if (retrievedConfig != null) {
log.info("Deleting configuration with id {}", retrievedConfig.getId());
manager.deleteConfiguration(retrievedConfig.getId());
}
log.info("Creating configuration");
final String id = manager.createConfiguration(configuration);
Assert.assertNotNull(id);
log.info("Created configuration, id is {}", id);
retrievedConfig = manager.getConfigurationById(id);
Assert.assertNotNull(retrievedConfig);
log.info("Retrieved config from the platform by id");
retrievedConfig = manager.getConfiguration(IDENTIFICATION, ConfigurationType.EXTERNAL_CONFIG, ENVIRONMENT);
Assert.assertNotNull(retrievedConfig);
log.info("Retrieved config from the platform by parameters");
configuration.setDescription("This is a new description");
log.info("Updating configuration with new description and identification {}", IDENTIFICATION);
manager.updateConfiguration(configuration, id);
log.info("Deleting configuration with id {}", id);
manager.deleteConfiguration(IDENTIFICATION, ConfigurationType.EXTERNAL_CONFIG, ENVIRONMENT);
}
}