Java Code Examples for org.apache.hadoop.fs.LocatedFileStatus#getModificationTime()

The following examples show how to use org.apache.hadoop.fs.LocatedFileStatus#getModificationTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HdfsUtils.java    From jstorm with Apache License 2.0 6 votes vote down vote up
/** list files sorted by modification time that have not been modified since 'olderThan'. if
 * 'olderThan' is <= 0 then the filtering is disabled */
public static ArrayList<Path> listFilesByModificationTime(FileSystem fs, Path directory, long olderThan)
        throws IOException {
  ArrayList<LocatedFileStatus> fstats = new ArrayList<>();

  RemoteIterator<LocatedFileStatus> itr = fs.listFiles(directory, false);
  while( itr.hasNext() ) {
    LocatedFileStatus fileStatus = itr.next();
    if(olderThan>0) {
      if( fileStatus.getModificationTime()<=olderThan )
        fstats.add(fileStatus);
    }
    else {
      fstats.add(fileStatus);
    }
  }
  Collections.sort(fstats, new ModifTimeComparator() );

  ArrayList<Path> result = new ArrayList<>(fstats.size());
  for (LocatedFileStatus fstat : fstats) {
    result.add(fstat.getPath());
  }
  return result;
}
 
Example 2
Source File: HDFSResourceStore.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void visitFolderImpl(String folderPath, boolean recursive, VisitFilter filter, boolean loadContent,
        Visitor visitor) throws IOException {
    Path p = getRealHDFSPath(folderPath);
    if (!fs.exists(p) || !fs.isDirectory(p)) {
        return;
    }

    String fsPathPrefix = p.toUri().getPath();
    String resPathPrefix = folderPath.endsWith("/") ? folderPath : folderPath + "/";

    RemoteIterator<LocatedFileStatus> it = fs.listFiles(p, recursive);
    while (it.hasNext()) {
        LocatedFileStatus status = it.next();
        if (status.isDirectory())
            continue;

        String path = status.getPath().toUri().getPath();
        if (!path.startsWith(fsPathPrefix))
            throw new IllegalStateException("File path " + path + " is supposed to start with " + fsPathPrefix);

        String resPath = resPathPrefix + path.substring(fsPathPrefix.length() + 1);

        if (filter.matches(resPath, status.getModificationTime())) {
            RawResource raw;
            if (loadContent)
                raw = new RawResource(resPath, status.getModificationTime(), fs.open(status.getPath()));
            else
                raw = new RawResource(resPath, status.getModificationTime());

            try {
                visitor.visit(raw);
            } finally {
                raw.close();
            }
        }
    }
}
 
Example 3
Source File: SpillServiceImpl.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private void sweep(String spillDir, long targetTime) {
  try {
    final Path spillDirPath = new Path(spillDir);
    FileSystem fileSystem = spillDirPath.getFileSystem(SPILLING_CONFIG);
    RemoteIterator<LocatedFileStatus> files = fileSystem.listLocatedStatus(spillDirPath);
    while (files.hasNext()) {
      LocatedFileStatus st = files.next();
      if (st.getModificationTime() <= targetTime) {
        fileSystem.delete(st.getPath(), true);
      }
    }
  } catch (IOException e) {
    // exception silently ignored. Directory will be revisited at the next sweep
  }
}
 
Example 4
Source File: HDFSResourceStore.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
protected void visitFolderImpl(String folderPath, boolean recursive, VisitFilter filter, boolean loadContent,
        Visitor visitor) throws IOException {
    Path p = getRealHDFSPath(folderPath);
    if (!fs.exists(p) || !fs.isDirectory(p)) {
        return;
    }

    String fsPathPrefix = p.toUri().getPath();
    String resPathPrefix = folderPath.endsWith("/") ? folderPath : folderPath + "/";

    RemoteIterator<LocatedFileStatus> it = fs.listFiles(p, recursive);
    while (it.hasNext()) {
        LocatedFileStatus status = it.next();
        if (status.isDirectory())
            continue;

        String path = status.getPath().toUri().getPath();
        if (!path.startsWith(fsPathPrefix))
            throw new IllegalStateException("File path " + path + " is supposed to start with " + fsPathPrefix);

        String resPath = resPathPrefix + path.substring(fsPathPrefix.length() + 1);

        if (filter.matches(resPath, status.getModificationTime())) {
            RawResource raw;
            if (loadContent)
                raw = new RawResource(resPath, status.getModificationTime(), fs.open(status.getPath()));
            else
                raw = new RawResource(resPath, status.getModificationTime());

            try {
                visitor.visit(raw);
            } finally {
                raw.close();
            }
        }
    }
}