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);
}
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;
}
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);
}
}
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);
}
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);
}
}
Aggregations