@Override public ScopedConfigView<S, K> getScopedView(S scopeType) { return new KeyedScopedConfigViewImpl<>(scopeType, this.key, this.factoryName, this.fullConfig); }
@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"); }
/** * 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); }