use of org.apache.commons.configuration.SystemConfiguration in project java-chassis by ServiceComb.
the class CseAutoConfiguration method configureArchaius.
protected void configureArchaius(ConfigurableEnvironmentConfiguration envConfig) {
if (INITIALIZED.compareAndSet(false, true)) {
String appName = this.env.getProperty("spring.application.name");
if (appName == null) {
appName = "application";
//log.warn("No spring.application.name found, defaulting to 'application'");
}
System.setProperty(DeploymentContext.ContextKey.appId.getKey(), appName);
ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration();
// etc...)
if (this.externalConfigurations != null) {
for (AbstractConfiguration externalConfig : this.externalConfigurations) {
config.addConfiguration(externalConfig);
}
}
config.addConfiguration(envConfig, ConfigurableEnvironmentConfiguration.class.getSimpleName());
// below come from ConfigurationManager.createDefaultConfigInstance()
DynamicURLConfiguration defaultURLConfig = new DynamicURLConfiguration();
try {
config.addConfiguration(defaultURLConfig, URL_CONFIG_NAME);
} catch (Throwable ex) {
//log.error("Cannot create config from " + defaultURLConfig, ex);
}
// TODO: sys/env above urls?
if (!Boolean.getBoolean(DISABLE_DEFAULT_SYS_CONFIG)) {
SystemConfiguration sysConfig = new SystemConfiguration();
config.addConfiguration(sysConfig, SYS_CONFIG_NAME);
}
if (!Boolean.getBoolean(DISABLE_DEFAULT_ENV_CONFIG)) {
EnvironmentConfiguration environmentConfiguration = new EnvironmentConfiguration();
config.addConfiguration(environmentConfiguration, ENV_CONFIG_NAME);
}
ConcurrentCompositeConfiguration appOverrideConfig = new ConcurrentCompositeConfiguration();
config.addConfiguration(appOverrideConfig, APPLICATION_PROPERTIES);
config.setContainerConfigurationIndex(config.getIndexOfConfiguration(appOverrideConfig));
addArchaiusConfiguration(config);
}
// else {
// // TODO: reinstall ConfigurationManager
// //log.warn(
// // "Netflix ConfigurationManager has already been installed, unable to re-install");
// }
}
use of org.apache.commons.configuration.SystemConfiguration in project es6draft by anba.
the class Resources method loadConfiguration.
/**
* Loads the configuration file.
*/
public static Configuration loadConfiguration(Class<?> clazz) {
TestConfiguration config = clazz.getAnnotation(TestConfiguration.class);
String file = config.file();
String name = config.name();
try {
PropertiesConfiguration properties = new PropertiesConfiguration();
// entries are mandatory unless an explicit default value was given
properties.setThrowExceptionOnMissing(true);
properties.getInterpolator().setParentInterpolator(MISSING_VAR);
properties.load(resource(file), "UTF-8");
Configuration configuration = new CompositeConfiguration(Arrays.asList(new SystemConfiguration(), properties));
return configuration.subset(name);
} catch (ConfigurationException | IOException e) {
throw new RuntimeException(e);
} catch (NoSuchElementException e) {
throw e;
}
}
use of org.apache.commons.configuration.SystemConfiguration in project chassis by Kixeye.
the class ConfigurationBuilder method build.
/**
* Build the Configuration
*
* @return the configuration
*/
public AbstractConfiguration build() {
initApplicationFileConfiguration();
initAppVersion();
initApplicationConfiguration();
initModuleConfiguration();
ConcurrentCompositeConfiguration finalConfiguration = new ConcurrentCompositeConfiguration();
if (addSystemConfigs) {
finalConfiguration.addConfiguration(new ConcurrentMapConfiguration(new SystemConfiguration()));
}
finalConfiguration.addProperty(BootstrapConfigKeys.APP_VERSION_KEY.getPropertyName(), appVersion);
addServerInstanceProperties(finalConfiguration);
if (applicationConfiguration == null) {
LOGGER.warn("\n\n ****** Default configuration being used ******\n client application \"" + appName + "\" is being configured with modules defaults. Defaults should only be used in development environments.\n In non-developement environments, a configuration provider should be used to configure the client application and it should define ALL required configuration properties.\n");
finalConfiguration.addConfiguration(applicationFileConfiguration);
finalConfiguration.addConfiguration(moduleDefaultConfiguration);
} else {
finalConfiguration.addConfiguration(applicationConfiguration);
finalConfiguration.addConfiguration(applicationFileConfiguration);
}
finalConfiguration.setProperty(BootstrapConfigKeys.APP_VERSION_KEY.getPropertyName(), appVersion);
configureArchaius(finalConfiguration);
logConfiguration(finalConfiguration);
return finalConfiguration;
}
use of org.apache.commons.configuration.SystemConfiguration in project chassis by Kixeye.
the class CuratorFrameworkBuilder method buildConfiguration.
private ConcurrentCompositeConfiguration buildConfiguration() {
ConcurrentCompositeConfiguration configuration = new ConcurrentCompositeConfiguration();
configuration.addConfiguration(new ConcurrentMapConfiguration(new SystemConfiguration()));
configuration.addConfiguration(this.configuration);
configuration.addConfiguration(defaults);
return configuration;
}
use of org.apache.commons.configuration.SystemConfiguration in project java-chassis by ServiceComb.
the class TestYAMLConfigurationSource method testFullOperation.
@Test
public void testFullOperation() {
// configuration from system properties
ConcurrentMapConfiguration configFromSystemProperties = new ConcurrentMapConfiguration(new SystemConfiguration());
// configuration from yaml file
YAMLConfigurationSource configSource = new YAMLConfigurationSource();
DynamicConfiguration configFromYamlFile = new DynamicConfiguration(configSource, new NeverStartPollingScheduler());
// create a hierarchy of configuration that makes
// 1) dynamic configuration source override system properties
ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration();
finalConfig.addConfiguration(configFromYamlFile, "yamlConfig");
finalConfig.addConfiguration(configFromSystemProperties, "systemEnvConfig");
ConfigurationManager.install(finalConfig);
DynamicDoubleProperty myprop = DynamicPropertyFactory.getInstance().getDoubleProperty("trace.handler.sampler.percent", 0.1);
Assert.assertEquals(0.5, myprop.getValue().doubleValue(), 0.5);
// DynamicStringListProperty property = new DynamicStringListProperty("trace.handler.tlist", "|", DynamicStringListProperty.DEFAULT_DELIMITER);
// List<String> ll = property.get();
// for (String s : ll) {
// System.out.println(s);
// }
Object o = ConfigUtil.getProperty("zq");
@SuppressWarnings("unchecked") List<Map<String, Object>> listO = (List<Map<String, Object>>) o;
Assert.assertEquals(3, listO.size());
}
Aggregations