Search in sources :

Example 1 with ConfigKeyPath

use of org.apache.gobblin.config.store.api.ConfigKeyPath in project incubator-gobblin by apache.

the class ConfigClient method getImports.

public Collection<URI> getImports(URI configKeyUri, boolean recursive, Optional<Config> runtimeConfig) throws ConfigStoreFactoryDoesNotExistsException, ConfigStoreCreationException, VersionDoesNotExistException {
    ConfigStoreAccessor accessor = this.getConfigStoreAccessor(configKeyUri);
    ConfigKeyPath configKeypath = ConfigClientUtils.buildConfigKeyPath(configKeyUri, accessor.configStore);
    Collection<ConfigKeyPath> result;
    if (!recursive) {
        result = accessor.topologyInspector.getOwnImports(configKeypath, runtimeConfig);
    } else {
        result = accessor.topologyInspector.getImportsRecursively(configKeypath, runtimeConfig);
    }
    return ConfigClientUtils.buildUriInClientFormat(result, accessor.configStore, configKeyUri.getAuthority() != null);
}
Also used : ConfigKeyPath(org.apache.gobblin.config.store.api.ConfigKeyPath)

Example 2 with ConfigKeyPath

use of org.apache.gobblin.config.store.api.ConfigKeyPath in project incubator-gobblin by apache.

the class ConfigClient method getConfigs.

/**
 * batch process for {@link #getConfig(URI)} method
 * @param configKeyUris
 * @return
 * @throws ConfigStoreFactoryDoesNotExistsException
 * @throws ConfigStoreCreationException
 * @throws VersionDoesNotExistException
 */
