Search in sources :

Example 1 with SSHCommand

use of org.apache.hive.ptest.execution.ssh.SSHCommand in project hive by apache.

the class HostExecutor method execInstances.

private List<ListenableFuture<RemoteCommandResult>> execInstances(List<Drone> drones, final String cmd) throws InterruptedException, IOException {
    List<ListenableFuture<RemoteCommandResult>> result = Lists.newArrayList();
    for (final Drone drone : ImmutableList.copyOf(drones)) {
        result.add(mExecutor.submit(new Callable<RemoteCommandResult>() {

            @Override
            public RemoteCommandResult call() throws Exception {
                Map<String, String> templateVariables = Maps.newHashMap(mTemplateDefaults);
                templateVariables.put("instanceName", drone.getInstanceName());
                templateVariables.put("localDir", drone.getLocalDirectory());
                String command = Templates.getTemplateResult(cmd, templateVariables);
                SSHResult result = new SSHCommand(mSSHCommandExecutor, drone.getPrivateKey(), drone.getUser(), drone.getHost(), drone.getInstance(), command, true).call();
                if (result.getExitCode() != Constants.EXIT_CODE_SUCCESS) {
                    // return value not checked due to concurrent access
                    mDrones.remove(drone);
                    mLogger.error("Aborting drone during exec " + command, new AbortDroneException("Drone " + drone + " exited with " + result.getExitCode() + ": " + result));
                    return null;
                } else {
                    return result;
                }
            }
        }));
    }
    return result;
}
Also used : SSHResult(org.apache.hive.ptest.execution.ssh.SSHResult) SSHCommand(org.apache.hive.ptest.execution.ssh.SSHCommand) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Callable(java.util.concurrent.Callable)

Example 2 with SSHCommand

use of org.apache.hive.ptest.execution.ssh.SSHCommand in project hive by apache.

the class CloudExecutionContextProvider method verifyHosts.

private Set<NodeMetadata> verifyHosts(Set<? extends NodeMetadata> hosts) throws CreateHostsFailedException {
    final Set<NodeMetadata> result = Collections.synchronizedSet(new HashSet<NodeMetadata>());
    if (!hosts.isEmpty()) {
        persistHostnamesToLog(hosts);
        ExecutorService executorService = Executors.newFixedThreadPool(Math.min(hosts.size(), 25));
        try {
            for (final NodeMetadata node : hosts) {
                executorService.submit(new Runnable() {

                    @Override
                    public void run() {
                        String ip = publicIpOrHostname(node);
                        SSHCommand command = new SSHCommand(mSSHCommandExecutor, mPrivateKey, mUser, ip, 0, "pkill -f java", true);
                        mSSHCommandExecutor.execute(command);
                        if (command.getExitCode() == Constants.EXIT_CODE_UNKNOWN || command.getException() != null) {
                            LOG.error("Node " + node + " is bad on startup", command.getException());
                            terminateInternal(node);
                        } else {
                            result.add(node);
                        }
                    }
                });
            }
            executorService.shutdown();
            if (!executorService.awaitTermination(10, TimeUnit.MINUTES)) {
                LOG.error("Verify command still executing on a host after 10 minutes");
            }
        } catch (InterruptedException e) {
            terminateInternal(result);
            throw new CreateHostsFailedException("Interrupted while trying to create hosts", e);
        } finally {
            if (!executorService.isShutdown()) {
                executorService.shutdownNow();
            }
        }
    }
    return result;
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) SSHCommand(org.apache.hive.ptest.execution.ssh.SSHCommand) ExecutorService(java.util.concurrent.ExecutorService)

Example 3 with SSHCommand

use of org.apache.hive.ptest.execution.ssh.SSHCommand in project hive by apache.

the class HostExecutor method executeTestBatch.

/**
 * Executes the test batch on the drone in question. If the command
 * exits with a status code of 255 throw an AbortDroneException.
 */
