diff --git a/MAC/APL/CEPCU/src/OfflineControl/CEPApplicationManager.h b/MAC/APL/CEPCU/src/OfflineControl/CEPApplicationManager.h index 0a0c45ab36e6d46de25b9b95ca98fdb0bca21ec2..24a0964917560da5410717d60430148b906ed4e4 100644 --- a/MAC/APL/CEPCU/src/OfflineControl/CEPApplicationManager.h +++ b/MAC/APL/CEPCU/src/OfflineControl/CEPApplicationManager.h @@ -137,12 +137,14 @@ inline CEPApplicationManager::CEPApplicationManager( _continuePoll(false), _lastOkCmd(ACC::ALC::ACCmdNone), _procName(appName) -{ +{ + LOG_DEBUG(formatString("constructing CEPApplicationManager(%s)",_procName.c_str())); use(); // to avoid that this object will be deleted in GCFTask::stop; } inline CEPApplicationManager::~CEPApplicationManager() { + LOG_DEBUG(formatString("destructing CEPApplicationManager(%s)",_procName.c_str())); GCFTask::deregisterHandler(*this); } diff --git a/MAC/APL/CEPCU/src/OfflineControl/OfflineControl.cc b/MAC/APL/CEPCU/src/OfflineControl/OfflineControl.cc index 1b02f12aaf288cebe91dc3ced85b84ee3c8eaaf0..e25903a9314aa6d9aef5a3c11b47db1bc1f55eee 100644 --- a/MAC/APL/CEPCU/src/OfflineControl/OfflineControl.cc +++ b/MAC/APL/CEPCU/src/OfflineControl/OfflineControl.cc @@ -67,6 +67,7 @@ OfflineControl::OfflineControl(const string& cntlrName) : itsCepAppParams (), itsResultParams (), itsProcessDependencies(), + itsCepAppStartTimes (), itsState (CTState::NOSTATE), itsTreePrefix (""), itsInstanceNr (0), @@ -427,7 +428,7 @@ GCFEvent::TResult OfflineControl::finished_state(GCFEvent& event, GCFPortInterfa // -// doPrepare(cntlrName) +// doClaim(cntlrName) // uint16_t OfflineControl::doClaim(const string& cntlrName) { @@ -544,12 +545,25 @@ void OfflineControl::prepareProcess(const string& cntlrName, const string& procN it->second.writeFile(paramFileName); // schedule all ACC commands + itsCepAppStartTimes[procName] = startTime; time_t initTime = startTime - it->second.getTime("AC.timeout_init"); time_t defineTime = initTime - it->second.getTime("AC.timeout_define") - it->second.getTime("AC.timeout_startup"); time_t bootTime = defineTime - it->second.getTime("AC.timeout_createsubsets"); time_t now = time(0); time_t stopTime = to_time_t(itsStopTime); + if(now >= stopTime) + { + // stoptime has already passed. Calculate a new stoptime based on the observation parameters + time_t startOffset = startTime - to_time_t(itsStartTime); + stopTime += startOffset; + // convert time_t to local time before constructing a ptime object from it + tm* ptm = localtime(&startTime); + itsStartTime = ptime_from_tm(*ptm); + ptm = localtime(&stopTime); + itsStopTime = ptime_from_tm(*ptm); + stopTime = to_time_t(itsStopTime); + } LOG_DEBUG(formatString("%d now %s time %d", now, ctime(&now), time(0))); LOG_DEBUG(formatString("%d boot %s", bootTime, ctime(&bootTime))); LOG_DEBUG(formatString("%d define %s", defineTime, ctime(&defineTime))); @@ -586,8 +600,12 @@ void OfflineControl::prepareProcess(const string& cntlrName, const string& procN default: assert(0); break; - } - } + } + } + else + { + LOG_WARN(formatString("Unable to find ACC process for %s.",procName.c_str())); + } APLCommon::APLUtilities::remoteCopy(paramFileName,hostName,LOFAR_SHARE_LOCATION); } } @@ -660,15 +678,29 @@ void OfflineControl::appBooted(const string& procName, uint16 result) LOG_INFO_STR("appBooted from " << procName); if (result == (AcCmdMaskOk | AcCmdMaskScheduled)) { - time_t startTime = to_time_t(itsStartTime); - time_t initTime = startTime - itsCepAppParams[0].getTime("AC.timeout_init"); - time_t defineTime = initTime - itsCepAppParams[0].getTime("AC.timeout_define") - - itsCepAppParams[0].getTime("AC.timeout_startup"); - map<string,CEPApplicationManagerPtr>::iterator it = itsCepApplications.find(procName); - if(it != itsCepApplications.end()) - { - it->second->define(defineTime); + map<string,CEPApplicationManagerPtr>::iterator itApp = itsCepApplications.find(procName); + map<string, ACC::APS::ParameterSet>::iterator itParam = itsCepAppParams.find(procName); + map<string,time_t>::iterator itStart = itsCepAppStartTimes.find(procName); + if(itApp != itsCepApplications.end() && itParam != itsCepAppParams.end() && itStart != itsCepAppStartTimes.end()) + { + time_t now = time(0); + time_t startTime = itStart->second; + time_t initTime = startTime - itParam->second.getTime("AC.timeout_init"); + time_t defineTime = initTime - itParam->second.getTime("AC.timeout_define") - + itParam->second.getTime("AC.timeout_startup"); + + LOG_DEBUG(formatString("%d now %s time %d", now, ctime(&now), time(0))); + LOG_DEBUG(formatString("%d define %s", defineTime, ctime(&defineTime))); + LOG_DEBUG(formatString("%d init %s", initTime, ctime(&initTime))); + LOG_DEBUG(formatString("%d start %s", startTime, ctime(&startTime))); + + itApp->second->define(defineTime); } + else + { + LOG_ERROR("Error in ACC. Stops CEP application and releases Offline Control."); + finishController(CT_RESULT_UNSPECIFIED); + } } else if (result == 0) // Error { @@ -682,18 +714,30 @@ void OfflineControl::appDefined(const string& procName, uint16 result) LOG_INFO_STR("appDefined from " << procName); if (result == (AcCmdMaskOk | AcCmdMaskScheduled)) { - time_t startTime = to_time_t(itsStartTime); - time_t initTime = startTime - itsCepAppParams[0].getTime("AC.timeout_init"); + map<string,CEPApplicationManagerPtr>::iterator itApp = itsCepApplications.find(procName); + map<string, ACC::APS::ParameterSet>::iterator itParam = itsCepAppParams.find(procName); + map<string,time_t>::iterator itStart = itsCepAppStartTimes.find(procName); + if(itApp != itsCepApplications.end() && itParam != itsCepAppParams.end() && itStart != itsCepAppStartTimes.end()) + { + time_t now = time(0); + time_t startTime = itStart->second; + time_t initTime = startTime - itParam->second.getTime("AC.timeout_init"); - map<string,CEPApplicationManagerPtr>::iterator it = itsCepApplications.find(procName); - if(it != itsCepApplications.end()) - { - it->second->init(initTime); + LOG_DEBUG(formatString("%d now %s time %d", now, ctime(&now), time(0))); + LOG_DEBUG(formatString("%d init %s", initTime, ctime(&initTime))); + LOG_DEBUG(formatString("%d start %s", startTime, ctime(&startTime))); + + itApp->second->init(initTime); } + else + { + LOG_ERROR("Error in ACC. Stops CEP application and releases Offline Control."); + finishController(CT_RESULT_UNSPECIFIED); + } } else if (result == 0) // Error { - LOG_ERROR("Error in ACC. Stops CEP application and releases VB."); + LOG_ERROR("Error in ACC. Stops CEP application and releases Offline Control."); finishController(CT_RESULT_UNSPECIFIED); } } @@ -707,15 +751,21 @@ void OfflineControl::appInitialized(const string& procName, uint16 result) } else if (result == (AcCmdMaskOk | AcCmdMaskScheduled)) { - map<string,CEPApplicationManagerPtr>::iterator it = itsCepApplications.find(procName); - if(it != itsCepApplications.end()) - { - it->second->run(to_time_t(itsStartTime)); + map<string,CEPApplicationManagerPtr>::iterator itApp = itsCepApplications.find(procName); + map<string,time_t>::iterator itStart = itsCepAppStartTimes.find(procName); + if(itApp != itsCepApplications.end() && itStart != itsCepAppStartTimes.end()) + { + itApp->second->run(itStart->second); } + else + { + LOG_ERROR("Error in ACC. Stops CEP application and releases Offline Control."); + finishController(CT_RESULT_UNSPECIFIED); + } } else if (result == 0) // Error { - LOG_ERROR("Error in ACC. Stops CEP application and releases VB."); + LOG_ERROR("Error in ACC. Stops CEP application and releases Offline Control."); finishController(CT_RESULT_UNSPECIFIED); } } @@ -725,36 +775,10 @@ void OfflineControl::appRunDone(const string& procName, uint16 result) LOG_INFO_STR("appRunDone from " << procName); if (result == (AcCmdMaskOk | AcCmdMaskScheduled)) { - map<string,CEPApplicationManagerPtr>::iterator it = itsCepApplications.find(procName); - if(it != itsCepApplications.end()) + map<string,CEPApplicationManagerPtr>::iterator itApp = itsCepApplications.find(procName); + if(itApp != itsCepApplications.end()) { - it->second->quit(to_time_t(itsStopTime)); - } - } - else if (result == AcCmdMaskOk) - { - // Run done. Check if processes depend on this process. - map<string, vector<string> >::iterator it; - for(it = itsProcessDependencies.begin(); it != itsProcessDependencies.end();++it) - { - if(it->second.size() > 0) - { - for(vector<string>::iterator dIt = it->second.begin(); dIt != it->second.end(); ++dIt) - { - if((*dIt) == procName) - { - // This process depends on the process that just finished - // Remove the process from the dependencies list. - it->second.erase(dIt); - // If the list is empty now, the new process can be started - if(it->second.size() == 0) - { - // start the process in 5 seconds - prepareProcess(itsCntlrName,it->first,time(0)+5); - } - } - } - } + itApp->second->quit(to_time_t(itsStopTime)); } } else if (result == 0) // Error @@ -776,9 +800,63 @@ void OfflineControl::appQuitDone(const string& procName, uint16 result) { //_qualityGuard.stopMonitoring(); // not in this increment } - else + else if (result == AcCmdMaskOk) { - finishController(CT_RESULT_NO_ERROR); + // process finished. Check if processes depend on this process. + map<string, vector<string> >::iterator itDep; + for(itDep = itsProcessDependencies.begin(); itDep != itsProcessDependencies.end();++itDep) + { + if(itDep->second.size() > 0) + { + vector<string>::iterator itDepProc = itDep->second.begin(); + bool found = false; + while(itDepProc != itDep->second.end() && !found) + { + LOG_DEBUG(formatString("appQuitDone: comparing %s with %s",itDepProc->c_str(),procName.c_str())); + if((*itDepProc) == procName) + { + found = true; + // This process depends on the process that just finished + // If the list only contains the finished process, the new process can be started + if(itDep->second.size() == 1) + { + map<string, ACC::APS::ParameterSet>::iterator itParam = itsCepAppParams.find(procName); + if(itParam != itsCepAppParams.end()) + { + // boot the process in 30 seconds + time_t bootTime = time(0) + 30; + time_t startTime = bootTime + itParam->second.getTime("AC.timeout_init") + + itParam->second.getTime("AC.timeout_define") + + itParam->second.getTime("AC.timeout_startup") + + itParam->second.getTime("AC.timeout_createsubsets"); + + prepareProcess(itsCntlrName,itDep->first,startTime); + } + } + } + else + { + ++itDepProc; + } + } + if(itDepProc != itDep->second.end() && found) + { + LOG_DEBUG(formatString("appQuitDone: removing dependency of %s",itDepProc->c_str())); + // Remove the process from the dependencies list. + itDep->second.erase(itDepProc); + } + } + } + // remove the process from the AC process list. If the list is empty, OfflineControl can be finished + itsCepApplications.erase(procName); + if(itsCepApplications.size() == 0) + { + finishController(CT_RESULT_NO_ERROR); + } + } + else if(result != 0) + { + finishController(CT_RESULT_UNSPECIFIED); } } @@ -802,15 +880,17 @@ void OfflineControl::appRecovered(const string& procName, uint16 /*result*/) { LOG_INFO_STR("appRecovered from " << procName); - time_t startTime = to_time_t(itsStartTime); - time_t reinitTime = startTime - itsCepAppParams[0].getTime("AC.timeout_reinit"); + map<string,CEPApplicationManagerPtr>::iterator itApp = itsCepApplications.find(procName); + map<string, ACC::APS::ParameterSet>::iterator itParam = itsCepAppParams.find(procName); + map<string,time_t>::iterator itStart = itsCepAppStartTimes.find(procName); + if(itApp != itsCepApplications.end() && itParam != itsCepAppParams.end() && itStart != itsCepAppStartTimes.end()) + { + time_t startTime = itStart->second; + time_t reinitTime = startTime - itParam->second.getTime("AC.timeout_reinit"); - string paramFileName(formatString("ACC-%s.param", getName().c_str())); + string paramFileName(formatString("ACC-%s.param", getName().c_str())); - map<string,CEPApplicationManagerPtr>::iterator it = itsCepApplications.find(procName); - if(it != itsCepApplications.end()) - { - it->second->reinit(reinitTime, paramFileName); + itApp->second->reinit(reinitTime, paramFileName); } } diff --git a/MAC/APL/CEPCU/src/OfflineControl/OfflineControl.h b/MAC/APL/CEPCU/src/OfflineControl/OfflineControl.h index 7c3a477b86f28a102852241f31b3770bc78e9ae9..c02f585623370648425cddaa763e9e4349120db1 100644 --- a/MAC/APL/CEPCU/src/OfflineControl/OfflineControl.h +++ b/MAC/APL/CEPCU/src/OfflineControl/OfflineControl.h @@ -134,15 +134,16 @@ private: map<string, CEPApplicationManagerPtr> itsCepApplications; map<string, ACC::APS::ParameterSet> itsCepAppParams; - ACC::APS::ParameterSet itsResultParams; + ACC::APS::ParameterSet itsResultParams; map<string, vector<string> > itsProcessDependencies; + map<string,time_t> itsCepAppStartTimes; CTState::CTstateNr itsState; // ParameterSet variables string itsTreePrefix; uint32 itsInstanceNr; - ptime itsStartTime; + ptime itsStartTime; ptime itsStopTime; uint32 itsClaimPeriod; uint32 itsPreparePeriod; diff --git a/MAC/APL/CEPCU/src/OfflineControl/OfflineControl.log_prop.in b/MAC/APL/CEPCU/src/OfflineControl/OfflineControl.log_prop.in index fc002f4164c120dd1c7d627eefd649598915e7ef..bd276a77804c605306a60087c42630bf33ffc546 100644 --- a/MAC/APL/CEPCU/src/OfflineControl/OfflineControl.log_prop.in +++ b/MAC/APL/CEPCU/src/OfflineControl/OfflineControl.log_prop.in @@ -1,10 +1,8 @@ # add your custom loggers and appenders here # -log4cplus.rootLogger=DEBUG, STDOUT, FILE - -log4cplus.logger.TRC=TRACE2 -log4cplus.additivity.TRC=FALSE +log4cplus.rootLogger=INFO, STDOUT, FILE +log4cplus.additivity.ASTRON=FALSE log4cplus.appender.STDOUT=log4cplus::ConsoleAppender log4cplus.appender.STDOUT.layout=log4cplus::PatternLayout @@ -18,3 +16,14 @@ log4cplus.appender.FILE.MaxBackupIndex=5 log4cplus.appender.FILE.layout=log4cplus::PatternLayout log4cplus.appender.FILE.layout.ConversionPattern=%D{%d-%m-%y %H:%M:%S.%q} %-5p %c{3} - %m [%.25l]%n +log4cplus.appender.DUMP=log4cplus::NullAppender + +log4cplus.logger.TRC=DUMP +log4cplus.additivity.TRC=FALSE + +log4cplus.additivity.MAC=FALSE +log4cplus.logger.MAC=DEBUG, STDOUT, FILE + +#log4cplus.additivity.TRC=FALSE +#log4cplus.logger.TRC=TRACE, FILE + diff --git a/MAC/APL/CEPCU/src/OfflineControl/OfflineControlMain.cc b/MAC/APL/CEPCU/src/OfflineControl/OfflineControlMain.cc index d8f1e2e3c1474885941400e6831733fdcf31e4a9..f827d1fedfbff9aef19b27e08e6fe62e95fb27cb 100644 --- a/MAC/APL/CEPCU/src/OfflineControl/OfflineControlMain.cc +++ b/MAC/APL/CEPCU/src/OfflineControl/OfflineControlMain.cc @@ -25,6 +25,7 @@ #include "OfflineControl.h" +using namespace LOFAR; using namespace LOFAR::GCF::TM; using namespace LOFAR::CEPCU; diff --git a/MAC/APL/CEPCU/src/OnlineControl/OnlineControl.cc b/MAC/APL/CEPCU/src/OnlineControl/OnlineControl.cc index a5c30db5e4adee850b9c42921807165d455a71f2..f105d497d5c3f5d7ada05a5b79a8fe3aa8944791 100644 --- a/MAC/APL/CEPCU/src/OnlineControl/OnlineControl.cc +++ b/MAC/APL/CEPCU/src/OnlineControl/OnlineControl.cc @@ -425,7 +425,7 @@ GCFEvent::TResult OnlineControl::finished_state(GCFEvent& event, GCFPortInterfac // -// doPrepare(cntlrName) +// doClaim(cntlrName) // uint16_t OnlineControl::doClaim(const string& cntlrName) {