Add a new API call:

rpc/dispatcher -> "action":"list"
This will list all the currently running/pending processes within the dispatcher queues.
Possible Queues: "no_queue", "pkg_queue", "iocage_queue"

REST Request:
-------------------------------
PUT /rpc/dispatcher
{
   "action" : "list"
}

WebSocket Request:
-------------------------------
{
   "args" : {
      "action" : "list"
   },
   "namespace" : "rpc",
   "name" : "dispatcher",
   "id" : "fooid"
}

Response:
-------------------------------
{
  "args": {
    "jobs": {
      "pkg_queue": {
        "sysadm_pkg_install-{9c079421-ace9-4b6e-8870-d023b48f4c49}": {
          "commands": [
            "pkg install -y --repository \"pcbsd-major\" misc/pcbsd-meta-mate"
          ],
          "queue_position": "0",
          "state": "running"
        }
      }
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "rpc"
}
This commit is contained in:
Ken Moore
2016-04-29 10:00:43 -04:00
parent 4cee9244e4
commit caad04ece9
3 changed files with 59 additions and 4 deletions

View File

@@ -30,6 +30,7 @@ DProcess::~DProcess(){
}
void DProcess::procReady(){
rawcmds = cmds;
proclog.insert("cmd_list",QJsonArray::fromStringList(cmds));
proclog.insert("process_id",ID);
proclog.insert("state","pending");
@@ -125,6 +126,56 @@ Dispatcher::~Dispatcher(){
}
QJsonObject Dispatcher::listJobs(){
QJsonObject out;
for(int i=0; i<enum_length; i++){
PROC_QUEUE queue = static_cast<PROC_QUEUE>(i);
if(HASH.contains(queue)){
QJsonObject obj;
QList<DProcess*> list = HASH[queue];
for(int j=0; j<list.length(); j++){
QJsonObject proc;
proc.insert("commands", QJsonArray::fromStringList(list[j]->rawcmds));
if(queue!=NO_QUEUE){ proc.insert("queue_position",QString::number(j)); }
if( list[j]->isRunning() ){ proc.insert("state", "running"); }
else if(list[j]->isDone() ){ proc.insert("state", "finished"); }
else{ proc.insert("state","pending"); }
obj.insert(list[j]->ID, proc);
} //end loop over list
QString qname;
switch(queue){
case NO_QUEUE:
qname="no_queue"; break;
case PKG_QUEUE:
qname="pkg_queue"; break;
case IOCAGE_QUEUE:
qname="iocage_queue"; break;
}
out.insert(qname,obj);
}
} //end loop over queue types
return out;
}
QJsonObject Dispatcher::killJobs(QStringList ids){
QStringList killed;
for(int i=0; i<enum_length; i++){
PROC_QUEUE queue = static_cast<PROC_QUEUE>(i);
if(HASH.contains(queue)){
QList<DProcess*> list = HASH[queue];
for(int j=0; j<list.length(); j++){
if(ids.contains(list[j]->ID)){
killed << list[j]->ID;
QTimer::singleShot(10, list[j], SLOT(kill())); //10ms buffer
}
} //end loop over list
}
} //end loop over queue types
QJsonObject obj;
obj.insert("killed_jobs", QJsonArray::fromStringList(killed));
return obj;
}
void Dispatcher::start(QString queuefile){
//Setup connections here (in case it was moved to different thread after creation)
//connect(this, SIGNAL(mkprocs(Dispatcher::PROC_QUEUE, DProcess*)), this, SLOT(mkProcs(Dispatcher::PROC_QUEUE, DProcess*)) );

View File

@@ -22,7 +22,7 @@ public:
//output variables for logging purposes
bool success;
//QDateTime t_started, t_finished;
// QStringList rawcmds; //copy of cmds at start of process
QStringList rawcmds; //copy of cmds at start of process
//Get the current process log (can be run during/after the process runs)
QJsonObject getProcLog();
@@ -61,6 +61,9 @@ public:
Dispatcher();
~Dispatcher();
QJsonObject listJobs();
QJsonObject killJobs(QStringList ids);
public slots:
//Main start/stop
void start(QString queuefile); //load any previously-unrun processes

View File

@@ -23,7 +23,7 @@
#define DEBUG 0
#define SCLISTDELIM QString("::::") //SysCache List Delimiter
//#define SCLISTDELIM QString("::::") //SysCache List Delimiter
RestOutputStruct::ExitCode WebSocket::AvailableSubsystems(bool allaccess, QJsonObject *out){
//Probe the various subsystems to see what is available through this server
//Output format:
@@ -287,8 +287,9 @@ RestOutputStruct::ExitCode WebSocket::EvaluateDispatcherRequest(bool allaccess,
//Return the PENDING result
LogManager::log(LogManager::HOST, "Client Launched Processes["+SockPeerIP+"]: "+ids.join(",") );
out->insert("started", QJsonArray::fromStringList(ids));
//}else if(act=="read"){
}else if(act=="list"){
QJsonObject info = DISPATCHER->listJobs();
out->insert("jobs", info);
}else{
return RestOutputStruct::BADREQUEST;
}