use of alluxio.client.file.options.ListStatusOptions in project alluxio by Alluxio.
the class LsCommand method ls.
/**
* Displays information for all directories and files directly under the path specified in args.
*
* @param path The {@link AlluxioURI} path as the input of the command
* @param recursive Whether list the path recursively
* @param dirAsFile list the directory status as a plain file
* @param rawSize print raw sizes
* @throws AlluxioException when Alluxio exception occurs
* @throws IOException when non-Alluxio exception occurs
*/
private void ls(AlluxioURI path, boolean recursive, boolean forceLoadMetadata, boolean dirAsFile, boolean rawSize) throws AlluxioException, IOException {
if (dirAsFile) {
URIStatus status = mFileSystem.getStatus(path);
System.out.print(formatLsString(rawSize, SecurityUtils.isSecurityEnabled(), status.isFolder(), FormatUtils.formatMode((short) status.getMode(), status.isFolder()), status.getOwner(), status.getGroup(), status.getLength(), status.getCreationTimeMs(), 100 == status.getInMemoryPercentage(), status.getPath()));
return;
}
ListStatusOptions options = ListStatusOptions.defaults();
if (forceLoadMetadata) {
options.setLoadMetadataType(LoadMetadataType.Always);
}
List<URIStatus> statuses = listStatusSortedByIncreasingCreationTime(path, options);
for (URIStatus status : statuses) {
System.out.print(formatLsString(rawSize, SecurityUtils.isSecurityEnabled(), status.isFolder(), FormatUtils.formatMode((short) status.getMode(), status.isFolder()), status.getOwner(), status.getGroup(), status.getLength(), status.getCreationTimeMs(), 100 == status.getInMemoryPercentage(), status.getPath()));
if (recursive && status.isFolder()) {
ls(new AlluxioURI(path.getScheme(), path.getAuthority(), status.getPath()), true, forceLoadMetadata, false, rawSize);
}
}
}
use of alluxio.client.file.options.ListStatusOptions in project alluxio by Alluxio.
the class BaseFileSystemTest method listStatus.
/**
* Tests for the {@link BaseFileSystem#listStatus(AlluxioURI, ListStatusOptions)} method.
*/
@Test
public void listStatus() throws Exception {
AlluxioURI file = new AlluxioURI("/file");
List<URIStatus> infos = new ArrayList<>();
infos.add(new URIStatus(new FileInfo()));
ListStatusOptions listStatusOptions = ListStatusOptions.defaults();
Mockito.when(mFileSystemMasterClient.listStatus(file, listStatusOptions)).thenReturn(infos);
Assert.assertSame(infos, mFileSystem.listStatus(file, listStatusOptions));
Mockito.verify(mFileSystemMasterClient).listStatus(file, listStatusOptions);
}
use of alluxio.client.file.options.ListStatusOptions in project alluxio by Alluxio.
the class BaseFileSystemTest method listStatusException.
/**
* Ensures that an exception is propagated correctly when listing the status.
*/
@Test
public void listStatusException() throws Exception {
AlluxioURI file = new AlluxioURI("/file");
Mockito.when(mFileSystemMasterClient.listStatus(file, ListStatusOptions.defaults())).thenThrow(EXCEPTION);
ListStatusOptions listStatusOptions = ListStatusOptions.defaults();
try {
mFileSystem.listStatus(file, listStatusOptions);
Assert.fail(SHOULD_HAVE_PROPAGATED_MESSAGE);
} catch (Exception e) {
Assert.assertSame(EXCEPTION, e);
}
}
Aggregations