if (reqC.length < 2) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
"Missing RunId.");
return;
}
RunId runId = new RunId(reqC[1]);
String user = request.getParameter("sun");
String password = request.getParameter("sp");
// Check the status of the run
boolean found = false;
boolean queued = false;
String terminateStatus = null;
RunResult result = RunResult.getInstance(runId);
if (result != null) {
found = true;
if ( "COMPLETED".equals(result.status) ||
"FAILED".equals(result.status) ||
"KILLED".equals(result.status) ) {
terminateStatus = result.status;
}
} else { // If not found, look in queue
String[] pending = RunQ.listPending();
if (pending != null) {
for (String run : pending) {
if (run.equals(runId.toString())) {
found = true;
queued = true;
break;
}
}
}
}
if (found && terminateStatus == null) { // not yet terminated
// First authenticate the user and make sure he/she is the CLI user.
boolean hasPermission = true;
if (Config.SECURITY_ENABLED) {
if (Config.CLI_SUBMITTER == null ||
Config.CLI_SUBMITTER.length() == 0 ||
!Config.CLI_SUBMITTER.equals(user)) {
hasPermission = false;
}
if (Config.SUBMIT_PASSWORD == null ||
Config.SUBMIT_PASSWORD.length() == 0 ||
!Config.SUBMIT_PASSWORD.equals(password)) {
hasPermission = false;
}
if (AccessController.isKillAllowed(user, runId.toString())) {
hasPermission = false;
}
}
if (hasPermission) {
// No matter of status, the run may be running by now.
// So check for active runs first.
if (RunQ.getHandle().killCurrentRun(runId.toString(), user)
!= null) {
terminateStatus = "KILLING";
} else { // Or the run may have already terminated...
result = RunResult.getInstance(runId);
if (result != null) {
if ( "COMPLETED".equals(result.status) ||
"FAILED".equals(result.status) ||
"KILLED".equals(result.status) ) {
terminateStatus = result.status;
}
} else if (queued) { // Or it still is in the queue
RunQ.getHandle().deleteRun(runId.toString());
terminateStatus = "DELETED";
}
}
} else {
if (queued) // Run was removed in the meantime