Search in sources :

Example 1 with ConfigValue

use of com.typesafe.config.ConfigValue in project incubator-gobblin by apache.

the class FsStateStoreFactory method createStateStore.

@Override
public <T extends State> StateStore<T> createStateStore(Config config, Class<T> stateClass) {
    // Add all job configuration properties so they are picked up by Hadoop
    Configuration conf = new Configuration();
    for (Map.Entry<String, ConfigValue> entry : config.entrySet()) {
        conf.set(entry.getKey(), entry.getValue().unwrapped().toString());
    }
    try {
        String stateStoreFsUri = ConfigUtils.getString(config, ConfigurationKeys.STATE_STORE_FS_URI_KEY, ConfigurationKeys.LOCAL_FS_URI);
        FileSystem stateStoreFs = FileSystem.get(URI.create(stateStoreFsUri), conf);
        String stateStoreRootDir = config.getString(ConfigurationKeys.STATE_STORE_ROOT_DIR_KEY);
        return new FsStateStore(stateStoreFs, stateStoreRootDir, stateClass);
    } catch (IOException e) {
        throw new RuntimeException("Failed to create FsStateStore with factory", e);
    }
}
Also used : ConfigValue(com.typesafe.config.ConfigValue) Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) IOException(java.io.IOException) Map(java.util.Map)

Example 2 with ConfigValue

use of com.typesafe.config.ConfigValue in project incubator-gobblin by apache.

the class MetricContextFactory method createResource.

@Override
public SharedResourceFactoryResponse<MetricContext> createResource(SharedResourcesBroker<S> broker, ScopedConfigView<S, MetricContextKey> config) throws NotConfiguredException {
    try {
        if (config.getKey() instanceof SubTaggedMetricContextKey) {
            SubTaggedMetricContextKey key = (SubTaggedMetricContextKey) config.getKey();
            MetricContext parent = broker.getSharedResource(this, new MetricContextKey());
            MetricContext.Builder builder = parent.childBuilder(key.getMetricContextName());
            for (Map.Entry<String, String> entry : key.getTags().entrySet()) {
                builder.addTag(new Tag<>(entry.getKey(), entry.getValue()));
            }
            return new ResourceInstance<>(builder.build());
        }
        MetricContext parentMetricContext = RootMetricContext.get();
        Collection<S> parents = config.getScope().parentScopes();
        if (parents != null && !parents.isEmpty()) {
            S parentScope = parents.iterator().next();
            parentMetricContext = broker.getSharedResourceAtScope(this, config.getKey(), parentScope);
        }
        // If this is the root scope, append a UUID to the name. This allows having a separate root context per broker.
        String metricContextName = parents == null ? config.getScope().name() + "_" + UUID.randomUUID().toString() : broker.selfScope().getScopeId();
        MetricContext.Builder builder = parentMetricContext.childBuilder(metricContextName);
        builder.addTag(new Tag<>(config.getScope().name(), broker.getScope(config.getScope()).getScopeId()));
        for (Map.Entry<String, ConfigValue> entry : ConfigUtils.getConfigOrEmpty(config.getConfig(), TAG_KEY).entrySet()) {
            builder.addTag(new Tag<>(entry.getKey(), entry.getValue().unwrapped()));
        }
        return new ResourceInstance<>(builder.build());
    } catch (NoSuchScopeException nsse) {
        throw new RuntimeException("Could not create MetricContext.", nsse);
    }
}
Also used : ConfigValue(com.typesafe.config.ConfigValue) NoSuchScopeException(org.apache.gobblin.broker.iface.NoSuchScopeException) MetricContext(org.apache.gobblin.metrics.MetricContext) RootMetricContext(org.apache.gobblin.metrics.RootMetricContext) ResourceInstance(org.apache.gobblin.broker.ResourceInstance) Map(java.util.Map)

Example 3 with ConfigValue

use of com.typesafe.config.ConfigValue in project incubator-gobblin by apache.

the class FsDatasetStateStore method createStateStore.

