Add a new API call: rpc/dispatcher -> "action":"kill"

This allows a user with full access to cancel pending/running jobs within the dispatcher system.

Required arguments: "job_id" : <ID string> or [<ID1>, <ID2>, etc..]

REST Request:
-------------------------------
PUT /rpc/dispatcher
{
   "action" : "kill",
   "job_id" : "sysadm_pkg_install-{9c079421-ace9-4b6e-8870-d023b48f4c49}"
}

WebSocket Request:
-------------------------------
{
   "args" : {
      "action" : "kill",
      "job_id" : "sysadm_pkg_install-{9c079421-ace9-4b6e-8870-d023b48f4c49}"
   },
   "namespace" : "rpc",
   "name" : "dispatcher",
   "id" : "fooid"
}

Response:
-------------------------------
{
  "args": {
    "killed": {
      "jobs": ["sysadm_pkg_install-{9c079421-ace9-4b6e-8870-d023b48f4c49}"]
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "rpc"
}
This commit is contained in:
Ken Moore
2016-04-29 10:25:36 -04:00
parent aa055be7a2
commit d56e90d557
2 changed files with 9 additions and 1 deletions

View File

@@ -172,7 +172,7 @@ QJsonObject Dispatcher::killJobs(QStringList ids){
}
} //end loop over queue types
QJsonObject obj;
obj.insert("killed_jobs", QJsonArray::fromStringList(killed));
obj.insert("jobs", QJsonArray::fromStringList(killed));
return obj;
}

View File

@@ -290,6 +290,14 @@ RestOutputStruct::ExitCode WebSocket::EvaluateDispatcherRequest(bool allaccess,
}else if(act=="list"){
QJsonObject info = DISPATCHER->listJobs();
out->insert("jobs", info);
}else if(act=="kill" && in_args.toObject().contains("job_id") ){
if(!allaccess){ return RestOutputStruct::FORBIDDEN; } //this user does not have permission to modify jobs
QStringList ids;
QJsonValue val = in_args.toObject().value("job_id");
if(val.isArray()){ ids = JsonArrayToStringList(val.toArray()); }
else if(val.isString()){ ids << val.toString(); }
else{ return RestOutputStruct::BADREQUEST; }
out->insert("killed", DISPATCHER->killJobs(ids));
}else{
return RestOutputStruct::BADREQUEST;
}