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.linkedin.pinot.broker.routing.builder.KafkaLowLevelConsumerRoutingTableBuilder.java

@Override
public void init(Configuration configuration, TableConfig tableConfig,
        ZkHelixPropertyStore<ZNRecord> propertyStore) {
    // TODO jfim This is a broker-level configuration for now, until we refactor the configuration of the routing table to allow per-table routing settings
    if (configuration.containsKey("realtimeTargetServerCountPerQuery")) {
        final String targetServerCountPerQuery = configuration.getString("realtimeTargetServerCountPerQuery");
        try {/*from   w w  w .  j a  v a  2 s .  com*/
            _targetNumServersPerQuery = Integer.parseInt(targetServerCountPerQuery);
            LOGGER.info("Using realtime target server count of {}", _targetNumServersPerQuery);
        } catch (Exception e) {
            LOGGER.warn(
                    "Could not get the realtime target server count per query from configuration value {}, keeping default value {}",
                    targetServerCountPerQuery, _targetNumServersPerQuery, e);
        }
    } else {
        LOGGER.info("Using default value for realtime target server count of {}", _targetNumServersPerQuery);
    }
}

From source file:com.linkedin.pinot.broker.routing.builder.DefaultOfflineRoutingTableBuilder.java

@Override
public void init(Configuration configuration, TableConfig tableConfig,
        ZkHelixPropertyStore<ZNRecord> propertyStore) {
    _largeClusterRoutingTableBuilder = new LargeClusterRoutingTableBuilder();
    _smallClusterRoutingTableBuilder = new BalancedRandomRoutingTableBuilder();
    if (configuration.containsKey("minServerCountForLargeCluster")) {
        final String minServerCountForLargeCluster = configuration.getString("minServerCountForLargeCluster");
        try {/*ww  w.  j  av a2  s  . c om*/
            _minServerCountForLargeCluster = Integer.parseInt(minServerCountForLargeCluster);
            LOGGER.info("Using large cluster min server count of {}", _minServerCountForLargeCluster);
        } catch (Exception e) {
            LOGGER.warn(
                    "Could not get the large cluster min server count from configuration value {}, keeping default value {}",
                    minServerCountForLargeCluster, _minServerCountForLargeCluster, e);
        }
    } else {
        LOGGER.info("Using default value for large cluster min server count of {}",
                _minServerCountForLargeCluster);
    }

    if (configuration.containsKey("minReplicaCountForLargeCluster")) {
        final String minReplicaCountForLargeCluster = configuration.getString("minReplicaCountForLargeCluster");
        try {
            _minReplicaCountForLargeCluster = Integer.parseInt(minReplicaCountForLargeCluster);
            LOGGER.info("Using large cluster min replica count of {}", _minReplicaCountForLargeCluster);
        } catch (Exception e) {
            LOGGER.warn(
                    "Could not get the large cluster min replica count from configuration value {}, keeping default value {}",
                    minReplicaCountForLargeCluster, _minReplicaCountForLargeCluster, e);
        }
    } else {
        LOGGER.info("Using default value for large cluster min replica count of {}",
                _minReplicaCountForLargeCluster);
    }

    _largeClusterRoutingTableBuilder.init(configuration, tableConfig, propertyStore);
    _smallClusterRoutingTableBuilder.init(configuration, tableConfig, propertyStore);
}

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

/**
 * Configures the algorithm.//from  www  .  j  a  va2 s. co  m
 */
