Search in sources :

Example 1 with PhysicalPathNotExistException

use of org.apache.gobblin.config.store.api.PhysicalPathNotExistException 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)

Aggregations

IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 SingleLinkedListConfigKeyPath (org.apache.gobblin.config.common.impl.SingleLinkedListConfigKeyPath)1 ConfigKeyPath (org.apache.gobblin.config.store.api.ConfigKeyPath)1 PhysicalPathNotExistException (org.apache.gobblin.config.store.api.PhysicalPathNotExistException)1