List of usage examples for org.apache.commons.configuration CompositeConfiguration addConfiguration
public void addConfiguration(Configuration config)
From source file:ffx.potential.utils.PotentialsDataConverter.java
/** * Converts the data structure to MolecularAssembly(s). *//*from w w w. j a va 2s . c om*/ @Override public void run() { if (dataStructure == null || dataType.equals(Utilities.DataType.UNK)) { throw new IllegalArgumentException("Object passed was not recognized."); } assemblies = new ArrayList<>(); propertyList = new ArrayList<>(); switch (dataType) { case BIOJAVA: Structure struct = (Structure) dataStructure; String name = struct.getPDBCode(); CompositeConfiguration properties = Keyword.loadProperties(file); MolecularAssembly assembly = new MolecularAssembly(name); assembly.setFile(file); ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties); ForceField forceField = forceFieldFilter.parse(); assembly.setForceField(forceField); BiojavaFilter filter = new BiojavaFilter(struct, assembly, forceField, properties); if (filter.convert()) { filter.applyAtomProperties(); assembly.finalize(true, forceField); ForceFieldEnergy energy = new ForceFieldEnergy(assembly, filter.getCoordRestraints()); assembly.setPotential(energy); assemblies.add(assembly); propertyList.add(properties); List<Character> altLocs = filter.getAltLocs(); if (altLocs.size() > 1 || altLocs.get(0) != ' ') { StringBuilder altLocString = new StringBuilder("\n Alternate locations found [ "); for (Character c : altLocs) { // Do not report the root conformer. if (c == ' ') { continue; } altLocString.append(format("(%s) ", c)); } altLocString.append("]\n"); logger.info(altLocString.toString()); } /** * Alternate conformers may have different chemistry, so * they each need to be their own MolecularAssembly. */ for (Character c : altLocs) { if (c.equals(' ') || c.equals('A')) { continue; } MolecularAssembly newAssembly = new MolecularAssembly(name); newAssembly.setForceField(assembly.getForceField()); filter.setAltID(newAssembly, c); filter.clearSegIDs(); if (filter.convert()) { String fileName = assembly.getFile().getAbsolutePath(); newAssembly.setName(FilenameUtils.getBaseName(fileName) + " " + c); filter.applyAtomProperties(); newAssembly.finalize(true, assembly.getForceField()); energy = new ForceFieldEnergy(newAssembly, filter.getCoordRestraints()); newAssembly.setPotential(energy); assemblies.add(newAssembly); properties.addConfiguration(properties); } } } else { logger.warning(String.format(" Failed to convert structure %s", dataStructure.toString())); } activeAssembly = assembly; activeProperties = properties; break; case UNK: default: throw new IllegalArgumentException("Object passed was not recognized."); } }
From source file:ninja.i18n.MessagesImpl.java
/** * Does all the loading of message files. * // ww w . j a v a 2 s. c o m * Only registered messages in application.conf are loaded. * */ private Map<String, Configuration> loadAllMessageFilesForRegisteredLanguages() { Map<String, Configuration> langToKeyAndValuesMappingMutable = Maps.newHashMap(); // Load default messages: Configuration defaultLanguage = loadLanguageConfiguration("conf/messages.properties"); // Make sure we got the file. // Everything else does not make much sense. if (defaultLanguage == null) { throw new RuntimeException( "Did not find conf/messages.properties. Please add a default language file."); } else { langToKeyAndValuesMappingMutable.put("", defaultLanguage); } // Get the languages from the application configuration. String[] applicationLangs = ninjaProperties.getStringArray(NinjaConstant.applicationLanguages); // If we don't have any languages declared we just return. // We'll use the default messages.properties file. if (applicationLangs == null) { return ImmutableMap.copyOf(langToKeyAndValuesMappingMutable); } // Load each language into the HashMap containing the languages: for (String lang : applicationLangs) { // First step: Load complete language eg. en-US Configuration configuration = loadLanguageConfiguration( String.format("conf/messages_%s.properties", lang)); Configuration configurationLangOnly = null; // If the language has a country code load the default values for // the language, too. For instance missing variables in en-US will // be // Overwritten by the default languages. if (lang.contains("-")) { // get the lang String langOnly = lang.split("-")[0]; // And load the configuraion configurationLangOnly = loadLanguageConfiguration( String.format("conf/messages_%s.properties", langOnly)); } // This is strange. If you defined the language in application.conf // it should be there propably. if (configuration == null) { logger.info( "Did not find conf/messages_{}.properties but it was specified in application.conf. Using default language instead.", lang); } else { // add new language, but combine with default language if stuff // is missing... CompositeConfiguration compositeConfiguration = new CompositeConfiguration(); // Add eg. "en-US" compositeConfiguration.addConfiguration(configuration); // Add eg. "en" if (configurationLangOnly != null) { compositeConfiguration.addConfiguration(configurationLangOnly); } // Add messages.conf (default pack) compositeConfiguration.addConfiguration(defaultLanguage); // and add the composed configuration to the hashmap with the // mapping. langToKeyAndValuesMappingMutable.put(lang, (Configuration) compositeConfiguration); } } return ImmutableMap.copyOf(langToKeyAndValuesMappingMutable); }
From source file:org.apache.accumulo.core.conf.SiteConfiguration.java
@SuppressFBWarnings(value = "URLCONNECTION_SSRF_FD", justification = "location of props is specified by an admin") private static ImmutableMap<String, String> createMap(URL accumuloPropsLocation, Map<String, String> overrides) { CompositeConfiguration config = new CompositeConfiguration(); config.setThrowExceptionOnMissing(false); config.setDelimiterParsingDisabled(true); PropertiesConfiguration propsConfig = new PropertiesConfiguration(); propsConfig.setDelimiterParsingDisabled(true); if (accumuloPropsLocation != null) { try {/*from w w w.j a v a 2 s. co m*/ propsConfig.load(accumuloPropsLocation.openStream()); } catch (IOException | ConfigurationException e) { throw new IllegalArgumentException(e); } } config.addConfiguration(propsConfig); // Add all properties in config file Map<String, String> result = new HashMap<>(); config.getKeys().forEachRemaining(key -> result.put(key, config.getString(key))); // Add all overrides overrides.forEach(result::put); // Add sensitive properties from credential provider (if set) String credProvider = result.get(Property.GENERAL_SECURITY_CREDENTIAL_PROVIDER_PATHS.getKey()); if (credProvider != null) { org.apache.hadoop.conf.Configuration hadoopConf = new org.apache.hadoop.conf.Configuration(); hadoopConf.set(CredentialProviderFactoryShim.CREDENTIAL_PROVIDER_PATH, credProvider); for (Property property : Property.values()) { if (property.isSensitive()) { char[] value = CredentialProviderFactoryShim.getValueFromCredentialProvider(hadoopConf, property.getKey()); if (value != null) { result.put(property.getKey(), new String(value)); } } } } return ImmutableMap.copyOf(result); }
From source file:org.apache.airavata.gfac.hadoop.handler.HadoopDeploymentHandler.java
private ClusterSpec whirrConfigurationToClusterSpec(HostDescription hostDescription, File workingDirectory) throws IOException, GFacHandlerException, ConfigurationException { File whirrConfig = getWhirrConfigurationFile(hostDescription, workingDirectory); CompositeConfiguration compositeConfiguration = new CompositeConfiguration(); Configuration configuration = new PropertiesConfiguration(whirrConfig); compositeConfiguration.addConfiguration(configuration); ClusterSpec hadoopClusterSpec = new ClusterSpec(compositeConfiguration); for (ClusterSpec.Property required : EnumSet.of(CLUSTER_NAME, PROVIDER, IDENTITY, CREDENTIAL, INSTANCE_TEMPLATES, PRIVATE_KEY_FILE)) { if (hadoopClusterSpec.getConfiguration().getString(required.getConfigName()) == null) { throw new IllegalArgumentException(String.format("Option '%s' not set.", required.getSimpleName())); }/*from ww w . j a v a 2 s.co m*/ } return hadoopClusterSpec; }
From source file:org.apache.bookkeeper.bookie.BookieShell.java
public static void main(String argv[]) throws Exception { BookieShell shell = new BookieShell(); if (argv.length <= 0) { shell.printShellUsage();/* ww w . j a v a 2s.c o m*/ System.exit(-1); } CompositeConfiguration conf = new CompositeConfiguration(); // load configuration if ("-conf".equals(argv[0])) { if (argv.length <= 1) { shell.printShellUsage(); System.exit(-1); } conf.addConfiguration(new PropertiesConfiguration(new File(argv[1]).toURI().toURL())); String[] newArgv = new String[argv.length - 2]; System.arraycopy(argv, 2, newArgv, 0, newArgv.length); argv = newArgv; } shell.setConf(conf); int res = shell.run(argv); System.exit(res); }
From source file:org.apache.bookkeeper.stream.cluster.StandaloneStarter.java
static int doMain(String[] args) throws Exception { StarterArgs starterArgs = new StarterArgs(); JCommander commander = new JCommander(); try {/*w ww . j a v a 2s.c o m*/ commander.setProgramName("standalone-starter"); commander.addObject(starterArgs); commander.parse(args); if (starterArgs.help) { commander.usage(); return 0; } } catch (Exception e) { commander.usage(); return -1; } StreamClusterSpec.StreamClusterSpecBuilder specBuilder = StreamClusterSpec.builder(); if (starterArgs.metadataServiceUri == null) { specBuilder = specBuilder.zkPort(starterArgs.zkPort).shouldStartZooKeeper(true); } else { ServiceURI serviceURI = ServiceURI.create(starterArgs.metadataServiceUri); specBuilder = specBuilder.metadataServiceUri(serviceURI).shouldStartZooKeeper(false); } CompositeConfiguration conf = new CompositeConfiguration(); if (null != starterArgs.configFile) { PropertiesConfiguration propsConf = new PropertiesConfiguration(starterArgs.configFile); conf.addConfiguration(propsConf); } checkArgument(starterArgs.numBookies > 0, "Invalid number of bookies : " + starterArgs.numBookies); if (starterArgs.numBookies == 1) { conf.setProperty("dlog.bkcEnsembleSize", 1); conf.setProperty("dlog.bkcWriteQuorumSize", 1); conf.setProperty("dlog.bkcAckQuorumSize", 1); } else { conf.setProperty("dlog.bkcEnsembleSize", starterArgs.numBookies); conf.setProperty("dlog.bkcWriteQuorumSize", starterArgs.numBookies); conf.setProperty("dlog.bkcAckQuorumSize", starterArgs.numBookies - 1); } StreamClusterSpec spec = specBuilder.baseConf(conf).numServers(starterArgs.numBookies) .initialBookiePort(starterArgs.initialBookiePort).initialGrpcPort(starterArgs.initialBookieGrpcPort) .storageRootDir(new File(starterArgs.dataDir)).build(); CountDownLatch liveLatch = new CountDownLatch(1); StreamCluster cluster = StreamCluster.build(spec); Runtime.getRuntime().addShutdownHook(new Thread(() -> { cluster.stop(); cluster.close(); liveLatch.countDown(); }, "Standalone-Shutdown-Thread")); cluster.start(); try { liveLatch.await(); } catch (InterruptedException e) { log.error("The standalone cluster is interrupted : ", e); } return 0; }
From source file:org.apache.bookkeeper.stream.server.StorageServer.java
private static void loadConfFile(CompositeConfiguration conf, String confFile) throws IllegalArgumentException { try {/*from w ww. java2 s . c om*/ Configuration loadedConf = new PropertiesConfiguration(new File(confFile).toURI().toURL()); conf.addConfiguration(loadedConf); } catch (MalformedURLException e) { log.error("Could not open configuration file {}", confFile, e); throw new IllegalArgumentException("Could not open configuration file " + confFile, e); } catch (ConfigurationException e) { log.error("Malformed configuration file {}", confFile, e); throw new IllegalArgumentException("Malformed configuration file " + confFile, e); } log.info("Loaded configuration file {}", confFile); }
From source file:org.apache.bookkeeper.tools.common.BKCommand.java
protected boolean apply(BKFlags bkFlags, CommandFlagsT cmdFlags) { ServiceURI serviceURI = null;//from w w w . jav a 2 s . c o m if (null != bkFlags.serviceUri) { serviceURI = ServiceURI.create(bkFlags.serviceUri); if (!acceptServiceUri(serviceURI)) { log.error("Unresolvable service uri by command '{}' : {}", path(), bkFlags.serviceUri); return false; } } CompositeConfiguration conf = new CompositeConfiguration(); if (!Strings.isNullOrEmpty(bkFlags.configFile)) { try { URL configFileUrl = Paths.get(bkFlags.configFile).toUri().toURL(); PropertiesConfiguration loadedConf = new PropertiesConfiguration(configFileUrl); conf.addConfiguration(loadedConf); } catch (MalformedURLException e) { log.error("Could not open configuration file : {}", bkFlags.configFile, e); throw new IllegalArgumentException(e); } catch (ConfigurationException e) { log.error("Malformed configuration file : {}", bkFlags.configFile, e); throw new IllegalArgumentException(e); } } return apply(serviceURI, conf, bkFlags, cmdFlags); }
From source file:org.apache.falcon.regression.core.util.Config.java
private void initConfig(String propFileName) throws ConfigurationException { CompositeConfiguration compositeConfiguration = new CompositeConfiguration(); LOGGER.info("Going to add properties from system properties."); compositeConfiguration.addConfiguration(new SystemConfiguration()); LOGGER.info("Going to read properties from: " + propFileName); final PropertiesConfiguration merlinConfig = new PropertiesConfiguration( Config.class.getResource("/" + propFileName)); //if changed configuration will be reloaded within 2 min final FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy(); reloadingStrategy.setRefreshDelay(2 * 60 * 1000); merlinConfig.setReloadingStrategy(reloadingStrategy); compositeConfiguration.addConfiguration(merlinConfig); this.confObj = compositeConfiguration; }
From source file:org.apache.juddi.config.AppConfig.java
/** * Does the actual work of reading the configuration from System * Properties and/or juddiv3.properties file. When the juddiv3.properties * file is updated the file will be reloaded. By default the reloadDelay is * set to 1 second to prevent excessive date stamp checking. *///from w w w .j a v a 2s .c o m private void loadConfiguration() throws ConfigurationException { //Properties from system properties CompositeConfiguration compositeConfig = new CompositeConfiguration(); compositeConfig.addConfiguration(new SystemConfiguration()); //Properties from file //changed 7-19-2013 AO for JUDDI-627 XMLConfiguration propConfig = null; final String filename = System.getProperty(JUDDI_CONFIGURATION_FILE_SYSTEM_PROPERTY); if (filename != null) { propConfig = new XMLConfiguration(filename); try { loadedFrom = new File(filename).toURI().toURL(); // propConfig = new PropertiesConfiguration(filename); } catch (MalformedURLException ex) { try { loadedFrom = new URL("file://" + filename); } catch (MalformedURLException ex1) { log.warn("unable to get an absolute path to " + filename + ". This may be ignorable if everything works properly.", ex1); } } } else { //propConfig = new PropertiesConfiguration(JUDDI_PROPERTIES); propConfig = new XMLConfiguration(JUDDI_PROPERTIES); loadedFrom = ClassUtil.getResource(JUDDI_PROPERTIES, this.getClass()); } //Hey! this may break things propConfig.setAutoSave(true); log.info("Reading from properties file: " + loadedFrom); long refreshDelay = propConfig.getLong(Property.JUDDI_CONFIGURATION_RELOAD_DELAY, 1000l); log.debug("Setting refreshDelay to " + refreshDelay); FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileChangedReloadingStrategy(); fileChangedReloadingStrategy.setRefreshDelay(refreshDelay); propConfig.setReloadingStrategy(fileChangedReloadingStrategy); compositeConfig.addConfiguration(propConfig); Properties properties = new Properties(); if ("Hibernate".equals(propConfig.getString(Property.PERSISTENCE_PROVIDER))) { if (propConfig.containsKey(Property.DATASOURCE)) properties.put("hibernate.connection.datasource", propConfig.getString(Property.DATASOURCE)); if (propConfig.containsKey(Property.HBM_DDL_AUTO)) properties.put("hibernate.hbm2ddl.auto", propConfig.getString(Property.HBM_DDL_AUTO)); if (propConfig.containsKey(Property.DEFAULT_SCHEMA)) properties.put("hibernate.default_schema", propConfig.getString(Property.DEFAULT_SCHEMA)); if (propConfig.containsKey(Property.HIBERNATE_DIALECT)) properties.put("hibernate.dialect", propConfig.getString(Property.HIBERNATE_DIALECT)); } // initialize the entityManagerFactory. PersistenceManager.initializeEntityManagerFactory(propConfig.getString(Property.JUDDI_PERSISTENCEUNIT_NAME), properties); // Properties from the persistence layer MapConfiguration persistentConfig = new MapConfiguration(getPersistentConfiguration(compositeConfig)); compositeConfig.addConfiguration(persistentConfig); //Making the new configuration globally accessible. config = compositeConfig; }