@Override
public void configure(Configuration conf) {
    try {
        super.configure(conf);

        if (conf.containsKey("ParetoFrontReplaceOperator.Class")) {
            setParetoFrontReplaceOperator((ParetoFrontReplaceOperator) Class
                    .forName(conf.getString("ParetoFrontReplaceOperator.Class")).newInstance());
        } else {
            (new ConfWarning("MMGAAlgorithm.ParetoFrontReplaceOperator", "ParetoFrontReplaceOperator")).warn();
            setParetoFrontReplaceOperator(new ParetoFrontReplaceOperator());
        }

        getParetoFrontReplaceOperator().configure(conf.subset("ParetoFrontReplaceOperator"));

        if (conf.containsKey("PopulationMemorySize")) {
            setPopulationMemorySize(conf.getInt("PopulationMemorySize"));
        } else {
            int memSize = getParetoFrontReplaceOperator().getMaximumParetoFrontSize() / 3;

            (new ConfWarning("MMGAAlgorithm.PopulationMemorySize", memSize)).warn();
            setPopulationMemorySize(memSize);
        }

        if (conf.containsKey("PopulationMemoryReplaceOperator.Class")) {
            setPopulationMemoryReplaceOperator((PopulationMemoryReplaceOperator) Class
                    .forName(conf.getString("PopulationMemoryReplaceOperator.Class")).newInstance());
        } else {
            (new ConfWarning("MMGAAlgorithm.PopulationMemoryReplaceOperator",
                    "PopulationMemoryReplaceOperator")).warn();
            setPopulationMemoryReplaceOperator(new PopulationMemoryReplaceOperator());
        }

        getPopulationMemoryReplaceOperator().setPopMemSize(getPopulationMemorySize());
        getPopulationMemoryReplaceOperator().configure(conf.subset("PopulationMemoryReplaceOperator"));

    } catch (Exception ex) {
        throw new ConfigurationException(this.getClass(), ex);
    }
}

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

public static boolean logCluster(CmServerLog logger, String label, Configuration configuration,
        CmServerCluster cluster, Set<Instance> instances) throws IOException {
    if (!instances.isEmpty()) {
        logger.logOperationInProgressSync(label, "HOST ADDRESSES");
        for (Instance instance : instances) {
            logger.logOperationInProgressSync(label,
                    "  " + instance.getId() + "@" + instance.getPublicHostName() + "@" + instance.getPublicIp()
                            + "@" + instance.getPrivateIp());
        }//from  w w w  .j  av  a  2  s.  c  o m
    }
    if (!cluster.getAgents().isEmpty()) {
        logger.logOperationInProgressSync(label, "HOST SSH");
    }
    SortedSet<String> cmAgentsSorted = new TreeSet<String>();
    for (CmServerService cmAgent : cluster.getAgents()) {
        cmAgentsSorted.add("  ssh -o StrictHostKeyChecking=no -i "
                + configuration.getString(ClusterSpec.Property.PRIVATE_KEY_FILE.getConfigName()) + " "
                + configuration.getString(ClusterSpec.Property.CLUSTER_USER.getConfigName()) + "@"
                + cmAgent.getIp());
    }
    for (String cmAgentSorted : cmAgentsSorted) {
        logger.logOperationInProgressSync(label, cmAgentSorted);
    }
    if (!cluster.getServiceTypes(CmServerServiceType.CLUSTER).isEmpty()) {
        for (CmServerServiceType type : cluster.getServiceTypes()) {
            logger.logOperationInProgressSync(label, "CDH " + type.toString() + " SERVICE");
            for (CmServerService service : cluster.getServices(type)) {
                logger.logOperationInProgressSync(label,
                        "  " + service.getName() + "@" + service.getIp() + "=" + service.getStatus());
            }
        }
    }
    Set<Instance> balancerInstances = new HashSet<Cluster.Instance>();
    for (Instance instance : instances) {
        if (instance.getRoles().contains(CmBalancerHandler.ROLE)) {
            balancerInstances.add(instance);
        }
    }
    if (!balancerInstances.isEmpty()) {
        logger.logOperationInProgressSync(label, "BALANCER IMPALA");
        for (Instance instance : balancerInstances) {
            logger.logOperationInProgressSync(label, "  impala-shell -i " + instance.getPrivateIp() + ":"
                    + configuration.getString(CmConstants.CONFIG_WHIRR_INTERNAL_PORT_BALANCER_IMPALA));
        }
    }
    logger.logOperationInProgressSync(label, "CONSOLE MANAGER");
    if (cluster.getServer() != null) {
        logger.logOperationInProgressSync(label, "  http://" + cluster.getServer().getHost() + ":"
                + configuration.getString(CmConstants.CONFIG_WHIRR_INTERNAL_PORT_WEB));
    } else {
        logger.logOperationInProgressSync(label, "NO CM SERVER");
    }
    logger.logOperationInProgressSync(label, "CONSOLE NAVIGATOR");
    if (cluster.getServer() != null) {
        logger.logOperationInProgressSync(label, "  http://" + cluster.getServer().getHost() + ":"
                + configuration.getString(CmConstants.CONFIG_WHIRR_INTERNAL_PORT_NAV));
    } else {
        logger.logOperationInProgressSync(label, "NO NAVIGATOR SERVER");
    }
    logger.logOperationInProgressSync(label, "CONSOLE HUE");
    if (cluster.getServiceTypes(CmServerServiceType.HUE) != null) {
        String hueHost = null;
        for (Instance instance : instances) {
            if (instance.getRoles().contains(CmCdhHueServerHandler.ROLE)) {
                hueHost = instance.getPublicHostName();
                break;
            }
        }
        logger.logOperationInProgressSync(label, "  http://" + hueHost + ":"
                + configuration.getString(CmConstants.CONFIG_WHIRR_INTERNAL_PORT_HUE));
    } else {
        logger.logOperationInProgressSync(label, "NO HUE SERVER");
    }
    return !cluster.isEmpty();
}

