use of org.apache.gobblin.config.store.api.ConfigKeyPath in project incubator-gobblin by apache.
the class ZipFileConfigStore method getOwnConfig.
/**
* Retrieves the {@link Config} for the given {@link ConfigKeyPath}. Similar to
* {@link SimpleHadoopFilesystemConfigStore#getOwnConfig}
*/
@Override
public Config getOwnConfig(ConfigKeyPath configKey, String version) throws VersionDoesNotExistException {
Preconditions.checkNotNull(configKey, "configKey cannot be null!");
Preconditions.checkArgument(version.equals(getCurrentVersion()));
Path datasetDir = getDatasetDirForKey(configKey);
Path mainConfFile = this.fs.getPath(datasetDir.toString(), SimpleHadoopFilesystemConfigStore.MAIN_CONF_FILE_NAME);
try {
if (!Files.exists(mainConfFile)) {
return ConfigFactory.empty();
}
if (!Files.isDirectory(mainConfFile)) {
try (InputStream mainConfInputStream = Files.newInputStream(mainConfFile)) {
return ConfigFactory.parseReader(new InputStreamReader(mainConfInputStream, Charsets.UTF_8));
}
}
return ConfigFactory.empty();
} catch (IOException e) {
throw new RuntimeException(String.format("Error while getting config for configKey: \"%s\"", configKey), e);
}
}
use of org.apache.gobblin.config.store.api.ConfigKeyPath in project incubator-gobblin by apache.
the class TestConfigStoreValueInspector method testResolveConfigOverridingInChild.
@Test
public void testResolveConfigOverridingInChild() {
ConfigStore mockConfigStore = mock(ConfigStore.class, Mockito.RETURNS_SMART_NULLS);
when(mockConfigStore.getCurrentVersion()).thenReturn(version);
ConfigStoreTopologyInspector mockTopology = mock(ConfigStoreTopologyInspector.class, Mockito.RETURNS_SMART_NULLS);
ConfigStoreBackedValueInspector valueInspector = new ConfigStoreBackedValueInspector(mockConfigStore, version, mockTopology);
ConfigKeyPath keyPathA = SingleLinkedListConfigKeyPath.ROOT.createChild("a");
ConfigKeyPath keyPathA_Slash_B = keyPathA.createChild("b");
when(mockConfigStore.getOwnConfig(keyPathA.getParent(), version)).thenReturn(ConfigFactory.empty());
when(mockConfigStore.getOwnConfig(keyPathA, version)).thenReturn(ConfigFactory.parseString("key1 = value1InA \n key2 = ${key1}"));
when(mockConfigStore.getOwnConfig(keyPathA_Slash_B, version)).thenReturn(ConfigFactory.parseString("key1 = value1InB"));
Assert.assertEquals(valueInspector.getResolvedConfig(keyPathA_Slash_B).getString("key2"), "value1InB");
}
use of org.apache.gobblin.config.store.api.ConfigKeyPath in project incubator-gobblin by apache.
the class TestSingleLinkedListConfigKeyPath method testNonRoot.
@Test
public void testNonRoot() {
ConfigKeyPath data = SingleLinkedListConfigKeyPath.ROOT.createChild("data");
Assert.assertEquals(data.getAbsolutePathString(), "/data");
ConfigKeyPath profile = data.createChild("databases").createChild("identity").createChild("profile");
Assert.assertEquals(profile.toString(), "/data/databases/identity/profile");
}
use of org.apache.gobblin.config.store.api.ConfigKeyPath in project incubator-gobblin by apache.
the class InMemoryValueInspector method getOwnConfigs.
/**
* {@inheritDoc}.
*
* <p>
* If present in the cache, return the cached {@link com.typesafe.config.Config} for given input
* Otherwise, simply delegate the functionality to the internal {ConfigStoreValueInspector} and store the value into cache
* </p>
*/
@Override
public Map<ConfigKeyPath, Config> getOwnConfigs(Collection<ConfigKeyPath> configKeys) {
Collection<ConfigKeyPath> configKeysNotInCache = new ArrayList<>();
Map<ConfigKeyPath, Config> result = new HashMap<>();
for (ConfigKeyPath configKey : configKeys) {
Config cachedValue = this.ownConfigCache.getIfPresent(configKey);
if (cachedValue == null) {
configKeysNotInCache.add(configKey);
} else {
result.put(configKey, cachedValue);
}
}
// for ConfigKeyPath which are not in cache
if (configKeysNotInCache.size() > 0) {
Map<ConfigKeyPath, Config> configsFromFallBack = this.valueFallback.getOwnConfigs(configKeysNotInCache);
this.ownConfigCache.putAll(configsFromFallBack);
result.putAll(configsFromFallBack);
}
return result;
}
use of org.apache.gobblin.config.store.api.ConfigKeyPath in project incubator-gobblin by apache.
the class InMemoryTopology method computeImportedByMap.
private synchronized void computeImportedByMap(Optional<Config> runtimeConfig) {
if (this.fullImportedByMap != null) {
return;
}
ImmutableMultimap.Builder<ConfigKeyPath, ConfigKeyPath> importedByBuilder = ImmutableMultimap.builder();
// breath first search the whole topology to build ownImports map and ownImportedByMap
// calls to retrieve cache / set cache if not present
Collection<ConfigKeyPath> currentLevel = this.getChildren(SingleLinkedListConfigKeyPath.ROOT);
List<ConfigKeyPath> rootImports = this.getOwnImports(SingleLinkedListConfigKeyPath.ROOT, runtimeConfig);
Preconditions.checkArgument(rootImports == null || rootImports.size() == 0, "Root can not import other nodes, otherwise circular dependency will happen");
while (!currentLevel.isEmpty()) {
Collection<ConfigKeyPath> nextLevel = new ArrayList<>();
for (ConfigKeyPath configKeyPath : currentLevel) {
// calls to retrieve cache / set cache if not present
List<ConfigKeyPath> ownImports = this.getOwnImports(configKeyPath, runtimeConfig);
this.ownImportMap.put(configKeyPath, ownImports);
for (ConfigKeyPath importedPath : ownImports) {
importedByBuilder.put(importedPath, configKeyPath);
}
// calls to retrieve cache / set cache if not present
Collection<ConfigKeyPath> tmp = this.getChildren(configKeyPath);
nextLevel.addAll(tmp);
}
currentLevel = nextLevel;
}
this.fullImportedByMap = importedByBuilder.build();
}
Aggregations