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);
}
}
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);
}
}
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);
}
}
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);
}
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;
}
Aggregations