Search in sources :

Example 11 with ConfigKeyPath

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);
    }
}
Also used : SingleLinkedListConfigKeyPath(org.apache.gobblin.config.common.impl.SingleLinkedListConfigKeyPath) Path(java.nio.file.Path) ConfigKeyPath(org.apache.gobblin.config.store.api.ConfigKeyPath) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 12 with ConfigKeyPath

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");
}
Also used : ConfigStore(org.apache.gobblin.config.store.api.ConfigStore) ConfigKeyPath(org.apache.gobblin.config.store.api.ConfigKeyPath) Test(org.testng.annotations.Test)

Example 13 with ConfigKeyPath

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");
}
Also used : ConfigKeyPath(org.apache.gobblin.config.store.api.ConfigKeyPath) Test(org.testng.annotations.Test)

Example 14 with ConfigKeyPath

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;
}
Also used : HashMap(java.util.HashMap) Config(com.typesafe.config.Config) ArrayList(java.util.ArrayList) ConfigKeyPath(org.apache.gobblin.config.store.api.ConfigKeyPath)

Example 15 with ConfigKeyPath

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();
}
Also used : ArrayList(java.util.ArrayList) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) ConfigKeyPath(org.apache.gobblin.config.store.api.ConfigKeyPath)

Aggregations

ConfigKeyPath (org.apache.gobblin.config.store.api.ConfigKeyPath)37 Test (org.testng.annotations.Test)18 SingleLinkedListConfigKeyPath (org.apache.gobblin.config.common.impl.SingleLinkedListConfigKeyPath)15 ArrayList (java.util.ArrayList)10 Path (org.apache.hadoop.fs.Path)9 ConfigStore (org.apache.gobblin.config.store.api.ConfigStore)8 Config (com.typesafe.config.Config)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)4 URI (java.net.URI)4 HashMap (java.util.HashMap)4 BufferedWriter (java.io.BufferedWriter)3 OutputStreamWriter (java.io.OutputStreamWriter)3 Path (java.nio.file.Path)3 FileStatus (org.apache.hadoop.fs.FileStatus)3 InputStreamReader (java.io.InputStreamReader)2 HashSet (java.util.HashSet)2 FsDeploymentConfig (org.apache.gobblin.config.store.deploy.FsDeploymentConfig)2 SeekableFSInputStream (org.apache.gobblin.util.io.SeekableFSInputStream)2 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1