Search in sources :

Example 6 with EnvironmentConfiguration

use of org.apache.commons.configuration.EnvironmentConfiguration in project incubator-servicecomb-java-chassis by apache.

the class ConfigUtil method createLocalConfig.

private static ConcurrentCompositeConfiguration createLocalConfig(List<ConfigModel> configModelList) {
    ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration();
    duplicateCseConfigToServicecomb(config, new ConcurrentMapConfigurationExt(new SystemConfiguration()), "configFromSystem");
    duplicateCseConfigToServicecomb(config, convertEnvVariable(new ConcurrentMapConfigurationExt(new EnvironmentConfiguration())), "configFromEnvironment");
    // If there is extra configurations, add it into config.
    EXTRA_CONFIG_MAP.entrySet().stream().filter(mapEntry -> !mapEntry.getValue().isEmpty()).forEachOrdered(configMapEntry -> duplicateCseConfigToServicecomb(config, new ConcurrentMapConfigurationExt(configMapEntry.getValue()), configMapEntry.getKey()));
    // we have already copy the cse config to the serviceComb config when we load the config from local yaml files
    // hence, we do not need duplicate copy it.
    config.addConfiguration(new DynamicConfigurationExt(new MicroserviceConfigurationSource(configModelList), new NeverStartPollingScheduler()), "configFromYamlFile");
    duplicateCseConfigToServicecombAtFront(config, new ConcurrentMapConfigurationExt(ConfigMapping.getConvertedMap(config)), "configFromMapping");
    return config;
}
Also used : Configuration(org.apache.commons.configuration.Configuration) CONFIG_KEY_SPLITER(org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_KEY_SPLITER) StringUtils(org.apache.commons.lang.StringUtils) WatchedUpdateListener(com.netflix.config.WatchedUpdateListener) DynamicConfigurationChangedEvent(org.apache.servicecomb.config.event.DynamicConfigurationChangedEvent) FieldUtils(org.apache.commons.lang.reflect.FieldUtils) ConfigModel(org.apache.servicecomb.config.archaius.sources.ConfigModel) CONFIG_CSE_PREFIX(org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_CSE_PREFIX) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) LoggerFactory(org.slf4j.LoggerFactory) SPIServiceUtils(org.apache.servicecomb.foundation.common.utils.SPIServiceUtils) HashMap(java.util.HashMap) ConfigCenterConfigurationSource(org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource) LinkedHashMap(java.util.LinkedHashMap) EventManager(org.apache.servicecomb.foundation.common.event.EventManager) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) DynamicProperty(com.netflix.config.DynamicProperty) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) Map(java.util.Map) Nonnull(javax.annotation.Nonnull) NeverStartPollingScheduler(org.apache.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) MicroserviceConfigurationSource(org.apache.servicecomb.config.archaius.sources.MicroserviceConfigurationSource) ConfigCenterConfigurationSourceLoader(org.apache.servicecomb.config.spi.ConfigCenterConfigurationSourceLoader) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConfigurationManager(com.netflix.config.ConfigurationManager) CONFIG_SERVICECOMB_PREFIX(org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_SERVICECOMB_PREFIX) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Collectors(java.util.stream.Collectors) WatchedUpdateResult(com.netflix.config.WatchedUpdateResult) DynamicPropertyFactory(com.netflix.config.DynamicPropertyFactory) EnvironmentConfiguration(org.apache.commons.configuration.EnvironmentConfiguration) Objects(java.util.Objects) List(java.util.List) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) MicroserviceConfigLoader(org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader) PropertyConverter(org.apache.commons.configuration.PropertyConverter) MicroserviceConfigurationSource(org.apache.servicecomb.config.archaius.sources.MicroserviceConfigurationSource) EnvironmentConfiguration(org.apache.commons.configuration.EnvironmentConfiguration) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) NeverStartPollingScheduler(org.apache.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler)

Example 7 with EnvironmentConfiguration

use of org.apache.commons.configuration.EnvironmentConfiguration in project incubator-servicecomb-java-chassis by apache.

the class MicroserviceFactory method createMicroserviceFromConfiguration.

private Microservice createMicroserviceFromConfiguration(Configuration configuration) {
    Microservice microservice = new Microservice();
    EnvironmentConfiguration envConfig = new EnvironmentConfiguration();
    if (!StringUtils.isEmpty(envConfig.getString(APP_MAPPING)) && !StringUtils.isEmpty(envConfig.getString(envConfig.getString(APP_MAPPING)))) {
        microservice.setAppId(envConfig.getString(envConfig.getString(APP_MAPPING)));
    } else {
        microservice.setAppId(BootStrapProperties.readApplication(configuration));
    }
    if (!StringUtils.isEmpty(envConfig.getString(SERVICE_MAPPING)) && !StringUtils.isEmpty(envConfig.getString(envConfig.getString(SERVICE_MAPPING)))) {
        microservice.setServiceName(envConfig.getString(envConfig.getString(SERVICE_MAPPING)));
    } else {
        microservice.setServiceName(BootStrapProperties.readServiceName(configuration));
    }
    String version;
    if (!StringUtils.isEmpty(envConfig.getString(VERSION_MAPPING)) && !StringUtils.isEmpty(envConfig.getString(envConfig.getString(VERSION_MAPPING)))) {
        version = envConfig.getString(envConfig.getString(VERSION_MAPPING));
    } else {
        version = BootStrapProperties.readServiceVersion(configuration);
    }
    // just check version format
    new Version(version);
    microservice.setVersion(version);
    microservice.setDescription(BootStrapProperties.readServiceDescription(configuration));
    microservice.setLevel(BootStrapProperties.readServiceRole(configuration));
    microservice.setPaths(ConfigurePropertyUtils.getMicroservicePaths(configuration));
    Map<String, String> propertiesMap = MicroservicePropertiesLoader.INSTANCE.loadProperties(configuration);
    microservice.setProperties(propertiesMap);
    microservice.setEnvironment(BootStrapProperties.readServiceEnvironment(configuration));
    // set alias name when allow cross app
    if (microservice.allowCrossApp()) {
        microservice.setAlias(Microservice.generateAbsoluteMicroserviceName(microservice.getAppId(), microservice.getServiceName()));
    }
    microservice.setFramework(createFramework());
    microservice.setRegisterBy(CONFIG_DEFAULT_REGISTER_BY);
    return microservice;
}
Also used : EnvironmentConfiguration(org.apache.commons.configuration.EnvironmentConfiguration) Version(org.apache.servicecomb.foundation.common.Version)

Aggregations

EnvironmentConfiguration (org.apache.commons.configuration.EnvironmentConfiguration)7 SystemConfiguration (org.apache.commons.configuration.SystemConfiguration)5 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)4 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)4 ConcurrentMapConfiguration (com.netflix.config.ConcurrentMapConfiguration)2 ConfigurationManager (com.netflix.config.ConfigurationManager)2 DynamicProperty (com.netflix.config.DynamicProperty)2 DynamicPropertyFactory (com.netflix.config.DynamicPropertyFactory)2 DynamicURLConfiguration (com.netflix.config.DynamicURLConfiguration)2 WatchedUpdateListener (com.netflix.config.WatchedUpdateListener)2 WatchedUpdateResult (com.netflix.config.WatchedUpdateResult)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)2 Collectors (java.util.stream.Collectors)2