diff --git a/shell/src/main/java/alluxio/cli/fs/command/AbstractFileSystemCommand.java b/shell/src/main/java/alluxio/cli/fs/command/AbstractFileSystemCommand.java index bbda6090f738..fbd75a62e6c6 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/AbstractFileSystemCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/AbstractFileSystemCommand.java @@ -11,10 +11,20 @@ package alluxio.cli.fs.command; +import alluxio.AlluxioURI; import alluxio.cli.Command; +import alluxio.cli.fs.FileSystemShellUtils; import alluxio.client.file.FileSystem; +import alluxio.exception.AlluxioException; + +import com.google.common.base.Joiner; +import org.apache.commons.cli.CommandLine; import javax.annotation.concurrent.ThreadSafe; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; /** * The base class for all the FileSystem {@link alluxio.cli.Command} classes. @@ -28,4 +38,46 @@ public abstract class AbstractFileSystemCommand implements Command { protected AbstractFileSystemCommand(FileSystem fs) { mFileSystem = fs; } + + /** + * Run the command for a particular URI that does not contain wildcard in its path. + * + * @param plainPath an AlluxioURI that does not contain wildcard + * @param cl object containing the original commandLine + * @throws AlluxioException + * @throws IOException + */ + protected void runPlainPath(AlluxioURI plainPath, CommandLine cl) + throws AlluxioException, IOException { + } + + /** + * Run the command for a particular URI that may contain wildcard in its path. + * + * @param wildCardPath an AlluxioURI that may or may not contain a wildcard + * @param cl object containing the original commandLine + * @throws AlluxioException + * @throws IOException + */ + protected void runWildCardCmd(AlluxioURI wildCardPath, CommandLine cl) throws IOException { + List paths = FileSystemShellUtils.getAlluxioURIs(mFileSystem, wildCardPath); + if (paths.size() == 0) { // A unified sanity check on the paths + throw new IOException(wildCardPath + " does not exist."); + } + paths.sort(Comparator.comparing(AlluxioURI::getPath)); + + List errorMessages = new ArrayList<>(); + for (AlluxioURI path : paths) { + try { + runPlainPath(path, cl); + } catch (AlluxioException | IOException e) { + errorMessages.add(e.getMessage() != null ? e.getMessage() : e.toString()); + } + } + + if (errorMessages.size() != 0) { + throw new IOException(Joiner.on('\n').join(errorMessages)); + } + + } } diff --git a/shell/src/main/java/alluxio/cli/fs/command/CatCommand.java b/shell/src/main/java/alluxio/cli/fs/command/CatCommand.java index b8ec3663d62c..41ceb9f0de61 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/CatCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/CatCommand.java @@ -32,7 +32,7 @@ * Prints the file's contents to the console. */ @ThreadSafe -public final class CatCommand extends WithWildCardPathCommand { +public final class CatCommand extends AbstractFileSystemCommand { /** * @param fs the filesystem of Alluxio @@ -47,7 +47,8 @@ public String getCommandName() { } @Override - protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException { + protected void runPlainPath(AlluxioURI path, CommandLine cl) + throws AlluxioException, IOException { URIStatus status = mFileSystem.getStatus(path); if (status.isFolder()) { @@ -78,4 +79,12 @@ public String getDescription() { public void validateArgs(CommandLine cl) throws InvalidArgumentException { CommandUtils.checkNumOfArgsNoLessThan(this, cl, 1); } + + @Override + public int run(CommandLine cl) throws IOException { + String[] args = cl.getArgs(); + runWildCardCmd(new AlluxioURI(args[0]), cl); + + return 0; + } } diff --git a/shell/src/main/java/alluxio/cli/fs/command/CheckConsistencyCommand.java b/shell/src/main/java/alluxio/cli/fs/command/CheckConsistencyCommand.java index 093824783ca8..f3b955cd4368 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/CheckConsistencyCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/CheckConsistencyCommand.java @@ -49,6 +49,12 @@ public CheckConsistencyCommand(FileSystem fs) { super(fs); } + @Override + protected void runPlainPath(AlluxioURI plainPath, CommandLine cl) + throws AlluxioException, IOException { + checkConsistency(plainPath, cl.hasOption("r")); + } + @Override public void validateArgs(CommandLine cl) throws InvalidArgumentException { CommandUtils.checkNumOfArgsEquals(this, cl, 1); @@ -68,7 +74,8 @@ public String getCommandName() { public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); AlluxioURI root = new AlluxioURI(args[0]); - checkConsistency(root, cl.hasOption("r")); + + runWildCardCmd(root, cl); return 0; } diff --git a/shell/src/main/java/alluxio/cli/fs/command/ChecksumCommand.java b/shell/src/main/java/alluxio/cli/fs/command/ChecksumCommand.java index 7c8a0fb15bf2..1a3cd7935883 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/ChecksumCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/ChecksumCommand.java @@ -43,6 +43,19 @@ public ChecksumCommand(FileSystem fs) { super(fs); } + @Override + protected void runPlainPath(AlluxioURI plainPath, CommandLine cl) + throws AlluxioException, IOException { + URIStatus status = mFileSystem.getStatus(plainPath); + if (status.isFolder()) { + throw new FileDoesNotExistException( + ExceptionMessage.PATH_MUST_BE_FILE.getMessage(plainPath.getPath())); + } + + String str = calculateChecksum(plainPath); + System.out.println("md5sum: " + str + "\n"); + } + @Override public String getCommandName() { return "checksum"; @@ -56,13 +69,7 @@ public void validateArgs(CommandLine cl) throws InvalidArgumentException { @Override public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); - AlluxioURI loc = new AlluxioURI(args[0]); - URIStatus status = mFileSystem.getStatus(loc); - if (status.isFolder()) { - throw new FileDoesNotExistException(ExceptionMessage.PATH_MUST_BE_FILE.getMessage(args[0])); - } - String str = calculateChecksum(loc); - System.out.println("md5sum: " + str); + runWildCardCmd(new AlluxioURI(args[0]), cl); return 0; } diff --git a/shell/src/main/java/alluxio/cli/fs/command/ChgrpCommand.java b/shell/src/main/java/alluxio/cli/fs/command/ChgrpCommand.java index d6068030c5bb..d129d09e0264 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/ChgrpCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/ChgrpCommand.java @@ -39,6 +39,8 @@ public final class ChgrpCommand extends AbstractFileSystemCommand { .desc("change group recursively") .build(); + private String mGroup; + /** * Creates a new instance of {@link ChgrpCommand}. * @@ -78,12 +80,19 @@ private void chgrp(AlluxioURI path, String group, boolean recursive) System.out.println("Changed group of " + path + " to " + group); } + @Override + protected void runPlainPath(AlluxioURI path, CommandLine cl) + throws IOException, AlluxioException { + chgrp(path, mGroup, cl.hasOption("R")); + } + @Override public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); - String group = args[0]; + mGroup = args[0]; AlluxioURI path = new AlluxioURI(args[1]); - chgrp(path, group, cl.hasOption("R")); + runWildCardCmd(path, cl); + return 0; } diff --git a/shell/src/main/java/alluxio/cli/fs/command/ChmodCommand.java b/shell/src/main/java/alluxio/cli/fs/command/ChmodCommand.java index 7c9eea9b8b41..ab51d845d653 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/ChmodCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/ChmodCommand.java @@ -42,6 +42,7 @@ public final class ChmodCommand extends AbstractFileSystemCommand { .build(); private final ModeParser mParser = new ModeParser(); + private String mModeString = ""; /** * Creates a new instance of {@link ChmodCommand}. @@ -52,6 +53,12 @@ public ChmodCommand(FileSystem fs) { super(fs); } + @Override + protected void runPlainPath(AlluxioURI plainPath, CommandLine cl) + throws AlluxioException, IOException { + chmod(plainPath, mModeString, cl.hasOption("R")); + } + @Override public String getCommandName() { return "chmod"; @@ -87,9 +94,10 @@ private void chmod(AlluxioURI path, String modeStr, boolean recursive) throws @Override public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); - String modeStr = args[0]; + mModeString = args[0]; + AlluxioURI path = new AlluxioURI(args[1]); - chmod(path, modeStr, cl.hasOption("R")); + runWildCardCmd(path, cl); return 0; } diff --git a/shell/src/main/java/alluxio/cli/fs/command/ChownCommand.java b/shell/src/main/java/alluxio/cli/fs/command/ChownCommand.java index 2c6b97e118df..2c84a1d3cb74 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/ChownCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/ChownCommand.java @@ -41,6 +41,9 @@ public final class ChownCommand extends AbstractFileSystemCommand { .desc("change owner recursively") .build(); + private String mGroup; + private String mOwner; + /** * Creates a new instance of {@link ChownCommand}. * @@ -50,6 +53,16 @@ public ChownCommand(FileSystem fs) { super(fs); } + @Override + protected void runPlainPath(AlluxioURI path, CommandLine cl) + throws AlluxioException, IOException { + if (mGroup == null) { + chown(path, mOwner, cl.hasOption("R")); + } else { + chown(path, mOwner, mGroup, cl.hasOption("R")); + } + } + @Override public String getCommandName() { return "chown"; @@ -110,13 +123,9 @@ public int run(CommandLine cl) throws AlluxioException, IOException { AlluxioURI path = new AlluxioURI(args[1]); Matcher matchUserGroup = USER_GROUP_PATTERN.matcher(args[0]); if (matchUserGroup.matches()) { - String owner = matchUserGroup.group("user"); - String group = matchUserGroup.group("group"); - if (group == null) { - chown(path, owner, cl.hasOption("R")); - } else { - chown(path, owner, group, cl.hasOption("R")); - } + mOwner = matchUserGroup.group("user"); + mGroup = matchUserGroup.group("group"); + runWildCardCmd(path, cl); return 0; } System.out.println("Failed to parse " + args[0] + " as user or user:group"); diff --git a/shell/src/main/java/alluxio/cli/fs/command/DuCommand.java b/shell/src/main/java/alluxio/cli/fs/command/DuCommand.java index d984a00b1bad..69a24824e0df 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/DuCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/DuCommand.java @@ -29,7 +29,7 @@ * Displays the size of a file or a directory specified by argv. */ @ThreadSafe -public final class DuCommand extends WithWildCardPathCommand { +public final class DuCommand extends AbstractFileSystemCommand { /** * @param fs the filesystem of Alluxio @@ -44,7 +44,8 @@ public String getCommandName() { } @Override - protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException { + protected void runPlainPath(AlluxioURI path, CommandLine cl) + throws AlluxioException, IOException { long sizeInBytes = getFileOrFolderSize(mFileSystem, path); System.out.println(path + " is " + sizeInBytes + " bytes"); } @@ -85,4 +86,13 @@ public String getDescription() { public void validateArgs(CommandLine cl) throws InvalidArgumentException { CommandUtils.checkNumOfArgsEquals(this, cl, 1); } + + @Override + public int run(CommandLine cl) throws AlluxioException, IOException { + String[] args = cl.getArgs(); + AlluxioURI path = new AlluxioURI(args[0]); + runWildCardCmd(path, cl); + + return 0; + } } diff --git a/shell/src/main/java/alluxio/cli/fs/command/FileInfoCommand.java b/shell/src/main/java/alluxio/cli/fs/command/FileInfoCommand.java index c2a8768ab8cb..9473acb60092 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/FileInfoCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/FileInfoCommand.java @@ -11,16 +11,12 @@ package alluxio.cli.fs.command; -import alluxio.AlluxioURI; import alluxio.cli.CommandUtils; import alluxio.client.file.FileSystem; -import alluxio.exception.AlluxioException; import alluxio.exception.status.InvalidArgumentException; import org.apache.commons.cli.CommandLine; -import java.io.IOException; - import javax.annotation.concurrent.ThreadSafe; /** @@ -30,7 +26,7 @@ */ @ThreadSafe @Deprecated -public final class FileInfoCommand extends WithWildCardPathCommand { +public final class FileInfoCommand extends AbstractFileSystemCommand { /** * @param fs the filesystem of Alluxio */ @@ -44,10 +40,11 @@ public String getCommandName() { } @Override - protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException { + public int run(CommandLine cl) { System.out .println("The \"alluxio fs fileInfo \" command is deprecated since version 1.5."); System.out.println("Use the \"alluxio fs stat \" command instead."); + return 0; } @Override diff --git a/shell/src/main/java/alluxio/cli/fs/command/FreeCommand.java b/shell/src/main/java/alluxio/cli/fs/command/FreeCommand.java index 6dcd0904c64f..4e78c1da4dbb 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/FreeCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/FreeCommand.java @@ -31,7 +31,7 @@ * folder). */ @ThreadSafe -public final class FreeCommand extends WithWildCardPathCommand { +public final class FreeCommand extends AbstractFileSystemCommand { private static final Option FORCE_OPTION = Option.builder("f") @@ -60,7 +60,8 @@ public String getCommandName() { } @Override - protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException { + protected void runPlainPath(AlluxioURI path, CommandLine cl) + throws AlluxioException, IOException { FreeOptions options = FreeOptions.defaults().setRecursive(true).setForced(cl.hasOption("f")); mFileSystem.free(path, options); System.out.println(path + " was successfully freed from memory."); @@ -77,6 +78,15 @@ public String getDescription() { + " Specify -f to force freeing pinned files in the directory."; } + @Override + public int run(CommandLine cl) throws AlluxioException, IOException { + String[] args = cl.getArgs(); + AlluxioURI path = new AlluxioURI(args[0]); + runWildCardCmd(path, cl); + + return 0; + } + @Override public void validateArgs(CommandLine cl) throws InvalidArgumentException { CommandUtils.checkNumOfArgsNoLessThan(this, cl, 1); diff --git a/shell/src/main/java/alluxio/cli/fs/command/HeadCommand.java b/shell/src/main/java/alluxio/cli/fs/command/HeadCommand.java index 7563218daab8..bb79805bce95 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/HeadCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/HeadCommand.java @@ -36,13 +36,15 @@ * Prints the file's first n bytes (by default, 1KB) to the console. */ @ThreadSafe -public final class HeadCommand extends WithWildCardPathCommand { +public final class HeadCommand extends AbstractFileSystemCommand { private static final Option BYTES_OPTION = Option.builder("c") .required(false) .numberOfArgs(1) .desc("number of bytes (e.g., 1024, 4KB)") .build(); + private int mNumOfBytes; + /** * @param fs the filesystem of Alluxio */ @@ -61,22 +63,18 @@ public void validateArgs(CommandLine cl) throws InvalidArgumentException { } @Override - protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException { - URIStatus status = mFileSystem.getStatus(path); - int numOfBytes = Constants.KB; - if (cl.hasOption('c')) { - numOfBytes = (int) FormatUtils.parseSpaceSize(cl.getOptionValue('c')); - Preconditions.checkArgument(numOfBytes > 0, "specified bytes must be > 0"); - } + protected void runPlainPath(AlluxioURI plainPath, CommandLine cl) + throws AlluxioException, IOException { + URIStatus status = mFileSystem.getStatus(plainPath); if (status.isFolder()) { - throw new IOException(ExceptionMessage.PATH_MUST_BE_FILE.getMessage(path)); + throw new IOException(ExceptionMessage.PATH_MUST_BE_FILE.getMessage(plainPath)); } OpenFileOptions options = OpenFileOptions.defaults(); - try (FileInStream is = mFileSystem.openFile(path, options)) { + try (FileInStream is = mFileSystem.openFile(plainPath, options)) { long bytesToRead; - if (status.getLength() > numOfBytes) { - bytesToRead = numOfBytes; + if (status.getLength() > mNumOfBytes) { + bytesToRead = mNumOfBytes; } else { bytesToRead = status.getLength(); } @@ -89,6 +87,20 @@ protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioExcepti } } + @Override + public int run(CommandLine cl) throws AlluxioException, IOException { + String[] args = cl.getArgs(); + mNumOfBytes = Constants.KB; + if (cl.hasOption('c')) { + mNumOfBytes = (int) FormatUtils.parseSpaceSize(cl.getOptionValue('c')); + Preconditions.checkArgument(mNumOfBytes > 0, "specified bytes must be > 0"); + } + AlluxioURI path = new AlluxioURI(args[0]); + runWildCardCmd(path, cl); + + return 0; + } + @Override public String getUsage() { return "head [-c ] "; diff --git a/shell/src/main/java/alluxio/cli/fs/command/LoadCommand.java b/shell/src/main/java/alluxio/cli/fs/command/LoadCommand.java index 501dab785a2c..dfd966d0a068 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/LoadCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/LoadCommand.java @@ -38,7 +38,7 @@ * Loads a file or directory in Alluxio space, making it resident in Alluxio. */ @ThreadSafe -public final class LoadCommand extends WithWildCardPathCommand { +public final class LoadCommand extends AbstractFileSystemCommand { private static final Option LOCAL_OPTION = Option.builder() .longOpt("local") @@ -68,8 +68,18 @@ public Options getOptions() { } @Override - protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException { - load(path, cl.hasOption(LOCAL_OPTION.getLongOpt())); + protected void runPlainPath(AlluxioURI plainPath, CommandLine cl) + throws AlluxioException, IOException { + load(plainPath, cl.hasOption(LOCAL_OPTION.getLongOpt())); + } + + @Override + public int run(CommandLine cl) throws AlluxioException, IOException { + String[] args = cl.getArgs(); + AlluxioURI path = new AlluxioURI(args[0]); + runWildCardCmd(path, cl); + + return 0; } /** diff --git a/shell/src/main/java/alluxio/cli/fs/command/LocationCommand.java b/shell/src/main/java/alluxio/cli/fs/command/LocationCommand.java index 5c828e2dd8b6..c688077b7c89 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/LocationCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/LocationCommand.java @@ -30,7 +30,7 @@ * Displays a list of hosts that have the file specified in args stored. */ @ThreadSafe -public final class LocationCommand extends WithWildCardPathCommand { +public final class LocationCommand extends AbstractFileSystemCommand { /** * Constructs a new instance to display a list of hosts that have the file specified in args * stored. @@ -47,10 +47,11 @@ public String getCommandName() { } @Override - protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException { - URIStatus status = mFileSystem.getStatus(path); + protected void runPlainPath(AlluxioURI plainPath, CommandLine cl) + throws AlluxioException, IOException { + URIStatus status = mFileSystem.getStatus(plainPath); - System.out.println(path + " with file id " + status.getFileId() + " is on nodes: "); + System.out.println(plainPath + " with file id " + status.getFileId() + " is on nodes: "); AlluxioBlockStore blockStore = AlluxioBlockStore.create(); for (long blockId : status.getBlockIds()) { for (BlockLocation location : blockStore.getInfo(blockId).getLocations()) { @@ -59,6 +60,14 @@ protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioExcepti } } + @Override + public int run(CommandLine cl) throws AlluxioException, IOException { + String[] args = cl.getArgs(); + AlluxioURI path = new AlluxioURI(args[0]); + runWildCardCmd(path, cl); + return 0; + } + @Override public String getUsage() { return "location "; diff --git a/shell/src/main/java/alluxio/cli/fs/command/LsCommand.java b/shell/src/main/java/alluxio/cli/fs/command/LsCommand.java index dc4edcde3daf..1b3619b84611 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/LsCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/LsCommand.java @@ -43,7 +43,7 @@ * can also display the information for all directly children under the path, or recursively. */ @ThreadSafe -public final class LsCommand extends WithWildCardPathCommand { +public final class LsCommand extends AbstractFileSystemCommand { public static final String IN_ALLUXIO_STATE_DIR = "DIR"; public static final String IN_ALLUXIO_STATE_FILE_FORMAT = "%d%%"; public static final String LS_FORMAT_PERMISSION = "%-11s"; @@ -246,7 +246,7 @@ private List sortByFieldAndOrder( if (!sortToUse.isPresent()) { throw new InvalidArgumentException(ExceptionMessage.INVALID_ARGS_SORT_FIELD - .getMessage(sortField)); + .getMessage(sortField)); } Comparator sortBy = sortToUse.get(); @@ -258,10 +258,19 @@ private List sortByFieldAndOrder( } @Override - public void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException { + protected void runPlainPath(AlluxioURI path, CommandLine cl) + throws AlluxioException, IOException { ls(path, cl.hasOption("R"), cl.hasOption("f"), cl.hasOption("d"), cl.hasOption("h"), - cl.hasOption("p"), cl.getOptionValue("sort", "name"), - cl.hasOption("r")); + cl.hasOption("p"), cl.getOptionValue("sort", "name"), cl.hasOption("r")); + } + + @Override + public int run(CommandLine cl) throws AlluxioException, IOException { + String[] args = cl.getArgs(); + AlluxioURI path = new AlluxioURI(args[0]); + runWildCardCmd(path, cl); + + return 0; } @Override diff --git a/shell/src/main/java/alluxio/cli/fs/command/PersistCommand.java b/shell/src/main/java/alluxio/cli/fs/command/PersistCommand.java index f1d8d3600751..3ddb33619e5c 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/PersistCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/PersistCommand.java @@ -51,12 +51,18 @@ public void validateArgs(CommandLine cl) throws InvalidArgumentException { CommandUtils.checkNumOfArgsNoLessThan(this, cl, 1); } + @Override + protected void runPlainPath(AlluxioURI plainPath, CommandLine cl) + throws AlluxioException, IOException { + persist(plainPath); + } + @Override public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); for (String path : args) { AlluxioURI inputPath = new AlluxioURI(path); - persist(inputPath); + runWildCardCmd(inputPath, cl); } return 0; } diff --git a/shell/src/main/java/alluxio/cli/fs/command/PinCommand.java b/shell/src/main/java/alluxio/cli/fs/command/PinCommand.java index 9bad00f4c720..84719a35716c 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/PinCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/PinCommand.java @@ -28,7 +28,7 @@ * never evicted from memory. */ @ThreadSafe -public final class PinCommand extends WithWildCardPathCommand { +public final class PinCommand extends AbstractFileSystemCommand { /** * @param fs the filesystem of Alluxio @@ -43,11 +43,20 @@ public String getCommandName() { } @Override - protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException { + protected void runPlainPath(AlluxioURI path, CommandLine cl) + throws AlluxioException, IOException { FileSystemCommandUtils.setPinned(mFileSystem, path, true); System.out.println("File '" + path + "' was successfully pinned."); } + @Override + public int run(CommandLine cl) throws AlluxioException, IOException { + String[] args = cl.getArgs(); + AlluxioURI path = new AlluxioURI(args[0]); + runWildCardCmd(path, cl); + return 0; + } + @Override public String getUsage() { return "pin "; diff --git a/shell/src/main/java/alluxio/cli/fs/command/ReportCommand.java b/shell/src/main/java/alluxio/cli/fs/command/ReportCommand.java index 1cb8a198afca..763e796d58f3 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/ReportCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/ReportCommand.java @@ -30,7 +30,7 @@ * Reports to the master that a file is lost. */ @ThreadSafe -public final class ReportCommand extends WithWildCardPathCommand { +public final class ReportCommand extends AbstractFileSystemCommand { /** * @param fs the filesystem of Alluxio @@ -45,11 +45,20 @@ public String getCommandName() { } @Override - protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException { + protected void runPlainPath(AlluxioURI path, CommandLine cl) + throws AlluxioException, IOException { LineageFileSystem.get(FileSystemContext.INSTANCE, LineageContext.INSTANCE).reportLostFile(path); System.out.println(path + " has been reported as lost."); } + @Override + public int run(CommandLine cl) throws AlluxioException, IOException { + String[] args = cl.getArgs(); + AlluxioURI path = new AlluxioURI(args[0]); + runWildCardCmd(path, cl); + return 0; + } + @Override public String getUsage() { return "report "; diff --git a/shell/src/main/java/alluxio/cli/fs/command/RmCommand.java b/shell/src/main/java/alluxio/cli/fs/command/RmCommand.java index b617283c8ceb..ef4d83eeaad5 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/RmCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/RmCommand.java @@ -32,7 +32,7 @@ * Removes the file specified by argv. */ @ThreadSafe -public final class RmCommand extends WithWildCardPathCommand { +public final class RmCommand extends AbstractFileSystemCommand { private static final Option RECURSIVE_OPTION = Option.builder("R") @@ -78,7 +78,8 @@ public Options getOptions() { } @Override - protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException { + protected void runPlainPath(AlluxioURI path, CommandLine cl) + throws AlluxioException, IOException { // TODO(calvin): Remove explicit state checking. boolean recursive = cl.hasOption("R"); if (!mFileSystem.exists(path)) { @@ -93,6 +94,7 @@ protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioExcepti if (cl.hasOption(REMOVE_UNCHECKED_OPTION_CHAR)) { options.setUnchecked(true); } + boolean isAlluxioOnly = cl.hasOption(REMOVE_ALLUXIO_ONLY.getLongOpt()); options.setAlluxioOnly(isAlluxioOnly); mFileSystem.delete(path, options); @@ -103,6 +105,15 @@ protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioExcepti } } + @Override + public int run(CommandLine cl) throws AlluxioException, IOException { + String[] args = cl.getArgs(); + AlluxioURI path = new AlluxioURI(args[0]); + runWildCardCmd(path, cl); + + return 0; + } + @Override public String getUsage() { return "rm [-R] [-U] [--alluxioOnly] "; diff --git a/shell/src/main/java/alluxio/cli/fs/command/SetTtlCommand.java b/shell/src/main/java/alluxio/cli/fs/command/SetTtlCommand.java index 57d9dcc7bf95..05eb850066e8 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/SetTtlCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/SetTtlCommand.java @@ -46,6 +46,7 @@ public final class SetTtlCommand extends AbstractFileSystemCommand { .build(); private TtlAction mAction = TtlAction.DELETE; + private long mTtlMs; /** * @param fs the filesystem of Alluxio @@ -78,15 +79,22 @@ public Options getOptions() { return new Options().addOption(TTL_ACTION_OPTION); } + @Override + protected void runPlainPath(AlluxioURI path, CommandLine cl) + throws AlluxioException, IOException { + FileSystemCommandUtils.setTtl(mFileSystem, path, mTtlMs, mAction); + System.out.println("TTL of path '" + path + "' was successfully set to " + mTtlMs + + " milliseconds, with expiry action set to " + mAction); + } + @Override public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); String ttl = CommonUtils.stripLeadingAndTrailingQuotes(args[1]); - long ttlMs = FileSystemShellUtils.getMs(ttl); + mTtlMs = FileSystemShellUtils.getMs(ttl); AlluxioURI path = new AlluxioURI(args[0]); - FileSystemCommandUtils.setTtl(mFileSystem, path, ttlMs, mAction); - System.out.println("TTL of path '" + path + "' was successfully set to " + ttlMs - + " milliseconds, with expiry action set to " + mAction); + runWildCardCmd(path, cl); + return 0; } diff --git a/shell/src/main/java/alluxio/cli/fs/command/StatCommand.java b/shell/src/main/java/alluxio/cli/fs/command/StatCommand.java index b1cb6c0d2604..9b67ffc56487 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/StatCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/StatCommand.java @@ -39,7 +39,7 @@ * If path is a file, it displays the file's all blocks info. */ @ThreadSafe -public final class StatCommand extends WithWildCardPathCommand { +public final class StatCommand extends AbstractFileSystemCommand { /** * @param fs the filesystem of Alluxio */ @@ -64,7 +64,8 @@ public Options getOptions() { } @Override - protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException { + protected void runPlainPath(AlluxioURI path, CommandLine cl) + throws AlluxioException, IOException { URIStatus status = mFileSystem.getStatus(path); if (cl.hasOption('f')) { System.out.println(formatOutput(cl, status)); @@ -89,6 +90,15 @@ protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioExcepti } } + @Override + public int run(CommandLine cl) throws AlluxioException, IOException { + String[] args = cl.getArgs(); + AlluxioURI path = new AlluxioURI(args[0]); + runWildCardCmd(path, cl); + + return 0; + } + @Override public String getUsage() { return "stat [-f ] "; diff --git a/shell/src/main/java/alluxio/cli/fs/command/TailCommand.java b/shell/src/main/java/alluxio/cli/fs/command/TailCommand.java index 2c1c5bae4107..150990962d74 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/TailCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/TailCommand.java @@ -36,7 +36,7 @@ * Prints the file's last n bytes (by default, 1KB) to the console. */ @ThreadSafe -public final class TailCommand extends WithWildCardPathCommand { +public final class TailCommand extends AbstractFileSystemCommand { private static final Option BYTES_OPTION = Option.builder("c") .required(false) .numberOfArgs(1) @@ -56,7 +56,8 @@ public String getCommandName() { } @Override - protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException { + protected void runPlainPath(AlluxioURI path, CommandLine cl) + throws AlluxioException, IOException { URIStatus status = mFileSystem.getStatus(path); int numOfBytes = Constants.KB; if (cl.hasOption('c')) { @@ -84,6 +85,14 @@ protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioExcepti } } + @Override + public int run(CommandLine cl) throws AlluxioException, IOException { + String[] args = cl.getArgs(); + AlluxioURI path = new AlluxioURI(args[0]); + runWildCardCmd(path, cl); + return 0; + } + @Override public String getUsage() { return "tail [-c ] "; diff --git a/shell/src/main/java/alluxio/cli/fs/command/TouchCommand.java b/shell/src/main/java/alluxio/cli/fs/command/TouchCommand.java index 9e3702b8696c..dafdeeb3f36b 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/TouchCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/TouchCommand.java @@ -47,13 +47,18 @@ public void validateArgs(CommandLine cl) throws InvalidArgumentException { CommandUtils.checkNumOfArgsEquals(this, cl, 1); } + @Override + protected void runPlainPath(AlluxioURI inputPath, CommandLine cl) + throws AlluxioException, IOException { + mFileSystem.createFile(inputPath, CreateFileOptions.defaults()).close(); + System.out.println(inputPath + " has been created"); + } + @Override public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); AlluxioURI inputPath = new AlluxioURI(args[0]); - - mFileSystem.createFile(inputPath, CreateFileOptions.defaults()).close(); - System.out.println(inputPath + " has been created"); + runWildCardCmd(inputPath, cl); return 0; } diff --git a/shell/src/main/java/alluxio/cli/fs/command/UnmountCommand.java b/shell/src/main/java/alluxio/cli/fs/command/UnmountCommand.java index 84295c1b3385..479a8b926805 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/UnmountCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/UnmountCommand.java @@ -46,13 +46,18 @@ public void validateArgs(CommandLine cl) throws InvalidArgumentException { CommandUtils.checkNumOfArgsEquals(this, cl, 1); } + @Override + protected void runPlainPath(AlluxioURI inputPath, CommandLine cl) + throws AlluxioException, IOException { + mFileSystem.unmount(inputPath); + System.out.println("Unmounted " + inputPath); + } + @Override public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); AlluxioURI inputPath = new AlluxioURI(args[0]); - - mFileSystem.unmount(inputPath); - System.out.println("Unmounted " + inputPath); + runWildCardCmd(inputPath, cl); return 0; } diff --git a/shell/src/main/java/alluxio/cli/fs/command/UnpinCommand.java b/shell/src/main/java/alluxio/cli/fs/command/UnpinCommand.java index 1b3df7ee24ca..c9504321b1f2 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/UnpinCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/UnpinCommand.java @@ -28,7 +28,7 @@ * are never evicted from memory, so this method will allow such files to be evicted. */ @ThreadSafe -public final class UnpinCommand extends WithWildCardPathCommand { +public final class UnpinCommand extends AbstractFileSystemCommand { /** * @param fs the filesystem of Alluxio @@ -43,11 +43,20 @@ public String getCommandName() { } @Override - protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException { + protected void runPlainPath(AlluxioURI path, CommandLine cl) + throws AlluxioException, IOException { FileSystemCommandUtils.setPinned(mFileSystem, path, false); System.out.println("File '" + path + "' was successfully unpinned."); } + @Override + public int run(CommandLine cl) throws AlluxioException, IOException { + String[] args = cl.getArgs(); + AlluxioURI path = new AlluxioURI(args[0]); + runWildCardCmd(path, cl); + return 0; + } + @Override public String getUsage() { return "unpin "; diff --git a/shell/src/main/java/alluxio/cli/fs/command/UnsetTtlCommand.java b/shell/src/main/java/alluxio/cli/fs/command/UnsetTtlCommand.java index e876f64a1e11..3c05c56a3212 100644 --- a/shell/src/main/java/alluxio/cli/fs/command/UnsetTtlCommand.java +++ b/shell/src/main/java/alluxio/cli/fs/command/UnsetTtlCommand.java @@ -49,12 +49,18 @@ public void validateArgs(CommandLine cl) throws InvalidArgumentException { } @Override - public int run(CommandLine cl) throws AlluxioException, IOException { - String[] args = cl.getArgs(); - AlluxioURI inputPath = new AlluxioURI(args[0]); + protected void runPlainPath(AlluxioURI inputPath, CommandLine cl) + throws AlluxioException, IOException { // Expiry doesn't matter in this case FileSystemCommandUtils.setTtl(mFileSystem, inputPath, Constants.NO_TTL, TtlAction.DELETE); System.out.println("TTL of file '" + inputPath + "' was successfully removed."); + } + + @Override + public int run(CommandLine cl) throws AlluxioException, IOException { + String[] args = cl.getArgs(); + AlluxioURI inputPath = new AlluxioURI(args[0]); + runWildCardCmd(inputPath, cl); return 0; } diff --git a/shell/src/main/java/alluxio/cli/fs/command/WithWildCardPathCommand.java b/shell/src/main/java/alluxio/cli/fs/command/WithWildCardPathCommand.java deleted file mode 100644 index 0d630fc8b900..000000000000 --- a/shell/src/main/java/alluxio/cli/fs/command/WithWildCardPathCommand.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 - * (the "License"). You may not use this work except in compliance with the License, which is - * available at www.apache.org/licenses/LICENSE-2.0 - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied, as more fully set forth in the License. - * - * See the NOTICE file distributed with this work for information regarding copyright ownership. - */ - -package alluxio.cli.fs.command; - -import alluxio.AlluxioURI; -import alluxio.client.file.FileSystem; -import alluxio.exception.AlluxioException; -import alluxio.cli.fs.FileSystemShellUtils; - -import com.google.common.base.Joiner; -import org.apache.commons.cli.CommandLine; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -import javax.annotation.concurrent.ThreadSafe; - -/** - * An abstract class for the commands that take exactly one path that could contain wildcard - * characters. - * - * It will first do a glob against the input pattern then run the command for each expanded path. - */ -@ThreadSafe -public abstract class WithWildCardPathCommand extends AbstractFileSystemCommand { - - protected WithWildCardPathCommand(FileSystem fs) { - super(fs); - } - - /** - * Actually runs the command against one expanded path. - * - * @param path the expanded input path - * @param cl the parsed command line object including options - */ - protected abstract void runCommand(AlluxioURI path, CommandLine cl) - throws AlluxioException, IOException; - - @Override - public int run(CommandLine cl) throws AlluxioException, IOException { - String[] args = cl.getArgs(); - for (String arg : args) { - AlluxioURI inputPath = new AlluxioURI(arg); - - List paths = FileSystemShellUtils.getAlluxioURIs(mFileSystem, inputPath); - if (paths.size() == 0) { // A unified sanity check on the paths - throw new IOException(inputPath + " does not exist."); - } - Collections.sort(paths, createAlluxioURIComparator()); - - List errorMessages = new ArrayList<>(); - for (AlluxioURI path : paths) { - try { - runCommand(path, cl); - } catch (AlluxioException | IOException e) { - errorMessages.add(e.getMessage() != null ? e.getMessage() : e.toString()); - } - } - - if (errorMessages.size() != 0) { - throw new IOException(Joiner.on('\n').join(errorMessages)); - } - } - return 0; - } - - private static Comparator createAlluxioURIComparator() { - return new Comparator() { - @Override - public int compare(AlluxioURI tUri1, AlluxioURI tUri2) { - // ascending order - return tUri1.getPath().compareTo(tUri2.getPath()); - } - }; - } -} diff --git a/tests/src/test/java/alluxio/cli/fs/command/CheckConsistencyCommandIntegrationTest.java b/tests/src/test/java/alluxio/cli/fs/command/CheckConsistencyCommandIntegrationTest.java index 18449071c292..de08cd1499d0 100644 --- a/tests/src/test/java/alluxio/cli/fs/command/CheckConsistencyCommandIntegrationTest.java +++ b/tests/src/test/java/alluxio/cli/fs/command/CheckConsistencyCommandIntegrationTest.java @@ -92,4 +92,23 @@ public void inconsistent() throws Exception { Assert.assertTrue(3 == mFileSystem.getStatus(new AlluxioURI("/testRoot/testDir/testFileB")) .getLength()); } + + /** + * Tests the check consistency shell command correctly identifies a consistent subtree. + */ + @Test + public void wildcard() throws Exception { + FileSystemTestUtils + .createByteFile(mFileSystem, "/testRoot/testDir2/testFileA", + WriteType.CACHE_THROUGH, 10); + + FileSystemTestUtils.createByteFile(mFileSystem, "/testRoot/testDir/testFileB", + WriteType.CACHE_THROUGH, 20); + mFsShell.run("checkConsistency", "/testRoot/*/testFile*"); + String expected = "/testRoot/testDir/testFileB is consistent with the under storage system.\n" + + "/testRoot/testDir2/testFileA is consistent " + + "with the under storage system.\n"; + Assert.assertEquals(expected, mOutput.toString()); + } + } diff --git a/tests/src/test/java/alluxio/cli/fs/command/ChecksumCommandIntegrationTest.java b/tests/src/test/java/alluxio/cli/fs/command/ChecksumCommandIntegrationTest.java index a522cda7ddbf..aa6ea024296a 100644 --- a/tests/src/test/java/alluxio/cli/fs/command/ChecksumCommandIntegrationTest.java +++ b/tests/src/test/java/alluxio/cli/fs/command/ChecksumCommandIntegrationTest.java @@ -45,6 +45,29 @@ public void checksum() throws Exception { } } + /** + * Tests md5 checksum calculation with wildcard. + */ + @Test + public void checksumWildCard() throws Exception { + FileSystemTestUtils.createByteFile(mFileSystem, + "/testDir/testFileA", WriteType.MUST_CACHE, 10); + FileSystemTestUtils.createByteFile(mFileSystem, + "/testDir2/testFileB", WriteType.MUST_CACHE, 10); + mFsShell.run("checksum", "/testDir*/testFile*"); + String str = mOutput.toString(); + String[] splitString = str.split("\\s+"); + + byte[] data = BufferUtils.getIncreasingByteArray(10); + try { + String expectedMd5 = DigestUtils.md5Hex(data); + Assert.assertEquals(splitString[1], expectedMd5); + Assert.assertEquals(splitString[3], expectedMd5); + } catch (Exception e) { + Assert.fail("md5cksum failure not expected: " + e.getMessage()); + } + } + /** * Test invalid args. */ @@ -53,9 +76,9 @@ public void checksumInvalidArgs() throws Exception { mFsShell.run("checksum", "/testFile"); String expected = ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage("/testFile") + "\n"; Assert.assertEquals(expected, mOutput.toString()); - mFsShell.run("mkdir", "/testFolder"); int ret = mFsShell.run("checksum", "/testFolder"); Assert.assertEquals(-1, ret); } + } diff --git a/tests/src/test/java/alluxio/cli/fs/command/ChgrpCommandIntegrationTest.java b/tests/src/test/java/alluxio/cli/fs/command/ChgrpCommandIntegrationTest.java index 2feb4af77b4b..2dd04a13a7e7 100644 --- a/tests/src/test/java/alluxio/cli/fs/command/ChgrpCommandIntegrationTest.java +++ b/tests/src/test/java/alluxio/cli/fs/command/ChgrpCommandIntegrationTest.java @@ -56,4 +56,34 @@ public void chgrpRecursive() throws IOException, AlluxioException { group = mFileSystem.getStatus(new AlluxioURI("/testDir/testFile")).getGroup(); Assert.assertEquals("group2", group); } + + /** + * Tests wildcard functionality. + */ + @Test + public void chgrpWildcard() throws IOException, AlluxioException { + clearLoginUser(); + FileSystemTestUtils.createByteFile(mFileSystem, + "/testDir/foo/testFile1", WriteType.MUST_CACHE, 10); + FileSystemTestUtils.createByteFile(mFileSystem, + "/testDir/foo/testFile2", WriteType.MUST_CACHE, 10); + FileSystemTestUtils.createByteFile(mFileSystem, + "/testDir/bar/testFile3", WriteType.MUST_CACHE, 10); + + mFsShell.run("chgrp", "group1", "/testDir/*/testFile*"); + String group = mFileSystem.getStatus(new AlluxioURI("/testDir/foo/testFile1")).getGroup(); + Assert.assertEquals("group1", group); + group = mFileSystem.getStatus(new AlluxioURI("/testDir/foo/testFile2")).getGroup(); + Assert.assertEquals("group1", group); + group = mFileSystem.getStatus(new AlluxioURI("/testDir/bar/testFile3")).getGroup(); + Assert.assertEquals("group1", group); + // chgrp to another group. + mFsShell.run("chgrp", "group2", "/testDir/*/testFile*"); + group = mFileSystem.getStatus(new AlluxioURI("/testDir/foo/testFile1")).getGroup(); + Assert.assertEquals("group2", group); + group = mFileSystem.getStatus(new AlluxioURI("/testDir/foo/testFile2")).getGroup(); + Assert.assertEquals("group2", group); + group = mFileSystem.getStatus(new AlluxioURI("/testDir/bar/testFile3")).getGroup(); + Assert.assertEquals("group2", group); + } } diff --git a/tests/src/test/java/alluxio/cli/fs/command/ChmodCommandIntegrationTest.java b/tests/src/test/java/alluxio/cli/fs/command/ChmodCommandIntegrationTest.java index fe49fd24562c..ebe9b4f90078 100644 --- a/tests/src/test/java/alluxio/cli/fs/command/ChmodCommandIntegrationTest.java +++ b/tests/src/test/java/alluxio/cli/fs/command/ChmodCommandIntegrationTest.java @@ -66,4 +66,26 @@ public void chmodSymbolic() throws IOException, AlluxioException { permission = mFileSystem.getStatus(new AlluxioURI("/testFile")).getMode(); Assert.assertEquals((short) 0755, permission); } + + /** + * Tests wildcard entries for chmod. + */ + @Test + public void chmodWildCard() throws IOException, AlluxioException { + clearLoginUser(); + FileSystemTestUtils.createByteFile(mFileSystem, + "/testDir/testFile1", WriteType.MUST_CACHE, 10); + FileSystemTestUtils.createByteFile(mFileSystem, + "/testDir2/testFile2", WriteType.MUST_CACHE, 10); + mFsShell.run("chmod", "a=rwx", "/testDir*/testFile*"); + int permission = mFileSystem.getStatus(new AlluxioURI("/testDir/testFile1")).getMode(); + Assert.assertEquals((short) 0777, permission); + permission = mFileSystem.getStatus(new AlluxioURI("/testDir2/testFile2")).getMode(); + Assert.assertEquals((short) 0777, permission); + mFsShell.run("chmod", "u=rwx,go=rx", "/testDir*/testFile*"); + permission = mFileSystem.getStatus(new AlluxioURI("/testDir/testFile1")).getMode(); + Assert.assertEquals((short) 0755, permission); + permission = mFileSystem.getStatus(new AlluxioURI("/testDir2/testFile2")).getMode(); + Assert.assertEquals((short) 0755, permission); + } } diff --git a/tests/src/test/java/alluxio/cli/fs/command/ChownCommandIntegrationTest.java b/tests/src/test/java/alluxio/cli/fs/command/ChownCommandIntegrationTest.java index 1f5618825c29..adda49d0a8e9 100644 --- a/tests/src/test/java/alluxio/cli/fs/command/ChownCommandIntegrationTest.java +++ b/tests/src/test/java/alluxio/cli/fs/command/ChownCommandIntegrationTest.java @@ -198,6 +198,24 @@ public void chownRecursive() throws IOException, AlluxioException { Assert.assertEquals(TEST_USER_2.getUser(), owner); } + /** + * Tests chown with wildcard entries. + */ + @Test + public void chownWildcard() throws IOException, AlluxioException { + clearLoginUser(); + FileSystemTestUtils.createByteFile(mFileSystem, + "/testDir/testFile1", WriteType.MUST_CACHE, 10); + FileSystemTestUtils.createByteFile(mFileSystem, + "/testDir2/testFile2", WriteType.MUST_CACHE, 10); + + mFsShell.run("chown", "-R", TEST_USER_1.getUser(), "/*/testFile*"); + String owner = mFileSystem.getStatus(new AlluxioURI("/testDir/testFile1")).getOwner(); + Assert.assertEquals(TEST_USER_1.getUser(), owner); + owner = mFileSystem.getStatus(new AlluxioURI("/testDir2/testFile2")).getOwner(); + Assert.assertEquals(TEST_USER_1.getUser(), owner); + } + /** * Checks whether the owner and group of the path are expectedOwner and expectedGroup. * diff --git a/tests/src/test/java/alluxio/cli/fs/command/DuCommandIntegrationTest.java b/tests/src/test/java/alluxio/cli/fs/command/DuCommandIntegrationTest.java index d82efb6a9d5d..2b97244c28b1 100644 --- a/tests/src/test/java/alluxio/cli/fs/command/DuCommandIntegrationTest.java +++ b/tests/src/test/java/alluxio/cli/fs/command/DuCommandIntegrationTest.java @@ -44,4 +44,19 @@ public void du() throws Exception { expected += "/testRoot/testDir is 50 bytes\n"; Assert.assertEquals(expected, mOutput.toString()); } + + @Test + public void duWildcard() throws Exception { + FileSystemTestUtils + .createByteFile(mFileSystem, "/testRoot/testDir1/testFileA", WriteType.MUST_CACHE, 10); + FileSystemTestUtils.createByteFile(mFileSystem, "/testRoot/testDir2/testFileB", + WriteType.MUST_CACHE, 20); + + String expected = ""; + // du a file with wildcard + mFsShell.run("du", "/testRoot/*/testFile*"); + expected += "/testRoot/testDir1/testFileA is 10 bytes\n"; + expected += "/testRoot/testDir2/testFileB is 20 bytes\n"; + Assert.assertEquals(expected, mOutput.toString()); + } } diff --git a/tests/src/test/java/alluxio/cli/fs/command/LoadCommandIntegrationTest.java b/tests/src/test/java/alluxio/cli/fs/command/LoadCommandIntegrationTest.java index ab2610cfa469..98ca4bf28f04 100644 --- a/tests/src/test/java/alluxio/cli/fs/command/LoadCommandIntegrationTest.java +++ b/tests/src/test/java/alluxio/cli/fs/command/LoadCommandIntegrationTest.java @@ -80,4 +80,25 @@ public void loadFileWithLocalOption() throws IOException, AlluxioException { status = mFileSystem.getStatus(uri); assertTrue(status.getInAlluxioPercentage() == 100); } + + @Test + public void loadFileWithWildcard() throws IOException, AlluxioException { + FileSystemTestUtils.createByteFile(mFileSystem, "/testDir1/testFile1", WriteType.THROUGH, 10); + FileSystemTestUtils.createByteFile(mFileSystem, "/testDir2/testFile2", WriteType.THROUGH, 10); + AlluxioURI uri = new AlluxioURI("/testDir1/testFile1"); + URIStatus status = mFileSystem.getStatus(uri); + assertFalse(status.getInAlluxioPercentage() == 100); + uri = new AlluxioURI("/testDir2/testFile2"); + status = mFileSystem.getStatus(uri); + assertFalse(status.getInAlluxioPercentage() == 100); + + // Testing loading with wild card + mFsShell.run("load", "/*/testFile*"); + uri = new AlluxioURI("/testDir1/testFile1"); + status = mFileSystem.getStatus(uri); + assertTrue(status.getInAlluxioPercentage() == 100); + uri = new AlluxioURI("/testDir2/testFile2"); + status = mFileSystem.getStatus(uri); + assertTrue(status.getInAlluxioPercentage() == 100); + } } diff --git a/tests/src/test/java/alluxio/cli/fs/command/PersistCommandTest.java b/tests/src/test/java/alluxio/cli/fs/command/PersistCommandTest.java index 1c2f404e0b05..58344131033a 100644 --- a/tests/src/test/java/alluxio/cli/fs/command/PersistCommandTest.java +++ b/tests/src/test/java/alluxio/cli/fs/command/PersistCommandTest.java @@ -175,4 +175,24 @@ public void persistWithAncestorPermission() throws Exception { Assert.assertEquals(grandParentMode, new Mode(ufs.getDirectoryStatus(PathUtils.concatPath(ufsRoot, grandParent)).getMode())); } + + @Test + public void persistWithWildCard() throws Exception { + String filePath1 = "/testPersist1/testFile1"; + String filePath2 = "/testPersist2/testFile2"; + String filePath3 = "/testPersist2/testFile3"; + FileSystemTestUtils.createByteFile(mFileSystem, filePath1, WriteType.MUST_CACHE, 10); + FileSystemTestUtils.createByteFile(mFileSystem, filePath2, WriteType.MUST_CACHE, 20); + FileSystemTestUtils.createByteFile(mFileSystem, filePath3, WriteType.MUST_CACHE, 30); + + Assert.assertFalse(mFileSystem.getStatus(new AlluxioURI(filePath1)).isPersisted()); + Assert.assertFalse(mFileSystem.getStatus(new AlluxioURI(filePath2)).isPersisted()); + Assert.assertFalse(mFileSystem.getStatus(new AlluxioURI(filePath3)).isPersisted()); + + int ret = mFsShell.run("persist", "/*/testFile*"); + Assert.assertEquals(0, ret); + checkFilePersisted(new AlluxioURI(filePath1), 10); + checkFilePersisted(new AlluxioURI(filePath2), 20); + checkFilePersisted(new AlluxioURI(filePath3), 30); + } }