templateVariables);
Templates.writeTemplateResult("batch-exec.vm", script, templateVariables);
copyToDroneFromLocal(drone, script.getAbsolutePath(), "$localDir/$instanceName/scratch/" + scriptName);
script.delete();
mLogger.info(drone + " executing " + batch + " with " + command);
RemoteCommandResult sshResult = new SSHCommand(mSSHCommandExecutor, drone.getPrivateKey(), drone.getUser(),
drone.getHost(), drone.getInstance(), command).
call();
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() + "/");
if(failedTestResults.size() > MAX_SOURCE_DIRS) {
File sourceDir = new File(batchLogDir, "source");
if(sourceDir.isDirectory()) {
mLogger.info("Max source directories exceeded, deleting " + sourceDir.getAbsolutePath()
+ ":" + FileUtils.deleteQuietly(sourceDir));
}
}
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;
}