protected static DatasetStateStore<JobState.DatasetState> createStateStore(Config config, String className) {
    // Add all job configuration properties so they are picked up by Hadoop
    Configuration conf = new Configuration();
    for (Map.Entry<String, ConfigValue> entry : config.entrySet()) {
        conf.set(entry.getKey(), entry.getValue().unwrapped().toString());
    }
    try {
        String stateStoreFsUri = ConfigUtils.getString(config, ConfigurationKeys.STATE_STORE_FS_URI_KEY, ConfigurationKeys.LOCAL_FS_URI);
        final FileSystem stateStoreFs = FileSystem.get(URI.create(stateStoreFsUri), conf);
        String stateStoreRootDir = config.getString(ConfigurationKeys.STATE_STORE_ROOT_DIR_KEY);
        Integer threadPoolOfGettingDatasetState = ConfigUtils.getInt(config, ConfigurationKeys.THREADPOOL_SIZE_OF_LISTING_FS_DATASET_STATESTORE, ConfigurationKeys.DEFAULT_THREADPOOL_SIZE_OF_LISTING_FS_DATASET_STATESTORE);
        final String datasetUrnStateStoreNameParserClass = ConfigUtils.getString(config, ConfigurationKeys.DATASETURN_STATESTORE_NAME_PARSER, SimpleDatasetUrnStateStoreNameParser.class.getName());
        LoadingCache<Path, DatasetUrnStateStoreNameParser> stateStoreNameParserLoadingCache = CacheBuilder.newBuilder().maximumSize(CACHE_SIZE).build(new CacheLoader<Path, DatasetUrnStateStoreNameParser>() {

            @Override
            public DatasetUrnStateStoreNameParser load(Path stateStoreDirWithStoreName) throws Exception {
                return (DatasetUrnStateStoreNameParser) GobblinConstructorUtils.invokeLongestConstructor(Class.forName(datasetUrnStateStoreNameParserClass), stateStoreFs, stateStoreDirWithStoreName);
            }
        });
        return (DatasetStateStore<JobState.DatasetState>) GobblinConstructorUtils.invokeLongestConstructor(Class.forName(className), stateStoreFs, stateStoreRootDir, threadPoolOfGettingDatasetState, stateStoreNameParserLoadingCache);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (ReflectiveOperationException e) {
        throw new RuntimeException("Failed to instantiate " + className, e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ConfigValue(com.typesafe.config.ConfigValue) Configuration(org.apache.hadoop.conf.Configuration) IOException(java.io.IOException) SimpleDatasetUrnStateStoreNameParser(org.apache.gobblin.metastore.nameParser.SimpleDatasetUrnStateStoreNameParser) DatasetStateStore(org.apache.gobblin.metastore.DatasetStateStore) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) FileSystem(org.apache.hadoop.fs.FileSystem) DatasetUrnStateStoreNameParser(org.apache.gobblin.metastore.nameParser.DatasetUrnStateStoreNameParser) SimpleDatasetUrnStateStoreNameParser(org.apache.gobblin.metastore.nameParser.SimpleDatasetUrnStateStoreNameParser) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 4 with ConfigValue

use of com.typesafe.config.ConfigValue in project incubator-gobblin by apache.

the class ConfigUtils method resolveEncrypted.

/**
 * Resolves encrypted config value(s) by considering on the path with "encConfigPath" as encrypted.
 * (If encConfigPath is absent or encConfigPath does not exist in config, config will be just returned untouched.)
 * It will use Password manager via given config. Thus, convention of PasswordManager need to be followed in order to be decrypted.
 * Note that "encConfigPath" path will be removed from the config key, leaving child path on the config key.
 * e.g:
 *  encConfigPath = enc.conf
 *  - Before : { enc.conf.secret_key : ENC(rOF43721f0pZqAXg#63a) }
 *  - After  : { secret_key : decrypted_val }
 *
 * @param config
 * @param encConfigPath
 * @return
 */
public static Config resolveEncrypted(Config config, Optional<String> encConfigPath) {
    if (!encConfigPath.isPresent() || !config.hasPath(encConfigPath.get())) {
        return config;
    }
    Config encryptedConfig = config.getConfig(encConfigPath.get());
    PasswordManager passwordManager = PasswordManager.getInstance(configToProperties(config));
    Map<String, String> tmpMap = Maps.newHashMap();
    for (Map.Entry<String, ConfigValue> entry : encryptedConfig.entrySet()) {
        String val = entry.getValue().unwrapped().toString();
        val = passwordManager.readPassword(val);
        tmpMap.put(entry.getKey(), val);
    }
    return ConfigFactory.parseMap(tmpMap).withFallback(config);
}
Also used : ConfigValue(com.typesafe.config.ConfigValue) Config(com.typesafe.config.Config) PasswordManager(org.apache.gobblin.password.PasswordManager) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 5 with ConfigValue

use of com.typesafe.config.ConfigValue in project incubator-gobblin by apache.

the class ConfigUtils method configToProperties.

/**
 * Convert a given {@link Config} instance to a {@link Properties} instance.
 *
 * @param config the given {@link Config} instance
 * @param prefix an optional prefix; if present, only properties whose name starts with the prefix
 *        will be returned.
 * @return a {@link Properties} instance
 */
public static Properties configToProperties(Config config, Optional<String> prefix) {
    Properties properties = new Properties();
    if (config != null) {
        Config resolvedConfig = config.resolve();
        for (Map.Entry<String, ConfigValue> entry : resolvedConfig.entrySet()) {
            if (!prefix.isPresent() || entry.getKey().startsWith(prefix.get())) {
                String propKey = desanitizeKey(entry.getKey());
                properties.setProperty(propKey, resolvedConfig.getString(entry.getKey()));
            }
        }
    }
    return properties;
}
Also used : ConfigValue(com.typesafe.config.ConfigValue) Config(com.typesafe.config.Config) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

ConfigValue (com.typesafe.config.ConfigValue)36 Map (java.util.Map)19 Config (com.typesafe.config.Config)11 ConfigException (com.typesafe.config.ConfigException)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 ConfigList (com.typesafe.config.ConfigList)5 ConfigObject (com.typesafe.config.ConfigObject)5 ImmutableMap (com.google.common.collect.ImmutableMap)3 BigInteger (java.math.BigInteger)3 Properties (java.util.Properties)3 Configuration (org.apache.hadoop.conf.Configuration)3 IOException (java.io.IOException)2 FileSystem (org.apache.hadoop.fs.FileSystem)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 ConfigOrigin (com.typesafe.config.ConfigOrigin)1 ConfigValueType (com.typesafe.config.ConfigValueType)1