use of org.apache.gobblin.config.store.api.ConfigKeyPath in project incubator-gobblin by apache.
the class ConfigClientUtils method getConfigKeyPath.
/**
* Build the {@link ConfigKeyPath} based on the absolute/relative path
* @param input - absolute/relative file path
* @return - {@link ConfigKeyPath} corresponding to the input
*/
public static ConfigKeyPath getConfigKeyPath(String input) {
ConfigKeyPath result = SingleLinkedListConfigKeyPath.ROOT;
String[] paths = input.split("/");
for (String p : paths) {
// in case input start with "/", some elements could be "", which should be skip
if (p.equals("")) {
continue;
}
result = result.createChild(p);
}
return result;
}
use of org.apache.gobblin.config.store.api.ConfigKeyPath in project incubator-gobblin by apache.
the class ZipFileConfigStore method getOwnImports.
public List<ConfigKeyPath> getOwnImports(ConfigKeyPath configKey, String version, Optional<Config> runtimeConfig) throws VersionDoesNotExistException {
Preconditions.checkNotNull(configKey, "configKey cannot be null!");
Preconditions.checkArgument(version.equals(getCurrentVersion()));
List<ConfigKeyPath> configKeyPaths = new ArrayList<>();
Path datasetDir = getDatasetDirForKey(configKey);
Path includesFile = this.fs.getPath(datasetDir.toString(), SimpleHadoopFilesystemConfigStore.INCLUDES_CONF_FILE_NAME);
try {
if (!Files.exists(includesFile)) {
return configKeyPaths;
}
if (!Files.isDirectory(includesFile)) {
try (InputStream includesConfInStream = Files.newInputStream(includesFile)) {
configKeyPaths = SimpleHadoopFilesystemConfigStore.getResolvedConfigKeyPaths(includesConfInStream, runtimeConfig);
}
}
} catch (IOException e) {
throw new RuntimeException(String.format("Error while getting config for configKey: \"%s\"", configKey), e);
}
return configKeyPaths;
}
use of org.apache.gobblin.config.store.api.ConfigKeyPath in project incubator-gobblin by apache.
the class ZipFileConfigStore method getChildren.
/**
* Retrieves all the children of the given {@link ConfigKeyPath} using {@link Files#walk} to list files
*/
@Override
public Collection<ConfigKeyPath> getChildren(ConfigKeyPath configKey, String version) throws VersionDoesNotExistException {
Preconditions.checkNotNull(configKey, "configKey cannot be null!");
Preconditions.checkArgument(version.equals(getCurrentVersion()));
List<ConfigKeyPath> children = new ArrayList<>();
Path datasetDir = getDatasetDirForKey(configKey);
try {
if (!Files.exists(this.fs.getPath(datasetDir.toString()))) {
throw new PhysicalPathNotExistException(this.logicalStoreRoot, "Cannot find physical location:" + this.fs.getPath(datasetDir.toString()));
}
Stream<Path> files = Files.walk(datasetDir, 1);
for (Iterator<Path> it = files.iterator(); it.hasNext(); ) {
Path path = it.next();
if (Files.isDirectory(path) && !path.equals(datasetDir)) {
children.add(configKey.createChild(StringUtils.removeEnd(path.getName(path.getNameCount() - 1).toString(), SingleLinkedListConfigKeyPath.PATH_DELIMETER)));
}
}
return children;
} catch (IOException e) {
throw new RuntimeException(String.format("Error while getting children for configKey: \"%s\"", configKey), e);
}
}
use of org.apache.gobblin.config.store.api.ConfigKeyPath in project incubator-gobblin by apache.
the class TestConfigStoreValueInspector method testSystemPropertyResolution.
@Test
public void testSystemPropertyResolution() {
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 testConfigKeyPath = SingleLinkedListConfigKeyPath.ROOT.createChild("a");
when(mockConfigStore.getOwnConfig(testConfigKeyPath.getParent(), version)).thenReturn(ConfigFactory.empty());
when(mockConfigStore.getOwnConfig(testConfigKeyPath, version)).thenReturn(ConfigFactory.parseString("configProp = ${?" + VALUE_INSPECTOR_SYS_PROP_KEY + "}"));
Assert.assertEquals(valueInspector.getResolvedConfig(testConfigKeyPath).getString("configProp"), VALUE_INSPECTOR_SYS_PROP_VALUE);
}
use of org.apache.gobblin.config.store.api.ConfigKeyPath in project incubator-gobblin by apache.
the class TestSingleLinkedListConfigKeyPath method testHash.
@Test
public void testHash() {
ConfigKeyPath data = SingleLinkedListConfigKeyPath.ROOT.createChild("data");
ConfigKeyPath profile1 = data.createChild("databases").createChild("identity").createChild("profile");
ConfigKeyPath profile2 = data.createChild("databases").createChild("identity").createChild("profile");
Assert.assertFalse(profile1 == profile2);
Assert.assertTrue(profile1.equals(profile2));
Assert.assertEquals(profile1.hashCode(), profile2.hashCode());
Set<ConfigKeyPath> testSet = new HashSet<ConfigKeyPath>();
testSet.add(profile1);
Assert.assertTrue(testSet.contains(profile2));
}
Aggregations