From source file:com.virtualparadigm.packman.processor.JPackageManagerOld.java

private static VelocityContext createVelocityContext(Configuration configuration) {

    ToolManager velocityToolManager = new ToolManager();
    velocityToolManager.configure("velocity-tools.xml");
    VelocityContext velocityContext = new VelocityContext(velocityToolManager.createContext());

    //       VelocityContext velocityContext = new VelocityContext();
    if (configuration != null) {
        String key = null;//  w w w  .  j a v  a  2s. c om
        for (Iterator<String> it = configuration.getKeys(); it.hasNext();) {
            key = it.next();
            velocityContext.put(key, configuration.getString(key));
        }
    }
    return velocityContext;
}

From source file:com.kixeye.chassis.bootstrap.ConfigurationBuilderTest.java

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test/*  ww w  .  j av  a 2 s .  co  m*/
public void zookeeperOverridesApplicationProperties() throws Exception {
    String key1 = UUID.randomUUID().toString();
    String value1 = UUID.randomUUID().toString();
    String key2 = UUID.randomUUID().toString();
    String value2 = UUID.randomUUID().toString();

    TestUtils.writePropertiesToFile(TEST_APP_CONFIG_PROPERTIES, filesCreated, new SimpleEntry(key1, value1),
            new SimpleEntry(key2, value2));

    curatorFramework.create().creatingParentsIfNeeded().forPath(ZOOKEEPER_CONFIG_ROOT + "/" + key1,
            "zookeepervalue".getBytes());

    configurationBuilder
            .withConfigurationProvider(new ZookeeperConfigurationProvider(zookeeperServer.getConnectString()));
    configurationBuilder.withApplicationProperties(TEST_APP_CONFIG_PROPERTIES_SPRING_PATH);
    Configuration configuration = configurationBuilder.build();

    //assert that the zookeeper config overrode the app properties config
    Assert.assertEquals("zookeepervalue", configuration.getString(key1));
    //assert that the proper which exists in app properties but not in zookeeper is found.
    Assert.assertEquals(value2, configuration.getString(key2));
}

From source file:com.netflix.appinfo.PropertiesInstanceConfig.java

/**
 * Gets the metadata map associated with the instance. The properties that
 * will be looked up for this will be <code>namespace + ".metadata"</code>.
 * /*from ww  w  . j  a va  2s .c  o  m*/
 * <p>
 * For instance, if the given namespace is <code>eureka.appinfo</code>, the
 * metadata keys are searched under the namespace
 * <code>eureka.appinfo.metadata</code>.
 * </p>
 */
@Override
public Map<String, String> getMetadataMap() {
    Map<String, String> metadataMap = new LinkedHashMap<String, String>();
    Configuration config = (Configuration) INSTANCE.getBackingConfigurationSource();
    for (Iterator<String> iter = config.subset(propMetadataNamespace).getKeys();

            iter.hasNext();) {

        String key = iter.next();
        String value = config.getString(propMetadataNamespace + key);
        metadataMap.put(key, value);
    }
    return metadataMap;
}

From source file:io.wcm.caravan.io.http.impl.CaravanHttpServiceConfig.java

/**
 * Checks if protocols are defined in the ribbon "listOfServers" properties, which is not supported by ribbon itself.
 * If this is the case, remove them and set our custom "http.protocol" property instead to the protocol, if
 * it is set to "auto"./*w ww  . j  av a2s  . co  m*/
 */
