diff --git a/MAC/APL/MainCU/src/MACScheduler/APLMACScheduler.dpl b/MAC/APL/MainCU/src/MACScheduler/APLMACScheduler.dpl index 763a416deb7f5ce262257c934522dbed15e29d7c..5564ad72f9df20fb886fc8a77edbe229075fdba6 100644 --- a/MAC/APL/MainCU/src/MACScheduler/APLMACScheduler.dpl +++ b/MAC/APL/MainCU/src/MACScheduler/APLMACScheduler.dpl @@ -2,8 +2,21 @@ # DpType TypeName -SwCntrl.MacScheduler 1#1 +LOFAR.LOFAR 1#1 + state 25#2 + +TypeName +PermSW.PermSW 1#1 + state 25#2 + +TypeName +MacScheduler.MacScheduler 1#1 state 25#2 error 25#3 + activeObservations 9#4 + OTDB 1#5 + connected 23#6 + lastPoll 25#7 + pollinterval 20#8 diff --git a/MAC/APL/MainCU/src/MACScheduler/ChildControl.cc b/MAC/APL/MainCU/src/MACScheduler/ChildControl.cc index 923f4e15ddbb79521ee71d186a4f7e3176fd3f44..a64a502e986cbaaecb500b103813da1228a0e161 100644 --- a/MAC/APL/MainCU/src/MACScheduler/ChildControl.cc +++ b/MAC/APL/MainCU/src/MACScheduler/ChildControl.cc @@ -149,7 +149,7 @@ bool ChildControl::startChild (const string& aName, ci.hostname = hostname; ci.requestedState = LDState::CONNECTED; ci.requestTime = time(0); - ci.currentState = LDState::UNKNOWN; + ci.currentState = LDState::NOSTATE; ci.establishTime = 0; ci.retryTime = 0; ci.nrRetries = 0; @@ -222,7 +222,7 @@ LDState::LDstateNr ChildControl::getCurrentState (const string& aName) { CIiter controller = findController(aName); if (controller == itsCntlrList.end()) { - return (LDState::UNKNOWN); + return (LDState::NOSTATE); } return (controller->currentState); @@ -237,7 +237,7 @@ LDState::LDstateNr ChildControl::getRequestedState (const string& aName) { CIiter controller = findController(aName); if (controller == itsCntlrList.end()) { - return (LDState::UNKNOWN); + return (LDState::NOSTATE); } return (controller->requestedState); @@ -437,7 +437,7 @@ void ChildControl::_processActionList() } break; - case LDState::RESUMED: + case LDState::ACTIVE: { LOGICALDEVICEResumeEvent request; controller->port->send(request); diff --git a/MAC/APL/MainCU/src/MACScheduler/LDState.cc b/MAC/APL/MainCU/src/MACScheduler/LDState.cc index 72830e57a4f81ac76c88338c63196a9f95c65d58..fdf0cbdd3c0ae3531d3fd07836ff2b059ae2b658 100644 --- a/MAC/APL/MainCU/src/MACScheduler/LDState.cc +++ b/MAC/APL/MainCU/src/MACScheduler/LDState.cc @@ -36,15 +36,14 @@ namespace LOFAR { LDState::LDState() { itsStates.resize(LAST_STATE); - itsStates[UNKNOWN] = "Unknown"; + itsStates[NOSTATE] = "Unknown"; itsStates[CONNECT] = "Connecting"; itsStates[CONNECTED] = "Connected"; itsStates[CLAIM] = "Claiming"; itsStates[CLAIMED] = "Claimed"; itsStates[PREPARE] = "Preparing"; itsStates[PREPARED] = "Prepared"; - itsStates[RESUME] = "Resuming"; - itsStates[RESUMED] = "Resumed"; + itsStates[ACTIVE] = "Active"; itsStates[SUSPEND] = "Suspending"; itsStates[SUSPENDED] = "Suspended"; itsStates[RELEASE] = "Releasing"; @@ -65,7 +64,7 @@ LDState::~LDState() // string LDState::name(uint16 aStateNr) { - return (((aStateNr >= UNKNOWN) && (aStateNr < LAST_STATE)) ? + return (((aStateNr >= NOSTATE) && (aStateNr < LAST_STATE)) ? itsStates[aStateNr] : ""); } @@ -74,7 +73,7 @@ string LDState::name(uint16 aStateNr) // uint16 LDState::value(const string& aStateName) { - uint16 i = UNKNOWN; + uint16 i = NOSTATE; while (i < LAST_STATE) { if (itsStates[i] == aStateName) { return (i); @@ -90,7 +89,7 @@ uint16 LDState::value(const string& aStateName) // uint16 LDState::value(LDstateNr aStateNr) { - ASSERTSTR((aStateNr >= UNKNOWN) && (aStateNr < LAST_STATE), + ASSERTSTR((aStateNr >= NOSTATE) && (aStateNr < LAST_STATE), aStateNr << " is not a valid LDState"); return ((uint16) aStateNr); diff --git a/MAC/APL/MainCU/src/MACScheduler/LDState.h b/MAC/APL/MainCU/src/MACScheduler/LDState.h index 3bed649785fa03aac562f6dedb10158e7197fdb6..0bba6a1eabebd8e6e1725ca272f68dd4e02e0360 100644 --- a/MAC/APL/MainCU/src/MACScheduler/LDState.h +++ b/MAC/APL/MainCU/src/MACScheduler/LDState.h @@ -49,15 +49,15 @@ public: // define enumeration for all states of an LogicalDevice. typedef enum { - UNKNOWN = 0, + ANYSTATE = -1, + NOSTATE = 0, CONNECT, CONNECTED, CLAIM, CLAIMED, PREPARE, PREPARED, - RESUME, - RESUMED, + ACTIVE, SUSPEND, SUSPENDED, RELEASE, diff --git a/MAC/APL/MainCU/src/MACScheduler/MACScheduler.cc b/MAC/APL/MainCU/src/MACScheduler/MACScheduler.cc index 01120ff9208c7c02f9008e5b6e6e25cce2a202ec..67321093b59e1899a83a46a5622960826ef8a168 100644 --- a/MAC/APL/MainCU/src/MACScheduler/MACScheduler.cc +++ b/MAC/APL/MainCU/src/MACScheduler/MACScheduler.cc @@ -25,11 +25,10 @@ #include <boost/shared_array.hpp> #include <APS/ParameterSet.h> #include <GCF/GCF_ServiceInfo.h> -#include <GCF/GCF_PVString.h> -#include <GCF/GCF_PVDouble.h> -#include <GCF/GCF_PVInteger.h> +#include <GCF/GCF_PVTypes.h> #include <GCF/PAL/GCF_PVSSInfo.h> #include <GCF/Utils.h> +#include <APL/APLCommon/APL_Defines.h> #include <APL/APLCommon/APLCommonExceptions.h> #include "MACSchedulerDefines.h" @@ -180,14 +179,18 @@ GCFEvent::TResult MACScheduler::initial_state(GCFEvent& event, GCFPortInterface& LOG_DEBUG ("Activating PropertySet"); itsPropertySet = GCFMyPropertySetPtr(new GCFMyPropertySet(MS_PROPSET_NAME, MS_PROPSET_TYPE, - PS_CAT_PERMANENT, + PS_CAT_PERM_AUTOLOAD, &itsPropertySetAnswer)); itsPropertySet->enable(); // update PVSS. LOG_TRACE_FLOW ("Updateing state to PVSS"); - itsPropertySet->setValue(string(PVSSNAME_FSM_STATE),GCFPVString("initial")); - itsPropertySet->setValue(string(PVSSNAME_FSM_ERROR),GCFPVString("")); + itsPropertySet->setValue(string(PVSSNAME_FSM_STATE),GCFPVString ("initial")); + itsPropertySet->setValue(string(PVSSNAME_FSM_ERROR),GCFPVString ("")); + itsPropertySet->setValue(string(MS_OTDB_CONNECTED), GCFPVBool (false)); + itsPropertySet->setValue(string(MS_OTDB_LASTPOLL), GCFPVString ("")); + itsPropertySet->setValue(string(MS_OTDB_POLL_ITV), GCFPVUnsigned(itsOTDBpollInterval)); + // Try to connect to the SAS database. ACC::APS::ParameterSet* pParamSet = ACC::APS::globalParameterSet(); @@ -202,6 +205,7 @@ GCFEvent::TResult MACScheduler::initial_state(GCFEvent& event, GCFPortInterface& "Unable to connect to database " << DBname << " using " << username << "," << password); LOG_INFO ("Connected to the OTDB"); + itsPropertySet->setValue(string(MS_OTDB_CONNECTED),GCFPVBool(true)); // Start ChildControl task LOG_DEBUG ("Enabling ChildControltask"); @@ -217,8 +221,6 @@ GCFEvent::TResult MACScheduler::initial_state(GCFEvent& event, GCFPortInterface& break; case F_DISCONNECTED: - itsPropertySet->setValue(string(PVSSNAME_FSM_ERROR), - GCFPVString("Waiting for StartDaemon")); break; case F_TIMER: @@ -379,7 +381,8 @@ void MACScheduler::_doOTDBcheck() ASSERTSTR (currentTime != not_a_date_time, "Can't determine systemtime, bailing out"); // REO: test pvss appl - itsPropertySet->setValue(string(PVSSNAME_FSM_STATE),GCFPVString(to_simple_string(currentTime))); + itsPropertySet->setValue(string(MS_OTDB_LASTPOLL), + GCFPVString(to_simple_string(currentTime))); while (idx < listSize) { // timediff = time to go before start of Observation @@ -398,11 +401,24 @@ void MACScheduler::_doOTDBcheck() // remember: timediff <= queueperiod if (timediff > seconds(itsClaimPeriod)) { // Observation is somewhere in the queueperiod - if (observationState != LDState::CONNECTED) { - itsChildControl->startChild(cntlrName, - newTreeList[idx].treeID(), + if (observationState != LDState::CONNECTED) { // requested a start before? + // no, let database construct the parset for the whole observation + OTDB::TreeMaintenance tm(itsOTDBconnection); + OTDB::treeIDType treeID = newTreeList[idx].treeID(); + OTDBnode topNode = tm.getTopNode(treeID); + string filename = formatString("%s/Observation_%d", + LOFAR_SHARE_LOCATION, treeID); + if (!tm.exportTree(treeID, topNode.nodeID(), filename)) { + LOG_ERROR_STR ("Cannot create startup file " << filename << + " for new observation. Observation CANNOT BE STARTED!"); + } + else { + // fire request for new controller + itsChildControl->startChild(cntlrName, + treeID, LDTYPE_OBSERVATIONCTRL, myHostname()); + } idx++; continue; } @@ -418,7 +434,7 @@ void MACScheduler::_doOTDBcheck() } // observation must be running (otherwise it would not be in the newTreeList) - if (observationState != LDState::RESUMED) { + if (observationState != LDState::ACTIVE) { // _executeObservation(&newTreeList[idx]); } diff --git a/MAC/APL/MainCU/src/MACScheduler/MACSchedulerDefines.h b/MAC/APL/MainCU/src/MACScheduler/MACSchedulerDefines.h index a88f2abbdb0dc71ea8072296fab6c210dc8cc635..fe9949ab65fa658c23d81d6c19c6a904c091a2b9 100644 --- a/MAC/APL/MainCU/src/MACScheduler/MACSchedulerDefines.h +++ b/MAC/APL/MainCU/src/MACScheduler/MACSchedulerDefines.h @@ -28,8 +28,11 @@ namespace LOFAR { #define MS_TASKNAME "MACScheduler" -#define MS_PROPSET_NAME "SwCntrl" +#define MS_PROPSET_NAME "LOFAR_PermSW_MacScheduler" #define MS_PROPSET_TYPE "MacScheduler" +#define MS_OTDB_CONNECTED "OTDB.connected" +#define MS_OTDB_LASTPOLL "OTDB.lastPoll" +#define MS_OTDB_POLL_ITV "OTDB.pollInterval" #define PVSSNAME_MS_QUEUEPERIOD "QueuePeriod" #define PVSSNAME_MS_CLAIMPERIOD "ClaimPeriod" diff --git a/MAC/APL/MainCU/src/MACScheduler/Makefile.am b/MAC/APL/MainCU/src/MACScheduler/Makefile.am index 68ec6941b0f59256f4344fcdfb16ad8f8db57a10..1d22e68a2bd4ce2dc45a09452a8128d0271314fc 100644 --- a/MAC/APL/MainCU/src/MACScheduler/Makefile.am +++ b/MAC/APL/MainCU/src/MACScheduler/Makefile.am @@ -8,7 +8,8 @@ MACScheduler_CPPFLAGS = -DBOOST_DISABLE_THREADS \ MACScheduler_SOURCES = MACScheduler.cc \ MACSchedulerMain.cc \ ChildControl.cc \ - LDState.cc + LDState.cc \ + Controller.cc MACScheduler_LDADD = -lpqxx $(LOFAR_DEPEND) MACScheduler_DEPENDENCIES = $(LOFAR_DEPEND)