Search in sources :

Example 1 with ListStatusOptions

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);
        }
    }
}
Also used : ListStatusOptions(alluxio.client.file.options.ListStatusOptions) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI)

Example 2 with ListStatusOptions

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);
}
Also used : FileInfo(alluxio.wire.FileInfo) ListStatusOptions(alluxio.client.file.options.ListStatusOptions) ArrayList(java.util.ArrayList) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with 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);
    }
}
Also used : ListStatusOptions(alluxio.client.file.options.ListStatusOptions) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

AlluxioURI (alluxio.AlluxioURI)3 ListStatusOptions (alluxio.client.file.options.ListStatusOptions)3 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 URIStatus (alluxio.client.file.URIStatus)1 FileInfo (alluxio.wire.FileInfo)1 ArrayList (java.util.ArrayList)1