This commit is contained in:
Kris Moore
2016-03-11 08:10:07 -05:00
5 changed files with 33 additions and 26 deletions

View File

@@ -20,7 +20,7 @@ DProcess::DProcess(QObject *parent) : QProcess(parent){
connect(uptimer, SIGNAL(timeout()), this, SLOT(emitUpdate()) );
this->setProcessEnvironment(QProcessEnvironment::systemEnvironment());
this->setProcessChannelMode(QProcess::MergedChannels);
connect(this, SIGNAL(readyRead()), this, SLOT(updateLog()) );
connect(this, SIGNAL(readyReadStandardOutput()), this, SLOT(updateLog()) );
}
DProcess::~DProcess(){
@@ -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; i<enum_length; i++){
j--;
}else{
//Need to start this one - has not run yet
qDebug() << "Call Start Proc:" << list[j]->ID;
//qDebug() << "Call Start Proc:" << list[j]->ID;
emit DispatchStarting(list[j]->ID);
list[j]->startProc();
//QTimer::singleShot(0,list[j], SLOT(startProc()) );

View File

@@ -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);

View File

@@ -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();
qDebug() << "Check Dispatcher Event:";
qDebug() << " - RAW LOG:" << log;
qDebug() << "cCmd:" << cCmd << "cLog:" << cLog << "isFinished:" << isFinished;
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,16 @@ 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){
//Note: this is the standard parsing for a "fetch" call
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 ") && !lines[i].endsWith(" Bps") ){ 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;
}
}

View File

@@ -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);

View File

@@ -80,7 +80,8 @@ QString NetDevice::ipv6AsString(){
addrs = addrs->ifa_next;
}
}
free(addrs);
// Causes crash in some cases
//free(addrs);
if(sadd==0){ qDebug() << "No socket address found"; return ""; }
//Now get the IPv6 address in string form
char straddr[INET6_ADDRSTRLEN];