List of usage examples for org.apache.commons.configuration PropertiesConfiguration setFile
public void setFile(File file)
From source file:eu.tango.energymodeller.energypredictor.AbstractEnergyPredictor.java
/** * This creates a new abstract energy predictor. * * It will create a energy-modeller-predictor properties file if it doesn't * exist./*from w ww. ja va 2 s . c o m*/ * * The main property: energy.modeller.energy.predictor.cpu.default_load * should be in the range 0..1 or -1. This indicates the predictor's default * assumption on how much load is been induced. -1 measures the CPU's * current load and uses that to forecast into the future. * * In the case of using -1 as a parameter to additional parameters are used: * energy.modeller.energy.predictor.cpu.utilisation.observe_time.sec * energy.modeller.energy.predictor.cpu.utilisation.observe_time.min * * These indicate the window of how long the CPU should be monitored for, to * determine the current load. */ public AbstractEnergyPredictor() { 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. readSettings(config); } catch (ConfigurationException ex) { Logger.getLogger(CpuOnlyEnergyPredictor.class.getName()).log(Level.SEVERE, "Taking the default load from the settings file did not work", ex); } }
From source file:eu.ascetic.zabbixdatalogger.datasource.ZabbixDirectDbDataSourceAdaptor.java
/** * This creates a new database connector for use. It establishes a database * connection immediately ready for use. *//*w ww . jav a 2 s. c om*/ public ZabbixDirectDbDataSourceAdaptor() { HISTORY_TABLES.add("history"); HISTORY_TABLES.add("history_str"); HISTORY_TABLES.add("history_uint"); HISTORY_TABLES.add("history_text"); 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("data.logger.zabbix.db.url", databaseURL); config.setProperty("data.logger.zabbix.db.url", databaseURL); databaseDriver = config.getString("data.logger.zabbix.db.driver", databaseDriver); try { Class.forName(databaseDriver); } catch (ClassNotFoundException ex) { //If the driver is not found on the class path revert to MariaDB. databaseDriver = "org.mariadb.jdbc.Driver"; } config.setProperty("data.logger.zabbix.db.driver", databaseDriver); databasePassword = config.getString("data.logger.zabbix.db.password", databasePassword); config.setProperty("data.logger.zabbix.db.password", databasePassword); databaseUser = config.getString("data.logger.zabbix.db.user", databaseUser); config.setProperty("data.logger.zabbix.db.user", databaseUser); begins = config.getString("data.logger.filter.begins", begins); config.setProperty("data.logger.filter.begins", begins); isHost = config.getBoolean("data.logger.filter.isHost", isHost); config.setProperty("data.logger.filter.isHost", isHost); onlyAvailableHosts = config.getBoolean("data.logger.zabbix.only.available.hosts", onlyAvailableHosts); config.setProperty("data.logger.zabbix.only.available.hosts", onlyAvailableHosts); if (onlyAvailableHosts) { ALL_ZABBIX_HOSTS = ALL_ZABBIX_HOSTS + " AND h.available = 1"; } } catch (ConfigurationException ex) { DB_LOGGER.log(Level.SEVERE, "Error loading the configuration of the Zabbix data logger"); } try { connection = getConnection(); } catch (IOException | SQLException | ClassNotFoundException ex) { DB_LOGGER.log(Level.SEVERE, "Failed to establish the connection to the Zabbix DB", ex); } }
From source file:eu.tango.energymodeller.datasourceclient.ZabbixDirectDbDataSourceAdaptor.java
/** * This creates a new database connector for use. It establishes a database * connection immediately ready for use. *///w w w . j a v a 2s .co m public ZabbixDirectDbDataSourceAdaptor() { HISTORY_TABLES.add("history"); HISTORY_TABLES.add("history_str"); HISTORY_TABLES.add("history_uint"); HISTORY_TABLES.add("history_text"); 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.zabbix.db.url", "jdbc:mysql://<ADD_ZABBIX_DB_SERVER_ADDRESS_HERE>:3306/zabbix"); config.setProperty("energy.modeller.zabbix.db.url", databaseURL); databaseDriver = config.getString("energy.modeller.zabbix.db.driver", databaseDriver); try { Class.forName(databaseDriver); } catch (ClassNotFoundException ex) { //If the driver is not found on the class path revert to MariaDB. databaseDriver = "com.mysql.jdbc.Driver"; } config.setProperty("energy.modeller.zabbix.db.driver", databaseDriver); databasePassword = config.getString("energy.modeller.zabbix.db.password", ""); config.setProperty("energy.modeller.zabbix.db.password", databasePassword); databaseUser = config.getString("energy.modeller.zabbix.db.user", databaseUser); config.setProperty("energy.modeller.zabbix.db.user", databaseUser); vmGroup = config.getString("energy.modeller.vm.group", vmGroup); config.setProperty("energy.modeller.vm.group", vmGroup); hostGroup = config.getString("energy.modeller.host.group", hostGroup); config.setProperty("energy.modeller.host.group", hostGroup); generalPowerConsumer = config.getString("energy.modeller.dfs.group", generalPowerConsumer); config.setProperty("energy.modeller.dfs.group", generalPowerConsumer); onlyAvailableHosts = config.getBoolean("energy.zabbix.only.available.hosts", onlyAvailableHosts); config.setProperty("energy.zabbix.only.available.hosts", onlyAvailableHosts); if (onlyAvailableHosts) { allZabbixHosts = allZabbixHosts + " AND h.available = 1"; } } catch (ConfigurationException ex) { DB_LOGGER.log(Level.SEVERE, "Error loading the configuration of the IaaS energy modeller", ex); } try { connection = getConnection(); } catch (IOException | SQLException | ClassNotFoundException ex) { DB_LOGGER.log(Level.SEVERE, "Failed to establish the connection to the Zabbix DB", ex); } }
From source file:eu.tango.energymodeller.datastore.DataGatherer.java
/** * This creates a data gather component for the energy modeller. * * @param datasource The data source that provides information about the * host resources and the virtual machines running on them. * @param connector The database connector used to do this. It is best to * give this component its own database connection as it will make heavy use * of it./*from w w w.j a v a2 s . c om*/ */ public DataGatherer(HostDataSource datasource, DatabaseConnector connector) { this.datasource = datasource; this.database = connector; populateHostList(); 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. logVmsToDisk = config.getBoolean("energy.modeller.data.gatherer.log.vms", logVmsToDisk); config.setProperty("energy.modeller.data.gatherer.log.vms", logVmsToDisk); logAppsToDisk = config.getBoolean("energy.modeller.data.gatherer.log.apps", logAppsToDisk); config.setProperty("energy.modeller.data.gatherer.log.apps", logAppsToDisk); loggerOutputFile = config.getString("energy.modeller.data.gatherer.log.vms.filename", loggerOutputFile); config.setProperty("energy.modeller.data.gatherer.log.vms.filename", loggerOutputFile); loggerOutputFile = config.getString("energy.modeller.data.gatherer.log.apps.filename", appLoggerOutputFile); config.setProperty("energy.modeller.data.gatherer.log.apps.filename", appLoggerOutputFile); loggerConsiderIdleEnergy = config.getBoolean("energy.modeller.data.gatherer.log.consider_idle_energy", loggerConsiderIdleEnergy); config.setProperty("energy.modeller.data.gatherer.log.consider_idle_energy", loggerConsiderIdleEnergy); useWorkloadCache = config.getBoolean("energy.modeller.data.gatherer.log.use_workload_cache", useWorkloadCache); config.setProperty("energy.modeller.data.gatherer.log.use_workload_cache", useWorkloadCache); if (useWorkloadCache) { workloadCache = WorkloadStatisticsCache.getInstance(); workloadCache.setInUse(true); } } catch (ConfigurationException ex) { Logger.getLogger(DataGatherer.class.getName()).log(Level.INFO, "Error loading the configuration of the IaaS energy modeller", ex); } }
From source file:eu.tango.energymodeller.datastore.DefaultDatabaseConnector.java
/** * This reads the settings for the database connection from file. *//*w w w.j a v a 2 s .c om*/ 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:eu.tango.energymodeller.EnergyModeller.java
/** * This is common code for the constructors *//*from ww w .j a v a2 s .co m*/ private void startup(boolean performDataGathering) { try { if (datasource == null) { 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. String datasourceStr = config.getString("energy.modeller.datasource", "SlurmDataSourceAdaptor"); setDataSource(datasourceStr); config.setProperty("energy.modeller.datasource", datasourceStr); String predictorStr = config.getString("energy.modeller.predictor", "CpuAndAcceleratorEnergyPredictor"); setEnergyPredictor(predictorStr); config.setProperty("energy.modeller.predictor", predictorStr); if (!new File(CONFIG_FILE).exists()) { config.save(); } } } catch (ConfigurationException ex) { Logger.getLogger(EnergyModeller.class.getName()).log(Level.INFO, "Error loading the configuration of the energy modeller", ex); } dataGatherer = new DataGatherer(datasource, database); dataGatherer.setPerformDataGathering(performDataGathering); try { dataGatherThread = new Thread(dataGatherer); dataGatherThread.setDaemon(true); dataGatherThread.start(); } catch (Exception ex) { Logger.getLogger(EnergyModeller.class.getName()).log(Level.SEVERE, "The energry modeller failed to start correctly", ex); } }
From source file:org.apache.wookie.server.ContextListener.java
public void contextInitialized(ServletContextEvent event) { try {/*from w ww . ja va 2 s. c om*/ ServletContext context = event.getServletContext(); /* * load the widgetserver.properties file and put it into this context * as an attribute 'properties' available to all resources */ PropertiesConfiguration configuration; File localPropsFile = new File( System.getProperty("user.dir") + File.separator + "local.widgetserver.properties"); if (localPropsFile.exists()) { configuration = new PropertiesConfiguration(localPropsFile); _logger.info("Using local widget server properties file: " + localPropsFile.toString()); } else { configuration = new PropertiesConfiguration("widgetserver.properties"); configuration.setFile(localPropsFile); configuration.save(); _logger.info("Using default widget server properties, configure your local server using: " + localPropsFile.toString()); } context.setAttribute("properties", (Configuration) configuration); /* * Merge in system properties overrides */ Iterator<Object> systemKeysIter = System.getProperties().keySet().iterator(); while (systemKeysIter.hasNext()) { String key = systemKeysIter.next().toString(); if (configuration.containsKey(key) || key.startsWith("widget.")) { String setting = configuration.getString(key); String override = System.getProperty(key); if ((override != null) && (override.length() > 0) && !override.equals(setting)) { configuration.setProperty(key, override); if (setting != null) { _logger.info("Overridden server configuration property: " + key + "=" + override); } } } } /* * Initialize persistence manager factory now, not on first request */ PersistenceManagerFactory.initialize(configuration); /* * Initialise the locale handler */ LocaleHandler.getInstance().initialize(configuration); final Locale locale = new Locale(configuration.getString("widget.default.locale")); final Messages localizedMessages = LocaleHandler.getInstance().getResourceBundle(locale); /* * load the opensocial.properties file and put it into this context * as an attribute 'opensocial' available to all resources */ PropertiesConfiguration opensocialConfiguration; File localOpenSocialPropsFile = new File( System.getProperty("user.dir") + File.separator + "local.opensocial.properties"); if (localOpenSocialPropsFile.exists()) { opensocialConfiguration = new PropertiesConfiguration(localOpenSocialPropsFile); _logger.info("Using local open social properties file: " + localOpenSocialPropsFile.toString()); } else { opensocialConfiguration = new PropertiesConfiguration("opensocial.properties"); opensocialConfiguration.setFile(localOpenSocialPropsFile); opensocialConfiguration.save(); _logger.info("Using default open social properties, configure your local server using: " + localOpenSocialPropsFile.toString()); } context.setAttribute("opensocial", (Configuration) opensocialConfiguration); /* * Load installed features */ PropertiesConfiguration featuresConfiguration; File localFeaturesPropsFile = new File( System.getProperty("user.dir") + File.separator + "local.features.properties"); if (localFeaturesPropsFile.exists()) { featuresConfiguration = new PropertiesConfiguration(localFeaturesPropsFile); _logger.info("Loading local features file: " + localOpenSocialPropsFile.toString()); } else { featuresConfiguration = new PropertiesConfiguration("features.properties"); featuresConfiguration.setFile(localFeaturesPropsFile); featuresConfiguration.save(); _logger.info("Loading default features, configure your local server using: " + localFeaturesPropsFile.toString()); } FeatureLoader.loadFeatures(featuresConfiguration); /* * Run diagnostics */ Diagnostics.run(context, configuration); /* * Start hot-deploy widget watcher */ if (configuration.getBoolean("widget.hot_deploy")) { startWatcher(context, configuration, localizedMessages); } else { _logger.info(localizedMessages.getString("WidgetHotDeploy.0")); } } catch (ConfigurationException ex) { _logger.error("ConfigurationException thrown: " + ex.toString()); } }
From source file:org.freemedsoftware.shim.Configuration.java
/** * Load configuration from both template and override properties files. *//* w w w.j a v a2s . c o m*/ public static void loadConfiguration() { log.trace("Entered loadConfiguration"); if (servletContext == null) { log.error("servletContext not set!"); } if (compositeConfiguration == null) { log.info("Configuration object not present, instantiating"); compositeConfiguration = new CompositeConfiguration(); PropertiesConfiguration defaults = null; try { defaults = new PropertiesConfiguration( servletContext.getServletContext().getRealPath(DEFAULT_CONFIG)); log.info("Loading default configuration from " + servletContext.getServletContext().getRealPath(DEFAULT_CONFIG)); } catch (ConfigurationException e) { log.error("Could not load default configuration from " + servletContext.getServletContext().getRealPath(DEFAULT_CONFIG)); // e.printStackTrace(); } if (OVERRIDE_CONFIG != null) { PropertiesConfiguration overrides = null; try { overrides = new PropertiesConfiguration(); overrides.setFile(new File(OVERRIDE_CONFIG)); overrides.setReloadingStrategy(new FileChangedReloadingStrategy()); overrides.load(); } catch (ConfigurationException e) { log.info("Could not load overrides", e); } compositeConfiguration.addConfiguration(overrides); } // Afterwards, add defaults so they're read second. compositeConfiguration.addConfiguration(defaults); } }
From source file:org.wisdom.maven.utils.Properties2HoconConverterTest.java
public final PropertiesConfiguration loadPropertiesWithApacheConfiguration(File file) { PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); propertiesConfiguration.setEncoding("utf-8"); propertiesConfiguration.setDelimiterParsingDisabled(true); propertiesConfiguration.setFile(file); propertiesConfiguration.setListDelimiter(','); propertiesConfiguration.getLayout().setSingleLine("application.secret", true); try {/*from w w w .j a v a2 s . co m*/ propertiesConfiguration.load(file); } catch (ConfigurationException e) { return null; } return propertiesConfiguration; }
From source file:pl.otros.vfs.browser.demo.TestBrowser.java
public static void main(final String[] args) throws InterruptedException, InvocationTargetException, SecurityException, IOException { if (args.length > 1) throw new IllegalArgumentException( "SYNTAX: java... " + TestBrowser.class.getName() + " [initialPath]"); SwingUtilities.invokeAndWait(new Runnable() { @Override//w w w . ja va 2 s . c om public void run() { tryLoadSubstanceLookAndFeel(); final JFrame f = new JFrame("OtrosVfsBrowser demo"); Container contentPane = f.getContentPane(); contentPane.setLayout(new BorderLayout()); DataConfiguration dc = null; final PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); File favoritesFile = new File("favorites.properties"); propertiesConfiguration.setFile(favoritesFile); if (favoritesFile.exists()) { try { propertiesConfiguration.load(); } catch (ConfigurationException e) { e.printStackTrace(); } } dc = new DataConfiguration(propertiesConfiguration); propertiesConfiguration.setAutoSave(true); final VfsBrowser comp = new VfsBrowser(dc, (args.length > 0) ? args[0] : null); comp.setSelectionMode(SelectionMode.FILES_ONLY); comp.setMultiSelectionEnabled(true); comp.setApproveAction(new AbstractAction(Messages.getMessage("demo.showContentButton")) { @Override public void actionPerformed(ActionEvent e) { FileObject[] selectedFiles = comp.getSelectedFiles(); System.out.println("Selected files count=" + selectedFiles.length); for (FileObject selectedFile : selectedFiles) { try { FileSize fileSize = new FileSize(selectedFile.getContent().getSize()); System.out.println(selectedFile.getName().getURI() + ": " + fileSize.toString()); byte[] bytes = readBytes(selectedFile.getContent().getInputStream(), 150 * 1024l); JScrollPane sp = new JScrollPane(new JTextArea(new String(bytes))); JDialog d = new JDialog(f); d.setTitle("Content of file: " + selectedFile.getName().getFriendlyURI()); d.getContentPane().add(sp); d.setSize(600, 400); d.setVisible(true); } catch (Exception e1) { LOGGER.error("Failed to read file", e1); JOptionPane.showMessageDialog(f, (e1.getMessage() == null) ? e1.toString() : e1.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } } }); comp.setCancelAction(new AbstractAction(Messages.getMessage("general.cancelButtonText")) { @Override public void actionPerformed(ActionEvent e) { f.dispose(); try { propertiesConfiguration.save(); } catch (ConfigurationException e1) { e1.printStackTrace(); } System.exit(0); } }); contentPane.add(comp); f.pack(); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }); }