Java Code Examples for org.apache.hadoop.fs.shell.FsCommand

The following examples show how to use org.apache.hadoop.fs.shell.FsCommand. These examples are extracted from open source projects. 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 Project: hadoop   Source File: TestFsShellReturnCode.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests valid and invalid group arguments to chgrp.
 */
@Test
public void testChgrpGroupValidity() {
  // This test only covers argument parsing, so override to skip processing.
  FsCommand chgrp = new FsShellPermissions.Chgrp() {
    @Override
    protected void processArgument(PathData item) {
    }
  };
  chgrp.setConf(new Configuration());

  // The following are valid (no exception expected).
  chgrp.run("group", "/path");

  // The following are valid only on Windows.
  assertValidArgumentsOnWindows(chgrp, "Group With Spaces", "/path");

  // The following are invalid (exception expected).
  assertIllegalArguments(chgrp, ":gr#oup", "/path");
  assertIllegalArguments(chgrp, ":gr%oup", "/path");
}
 
Example 2
Source Project: big-c   Source File: TestFsShellReturnCode.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests valid and invalid group arguments to chgrp.
 */
@Test
public void testChgrpGroupValidity() {
  // This test only covers argument parsing, so override to skip processing.
  FsCommand chgrp = new FsShellPermissions.Chgrp() {
    @Override
    protected void processArgument(PathData item) {
    }
  };
  chgrp.setConf(new Configuration());

  // The following are valid (no exception expected).
  chgrp.run("group", "/path");

  // The following are valid only on Windows.
  assertValidArgumentsOnWindows(chgrp, "Group With Spaces", "/path");

  // The following are invalid (exception expected).
  assertIllegalArguments(chgrp, ":gr#oup", "/path");
  assertIllegalArguments(chgrp, ":gr%oup", "/path");
}
 
Example 3
Source Project: hadoop-ozone   Source File: OzoneFsShell.java    License: Apache License 2.0 5 votes vote down vote up
protected void registerCommands(CommandFactory factory) {
  // TODO: DFSAdmin subclasses FsShell so need to protect the command
  // registration.  This class should morph into a base class for
  // commands, and then this method can be abstract
  if (this.getClass().equals(OzoneFsShell.class)) {
    factory.registerCommands(FsCommand.class);
  }
}
 
Example 4
Source Project: hdfs-shell   Source File: ContextCommandsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@Ignore
public void generateMethods() {
    final CommandFactory commandFactory = new CommandFactory(new Configuration());
    FsCommand.registerCommands(commandFactory);
    final String[] names = commandFactory.getNames();
    final String collect = Arrays.stream(names).map(item -> "\"" + item.replace("-", "") + "\"").collect(Collectors.joining(","));
    System.out.println(collect);
    Arrays.stream(names).map(commandFactory::getInstance).forEach(item -> {
        String description = "";
        final String[] sentences = item.getDescription().split("\\.");
        if (sentences.length == 0) {
            description = item.getDescription();
        } else {
            description = sentences[0] + ".";
        }


        String cliCommand = String.format("@CliCommand(value = {\"%s\", \"hdfs dfs -%s\"}, help = \"%s\")", item.getCommandName(), item.getCommandName(), description);
        String content = String.format("    public String %s(\n" +
                "            @CliOption(key = {\"\"}, help = \"%s\") String path\n" +
                "    ) {\n" +
                "        return runCommand(\"%s\", path);\n" +
                "    }\n", item.getCommandName(), description, item.getCommandName());

        System.out.println(cliCommand);
        System.out.println(content);

        System.out.println();

    });

}
 
Example 5
Source Project: hadoop   Source File: FsShell.java    License: Apache License 2.0 5 votes vote down vote up
protected void registerCommands(CommandFactory factory) {
  // TODO: DFSAdmin subclasses FsShell so need to protect the command
  // registration.  This class should morph into a base class for
  // commands, and then this method can be abstract
  if (this.getClass().equals(FsShell.class)) {
    factory.registerCommands(FsCommand.class);
  }
}
 
Example 6
Source Project: hadoop   Source File: TestFsShellReturnCode.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Tests combinations of valid and invalid user and group arguments to chown.
 */
@Test
public void testChownUserAndGroupValidity() {
  // This test only covers argument parsing, so override to skip processing.
  FsCommand chown = new FsShellPermissions.Chown() {
    @Override
    protected void processArgument(PathData item) {
    }
  };
  chown.setConf(new Configuration());

  // The following are valid (no exception expected).
  chown.run("user", "/path");
  chown.run("user:group", "/path");
  chown.run(":group", "/path");

  // The following are valid only on Windows.
  assertValidArgumentsOnWindows(chown, "User With Spaces", "/path");
  assertValidArgumentsOnWindows(chown, "User With Spaces:group", "/path");
  assertValidArgumentsOnWindows(chown, "User With Spaces:Group With Spaces",
    "/path");
  assertValidArgumentsOnWindows(chown, "user:Group With Spaces", "/path");
  assertValidArgumentsOnWindows(chown, ":Group With Spaces", "/path");

  // The following are invalid (exception expected).
  assertIllegalArguments(chown, "us!er", "/path");
  assertIllegalArguments(chown, "us^er", "/path");
  assertIllegalArguments(chown, "user:gr#oup", "/path");
  assertIllegalArguments(chown, "user:gr%oup", "/path");
  assertIllegalArguments(chown, ":gr#oup", "/path");
  assertIllegalArguments(chown, ":gr%oup", "/path");
}
 
