List of usage examples for org.apache.commons.configuration SystemConfiguration SystemConfiguration
public SystemConfiguration()
From source file:com.nesscomputing.config.Config.java
/** * Loads the configuration. The no-args method uses system properties to determine which configurations * to load./* www. j a v a 2 s .c o m*/ * * -Dness.config=x/y/z defines a hierarchy of configurations from general * to detail. * * The ness.config.location variable must be set. * If the ness.config variable is unset, the default value "default" is used. * * @throws IllegalStateException If the ness.config.location variable is not set. */ public static Config getConfig() { final Configuration systemConfig = new SystemConfiguration(); final String configName = systemConfig.getString(CONFIG_PROPERTY_NAME); final String configLocation = systemConfig.getString(CONFIG_LOCATION_PROPERTY_NAME); Preconditions.checkState(configLocation != null, "Config location must be set!"); final ConfigFactory configFactory = new ConfigFactory(URI.create(configLocation), configName); return new Config(configFactory.load()); }
From source file:com.nesscomputing.service.discovery.server.TestConfiguredStaticAnnouncements.java
@Before public void spinup() throws Exception { final Map<String, String> announceConfig = ImmutableMap.<String, String>builder() .put("org.quartz.threadPool.threadCount", "1") .put("ness.discovery.static-announce.65f57132-8415-422e-b44a-7543dda54858.name", "foo") .put("ness.discovery.static-announce.65f57132-8415-422e-b44a-7543dda54858.scheme", "http") .put("ness.discovery.static-announce.65f57132-8415-422e-b44a-7543dda54858.address", "127.0.0.1") .put("ness.discovery.static-announce.65f57132-8415-422e-b44a-7543dda54858.port", "12345") .put("ness.discovery.static-announce.65f57132-8415-422e-b44a-7543dda54858.type", "bar").build(); System.setProperty("ness.discovery.enabled", "true"); server = new DiscoveryServerMain() { @Override// w w w .j a va2 s. c om public Config getConfig() { final File tmpDir = Files.createTempDir(); tmpDir.deleteOnExit(); final String httpPort = Integer.toString(findUnusedPort()); serverBase = "http://localhost:" + httpPort; System.setProperty("galaxy.internal.port.http", httpPort); System.setProperty("ness.zookeeper.dataDir", tmpDir.getAbsolutePath()); System.setProperty("ness.zookeeper.clientPort", Integer.toString(findUnusedPort())); System.setProperty("ness.jmx.enabled", "false"); final int port1 = findUnusedPort(); final int port2 = findUnusedPort(); System.setProperty("ness.zookeeper.server.1", format("127.0.0.1:%d:%d", port1, port2)); System.setProperty("ness.zookeeper.clientPortAddress", "127.0.0.1"); return Config.getOverriddenConfig( Config.getConfig(URI.create("classpath:/config"), "discovery-server"), new MapConfiguration(announceConfig)); } }; server.startServer(); Guice.createInjector(Stage.PRODUCTION, new AbstractModule() { @Override protected void configure() { binder().requireExplicitBindings(); binder().disableCircularProxies(); install(new ConfigModule(Config.getFixedConfig(new SystemConfiguration()))); install(new LifecycleModule(ServiceDiscoveryLifecycle.class)); install(new NessJacksonModule()); install(new DiscoveryClientModule(true)); } }).injectMembers(this); lifecycle.executeTo(LifecycleStage.START_STAGE); }
From source file:com.nesscomputing.migratory.mojo.database.AbstractDatabaseMojo.java
@Override public final void execute() throws MojoExecutionException, MojoFailureException { ConfigureLog4j.start(this); try {/*from www.j a va 2 s.com*/ // Load the default manifest information. // final CombinedConfiguration config = new CombinedConfiguration(new OverrideCombiner()); // everything can be overridden by system properties. config.addConfiguration(new SystemConfiguration(), "systemProperties"); final String userHome = System.getProperty("user.home"); if (userHome != null) { final File propertyFile = new File(userHome, MIGRATORY_PROPERTIES_FILE); if (propertyFile.exists() && propertyFile.canRead() && propertyFile.isFile()) { config.addConfiguration(new PropertiesConfiguration(propertyFile)); } } final ConfigurationObjectFactory initialConfigFactory = new ConfigurationObjectFactory( new CommonsConfigSource(config)); // Load the initial config from the local config file this.initialConfig = initialConfigFactory.build(InitialConfig.class); if (this.manifestUrl == null) { this.manifestUrl = initialConfig.getManifestUrl(); } if (this.manifestName == null) { this.manifestName = initialConfig.getManifestName(); } if (manifestUrl == null) { throw new MojoExecutionException( "no manifest url found (did you create a .migratory.properties file?)"); } if (manifestName == null) { throw new MojoExecutionException( "no manifest name found (did you create a .migratory.properties file?)"); } LOG.debug("Manifest URL: %s", manifestUrl); LOG.debug("Manifest Name: %s", manifestName); this.optionList = parseOptions(options); final StringBuilder location = new StringBuilder(manifestUrl); if (!this.manifestUrl.endsWith("/")) { location.append("/"); } // After here, the manifestUrl is guaranteed to have a / at the end! this.manifestUrl = location.toString(); location.append(manifestName); location.append(".manifest"); LOG.debug("Manifest Location: %s", location); final MigratoryConfig initialMigratoryConfig = initialConfigFactory.build(MigratoryConfig.class); final LoaderManager initialLoaderManager = createLoaderManager(initialMigratoryConfig); final String contents = initialLoaderManager.loadFile(URI.create(location.toString())); if (contents == null) { throw new MojoExecutionException( format("Could not load manifest '%s' from '%s'", manifestName, manifestUrl)); } // // Now add the contents of the manifest file to the configuration creating the // final configuration for building the sql migration sets. // final PropertiesConfiguration pc = new PropertiesConfiguration(); pc.load(new StringReader(contents)); config.addConfiguration(pc); if (!validateConfiguration(config)) { throw new MojoExecutionException( format("Manifest '%s' is not valid. Refusing to execute!", manifestName)); } this.config = config; this.factory = new ConfigurationObjectFactory(new CommonsConfigSource(config)); this.migratoryConfig = factory.build(MigratoryConfig.class); this.loaderManager = createLoaderManager(migratoryConfig); LOG.debug("Configuration: %s", this.config); this.rootDBIConfig = getDBIConfig(getPropertyName("default.root_")); stateCheck(); doExecute(); } catch (Exception e) { Throwables.propagateIfInstanceOf(e, MojoExecutionException.class); LOG.errorDebug(e, "While executing Mojo %s", this.getClass().getSimpleName()); throw new MojoExecutionException("Failure:", e); } finally { ConfigureLog4j.stop(this); } }
From source file:com.nesscomputing.service.discovery.server.TestStaticAnnounce.java
@Before public void spinup() throws Exception { System.setProperty("ness.discovery.enabled", "true"); server = new DiscoveryServerMain() { @Override// ww w . j av a2s.c o m public Config getConfig() { final File tmpDir = Files.createTempDir(); tmpDir.deleteOnExit(); final String httpPort = Integer.toString(findUnusedPort()); serverBase = "http://localhost:" + httpPort; System.setProperty("galaxy.internal.port.http", httpPort); System.setProperty("ness.zookeeper.dataDir", tmpDir.getAbsolutePath()); System.setProperty("ness.zookeeper.clientPort", Integer.toString(findUnusedPort())); System.setProperty("ness.jmx.enabled", "false"); final int port1 = findUnusedPort(); final int port2 = findUnusedPort(); System.setProperty("ness.zookeeper.server.1", format("127.0.0.1:%d:%d", port1, port2)); System.setProperty("ness.zookeeper.clientPortAddress", "127.0.0.1"); return Config.getConfig(URI.create("classpath:/config"), "discovery-server"); } }; server.startServer(); Guice.createInjector(Stage.PRODUCTION, new AbstractModule() { @Override protected void configure() { binder().requireExplicitBindings(); binder().disableCircularProxies(); install(new ConfigModule(Config.getFixedConfig(new SystemConfiguration()))); install(new LifecycleModule(ServiceDiscoveryLifecycle.class)); install(new NessJacksonModule()); install(new HttpClientModule("test")); install(new DiscoveryClientModule(true)); } }).injectMembers(this); lifecycle.executeTo(LifecycleStage.START_STAGE); }
From source file:com.netflix.config.ConfigurationManager.java
private static AbstractConfiguration createDefaultConfigInstance() { ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration(); if (!Boolean.getBoolean(DynamicPropertyFactory.DISABLE_DEFAULT_SYS_CONFIG)) { try {//from ww w . ja va 2 s . c om DynamicURLConfiguration defaultURLConfig = new DynamicURLConfiguration(); config.addConfiguration(defaultURLConfig, DynamicPropertyFactory.URL_CONFIG_NAME); } catch (Throwable e) { logger.warn("Failed to create default dynamic configuration", e); } SystemConfiguration sysConfig = new SystemConfiguration(); config.addConfiguration(sysConfig, DynamicPropertyFactory.SYS_CONFIG_NAME); int index = config.getIndexOfConfiguration(sysConfig); config.setContainerConfigurationIndex(index); } return config; }
From source file:com.opentable.config.Config.java
/** * Loads the configuration. The no-args method uses system properties to determine which configurations * to load./*from ww w . j a va2 s . co m*/ * * -Dot.config=x/y/z defines a hierarchy of configurations from general * to detail. * * The ot.config.location variable must be set. * If the ot.config variable is unset, the default value "default" is used. * * @throws IllegalStateException If the ot.config.location variable is not set. */ public static Config getConfig() { final Configuration systemConfig = new SystemConfiguration(); final String configName = StringUtils.join(systemConfig.getList(CONFIG_PROPERTY_NAME), ','); final String configLocation = systemConfig.getString(CONFIG_LOCATION_PROPERTY_NAME); Preconditions.checkState(configLocation != null, "Config location must be set!"); final ConfigFactory configFactory = new ConfigFactory(URI.create(configLocation), configName); return new Config(configFactory.load()); }
From source file:ffx.autoparm.Keyword_poltype.java
/** * This method sets up configuration properties in the following precedence * order: 1.) Java system properties a.) -Dkey=value from the Java command * line b.) System.setProperty("key","value") within Java code. * * 2.) Structure specific properties (for example pdbname.properties) * * 3.) User specific properties (~/.ffx/ffx.properties) * * 4.) System wide properties (file defined by environment variable * FFX_PROPERTIES)// www .j av a 2 s. c om * * 5.) Internal force field definition. * * @since 1.0 * @param file a {@link java.io.File} object. * @return a {@link org.apache.commons.configuration.CompositeConfiguration} * object. */ public static CompositeConfiguration loadProperties(File file) { /** * Command line options take precedences. */ CompositeConfiguration properties = new CompositeConfiguration(); properties.addConfiguration(new SystemConfiguration()); /** * Structure specific options are 2nd. */ if (file != null && file.exists() && file.canRead()) { try { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file))); String prmfilename = br.readLine().split(" +")[1]; File prmfile = new File(prmfilename); if (prmfile.exists() && prmfile.canRead()) { properties.addConfiguration(new PropertiesConfiguration(prmfile)); properties.addProperty("propertyFile", prmfile.getCanonicalPath()); } } catch (Exception e1) { e1.printStackTrace(); } } // /** // * User specific options are 3rd. // */ // String filename = System.getProperty("user.home") + File.separator // + ".ffx/ffx.properties"; // File userPropFile = new File(filename); // if (userPropFile.exists() && userPropFile.canRead()) { // try { // properties.addConfiguration(new PropertiesConfiguration( // userPropFile)); // } catch (Exception e) { // logger.info("Error loading " + filename + "."); // } // } // // /** // * System wide options are 2nd to last. // */ // filename = System.getenv("FFX_PROPERTIES"); // if (filename != null) { // File systemPropFile = new File(filename); // if (systemPropFile.exists() && systemPropFile.canRead()) { // try { // properties.addConfiguration(new PropertiesConfiguration( // systemPropFile)); // } catch (Exception e) { // logger.info("Error loading " + filename + "."); // } // } // } /** * Echo the interpolated configuration. */ if (logger.isLoggable(Level.FINE)) { Configuration config = properties.interpolatedConfiguration(); Iterator<String> i = config.getKeys(); while (i.hasNext()) { String s = i.next(); logger.fine("Key: " + s + ", Value: " + Arrays.toString(config.getList(s).toArray())); } } return properties; }
From source file:com.yahoo.bard.webservice.config.LayeredFileSystemConfig.java
/** * Build a Layered File System Configuration, using first the environment and an application configuration source, * then drill down into available modules and load each of them in package dependency order. *//*from w w w.j a v a 2 s.c o m*/ @SuppressWarnings(value = "unchecked") public LayeredFileSystemConfig() { masterConfiguration = new CompositeConfiguration(); masterConfiguration.setThrowExceptionOnMissing(true); runtimeProperties = new Properties(); try { List<Configuration> userConfig = loader.loadConfigurations(USER_CONFIG_FILE_NAME); // User configuration provides overrides for configuration on a specific environment or specialized role if (userConfig.size() > 1) { List<Resource> resources = loader.loadResourcesWithName(USER_CONFIG_FILE_NAME) .collect(Collectors.toList()); LOG.error(TOO_MANY_USER_CONFIGS.logFormat(resources.toString())); throw new SystemConfigException(TOO_MANY_USER_CONFIGS.format(resources.size())); } // Test application configuration provides overrides for configuration in a testing environment List<Configuration> testApplicationConfig = loader.loadConfigurationsNoJars(TEST_CONFIG_FILE_NAME); // Application configuration defines configuration at an application level for a bard instance List<Configuration> applicationConfig = loader.loadConfigurations(APPLICATION_CONFIG_FILE_NAME); if (applicationConfig.size() > 1) { List<Resource> resources = loader.loadResourcesWithName(APPLICATION_CONFIG_FILE_NAME) .collect(Collectors.toList()); LOG.error(TOO_MANY_APPLICATION_CONFIGS.logFormat(resources.toString())); throw new SystemConfigException(TOO_MANY_APPLICATION_CONFIGS.format(resources.size())); } // Environment config has higher priority than java system properties // Java system properties have higher priority than file based configuration // Also, a runtime map is maintained to support on-the-fly configuration changes // Load the rest of the config "top down" through the layers, in highest to lowest precedence Stream.of(Stream.of(new MapConfiguration(runtimeProperties)), Stream.of(new EnvironmentConfiguration()), Stream.of(new SystemConfiguration()), userConfig.stream(), testApplicationConfig.stream(), applicationConfig.stream()).flatMap(Function.identity()).filter(Objects::nonNull) .forEachOrdered(masterConfiguration::addConfiguration); // Use the config which has been loaded to identify module dependencies List<String> dependentModules = (List<String>) masterConfiguration .getList(ConfigurationGraph.DEPENDENT_MODULE_KEY, Collections.<String>emptyList()); // Add module dependencies to the master configuration new ModuleLoader(loader).getConfigurations(dependentModules) .forEach(masterConfiguration::addConfiguration); } catch (IOException e) { throw new SystemConfigException(e); } }
From source file:io.servicecomb.foundation.ssl.SSLOptionTest.java
@Test public void testSSLOptionYaml() { // configuration from yaml files: default microservice.yaml DynamicConfiguration configFromYamlFile = new DynamicConfiguration(yamlConfigSource(), new FixedDelayPollingScheduler()); // configuration from system properties ConcurrentMapConfiguration configFromSystemProperties = new ConcurrentMapConfiguration( new SystemConfiguration()); // create a hierarchy of configuration that makes // 1) dynamic configuration source override system properties ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration(); finalConfig.addConfiguration(configFromSystemProperties, "systemEnvConfig"); finalConfig.addConfiguration(configFromYamlFile, "configFromYamlFile"); ConfigurationManager.install(finalConfig); SSLOption option = SSLOption.buildFromYaml("server"); String protocols = option.getProtocols(); option.setProtocols(protocols);//from w w w.j a v a 2s . c o m Assert.assertEquals("TLSv1.2,TLSv1.1,TLSv1,SSLv2Hello", protocols); String ciphers = option.getCiphers(); option.setCiphers(ciphers); Assert.assertEquals( "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_DSS_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_RSA_WITH_AES_128_CBC_SH" + "A,TLS_DHE_DSS_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA", ciphers); boolean authPeer = option.isAuthPeer(); option.setAuthPeer(authPeer); Assert.assertEquals(true, authPeer); boolean checkCNHost = option.isCheckCNHost(); option.setCheckCNHost(checkCNHost); Assert.assertEquals(true, checkCNHost); boolean checkCNWhite = option.isCheckCNWhite(); option.setCheckCNWhite(checkCNWhite); Assert.assertEquals(true, checkCNWhite); String checkCNWhiteFile = option.getCheckCNWhiteFile(); option.setCheckCNWhiteFile(checkCNWhiteFile); Assert.assertEquals("white.list", checkCNWhiteFile); boolean allowRenegociate = option.isAllowRenegociate(); option.setAllowRenegociate(allowRenegociate); Assert.assertEquals(false, allowRenegociate); String storePath = option.getStorePath(); option.setStorePath(storePath); Assert.assertEquals("internal", storePath); String trustStore = option.getTrustStore(); option.setTrustStore(trustStore); Assert.assertEquals("trust.jks", trustStore); String trustStoreType = option.getTrustStoreType(); option.setTrustStoreType(trustStoreType); Assert.assertEquals("JKS", trustStoreType); String trustStoreValue = option.getTrustStoreValue(); option.setTrustStoreValue(trustStoreValue); Assert.assertEquals("Changeme_123", trustStoreValue); String keyStore = option.getKeyStore(); option.setKeyStore(keyStore); Assert.assertEquals("server.p12", keyStore); String keyStoreType = option.getKeyStoreType(); option.setKeyStoreType(keyStoreType); Assert.assertEquals("PKCS12", keyStoreType); String keyStoreValue = option.getKeyStoreValue(); option.setKeyStoreValue(keyStoreValue); Assert.assertEquals("Changeme_123", keyStoreValue); String crl = option.getCrl(); option.setCrl(crl); Assert.assertEquals("revoke.crl", crl); option.setSslCustomClass("123"); SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass()); Assert.assertArrayEquals(custom.decode("123".toCharArray()), "123".toCharArray()); }
From source file:cc.kune.core.server.properties.KunePropertiesDefault.java
/** * Load configuration./*from ww w.jav a 2 s . co m*/ */ private void loadConfiguration() { try { config = new CompositeConfiguration(); config.addConfiguration(new SystemConfiguration()); config.addConfiguration(new PropertiesConfiguration(fileName)); } catch (final ConfigurationException e) { final String msg = MessageFormat.format("Couldn't open property file {0}", fileName); throw new ServerException(msg, e); } }