Java 类org.apache.hadoop.fs.shell.Command 实例源码

项目:hops    文件:TestFsShell.java   
@Test
public void testExceptionNullMessage() throws Exception {
  final String cmdName = "-cmdExNullMsg";
  final Command cmd = Mockito.mock(Command.class);
  Mockito.when(cmd.run(Mockito.<String>anyVararg())).thenThrow(
      new IllegalArgumentException());
  Mockito.when(cmd.getUsage()).thenReturn(cmdName);

  final CommandFactory cmdFactory = Mockito.mock(CommandFactory.class);
  final String[] names = {cmdName};
  Mockito.when(cmdFactory.getNames()).thenReturn(names);
  Mockito.when(cmdFactory.getInstance(cmdName)).thenReturn(cmd);

  FsShell shell = new FsShell(new Configuration());
  shell.commandFactory = cmdFactory;
  try (GenericTestUtils.SystemErrCapturer capture =
           new GenericTestUtils.SystemErrCapturer()) {
    ToolRunner.run(shell, new String[]{cmdName});
    Assert.assertThat(capture.getOutput(),
        StringContains.containsString(cmdName
            + ": Null exception message"));
  }
}
项目:hadoop-oss    文件:FsShell.java   
private void displayError(String cmd, String message) {
  for (String line : message.split("\n")) {
    System.err.println(cmd + ": " + line);
    if (cmd.charAt(0) != '-') {
      Command instance = null;
      instance = commandFactory.getInstance("-" + cmd);
      if (instance != null) {
        System.err.println("Did you mean -" + cmd + "?  This command " +
            "begins with a dash.");
      }
    }
  }
}
项目:hadoop    文件:FsShell.java   
private void displayError(String cmd, String message) {
  for (String line : message.split("\n")) {
    System.err.println(cmd + ": " + line);
    if (cmd.charAt(0) != '-') {
      Command instance = null;
      instance = commandFactory.getInstance("-" + cmd);
      if (instance != null) {
        System.err.println("Did you mean -" + cmd + "?  This command " +
            "begins with a dash.");
      }
    }
  }
}
项目:aliyun-oss-hadoop-fs    文件:FsShell.java   
private void displayError(String cmd, String message) {
  for (String line : message.split("\n")) {
    System.err.println(cmd + ": " + line);
    if (cmd.charAt(0) != '-') {
      Command instance = null;
      instance = commandFactory.getInstance("-" + cmd);
      if (instance != null) {
        System.err.println("Did you mean -" + cmd + "?  This command " +
            "begins with a dash.");
      }
    }
  }
}
项目:big-c    文件:FsShell.java   
private void displayError(String cmd, String message) {
  for (String line : message.split("\n")) {
    System.err.println(cmd + ": " + line);
    if (cmd.charAt(0) != '-') {
      Command instance = null;
      instance = commandFactory.getInstance("-" + cmd);
      if (instance != null) {
        System.err.println("Did you mean -" + cmd + "?  This command " +
            "begins with a dash.");
      }
    }
  }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:FsShell.java   
private void displayError(String cmd, String message) {
  for (String line : message.split("\n")) {
    System.err.println(cmd + ": " + line);
    if (cmd.charAt(0) != '-') {
      Command instance = null;
      instance = commandFactory.getInstance("-" + cmd);
      if (instance != null) {
        System.err.println("Did you mean -" + cmd + "?  This command " +
            "begins with a dash.");
      }
    }
  }
}
项目:hadoop-plus    文件:FsShell.java   
private void printInstanceHelp(PrintStream out, Command instance) {
  boolean firstLine = true;
  for (String line : instance.getDescription().split("\n")) {
    String prefix;
    if (firstLine) {
      prefix = instance.getUsage() + ":\t";
      firstLine = false;
    } else {
      prefix = "\t\t";
    }
    System.out.println(prefix + line);
  }    
}
项目:hadoop-plus    文件:FsShell.java   
private void displayError(String cmd, String message) {
  for (String line : message.split("\n")) {
    System.err.println(cmd + ": " + line);
    if (cmd.charAt(0) != '-') {
      Command instance = null;
      instance = commandFactory.getInstance("-" + cmd);
      if (instance != null) {
        System.err.println("Did you mean -" + cmd + "?  This command " +
            "begins with a dash.");
      }
    }
  }
}
项目:prairie    文件:CommandFactoryWithIO.java   
@Override
public Command getInstance(String cmd) {
    Command command = commandFactory.getInstance(cmd);
    command.err = this.err;
    command.out = this.out;
    return command;
}
项目:prairie    文件:CommandFactoryWithIO.java   
@Override
public Command getInstance(String cmdName, Configuration conf) {
    Command command = commandFactory.getInstance(cmdName, conf);
    command.err = this.err;
    command.out = this.out;
    return command;
}
项目:hops    文件:FsShell.java   
private void displayError(String cmd, String message) {
  for (String line : message.split("\n")) {
    System.err.println(cmd + ": " + line);
    if (cmd.charAt(0) != '-') {
      Command instance = null;
      instance = commandFactory.getInstance("-" + cmd);
      if (instance != null) {
        System.err.println("Did you mean -" + cmd + "?  This command " +
            "begins with a dash.");
      }
    }
  }
}
项目:hadoop-TCP    文件:FsShell.java   
private void printInstanceHelp(PrintStream out, Command instance) {
  boolean firstLine = true;
  for (String line : instance.getDescription().split("\n")) {
    String prefix;
    if (firstLine) {
      prefix = instance.getUsage() + ":\t";
      firstLine = false;
    } else {
      prefix = "\t\t";
    }
    System.out.println(prefix + line);
  }    
}
项目:hadoop-TCP    文件:FsShell.java   
private void displayError(String cmd, String message) {
  for (String line : message.split("\n")) {
    System.err.println(cmd + ": " + line);
    if (cmd.charAt(0) != '-') {
      Command instance = null;
      instance = commandFactory.getInstance("-" + cmd);
      if (instance != null) {
        System.err.println("Did you mean -" + cmd + "?  This command " +
            "begins with a dash.");
      }
    }
  }
}
项目:hardfs    文件:FsShell.java   
private void printInstanceHelp(PrintStream out, Command instance) {
  boolean firstLine = true;
  for (String line : instance.getDescription().split("\n")) {
    String prefix;
    if (firstLine) {
      prefix = instance.getUsage() + ":\t";
      firstLine = false;
    } else {
      prefix = "\t\t";
    }
    System.out.println(prefix + line);
  }    
}
项目:hardfs    文件:FsShell.java   
private void displayError(String cmd, String message) {
  for (String line : message.split("\n")) {
    System.err.println(cmd + ": " + line);
    if (cmd.charAt(0) != '-') {
      Command instance = null;
      instance = commandFactory.getInstance("-" + cmd);
      if (instance != null) {
        System.err.println("Did you mean -" + cmd + "?  This command " +
            "begins with a dash.");
      }
    }
  }
}
项目:hadoop-on-lustre2    文件:FsShell.java   
private void printInstanceHelp(PrintStream out, Command instance) {
  boolean firstLine = true;
  for (String line : instance.getDescription().split("\n")) {
    String prefix;
    if (firstLine) {
      prefix = instance.getUsage() + ":\t";
      firstLine = false;
    } else {
      prefix = "\t\t";
    }
    System.out.println(prefix + line);
  }    
}
项目:hadoop-on-lustre2    文件:FsShell.java   
private void displayError(String cmd, String message) {
  for (String line : message.split("\n")) {
    System.err.println(cmd + ": " + line);
    if (cmd.charAt(0) != '-') {
      Command instance = null;
      instance = commandFactory.getInstance("-" + cmd);
      if (instance != null) {
        System.err.println("Did you mean -" + cmd + "?  This command " +
            "begins with a dash.");
      }
    }
  }
}
项目:hadoop-oss    文件:FsShell.java   
private void printInstanceUsage(PrintStream out, Command instance) {
  out.println(getUsagePrefix() + " " + instance.getUsage());
}
项目:hdfs-shell    文件:HadoopDfsCommands.java   
String runCommand(String cmdName, String[] arguments)  {
        final Configuration conf = contextCommands.getConfiguration();

        cmdName = "-" + cmdName;
        final Command command = getCommandInstance(cmdName, conf);
        if (command == null) {
            return "Unknown command " + cmdName;
        }

        if (arguments.length == 0 && !NO_PARAMS_COMMANDS.contains(cmdName)) {
            return command.getDescription();
        }


        contextCommands.updateCurrentWorkingDirectory();

        arguments = replaceHdfsPath(arguments);
        final PrintStream printStream = ClientConnection.context.get();
        if (printStream != null) {
            command.err = printStream;
            command.out = printStream;
        }
//        final ByteArrayOutputStream out = new ByteArrayOutputStream();
//        final PrintStream printStream = new PrintStream(out);
//        command.err = printStream;
//        command.out = printStream;

        final int result = command.run(arguments);
        if (contextCommands.isShowResultCode()) {
            if (result == 0) {
                command.out.println("Exit code = " + result);
            } else {
                command.err.println("Exit code = " + result);
            }
        }

        //printStream.close();
        if (result != 0 && contextCommands.isFailOnError()) {
            throw new RuntimeException("HDFS Command finished with result code " + result);
        }
        return "";
    }
项目:hdfs-shell    文件:HadoopDfsCommands.java   
private static Command getCommandInstance(String cmdName, Configuration conf) {
    final CommandFactory commandFactory = new CommandFactory(conf);
    FsCommand.registerCommands(commandFactory);
    return commandFactory.getInstance(cmdName, conf);
}
项目:hadoop    文件:FsShell.java   
private void printInstanceUsage(PrintStream out, Command instance) {
  out.println(usagePrefix + " " + instance.getUsage());
}
项目:aliyun-oss-hadoop-fs    文件:FsShell.java   
private void printInstanceUsage(PrintStream out, Command instance) {
  out.println(getUsagePrefix() + " " + instance.getUsage());
}
项目:big-c    文件:FsShell.java   
private void printInstanceUsage(PrintStream out, Command instance) {
  out.println(usagePrefix + " " + instance.getUsage());
}
项目:hadoop-2.6.0-cdh5.4.3    文件:FsShell.java   
private void printInstanceUsage(PrintStream out, Command instance) {
  out.println(usagePrefix + " " + instance.getUsage());
}
项目:hadoop-plus    文件:FsShell.java   
private void printInstanceUsage(PrintStream out, Command instance) {
  out.println(usagePrefix + " " + instance.getUsage());
}
项目:prairie    文件:CommandFactoryWithIO.java   
@Override
public void addClass(Class<? extends Command> cmdClass, String... names) {
    commandFactory.addClass(cmdClass, names);
}
项目:prairie    文件:CommandFactoryWithIO.java   
@Override
public void addObject(Command cmdObject, String... names) {
    commandFactory.addObject(cmdObject, names);
}
项目:hops    文件:FsShell.java   
private void printInstanceUsage(PrintStream out, Command instance) {
  out.println(usagePrefix + " " + instance.getUsage());
}
项目:hadoop-TCP    文件:FsShell.java   
private void printInstanceUsage(PrintStream out, Command instance) {
  out.println(usagePrefix + " " + instance.getUsage());
}
项目:hardfs    文件:FsShell.java   
private void printInstanceUsage(PrintStream out, Command instance) {
  out.println(usagePrefix + " " + instance.getUsage());
}
项目:hadoop-on-lustre2    文件:FsShell.java   
private void printInstanceUsage(PrintStream out, Command instance) {
  out.println(usagePrefix + " " + instance.getUsage());
}