private boolean executeTestBatch(Drone drone, TestBatch batch, Set<TestBatch> failedTestResults) throws IOException, SSHExecutionException, AbortDroneException {
    String scriptName = "hiveptest-" + batch.getName() + ".sh";
    File script = new File(mLocalScratchDirectory, scriptName);
    Map<String, String> templateVariables = Maps.newHashMap(mTemplateDefaults);
    templateVariables.put("instanceName", drone.getInstanceName());
    templateVariables.put("batchName", batch.getName());
    templateVariables.put("testArguments", batch.getTestArguments());
    templateVariables.put("localDir", drone.getLocalDirectory());
    templateVariables.put("logDir", drone.getLocalLogDirectory());
    Preconditions.checkArgument(StringUtils.isNotBlank(batch.getTestModuleRelativeDir()));
    templateVariables.put("testModule", batch.getTestModuleRelativeDir());
    String command = Templates.getTemplateResult("bash $localDir/$instanceName/scratch/" + script.getName(), templateVariables);
    Templates.writeTemplateResult("batch-exec.vm", script, templateVariables);
    copyToDroneFromLocal(drone, script.getAbsolutePath(), "$localDir/$instanceName/scratch/" + scriptName);
    script.delete();
    Stopwatch sw = Stopwatch.createStarted();
    mLogger.info(drone + " executing " + batch + " with " + command);
    RemoteCommandResult sshResult = new SSHCommand(mSSHCommandExecutor, drone.getPrivateKey(), drone.getUser(), drone.getHost(), drone.getInstance(), command, true).call();
    sw.stop();
    mLogger.info("Completed executing tests for batch [{}] on host {}. ElapsedTime(ms)={}", new Object[] { batch.getName(), getHost().toShortString(), sw.elapsed(TimeUnit.MILLISECONDS) });
    File batchLogDir = null;
    if (sshResult.getExitCode() == Constants.EXIT_CODE_UNKNOWN) {
        throw new AbortDroneException("Drone " + drone.toString() + " exited with " + Constants.EXIT_CODE_UNKNOWN + ": " + sshResult);
    }
    if (mShutdown) {
        mLogger.warn("Shutting down host " + mHost.getName());
        return false;
    }
    boolean result;
    if (sshResult.getExitCode() != 0 || sshResult.getException() != null) {
        result = false;
        batchLogDir = Dirs.create(new File(mFailedTestLogDir, batch.getName()));
    } else {
        result = true;
        batchLogDir = Dirs.create(new File(mSuccessfulTestLogDir, batch.getName()));
    }
    copyFromDroneToLocal(drone, batchLogDir.getAbsolutePath(), drone.getLocalLogDirectory() + "/", fetchLogsForSuccessfulTests || !result);
    File logFile = new File(batchLogDir, String.format("%s.txt", batch.getName()));
    PrintWriter writer = new PrintWriter(logFile);
    writer.write(String.format("result = '%s'\n", sshResult.toString()));
    writer.write(String.format("output = '%s'\n", sshResult.getOutput()));
    if (sshResult.getException() != null) {
        sshResult.getException().printStackTrace(writer);
    }
    writer.close();
    return result;
}
Also used : SSHCommand(org.apache.hive.ptest.execution.ssh.SSHCommand) Stopwatch(com.google.common.base.Stopwatch) RemoteCommandResult(org.apache.hive.ptest.execution.ssh.RemoteCommandResult) File(java.io.File) PrintWriter(java.io.PrintWriter)

Aggregations

SSHCommand (org.apache.hive.ptest.execution.ssh.SSHCommand)3 Stopwatch (com.google.common.base.Stopwatch)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 Callable (java.util.concurrent.Callable)1 ExecutorService (java.util.concurrent.ExecutorService)1 RemoteCommandResult (org.apache.hive.ptest.execution.ssh.RemoteCommandResult)1 SSHResult (org.apache.hive.ptest.execution.ssh.SSHResult)1 NodeMetadata (org.jclouds.compute.domain.NodeMetadata)1