private void applyRibbonHostsProcotol(String serviceId) {
    Configuration archaiusConfig = ArchaiusConfig.getConfiguration();

    String[] listOfServers = archaiusConfig.getStringArray(serviceId + RIBBON_PARAM_LISTOFSERVERS);
    String protocolForAllServers = archaiusConfig.getString(serviceId + HTTP_PARAM_PROTOCOL);

    // get protocols defined in servers
    Set<String> protocolsFromListOfServers = Arrays.stream(listOfServers)
            .filter(server -> StringUtils.contains(server, "://"))
            .map(server -> StringUtils.substringBefore(server, "://")).collect(Collectors.toSet());

    // skip further processing of no protocols defined
    if (protocolsFromListOfServers.isEmpty()) {
        return;
    }

    // ensure that only one protocol is defined. if not use the first one and write a warning to the log files.
    String protocol = new TreeSet<String>(protocolsFromListOfServers).iterator().next();
    if (protocolsFromListOfServers.size() > 1) {
        log.warn("Different protocols are defined for property {}: {}. Only protocol '{}' is used.",
                RIBBON_HOSTS_PROPERTY, StringUtils.join(listOfServers, LIST_SEPARATOR), protocol);
    }

    // if http protocol is not set to "auto" write a warning as well, because protocol is defined in server list as well
    if (!(StringUtils.equals(protocolForAllServers, RequestUtil.PROTOCOL_AUTO)
            || StringUtils.equals(protocolForAllServers, protocol))) {
        log.warn(
                "Protocol '{}' is defined for property {}: {}, but an other protocol is defined in the server list: {}. Only protocol '{}' is used.",
                protocolForAllServers, PROTOCOL_PROPERTY, StringUtils.join(listOfServers, LIST_SEPARATOR),
                protocol);
    }

    // remove protocol from list of servers and store default protocol
    List<String> listOfServersWithoutProtocol = Arrays.stream(listOfServers)
            .map(server -> StringUtils.substringAfter(server, "://")).collect(Collectors.toList());
    archaiusConfig.setProperty(serviceId + RIBBON_PARAM_LISTOFSERVERS,
            StringUtils.join(listOfServersWithoutProtocol, LIST_SEPARATOR));
    archaiusConfig.setProperty(serviceId + HTTP_PARAM_PROTOCOL, protocol);
}

From source file:com.datastax.openflights.OpenflightsBulkLoaderVertexProgram.java

private BulkLoader createBulkLoader() {
    final BulkLoader loader;
    final Configuration config = configuration.subset(BULK_LOADER_VERTEX_PROGRAM_CFG_PREFIX);
    if (config.containsKey("class")) {
        final String className = config.getString("class");
        try {//from   w  ww  . ja  v  a 2s. co m
            final Class<?> bulkLoaderClass = Class.forName(className);
            loader = (BulkLoader) bulkLoaderClass.getConstructor().newInstance();
        } catch (ClassNotFoundException e) {
            LOGGER.error("Unable to find custom bulk loader class: {}", className);
            throw new IllegalStateException(e);
        } catch (Exception e) {
            LOGGER.error("Unable to create an instance of the given bulk loader class: {}", className);
            throw new IllegalStateException(e);
        }
    } else {
        loader = new IncrementalBulkLoader();
    }
    loader.configure(configuration);
    return loader;
}

From source file:es.udc.gii.common.eaf.factory.XMLSimpleFactory.java

@Override
public RestartStrategy createRestartStrategy() {

    //01 - 07 - 2011 : Se aaden las estrategas de reinicio.
    if (EAFConfiguration.getInstance().containsKey("RestartStrategy.Class")) {
        Configuration conf = EAFConfiguration.getInstance().subset("RestartStrategy");
        try {//  w  w w  . j a  v  a2  s .  co  m

            RestartStrategy rs = (RestartStrategy) Class.forName(conf.getString("Class")).newInstance();

            rs.configure(conf);

            return rs;
        } catch (Exception ex) {
            throw new ConfigurationException("Wrong restart strategy configuration for  "
                    + conf.getString("Class") + " ?" + " \n Thrown exception: \n" + ex);
        }
    } else {
        return null;
    }
}