Search in sources :

Example 66 with LocatedFileStatus

use of org.apache.hadoop.fs.LocatedFileStatus in project SpyGlass by ParallelAI.

the class JobLibLoader method loadJars.

public static void loadJars(String libPathStr, Configuration config) {
    try {
        Path libPath = new Path(libPathStr);
        FileSystem fs = FileSystem.get(config);
        RemoteIterator<LocatedFileStatus> itr = fs.listFiles(libPath, true);
        while (itr.hasNext()) {
            LocatedFileStatus f = itr.next();
            if (!f.isDirectory() && f.getPath().getName().endsWith("jar")) {
                logger.info("Loading Jar : " + f.getPath().getName());
                DistributedCache.addFileToClassPath(f.getPath(), config);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(e.toString());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus)

Example 67 with LocatedFileStatus

use of org.apache.hadoop.fs.LocatedFileStatus in project presto by prestodb.

the class BackgroundHiveSplitLoader method loadSplits.

private CompletableFuture<?> loadSplits() throws IOException {
    HiveFileIterator files = fileIterators.poll();
    if (files == null) {
        HivePartitionMetadata partition = partitions.poll();
        if (partition == null) {
            return COMPLETED_FUTURE;
        }
        loadPartition(partition);
        return COMPLETED_FUTURE;
    }
    while (files.hasNext() && !stopped) {
        LocatedFileStatus file = files.next();
        if (isDirectory(file)) {
            if (recursiveDirWalkerEnabled) {
                HiveFileIterator fileIterator = new HiveFileIterator(file.getPath(), files.getFileSystem(), files.getDirectoryLister(), files.getNamenodeStats(), files.getPartitionName(), files.getInputFormat(), files.getSchema(), files.getPartitionKeys(), files.getEffectivePredicate(), files.getColumnCoercions());
                fileIterators.add(fileIterator);
            }
        } else {
            boolean splittable = isSplittable(files.getInputFormat(), hdfsEnvironment.getFileSystem(session.getUser(), file.getPath()), file.getPath());
            CompletableFuture<?> future = hiveSplitSource.addToQueue(createHiveSplitIterator(files.getPartitionName(), file.getPath().toString(), file.getBlockLocations(), 0, file.getLen(), files.getSchema(), files.getPartitionKeys(), splittable, session, OptionalInt.empty(), files.getEffectivePredicate(), files.getColumnCoercions()));
            if (!future.isDone()) {
                fileIterators.addFirst(files);
                return future;
            }
        }
    }
    // No need to put the iterator back, since it's either empty or we've stopped
    return COMPLETED_FUTURE;
}
Also used : HiveFileIterator(com.facebook.presto.hive.util.HiveFileIterator) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus)

Example 68 with LocatedFileStatus

use of org.apache.hadoop.fs.LocatedFileStatus in project apex-core by apache.

the class RecordingsAgent method getRecordingInfo.

public List<RecordingInfo> getRecordingInfo(String appId) {
    List<RecordingInfo> result = new ArrayList<>();
    String dir = getRecordingsDirectory(appId);
    if (dir == null) {
        return result;
    }
    Path path = new Path(dir);
    try {
        FileStatus fileStatus = stramAgent.getFileSystem().getFileStatus(path);
        if (!fileStatus.isDirectory()) {
            return result;
        }
        RemoteIterator<LocatedFileStatus> ri = stramAgent.getFileSystem().listLocatedStatus(path);
        while (ri.hasNext()) {
            LocatedFileStatus lfs = ri.next();
            if (lfs.isDirectory()) {
                try {
                    String opId = lfs.getPath().getName();
                    result.addAll(getRecordingInfo(appId, opId));
                } catch (NumberFormatException ex) {
                // ignore
                }
            }
        }
    } catch (IOException ex) {
        LOG.warn("Cannot get recording info for app id {}: {}", appId, ex);
        return result;
    }
    return result;
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus) ArrayList(java.util.ArrayList) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus) ObjectMapperString(com.datatorrent.common.util.ObjectMapperString) IOException(java.io.IOException)

Example 69 with LocatedFileStatus

use of org.apache.hadoop.fs.LocatedFileStatus in project apex-core by apache.

the class FSAgent method listFilesInfo.

public List<LocatedFileStatus> listFilesInfo(String dir) throws IOException {
    List<LocatedFileStatus> files = new ArrayList<>();
    Path path = new Path(dir);
    FileStatus fileStatus = fileSystem.getFileStatus(path);
    if (!fileStatus.isDirectory()) {
        throw new FileNotFoundException("Cannot read directory " + dir);
    }
    RemoteIterator<LocatedFileStatus> it = fileSystem.listFiles(path, false);
    while (it.hasNext()) {
        LocatedFileStatus lfs = it.next();
        files.add(lfs);
    }
    return files;
}
Also used : Path(org.apache.hadoop.fs.Path) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus) FileStatus(org.apache.hadoop.fs.FileStatus) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus)

Example 70 with LocatedFileStatus

use of org.apache.hadoop.fs.LocatedFileStatus in project drill by apache.

the class TestCTTAS method checkPermission.

private void checkPermission(String tmpTableName) throws IOException {
    File[] files = findTemporaryTableLocation(tmpTableName);
    assertEquals("Only one directory should match temporary table name " + tmpTableName, 1, files.length);
    Path tmpTablePath = new Path(files[0].toURI().getPath());
    assertEquals("Directory permission should match", expectedFolderPermission, fs.getFileStatus(tmpTablePath).getPermission());
    RemoteIterator<LocatedFileStatus> fileIterator = fs.listFiles(tmpTablePath, false);
    while (fileIterator.hasNext()) {
        assertEquals("File permission should match", expectedFilePermission, fileIterator.next().getPermission());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus) File(java.io.File)

Aggregations

LocatedFileStatus (org.apache.hadoop.fs.LocatedFileStatus)70 Path (org.apache.hadoop.fs.Path)51 FileSystem (org.apache.hadoop.fs.FileSystem)29 ArrayList (java.util.ArrayList)24 Test (org.junit.Test)20 FileStatus (org.apache.hadoop.fs.FileStatus)18 IOException (java.io.IOException)14 Configuration (org.apache.hadoop.conf.Configuration)10 File (java.io.File)8 FileNotFoundException (java.io.FileNotFoundException)7 BlockLocation (org.apache.hadoop.fs.BlockLocation)5 BufferedReader (java.io.BufferedReader)4 InputStreamReader (java.io.InputStreamReader)4 Matcher (java.util.regex.Matcher)4 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)4 RemoteIterator (org.apache.hadoop.fs.RemoteIterator)4 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)4 PrestoException (com.facebook.presto.spi.PrestoException)3 DataSegment (io.druid.timeline.DataSegment)3 Path (java.nio.file.Path)3