Search in sources :

Example 21 with ConfigValue

use of com.typesafe.config.ConfigValue in project config by typesafehub.

the class SimpleConfig method getBytesList.

@Override
public List<Long> getBytesList(String path) {
    List<Long> l = new ArrayList<Long>();
    List<? extends ConfigValue> list = getList(path);
    for (ConfigValue v : list) {
        if (v.valueType() == ConfigValueType.NUMBER) {
            l.add(((Number) v.unwrapped()).longValue());
        } else if (v.valueType() == ConfigValueType.STRING) {
            String s = (String) v.unwrapped();
            Long n = parseBytes(s, v.origin(), path);
            l.add(n);
        } else {
            throw new ConfigException.WrongType(v.origin(), path, "memory size string or number of bytes", v.valueType().name());
        }
    }
    return l;
}
Also used : ConfigValue(com.typesafe.config.ConfigValue) ArrayList(java.util.ArrayList) ConfigException(com.typesafe.config.ConfigException)

Example 22 with ConfigValue

use of com.typesafe.config.ConfigValue in project archaius by Netflix.

the class TypesafeConfigurationSource method load.

synchronized Map<String, Object> load() throws Exception {
    Config config = config();
    Map<String, Object> map = new HashMap<String, Object>();
    for (Map.Entry<String, ConfigValue> entry : config.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue().unwrapped();
        if (value instanceof List) {
            if (false == safeArrayKeyExpansion(config, key)) {
                log.error("Unable to expand array: {}", key);
                continue;
            }
            List values = (List) value;
            map.put(lengthKey(key), values.size());
            for (int i = 0; i < values.size(); i++) {
                map.put(indexedKey(key, i), values.get(i));
            }
        } else {
            map.put(key, value);
        }
    }
    return map;
}
Also used : ConfigValue(com.typesafe.config.ConfigValue) HashMap(java.util.HashMap) Config(com.typesafe.config.Config) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap)

Example 23 with ConfigValue

use of com.typesafe.config.ConfigValue in project apollo by spotify.

the class ConfigFilter method filterConfigObject.

static ConfigObject filterConfigObject(ConfigObject config, Set<String> filter) {
    ConfigObject result = config;
    for (Map.Entry<String, ConfigValue> entry : config.entrySet()) {
        String key = entry.getKey();
        final ConfigValue filteredValue;
        if (!isFiltered(key, filter)) {
            final ConfigValue value = entry.getValue();
            if (!"_meta".equals(key) && value.valueType() == ConfigValueType.OBJECT) {
                filteredValue = filterConfigObject((ConfigObject) value, filter);
            } else {
                filteredValue = value;
            }
        } else {
            filteredValue = fromAnyRef("*******", "filtered by config-filter settings");
        }
        result = result.withValue(key, filteredValue);
    }
    return result;
}
Also used : ConfigValue(com.typesafe.config.ConfigValue) ConfigObject(com.typesafe.config.ConfigObject) Map(java.util.Map)

Example 24 with ConfigValue

use of com.typesafe.config.ConfigValue in project play2-elasticsearch by cleverage.

the class IndexConfig method loadMappingFromConfig.

/**
 * Load additional mappings from config entry "elasticsearch.index.mapping"
 * @param indexName
 */
private void loadMappingFromConfig(String indexName) {
    Configuration mappingConfig = (configuration.getConfig("elasticsearch." + indexName + ".mappings") == Option.apply((Configuration) null)) ? null : configuration.getConfig("elasticsearch." + indexName + ".mappings").get();
    if (mappingConfig != null) {
        Iterator<Tuple2<String, ConfigValue>> iter = mappingConfig.entrySet().iterator();
        while (iter.hasNext()) {
            Tuple2<String, ConfigValue> mapping = iter.next();
            String indexType = mapping._1();
            IndexQueryPath indexQueryPath = new IndexQueryPath(indexName, indexType);
            if (mapping._2().unwrapped() instanceof String) {
                indexMappings.put(indexQueryPath, (String) mapping._2().unwrapped());
            } else {
                try {
                    indexMappings.put(indexQueryPath, Json.toJson(mapping._2().unwrapped()).toString());
                } catch (Exception e) {
                    Logger.warn("Incorrect value in elasticsearch.index.mappings", e);
                }
            }
        }
    }
}
Also used : ConfigValue(com.typesafe.config.ConfigValue) Configuration(play.api.Configuration) Tuple2(scala.Tuple2)

Example 25 with ConfigValue

use of com.typesafe.config.ConfigValue in project helios by spotify.

the class TemporaryJobs method getListByKey.

private static List<String> getListByKey(final String key, final Config config) {
    final ConfigList endpointList = config.getList(key);
    final List<String> stringList = Lists.newArrayList();
    for (final ConfigValue v : endpointList) {
        if (v.valueType() != ConfigValueType.STRING) {
            throw new RuntimeException("Item in " + key + " list [" + v + "] is not a string");
        }
        stringList.add((String) v.unwrapped());
    }
    return stringList;
}
Also used : ConfigValue(com.typesafe.config.ConfigValue) ConfigList(com.typesafe.config.ConfigList)

Aggregations

ConfigValue (com.typesafe.config.ConfigValue)37 Map (java.util.Map)20 Config (com.typesafe.config.Config)11 ConfigException (com.typesafe.config.ConfigException)10 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)6 ConfigList (com.typesafe.config.ConfigList)5 ConfigObject (com.typesafe.config.ConfigObject)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 Configuration (org.apache.hadoop.conf.Configuration)4 IOException (java.io.IOException)3 BigInteger (java.math.BigInteger)3 FileSystem (org.apache.hadoop.fs.FileSystem)3 Properties (java.util.Properties)2 ParaObject (com.erudika.para.core.ParaObject)1 Sysprop (com.erudika.para.core.Sysprop)1 Pager (com.erudika.para.core.utils.Pager)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Gson (com.google.gson.Gson)1 ConfigOrigin (com.typesafe.config.ConfigOrigin)1