Java Code Examples for org.apache.hadoop.util.Shell#ExitCodeException

The following examples show how to use org.apache.hadoop.util.Shell#ExitCodeException . 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 File: HBaseClusterManager.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Execute the given command on the host using SSH
 * @return pair of exit code and command output
 * @throws IOException if something goes wrong.
 */
protected Pair<Integer, String> exec(String hostname, ServiceType service, String... cmd)
  throws IOException {
  LOG.info("Executing remote command: {}, hostname:{}", StringUtils.join(cmd, " "),
      hostname);

  RemoteShell shell = new RemoteShell(hostname, getServiceUser(service), cmd);
  try {
    shell.execute();
  } catch (Shell.ExitCodeException ex) {
    // capture the stdout of the process as well.
    String output = shell.getOutput();
    // add output for the ExitCodeException.
    throw new Shell.ExitCodeException(ex.getExitCode(), "stderr: " + ex.getMessage()
      + ", stdout: " + output);
  }

  LOG.info("Executed remote command, exit code:{} , output:{}", shell.getExitCode(),
      shell.getOutput());

  return new Pair<>(shell.getExitCode(), shell.getOutput());
}
 
Example 2
Source File: HBaseClusterManager.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Execute the given command on the host using SSH
 * @return pair of exit code and command output
 * @throws IOException if something goes wrong.
 */
public Pair<Integer, String> execSudo(String hostname, long timeout, String... cmd)
    throws IOException {
  LOG.info("Executing remote command: {} , hostname:{}", StringUtils.join(cmd, " "),
      hostname);

  RemoteSudoShell shell = new RemoteSudoShell(hostname, cmd, timeout);
  try {
    shell.execute();
  } catch (Shell.ExitCodeException ex) {
    // capture the stdout of the process as well.
    String output = shell.getOutput();
    // add output for the ExitCodeException.
    throw new Shell.ExitCodeException(ex.getExitCode(), "stderr: " + ex.getMessage()
        + ", stdout: " + output);
  }

  LOG.info("Executed remote command, exit code:{} , output:{}", shell.getExitCode(),
      shell.getOutput());

  return new Pair<>(shell.getExitCode(), shell.getOutput());
}
 
Example 3
Source File: GracefulRollingRestartRsAction.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void perform() throws Exception {
  getLogger().info("Performing action: Rolling restarting non-master region servers");
  List<ServerName> selectedServers = selectServers();

  getLogger().info("Disabling balancer to make unloading possible");
  setBalancer(false, true);

  for (ServerName server : selectedServers) {
    String rsName = server.getAddress().toString();
    try (RegionMover rm =
        new RegionMover.RegionMoverBuilder(rsName, getConf()).ack(true).build()) {
      getLogger().info("Unloading {}", server);
      rm.unload();
      getLogger().info("Restarting {}", server);
      gracefulRestartRs(server, sleepTime);
      getLogger().info("Loading {}", server);
      rm.load();
    } catch (Shell.ExitCodeException e) {
      getLogger().info("Problem restarting but presume successful; code={}", e.getExitCode(), e);
    }
    sleep(RandomUtils.nextInt(0, (int)sleepTime));
  }
  getLogger().info("Enabling balancer");
  setBalancer(true, true);
}
 
Example 4
Source File: ShellExecEndpointCoprocessor.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Execute {@code shell} and collect results into {@code builder} as side-effects.
 */
private void doExec(
  final Shell.ShellCommandExecutor shell,
  final ShellExecResponse.Builder builder
) throws IOException {
  try {
    shell.execute();
    builder
      .setExitCode(shell.getExitCode())
      .setStdout(shell.getOutput());
  } catch (Shell.ExitCodeException e) {
    LOG.warn("Launched process failed", e);
    builder
      .setExitCode(e.getExitCode())
      .setStdout(shell.getOutput())
      .setStderr(e.getMessage());
  }
}
 
Example 5
Source File: DockerContainerExecutor.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the process with the specified pid is alive.
 *
 * @param pid String pid
 * @return boolean true if the process is alive
 */
@VisibleForTesting
public static boolean containerIsAlive(String pid) throws IOException {
  try {
    new ShellCommandExecutor(Shell.getCheckProcessIsAliveCommand(pid))
      .execute();
    // successful execution means process is alive
    return true;
  }
  catch (Shell.ExitCodeException e) {
    // failure (non-zero exit code) means process is not alive
    return false;
  }
}
 
Example 6
Source File: DockerContainerExecutor.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the process with the specified pid is alive.
 *
 * @param pid String pid
 * @return boolean true if the process is alive
 */
@VisibleForTesting
public static boolean containerIsAlive(String pid) throws IOException {
  try {
    new ShellCommandExecutor(Shell.getCheckProcessIsAliveCommand(pid))
      .execute();
    // successful execution means process is alive
    return true;
  }
  catch (Shell.ExitCodeException e) {
    // failure (non-zero exit code) means process is not alive
    return false;
  }
}
 
Example 7
Source File: ThriftServer.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
protected void printUsageAndExit(Options options, int exitCode)
    throws Shell.ExitCodeException {
  HelpFormatter formatter = new HelpFormatter();
  formatter.printHelp("Thrift", null, options,
      "To start the Thrift server run 'hbase-daemon.sh start thrift2' or " +
          "'hbase thrift2'\n" +
          "To shutdown the thrift server run 'hbase-daemon.sh stop thrift2' or" +
          " send a kill signal to the thrift server pid",
      true);
  throw new Shell.ExitCodeException(exitCode, "");
}
 
Example 8
Source File: ThriftServer.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
protected void parseCommandLine(CommandLine cmd, Options options) throws Shell.ExitCodeException {
  super.parseCommandLine(cmd, options);
  boolean readOnly = THRIFT_READONLY_ENABLED_DEFAULT;
  if (cmd.hasOption(READONLY_OPTION)) {
    readOnly = true;
  }
  conf.setBoolean(THRIFT_READONLY_ENABLED, readOnly);
}