public Map<URI, Config> getConfigs(Collection<URI> configKeyUris) throws ConfigStoreFactoryDoesNotExistsException, ConfigStoreCreationException, VersionDoesNotExistException {
    if (configKeyUris == null || configKeyUris.size() == 0)
        return Collections.emptyMap();
    Map<URI, Config> result = new HashMap<>();
    Multimap<ConfigStoreAccessor, ConfigKeyPath> partitionedAccessor = ArrayListMultimap.create();
    // map contains the mapping between ConfigKeyPath back to original URI , partitioned by ConfigStoreAccessor
    Map<ConfigStoreAccessor, Map<ConfigKeyPath, URI>> reverseMap = new HashMap<>();
    // partitioned the ConfigKeyPaths which belongs to the same store to one accessor
    for (URI u : configKeyUris) {
        ConfigStoreAccessor accessor = this.getConfigStoreAccessor(u);
        ConfigKeyPath configKeypath = ConfigClientUtils.buildConfigKeyPath(u, accessor.configStore);
        partitionedAccessor.put(accessor, configKeypath);
        if (!reverseMap.containsKey(accessor)) {
            reverseMap.put(accessor, new HashMap<ConfigKeyPath, URI>());
        }
        reverseMap.get(accessor).put(configKeypath, u);
    }
    for (Map.Entry<ConfigStoreAccessor, Collection<ConfigKeyPath>> entry : partitionedAccessor.asMap().entrySet()) {
        Map<ConfigKeyPath, Config> batchResult = entry.getKey().valueInspector.getResolvedConfigs(entry.getValue());
        for (Map.Entry<ConfigKeyPath, Config> resultEntry : batchResult.entrySet()) {
            // get the original URI from reverseMap
            URI orgURI = reverseMap.get(entry.getKey()).get(resultEntry.getKey());
            result.put(orgURI, resultEntry.getValue());
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Config(com.typesafe.config.Config) URI(java.net.URI) Collection(java.util.Collection) ConfigKeyPath(org.apache.gobblin.config.store.api.ConfigKeyPath) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 3 with ConfigKeyPath

use of org.apache.gobblin.config.store.api.ConfigKeyPath in project incubator-gobblin by apache.

the class TestCircularDependency method testLoops.

@Test
public void testLoops() {
    ConfigKeyPath tag = SingleLinkedListConfigKeyPath.ROOT.createChild("tag");
    ConfigKeyPath subTag1 = tag.createChild("subTag1");
    ConfigKeyPath subTag2 = tag.createChild("subTag2");
    ConfigKeyPath subTag3 = tag.createChild("subTag3");
    ConfigStore mockConfigStore = mock(ConfigStore.class, Mockito.RETURNS_SMART_NULLS);
    when(mockConfigStore.getCurrentVersion()).thenReturn(version);
    addConfigStoreChildren(mockConfigStore, version, SingleLinkedListConfigKeyPath.ROOT, tag);
    addConfigStoreChildren(mockConfigStore, version, tag, subTag1, subTag2, subTag3);
    // self import descendant
    // formed loop /tag/subTag1 -> /tag/subTag2 -> /tag/subTag3 -> /tag/subTag1
    addConfigStoreImports(mockConfigStore, version, subTag1, subTag2);
    addConfigStoreImports(mockConfigStore, version, subTag2, subTag3);
    addConfigStoreImports(mockConfigStore, version, subTag3, subTag1);
    ConfigStoreBackedTopology csTopology = new ConfigStoreBackedTopology(mockConfigStore, this.version);
    InMemoryTopology inMemory = new InMemoryTopology(csTopology);
    try {
        inMemory.getImportsRecursively(subTag1);
        Assert.fail("Did not catch expected CircularDependencyException");
    } catch (CircularDependencyException e) {
        Assert.assertTrue(e.getMessage().indexOf("/tag/subTag1") > 0 && e.getMessage().indexOf("/tag/subTag2") > 0 && e.getMessage().indexOf("/tag/subTag3") > 0);
    }
}
Also used : ConfigStore(org.apache.gobblin.config.store.api.ConfigStore) ConfigKeyPath(org.apache.gobblin.config.store.api.ConfigKeyPath) Test(org.testng.annotations.Test)

Example 4 with ConfigKeyPath

use of org.apache.gobblin.config.store.api.ConfigKeyPath in project incubator-gobblin by apache.

the class TestCircularDependency method addConfigStoreChildren.

private static void addConfigStoreChildren(ConfigStore mockup, String version, ConfigKeyPath parent, ConfigKeyPath... configKeyPaths) {
    List<ConfigKeyPath> children = new ArrayList<ConfigKeyPath>();
    for (ConfigKeyPath p : configKeyPaths) {
        children.add(p);
    }
    when(mockup.getChildren(parent, version)).thenReturn(children);
}
Also used : ArrayList(java.util.ArrayList) ConfigKeyPath(org.apache.gobblin.config.store.api.ConfigKeyPath)

Example 5 with ConfigKeyPath

use of org.apache.gobblin.config.store.api.ConfigKeyPath in project incubator-gobblin by apache.

the class TestCircularDependency method testSelfImportDescendant.

@Test
public void testSelfImportDescendant() {
    ConfigKeyPath tag = SingleLinkedListConfigKeyPath.ROOT.createChild("tag");
    ConfigKeyPath highPriorityTag = tag.createChild("highPriorityTag");
    ConfigKeyPath nertzHighPriorityTag = highPriorityTag.createChild("nertzHighPriorityTag");
    ConfigStore mockConfigStore = mock(ConfigStore.class, Mockito.RETURNS_SMART_NULLS);
    when(mockConfigStore.getCurrentVersion()).thenReturn(version);
    addConfigStoreChildren(mockConfigStore, version, SingleLinkedListConfigKeyPath.ROOT, tag);
    addConfigStoreChildren(mockConfigStore, version, tag, highPriorityTag);
    addConfigStoreChildren(mockConfigStore, version, highPriorityTag, nertzHighPriorityTag);
    // self import descendant
    // formed the loop /tag -> /tag/highPriorityTag/nertzHighPriorityTag -> /tag/highPriorityTag -> /tag
    addConfigStoreImports(mockConfigStore, version, tag, nertzHighPriorityTag);
    ConfigStoreBackedTopology csTopology = new ConfigStoreBackedTopology(mockConfigStore, this.version);
    InMemoryTopology inMemory = new InMemoryTopology(csTopology);
    try {
        inMemory.getImportsRecursively(tag);
        Assert.fail("Did not catch expected CircularDependencyException");
    } catch (CircularDependencyException e) {
        Assert.assertTrue(e.getMessage().indexOf("/tag/highPriorityTag/nertzHighPriorityTag") > 0 && e.getMessage().indexOf("/tag/highPriorityTag ") > 0 && e.getMessage().indexOf("/tag ") > 0);
    }
}
Also used : ConfigStore(org.apache.gobblin.config.store.api.ConfigStore) ConfigKeyPath(org.apache.gobblin.config.store.api.ConfigKeyPath) Test(org.testng.annotations.Test)

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