use of org.apache.hive.ptest.execution.ssh.RemoteCommandResult in project hive by apache.
the class Phase method initalizeHosts.
protected List<RemoteCommandResult> initalizeHosts() throws Exception {
List<ListenableFuture<List<RemoteCommandResult>>> futures = Lists.newArrayList();
ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(hostExecutors.size()));
try {
for (final HostExecutor hostExecutor : hostExecutors) {
futures.add(executor.submit(new Callable<List<RemoteCommandResult>>() {
@Override
public List<RemoteCommandResult> call() throws Exception {
return initalizeHost(hostExecutor);
}
}));
}
List<RemoteCommandResult> results = Lists.newArrayList();
for (ListenableFuture<List<RemoteCommandResult>> future : futures) {
List<RemoteCommandResult> result = future.get();
if (result != null) {
results.addAll(result);
}
}
executor.shutdown();
return results;
} finally {
if (executor.isShutdown()) {
executor.shutdownNow();
}
}
}
use of org.apache.hive.ptest.execution.ssh.RemoteCommandResult 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;
}
Aggregations