Skip to content
Snippets Groups Projects
MACScheduler.cc 42.9 KiB
Newer Older
Ruud Overeem's avatar
Ruud Overeem committed

	// Finally we can pass the list with planned observations to PVSS.
	itsPropertySet->setValue(PN_MS_PLANNED_OBSERVATIONS, GCFPVDynArr(LPT_DYNSTRING, plannedArr));
	itsNrPlanned = plannedArr.size();

	// free used memory
	for (int i = plannedArr.size()-1; i>=0; --i) {
		delete plannedArr[i];
	}
Ruud Overeem's avatar
Ruud Overeem committed

	// the backupObsList now contains the observations that were are in the preparedObs list but are not in
	// the SAS list anymore. Remove them here from the preparedObs list.
	OLiter	oldObsIter = backupObsList.begin();
	OLiter	prepIter;
	while (oldObsIter != backupObsList.end()) {
		prepIter = itsPreparedObs.find(oldObsIter->first);
		if (prepIter != itsPreparedObs.end()) {
			LOG_INFO_STR("Removing " << oldObsIter->first << " from the 'preparing' list.");
Ruud Overeem's avatar
Ruud Overeem committed
}

Ruud Overeem's avatar
Ruud Overeem committed
//
Ruud Overeem's avatar
Ruud Overeem committed
//
Ruud Overeem's avatar
Ruud Overeem committed
{
Ruud Overeem's avatar
Ruud Overeem committed

	// get new list (list is ordered on starttime)
	vector<OTDBtree> activeDBlist = itsOTDBconnection->getTreeGroup(2, 0, itsExclPLcluster);
		// NOTE: do not exit routine on emptylist: we need to write an empty list to clear the DB
Ruud Overeem's avatar
Ruud Overeem committed
	}

	// walk through the list, prepare PVSS for the new obs, update own admin lists.
	for ( ; idx >= 0; idx--)  {
		if (activeDBlist[idx].processType=="RESERVATION" || activeDBlist[idx].processType=="MAINTENANCE") {
			continue;
		}

		// construct name and timings info for observation
		string		obsName(observationName(activeDBlist[idx].treeID()));
		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's avatar
Ruud Overeem 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			idx = activeSubTasks.size() - 1;
	for ( ; idx >= 0; idx--)  {
	    Json::Value subtask = activeSubTasks[idx];

//		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

	// Finally we can pass the list with active observations to PVSS.
	itsPropertySet->setValue(PN_MS_ACTIVE_OBSERVATIONS,	GCFPVDynArr(LPT_DYNSTRING, activeArr));
	itsNrActive = activeArr.size();

	// free used memory
	for (int i = activeArr.size()-1; i>=0; --i) {
		delete activeArr[i];
	}
Ruud Overeem's avatar
Ruud Overeem committed
}

//
Ruud Overeem's avatar
Ruud Overeem committed
//
Ruud Overeem's avatar
Ruud Overeem committed
{
Ruud Overeem's avatar
Ruud Overeem committed

	GCFPValueArray	finishedArr;
	int32	freeSpace = MAX_CONCURRENT_OBSERVATIONS - itsNrPlanned - itsNrActive;

	// get new list (list is ordered on starttime)
	vector<OTDBtree> finishedDBlist = itsOTDBconnection->getTreeGroup(3, itsFinishedPeriod, itsExclPLcluster);
		// NOTE: do not exit routine on emptylist: we need to write an empty list to clear the DB
Ruud Overeem's avatar
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);
	for ( ; idx >= limit ; idx--)  {
		if (finishedDBlist[idx].processType=="RESERVATION" || finishedDBlist[idx].processType=="MAINTENANCE") {
			continue;
		}

		// construct name and timings info for observation
		string		obsName(observationName(finishedDBlist[idx].treeID()));
		finishedArr.push_back(new GCFPVString(obsName));

	// 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];
	}
    //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	idx       = finishingSubTasks.size() - 1;
	int32	limit     = idx - (MIN2(MIN2(finishingSubTasks.size(), itsMaxFinished), (uint32)freeSpace) - 1);
	for ( ; idx >= limit ; idx--)  {
	    Json::Value subtask = finishingSubTasks[idx];

//		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.
	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];
	}
Ruud Overeem's avatar
Ruud Overeem committed
}

//
// _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);
Ruud Overeem's avatar
Ruud Overeem committed

//
// _connectedHandler(port)
//
blaakmeer's avatar
blaakmeer committed
void MACScheduler::_connectedHandler(GCFPortInterface& /*port*/)
Ruud Overeem's avatar
Ruud Overeem committed
{
}

//
// _disconnectedHandler(port)
//
void MACScheduler::_disconnectedHandler(GCFPortInterface& port)
{
	port.close();
}


};
};