@Override public ScopedConfigView<S, K> getScopedView(S scopeType) { return new KeyedScopedConfigViewImpl<>(scopeType, this.key, this.factoryName, this.fullConfig); }
@Override public Config getConfig() { return getKeyedScopedConfig().withFallback(getKeyedConfig()).withFallback(getScopedConfig()).withFallback(getFactorySpecificConfig()); }
@Test public void test() { String key = "myKey"; // Correct creation behavior Config config = ConfigFactory.parseMap(ImmutableMap.<String, String>builder() .put("key1", "value1") .put("key2", "value2") .put(JOINER.join(key, "key2"), "value2key") .put(JOINER.join(GobblinScopeTypes.JOB.name(), "key2"), "value2scope") .put(JOINER.join(GobblinScopeTypes.JOB.name(), key, "key2"), "value2scopekey") .build()); KeyedScopedConfigViewImpl<GobblinScopeTypes, TestResourceKey> configView = new KeyedScopedConfigViewImpl<>(GobblinScopeTypes.JOB, new TestResourceKey(key), TestFactory.NAME, config); Assert.assertEquals(configView.getScope(), GobblinScopeTypes.JOB); Assert.assertEquals(configView.getKey().toConfigurationKey(), key); Assert.assertEquals(configView.getKeyedConfig().getString("key2"), "value2key"); Assert.assertEquals(configView.getScopedConfig().getString("key2"), "value2scope"); Assert.assertEquals(configView.getKeyedScopedConfig().getString("key2"), "value2scopekey"); Assert.assertEquals(configView.getFactorySpecificConfig().getString("key1"), "value1"); Assert.assertEquals(configView.getFactorySpecificConfig().getString("key2"), "value2"); Assert.assertEquals(configView.getConfig().getString("key2"), "value2scopekey"); Assert.assertEquals(configView.getConfig().getString("key1"), "value1"); }
public Config getKeyedScopedConfig() { if (this.scope == null || this.key.toConfigurationKey() == null) { return ConfigFactory.empty(); } return ConfigUtils.getConfigOrEmpty(this.fullConfig, chainConfigKeys(this.scope.name(), this.key.toConfigurationKey())); }
@Test public void testCorrectConfigInjection() { String key = "myKey"; Config config = ConfigFactory.parseMap(ImmutableMap.of( JOINER.join(BrokerConstants.GOBBLIN_BROKER_CONFIG_PREFIX, TestFactory.NAME, "key1"), "value1", JOINER.join(BrokerConstants.GOBBLIN_BROKER_CONFIG_PREFIX, TestFactory.NAME, "key2"), "value2", JOINER.join(BrokerConstants.GOBBLIN_BROKER_CONFIG_PREFIX, TestFactory.NAME, GobblinScopeTypes.CONTAINER.name(), "key2"), "value2scope", JOINER.join(BrokerConstants.GOBBLIN_BROKER_CONFIG_PREFIX, TestFactory.NAME, key, "key2"), "value2key", JOINER.join(BrokerConstants.GOBBLIN_BROKER_CONFIG_PREFIX, TestFactory.NAME, GobblinScopeTypes.CONTAINER.name(), key, "key2"), "value2scopekey" )); SharedResourcesBrokerImpl<GobblinScopeTypes> topBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config, GobblinScopeTypes.GLOBAL.defaultScopeInstance()); KeyedScopedConfigViewImpl<GobblinScopeTypes, TestResourceKey> configView = topBroker.getConfigView(GobblinScopeTypes.CONTAINER, new TestResourceKey(key), TestFactory.NAME); Assert.assertEquals(configView.getScope(), GobblinScopeTypes.CONTAINER); Assert.assertEquals(configView.getKey().toConfigurationKey(), key); Assert.assertEquals(configView.getKeyedConfig().getString("key2"), "value2key"); Assert.assertEquals(configView.getScopedConfig().getString("key2"), "value2scope"); Assert.assertEquals(configView.getKeyedScopedConfig().getString("key2"), "value2scopekey"); Assert.assertEquals(configView.getFactorySpecificConfig().getString("key1"), "value1"); Assert.assertEquals(configView.getFactorySpecificConfig().getString("key2"), "value2"); Assert.assertEquals(configView.getConfig().getString("key2"), "value2scopekey"); Assert.assertEquals(configView.getConfig().getString("key1"), "value1"); configView = topBroker.getConfigView(GobblinScopeTypes.TASK, new TestResourceKey(key), TestFactory.NAME); Assert.assertEquals(configView.getConfig().getString("key2"), "value2key"); }
public Config getKeyedScopedConfig() { if (this.scope == null || this.key.toConfigurationKey() == null) { return ConfigFactory.empty(); } return ConfigUtils.getConfigOrEmpty(this.fullConfig, chainConfigKeys(this.scope.name(), this.key.toConfigurationKey())); }
@Override public Config getConfig() { return getKeyedScopedConfig().withFallback(getKeyedConfig()).withFallback(getScopedConfig()).withFallback(getFactorySpecificConfig()); }
/** * Get a {@link org.apache.gobblin.broker.iface.ConfigView} for the input scope, key, and factory. */ public <K extends SharedResourceKey> KeyedScopedConfigViewImpl<S, K> getConfigView(S scope, K key, String factoryName) { Config config = ConfigFactory.empty(); for (ScopedConfig<S> scopedConfig : this.scopedConfigs) { if (scopedConfig.getScopeType().equals(scopedConfig.getScopeType().rootScope())) { config = ConfigUtils.getConfigOrEmpty(scopedConfig.getConfig(), factoryName).withFallback(config); } else if (scope != null && SharedResourcesBrokerUtils.isScopeTypeAncestor(scope, scopedConfig.getScopeType())) { Config tmpConfig = ConfigUtils.getConfigOrEmpty(scopedConfig.getConfig(), factoryName); tmpConfig = ConfigUtils.getConfigOrEmpty(tmpConfig, scope.name()); config = tmpConfig.atKey(scope.name()).withFallback(config); } } return new KeyedScopedConfigViewImpl<>(scope, key, factoryName, config); }
@Override public ScopedConfigView<S, K> getScopedView(S scopeType) { return new KeyedScopedConfigViewImpl<>(scopeType, this.key, this.factoryName, this.fullConfig); }
/** * Get a {@link org.apache.gobblin.broker.iface.ConfigView} for the input scope, key, and factory. */ public <K extends SharedResourceKey> KeyedScopedConfigViewImpl<S, K> getConfigView(S scope, K key, String factoryName) { Config config = ConfigFactory.empty(); for (ScopedConfig<S> scopedConfig : this.scopedConfigs) { if (scopedConfig.getScopeType().equals(scopedConfig.getScopeType().rootScope())) { config = ConfigUtils.getConfigOrEmpty(scopedConfig.getConfig(), factoryName).withFallback(config); } else if (scope != null && SharedResourcesBrokerUtils.isScopeTypeAncestor(scope, scopedConfig.getScopeType())) { Config tmpConfig = ConfigUtils.getConfigOrEmpty(scopedConfig.getConfig(), factoryName); tmpConfig = ConfigUtils.getConfigOrEmpty(tmpConfig, scope.name()); config = tmpConfig.atKey(scope.name()).withFallback(config); } } return new KeyedScopedConfigViewImpl<>(scope, key, factoryName, config); }