Example usage for org.apache.commons.configuration Configuration getString

List of usage examples for org.apache.commons.configuration Configuration getString

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration getString.

Prototype

String getString(String key);

Source Link

Document

Get a string associated with the given configuration key.

Usage

From source file:com.cloudera.whirr.cm.CmServerClusterInstance.java

@SuppressWarnings("unchecked")
public static Map<String, Map<String, Map<String, String>>> getClusterConfiguration(
        final Configuration configuration, SortedSet<String> mounts) throws IOException {

    Map<String, Map<String, Map<String, String>>> clusterConfiguration = new HashMap<String, Map<String, Map<String, String>>>();

    Iterator<String> keys = configuration.getKeys();
    while (keys.hasNext()) {
        String key = keys.next();
        if (key.startsWith(CONFIG_WHIRR_CM_CONFIG_PREFIX)) {
            String[] keyTokens = getClusterConfigurationKeyTokens(clusterConfiguration, key,
                    CONFIG_WHIRR_CM_CONFIG_PREFIX);
            clusterConfiguration.get(keyTokens[0]).get(keyTokens[1]).put(keyTokens[2],
                    configuration.getString(key));
        }/* w w  w  .ja  v a  2 s .  c  om*/
    }

    keys = configuration.getKeys();
    while (keys.hasNext()) {
        final String key = keys.next();
        if (key.startsWith(CONFIG_WHIRR_INTERNAL_CM_CONFIG_DEFAULT_PREFIX)) {
            String[] keyTokens = getClusterConfigurationKeyTokens(clusterConfiguration, key,
                    CONFIG_WHIRR_INTERNAL_CM_CONFIG_DEFAULT_PREFIX);
            if (configuration.getString(
                    CONFIG_WHIRR_CM_CONFIG_PREFIX + keyTokens[1].toLowerCase() + "." + keyTokens[2]) == null) {
                if ((keyTokens[2].endsWith(CONFIG_CM_DIR_SUFFIX_LIST)
                        || keyTokens[2].endsWith(CONFIG_CM_DIR_SUFFIX_PLURAL)) && !mounts.isEmpty()) {
                    clusterConfiguration.get(keyTokens[0]).get(keyTokens[1]).put(keyTokens[2], Joiner.on(',')
                            .join(Lists.transform(Lists.newArrayList(mounts), new Function<String, String>() {
                                @Override
                                public String apply(String input) {
                                    return input + configuration.getString(key);
                                }
                            })));
                } else {
                    clusterConfiguration.get(keyTokens[0]).get(keyTokens[1]).put(keyTokens[2],
                            (mounts.isEmpty() ? configuration.getString(CONFIG_WHIRR_INTERNAL_DATA_DIRS_DEFAULT)
                                    : mounts.iterator().next()) + configuration.getString(key));
                }
            }
        }
    }

    keys = configuration.getKeys();
    while (keys.hasNext()) {
        final String key = keys.next();
        if (key.startsWith(CONFIG_WHIRR_CM_CONFIG_PREFIX) && key.endsWith(CONFIG_CM_DB_SUFFIX_TYPE)) {
            String[] keyTokens = getClusterConfigurationKeyTokens(clusterConfiguration, key,
                    CONFIG_WHIRR_CM_CONFIG_PREFIX);
            if (configuration.getString(key) != null && configuration.getString(key).length() == 0) {
                clusterConfiguration.get(keyTokens[0]).get(keyTokens[1]).put(keyTokens[2],
                        configuration.getString(CONFIG_WHIRR_DB_TYPE));
                if (configuration
                        .getString(key.replace(CONFIG_CM_DB_SUFFIX_TYPE, CONFIG_CM_DB_SUFFIX_PORT)) != null
                        && configuration
                                .getString(key.replace(CONFIG_CM_DB_SUFFIX_TYPE, CONFIG_CM_DB_SUFFIX_PORT))
                                .length() == 0) {
                    clusterConfiguration.get(keyTokens[0]).get(keyTokens[1]).put(
                            keyTokens[2].replace(CONFIG_CM_DB_SUFFIX_TYPE, CONFIG_CM_DB_SUFFIX_PORT),
                            configuration.getString(CONFIG_WHIRR_INTERNAL_PORTS_DB_PREFIX
                                    + configuration.getString(CONFIG_WHIRR_DB_TYPE)));
                } else if (configuration
                        .getString(key.replace(CONFIG_CM_DB_SUFFIX_TYPE, CONFIG_CM_DB_SUFFIX_HOST)) != null
                        && !configuration
                                .getString(key.replace(CONFIG_CM_DB_SUFFIX_TYPE, CONFIG_CM_DB_SUFFIX_HOST))
                                .contains(":")) {
                    clusterConfiguration.get(keyTokens[0]).get(keyTokens[1]).put(
                            keyTokens[2].replace(CONFIG_CM_DB_SUFFIX_TYPE, CONFIG_CM_DB_SUFFIX_HOST),
                            configuration
                                    .getString(key.replace(CONFIG_CM_DB_SUFFIX_TYPE, CONFIG_CM_DB_SUFFIX_HOST))
                                    + ":" + configuration.getString(CONFIG_WHIRR_INTERNAL_PORTS_DB_PREFIX
                                            + configuration.getString(CONFIG_WHIRR_DB_TYPE)));
                }
            }
        }
    }

    if (clusterConfiguration.get(CM_API_BASE_VERSION) == null) {
        clusterConfiguration.put(CM_API_BASE_VERSION, new HashMap<String, Map<String, String>>());
    }
    if (clusterConfiguration.get(CM_API_BASE_VERSION).get(CmServerServiceType.CLUSTER.getId()) == null) {
        clusterConfiguration.get(CM_API_BASE_VERSION).put(CmServerServiceType.CLUSTER.getId(),
                new HashMap<String, String>());
    }

    if (clusterConfiguration.get(CM_API_BASE_VERSION).get(CmServerServiceType.CLUSTER.getId())
            .get(CONFIG_CM_LICENSE_PROVIDED) == null) {
        if (Utils.urlForURI(configuration.getString(CONFIG_WHIRR_CM_LICENSE_URI)) != null) {
            clusterConfiguration.get(CM_API_BASE_VERSION).get(CmServerServiceType.CLUSTER.getId())
                    .put(CONFIG_CM_LICENSE_PROVIDED, Boolean.TRUE.toString());
        } else {
            clusterConfiguration.get(CM_API_BASE_VERSION).get(CmServerServiceType.CLUSTER.getId())
                    .put(CONFIG_CM_LICENSE_PROVIDED, Boolean.FALSE.toString());
        }
    }

    if (clusterConfiguration.get(CM_API_BASE_VERSION).get(CmServerServiceType.CLUSTER.getId())
            .get(CONFIG_CM_LICENSE_PROVIDED).equals(Boolean.TRUE.toString())) {
        if (clusterConfiguration.get(CM_API_BASE_VERSION)
                .get(CmServerServiceType.MAPREDUCE_TASK_TRACKER.getId()) == null) {
            clusterConfiguration.get(CM_API_BASE_VERSION)
                    .put(CmServerServiceType.MAPREDUCE_TASK_TRACKER.getId(), new HashMap<String, String>());
        }
        clusterConfiguration.get(CM_API_BASE_VERSION).get(CmServerServiceType.MAPREDUCE_TASK_TRACKER.getId())
                .put(CONFIG_CM_TASKTRACKER_INSTRUMENTATION, "org.apache.hadoop.mapred.TaskTrackerCmonInst");
    }

    return clusterConfiguration;

}

