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

The following examples show how to use org.apache.hadoop.fs.shell.CommandFactory. 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-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 2
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 3
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 4
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 5
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);
}
 
Example 6
Source Project: hadoop   Source File: FsShellPermissions.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Register the permission related commands with the factory
 * @param factory the command factory
 */
public static void registerCommands(CommandFactory factory) {
  factory.addClass(Chmod.class, "-chmod");
  factory.addClass(Chown.class, "-chown");
  factory.addClass(Chgrp.class, "-chgrp");
}
 
Example 7
Source Project: big-c   Source File: FsShellPermissions.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Register the permission related commands with the factory
 * @param factory the command factory
 */
public static void registerCommands(CommandFactory factory) {
  factory.addClass(Chmod.class, "-chmod");
  factory.addClass(Chown.class, "-chown");
  factory.addClass(Chgrp.class, "-chgrp");
}
 
Example 8
Source Project: examples   Source File: Find.java    License: Apache License 2.0 4 votes vote down vote up
/** sets the command factory for later use */
public void setCommandFactory(CommandFactory factory) { // FIXME FsShell should call this
  this.commandFactory = factory;
}
 
Example 9
Source Project: examples   Source File: Find.java    License: Apache License 2.0 4 votes vote down vote up
/** retrieves the command factory */
protected CommandFactory getCommandFactory() {
  return this.commandFactory;
}
 
Example 10
Source Project: examples   Source File: HdfsFindTool.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void registerCommands(CommandFactory factory) {
  super.registerCommands(factory);
  factory.registerCommands(Find.class);
}
 
Example 11
Source Project: hadoop   Source File: FindOptions.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Set the command factory.
 *
 * @param factory {@link CommandFactory}
 */
public void setCommandFactory(CommandFactory factory) {
  this.commandFactory = factory;
}
 
Example 12
Source Project: hadoop   Source File: FindOptions.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Return the command factory.
 *
 * @return {@link CommandFactory}
 */
public CommandFactory getCommandFactory() {
  return this.commandFactory;
}
 
Example 13
Source Project: hadoop   Source File: Find.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Register the names for the count command
 * 
 * @param factory the command factory that will instantiate this class
 */
public static void registerCommands(CommandFactory factory) {
  factory.addClass(Find.class, "-find");
}
 
Example 14
Source Project: big-c   Source File: FindOptions.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Set the command factory.
 *
 * @param factory {@link CommandFactory}
 */
public void setCommandFactory(CommandFactory factory) {
  this.commandFactory = factory;
}
 
Example 15
Source Project: big-c   Source File: FindOptions.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Return the command factory.
 *
 * @return {@link CommandFactory}
 */
public CommandFactory getCommandFactory() {
  return this.commandFactory;
}
 
Example 16
Source Project: big-c   Source File: Find.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Register the names for the count command
 * 
 * @param factory the command factory that will instantiate this class
 */
public static void registerCommands(CommandFactory factory) {
  factory.addClass(Find.class, "-find");
}
 
Example 17
Source Project: examples   Source File: Find.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Register the names for the count command
 * @param factory the command factory that will instantiate this class
 */
public static void registerCommands(CommandFactory factory) {
  factory.addClass(Find.class, "-find");
}
 
Example 18
Source Project: examples   Source File: FindOptions.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Set the command factory.
 * @param factory {@link CommandFactory}
 */
public void setCommandFactory(CommandFactory factory) {
  this.commandFactory = factory;
}
 
Example 19
Source Project: examples   Source File: FindOptions.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Return the command factory.
 * @return {@link CommandFactory}
 */
public CommandFactory getCommandFactory() {
  return this.commandFactory;
}