Newer
Older
Arno Schoenmakers
committed
}
Ruud Overeem
committed
// _updateActiveList()
Ruud Overeem
committed
void MACScheduler::_updateActiveList()
Ruud Overeem
committed
LOG_DEBUG("_updateActiveList()");

Jorrit Schaap
committed
GCFPValueArray activeArr;

Jorrit Schaap
committed
#ifndef DONT_COMPILE_OTDB_AND_PVSS_CODE
Ruud Overeem
committed
// get new list (list is ordered on starttime)
Ruud Overeem
committed
vector<OTDBtree> activeDBlist = itsOTDBconnection->getTreeGroup(2, 0, itsExclPLcluster);
Ruud Overeem
committed
if (activeDBlist.empty()) {

Jorrit Schaap
committed
LOG_DEBUG ("No active OTDB Observations");
// NOTE: do not exit routine on emptylist: we need to write an empty list to clear the DB
Ruud Overeem
committed
// walk through the list, prepare PVSS for the new obs, update own admin lists.
Arno Schoenmakers
committed
int32 idx = activeDBlist.size() - 1;
Ruud Overeem
committed
for ( ; idx >= 0; idx--) {
if (activeDBlist[idx].processType=="RESERVATION" || activeDBlist[idx].processType=="MAINTENANCE") {
continue;
}
Ruud Overeem
committed
// construct name and timings info for observation
string obsName(observationName(activeDBlist[idx].treeID()));
Ruud Overeem
committed
activeArr.push_back(new GCFPVString(obsName));
// remove obs from planned-list if its still their.
OLiter prepIter = itsPreparedObs.find(activeDBlist[idx].treeID());
if (prepIter != itsPreparedObs.end()) {
itsPreparedObs.erase(prepIter);
}
Ruud Overeem
committed
} // for

Jorrit Schaap
committed
#endif

Jorrit Schaap
committed
// get new list (list is/should_be ordered on starttime)
Json::Value activeSubTasks = itsTMSSconnection->getActiveSubTasks();
if (activeSubTasks.empty()) {
LOG_DEBUG ("No active TMSS Observations");
// NOTE: do not exit routine on emptylist: we need to write an empty list to clear the DB
}
// walk through the list, prepare PVSS for the new obs, update own admin lists.
int32 idx2 = activeSubTasks.size() - 1;
for ( ; idx2 >= 0; idx2--) {
Json::Value subtask = activeSubTasks[idx2];

Jorrit Schaap
committed
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
// if (subtask.processType=="RESERVATION" || subtask.processType=="MAINTENANCE") {
// continue;
// }
// get subtask_id from url. I know, ugly, needs to be in json itself.
vector<string> tmp;
string url(subtask["url"].asString());
boost::split(tmp, url, [](char c){return c == '/';});
int subtask_id = stoi(tmp[tmp.size()-2]);
// construct name and timings info for observation
string obsName(observationName(subtask_id));
ptime start_time = time_from_string(subtask["start_time"].asString().replace(10, 1, " "));
ptime modTime = time_from_string(subtask["updated_at"].asString().replace(10, 1, " "));
activeArr.push_back(new GCFPVString(obsName));
// remove obs from planned-list if its still in there.
OLiter prepIter = itsPreparedObs.find(subtask_id);
if (prepIter != itsPreparedObs.end()) {
itsPreparedObs.erase(prepIter);
}
} // for

Jorrit Schaap
committed
#ifndef DONT_COMPILE_OTDB_AND_PVSS_CODE

Jorrit Schaap
committed
// Finally we can pass the list with active observations to PVSS.
Ruud Overeem
committed
itsPropertySet->setValue(PN_MS_ACTIVE_OBSERVATIONS, GCFPVDynArr(LPT_DYNSTRING, activeArr));

Jorrit Schaap
committed
#endif
itsNrActive = activeArr.size();
Arno Schoenmakers
committed
// free used memory
for (int i = activeArr.size()-1; i>=0; --i) {
delete activeArr[i];
}
Ruud Overeem
committed
// _updateFinishedList()
Ruud Overeem
committed
void MACScheduler::_updateFinishedList()
Ruud Overeem
committed
LOG_DEBUG("_updateFinishedList()");

Jorrit Schaap
committed
GCFPValueArray finishedArr;
int32 freeSpace = MAX_CONCURRENT_OBSERVATIONS - itsNrPlanned - itsNrActive;

Jorrit Schaap
committed
#ifndef DONT_COMPILE_OTDB_AND_PVSS_CODE
Ruud Overeem
committed
// get new list (list is ordered on starttime)
Ruud Overeem
committed
vector<OTDBtree> finishedDBlist = itsOTDBconnection->getTreeGroup(3, itsFinishedPeriod, itsExclPLcluster);
Ruud Overeem
committed
if (finishedDBlist.empty()) {

Jorrit Schaap
committed
LOG_DEBUG ("No finishing OTDB Observations");
// NOTE: do not exit routine on emptylist: we need to write an empty list to clear the DB
Ruud Overeem
committed
// walk through the list, prepare PVSS for the new obs, update own admin lists.
// We must show the last part of the (optional) limited list.
int32 idx = finishedDBlist.size() - 1;
int32 limit = idx - (MIN2(MIN2(finishedDBlist.size(), itsMaxFinished), (uint32)freeSpace) - 1);
Ruud Overeem
committed
for ( ; idx >= limit ; idx--) {
if (finishedDBlist[idx].processType=="RESERVATION" || finishedDBlist[idx].processType=="MAINTENANCE") {
continue;
}
Ruud Overeem
committed
// construct name and timings info for observation
string obsName(observationName(finishedDBlist[idx].treeID()));
Ruud Overeem
committed
finishedArr.push_back(new GCFPVString(obsName));
Ruud Overeem
committed
} // for

Jorrit Schaap
committed
// Finally we can pass the list with finished observations to PVSS.
itsPropertySet->setValue(PN_MS_FINISHED_OBSERVATIONS, GCFPVDynArr(LPT_DYNSTRING, finishedArr));
// free used memory
for (int i = finishedArr.size()-1; i>=0; --i) {
delete finishedArr[i];
}

Jorrit Schaap
committed
#endif
Ruud Overeem
committed

Jorrit Schaap
committed
//reset for TMSS
finishedArr = GCFPValueArray();
freeSpace = MAX_CONCURRENT_OBSERVATIONS - itsNrPlanned - itsNrActive;
// get new list (list is/should_be ordered on starttime)
Json::Value finishingSubTasks = itsTMSSconnection->getFinishingSubTasks();
if (finishingSubTasks.empty()) {
LOG_DEBUG ("No finishing TMSS Observations");
// NOTE: do not exit routine on emptylist: we need to write an empty list to clear the DB
}
// walk through the list, prepare PVSS for the new obs, update own admin lists.
// We must show the last part of the (optional) limited list.
int32 idx2 = finishingSubTasks.size() - 1;
int32 limit2 = idx2 - (MIN2(MIN2(finishingSubTasks.size(), itsMaxFinished), (uint32)freeSpace) - 1);
for ( ; idx2 >= limit2 ; idx2--) {
Json::Value subtask = finishingSubTasks[idx2];

Jorrit Schaap
committed
// if (subtask.processType=="RESERVATION" || subtask.processType=="MAINTENANCE") {
// continue;
// }
// get subtask_id from url. I know, ugly, needs to be in json itself.
vector<string> tmp;
string url(subtask["url"].asString());
boost::split(tmp, url, [](char c){return c == '/';});
int subtask_id = stoi(tmp[tmp.size()-2]);
// construct name info for observation
string obsName(observationName(subtask_id));
finishedArr.push_back(new GCFPVString(obsName));
} // for
// Finally we can pass the list with finished observations to PVSS.

Jorrit Schaap
committed
#ifndef DONT_COMPILE_OTDB_AND_PVSS_CODE
Arno Schoenmakers
committed
itsPropertySet->setValue(PN_MS_FINISHED_OBSERVATIONS, GCFPVDynArr(LPT_DYNSTRING, finishedArr));

Jorrit Schaap
committed
#endif
Arno Schoenmakers
committed
// free used memory
for (int i = finishedArr.size()-1; i>=0; --i) {
delete finishedArr[i];
}
//
// _setParsetOnMsgBus(parsetFile)
//
void MACScheduler::_setParsetOnMsgBus(const string& filename) const
{
// open file
ParameterSet obsSpecs(filename);
string obsPrefix = obsSpecs.fullModuleName("Observation");
string momID = obsSpecs.getString(obsPrefix + ".momID");
string sasID = obsSpecs.getString(obsPrefix + ".otdbID");
// from, forUser, summary, protocol, protocolVersion, momID, sasID
TaskSpecificationSystem outMsg("LOFAR.MACScheduler", "", "", momID, sasID, obsSpecs);

Jorrit Schaap
committed
#ifndef DONT_COMPILE_OTDB_AND_PVSS_CODE
itsMsgQueue->send(outMsg);

Jorrit Schaap
committed
#endif
}
void MACScheduler::_connectedHandler(GCFPortInterface& /*port*/)