Search in sources :

Example 1 with ConfigLoaderFactory

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));
}
Also used : ConfigLoader(org.apache.samza.config.ConfigLoader) ConfigLoaderFactory(org.apache.samza.config.ConfigLoaderFactory) ConfigException(org.apache.samza.config.ConfigException) JobConfig(org.apache.samza.config.JobConfig)

Example 2 with ConfigLoaderFactory

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;
}
Also used : PropertiesConfigLoaderFactory(org.apache.samza.config.loaders.PropertiesConfigLoaderFactory) HashMap(java.util.HashMap) ApplicationConfig(org.apache.samza.config.ApplicationConfig) MapConfig(org.apache.samza.config.MapConfig) ZkConfig(org.apache.samza.config.ZkConfig) JobCoordinatorConfig(org.apache.samza.config.JobCoordinatorConfig) Config(org.apache.samza.config.Config) ConfigLoaderFactory(org.apache.samza.config.ConfigLoaderFactory) PropertiesConfigLoaderFactory(org.apache.samza.config.loaders.PropertiesConfigLoaderFactory) MapConfig(org.apache.samza.config.MapConfig) File(java.io.File)

Aggregations

ConfigLoaderFactory (org.apache.samza.config.ConfigLoaderFactory)2 File (java.io.File)1 HashMap (java.util.HashMap)1 ApplicationConfig (org.apache.samza.config.ApplicationConfig)1 Config (org.apache.samza.config.Config)1 ConfigException (org.apache.samza.config.ConfigException)1 ConfigLoader (org.apache.samza.config.ConfigLoader)1 JobConfig (org.apache.samza.config.JobConfig)1 JobCoordinatorConfig (org.apache.samza.config.JobCoordinatorConfig)1 MapConfig (org.apache.samza.config.MapConfig)1 ZkConfig (org.apache.samza.config.ZkConfig)1 PropertiesConfigLoaderFactory (org.apache.samza.config.loaders.PropertiesConfigLoaderFactory)1