Package org.apache.hive.ptest.execution.LocalCommand

Examples of org.apache.hive.ptest.execution.LocalCommand.CollectPolicy


  /**
   * Execute the given command via the ssh command line tool. If the command
   * exits with status code 255 the command will be tries up to three times.
   */
  public void execute(SSHCommand command) {
    CollectPolicy collector = new CollectPolicy();
    try {
      String commandText = String.format("ssh -v -i %s -l %s %s '%s'", command.getPrivateKey(),
          command.getUser(), command.getHost(), command.getCommand());
      int attempts = 0;
      boolean retry;
      LocalCommand cmd;
      do {
        retry = false;
        cmd = mLocalCommandFactory.create(collector, commandText);
        if(mShutdown) {
          mLogger.warn("Shutting down command " + command);
          cmd.kill();
          command.setExitCode(Constants.EXIT_CODE_UNKNOWN);
          return;
        }
        if(attempts++ <= 3 && cmd.getExitCode() == Constants.EXIT_CODE_UNKNOWN) {
          mLogger.warn("Command exited with " + cmd.getExitCode() + ", will retry: " + command);
          retry = true;
          TimeUnit.SECONDS.sleep(5);
        }
      } while (!mShutdown && retry); // an error occurred, re-try
      command.setExitCode(cmd.getExitCode());
    } catch (Exception e) {
      if(command.getExitCode() == Constants.EXIT_CODE_SUCCESS) {
        command.setExitCode(Constants.EXIT_CODE_EXCEPTION);
      }
      command.setException(e);
    } finally {
      command.setOutput(collector.getOutput());
    }
  }
View Full Code Here


  /**
   * Execute the given RSync. If the command exits with a non-zero
   * exit status the command will be retried up to three times.
   */
  public void execute(RSyncCommand command) {
    CollectPolicy collector = new CollectPolicy();
    boolean release = false;
    try {
      mSemaphore.acquire();
      release = true;
      int attempts = 0;
      boolean retry;
      LocalCommand cmd;
      do {
        retry = false;
        if(command.getType() == RSyncCommand.Type.TO_LOCAL) {
          cmd = mLocalCommandFactory.create(collector,
              String.format("timeout 1h rsync -vaPe \"ssh -i %s\" --timeout 600 %s@%s:%s %s",
                  command.getPrivateKey(), command.getUser(), command.getHost(),
                  command.getRemoteFile(), command.getLocalFile()));
        } else if(command.getType() == RSyncCommand.Type.FROM_LOCAL) {
          cmd = mLocalCommandFactory.create(collector,
              String.format("timeout 1h rsync -vaPe \"ssh -i %s\" --timeout 600 --delete --delete-during --force %s %s@%s:%s",
                  command.getPrivateKey(), command.getLocalFile(), command.getUser(), command.getHost(),
                  command.getRemoteFile()));
        } else {
          throw new UnsupportedOperationException(String.valueOf(command.getType()));
        }
        if(mShutdown) {
          mLogger.warn("Shutting down command " + command);
          cmd.kill();
          command.setExitCode(Constants.EXIT_CODE_UNKNOWN);
          return;
        }
        // 12 is timeout and 255 is unspecified error
        if(attempts++ <= 3 && cmd.getExitCode() != 0) {
          mLogger.warn("Command exited with " + cmd.getExitCode() + ", will retry: " + command);
          retry = true;
          TimeUnit.SECONDS.sleep(20);
        }
      } while (!mShutdown && retry); // an error occurred, re-try
      command.setExitCode(cmd.getExitCode());
    } catch (IOException e) {
      command.setException(e);
    } catch (InterruptedException e) {
      command.setException(e);
    } finally {
      if(release) {
        mSemaphore.release();
      }
      command.setOutput(collector.getOutput());
    }
  }
View Full Code Here

  /**
   * Execute the given command via the ssh command line tool. If the command
   * exits with status code 255 the command will be tries up to three times.
   */
  public void execute(SSHCommand command) {
    CollectPolicy collector = new CollectPolicy();
    try {
      String commandText = String.format("ssh -v -i %s %s -l %s %s '%s'", command.getPrivateKey(),
          mSshOpts, command.getUser(), command.getHost(), command.getCommand());
      int attempts = 0;
      boolean retry;
      LocalCommand cmd;
      do {
        retry = false;
        cmd = mLocalCommandFactory.create(collector, commandText);
        if(mShutdown) {
          mLogger.warn("Shutting down command " + command);
          cmd.kill();
          command.setExitCode(Constants.EXIT_CODE_UNKNOWN);
          return;
        }
        if(attempts++ <= 3 && cmd.getExitCode() == Constants.EXIT_CODE_UNKNOWN) {
          mLogger.warn("Command exited with " + cmd.getExitCode() + ", will retry: " + command);
          retry = true;
          TimeUnit.SECONDS.sleep(5);
        }
      } while (!mShutdown && retry); // an error occurred, re-try
      command.setExitCode(cmd.getExitCode());
    } catch (Exception e) {
      if(command.getExitCode() == Constants.EXIT_CODE_SUCCESS) {
        command.setExitCode(Constants.EXIT_CODE_EXCEPTION);
      }
      command.setException(e);
    } finally {
      command.setOutput(collector.getOutput());
    }
  }
View Full Code Here

  /**
   * Execute the given RSync. If the command exits with a non-zero
   * exit status the command will be retried up to three times.
   */
  public void execute(RSyncCommand command) {
    CollectPolicy collector = new CollectPolicy();
    boolean release = false;
    try {
      mSemaphore.acquire();
      release = true;
      int attempts = 0;
      boolean retry;
      LocalCommand cmd;
      do {
        retry = false;
        if(command.getType() == RSyncCommand.Type.TO_LOCAL) {
          cmd = mLocalCommandFactory.create(collector,
              String.format("timeout 1h rsync -vaPe \"ssh -i %s\" --timeout 600 %s@%s:%s %s",
                  command.getPrivateKey(), command.getUser(), command.getHost(),
                  command.getRemoteFile(), command.getLocalFile()));
        } else if(command.getType() == RSyncCommand.Type.FROM_LOCAL) {
          cmd = mLocalCommandFactory.create(collector,
              String.format("timeout 1h rsync -vaPe \"ssh -i %s\" --timeout 600 --delete --delete-during --force %s %s@%s:%s",
                  command.getPrivateKey(), command.getLocalFile(), command.getUser(), command.getHost(),
                  command.getRemoteFile()));
        } else {
          throw new UnsupportedOperationException(String.valueOf(command.getType()));
        }
        if(mShutdown) {
          mLogger.warn("Shutting down command " + command);
          cmd.kill();
          command.setExitCode(Constants.EXIT_CODE_UNKNOWN);
          return;
        }
        // 12 is timeout and 255 is unspecified error
        if(attempts++ <= 3 && cmd.getExitCode() != 0) {
          mLogger.warn("Command exited with " + cmd.getExitCode() + ", will retry: " + command);
          retry = true;
          TimeUnit.SECONDS.sleep(20);
        }
      } while (!mShutdown && retry); // an error occurred, re-try
      command.setExitCode(cmd.getExitCode());
    } catch (IOException e) {
      command.setException(e);
    } catch (InterruptedException e) {
      command.setException(e);
    } finally {
      if(release) {
        mSemaphore.release();
      }
      command.setOutput(collector.getOutput());
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.hive.ptest.execution.LocalCommand.CollectPolicy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.