use of org.apache.samza.config.ConfigLoaderFactory in project samza by apache.
the class ConfigUtil method loadConfig.
/**
* Load full job config with {@link ConfigLoaderFactory} when present.
*
* @param original config
* @return full job config
*/
public static Config loadConfig(Config original) {
JobConfig jobConfig = new JobConfig(original);
if (!jobConfig.getConfigLoaderFactory().isPresent()) {
throw new ConfigException("Missing key " + JobConfig.CONFIG_LOADER_FACTORY + ".");
}
ConfigLoaderFactory factory = ReflectionUtil.getObj(jobConfig.getConfigLoaderFactory().get(), ConfigLoaderFactory.class);
ConfigLoader loader = factory.getLoader(original.subset(ConfigLoaderFactory.CONFIG_LOADER_PROPERTIES_PREFIX));
// overrides config loaded with original config, which may contain overridden values.
return rewriteConfig(override(loader.getConfig(), original));
}
use of org.apache.samza.config.ConfigLoaderFactory in project beam by apache.
the class ConfigBuilder method createUserConfig.
private static Map<String, String> createUserConfig(SamzaPipelineOptions options) throws Exception {
final Map<String, String> config = new HashMap<>();
// apply user configs
final String configFilePath = options.getConfigFilePath();
// If user provides a config file, use it as base configs.
if (StringUtils.isNoneEmpty(configFilePath)) {
LOG.info("configFilePath: " + configFilePath);
final Config properties = new MapConfig(Collections.singletonMap("path", configFilePath));
final ConfigLoaderFactory configLoaderFactory = options.getConfigLoaderFactory().getDeclaredConstructor().newInstance();
LOG.info("configLoaderFactory: " + configLoaderFactory.getClass().getName());
// pass the command-line args through the containers
if (configLoaderFactory instanceof PropertiesConfigLoaderFactory) {
checkArgument(new File(configFilePath).exists(), "Config file %s does not exist", configFilePath);
}
config.putAll(configLoaderFactory.getLoader(properties).getConfig());
}
// Apply override on top
if (options.getConfigOverride() != null) {
config.putAll(options.getConfigOverride());
}
return config;
}
Aggregations