diff --git a/src/server/Dispatcher.cpp b/src/server/Dispatcher.cpp index 1804c22..c6f5293 100644 --- a/src/server/Dispatcher.cpp +++ b/src/server/Dispatcher.cpp @@ -38,8 +38,6 @@ void DProcess::startProc(){ emit ProcFinished(ID, proclog); return; } - cCmd = cmds.takeFirst(); - success = false; //not finished yet if(proclog.isEmpty()){ //first cmd started proclog.insert("time_started", QDateTime::currentDateTime().toString(Qt::ISODate)); @@ -51,6 +49,8 @@ void DProcess::startProc(){ connect(this, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(cmdFinished(int, QProcess::ExitStatus)) ); connect(this, SIGNAL(error(QProcess::ProcessError)), this, SLOT(cmdError(QProcess::ProcessError)) ); } + cCmd = cmds.takeFirst(); + success = false; //not finished yet proclog.insert("current_cmd",cCmd); //qDebug() << "Proc Starting:" << ID << cmd; this->start(cCmd); @@ -139,7 +139,7 @@ DProcess* Dispatcher::queueProcess(Dispatcher::PROC_QUEUE queue, QString ID, QSt DProcess* Dispatcher::queueProcess(Dispatcher::PROC_QUEUE queue, QString ID, QStringList cmds){ //This is the primary queueProcess() function - all the overloads end up here to do the actual work //For multi-threading, need to emit a signal/slot for this action (object creations need to be in same thread as parent) - qDebug() << "Queue Process:" << queue << ID << cmds; + //qDebug() << "Queue Process:" << queue << ID << cmds; DProcess *P = createProcess(ID, cmds); //connect(this, SIGNAL(mkprocs(Dispatcher::PROC_QUEUE, DProcess*)), this, SLOT(mkProcs(Dispatcher::PROC_QUEUE, DProcess*)) ); emit mkprocs(queue, P); @@ -170,7 +170,7 @@ void Dispatcher::mkProcs(Dispatcher::PROC_QUEUE queue, DProcess *P){ void Dispatcher::ProcFinished(QString ID, QJsonObject log){ //Find the process with this ID and close it down (with proper events) - qDebug() << " - Got Proc Finished Signal:" << ID; + //qDebug() << " - Got Proc Finished Signal:" << ID; LogManager::log(LogManager::DISPATCH, log); //First emit any subsystem-specific event, falling back on the raw log QJsonObject ev = CreateDispatcherEventNotification(ID,log); @@ -204,7 +204,7 @@ for(int i=0; iID; + //qDebug() << "Call Start Proc:" << list[j]->ID; emit DispatchStarting(list[j]->ID); list[j]->startProc(); //QTimer::singleShot(0,list[j], SLOT(startProc()) ); diff --git a/src/server/Dispatcher.h b/src/server/Dispatcher.h index e6a5cf6..5b6761e 100644 --- a/src/server/Dispatcher.h +++ b/src/server/Dispatcher.h @@ -84,7 +84,7 @@ private: // Functions to do parsing out dispatcher queued tasks // Please keep these sorted - QJsonObject parseIohyveFetchOutput(QString outputLog); + void parseIohyveFetchOutput(QString outputLog, QJsonObject *out); private slots: void mkProcs(Dispatcher::PROC_QUEUE, DProcess *P); diff --git a/src/server/DispatcherParsing.cpp b/src/server/DispatcherParsing.cpp index 42ddda4..76a48c9 100644 --- a/src/server/DispatcherParsing.cpp +++ b/src/server/DispatcherParsing.cpp @@ -17,11 +17,16 @@ QJsonObject Dispatcher::CreateDispatcherEventNotification(QString ID, QJsonObjec //Quick flags/simplifications for use later QString cCmd, cLog; //Current command/log for that command (might be a chain of commands) cCmd = log.value("current_cmd").toString(); //This is usually empty if the proc finished - if(!cCmd.isEmpty()){ cLog = log.value(cCmd).toString(); } - bool isFinished = log.contains("return_codes/"+cCmd) || cCmd.isEmpty(); + if(cCmd.isEmpty()){ cCmd = log.value("cmd_list").toArray().last().toString(); } + cLog = log.value(cCmd).toString(); + bool isFinished = (log.value("state").toString()=="finished"); qDebug() << "Check Dispatcher Event:"; qDebug() << " - RAW LOG:" << log; qDebug() << "cCmd:" << cCmd << "cLog:" << cLog << "isFinished:" << isFinished; + //Add the generic process values + args.insert("state",isFinished ? "finished" : "running"); + args.insert("process_details", log); //full process log array here + //Now parse the notification based on the dispatch ID or current command //NOTE: There might be a random string on the end of the ID (to accomodate similar process calls) if(ID.startsWith("sysadm_iohyve")){ @@ -29,13 +34,7 @@ QJsonObject Dispatcher::CreateDispatcherEventNotification(QString ID, QJsonObjec //Now perform additional cmd/system based filtering if(ID.section("::",0,0)=="sysadm_iohyve_fetch" || cCmd.startsWith("iohyve fetch ")){ //Do some parsing of the log - if(isFinished){ - args.insert("state","finished"); - }else{ - args.insert("state","running"); - args.insert("progress", parseIohyveFetchOutput(cLog)); - //args.insert("progress", cLog.section("\n",-1, QString::SectionSkipEmpty)); //send the last line of the fetch - } + parseIohyveFetchOutput(cLog,&args); } } @@ -46,9 +45,15 @@ QJsonObject Dispatcher::CreateDispatcherEventNotification(QString ID, QJsonObjec return args; } -QJsonObject Dispatcher::parseIohyveFetchOutput(QString output) -{ - qDebug() << "Parsing iohyve log" << output.section("\n", -1, QString::SectionSkipEmpty); - QJsonObject ret; - return ret; +void Dispatcher::parseIohyveFetchOutput(QString outputLog, QJsonObject *out){ + QStringList lines = outputLog.split("\n", QString::SkipEmptyParts); + if(lines.isEmpty()){ return; } //nothing to report + for(int i=lines.length()-1; i>=0; i--){ + qDebug() << "Parsing iohyve fetch line:" << lines[i]; + if(!lines[i].contains("% of ")){ continue; } + out->insert("filename", lines[i].section("\t",0,0) ); + out->insert("percent_done",lines[i].section("\t",1,1) ); + out->insert("download_rate",lines[i].section("\t",2,-1) ); + break; + } } diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index 2f2c211..0852070 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -99,7 +99,7 @@ RestOutputStruct::ExitCode WebSocket::EvaluateBackendRequest(const RestInputStru AvailableSubsystems(IN.fullaccess, &avail); if(!avail.contains(namesp+"/"+name)){ return RestOutputStruct::NOTFOUND; } } - qDebug() << "Evaluate Backend Request:" << namesp << name; + //qDebug() << "Evaluate Backend Request:" << namesp << name; //Go through and forward this request to the appropriate sub-system if(namesp=="sysadm" && name=="settings"){ return EvaluateSysadmSettingsRequest(IN.args, out);