Package org.apache.hive.ptest.execution

Examples of org.apache.hive.ptest.execution.LocalCommand$OutputPolicy


    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);
View Full Code Here


    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 {
View Full Code Here

    localCommandFactory = new MockLocalCommandFactory(LOG);
  }

  @Test
  public void testShutdownBeforeWaitFor() throws Exception {
    LocalCommand localCommand = mock(LocalCommand.class);
    localCommandFactory.setInstance(localCommand);
    SSHCommandExecutor executor = new SSHCommandExecutor(LOG, localCommandFactory,
      "-o StrictHostKeyChecking=no");
    Assert.assertFalse(executor.isShutdown());
    executor.shutdownNow();
View Full Code Here

    }
    verify(localCommand, times(1)).kill();
  }
  @Test
  public void testShutdownDuringWaitFor() throws Exception {
    LocalCommand localCommand = mock(LocalCommand.class);
    localCommandFactory.setInstance(localCommand);
    final SSHCommandExecutor executor = new SSHCommandExecutor(LOG, localCommandFactory,
      "-o StrictHostKeyChecking=no");
    Assert.assertFalse(executor.isShutdown());
    when(localCommand.getExitCode()).thenAnswer(new Answer<Integer>() {
      @Override
      public Integer answer(InvocationOnMock invocation) throws Throwable {
        executor.shutdownNow();
        return Constants.EXIT_CODE_UNKNOWN;
      }
View Full Code Here

    localCommandFactory = new MockLocalCommandFactory(LOG);
  }

  @Test
  public void testShutdownBeforeWaitFor() throws Exception {
    LocalCommand localCommand = mock(LocalCommand.class);
    localCommandFactory.setInstance(localCommand);
    RSyncCommandExecutor executor = new RSyncCommandExecutor(LOG, 1, localCommandFactory);
    Assert.assertFalse(executor.isShutdown());
    executor.shutdownNow();
    RSyncCommand command = new RSyncCommand(executor, "privateKey", "user", "host", 1, "local", "remote", RSyncCommand.Type.FROM_LOCAL);
View Full Code Here

    }
    verify(localCommand, times(1)).kill();
  }
  @Test
  public void testShutdownDuringWaitFor() throws Exception {
    LocalCommand localCommand = mock(LocalCommand.class);
    localCommandFactory.setInstance(localCommand);
    final RSyncCommandExecutor executor = new RSyncCommandExecutor(LOG, 1, localCommandFactory);
    Assert.assertFalse(executor.isShutdown());
    when(localCommand.getExitCode()).thenAnswer(new Answer<Integer>() {
      @Override
      public Integer answer(InvocationOnMock invocation) throws Throwable {
        executor.shutdownNow();
        return Constants.EXIT_CODE_UNKNOWN;
      }
View Full Code Here

    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);
View Full Code Here

    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 {
View Full Code Here

    localCommandFactory = new MockLocalCommandFactory(LOG);
  }

  @Test
  public void testShutdownBeforeWaitFor() throws Exception {
    LocalCommand localCommand = mock(LocalCommand.class);
    localCommandFactory.setInstance(localCommand);
    SSHCommandExecutor executor = new SSHCommandExecutor(LOG, localCommandFactory);
    Assert.assertFalse(executor.isShutdown());
    executor.shutdownNow();
    SSHCommand command = new SSHCommand(executor, "privateKey", "user", "host", 1, "whoami");
View Full Code Here

    }
    verify(localCommand, times(1)).kill();
  }
  @Test
  public void testShutdownDuringWaitFor() throws Exception {
    LocalCommand localCommand = mock(LocalCommand.class);
    localCommandFactory.setInstance(localCommand);
    final SSHCommandExecutor executor = new SSHCommandExecutor(LOG, localCommandFactory);
    Assert.assertFalse(executor.isShutdown());
    when(localCommand.getExitCode()).thenAnswer(new Answer<Integer>() {
      @Override
      public Integer answer(InvocationOnMock invocation) throws Throwable {
        executor.shutdownNow();
        return Constants.EXIT_CODE_UNKNOWN;
      }
View Full Code Here

TOP

Related Classes of org.apache.hive.ptest.execution.LocalCommand$OutputPolicy

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.