Ignore:
Timestamp:
Oct 21, 2013 8:12:00 AM (6 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, 9.2-release, releng/10.0, releng/10.0.1
Children:
4bf853e
Parents:
dca28eb
Message:

Remove the old life-preserver from the src-qt4/life-preserver dir, and replace it with src-qt4/life-preserver/lp-tray and src-qt4/life-preserver/lp-gui.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • src-qt4/life-preserver/lp-tray/LPWatcher.cpp

    r490345a r6a2483b  
    7878  logfile->close(); 
    7979  timer->stop(); 
     80} 
     81 
     82void LPWatcher::refresh(){ 
     83  QTimer::singleShot(1, this, SLOT(checkPoolStatus()) ); 
    8084} 
    8185 
     
    143147// ------------------------------------- 
    144148void LPWatcher::readLogFile(bool quiet){ 
     149  QStringList reppools = listReplicatedPools(); 
    145150  QTextStream in(logfile); 
    146151  while(!LFSTREAM->atEnd()){ 
     
    167172      FILE_REPLICATION = dev; 
    168173      dev = message.section(" ",5,5,QString::SectionSkipEmpty); 
    169       startRepFileWatcher(); 
    170       //Set the appropriate status variables 
    171       LOGS.insert(20,"STARTED"); 
    172       LOGS.insert(21, dev); //zpool 
    173       LOGS.insert(22, tr("Replication Starting") ); //summary 
    174       LOGS.insert(23, QString(tr("Starting replication for %1")).arg(dev) ); //Full message 
    175       LOGS.insert(24, timestamp); //full timestamp 
    176       LOGS.insert(25, time); // time only 
    177       LOGS.insert(26,tr("Replication Log")+" <"+FILE_REPLICATION+">"); //log file 
    178       if(!quiet){ emit MessageAvailable("replication"); } 
     174      //Make sure the device is currently setup for replication 
     175      if( !reppools.contains(dev) ){ FILE_REPLICATION.clear(); continue; } 
     176      //Try to start the replication watcher 
     177      if( startRepFileWatcher() ){ 
     178        //Set the appropriate status variables 
     179        LOGS.insert(20,"STARTED"); 
     180        LOGS.insert(21, dev); //zpool 
     181        LOGS.insert(22, tr("Replication Starting") ); //summary 
     182        LOGS.insert(23, QString(tr("Starting replication for %1")).arg(dev) ); //Full message 
     183        LOGS.insert(24, timestamp); //full timestamp 
     184        LOGS.insert(25, time); // time only 
     185        LOGS.insert(26,tr("Replication Log")+" <"+FILE_REPLICATION+">"); //log file 
     186        if(!quiet){ emit MessageAvailable("replication"); } 
     187      } 
    179188    }else if(message.contains("finished replication")){ 
    180189      stopRepFileWatcher(); 
    181190      dev = message.section(" ",-1).simplified(); 
    182       //Now set the status of the process 
    183       LOGS.insert(20,"FINISHED"); 
    184       LOGS.insert(21,dev); //dataset 
    185       LOGS.insert(22, tr("Finished Replication") ); //summary 
    186       LOGS.insert(23, QString(tr("Finished replication for %1")).arg(dev) ); 
    187       LOGS.insert(24, timestamp); //full timestamp 
    188       LOGS.insert(25, time); // time only 
    189       LOGS.insert(26, ""); //clear the log file entry 
    190       if(!quiet){ emit MessageAvailable("replication"); } 
     191      //Make sure the device is currently setup for replication 
     192      if( reppools.contains(dev) ){ 
     193        //Now set the status of the process 
     194        LOGS.insert(20,"FINISHED"); 
     195        LOGS.insert(21,dev); //dataset 
     196        LOGS.insert(22, tr("Finished Replication") ); //summary 
     197        LOGS.insert(23, QString(tr("Finished replication for %1")).arg(dev) ); 
     198        LOGS.insert(24, timestamp); //full timestamp 
     199        LOGS.insert(25, time); // time only 
     200        LOGS.insert(26, ""); //clear the log file entry 
     201        if(!quiet){ emit MessageAvailable("replication"); } 
     202      }else if( !reppools.contains( LOGS.value(21) ) ){ 
     203        //Clear the current replication log, device was removed from replication 
     204        LOGS.remove(20); 
     205        LOGS.remove(21); 
     206        LOGS.remove(22); 
     207        LOGS.remove(23); 
     208        LOGS.remove(24); 
     209        LOGS.remove(25); 
     210        LOGS.remove(26); 
     211        if(!quiet){ emit MessageAvailable(""); } 
     212      } 
    191213    }else if( message.contains("failed replication") ){ 
    192214      stopRepFileWatcher(); 
    193215      //Now set the status of the process 
    194216      dev = message.section(" ",-1).simplified(); 
    195       QString file = log.section("LOGFILE:",1,1).simplified(); 
    196       QString tt = QString(tr("Replication Failed for %1")).arg(dev) +"\n"+ QString(tr("Logfile available at: %1")).arg(file); 
    197       LOGS.insert(20,"ERROR"); 
    198       LOGS.insert(21,dev); //dataset 
    199       LOGS.insert(22, tr("Replication Failed") ); //summary 
    200       LOGS.insert(23, tt ); 
    201       LOGS.insert(24, timestamp); //full timestamp 
    202       LOGS.insert(25, time); // time only       
    203       LOGS.insert(26, tr("Replication Error Log")+" <"+file+">" ); 
    204       if(!quiet){ emit MessageAvailable("replication"); } 
     217      //Make sure the device is currently setup for replication 
     218      if( reppools.contains(dev) ){ 
     219        //Update the logs 
     220        QString file = log.section("LOGFILE:",1,1).simplified(); 
     221        QString tt = QString(tr("Replication Failed for %1")).arg(dev) +"\n"+ QString(tr("Logfile available at: %1")).arg(file); 
     222        LOGS.insert(20,"ERROR"); 
     223        LOGS.insert(21,dev); //dataset 
     224        LOGS.insert(22, tr("Replication Failed") ); //summary 
     225        LOGS.insert(23, tt ); 
     226        LOGS.insert(24, timestamp); //full timestamp 
     227        LOGS.insert(25, time); // time only       
     228        LOGS.insert(26, tr("Replication Error Log")+" <"+file+">" ); 
     229        if(!quiet){ emit MessageAvailable("replication"); } 
     230      }else if( !reppools.contains( LOGS.value(21) ) ){ 
     231        //Clear the current replication log, device was removed from replication 
     232        LOGS.remove(20); 
     233        LOGS.remove(21); 
     234        LOGS.remove(22); 
     235        LOGS.remove(23); 
     236        LOGS.remove(24); 
     237        LOGS.remove(25); 
     238        LOGS.remove(26); 
     239        if(!quiet){ emit MessageAvailable(""); } 
     240      } 
    205241    } 
    206242           
     
    253289} 
    254290 
    255 void LPWatcher::startRepFileWatcher(){ 
     291bool LPWatcher::startRepFileWatcher(){ 
    256292  //qDebug() << "Start Rep File Watcher:" << FILE_REPLICATION; 
    257   if(FILE_REPLICATION.isEmpty()){ return; } 
    258  
    259   if(watcher->files().contains(FILE_REPLICATION)){ return; } //duplicate - file already opened 
     293  if(FILE_REPLICATION.isEmpty()){ return false; } 
     294  if(watcher->files().contains(FILE_REPLICATION)){ return true; } //duplicate - file already opened 
    260295  /*else if(!watcher->files().isEmpty()){  
    261296    //Check that the file watcher is not already operating on a file 
     
    267302  }*/ 
    268303  //Check to make sure that lpreserver actually has a process running before starting this 
    269   if( !isReplicationRunning() ){ FILE_REPLICATION.clear(); return; } 
     304  if( !isReplicationRunning() ){ qDebug() << "PID not found"; FILE_REPLICATION.clear(); return false; } 
    270305  //Check for the existance of the file to watch and create it as necessary   
    271306  if(!QFile::exists(FILE_REPLICATION)){ system( QString("touch "+FILE_REPLICATION).toUtf8() ); } 
     
    276311  watcher->addPath(FILE_REPLICATION); 
    277312  //qDebug() << "Finished starting rep file watcher"; 
     313  return true; 
    278314} 
    279315 
     
    313349  //Check for the replication PID 
    314350  QDir dir("/var/db/lpreserver"); 
    315   QStringList files = dir.entryList( QStringList() << ".reptask-*" ); 
     351  QStringList files = dir.entryList( QStringList() << ".reptask-*", QDir::Files | QDir::Hidden); 
    316352  return ( !files.isEmpty() ); 
     353} 
     354 
     355QStringList LPWatcher::listReplicatedPools(){ 
     356  QStringList out; 
     357  QStringList cmdout = getCmdOutput("lpreserver replicate list"); 
     358  for(int i=0; i<cmdout.length(); i++){ 
     359    if(cmdout[i].contains("->")){ 
     360      QString ds = cmdout[i].section("->",0,0).simplified(); 
     361      if(!ds.isEmpty()){ out << ds; } 
     362    } 
     363  } 
     364  return out; 
     365} 
     366 
     367QStringList LPWatcher::getCmdOutput(QString  cmd){ 
     368  QProcess *proc = new QProcess; 
     369  proc->setProcessChannelMode(QProcess::MergedChannels); 
     370  proc->start(cmd); 
     371  while(!proc->waitForFinished(300)){ 
     372    QCoreApplication::processEvents(); 
     373  } 
     374  QStringList out = QString(proc->readAllStandardOutput()).split("\n");  
     375  delete proc;   
     376  return out;    
    317377} 
    318378 
     
    327387void LPWatcher::checkPoolStatus(){ 
    328388  //Now check zpool status for bad/running statuses 
    329   QStringList zstat = LPBackend::getCmdOutput("zpool status"); 
     389  QStringList zstat = getCmdOutput("zpool status"); 
    330390    //parse the output 
    331391    QString pool, state, timestamp; 
     
    366426            LOGS.insert(65, timestamp.section(" ",3,3) ); 
    367427            if(timer->interval() != sysCheckTime){ timer->start(sysCheckTime); } 
     428          }else if(zstat[i].contains(" scrub cancel")){ 
     429            //Scrub was cancelled before finishing 
     430            zstat[i]  = zstat[i].replace("\t"," ").simplified(); 
     431            timestamp = zstat[i].section(" ",4,8,QString::SectionSkipEmpty); 
     432            LOGS.insert(60, "FINISHED"); 
     433            LOGS.insert(61, pool); 
     434            LOGS.insert(62, QString(tr("Scrub cancelled for %1")).arg(pool) ); 
     435            LOGS.insert(63, QString(tr("Scrub cancelled for %1")).arg(pool) ); 
     436            LOGS.insert(64, timestamp); 
     437            LOGS.insert(65,timestamp.section(" ",3,3) ); 
    368438          }else{ 
    369439            //Scrub is running - parse the line 
Note: See TracChangeset for help on using the changeset viewer.