List of usage examples for org.apache.commons.configuration PropertiesConfiguration PropertiesConfiguration
public PropertiesConfiguration(URL url) throws ConfigurationException
From source file:com.liferay.portal.configuration.easyconf.ClassLoaderAggregateProperties.java
private Configuration _addFileProperties(String fileName, CompositeConfiguration loadedCompositeConfiguration) throws ConfigurationException { try {//from ww w. j ava2s . com FileConfiguration newFileConfiguration = new PropertiesConfiguration(fileName); URL url = newFileConfiguration.getURL(); if (_log.isDebugEnabled()) { _log.debug("Adding file " + url); } Long delay = _getReloadDelay(loadedCompositeConfiguration, newFileConfiguration); if (delay != null) { FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileConfigurationChangedReloadingStrategy(); if (_log.isDebugEnabled()) { _log.debug("File " + url + " will be reloaded every " + delay + " seconds"); } long milliseconds = delay.longValue() * 1000; fileChangedReloadingStrategy.setRefreshDelay(milliseconds); newFileConfiguration.setReloadingStrategy(fileChangedReloadingStrategy); } _addIncludedPropertiesSources(newFileConfiguration, loadedCompositeConfiguration); return newFileConfiguration; } catch (org.apache.commons.configuration.ConfigurationException ce) { if (_log.isDebugEnabled()) { _log.debug("Configuration source " + fileName + " ignored"); } return null; } }
From source file:com.impetus.ankush.agent.action.impl.PropertyFileManipulator.java
/** * Read conf value.//w ww . j av a 2 s . c om * * @param file * the file * @param propertyName * the property name * @return the string */ @Override public String readConfValue(String file, String propertyName) { String confValue = null; try { // read conf file File confFile = new File(file); if (!confFile.exists()) { System.err.println("File " + file + " does not exists."); return confValue; } PropertiesConfiguration props = new PropertiesConfiguration(file); confValue = props.getProperty(propertyName).toString(); } catch (Exception e) { System.err.println(e.getMessage()); } return confValue; }
From source file:com.linkedin.pinot.tools.admin.command.AbstractBaseAdminCommand.java
PropertiesConfiguration readConfigFromFile(String configFileName) throws ConfigurationException { if (configFileName != null) { File configFile = new File(configFileName); if (configFile.exists()) { return new PropertiesConfiguration(configFile); } else {// w ww . j a va 2 s .c om return null; } } else { return null; } }
From source file:eu.artist.methodology.mpt.webapp.config.ListFileHandlerBean.java
public void save() throws IOException { String path_to_properties_file = getMptProperties().getProperty("path_to_reports") + "\\" + CurrentSession.getUserName() + "\\mpt" + CurrentSession.getUserName() + ".properties"; checkPropertiesFile(path_to_properties_file); logger.debug("Path to properties file is " + path_to_properties_file); try {/*from w w w .ja va2s .c om*/ File f = new File(path_to_properties_file); URL url = f.toURI().toURL(); logger.debug("File URL is " + url.toString()); logger.info("Configuration saved"); logger.debug("Selected file is " + selectedFile); PropertiesConfiguration config = new PropertiesConfiguration(url); String chosenButton = CurrentSession.getExternalContext().getRequestParameterMap().get("button"); String propertyToSet = null; if ("mat".equalsIgnoreCase(chosenButton)) { propertyToSet = "mat_report"; } else if ("tft".equalsIgnoreCase(chosenButton)) { propertyToSet = "tft_report"; } else if ("bft".equalsIgnoreCase(chosenButton)) { propertyToSet = "bft_report"; } else if ("mig".equalsIgnoreCase(chosenButton)) { propertyToSet = "mig_report"; } config.setProperty(propertyToSet, "\\" + selectedFile); config.save(); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Configuration saved")); } catch (Exception e) { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Configuration failed")); logger.error("Configuration not saved"); e.printStackTrace(); } }
From source file:eu.tango.energymodeller.datastore.DefaultDatabaseConnector.java
/** * This reads the settings for the database connection from file. *//*from w ww . j a va 2 s . c o m*/ protected final void loadSettings() { try { PropertiesConfiguration config; if (new File(CONFIG_FILE).exists()) { config = new PropertiesConfiguration(CONFIG_FILE); } else { config = new PropertiesConfiguration(); config.setFile(new File(CONFIG_FILE)); } config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting. databaseURL = config.getString("energy.modeller.db.url", databaseURL); config.setProperty("energy.modeller.db.url", databaseURL); databaseDriver = config.getString("energy.modeller.db.driver", databaseDriver); try { Class.forName(databaseDriver); } catch (ClassNotFoundException ex) { //If the driver is not found on the class path revert to mysql connector. databaseDriver = "com.mysql.jdbc.Driver"; } config.setProperty("energy.modeller.db.driver", databaseDriver); databasePassword = config.getString("energy.modeller.db.password", ""); config.setProperty("energy.modeller.db.password", databasePassword); databaseUser = config.getString("energy.modeller.db.user", databaseUser); config.setProperty("energy.modeller.db.user", databaseUser); } catch (ConfigurationException ex) { Logger.getLogger(DefaultDatabaseConnector.class.getName()).log(Level.INFO, "Error loading database configuration information", ex); } }
From source file:com.linkedin.pinot.core.minion.RawIndexConverter.java
/** * NOTE: original segment should be in V1 format. * TODO: support V3 format/*from w w w. j a va 2 s . c o m*/ */ public RawIndexConverter(@Nonnull File originalIndexDir, @Nonnull File convertedIndexDir, @Nullable String columnsToConvert) throws Exception { FileUtils.copyDirectory(originalIndexDir, convertedIndexDir); IndexLoadingConfig indexLoadingConfig = new IndexLoadingConfig(); indexLoadingConfig.setSegmentVersion(SegmentVersion.v1); indexLoadingConfig.setReadMode(ReadMode.mmap); _originalIndexSegment = ColumnarSegmentLoader.load(originalIndexDir, indexLoadingConfig); _originalSegmentMetadata = (SegmentMetadataImpl) _originalIndexSegment.getSegmentMetadata(); _convertedIndexDir = convertedIndexDir; _convertedProperties = new PropertiesConfiguration( new File(_convertedIndexDir, V1Constants.MetadataKeys.METADATA_FILE_NAME)); _columnsToConvert = columnsToConvert; }
From source file:es.bsc.demiurge.core.configuration.Config.java
/** * Returns a properties file that contains the configuration parameters for the VM Manager. * * @return the properties file//from w w w . j av a 2 s . c o m */ private Configuration getPropertiesObjectFromConfigFile() { Logger log = LogManager.getLogger(Config.class); try { Configuration embeddedConfig = null; URL embeddedConfigURL = Configuration.class.getResource(DEFAULT_CONF_CLASSPATH_LOCATION); if (embeddedConfigURL != null) { try { embeddedConfig = new PropertiesConfiguration(embeddedConfigURL); } catch (ConfigurationException e) { log.warn("Error processing embedded config file", e); } } // TO ALLOW COMPATIBILITY WITH OLDER VERSIONS OF VMM (Ascetic_exclusive) // If there is a config file in the newest default location, looks for it // if not, it looks in the old Ascetic default location String defaultFileName = OLD_ASCETIC_DEFAULT_CONF_FILE_LOCATION; if (new File(DEFAULT_CONF_FILE_LOCATION).exists()) { defaultFileName = DEFAULT_CONF_FILE_LOCATION; } configurationFileName = System.getProperty(PROPNAME_CONF_FILE, defaultFileName); log.debug("Loading configuration file: " + configurationFileName); Configuration fileConfig = null; if (new File(configurationFileName).exists()) { fileConfig = new PropertiesConfiguration(configurationFileName); } if (embeddedConfig == null) { if (fileConfig == null) { throw new IllegalStateException("No configuration found at " + configurationFileName); } return fileConfig; } else { CompositeConfiguration compositeConfiguration = new CompositeConfiguration(); if (fileConfig != null) { compositeConfiguration.addConfiguration(fileConfig); } compositeConfiguration.addConfiguration(embeddedConfig); return compositeConfiguration; } } catch (ConfigurationException e) { log.error("Error loading properties file", e); e.printStackTrace(); } return null; }
From source file:com.opensoc.topology.runner.TopologyRunner.java
public void initTopology(String args[], String subdir) throws Exception { Cli command_line = new Cli(args); command_line.parse();// w w w. j av a 2 s. com System.out.println("[OpenSOC] Starting topology deployment..."); debug = command_line.isDebug(); System.out.println("[OpenSOC] Debug mode set to: " + debug); local_mode = command_line.isLocal_mode(); System.out.println("[OpenSOC] Local mode set to: " + local_mode); if (command_line.getPath() != null) { config_path = command_line.getPath(); System.out.println("[OpenSOC] Setting config path to external config path: " + config_path); } else { config_path = default_config_path; System.out.println("[OpenSOC] Initializing from default internal config path: " + config_path); } String topology_conf_path = config_path + "/topologies/" + subdir + "/topology.conf"; String environment_identifier_path = config_path + "/topologies/environment_identifier.conf"; String topology_identifier_path = config_path + "/topologies/" + subdir + "/topology_identifier.conf"; System.out.println("[OpenSOC] Looking for environment identifier: " + environment_identifier_path); System.out.println("[OpenSOC] Looking for topology identifier: " + topology_identifier_path); System.out.println("[OpenSOC] Looking for topology config: " + topology_conf_path); config = new PropertiesConfiguration(topology_conf_path); JSONObject environment_identifier = SettingsLoader.loadEnvironmentIdnetifier(environment_identifier_path); JSONObject topology_identifier = SettingsLoader.loadTopologyIdnetifier(topology_identifier_path); String topology_name = SettingsLoader.generateTopologyName(environment_identifier, topology_identifier); System.out.println("[OpenSOC] Initializing Topology: " + topology_name); builder = new TopologyBuilder(); conf = new Config(); conf.registerSerialization(JSONObject.class, MapSerializer.class); conf.setDebug(debug); System.out.println("[OpenSOC] Initializing Spout: " + topology_name); if (command_line.isGenerator_spout()) { String component_name = config.getString("spout.test.name", "DefaultTopologySpout"); success = initializeTestingSpout(component_name); messageComponents.add(component_name); System.out.println( "[OpenSOC] ------Component " + component_name + " initialized with the following settings:"); SettingsLoader.printConfigOptions((PropertiesConfiguration) config, "spout.test"); } if (!command_line.isGenerator_spout()) { String component_name = config.getString("spout.kafka.name", "DefaultTopologyKafkaSpout"); success = initializeKafkaSpout(component_name); messageComponents.add(component_name); System.out.println( "[OpenSOC] ------Component " + component_name + " initialized with the following settings:"); SettingsLoader.printConfigOptions((PropertiesConfiguration) config, "spout.kafka"); } if (config.getBoolean("bolt.parser.enabled", true)) { String component_name = config.getString("bolt.parser.name", "DefaultTopologyParserBot"); success = initializeParsingBolt(topology_name, component_name); messageComponents.add(component_name); errorComponents.add(component_name); dataComponents.add(component_name); System.out.println( "[OpenSOC] ------Component " + component_name + " initialized with the following settings:"); SettingsLoader.printConfigOptions((PropertiesConfiguration) config, "bolt.parser"); } if (config.getBoolean("bolt.enrichment.geo.enabled", false)) { String component_name = config.getString("bolt.enrichment.geo.name", "DefaultGeoEnrichmentBolt"); success = initializeGeoEnrichment(topology_name, component_name); messageComponents.add(component_name); errorComponents.add(component_name); System.out.println( "[OpenSOC] ------Component " + component_name + " initialized with the following settings:"); SettingsLoader.printConfigOptions((PropertiesConfiguration) config, "bolt.enrichment.geo"); SettingsLoader.printConfigOptions((PropertiesConfiguration) config, "mysql"); } if (config.getBoolean("bolt.enrichment.host.enabled", false)) { String component_name = config.getString("bolt.enrichment.host.name", "DefaultHostEnrichmentBolt"); success = initializeHostsEnrichment(topology_name, component_name, "OpenSOC_Configs/etc/whitelists/known_hosts.conf"); messageComponents.add(component_name); errorComponents.add(component_name); System.out.println( "[OpenSOC] ------Component " + component_name + " initialized with the following settings:"); SettingsLoader.printConfigOptions((PropertiesConfiguration) config, "bolt.enrichment.host"); } if (config.getBoolean("bolt.enrichment.whois.enabled", false)) { String component_name = config.getString("bolt.enrichment.whois.name", "DefaultWhoisEnrichmentBolt"); success = initializeWhoisEnrichment(topology_name, component_name); messageComponents.add(component_name); errorComponents.add(component_name); System.out.println( "[OpenSOC] ------Component " + component_name + " initialized with the following settings:"); SettingsLoader.printConfigOptions((PropertiesConfiguration) config, "bolt.enrichment.whois"); } if (config.getBoolean("bolt.enrichment.cif.enabled", false)) { String component_name = config.getString("bolt.enrichment.cif.name", "DefaultCIFEnrichmentBolt"); success = initializeCIFEnrichment(topology_name, component_name); messageComponents.add(component_name); errorComponents.add(component_name); System.out.println( "[OpenSOC] ------Component " + component_name + " initialized with the following settings:"); SettingsLoader.printConfigOptions((PropertiesConfiguration) config, "bolt.enrichment.cif"); } if (config.getBoolean("bolt.enrichment.threat.enabled", false)) { String component_name = config.getString("bolt.enrichment.threat.name", "DefaultThreatEnrichmentBolt"); success = initializeThreatEnrichment(topology_name, component_name); messageComponents.add(component_name); errorComponents.add(component_name); System.out.println( "[OpenSOC] ------Component " + component_name + " initialized with the following settings:"); SettingsLoader.printConfigOptions((PropertiesConfiguration) config, "bolt.enrichment.threat"); } if (config.getBoolean("bolt.alerts.enabled", false)) { String component_name = config.getString("bolt.alerts.name", "DefaultAlertsBolt"); success = initializeAlerts(topology_name, component_name, config_path + "/topologies/" + subdir + "/alerts.xml", environment_identifier, topology_identifier); messageComponents.add(component_name); errorComponents.add(component_name); alertComponents.add(component_name); System.out.println( "[OpenSOC] ------Component " + component_name + " initialized with the following settings:"); SettingsLoader.printConfigOptions((PropertiesConfiguration) config, "bolt.alerts"); } if (config.getBoolean("bolt.alerts.indexing.enabled") && config.getBoolean("bolt.alerts.enabled")) { String component_name = config.getString("bolt.alerts.indexing.name", "DefaultAlertsBolt"); success = initializeAlertIndexing(component_name); terminalComponents.add(component_name); System.out.println( "[OpenSOC] ------Component " + component_name + " initialized with the following settings:"); SettingsLoader.printConfigOptions((PropertiesConfiguration) config, "bolt.alerts.indexing"); } if (config.getBoolean("bolt.kafka.enabled", false)) { String component_name = config.getString("bolt.kafka.name", "DefaultKafkaBolt"); success = initializeKafkaBolt(component_name); terminalComponents.add(component_name); System.out.println("[OpenSOC] Component " + component_name + " initialized"); System.out.println( "[OpenSOC] ------Component " + component_name + " initialized with the following settings:"); SettingsLoader.printConfigOptions((PropertiesConfiguration) config, "bolt.kafka"); } if (config.getBoolean("bolt.indexing.enabled", true)) { String component_name = config.getString("bolt.indexing.name", "DefaultIndexingBolt"); success = initializeIndexingBolt(component_name); errorComponents.add(component_name); terminalComponents.add(component_name); System.out.println( "[OpenSOC] ------Component " + component_name + " initialized with the following settings:"); SettingsLoader.printConfigOptions((PropertiesConfiguration) config, "bolt.indexing"); } if (config.getBoolean("bolt.hdfs.enabled", false)) { String component_name = config.getString("bolt.hdfs.name", "DefaultHDFSBolt"); success = initializeHDFSBolt(topology_name, component_name); terminalComponents.add(component_name); System.out.println( "[OpenSOC] ------Component " + component_name + " initialized with the following settings:"); SettingsLoader.printConfigOptions((PropertiesConfiguration) config, "bolt.hdfs"); } if (config.getBoolean("bolt.error.indexing.enabled")) { String component_name = config.getString("bolt.error.indexing.name", "DefaultErrorIndexingBolt"); success = initializeErrorIndexBolt(component_name); terminalComponents.add(component_name); System.out.println( "[OpenSOC] ------Component " + component_name + " initialized with the following settings:"); SettingsLoader.printConfigOptions((PropertiesConfiguration) config, "bolt.error"); } if (config.containsKey("bolt.hbase.enabled") && config.getBoolean("bolt.hbase.enabled")) { String component_name = config.getString("bolt.hbase.name", "DefaultHbaseBolt"); String shuffleType = config.getString("bolt.hbase.shuffle.type", "direct"); success = initializeHbaseBolt(component_name, shuffleType); terminalComponents.add(component_name); System.out.println( "[OpenSOC] ------Component " + component_name + " initialized with the following settings:"); SettingsLoader.printConfigOptions((PropertiesConfiguration) config, "bolt.hbase"); } System.out.println("[OpenSOC] Topology Summary: "); System.out.println("[OpenSOC] Message Stream: " + printComponentStream(messageComponents)); System.out.println("[OpenSOC] Alerts Stream: " + printComponentStream(alertComponents)); System.out.println("[OpenSOC] Error Stream: " + printComponentStream(errorComponents)); System.out.println("[OpenSOC] Data Stream: " + printComponentStream(dataComponents)); System.out.println("[OpenSOC] Terminal Components: " + printComponentStream(terminalComponents)); if (local_mode) { conf.setNumWorkers(config.getInt("num.workers")); conf.setMaxTaskParallelism(1); LocalCluster cluster = new LocalCluster(); cluster.submitTopology(topology_name, conf, builder.createTopology()); } else { conf.setNumWorkers(config.getInt("num.workers")); conf.setNumAckers(config.getInt("num.ackers")); StormSubmitter.submitTopology(topology_name, conf, builder.createTopology()); } }