Example 7
Source Project: hadoop   Source File: TestFsShellReturnCode.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that for the given command, the given arguments are considered
 * invalid.  The expectation is that the command will throw
 * IllegalArgumentException.
 * 
 * @param cmd FsCommand to check
 * @param args String... arguments to check
 */
private static void assertIllegalArguments(FsCommand cmd, String... args) {
  try {
    cmd.run(args);
    fail("Expected IllegalArgumentException from args: " +
      Arrays.toString(args));
  } catch (IllegalArgumentException e) {
  }
}
 
Example 8
Source Project: hadoop   Source File: TestFsShellReturnCode.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that for the given command, the given arguments are considered valid
 * on Windows, but invalid elsewhere.
 * 
 * @param cmd FsCommand to check
 * @param args String... arguments to check
 */
private static void assertValidArgumentsOnWindows(FsCommand cmd,
    String... args) {
  if (Shell.WINDOWS) {
    cmd.run(args);
  } else {
    assertIllegalArguments(cmd, args);
  }
}
 
Example 9
Source Project: big-c   Source File: FsShell.java    License: Apache License 2.0 5 votes vote down vote up
protected void registerCommands(CommandFactory factory) {
  // TODO: DFSAdmin subclasses FsShell so need to protect the command
  // registration.  This class should morph into a base class for
  // commands, and then this method can be abstract
  if (this.getClass().equals(FsShell.class)) {
    factory.registerCommands(FsCommand.class);
  }
}
 
Example 10
Source Project: big-c   Source File: TestFsShellReturnCode.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Tests combinations of valid and invalid user and group arguments to chown.
 */
@Test
public void testChownUserAndGroupValidity() {
  // This test only covers argument parsing, so override to skip processing.
  FsCommand chown = new FsShellPermissions.Chown() {
    @Override
    protected void processArgument(PathData item) {
    }
  };
  chown.setConf(new Configuration());

  // The following are valid (no exception expected).
  chown.run("user", "/path");
  chown.run("user:group", "/path");
  chown.run(":group", "/path");

  // The following are valid only on Windows.
  assertValidArgumentsOnWindows(chown, "User With Spaces", "/path");
  assertValidArgumentsOnWindows(chown, "User With Spaces:group", "/path");
  assertValidArgumentsOnWindows(chown, "User With Spaces:Group With Spaces",
    "/path");
  assertValidArgumentsOnWindows(chown, "user:Group With Spaces", "/path");
  assertValidArgumentsOnWindows(chown, ":Group With Spaces", "/path");

  // The following are invalid (exception expected).
  assertIllegalArguments(chown, "us!er", "/path");
  assertIllegalArguments(chown, "us^er", "/path");
  assertIllegalArguments(chown, "user:gr#oup", "/path");
  assertIllegalArguments(chown, "user:gr%oup", "/path");
  assertIllegalArguments(chown, ":gr#oup", "/path");
  assertIllegalArguments(chown, ":gr%oup", "/path");
}
 
Example 11
Source Project: big-c   Source File: TestFsShellReturnCode.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that for the given command, the given arguments are considered
 * invalid.  The expectation is that the command will throw
 * IllegalArgumentException.
 * 
 * @param cmd FsCommand to check
 * @param args String... arguments to check
 */
private static void assertIllegalArguments(FsCommand cmd, String... args) {
  try {
    cmd.run(args);
    fail("Expected IllegalArgumentException from args: " +
      Arrays.toString(args));
  } catch (IllegalArgumentException e) {
  }
}
 
Example 12
Source Project: big-c   Source File: TestFsShellReturnCode.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that for the given command, the given arguments are considered valid
 * on Windows, but invalid elsewhere.
 * 
 * @param cmd FsCommand to check
 * @param args String... arguments to check
 */
private static void assertValidArgumentsOnWindows(FsCommand cmd,
    String... args) {
  if (Shell.WINDOWS) {
    cmd.run(args);
  } else {
    assertIllegalArguments(cmd, args);
  }
}
 
Example 13
Source Project: hdfs-shell   Source File: HadoopDfsCommands.java    License: Apache License 2.0 4 votes vote down vote up
private static Command getCommandInstance(String cmdName, Configuration conf) {
    final CommandFactory commandFactory = new CommandFactory(conf);
    FsCommand.registerCommands(commandFactory);
    return commandFactory.getInstance(cmdName, conf);
}