Java Code Examples for org.apache.hadoop.fs.FileContext#listStatus()
The following examples show how to use
org.apache.hadoop.fs.FileContext#listStatus() .
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: ResourceLocalizationService.java From hadoop with Apache License 2.0 | 6 votes |
private void deleteLocalDir(FileContext lfs, DeletionService del, String localDir) throws IOException { RemoteIterator<FileStatus> fileStatus = lfs.listStatus(new Path(localDir)); if (fileStatus != null) { while (fileStatus.hasNext()) { FileStatus status = fileStatus.next(); try { if (status.getPath().getName().matches(".*" + ContainerLocalizer.USERCACHE + "_DEL_.*")) { LOG.info("usercache path : " + status.getPath().toString()); cleanUpFilesPerUserDir(lfs, del, status.getPath()); } else if (status.getPath().getName() .matches(".*" + NM_PRIVATE_DIR + "_DEL_.*") || status.getPath().getName() .matches(".*" + ContainerLocalizer.FILECACHE + "_DEL_.*")) { del.delete(null, status.getPath(), new Path[] {}); } } catch (IOException ex) { // Do nothing, just give the warning LOG.warn("Failed to delete this local Directory: " + status.getPath().getName()); } } } }
Example 2
Source File: ResourceLocalizationService.java From hadoop with Apache License 2.0 | 6 votes |
private void cleanUpFilesPerUserDir(FileContext lfs, DeletionService del, Path userDirPath) throws IOException { RemoteIterator<FileStatus> userDirStatus = lfs.listStatus(userDirPath); FileDeletionTask dependentDeletionTask = del.createFileDeletionTask(null, userDirPath, new Path[] {}); if (userDirStatus != null && userDirStatus.hasNext()) { List<FileDeletionTask> deletionTasks = new ArrayList<FileDeletionTask>(); while (userDirStatus.hasNext()) { FileStatus status = userDirStatus.next(); String owner = status.getOwner(); FileDeletionTask deletionTask = del.createFileDeletionTask(owner, null, new Path[] { status.getPath() }); deletionTask.addFileDeletionTaskDependency(dependentDeletionTask); deletionTasks.add(deletionTask); } for (FileDeletionTask task : deletionTasks) { del.scheduleFileDeletionTask(task); } } else { del.scheduleFileDeletionTask(dependentDeletionTask); } }
Example 3
Source File: HistoryFileManager.java From hadoop with Apache License 2.0 | 6 votes |
@VisibleForTesting protected static List<FileStatus> scanDirectory(Path path, FileContext fc, PathFilter pathFilter) throws IOException { path = fc.makeQualified(path); List<FileStatus> jhStatusList = new ArrayList<FileStatus>(); try { RemoteIterator<FileStatus> fileStatusIter = fc.listStatus(path); while (fileStatusIter.hasNext()) { FileStatus fileStatus = fileStatusIter.next(); Path filePath = fileStatus.getPath(); if (fileStatus.isFile() && pathFilter.accept(filePath)) { jhStatusList.add(fileStatus); } } } catch (FileNotFoundException fe) { LOG.error("Error while scanning directory " + path, fe); } return jhStatusList; }
Example 4
Source File: TestDFSClientFailover.java From hadoop with Apache License 2.0 | 6 votes |
/** * Same test as above, but for FileContext. */ @Test public void testFileContextDoesntDnsResolveLogicalURI() throws Exception { FileSystem fs = HATestUtil.configureFailoverFs(cluster, conf); NameService spyNS = spyOnNameService(); String logicalHost = fs.getUri().getHost(); Configuration haClientConf = fs.getConf(); FileContext fc = FileContext.getFileContext(haClientConf); Path root = new Path("/"); fc.listStatus(root); fc.listStatus(fc.makeQualified(root)); fc.getDefaultFileSystem().getCanonicalServiceName(); // Ensure that the logical hostname was never resolved. Mockito.verify(spyNS, Mockito.never()).lookupAllHostAddr(Mockito.eq(logicalHost)); }
Example 5
Source File: ResourceLocalizationService.java From big-c with Apache License 2.0 | 6 votes |
private void deleteLocalDir(FileContext lfs, DeletionService del, String localDir) throws IOException { RemoteIterator<FileStatus> fileStatus = lfs.listStatus(new Path(localDir)); if (fileStatus != null) { while (fileStatus.hasNext()) { FileStatus status = fileStatus.next(); try { if (status.getPath().getName().matches(".*" + ContainerLocalizer.USERCACHE + "_DEL_.*")) { LOG.info("usercache path : " + status.getPath().toString()); cleanUpFilesPerUserDir(lfs, del, status.getPath()); } else if (status.getPath().getName() .matches(".*" + NM_PRIVATE_DIR + "_DEL_.*") || status.getPath().getName() .matches(".*" + ContainerLocalizer.FILECACHE + "_DEL_.*")) { del.delete(null, status.getPath(), new Path[] {}); } } catch (IOException ex) { // Do nothing, just give the warning LOG.warn("Failed to delete this local Directory: " + status.getPath().getName()); } } } }
Example 6
Source File: ResourceLocalizationService.java From big-c with Apache License 2.0 | 6 votes |
private void cleanUpFilesPerUserDir(FileContext lfs, DeletionService del, Path userDirPath) throws IOException { RemoteIterator<FileStatus> userDirStatus = lfs.listStatus(userDirPath); FileDeletionTask dependentDeletionTask = del.createFileDeletionTask(null, userDirPath, new Path[] {}); if (userDirStatus != null && userDirStatus.hasNext()) { List<FileDeletionTask> deletionTasks = new ArrayList<FileDeletionTask>(); while (userDirStatus.hasNext()) { FileStatus status = userDirStatus.next(); String owner = status.getOwner(); FileDeletionTask deletionTask = del.createFileDeletionTask(owner, null, new Path[] { status.getPath() }); deletionTask.addFileDeletionTaskDependency(dependentDeletionTask); deletionTasks.add(deletionTask); } for (FileDeletionTask task : deletionTasks) { del.scheduleFileDeletionTask(task); } } else { del.scheduleFileDeletionTask(dependentDeletionTask); } }
Example 7
Source File: HistoryFileManager.java From big-c with Apache License 2.0 | 6 votes |
@VisibleForTesting protected static List<FileStatus> scanDirectory(Path path, FileContext fc, PathFilter pathFilter) throws IOException { path = fc.makeQualified(path); List<FileStatus> jhStatusList = new ArrayList<FileStatus>(); try { RemoteIterator<FileStatus> fileStatusIter = fc.listStatus(path); while (fileStatusIter.hasNext()) { FileStatus fileStatus = fileStatusIter.next(); Path filePath = fileStatus.getPath(); if (fileStatus.isFile() && pathFilter.accept(filePath)) { jhStatusList.add(fileStatus); } } } catch (FileNotFoundException fe) { LOG.error("Error while scanning directory " + path, fe); } return jhStatusList; }
Example 8
Source File: TestDFSClientFailover.java From big-c with Apache License 2.0 | 6 votes |
/** * Same test as above, but for FileContext. */ @Test public void testFileContextDoesntDnsResolveLogicalURI() throws Exception { FileSystem fs = HATestUtil.configureFailoverFs(cluster, conf); NameService spyNS = spyOnNameService(); String logicalHost = fs.getUri().getHost(); Configuration haClientConf = fs.getConf(); FileContext fc = FileContext.getFileContext(haClientConf); Path root = new Path("/"); fc.listStatus(root); fc.listStatus(fc.makeQualified(root)); fc.getDefaultFileSystem().getCanonicalServiceName(); // Ensure that the logical hostname was never resolved. Mockito.verify(spyNS, Mockito.never()).lookupAllHostAddr(Mockito.eq(logicalHost)); }
Example 9
Source File: FileContextIntegrationTest.java From garmadon with Apache License 2.0 | 3 votes |
public static void main(String[] args) throws IOException { FileContext fileContext = FileContext.getFileContext(new Configuration()); Path src = new Path("/tmp/garmadon/test"); Path dst = new Path("/tmp/garmadon/test2"); fileContext.mkdir(src, FsPermission.getDefault(), true); fileContext.rename(src, dst, Options.Rename.OVERWRITE); fileContext.listStatus(dst); fileContext.delete(dst, false); }