List of usage examples for org.apache.commons.configuration ConfigurationConverter getConfiguration
public static Configuration getConfiguration(Properties props)
From source file:com.tribloom.reposize.GetRepoSize.java
@Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) { if (logger.isDebugEnabled()) { logger.debug("Entering GetRepoSize.executeImpl()"); }//ww w.j a v a 2s . co m Map<String, Object> model = new HashMap<String, Object>(); // Use Apache Configuration library to perform variable interpolation if // necessary MapConfiguration config = (MapConfiguration) ConfigurationConverter.getConfiguration(globalProperties); Configuration intConfig = config.interpolatedConfiguration(); String contentStore = (String) intConfig.getProperty("dir.contentstore"); String indexes = (String) intConfig.getProperty("dir.indexes"); String indexesBackup = (String) intConfig.getProperty("dir.indexes.backup"); if (logger.isDebugEnabled()) { logger.debug(" contentStorePath = " + contentStore); logger.debug(" indexes = " + indexes); logger.debug(" indexesBackup = " + indexesBackup); } try { /** * TODO: Figure if there's a need and a way to perform this size request on multiple * stores, configured with the Content Selector Service * * Can do nodeService.getStores() to get the StoreRef's, but how * to retrieve contentService for these refs? Or does contentService * intelligently handle this? */ long storeFreeSpace = contentService.getStoreFreeSpace(); long storeTotalSpace = contentService.getStoreTotalSpace(); if (logger.isDebugEnabled()) { logger.debug(" storeFreeSpace = " + storeFreeSpace); logger.debug(" storeTotalSpace = " + storeTotalSpace); } long contentStoreSize = getFileSize(new File(contentStore)); if (logger.isDebugEnabled()) { logger.debug(" contentStoreSize = " + contentStoreSize); } long indexesSize = getFileSize(new File(indexes)); long indexesBackupSize = getFileSize(new File(indexesBackup)); if (logger.isDebugEnabled()) { logger.debug(" indexesSize = " + indexesSize); logger.debug(" indexesBackupSize = " + indexesBackupSize); } model.put("contentStorePath", contentStore); model.put("contentStoreSize", contentStoreSize); model.put("storeFreeSpace", storeFreeSpace); model.put("storeTotalSpace", storeTotalSpace); model.put("indexesPath", indexes); model.put("indexesSize", indexesSize); model.put("indexesBackupPath", indexesBackup); model.put("indexesBackupSize", indexesBackupSize); } catch (Exception e) { logger.error("Exception encountered during GetRepoSize webscript processing: ", e); status.setCode(Status.STATUS_INTERNAL_SERVER_ERROR); status.setException(e); status.setMessage(e.getMessage()); status.setRedirect(false); } if (logger.isDebugEnabled()) { logger.debug("Exiting GetRepoSize.executeImpl()"); } return model; }
From source file:io.fluo.mapreduce.FluoOutputFormat.java
@Override public RecordWriter<Loader, NullWritable> getRecordWriter(TaskAttemptContext context) throws IOException, InterruptedException { ByteArrayInputStream bais = new ByteArrayInputStream( context.getConfiguration().get(PROPS_CONF_KEY).getBytes("UTF-8")); Properties props = new Properties(); props.load(bais);// www. j a v a2 s . c o m FluoConfiguration config = new FluoConfiguration(ConfigurationConverter.getConfiguration(props)); try (final LoaderExecutorImpl lexecutor = new LoaderExecutorImpl(config)) { return new RecordWriter<Loader, NullWritable>() { @Override public void close(TaskAttemptContext conext) throws IOException, InterruptedException { lexecutor.close(); } @Override public void write(Loader loader, NullWritable nullw) throws IOException, InterruptedException { lexecutor.execute(loader); } }; } catch (Exception e) { throw new IOException(e); } }
From source file:com.netflix.explorers.PropertiesGlobalModelContext.java
public PropertiesGlobalModelContext(Properties props) { this.properties = props; environmentName = props.getProperty(PROPERTY_ENVIRONMENT_NAME); currentRegion = props.getProperty(PROPERTY_CURRENT_REGION); applicationVersion = props.getProperty(PROPERTY_APPLICATION_VERSION); applicationName = props.getProperty(PROPERTY_APPLICATION_NAME); isLocal = Boolean.parseBoolean(props.getProperty(PROPERTY_IS_LOCAL, "false")); homePageUrl = props.getProperty(PROPERTY_HOME_PAGE); defaultPort = Short.parseShort(props.getProperty(PROPERTY_DEFAULT_PORT, "8080")); dataCenter = props.getProperty(PROPERTY_DATA_CENTER); defaultExplorerName = props.getProperty(PROPERTY_DEFAULT_EXPLORER); try {/*from w ww . j a v a 2 s.c om*/ Map<Object, Object> dcs = ConfigurationConverter .getMap(ConfigurationConverter.getConfiguration(props).subset(PROPERTIES_PREFIX + ".dc")); for (Entry<Object, Object> dc : dcs.entrySet()) { String key = StringUtils.substringBefore(dc.getKey().toString(), "."); String attr = StringUtils.substringAfter(dc.getKey().toString(), "."); CrossLink link = links.get(key); if (link == null) { link = new CrossLink(); links.put(key, link); } BeanUtils.setProperty(link, attr, dc.getValue()); } } catch (Exception e) { LOG.error("Exception ", e); throw new RuntimeException(e); } }
From source file:io.fluo.mapreduce.FluoInputFormat.java
/** * Configure properties needed to connect to a Fluo instance * // w ww .j av a2s . co m * @param conf * @param props * use {@link io.fluo.api.config.FluoConfiguration} to configure programmatically */ @SuppressWarnings("deprecation") public static void configure(Job conf, Properties props) { try { FluoConfiguration config = new FluoConfiguration(ConfigurationConverter.getConfiguration(props)); try (Environment env = new Environment(config)) { long ts = env.getSharedResources().getTimestampTracker().allocateTimestamp(); conf.getConfiguration().setLong(TIMESTAMP_CONF_KEY, ts); ByteArrayOutputStream baos = new ByteArrayOutputStream(); props.store(baos, ""); conf.getConfiguration().set(PROPS_CONF_KEY, new String(baos.toByteArray(), "UTF8")); AccumuloInputFormat.setZooKeeperInstance(conf, config.getAccumuloInstance(), config.getZookeepers()); AccumuloInputFormat.setConnectorInfo(conf, config.getAccumuloUser(), new PasswordToken(config.getAccumuloPassword())); AccumuloInputFormat.setInputTableName(conf, env.getTable()); AccumuloInputFormat.setScanAuthorizations(conf, env.getAuthorizations()); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.nesscomputing.jdbc.C3P0DataSourceProvider.java
private Properties getProperties(final String suffix) { final CombinedConfiguration cc = new CombinedConfiguration(new OverrideCombiner()); if (props != null) { // Allow setting of internal defaults by using "ds.xxx" and "pool.xxx" if a properties // object is present. cc.addConfiguration(//www . j ava 2s. c om new ImmutableConfiguration(ConfigurationConverter.getConfiguration(props).subset(suffix))); } if (config != null) { cc.addConfiguration(config.getConfiguration(propertiesPrefix + "." + suffix)); cc.addConfiguration(config.getConfiguration(DEFAULTS_PREFIX + "." + suffix)); } return ConfigurationConverter.getProperties(cc); }
From source file:io.fluo.core.impl.Environment.java
/** * read configuration from zookeeper//from ww w . j a va2s . c o m * * @throws InterruptedException * @throws KeeperException */ private void readConfig(CuratorFramework curator) throws Exception { accumuloInstance = new String(curator.getData().forPath(ZookeeperConstants.instanceNamePath(zoodir)), "UTF-8"); accumuloInstanceID = new String( curator.getData().forPath(ZookeeperConstants.accumuloInstanceIdPath(zoodir)), "UTF-8"); fluoInstanceID = new String(curator.getData().forPath(ZookeeperConstants.fluoInstanceIdPath(zoodir)), "UTF-8"); table = new String(curator.getData().forPath(ZookeeperConstants.tablePath(zoodir)), "UTF-8"); ByteArrayInputStream bais = new ByteArrayInputStream( curator.getData().forPath(ZookeeperConstants.observersPath(zoodir))); DataInputStream dis = new DataInputStream(bais); observers = Collections.unmodifiableMap(readObservers(dis)); weakObservers = Collections.unmodifiableMap(readObservers(dis)); allObserversColumns = new HashSet<>(); allObserversColumns.addAll(observers.keySet()); allObserversColumns.addAll(weakObservers.keySet()); allObserversColumns = Collections.unmodifiableSet(allObserversColumns); bais = new ByteArrayInputStream(curator.getData().forPath(ZookeeperConstants.sharedConfigPath(zoodir))); Properties sharedProps = new Properties(); sharedProps.load(bais); config.addConfiguration(ConfigurationConverter.getConfiguration(sharedProps)); }
From source file:io.fluo.api.config.FluoConfigurationTest.java
@Test public void testMultipleZookeepers() { Properties props = new Properties(); props.setProperty(FluoConfiguration.CLIENT_ACCUMULO_ZOOKEEPERS_PROP, "zk1,zk2,zk3"); props.setProperty(FluoConfiguration.CLIENT_ZOOKEEPER_CONNECT_PROP, "zk1,zk2,zk3/fluo"); props.setProperty(FluoConfiguration.CLIENT_APPLICATION_NAME_PROP, "myapp"); //ran into a bug where this particular constructor was truncating everything after zk1 FluoConfiguration config = new FluoConfiguration(ConfigurationConverter.getConfiguration(props)); Assert.assertEquals("zk1,zk2,zk3", config.getAccumuloZookeepers()); Assert.assertEquals("zk1,zk2,zk3/fluo/myapp", config.getAppZookeepers()); }
From source file:org.mifos.config.business.MifosConfigurationManager.java
private MifosConfigurationManager() { String defaultConfig = "org/mifos/config/resources/applicationConfiguration.default.properties"; Properties props = new Properties(); try {//w w w . j a v a2s. com InputStream applicationConfig = MifosResourceUtil.getClassPathResourceAsStream(defaultConfig); props.load(applicationConfig); ConfigurationLocator configurationLocator = new ConfigurationLocator(); Resource customApplicationConfig = configurationLocator.getResource(CUSTOM_CONFIG_PROPS_FILENAME); if (customApplicationConfig.exists()) { InputStream is = customApplicationConfig.getInputStream(); props.load(is); is.close(); } LOGGER.info( "Dump of all configuration properties read by MifosConfigurationManager: " + props.toString()); } catch (IOException e) { throw new MifosRuntimeException(e); } configuration = ConfigurationConverter.getConfiguration(props); }
From source file:org.mifos.config.ConfigurationManager.java
private ConfigurationManager() { ConfigurationLocator configurationLocator = new ConfigurationLocator(); Properties props = new Properties(); try {/*from w ww. j a va 2 s .com*/ File defaults = configurationLocator.getFile(DEFAULT_CONFIG_PROPS_FILENAME); props.load(new BufferedInputStream(new FileInputStream(defaults))); } catch (IOException e) { throw new RuntimeException(e); } TestMode currentTestMode = new StandardTestingService().getTestMode(); File customConfigFile = null; try { if (TestMode.MAIN == currentTestMode) { customConfigFile = configurationLocator.getFile(CUSTOM_CONFIG_PROPS_FILENAME); } else if (TestMode.ACCEPTANCE == currentTestMode) { customConfigFile = configurationLocator.getFile(ACCEPTANCE_CONFIG_PROPS_FILENAME); } else if (TestMode.INTEGRATION == currentTestMode) { customConfigFile = new ClassPathResource( "org/mifos/config/resources/" + CUSTOM_CONFIG_PROPS_FILENAME).getFile(); } props.load(new BufferedInputStream(new FileInputStream(customConfigFile))); } catch (FileNotFoundException e) { /* * An FileNotFoundException will be thrown if a file is not found by * getFile(); for normal runtime and acceptance testing modes, the * custom config file is optional, hence, ignore the exception. */ } catch (IOException e) { /* * An IOException is thrown by ClassPathResource if the file is not * found. Integration tests require a (dummy) custom config file and * we should fail if the file is missing. */ throw new SystemException(e); } configuration = ConfigurationConverter.getConfiguration(props); }
From source file:org.rzo.yajsw.config.YajswConfigurationImpl.java
public void init() { if (_init)//from ww w . ja v a 2 s . co m return; /* ConfigurationInterpolator in = (ConfigurationInterpolator) getSubstitutor().getVariableResolver(); StrLookup orgLookup = in.getDefaultLookup(); in.setDefaultLookup(new MyStrLookup(orgLookup)); */ _interpolator = new GInterpolator(this, true, null, _scriptUtils); try { this.setInterpolator(_interpolator); } catch (Exception e1) { e1.printStackTrace(); } if (_localConfiguration != null) { _systemConfiguration.addConfiguration(_localConfiguration); if (debug) log.info("added local configuration "); } // order of adding configurations to composite is important // first added hides the others // load configuration from System Properties if (_useSystemProperties) { _systemProperties = ConfigurationConverter .getConfiguration((Properties) System.getProperties().clone()); _systemConfiguration.addConfiguration(_systemProperties); if (debug) log.info("added system configuration "); } addConfiguration(_systemConfiguration); // check if we have config file String configFile = (String) getProperty("wrapper.config"); if (configFile != null && configFile.contains("\"")) configFile = configFile.replaceAll("\"", ""); // load configuration from file if (configFile == null) { if (debug) log.info("configuration file not set"); } else if (!fileExists(configFile)) log.info("configuration file not found: " + configFile); else { //check if we have a jnlp file if (configFile.endsWith(".jnlp")) try { JnlpSupport jnlp = new JnlpSupport(configFile); _fileConfiguration = jnlp.toConfiguration((String) getProperty("wrapperx.default.config")); _fileConfiguration.setFileName(configFile); addConfiguration(_fileConfiguration); } catch (Exception ex) { ex.printStackTrace(); return; } // else try a standard configuration if (_fileConfiguration == null) try { // enable VFS FileSystem fs = new VFSFileSystem(); fs.setFileOptionsProvider(new FileOptionsProvider() { public Map getOptions() { Map result = new HashMap(); String httpProxy = System.getProperty("http.proxyHost"); String httpPort = System.getProperty("http.proxyPort"); if (httpProxy != null) { int port = 8080; if (httpPort != null) try { port = Integer.parseInt(httpPort); } catch (Exception ex) { ex.printStackTrace(); } result.put(FileOptionsProvider.PROXY_HOST, httpProxy); result.put(FileOptionsProvider.PROXY_PORT, port); } return result; } }); FileSystem.setDefaultFileSystem(fs); // allow for conditional incldues -> first createn an empty properties conf _fileConfiguration = new PropertiesConfiguration(); // then set the file name and load it _fileConfiguration.setFileName(configFile); try { _fileConfiguration.setBasePath(new File(".").getCanonicalPath()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } _fileConfiguration.append(_systemProperties); _fileConfiguration.load(); addConfiguration(_fileConfiguration); } catch (ConfigurationException e) { e.printStackTrace(); log.throwing("error loading configuration file", "<init>AsjwConfiguration", e); } if (!isLocalFile()) { // if no working dir is defined: set working dir to the cache if (_fileConfiguration.getProperty("wrapper.working.dir") == null) try { _fileConfiguration.setProperty("wrapper.working.dir", new File(getCache()).getCanonicalPath().replaceAll("\\\\", "/")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // if no cache path is defined in the file configuration then set it, so it can be accessed by the wrapper for example to get // a system tray icon if (_fileConfiguration.containsKey("wrapper.cache")) _fileConfiguration.setProperty("wrapper.cache", getCache()); } } // load configuration from System Environement addConfiguration(getConfiguration(System.getenv())); _isStopper = this.getBoolean("wrapper.stopper", false); try { _isJavaDebug = this.getInt("wrapper.java.debug.port", -1) != -1; } catch (Exception ex) { ex.printStackTrace(); } _init = true; }