final File topdir;
try {
topdir = CloudClientUtil.getHistoryDir(historyDir);
} catch (ParameterProblem e) {
throw new ExecutionProblem(e.getMessage(), e);
}
final int nextnum = HistoryUtil.findNextSingleNumber(topdir, print);
final String suffix = HistoryUtil.format.format(nextnum);
final String newDirName = HistoryUtil.historyDirPrefix + suffix;
print.debugln("Next directory: " + newDirName);
final File newdir = new File(topdir, newDirName);
final String newdirPath = newdir.getAbsolutePath();
if (newdir.mkdir()) {
print.debugln("Created directory: " + newdirPath);
} else {
// could be a race condition on the name, or odd perm problem
// (note we checked parent dir was writeable)
throw new ExecutionProblem(
"Could not create directory '" + newdirPath + "'");
}
final File runLog =
HistoryUtil.newLogFile(newdir, RunTask.LOG_FILE_NAME, print);
if (runLog != null) {
try {
print.getOpts().setInfoErrFile(runLog.getAbsolutePath());
} catch (Exception e) {
print.errln("Problem setting InfoErrFile: " + e.getMessage());
// carry on
}
}
final File debugLog =
HistoryUtil.newLogFile(newdir, RunTask.DEBUG_LOG_FILE_NAME, print);
if (debugLog != null) {
try {
print.getOpts().setAllOutFile(debugLog.getAbsolutePath());
} catch (Exception e) {
print.errln("Problem setting AllOutFile: " + e.getMessage());
// carry on
}
}
final File eprFile = new File(newdir, HistoryUtil.SINGLE_EPR_FILE_NAME);
final String eprPath = eprFile.getAbsolutePath();
print.debugln("EPR will be written to:");
print.debugln(" - '" + eprPath + "'");
print.debugln("");
final FutureTask task =
this.getWorkspaceTask(workspaceFactoryURL,
eprPath,
metadata,
metadata_fileName,
deploymentRequest,
deploymentRequest_fileName,
sshfile,
newdir,
newDirName,
pollMs,
identityAuthorization,
disableAllStateChecks,
"Running",
null,
false,
false,
print,
null,
null);
this.executor.submit(task);
try {
final Integer retCode = (Integer) task.get();
if (retCode.intValue() == BaseClient.SUCCESS_EXIT_CODE) {
print.infoln("\nRunning: '" + newDirName + "'");
} else {
print.errln("\nProblem running '" + newDirName + "'.");
throw new ExitNow(retCode.intValue());
}
} catch (InterruptedException e) {
throw new ExecutionProblem(e.getMessage(), e);
} catch (ExecutionException e) {
throw new ExecutionProblem(e.getMessage(), e);
}
}