Search in sources :

Example 16 with ConfigKeyPath

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;
}
Also used : ConfigKeyPath(org.apache.gobblin.config.store.api.ConfigKeyPath) SingleLinkedListConfigKeyPath(org.apache.gobblin.config.common.impl.SingleLinkedListConfigKeyPath)

Example 17 with ConfigKeyPath

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

Example 18 with ConfigKeyPath

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

Example 19 with ConfigKeyPath

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

Example 20 with ConfigKeyPath

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