Skip to content

Commit

Permalink
Merge pull request #2 from ShailShah/listpinned
Browse files Browse the repository at this point in the history
Add feature to list all the pinned files
  • Loading branch information
ShailShah authored Mar 10, 2017
2 parents d313f67 + 0645ba7 commit 859a0f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ public abstract class AbstractShellCommand implements ShellCommand {
.hasArg(false)
.desc("list directories as plain files")
.build();

protected static final Option LIST_PINNED_FILES_OPTION =
Option.builder("p")
.required(false)
.hasArg(false)
.desc("list all pinned files")
.build();
protected AbstractShellCommand(FileSystem fs) {
mFileSystem = fs;
}
Expand Down
21 changes: 13 additions & 8 deletions shell/src/main/java/alluxio/shell/command/LsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public final class LsCommand extends WithWildCardPathCommand {
public static final String STATE_FOLDER = "Directory";
public static final String STATE_FILE_IN_MEMORY = "In Memory";
public static final String STATE_FILE_NOT_IN_MEMORY = "Not In Memory";
public static final String STATE_PINNED = "Pinned";
public static final String STATE_UNPINNED = "Unpinned";

/**
* Formats the ls result string.
Expand All @@ -56,21 +58,22 @@ public final class LsCommand extends WithWildCardPathCommand {
* @return the formatted string according to acl and isFolder
*/
public static String formatLsString(boolean acl, boolean isFolder, String permission,
String userName, String groupName, long size, long createTimeMs, boolean inMemory,
String userName, String groupName, long size, long createTimeMs, boolean inMemory, boolean isPinned,
String path) {
String memoryState;
if (isFolder) {
memoryState = STATE_FOLDER;
} else {
memoryState = inMemory ? STATE_FILE_IN_MEMORY : STATE_FILE_NOT_IN_MEMORY;
pinnedState = isPinned ? STATE_PINNED : STATE_UNPINNED;
}
if (acl) {
return String.format(Constants.LS_FORMAT, permission, userName, groupName,
FormatUtils.getSizeFromBytes(size), CommandUtils.convertMsToDate(createTimeMs),
memoryState, path);
memoryState, pinnedState, path);
} else {
return String.format(Constants.LS_FORMAT_NO_ACL, FormatUtils.getSizeFromBytes(size),
CommandUtils.convertMsToDate(createTimeMs), memoryState, path);
CommandUtils.convertMsToDate(createTimeMs), memoryState, pinnedState, path);
}
}

Expand Down Expand Up @@ -99,7 +102,8 @@ protected Options getOptions() {
return new Options()
.addOption(RECURSIVE_OPTION)
.addOption(FORCE_OPTION)
.addOption(LIST_DIR_AS_FILE_OPTION);
.addOption(LIST_DIR_AS_FILE_OPTION)
.addOption(LIST_PINNED_FILES_OPTION);
}

/**
Expand All @@ -111,14 +115,14 @@ protected Options getOptions() {
* @throws AlluxioException when Alluxio exception occurs
* @throws IOException when non-Alluxio exception occurs
*/
private void ls(AlluxioURI path, boolean recursive, boolean forceLoadMetadata, boolean dirAsFile)
private void ls(AlluxioURI path, boolean recursive, boolean forceLoadMetadata, boolean dirAsFile, boolean pinnedMetadata)
throws AlluxioException, IOException {
if (dirAsFile) {
URIStatus status = mFileSystem.getStatus(path);
System.out.print(formatLsString(SecurityUtils.isSecurityEnabled(), status.isFolder(),
FormatUtils.formatMode((short) status.getMode(), status.isFolder()), status.getOwner(),
status.getGroup(), status.getLength(), status.getCreationTimeMs(),
100 == status.getInMemoryPercentage(), status.getPath()));
100 == status.getInMemoryPercentage(), status.isPinned(), status.getPath()));
return;
}

Expand Down Expand Up @@ -162,7 +166,7 @@ public int compare(URIStatus status1, URIStatus status2) {

@Override
public void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException {
ls(path, cl.hasOption("R"), cl.hasOption("f"), cl.hasOption("d"));
ls(path, cl.hasOption("R"), cl.hasOption("f"), cl.hasOption("d"), cl.hasOption("p"));
}

@Override
Expand All @@ -175,6 +179,7 @@ public String getDescription() {
return "Displays information for all files and directories directly under the specified path."
+ " Specify -R to display files and directories recursively."
+ " Specify -d to list directories as plain files."
+ " Specify -f to force loading files in the directory.";
+ " Specify -f to force loading files in the directory."
+ "Specify -p to list all the pinned files in the specified path";
}
}

0 comments on commit 859a0f2

Please sign in to comment.