bool JobControllerPluginCREAM::CancelJobs(const std::list<Job*>& jobs, std::list<std::string>& IDsProcessed, std::list<std::string>& IDsNotProcessed, bool isGrouped) const { MCCConfig cfg; usercfg.ApplyToConfig(cfg); bool ok = true; for (std::list<Job*>::const_iterator it = jobs.begin(); it != jobs.end(); ++it) { Job& job = **it; CREAMClient gLiteClient(job.JobManagementURL.str() + "/CREAM2", cfg, usercfg.Timeout()); if (!gLiteClient.cancel(job.IDFromEndpoint)) { logger.msg(INFO, "Failed canceling job: %s", job.JobID); ok = false; IDsNotProcessed.push_back(job.JobID); continue; } job.State = JobStateCREAM("CANCELLED"); IDsProcessed.push_back(job.JobID); } return ok; }
bool CREAMClient::stat(const std::string& jobid, Job& job) { logger.msg(VERBOSE, "Creating and sending a status request"); action = "JobInfo"; PayloadSOAP req(cream_ns); XMLNode xjobId = req.NewChild("types:" + action + "Request").NewChild("types:jobId"); xjobId.NewChild("types:id") = jobid; xjobId.NewChild("types:creamURL") = client->GetURL().str(); XMLNode response; if (!process(req, response)) return false; XMLNode jobInfoNode; jobInfoNode = response["result"]["jobInfo"]; XMLNode lastStatusNode = jobInfoNode.Path("status").back(); if (lastStatusNode["name"]) { job.State = JobStateCREAM((std::string)lastStatusNode["name"]); } if (lastStatusNode["failureReason"]) { job.Error.push_back((std::string)lastStatusNode["failureReason"]); } if (!job.State) { logger.msg(VERBOSE, "Unable to retrieve job status."); return false; } if (ISVALID(jobInfoNode["jobId"]["id"])) { job.IDFromEndpoint = (std::string)jobInfoNode["jobId"]["id"]; } if (ISVALID(jobInfoNode["type"])) job.Type = (std::string)jobInfoNode["type"]; if (ISVALID(jobInfoNode["JDL"])) { job.JobDescription = "egee:jdl"; job.JobDescriptionDocument = (std::string)jobInfoNode["JDL"]; std::list<JobDescription> jds; if (JobDescription::Parse(job.JobDescriptionDocument, jds) && !jds.empty()) { if (!jds.front().Application.Input.empty()) job.StdIn = jds.front().Application.Input; if (!jds.front().Application.Output.empty()) job.StdOut = jds.front().Application.Output; if (!jds.front().Application.Error.empty()) job.StdErr = jds.front().Application.Error; if (!jds.front().Resources.QueueName.empty()) { job.Queue = jds.front().Resources.QueueName; } } } if (ISVALID(lastStatusNode["exitCode"])) job.ExitCode = stringtoi((std::string)lastStatusNode["exitCode"]); if (ISVALID(jobInfoNode["delegationProxyInfo"])) { /* Format of delegationProxyInfo node. [ isRFC="<true|false>"; valid from="<mon>/<date>/<yy> <hour>:<min> <AM|PM> (<timezone>)"; valid to="<mon>/<date>/<yy> <hour>:<min> <AM|PM> (<timezone>)"; holder DN="<DN>"; holder AC issuer="<DN>"; VO="<VO-name>"; AC issuer="<DN>"; VOMS attributes=<VOMS-Attributes> ] */ std::string delegationProxy = (std::string)jobInfoNode["delegationProxyInfo"]; std::size_t lBracketPos = delegationProxy.find('['), rBracketPos = delegationProxy.rfind(']'); if (lBracketPos != std::string::npos && rBracketPos != std::string::npos) { delegationProxy = trim(delegationProxy.substr(lBracketPos, rBracketPos - lBracketPos)); } std::list<std::string> tDelegInfo; tokenize(delegationProxy, tDelegInfo, ";"); for (std::list<std::string>::iterator it = tDelegInfo.begin(); it != tDelegInfo.end(); ++it) { std::list<std::string> keyValuePair; tokenize(*it, keyValuePair, "=", "\"", "\""); if (keyValuePair.size() != 2) continue; if (lower(trim(keyValuePair.front())) == "holder dn") job.Owner = trim(keyValuePair.back(), " \""); if (lower(trim(keyValuePair.front())) == "valid to") stringtoTime(trim(keyValuePair.back(), " \""), job.ProxyExpirationTime); } } if (ISVALID(jobInfoNode["localUser"])) job.LocalOwner = (std::string)jobInfoNode["localUser"]; if (ISVALID(jobInfoNode["lastCommand"])) { int job_register_id_first = -1; int job_register_id_last = -1; int job_start_id_first = -1; int job_start_id_last = -1; int local_id = 0; while (true) { if (!jobInfoNode["lastCommand"][local_id]) break; if ((std::string)jobInfoNode["lastCommand"][local_id]["name"] == "JOB_REGISTER") { if (job_register_id_first == -1 && job_register_id_last == -1) { job_register_id_first = local_id; job_register_id_last = local_id; } else if (job_register_id_last > -1) job_register_id_last = local_id; } //end of the JOB_REGISTER if ((std::string)jobInfoNode["lastCommand"][local_id]["name"] == "JOB_START") { if (job_start_id_first == -1 && job_start_id_last == -1) { job_start_id_first = local_id; job_start_id_last = local_id; } else if (job_start_id_last > -1) job_start_id_last = local_id; } //end of the JOB_START local_id++; } //dependent on JOB_REGISTER if (job_register_id_first > -1) if (ISVALID(jobInfoNode["lastCommand"][job_register_id_first]["creationTime"])) { Time time((std::string)jobInfoNode["lastCommand"][job_register_id_first]["creationTime"]); if (time.GetTime() != -1) job.SubmissionTime = time; } if (job_register_id_last > -1) if (ISVALID(jobInfoNode["lastCommand"][job_register_id_last]["creationTime"])) { Time time((std::string)jobInfoNode["lastCommand"][job_register_id_last]["creationTime"]); if (time.GetTime() != -1) job.CreationTime = time; } //end of the JOB_REGISTER //dependent on JOB_START if (job_start_id_first > -1) { if (ISVALID(jobInfoNode["lastCommand"][job_start_id_first]["startSchedulingTime"])) { Time time((std::string)jobInfoNode["lastCommand"][job_start_id_first]["startSchedulingTime"]); if (time.GetTime() != -1) job.ComputingManagerSubmissionTime = time; } if (ISVALID(jobInfoNode["lastCommand"][job_start_id_first]["startProcessingTime"])) { Time time((std::string)jobInfoNode["lastCommand"][job_start_id_first]["startProcessingTime"]); if (time.GetTime() != -1) job.StartTime = time; } } if (job_start_id_last > -1) if (ISVALID(jobInfoNode["lastCommand"][job_start_id_last]["executionCompletedTime"])) { Time time((std::string)jobInfoNode["lastCommand"][job_start_id_last]["executionCompletedTime"]); if (time.GetTime() != -1) job.ComputingManagerEndTime = time; } //end of the JOB_START } //end of the LastCommand if (ISVALID(lastStatusNode["timestamp"]) && (job.State() == "DONE-OK" || job.State() == "DONE-FAILED")) { Time time((std::string)lastStatusNode["timestamp"]); if (time.GetTime() != -1) job.EndTime = time; } return true; }