From source file:de.nec.nle.siafu.output.CSVPrinter.java

/**
 * Builds a <code>CVSPrinter</code> object. If history is to be kept, this
 * already initializes the output file.//from  w  w w .  j  a  v  a  2  s .com
 * 
 * @param world
 *            the world to print about
 * @param config
 *            the simulation configuration file
 */
public CSVPrinter(final World world, final Configuration config) {
    this.world = world;
    this.outputPath = config.getString("output.csv.path");
    this.keepHistory = config.getBoolean("output.csv.keephistory");
    this.intervalInMillis = SECOND_TO_MS_FACTOR * config.getInt("output.csv.interval");

    this.header = createHeader();

    if (keepHistory) {
        initializeFile(outputPath);
    }
}

From source file:es.udc.gii.common.eaf.algorithm.operator.reproduction.ColonizationOperator.java

@Override
public void configure(Configuration conf) {
    ConfWarning w;/*from   ww w .  j a  va2s. c o  m*/
    try {
        if (conf.containsKey("Rho.Class")) {
            this.rho = (Parameter) Class.forName(conf.getString("Rho.Class")).newInstance();
            this.rho.configure(conf.subset("Rho"));
        } else {
            w = new ConfWarning("Rho", this.rho.toString());
            w.warn();
        }
        if (conf.containsKey("Lambda.Class")) {
            this.lambdaGenerator = (Parameter) Class.forName(conf.getString("Lambda.Class")).newInstance();
            this.lambdaGenerator.configure(conf.subset("Lambda"));
        } else {
            w = new ConfWarning("Lambda", this.lambdaGenerator.toString());
            w.warn();
        }
        if (conf.containsKey("Tau.Class")) {
            this.tau = (Parameter) Class.forName(conf.getString("Tau.Class")).newInstance();
            this.tau.configure(conf.subset("Tau"));
        } else {
            w = new ConfWarning("Tau", this.tau.toString());
            w.warn();
        }

        if (conf.containsKey("Chooser.Class")) {
            this.chooser = (IndividualChooser) Class.forName(conf.getString("Chooser.Class")).newInstance();
            this.chooser.configure(conf.subset("Chooser"));
        } else {
            w = new ConfWarning("Chooser", this.chooser.toString());
            w.warn();
        }

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:net.sf.mpaxs.spi.server.DrmaaComputeHostLauncher.java

/**
 * Submits a new ComputeHost to the GridEngine.
 * Settings from the Settings class are used and converted to <code>Configuration</code>.
 *
 * @param cfg the configuration to use//from   w w w . j  av  a2s .  co  m
 * @see net.sf.mpaxs.spi.computeHost.Settings
 */
@Override
public void startComputeHost(Configuration cfg) {
    String drmaaImplementation = SessionFactory.getFactory().getSession().getDrmaaImplementation();
    System.out.println("Drmaa Implementation: " + drmaaImplementation);
    File configLocation = new File(cfg.getString(ConfigurationKeys.KEY_COMPUTE_HOST_WORKING_DIR),
            "computeHost.properties");
    try {
        PropertiesConfiguration pc = new PropertiesConfiguration(configLocation);
        ConfigurationUtils.copy(cfg, pc);
        pc.save();
    } catch (ConfigurationException ex) {
        Logger.getLogger(DrmaaComputeHostLauncher.class.getName()).log(Level.SEVERE, null, ex);
    }

    List<String> arguments = new ArrayList<String>();
    arguments.add("-cp");
    arguments.add(cfg.getString(ConfigurationKeys.KEY_PATH_TO_COMPUTEHOST_JAR));
    arguments.add(cfg.getString(ConfigurationKeys.KEY_COMPUTE_HOST_MAIN_CLASS));
    arguments.add("-c");
    try {
        arguments.add(configLocation.toURI().toURL().toString());
    } catch (MalformedURLException ex) {
        Logger.getLogger(DrmaaComputeHostLauncher.class.getName()).log(Level.SEVERE, null, ex);
    }
    Logger.getLogger(this.getClass().getName()).log(Level.INFO, "ComputeHost configuration: {0}",
            ConfigurationUtils.toString(cfg));
    try {
        SessionFactory factory = SessionFactory.getFactory();
        Session session = factory.getSession();
        Logger.getLogger(this.getClass().getName()).log(Level.INFO,
                "DRM System: {0} Implementation: {1} Version: {2}", new Object[] { session.getDrmSystem(),
                        session.getDrmaaImplementation(), session.getVersion() });
        session.init("");
        JobTemplate jt = session.createJobTemplate();
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Remote command: {0}",
                cfg.getString(ConfigurationKeys.KEY_PATH_TO_JAVA));
        jt.setRemoteCommand(cfg.getString(ConfigurationKeys.KEY_PATH_TO_JAVA));
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Working dir: {0}",
                cfg.getString(ConfigurationKeys.KEY_COMPUTE_HOST_WORKING_DIR));
        jt.setWorkingDirectory(cfg.getString(ConfigurationKeys.KEY_COMPUTE_HOST_WORKING_DIR));
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Arguments: {0}", arguments);
        jt.setArgs(arguments);
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Error path: {0}",
                cfg.getString(ConfigurationKeys.KEY_ERROR_FILE));
        jt.setErrorPath(":" + cfg.getString(ConfigurationKeys.KEY_ERROR_FILE));
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Output path: {0}",
                cfg.getString(ConfigurationKeys.KEY_OUTPUT_FILE));
        jt.setOutputPath(":" + cfg.getString(ConfigurationKeys.KEY_OUTPUT_FILE));
        jt.setNativeSpecification(cfg.getString(ConfigurationKeys.KEY_NATIVE_SPEC, ""));
        jt.setJobName("mpaxs-chost");
        session.runJob(jt);
        session.deleteJobTemplate(jt);
        session.exit();
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Session started!");
    } catch (DrmaaException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.boozallen.cognition.ingest.storm.bolt.enrich.EsIndexBolt.java

@Override
public void configure(Configuration conf) {
    conf.getKeys().forEachRemaining(key -> {
        String keyString = key.toString();
        if (keyString.startsWith("es")) {
            String cleanedKey = keyString.replaceAll("\\.\\.", ".");
            boltConfig.put(cleanedKey, conf.getString(keyString));
        }//from w  w w . ja  v a 2  s.co m
    });

    manualFlushFreqSecs = conf.getInt(MANUAL_FLUSH_FREQ_SECS);
}

From source file:com.nesscomputing.config.SystemOverrideTest.java

@Test
public void loadStringValues() {
    Assert.assertThat(cfg, is(notNullValue()));
    final Configuration config = cfg.getConfiguration();

    Assert.assertThat(config, is(notNullValue()));

    Assert.assertThat(System.getProperty("string-value"), is("OVERRIDDEN"));
    Assert.assertThat(System.getProperties().getProperty("string-value"), is("OVERRIDDEN"));

    final String s_cfg2 = config.getString("string-value");
    Assert.assertThat(s_cfg2, is("OVERRIDDEN"));
}

From source file:edu.lternet.pasta.portal.user.SavedData.java

public SavedData(String uid) {
    this.uid = uid;
    Configuration options = ConfigurationListener.getOptions();
    String dbDriver = options.getString("db.Driver");
    String dbURL = options.getString("db.URL");
    String dbUser = options.getString("db.User");
    String dbPassword = options.getString("db.Password");
    this.databaseClient = new DatabaseClient(dbDriver, dbURL, dbUser, dbPassword);
}

From source file:com.boozallen.cognition.ingest.accumulo.storm.AccumuloEventStorageBoltTest.java

@Test
public void testConfigureAccumuloBolt(@Injectable Configuration conf) {
    new Expectations() {
        {//from w w w  .j a v  a2  s .co  m
            conf.getString(EVENT_TABLE);
            result = "eventTable";
            conf.getString(UUID_PREFIX, UUID_PREFIX_DEFAULT);
            result = UUID_PREFIX_DEFAULT;
            conf.getInt(SPLITS, SPLITS_DEFAULT);
            result = SPLITS_DEFAULT;
            conf.getString(VISIBILITY);
            result = "";
            conf.getString(VISIBILITY_BY_FIELD);
            result = "";
        }
    };

    bolt.configureAccumuloBolt(conf);
}

From source file:net.handle.servlet.Settings.java

private void initRequestParameters(Configuration configuration) throws SettingsException {
    try {/* w  ww  .  j  a va2 s  . c om*/
        handleIdRequestParameterName = configuration.getString(HANDLE_ID_KEY);
        if (isNotBlank(handleIdRequestParameterName)) {
            LOG.info("Setting " + HANDLE_ID_KEY + " to '" + handleIdRequestParameterName + "'");
        } else {
            throw new SettingsException(HANDLE_ID_KEY + " is blank");
        }

        datatypesRequestParameterName = configuration.getString(DATATYPES_KEY);
        if (isNotBlank(datatypesRequestParameterName)) {
            LOG.info("Setting " + DATATYPES_KEY + " to '" + datatypesRequestParameterName + "'");
        } else {
            throw new SettingsException(DATATYPES_KEY + " is blank");
        }

        formatRequestParameterName = configuration.getString(FORMAT_KEY);
        if (isNotBlank(formatRequestParameterName)) {
            LOG.info("Setting " + FORMAT_KEY + " to '" + formatRequestParameterName + "'");
        } else {
            throw new SettingsException(FORMAT_KEY + " is blank");
        }

        indexRequestParameterName = configuration.getString(INDEX_KEY);
        if (isNotBlank(indexRequestParameterName)) {
            LOG.info("Setting " + INDEX_KEY + " to '" + indexRequestParameterName + "'");
        } else {
            throw new SettingsException(INDEX_KEY + " is blank");
        }

        typeRequestParameterName = configuration.getString(TYPE_KEY);
        if (isNotBlank(typeRequestParameterName)) {
            LOG.info("Setting " + TYPE_KEY + " to '" + typeRequestParameterName + "'");
        } else {
            throw new SettingsException(TYPE_KEY + " is blank");
        }
    } catch (ConversionException e) {
        throw new SettingsException(e);
    }
}

From source file:es.udc.gii.common.eaf.algorithm.NSGA2Algorithm.java

@Override
public void configure(Configuration conf) {
    super.configure(conf);
    try {//from w  ww. j  a v a  2 s. c  o  m

        if (conf.containsKey("ParametersPlugin.Class")) {
            this.parametersPlugin = ((MultiobjectiveIndividualParametersPlugin) (Class
                    .forName(conf.getString("ParametersPlugin.Class"))).newInstance());
            this.parametersPlugin.configure(conf.subset("ParametersPlugin"));
        } else {
            this.parametersPlugin = new NSGA2IndividualParametersPlugin();
            (new ConfWarning("ParametersPlugin", parametersPlugin.getClass().getCanonicalName())).warn();
        }
        if (conf.containsKey("Ranking.Class")) {
            this.setRanking((NSGA2Ranking) Class.forName(conf.getString("Ranking.Class")).newInstance());
            this.getRanking().configure(conf);
        } else {
            this.setRanking(new NSGA2Ranking());
            (new ConfWarning("Ranking", "NSGA2Ranking")).warn();
        }

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}