1 #include "otsdaq-core/Supervisor/Supervisor.h"
2 #include "otsdaq-core/MessageFacility/MessageFacility.h"
3 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
4 #include "otsdaq-core/XmlUtilities/HttpXmlDocument.h"
5 #include "otsdaq-core/CgiDataUtilities/CgiDataUtilities.h"
6 #include "otsdaq-core/SOAPUtilities/SOAPUtilities.h"
7 #include "otsdaq-core/SOAPUtilities/SOAPCommand.h"
9 #include "otsdaq-core/WorkLoopManager/WorkLoopManager.h"
10 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
11 #include "otsdaq-core/ConfigurationInterface/ConfigurationManagerRW.h"
12 #include "otsdaq-core/ConfigurationPluginDataFormats/XDAQContextConfiguration.h"
13 #include <cgicc/HTMLClasses.h>
14 #include <cgicc/HTTPCookie.h>
15 #include <cgicc/HTMLDoctype.h>
16 #include <cgicc/HTTPHeader.h>
17 #include <xgi/Utils.h>
19 #include <xoap/Method.h>
20 #include <xdaq/NamespaceURI.h>
21 #include <toolbox/task/WorkLoopFactory.h>
22 #include <toolbox/fsm/FailedEvent.h>
32 #define ICON_FILE_NAME std::string(getenv("SERVICE_DATA_PATH")) + "/OtsWizardData/iconList.dat"
33 #define RUN_NUMBER_PATH std::string(getenv("SERVICE_DATA_PATH")) + "/RunNumber/"
34 #define RUN_NUMBER_FILE_NAME "NextRunNumber.txt"
35 #define FSM_LAST_GROUP_ALIAS_PATH std::string(getenv("SERVICE_DATA_PATH")) + "/RunControlData/"
36 #define FSM_LAST_GROUP_ALIAS_FILE_START std::string("FSMLastGroupAlias-")
37 #define FSM_USERS_PREFERENCES_FILETYPE "pref"
41 #define __MF_SUBJECT__ "OmniSuper"
49 :xdaq::Application (s)
55 ,stateMachineWorkLoopManager_(toolbox::task::bind(this, &Supervisor::stateMachineThread,"StateMachine"))
56 ,stateMachineSemaphore_ (toolbox::BSem::FULL)
57 ,infoRequestWorkLoopManager_ (toolbox::task::bind(this, &Supervisor::infoRequestThread, "InfoRequest"))
58 ,infoRequestSemaphore_ (toolbox::BSem::FULL)
59 , activeStateMachineName_ ("")
62 INIT_MF(
"Supervisor");
63 __MOUT__ << std::endl;
66 mkdir((FSM_LAST_GROUP_ALIAS_PATH).c_str(), 0755);
67 mkdir((RUN_NUMBER_PATH).c_str(), 0755);
69 securityType_ = theWebUsers_.getSecurity();
71 __MOUT__ <<
"Security: " << securityType_ << std::endl;
73 xgi::bind(
this, &Supervisor::Default,
"Default");
74 xgi::bind(
this, &Supervisor::loginRequest,
"LoginRequest");
75 xgi::bind(
this, &Supervisor::request,
"Request");
76 xgi::bind(
this, &Supervisor::stateMachineXgiHandler,
"StateMachineXgiHandler");
77 xgi::bind(
this, &Supervisor::infoRequestHandler,
"InfoRequestHandler");
78 xgi::bind(
this, &Supervisor::infoRequestResultHandler,
"InfoRequestResultHandler");
79 xgi::bind(
this, &Supervisor::tooltipRequest,
"TooltipRequest");
81 xoap::bind(
this, &Supervisor::supervisorCookieCheck,
"SupervisorCookieCheck", XDAQ_NS_URI);
82 xoap::bind(
this, &Supervisor::supervisorGetActiveUsers,
"SupervisorGetActiveUsers", XDAQ_NS_URI);
83 xoap::bind(
this, &Supervisor::supervisorSystemMessage,
"SupervisorSystemMessage", XDAQ_NS_URI);
84 xoap::bind(
this, &Supervisor::supervisorGetUserInfo,
"SupervisorGetUserInfo", XDAQ_NS_URI);
85 xoap::bind(
this, &Supervisor::supervisorSystemLogbookEntry,
"SupervisorSystemLogbookEntry", XDAQ_NS_URI);
86 xoap::bind(
this, &Supervisor::supervisorLastConfigGroupRequest,
"SupervisorLastConfigGroupRequest", XDAQ_NS_URI);
102 Supervisor::~Supervisor(
void)
104 delete theConfigurationManager_;
105 makeSystemLogbookEntry(
"ots halted.");
109 void Supervisor::init(
void)
112 theSupervisorDescriptorInfo_.init(getApplicationContext());
113 theSupervisorsInfo_.init(theSupervisorDescriptorInfo_);
115 supervisorGuiHasBeenLoaded_ =
false;
119 supervisorContextUID_ = contextConfiguration->getContextUID(
120 getApplicationContext()->getContextDescriptor()->getURL()
122 __MOUT__ <<
"Context UID:" << supervisorContextUID_ << std::endl;
124 supervisorApplicationUID_ = contextConfiguration->getApplicationUID(
125 getApplicationContext()->getContextDescriptor()->getURL(),
126 getApplicationDescriptor()->getLocalId()
129 __MOUT__ <<
"Application UID:" << supervisorApplicationUID_ << std::endl;
131 ConfigurationTree configLinkNode = theConfigurationManager_->getSupervisorConfigurationNode(
132 supervisorContextUID_, supervisorApplicationUID_);
137 std::string supervisorUID;
138 if(!configLinkNode.isDisconnected())
139 supervisorUID = configLinkNode.getValue();
141 supervisorUID = ViewColumnInfo::DATATYPE_LINK_DEFAULT;
143 __MOUT__ <<
"Supervisor UID:" << supervisorUID << std::endl;
147 void Supervisor::URLDisplayThread(Supervisor *supervisorPtr)
149 INIT_MF(
"Supervisor");
155 std::this_thread::sleep_for (std::chrono::seconds(2));
156 std:: cout << __COUT_HDR_FL__ <<
"\n*********************************************************************" << std::endl;
157 std:: cout << __COUT_HDR_FL__ <<
"\n\n"
158 << supervisorPtr->getApplicationContext()->getContextDescriptor()->getURL()
160 <<
"/urn:xdaq-application:lid="
161 << supervisorPtr->getApplicationDescriptor()->getLocalId() <<
"/"
162 <<
"\n" << std::endl;
163 std:: cout << __COUT_HDR_FL__ <<
"\n*********************************************************************" << std::endl;
172 void Supervisor::makeSystemLogbookEntry(std::string entryText)
174 __MOUT__ <<
"Making System Logbook Entry: " << entryText << std::endl;
177 if(!theSupervisorDescriptorInfo_.getLogbookDescriptor())
179 __MOUT__ <<
"Just kidding... Logbook Descriptor not found." << std:: endl;
185 std::string replace[] =
186 {
"\"",
"'",
"&",
"<",
">",
"\n",
" "};
188 {
"%22",
"%27",
"%26",
"%3C",
"%3E",
"%0A%0D",
"%20%20"};
193 for(
int i=0;i<numOfKeys;++i)
195 while((f=entryText.find(replace[i])) != std::string::npos)
197 entryText = entryText.substr(0,f) + with[i] + entryText.substr(f+replace[i].length());
208 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(theSupervisorDescriptorInfo_.getLogbookDescriptor(),
"MakeSystemLogbookEntry",parameters);
213 receive(retMsg, retParameters);
215 __MOUT__ <<
"Returned Status: " << retParameters.getValue(
"Status") << std::endl;
220 void Supervisor::Default(xgi::Input* in, xgi::Output* out)
221 throw (xgi::exception::Exception)
224 if (!supervisorGuiHasBeenLoaded_ && (supervisorGuiHasBeenLoaded_ =
true))
225 makeSystemLogbookEntry(
"ots started.");
228 "<!DOCTYPE HTML><html lang='en'><head><title>ots</title>" <<
231 "<link rel='apple-touch-icon' sizes='57x57' href='/WebPath/images/otsdaqIcons/apple-icon-57x57.png'>\
232 <link rel='apple-touch-icon' sizes='60x60' href='/WebPath/images/otsdaqIcons/apple-icon-60x60.png'>\
233 <link rel='apple-touch-icon' sizes='72x72' href='/WebPath/images/otsdaqIcons/apple-icon-72x72.png'>\
234 <link rel='apple-touch-icon' sizes='76x76' href='/WebPath/images/otsdaqIcons/apple-icon-76x76.png'>\
235 <link rel='apple-touch-icon' sizes='114x114' href='/WebPath/images/otsdaqIcons/apple-icon-114x114.png'>\
236 <link rel='apple-touch-icon' sizes='120x120' href='/WebPath/images/otsdaqIcons/apple-icon-120x120.png'>\
237 <link rel='apple-touch-icon' sizes='144x144' href='/WebPath/images/otsdaqIcons/apple-icon-144x144.png'>\
238 <link rel='apple-touch-icon' sizes='152x152' href='/WebPath/images/otsdaqIcons/apple-icon-152x152.png'>\
239 <link rel='apple-touch-icon' sizes='180x180' href='/WebPath/images/otsdaqIcons/apple-icon-180x180.png'>\
240 <link rel='icon' type='image/png' sizes='192x192' href='/WebPath/images/otsdaqIcons/android-icon-192x192.png'>\
241 <link rel='icon' type='image/png' sizes='32x32' href='/WebPath/images/otsdaqIcons/favicon-32x32.png'>\
242 <link rel='icon' type='image/png' sizes='96x96' href='/WebPath/images/otsdaqIcons/favicon-96x96.png'>\
243 <link rel='icon' type='image/png' sizes='16x16' href='/WebPath/images/otsdaqIcons/favicon-16x16.png'>\
244 <link rel='manifest' href='/WebPath/images/otsdaqIcons/manifest.json'>\
245 <meta name='msapplication-TileColor' content='#ffffff'>\
246 <meta name='msapplication-TileImage' content='/ms-icon-144x144.png'>\
247 <meta name='theme-color' content='#ffffff'>" <<
250 "<frameset col='100%' row='100%'>" <<
251 "<frame src='/WebPath/html/Supervisor.html?urn=" <<
252 this->getApplicationDescriptor()->getLocalId() <<
"=securityType=" <<
253 securityType_ <<
"'></frameset></html>";
259 void Supervisor::stateMachineXgiHandler(xgi::Input* in, xgi::Output* out)
260 throw (xgi::exception::Exception)
262 cgicc::Cgicc cgi(in);
264 uint8_t userPermissions;
266 std::string userWithLock;
267 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
268 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions,
269 &uid,
"0", 1, &userWithLock))
276 std::string username =
"";
277 username = theWebUsers_.getUsersUsername(uid);
278 if (userWithLock !=
"" && userWithLock != username)
280 *out << WebUsers::REQ_USER_LOCKOUT_RESPONSE;
281 __MOUT__ <<
"User " << username <<
" is locked out. " << userWithLock <<
" has lock." << std::endl;
287 std::string command = CgiDataUtilities::getData(cgi,
"StateMachine");
288 std::string fsmName = CgiDataUtilities::getData(cgi,
"fsmName");
289 std::string fsmWindowName = CgiDataUtilities::getData(cgi,
"fsmWindowName");
290 fsmWindowName = CgiDataUtilities::decodeURIComponent(fsmWindowName);
291 std::string currentState = theStateMachine_.getCurrentStateName();
293 __MOUT__ <<
"fsmName = " << fsmName << std::endl;
294 __MOUT__ <<
"fsmWindowName = " << fsmWindowName << std::endl;
295 __MOUT__ <<
"activeStateMachineName_ = " << activeStateMachineName_ << std::endl;
298 if (theStateMachine_.isInTransition())
300 __SS__ <<
"Error - Can not accept request since State Machine is already in transition!" << std::endl;
301 __MOUT_ERR__ <<
"\n" << ss.str();
303 xmldoc.addTextElementToData(
"state_tranisition_attempted",
"0");
304 xmldoc.addTextElementToData(
"state_tranisition_attempted_err",
306 xmldoc.outputXmlDocument((std::ostringstream*) out,
false,
true);
316 if(activeStateMachineName_ !=
"" &&
317 activeStateMachineName_ != fsmName)
319 __MOUT__ <<
"currentState = " <<
320 currentState << std::endl;
321 if(currentState !=
"Halted" &&
322 currentState !=
"Initial")
326 __SS__ <<
"Error - Can not accept request since State Machine " <<
327 "with window name '" <<
328 activeStateMachineWindowName_ <<
"' (UID: " <<
329 activeStateMachineName_ <<
") "
331 "in control of State Machine progress. ";
332 ss <<
"\n\nIn order for this State Machine with window name '" <<
333 fsmWindowName <<
"' (UID: " << fsmName <<
") "
334 "to control progress, please transition to Halted using the active " <<
335 "State Machine '" << activeStateMachineWindowName_ <<
".'" << std::endl;
336 __MOUT_ERR__ <<
"\n" << ss.str();
338 xmldoc.addTextElementToData(
"state_tranisition_attempted",
"0");
339 xmldoc.addTextElementToData(
"state_tranisition_attempted_err",
341 xmldoc.outputXmlDocument((std::ostringstream*) out,
false,
true);
346 activeStateMachineName_ =
"";
347 activeStateMachineWindowName_ =
"";
355 if (command ==
"Configure")
357 if(currentState !=
"Halted")
359 __SS__ <<
"Error - Can only transition to Configured if the current " <<
360 "state is Halted. Perhaps your state machine is out of sync." <<
362 __MOUT_ERR__ <<
"\n" << ss.str();
364 xmldoc.addTextElementToData(
"state_tranisition_attempted",
"0");
365 xmldoc.addTextElementToData(
"state_tranisition_attempted_err",
367 xmldoc.outputXmlDocument((std::ostringstream*) out,
false,
true);
373 parameters.addParameter(
"ConfigurationAlias",
374 CgiDataUtilities::postData(cgi,
"ConfigurationAlias"));
376 std::string configurationAlias = parameters.getValue(
"ConfigurationAlias");
377 __MOUT__ <<
"Configure --> Name: ConfigurationAlias Value: " <<
378 configurationAlias << std::endl;
381 std::string fn = FSM_LAST_GROUP_ALIAS_PATH + FSM_LAST_GROUP_ALIAS_FILE_START +
382 username +
"." + FSM_USERS_PREFERENCES_FILETYPE;
384 __MOUT__ <<
"Save FSM preferences: " << fn << std::endl;
385 FILE *fp = fopen(fn.c_str(),
"w");
387 throw std::runtime_error(
"Could not open file: " + fn);
388 fprintf(fp,
"FSM_last_configuration_alias %s",configurationAlias.c_str());
391 activeStateMachineName_ = fsmName;
392 activeStateMachineWindowName_ = fsmWindowName;
394 else if (command ==
"Start")
396 if(currentState !=
"Configured")
398 __SS__ <<
"Error - Can only transition to Configured if the current " <<
399 "state is Halted. Perhaps your state machine is out of sync. " <<
400 "(Likely the server was restarted or another user changed the state)" <<
402 __MOUT_ERR__ <<
"\n" << ss.str();
404 xmldoc.addTextElementToData(
"state_tranisition_attempted",
"0");
405 xmldoc.addTextElementToData(
"state_tranisition_attempted_err",
407 xmldoc.outputXmlDocument((std::ostringstream*) out,
false,
true);
411 unsigned int runNumber = getNextRunNumber();
412 parameters.addParameter(
"RunNumber", runNumber);
413 setNextRunNumber(++runNumber);
416 xoap::MessageReference message = SOAPUtilities::makeSOAPMessageReference(
417 command, parameters);
419 xoap::MessageReference reply = stateMachineXoapHandler(message);
423 xmldoc.addTextElementToData(
"state_tranisition_attempted",
"1");
424 xmldoc.outputXmlDocument((std::ostringstream*) out,
false);
425 __MOUT__ <<
"Done - Xgi Request!" << std::endl;
429 void Supervisor::stateMachineResultXgiHandler(xgi::Input* in, xgi::Output* out)
430 throw (xgi::exception::Exception)
432 cgicc::Cgicc cgi(in);
433 __MOUT__ <<
"Xgi Request!" << std::endl;
435 uint8_t userPermissions;
436 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
437 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode,
446 std::string command = CgiDataUtilities::getData(cgi,
"StateMachine");
467 xoap::MessageReference message = SOAPUtilities::makeSOAPMessageReference(
468 CgiDataUtilities::getData(cgi,
"StateMachine"), parameters);
470 xoap::MessageReference reply = stateMachineResultXoapHandler(message);
474 __MOUT__ <<
"Done - Xgi Request!" << std::endl;
478 xoap::MessageReference Supervisor::stateMachineXoapHandler(xoap::MessageReference message)
479 throw (xoap::exception::Exception)
481 __MOUT__ <<
"Soap Handler!" << std::endl;
482 stateMachineWorkLoopManager_.removeProcessedRequests();
483 stateMachineWorkLoopManager_.processRequest(message);
484 __MOUT__ <<
"Done - Soap Handler!" << std::endl;
489 xoap::MessageReference Supervisor::stateMachineResultXoapHandler(
490 xoap::MessageReference message)
491 throw (xoap::exception::Exception)
493 __MOUT__ <<
"Soap Handler!" << std::endl;
496 __MOUT__ <<
"Done - Soap Handler!" << std::endl;
501 bool Supervisor::stateMachineThread(toolbox::task::WorkLoop* workLoop)
503 stateMachineSemaphore_.take();
504 __MOUT__ <<
"Re-sending message..." << SOAPUtilities::translate( stateMachineWorkLoopManager_.getMessage(workLoop)).getCommand() << std::endl;
505 std::string reply = send(
506 theSupervisorDescriptorInfo_.getSupervisorDescriptor(),
507 stateMachineWorkLoopManager_.getMessage(workLoop));
508 stateMachineWorkLoopManager_.report(workLoop, reply, 100,
true);
510 __MOUT__ <<
"Done with message" << std::endl;
511 stateMachineSemaphore_.give();
521 void Supervisor::infoRequestHandler(xgi::Input* in, xgi::Output* out)
522 throw (xgi::exception::Exception)
524 __MOUT__ <<
"Starting to Request!" << std::endl;
525 cgicc::Cgicc cgi(in);
530 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
531 uint8_t userPermissions;
532 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions))
545 HttpXmlDocument tmpDoc = infoRequestWorkLoopManager_.processRequest(cgi);
547 xmldoc.copyDataChildren(tmpDoc);
549 xmldoc.outputXmlDocument((std::ostringstream*) out,
false);
553 void Supervisor::infoRequestResultHandler(xgi::Input* in, xgi::Output* out)
554 throw (xgi::exception::Exception)
556 __MOUT__ <<
"Starting ask!" << std::endl;
557 cgicc::Cgicc cgi(in);
562 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
563 uint8_t userPermissions;
564 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions))
573 infoRequestWorkLoopManager_.getRequestResult(cgi, xmldoc);
576 xmldoc.outputXmlDocument((std::ostringstream*) out,
false);
578 __MOUT__ <<
"Done asking!" << std::endl;
582 bool Supervisor::infoRequestThread(toolbox::task::WorkLoop* workLoop)
587 infoRequestSemaphore_.take();
591 for (
unsigned long long i = 0; i < 100000000; i++)
594 vectorTest_.push_back(counterTest_);
597 infoRequestWorkLoopManager_.report(workLoop,
598 "RESULT: This is the best result ever", 50,
false);
599 std::string workLoopName = workLoop->getName();
600 __MOUT__ << workLoopName <<
" test: " << counterTest_
601 <<
" vector size: " << vectorTest_.size() << std::endl;
602 wait(400,
"InfoRequestThread ----- locked");
603 infoRequestSemaphore_.give();
605 wait(200,
"InfoRequestThread");
607 infoRequestSemaphore_.take();
611 for (
unsigned long long i = 0; i < 100000000; i++)
614 vectorTest_.push_back(counterTest_);
617 wait(400,
"InfoRequestThread ----- locked");
618 __MOUT__ << workLoopName <<
" test: " << counterTest_ <<
" vector size: " << vectorTest_.size() << std::endl;
619 infoRequestSemaphore_.give();
622 infoRequestWorkLoopManager_.report(workLoop,
623 theStateMachine_.getCurrentStateName(), 100,
true);
630 void Supervisor::stateInitial(toolbox::fsm::FiniteStateMachine & fsm)
631 throw (toolbox::fsm::exception::Exception)
633 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
639 void Supervisor::statePaused(toolbox::fsm::FiniteStateMachine & fsm)
640 throw (toolbox::fsm::exception::Exception)
642 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
658 void Supervisor::stateRunning(toolbox::fsm::FiniteStateMachine & fsm)
659 throw (toolbox::fsm::exception::Exception)
662 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
678 void Supervisor::stateHalted(toolbox::fsm::FiniteStateMachine& fsm)
679 throw (toolbox::fsm::exception::Exception)
681 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
682 __MOUT__ <<
"Fsm is in transition?" << theStateMachine_.isInTransition() << std::endl;
708 void Supervisor::stateConfigured(toolbox::fsm::FiniteStateMachine & fsm)
709 throw (toolbox::fsm::exception::Exception)
777 void Supervisor::inError(toolbox::fsm::FiniteStateMachine & fsm)
778 throw (toolbox::fsm::exception::Exception)
780 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
785 void Supervisor::enteringError(toolbox::Event::Reference e)
786 throw (toolbox::fsm::exception::Exception)
788 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
791 toolbox::fsm::FailedEvent& failedEvent =
dynamic_cast<toolbox::fsm::FailedEvent&
> (*e);
792 __SS__ <<
"\nFailure performing transition from " << failedEvent.getFromState() <<
"-" <<
793 theStateMachine_.getStateName(failedEvent.getFromState()) <<
794 " to " << failedEvent.getToState() <<
"-" <<
795 theStateMachine_.getStateName(failedEvent.getToState()) <<
796 ".\n\nException:\n" << failedEvent.getException().what() << std::endl;
797 __MOUT_ERR__ <<
"\n" << ss.str();
799 theStateMachine_.setErrorMessage(ss.str());
812 void Supervisor::getSupervisorsStatus(
void)
813 throw (toolbox::fsm::exception::Exception)
815 theSupervisorsInfo_.getSupervisorInfo().setStatus(
816 theStateMachine_.getCurrentStateName());
820 SupervisorDescriptors::const_iterator it =
821 theSupervisorDescriptorInfo_.getFEDescriptors().begin();
822 for (; it != theSupervisorDescriptorInfo_.getFEDescriptors().end();
827 std::string state = send(it->second,
828 "StateMachineStateRequest");
830 theSupervisorsInfo_.getFESupervisorInfo(it->first).setStatus(
833 __MOUT__ <<
"PixelFESupervisor instance " << it->first <<
" is in FSM state " << state << std::endl;
834 __MOUT__ <<
"Look! Here's a FEW! @@@" << std::endl;
836 catch (xdaq::exception::Exception& e)
859 for (
auto& it : theSupervisorDescriptorInfo_.getARTDAQFEDataManagerDescriptors())
863 std::string state = send(it.second,
864 "StateMachineStateRequest");
865 theSupervisorsInfo_.getARTDAQFEDataManagerSupervisorInfo(it.first).setStatus(
867 __MOUT__ <<
"PixelFERSupervisor instance " << it.first <<
" is in FSM state " << state << std::endl;
868 __MOUT__ <<
"Look! Here's a FER! @@@" << std::endl;
870 catch (xdaq::exception::Exception& e)
875 for (
auto& it : theSupervisorDescriptorInfo_.getARTDAQDataManagerDescriptors())
879 std::string state = send(it.second,
880 "StateMachineStateRequest");
881 theSupervisorsInfo_.getARTDAQDataManagerSupervisorInfo(it.first).setStatus(
883 __MOUT__ <<
"PixelFERSupervisor instance " << it.first <<
" is in FSM state " << state << std::endl;
884 __MOUT__ <<
"Look! Here's a FER! @@@" << std::endl;
886 catch (xdaq::exception::Exception& e)
892 catch (xdaq::exception::Exception& e)
895 <<
"No PixelFESupervisor found in the \"daq\" group in the Configuration XML file."
903 void Supervisor::transitionConfiguring(toolbox::Event::Reference e)
904 throw (toolbox::fsm::exception::Exception)
908 theProgressBar_.step();
910 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
912 std::string systemAlias = SOAPUtilities::translate(
913 theStateMachine_.getCurrentMessage()).getParameters().getValue(
"ConfigurationAlias");
915 __MOUT__ <<
"Transition parameter: " << systemAlias << std::endl;
917 theProgressBar_.step();
922 theConfigurationManager_->init();
926 __SS__ <<
"\nTransition to Configuring interrupted! " <<
927 "The Configuration Manager could not be initialized." << std::endl;
929 __MOUT_ERR__ <<
"\n" << ss.str();
930 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
934 theProgressBar_.step();
939 theConfigurationGroup_ = theConfigurationManager_->getConfigurationGroupFromAlias(systemAlias);
943 __MOUT_INFO__ <<
"Exception occurred" << std::endl;
946 theProgressBar_.step();
948 if(theConfigurationGroup_.second.isInvalid())
950 __SS__ <<
"\nTransition to Configuring interrupted! System Alias " <<
951 systemAlias <<
" could not be translated to a group name and key." << std::endl;
953 __MOUT_ERR__ <<
"\n" << ss.str();
954 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
958 theProgressBar_.step();
960 __MOUT__ <<
"Configuration group name: " << theConfigurationGroup_.first <<
" key: " <<
961 theConfigurationGroup_.second << std::endl;
965 std::stringstream ss;
966 ss <<
"Configuring '" << systemAlias <<
"' which translates to " <<
967 theConfigurationGroup_.first <<
" (" << theConfigurationGroup_.second <<
").";
968 makeSystemLogbookEntry(ss.str());
971 theProgressBar_.step();
976 theConfigurationManager_->loadConfigurationGroup(theConfigurationGroup_.first, theConfigurationGroup_.second,
true);
980 tmpCfgMgr.activateConfigurationGroup(theConfigurationGroup_.first, theConfigurationGroup_.second);
984 __SS__ <<
"\nTransition to Configuring interrupted! System Alias " <<
985 systemAlias <<
" was translated to " << theConfigurationGroup_.first <<
986 " (" << theConfigurationGroup_.second <<
") but could not be loaded and initialized." << std::endl;
987 ss <<
"\n\nTo debug this problem, try activating this group in the Configuration GUI " <<
988 " and detailed errors will be shown." << std::endl;
989 __MOUT_ERR__ <<
"\n" << ss.str();
990 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
996 ConfigurationTree configLinkNode = theConfigurationManager_->getSupervisorConfigurationNode(
997 supervisorContextUID_, supervisorApplicationUID_);
998 if(!configLinkNode.isDisconnected())
1002 ConfigurationTree fsmLinkNode = configLinkNode.getNode(
"LinkToStateMachineConfiguration");
1003 if(!fsmLinkNode.isDisconnected() &&
1004 fsmLinkNode.getNode(activeStateMachineName_ +
1005 "/EnableConfigurationDumpOnConfigureTransition").getValue<
bool>())
1008 theConfigurationManager_->dumpActiveConfiguration(
1009 fsmLinkNode.getNode(activeStateMachineName_ +
1010 "/ConfigurationDumpOnConfigureFilePath").getValue<std::string>() +
1012 fsmLinkNode.getNode(activeStateMachineName_ +
1013 "/ConfigurationDumpOnConfigureFileRadix").getValue<std::string>() +
1015 std::to_string(time(0)) +
1017 fsmLinkNode.getNode(activeStateMachineName_ +
1018 "/ConfigurationDumpOnConfigureFormat").getValue<std::string>()
1022 __MOUT_INFO__ <<
"FSM Link disconnected." << std::endl;
1024 catch(std::runtime_error &e) {
1025 __SS__ <<
"\nTransition to Configuring interrupted! There was an error identified " <<
1026 "during the configuration dump attempt:\n\n " <<
1027 e.what() << std::endl;
1028 __MOUT_ERR__ <<
"\n" << ss.str();
1029 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
1033 __SS__ <<
"\nTransition to Configuring interrupted! There was an error identified " <<
1034 "during the configuration dump attempt.\n\n " <<
1036 __MOUT_ERR__ <<
"\n" << ss.str();
1037 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
1044 theProgressBar_.step();
1046 parameters.addParameter(
"ConfigurationGroupName", theConfigurationGroup_.first);
1047 parameters.addParameter(
"ConfigurationGroupKey", theConfigurationGroup_.second.toString());
1050 xoap::MessageReference message = theStateMachine_.getCurrentMessage();
1051 SOAPUtilities::addParameters(message,parameters);
1052 broadcastMessage(message);
1053 theProgressBar_.step();
1058 saveGroupNameAndKey(theConfigurationGroup_,FSM_LAST_CONFIGURED_GROUP_ALIAS_FILE);
1060 __MOUT__ <<
"Done" << std::endl;
1061 theProgressBar_.complete();
1065 void Supervisor::transitionHalting(toolbox::Event::Reference e)
1066 throw (toolbox::fsm::exception::Exception)
1068 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
1070 makeSystemLogbookEntry(
"Run halting.");
1072 broadcastMessage(theStateMachine_.getCurrentMessage());
1076 void Supervisor::transitionInitializing(toolbox::Event::Reference e)
1077 throw (toolbox::fsm::exception::Exception)
1079 __MOUT__ << theStateMachine_.getCurrentStateName() << std::endl;
1082 getSupervisorsStatus();
1084 if(!broadcastMessage(theStateMachine_.getCurrentMessage()))
1086 __MOUT__ <<
"I can't Initialize the supervisors!" << std::endl;
1089 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
1090 __MOUT__ <<
"Fsm current transition: " << theStateMachine_.getCurrentTransitionName(e->type()) << std::endl;
1091 __MOUT__ <<
"Fsm final state: " << theStateMachine_.getTransitionFinalStateName(e->type()) << std::endl;
1095 void Supervisor::transitionPausing(toolbox::Event::Reference e)
1096 throw (toolbox::fsm::exception::Exception)
1098 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
1100 makeSystemLogbookEntry(
"Run pausing.");
1102 broadcastMessage(theStateMachine_.getCurrentMessage());
1106 void Supervisor::transitionResuming(toolbox::Event::Reference e)
1107 throw (toolbox::fsm::exception::Exception)
1109 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
1111 makeSystemLogbookEntry(
"Run resuming.");
1113 broadcastMessage(theStateMachine_.getCurrentMessage());
1117 void Supervisor::transitionStarting(toolbox::Event::Reference e)
1118 throw (toolbox::fsm::exception::Exception)
1120 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
1123 receive(theStateMachine_.getCurrentMessage(), parameters);
1125 std::string runNumber = parameters.getValue(
"RunNumber");
1126 __MOUT__ << runNumber << std::endl;
1130 ConfigurationTree configLinkNode = theConfigurationManager_->getSupervisorConfigurationNode(
1131 supervisorContextUID_, supervisorApplicationUID_);
1132 if(!configLinkNode.isDisconnected())
1136 ConfigurationTree fsmLinkNode = configLinkNode.getNode(
"LinkToStateMachineConfiguration");
1137 if(!fsmLinkNode.isDisconnected() &&
1138 fsmLinkNode.getNode(activeStateMachineName_ +
1139 "/EnableConfigurationDumpOnRunTransition").getValue<
bool>())
1142 theConfigurationManager_->dumpActiveConfiguration(
1143 fsmLinkNode.getNode(activeStateMachineName_ +
1144 "/ConfigurationDumpOnRunFilePath").getValue<std::string>() +
1146 fsmLinkNode.getNode(activeStateMachineName_ +
1147 "/ConfigurationDumpOnRunFileRadix").getValue<std::string>() +
1151 std::to_string(time(0)) +
1153 fsmLinkNode.getNode(activeStateMachineName_ +
1154 "/ConfigurationDumpOnRunFormat").getValue<std::string>()
1158 __MOUT_INFO__ <<
"FSM Link disconnected." << std::endl;
1160 catch(std::runtime_error &e) {
1161 __SS__ <<
"\nTransition to Configuring interrupted! There was an error identified " <<
1162 "during the configuration dump attempt:\n\n " <<
1163 e.what() << std::endl;
1164 __MOUT_ERR__ <<
"\n" << ss.str();
1165 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
1169 __SS__ <<
"\nTransition to Configuring interrupted! There was an error identified " <<
1170 "during the configuration dump attempt.\n\n " <<
1172 __MOUT_ERR__ <<
"\n" << ss.str();
1173 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
1181 makeSystemLogbookEntry(
"Run " + runNumber +
" starting.");
1183 broadcastMessage(theStateMachine_.getCurrentMessage());
1186 saveGroupNameAndKey(theConfigurationGroup_,FSM_LAST_STARTED_GROUP_ALIAS_FILE);
1190 void Supervisor::transitionStopping(toolbox::Event::Reference e)
1191 throw (toolbox::fsm::exception::Exception)
1193 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
1195 makeSystemLogbookEntry(
"Run stopping.");
1197 broadcastMessage(theStateMachine_.getCurrentMessage());
1205 bool Supervisor::broadcastMessage(xoap::MessageReference message)
1206 throw (toolbox::fsm::exception::Exception)
1208 std::string command = SOAPUtilities::translate(message).getCommand();
1209 bool proceed =
true;
1214 for(
auto& it: theSupervisorDescriptorInfo_.getFEDescriptors())
1216 RunControlStateMachine::theProgressBar_.step();
1217 __MOUT__ <<
"Sending message to FESupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1218 __MOUT__ <<
"Sending message to FESupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1219 __MOUT__ <<
"Sending message to FESupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1220 __MOUT__ <<
"Sending message to FESupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1221 __MOUT__ <<
"Sending message to FESupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1225 reply = send(it.second, message);
1227 catch(
const xdaq::exception::Exception &e)
1230 __SS__ <<
"Can NOT " << command <<
" FESupervisors, instance = " << it.first <<
".\n\n" <<
1231 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
1232 __MOUT_ERR__ << ss.str();
1233 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1237 if (reply != command +
"Done")
1241 __SS__ <<
"Can NOT " << command <<
" FESupervisor, instance = " << it.first <<
".\n\n" <<
1243 __MOUT_ERR__ << ss.str() << std::endl;
1245 __MOUT__ <<
"Getting error message..." << std::endl;
1246 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference(
"StateMachineErrorMessageRequest"));
1248 parameters.addParameter(
"ErrorMessage");
1249 SOAPMessenger::receive(errorMessage, parameters);
1250 __MOUT_ERR__ <<
"errorMessage = " << parameters.getValue(
"ErrorMessage") << std::endl;
1251 ss <<
"\n\nError Message: " << parameters.getValue(
"ErrorMessage") << std::endl;
1252 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1258 __MOUT__ <<
"FESupervisor supervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1263 for(
auto& it: theSupervisorDescriptorInfo_.getDataManagerDescriptors())
1265 RunControlStateMachine::theProgressBar_.step();
1266 __MOUT__ <<
"Sending message to DataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1267 __MOUT__ <<
"Sending message to DataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1268 __MOUT__ <<
"Sending message to DataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1269 __MOUT__ <<
"Sending message to DataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1270 __MOUT__ <<
"Sending message to DataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1274 reply = send(it.second, message);
1276 catch(
const xdaq::exception::Exception &e)
1279 __SS__ <<
"Can NOT " << command <<
" DataManagerSupervisors, instance = " << it.first <<
".\n\n" <<
1280 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
1281 __MOUT_ERR__ << ss.str();
1282 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1286 if (reply != command +
"Done")
1288 __SS__ <<
"Can NOT " << command <<
" DataManagerSupervisor, instance = " << it.first <<
".\n\n" <<
1290 __MOUT_ERR__ << ss.str() << std::endl;
1291 __MOUT__ <<
"Getting error message..." << std::endl;
1292 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference(
"StateMachineErrorMessageRequest"));
1294 parameters.addParameter(
"ErrorMessage");
1295 SOAPMessenger::receive(errorMessage, parameters);
1296 __MOUT_ERR__ <<
"errorMessage = " << parameters.getValue(
"ErrorMessage") << std::endl;
1297 ss <<
"\n\nError Message: " << parameters.getValue(
"ErrorMessage") << std::endl;
1298 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1303 __MOUT__ <<
"DataManagerSupervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1308 for (
auto& it: theSupervisorDescriptorInfo_.getFEDataManagerDescriptors())
1310 RunControlStateMachine::theProgressBar_.step();
1311 __MOUT__ <<
"Sending message to FEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1312 __MOUT__ <<
"Sending message to FEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1313 __MOUT__ <<
"Sending message to FEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1314 __MOUT__ <<
"Sending message to FEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1315 __MOUT__ <<
"Sending message to FEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1319 reply = send(it.second, message);
1321 catch(
const xdaq::exception::Exception &e)
1324 __SS__ <<
"Can NOT " << command <<
" FEDataManagerSupervisors, instance = " << it.first <<
".\n\n" <<
1325 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
1326 __MOUT_ERR__ << ss.str();
1327 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1331 if (reply != command +
"Done")
1333 __SS__ <<
"Can NOT " << command <<
" FEDataManagerSupervisor, instance = " << it.first <<
".\n\n" <<
1335 __MOUT_ERR__ << ss.str() << std::endl;
1336 __MOUT__ <<
"Getting error message..." << std::endl;
1337 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference(
"StateMachineErrorMessageRequest"));
1339 parameters.addParameter(
"ErrorMessage");
1340 SOAPMessenger::receive(errorMessage, parameters);
1341 __MOUT_ERR__ <<
"errorMessage = " << parameters.getValue(
"ErrorMessage") << std::endl;
1342 ss <<
"\n\nError Message: " << parameters.getValue(
"ErrorMessage") << std::endl;
1343 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1348 __MOUT__ <<
"FEDataManagerSupervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1353 for(
auto& it: theSupervisorDescriptorInfo_.getVisualDescriptors())
1355 RunControlStateMachine::theProgressBar_.step();
1356 __MOUT__ <<
"Sending message to VisualSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1357 __MOUT__ <<
"Sending message to VisualSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1358 __MOUT__ <<
"Sending message to VisualSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1359 __MOUT__ <<
"Sending message to VisualSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1360 __MOUT__ <<
"Sending message to VisualSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1365 reply = send(it.second, message);
1367 catch(
const xdaq::exception::Exception &e)
1370 __SS__ <<
"Can NOT " << command <<
" VisualSupervisor, instance = " << it.first <<
".\n\n" <<
1371 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
1372 __MOUT_ERR__ << ss.str();
1373 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1378 if (reply != command +
"Done")
1380 __SS__ <<
"Can NOT " << command <<
" VisualSupervisor, instance = " << it.first <<
".\n\n" <<
1382 __MOUT_ERR__ << ss.str() << std::endl;
1383 __MOUT__ <<
"Getting error message..." << std::endl;
1384 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference(
"StateMachineErrorMessageRequest"));
1386 parameters.addParameter(
"ErrorMessage");
1387 SOAPMessenger::receive(errorMessage, parameters);
1388 __MOUT_ERR__ <<
"errorMessage = " << parameters.getValue(
"ErrorMessage") << std::endl;
1389 ss <<
"\n\nError Message: " << parameters.getValue(
"ErrorMessage") << std::endl;
1390 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1395 __MOUT__ <<
"VisualSupervisor supervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1403 bool artdaqRestarted =
false;
1404 bool artdaqWasRestarted =
false;
1406 RunControlStateMachine::theProgressBar_.step();
1407 if(command ==
"Halt" || command ==
"Initialize")
1414 FILE *fp = fopen((std::string(getenv(
"SERVICE_DATA_PATH")) +
1415 "/StartOTS_action.cmd").c_str(),
"w");
1418 fprintf(fp,
"RESET_MPI");
1423 artdaqRestarted =
true;
1426 message = SOAPUtilities::makeSOAPMessageReference(
1427 "Initialize", parameters);
1428 command = SOAPUtilities::translate(message).getCommand();
1429 __MOUT__ <<
"command now is " << command << std::endl;
1431 RunControlStateMachine::theProgressBar_.step();
1434 int MAX_ARTDAQ_RESTARTS = 10;
1435 int ARTDAQ_RESTART_DELAY = 2;
1436 int artdaqRestartCount = 0;
1437 bool preArtdaqProceed = proceed;
1440 if(artdaqWasRestarted)
1442 ++artdaqRestartCount;
1443 proceed = preArtdaqProceed;
1444 if(artdaqRestartCount < MAX_ARTDAQ_RESTARTS)
1445 artdaqWasRestarted =
false;
1446 for(
int i=0;i<ARTDAQ_RESTART_DELAY;++i)
1449 __MOUT_INFO__ <<
"Waiting on artdaq reboot... " << i <<
" for " << artdaqRestartCount <<
"x" << std::endl;
1454 for(
auto& it: theSupervisorDescriptorInfo_.getARTDAQFEDataManagerDescriptors())
1456 RunControlStateMachine::theProgressBar_.step();
1457 __MOUT__ <<
"Sending message to ARTDAQFEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1458 __MOUT__ <<
"Sending message to ARTDAQFEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1459 __MOUT__ <<
"Sending message to ARTDAQFEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1460 __MOUT__ <<
"Sending message to ARTDAQFEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1461 __MOUT__ <<
"Sending message to ARTDAQFEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1465 reply = send(it.second, message);
1466 if (reply != command +
"Done")
1468 __SS__ <<
"Can NOT " << command <<
" ARTDAQFEDataManagerSupervisor, instance = " << it.first <<
".\n\n" <<
1470 __MOUT_ERR__ << ss.str() << std::endl;
1471 __MOUT__ <<
"Getting error message..." << std::endl;
1472 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference(
"StateMachineErrorMessageRequest"));
1474 parameters.addParameter(
"ErrorMessage");
1475 SOAPMessenger::receive(errorMessage, parameters);
1476 __MOUT_ERR__ <<
"errorMessage = " << parameters.getValue(
"ErrorMessage") << std::endl;
1477 ss <<
"\n\nError Message: " << parameters.getValue(
"ErrorMessage") << std::endl;
1478 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1483 __MOUT__ <<
"ARTDAQFEDataManagerSupervisors supervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1486 catch(
const xdaq::exception::Exception &e)
1488 if(artdaqRestarted && !artdaqWasRestarted)
1490 artdaqWasRestarted =
true;
1496 __SS__ <<
"Can NOT " << command <<
" ARTDAQFEDataManagerSupervisor, instance = " << it.first <<
".\n\n" <<
1497 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
1498 __MOUT_ERR__ << ss.str();
1499 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1503 catch(
const toolbox::fsm::exception::Exception &e)
1505 if(artdaqRestarted && !artdaqWasRestarted)
1507 artdaqWasRestarted =
true;
1523 for(
auto& it: theSupervisorDescriptorInfo_.getARTDAQDataManagerDescriptors())
1525 RunControlStateMachine::theProgressBar_.step();
1526 __MOUT__ <<
"Sending message to ARTDAQDataManagerSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1527 __MOUT__ <<
"Sending message to ARTDAQDataManagerSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1528 __MOUT__ <<
"Sending message to ARTDAQDataManagerSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1529 __MOUT__ <<
"Sending message to ARTDAQDataManagerSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1530 __MOUT__ <<
"Sending message to ARTDAQDataManagerSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1533 reply = send(it.second, message);
1534 if (reply != command +
"Done")
1536 __SS__ <<
"Can NOT " << command <<
" ARTDAQDataManagerSupervisor, instance = " << it.first <<
".\n\n" <<
1538 __MOUT_ERR__ << ss.str() << std::endl;
1539 __MOUT__ <<
"Getting error message..." << std::endl;
1540 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference(
"StateMachineErrorMessageRequest"));
1542 parameters.addParameter(
"ErrorMessage");
1543 SOAPMessenger::receive(errorMessage, parameters);
1544 __MOUT_ERR__ <<
"errorMessage = " << parameters.getValue(
"ErrorMessage") << std::endl;
1545 ss <<
"\n\nError Message: " << parameters.getValue(
"ErrorMessage") << std::endl;
1546 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1551 __MOUT__ <<
"ARTDAQDataManagerSupervisor supervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1554 catch(
const xdaq::exception::Exception &e)
1556 if(artdaqRestarted && !artdaqWasRestarted)
1558 artdaqWasRestarted =
true;
1564 __SS__ <<
"Can NOT " << command <<
" ARTDAQDataManagerSupervisor, instance = " << it.first <<
".\n\n" <<
1565 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
1566 __MOUT_ERR__ << ss.str();
1567 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1571 catch(
const toolbox::fsm::exception::Exception &e)
1573 if(artdaqRestarted && !artdaqWasRestarted)
1575 artdaqWasRestarted =
true;
1584 for(
auto& it: theSupervisorDescriptorInfo_.getARTDAQBuilderDescriptors())
1586 RunControlStateMachine::theProgressBar_.step();
1587 __MOUT__ <<
"Sending message to ARTDAQBuilderSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1588 __MOUT__ <<
"Sending message to ARTDAQBuilderSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1589 __MOUT__ <<
"Sending message to ARTDAQBuilderSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1590 __MOUT__ <<
"Sending message to ARTDAQBuilderSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1591 __MOUT__ <<
"Sending message to ARTDAQBuilderSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1595 reply = send(it.second, message);
1596 if (reply != command +
"Done")
1598 __SS__ <<
"Can NOT " << command <<
" ARTDAQBuilderSupervisor, instance = " << it.first <<
".\n\n" <<
1600 __MOUT_ERR__ << ss.str() << std::endl;
1601 __MOUT__ <<
"Getting error message..." << std::endl;
1602 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference(
"StateMachineErrorMessageRequest"));
1604 parameters.addParameter(
"ErrorMessage");
1605 SOAPMessenger::receive(errorMessage, parameters);
1606 __MOUT_ERR__ <<
"errorMessage = " << parameters.getValue(
"ErrorMessage") << std::endl;
1607 ss <<
"\n\nError Message: " << parameters.getValue(
"ErrorMessage") << std::endl;
1608 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1613 __MOUT__ <<
"ARTDAQBuilderSupervisor supervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1616 catch(
const xdaq::exception::Exception &e)
1618 if(artdaqRestarted && !artdaqWasRestarted)
1620 artdaqWasRestarted =
true;
1626 __SS__ <<
"Can NOT " << command <<
" ARTDAQBuilderSupervisor, instance = " << it.first <<
".\n\n" <<
1627 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
1628 __MOUT_ERR__ << ss.str();
1629 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1633 catch(
const toolbox::fsm::exception::Exception &e)
1635 if(artdaqRestarted && !artdaqWasRestarted)
1637 artdaqWasRestarted =
true;
1646 for(
auto& it: theSupervisorDescriptorInfo_.getARTDAQAggregatorDescriptors())
1648 RunControlStateMachine::theProgressBar_.step();
1649 __MOUT__ <<
"Sending message to ARTDAQAggregatorSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1650 __MOUT__ <<
"Sending message to ARTDAQAggregatorSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1651 __MOUT__ <<
"Sending message to ARTDAQAggregatorSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1652 __MOUT__ <<
"Sending message to ARTDAQAggregatorSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1653 __MOUT__ <<
"Sending message to ARTDAQAggregatorSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1657 reply = send(it.second, message);
1658 if (reply != command +
"Done")
1660 __SS__ <<
"Can NOT " << command <<
" ARTDAQAggregatorSupervisor, instance = " << it.first <<
".\n\n" <<
1662 __MOUT_ERR__ << ss.str() << std::endl;
1663 __MOUT__ <<
"Getting error message..." << std::endl;
1664 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference(
"StateMachineErrorMessageRequest"));
1666 parameters.addParameter(
"ErrorMessage");
1667 SOAPMessenger::receive(errorMessage, parameters);
1668 __MOUT_ERR__ <<
"errorMessage = " << parameters.getValue(
"ErrorMessage") << std::endl;
1669 ss <<
"\n\nError Message: " << parameters.getValue(
"ErrorMessage") << std::endl;
1670 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1675 __MOUT__ <<
"ARTDAQAggregatorSupervisor supervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1678 catch(
const xdaq::exception::Exception &e)
1680 if(artdaqRestarted && !artdaqWasRestarted)
1682 artdaqWasRestarted =
true;
1688 __SS__ <<
"Can NOT " << command <<
" ARTDAQAggregatorSupervisor, instance = " << it.first <<
".\n\n" <<
1689 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
1690 __MOUT_ERR__ << ss.str();
1691 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1695 catch(
const toolbox::fsm::exception::Exception &e)
1697 if(artdaqRestarted && !artdaqWasRestarted)
1699 artdaqWasRestarted =
true;
1711 void Supervisor::wait(
int milliseconds, std::string who)
const
1713 for (
int s = 1; s <= milliseconds; s++)
1718 __MOUT__ << s <<
" msecs " << who << std::endl;
1727 void Supervisor::loginRequest(xgi::Input * in, xgi::Output * out)
1728 throw (xgi::exception::Exception)
1730 cgicc::Cgicc cgi(in);
1731 std::string Command = CgiDataUtilities::getData(cgi,
"RequestType");
1733 __MOUT__ << Command << std::endl;
1742 std::vector<std::string> loggedOutUsernames;
1743 theWebUsers_.cleanupExpiredEntries(&loggedOutUsernames);
1744 for (
unsigned int i = 0; i < loggedOutUsernames.size(); ++i)
1745 makeSystemLogbookEntry(loggedOutUsernames[i] +
" login timed out.");
1747 if (Command ==
"sessionId")
1754 std::string uuid = CgiDataUtilities::postData(cgi,
"uuid");
1756 std::string sid = theWebUsers_.createNewLoginSession(uuid);
1758 __MOUT__ <<
"uuid = " << uuid << std::endl;
1759 __MOUT__ <<
"SessionId = " << sid.substr(0, 10) << std::endl;
1762 else if (Command ==
"checkCookie")
1766 std::string jumbledUser;
1767 std::string cookieCode;
1777 uuid = CgiDataUtilities::postData(cgi,
"uuid");
1778 jumbledUser = CgiDataUtilities::postData(cgi,
"ju");
1779 cookieCode = CgiDataUtilities::postData(cgi,
"cc");
1781 __MOUT__ <<
"Cookie Code = " << cookieCode.substr(0, 10) << std::endl;
1782 __MOUT__ <<
"jumbledUser = " << jumbledUser.substr(0, 10) << std::endl;
1783 __MOUT__ <<
"uuid = " << uuid << std::endl;
1786 uid = theWebUsers_.isCookieCodeActiveForLogin(uuid, cookieCode,
1789 if (uid == theWebUsers_.NOT_FOUND_IN_DATABASE)
1791 __MOUT__ <<
"cookieCode invalid" << std::endl;
1799 theWebUsers_.insertSettingsForUser(uid, &xmldoc);
1801 xmldoc.outputXmlDocument((std::ostringstream*) out);
1804 else if (Command ==
"login")
1815 std::string uuid = CgiDataUtilities::postData(cgi,
"uuid");
1816 std::string newAccountCode = CgiDataUtilities::postData(cgi,
"nac");
1817 std::string jumbledUser = CgiDataUtilities::postData(cgi,
"ju");
1818 std::string jumbledPw = CgiDataUtilities::postData(cgi,
"jp");
1820 __MOUT__ <<
"jumbledUser = " << jumbledUser.substr(0, 10) << std::endl;
1821 __MOUT__ <<
"jumbledPw = " << jumbledPw.substr(0, 10) << std::endl;
1822 __MOUT__ <<
"uuid = " << uuid << std::endl;
1823 __MOUT__ <<
"nac =-" << newAccountCode <<
"-" << std::endl;
1825 uint64_t uid = theWebUsers_.attemptActiveSession(uuid, jumbledUser,
1826 jumbledPw, newAccountCode);
1829 if (uid == theWebUsers_.NOT_FOUND_IN_DATABASE)
1831 __MOUT__ <<
"cookieCode invalid" << std::endl;
1833 if (newAccountCode !=
"1")
1834 newAccountCode =
"0";
1837 __MOUT__ <<
"new cookieCode = " << newAccountCode.substr(0, 10) << std::endl;
1841 theWebUsers_.insertSettingsForUser(uid, &xmldoc);
1845 if (uid != theWebUsers_.NOT_FOUND_IN_DATABASE)
1847 uint64_t asCnt = theWebUsers_.getActiveSessionCountForUser(uid) - 1;
1849 sprintf(asStr,
"%lu", asCnt);
1850 xmldoc.addTextElementToData(
"user_active_session_count", asStr);
1853 xmldoc.outputXmlDocument((std::ostringstream*) out);
1856 makeSystemLogbookEntry(
1857 theWebUsers_.getUsersUsername(uid) +
" logged in.");
1859 else if (Command ==
"logout")
1861 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
1862 std::string logoutOthers = CgiDataUtilities::postData(cgi,
1865 __MOUT__ <<
"Cookie Code = " << cookieCode.substr(0, 10) << std::endl;
1866 __MOUT__ <<
"logoutOthers = " << logoutOthers << std::endl;
1869 if (theWebUsers_.cookieCodeLogout(cookieCode, logoutOthers ==
"1", &uid)
1870 != theWebUsers_.NOT_FOUND_IN_DATABASE)
1874 if (!theWebUsers_.isUserIdActive(uid))
1875 makeSystemLogbookEntry(
1876 theWebUsers_.getUsersUsername(uid) +
" logged out.");
1881 __MOUT__ << __LINE__ <<
"\tInvalid Command" << std::endl;
1887 void Supervisor::tooltipRequest(xgi::Input * in, xgi::Output * out)
1888 throw (xgi::exception::Exception)
1890 cgicc::Cgicc cgi(in);
1892 std::string Command = CgiDataUtilities::getData(cgi,
"RequestType");
1893 __MOUT__ << Command << std::endl;
1899 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
1900 uint8_t userPermissions;
1903 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions,
1914 if(Command ==
"check")
1916 WebUsers::tooltipCheckForUsername(
1917 theWebUsers_.getUsersUsername(uid),
1919 CgiDataUtilities::getData(cgi,
"srcFile"),
1920 CgiDataUtilities::getData(cgi,
"srcFunc"),
1921 CgiDataUtilities::getData(cgi,
"srcId"));
1923 else if(Command ==
"setNeverShow")
1925 WebUsers::tooltipSetNeverShowForUsername(
1926 theWebUsers_.getUsersUsername(uid),
1928 CgiDataUtilities::getData(cgi,
"srcFile"),
1929 CgiDataUtilities::getData(cgi,
"srcFunc"),
1930 CgiDataUtilities::getData(cgi,
"srcId"),
1931 CgiDataUtilities::getData(cgi,
"doNeverShow") ==
"1"?
true:
false,
1932 CgiDataUtilities::getData(cgi,
"temporarySilence") ==
"1"?
true:
false);
1936 __MOUT__ <<
"Command Request, " << Command <<
", not recognized." << std::endl;
1938 xmldoc.outputXmlDocument((std::ostringstream*) out,
false,
true);
1942 void Supervisor::request(xgi::Input * in, xgi::Output * out)
1943 throw (xgi::exception::Exception)
1945 cgicc::Cgicc cgi(in);
1947 std::string Command = CgiDataUtilities::getData(cgi,
"RequestType");
1954 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
1955 uint8_t userPermissions;
1957 std::string userWithLock;
1959 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions,
1960 &uid,
"0", Command !=
"getSystemMessages", &userWithLock))
1987 if (Command ==
"getSettings")
1989 std::string accounts = CgiDataUtilities::getData(cgi,
"accounts");
1991 __MOUT__ <<
"Get Settings Request" << std::endl;
1992 __MOUT__ <<
"accounts = " << accounts << std::endl;
1993 theWebUsers_.insertSettingsForUser(uid, &xmldoc, accounts ==
"1");
1995 else if (Command ==
"setSettings")
1997 std::string bgcolor = CgiDataUtilities::postData(cgi,
"bgcolor");
1998 std::string dbcolor = CgiDataUtilities::postData(cgi,
"dbcolor");
1999 std::string wincolor = CgiDataUtilities::postData(cgi,
"wincolor");
2000 std::string layout = CgiDataUtilities::postData(cgi,
"layout");
2001 std::string syslayout = CgiDataUtilities::postData(cgi,
"syslayout");
2003 __MOUT__ <<
"Set Settings Request" << std::endl;
2004 __MOUT__ <<
"bgcolor = " << bgcolor << std::endl;
2005 __MOUT__ <<
"dbcolor = " << dbcolor << std::endl;
2006 __MOUT__ <<
"wincolor = " << wincolor << std::endl;
2007 __MOUT__ <<
"layout = " << layout << std::endl;
2008 __MOUT__ <<
"syslayout = " << syslayout << std::endl;
2009 theWebUsers_.changeSettingsForUser(uid, bgcolor, dbcolor, wincolor,
2011 theWebUsers_.insertSettingsForUser(uid, &xmldoc,
true);
2013 else if (Command ==
"accountSettings")
2015 std::string type = CgiDataUtilities::postData(cgi,
"type");
2018 if (type ==
"updateAccount")
2020 else if (type ==
"createAccount")
2022 else if (type ==
"deleteAccount")
2025 std::string username = CgiDataUtilities::postData(cgi,
"username");
2026 std::string displayname = CgiDataUtilities::postData(cgi,
2028 std::string permissions = CgiDataUtilities::postData(cgi,
2030 std::string accounts = CgiDataUtilities::getData(cgi,
"accounts");
2032 __MOUT__ <<
"accountSettings Request" << std::endl;
2033 __MOUT__ <<
"type = " << type <<
" - " << type_int << std::endl;
2034 __MOUT__ <<
"username = " << username << std::endl;
2035 __MOUT__ <<
"displayname = " << displayname << std::endl;
2036 __MOUT__ <<
"permissions = " << permissions << std::endl;
2038 theWebUsers_.modifyAccountSettings(uid, type_int, username, displayname,
2041 __MOUT__ <<
"accounts = " << accounts << std::endl;
2043 theWebUsers_.insertSettingsForUser(uid, &xmldoc, accounts ==
"1");
2045 else if(Command ==
"stateMatchinePreferences")
2047 std::string set = CgiDataUtilities::getData(cgi,
"set");
2048 const std::string DEFAULT_FSM_VIEW =
"Default_FSM_View";
2050 theWebUsers_.setGenericPreference(uid, DEFAULT_FSM_VIEW,
2051 CgiDataUtilities::getData(cgi, DEFAULT_FSM_VIEW));
2053 theWebUsers_.getGenericPreference(uid, DEFAULT_FSM_VIEW, &xmldoc);
2055 else if(Command ==
"getAliasList")
2057 std::string username = theWebUsers_.getUsersUsername(uid);
2058 std::string fsmName = CgiDataUtilities::getData(cgi,
"fsmName");
2059 __MOUT__ <<
"fsmName = " << fsmName << std::endl;
2061 std::string stateMachineAliasFilter =
"*";
2063 std::map<std::string ,
2065 theConfigurationManager_->getGroupAliasesConfiguration();
2069 ConfigurationTree configLinkNode = theConfigurationManager_->getSupervisorConfigurationNode(
2070 supervisorContextUID_, supervisorApplicationUID_);
2072 if(!configLinkNode.isDisconnected())
2076 ConfigurationTree fsmLinkNode = configLinkNode.getNode(
"LinkToStateMachineConfiguration");
2077 if(!fsmLinkNode.isDisconnected())
2078 stateMachineAliasFilter =
2079 fsmLinkNode.getNode(fsmName +
"/SystemAliasFilter").getValue<std::string>();
2081 __MOUT_INFO__ <<
"FSM Link disconnected." << std::endl;
2083 catch(std::runtime_error &e) { __MOUT_INFO__ << e.what() << std::endl; }
2084 catch(...) { __MOUT_ERR__ <<
"Unknown error. Should never happen." << std::endl; }
2087 __MOUT_INFO__ <<
"FSM Link disconnected." << std::endl;
2089 __MOUT__ <<
"stateMachineAliasFilter = " << stateMachineAliasFilter << std::endl;
2096 bool invertFilter = stateMachineAliasFilter.size() && stateMachineAliasFilter[0] ==
'!';
2097 std::vector<std::string> filterArr;
2100 if(invertFilter) ++i;
2103 while((f = stateMachineAliasFilter.find(
'*',i)) != std::string::npos)
2105 tmp = stateMachineAliasFilter.substr(i,f-i);
2107 filterArr.push_back(tmp);
2112 if(i <= stateMachineAliasFilter.size())
2114 tmp = stateMachineAliasFilter.substr(i);
2115 filterArr.push_back(tmp);
2123 for(
auto& aliasMapPair : aliasMap)
2129 if(filterArr.size() == 1)
2131 if(filterArr[0] !=
"" &&
2132 filterArr[0] !=
"*" &&
2133 aliasMapPair.first != filterArr[0])
2134 filterMatch =
false;
2139 for(f=0;f<filterArr.size();++f)
2141 if(!filterArr[f].size())
continue;
2145 if((i = aliasMapPair.first.find(filterArr[f])) != 0)
2147 filterMatch =
false;
2151 else if(f == filterArr.size()-1)
2153 if(aliasMapPair.first.rfind(filterArr[f]) !=
2154 aliasMapPair.first.size() - filterArr[f].size())
2156 filterMatch =
false;
2160 else if((i = aliasMapPair.first.find(filterArr[f])) ==
2163 filterMatch =
false;
2169 if(invertFilter) filterMatch = !filterMatch;
2173 if(!filterMatch)
continue;
2175 xmldoc.addTextElementToData(
"config_alias", aliasMapPair.first);
2176 xmldoc.addTextElementToData(
"config_key",
2177 ConfigurationGroupKey::getFullGroupString(aliasMapPair.second.first,
2178 aliasMapPair.second.second).c_str());
2180 std::string groupComment, groupAuthor, groupCreationTime;
2183 theConfigurationManager_->loadConfigurationGroup(
2184 aliasMapPair.second.first,aliasMapPair.second.second,
2186 &groupComment, &groupAuthor, &groupCreationTime,
false );
2188 xmldoc.addTextElementToData(
"config_comment", groupComment);
2189 xmldoc.addTextElementToData(
"config_author", groupAuthor);
2190 xmldoc.addTextElementToData(
"config_create_time", groupCreationTime);
2194 __MOUT_WARN__ <<
"Failed to load group metadata." << std::endl;
2200 std::string fn = FSM_LAST_GROUP_ALIAS_PATH + FSM_LAST_GROUP_ALIAS_FILE_START +
2201 username +
"." + FSM_USERS_PREFERENCES_FILETYPE;
2202 __MOUT__ <<
"Load preferences: " << fn << std::endl;
2203 FILE *fp = fopen(fn.c_str(),
"r");
2206 char tmpLastAlias[500];
2207 fscanf(fp,
"%*s %s",tmpLastAlias);
2208 __MOUT__ <<
"tmpLastAlias: " << tmpLastAlias << std::endl;
2210 xmldoc.addTextElementToData(
"UserLastConfigAlias",tmpLastAlias);
2214 else if (Command ==
"getFecList")
2216 xmldoc.addTextElementToData(
"fec_list",
"");
2218 for (
unsigned int i = 0; i< theSupervisorDescriptorInfo_.getFEDescriptors().size(); ++i)
2220 xmldoc.addTextElementToParent(
"fec_url",
2221 theSupervisorDescriptorInfo_.getFEURL(i),
"fec_list");
2222 xmldoc.addTextElementToParent(
2224 theSupervisorDescriptorInfo_.getFEDescriptor(i)->getURN(),
2228 else if (Command ==
"getSystemMessages")
2230 xmldoc.addTextElementToData(
"systemMessages",
2231 theSysMessenger_.getSysMsg(
2232 theWebUsers_.getUsersDisplayName(uid)));
2234 xmldoc.addTextElementToData(
"username_with_lock",
2235 theWebUsers_.getUserWithLock());
2239 else if (Command ==
"setUserWithLock")
2241 std::string username = CgiDataUtilities::postData(cgi,
"username");
2242 std::string lock = CgiDataUtilities::postData(cgi,
"lock");
2243 std::string accounts = CgiDataUtilities::getData(cgi,
"accounts");
2245 __MOUT__ << Command << std::endl;
2246 __MOUT__ <<
"username " << username << std::endl;
2247 __MOUT__ <<
"lock " << lock << std::endl;
2248 __MOUT__ <<
"accounts " << accounts << std::endl;
2249 __MOUT__ <<
"uid " << uid << std::endl;
2251 std::string tmpUserWithLock = theWebUsers_.getUserWithLock();
2252 if(!theWebUsers_.setUserWithLock(uid, lock ==
"1", username))
2253 xmldoc.addTextElementToData(
"server_alert",
2254 std::string(
"Set user lock action failed. You must have valid permissions and ") +
2255 "locking user must be currently logged in.");
2257 theWebUsers_.insertSettingsForUser(uid, &xmldoc, accounts ==
"1");
2259 if (tmpUserWithLock != theWebUsers_.getUserWithLock())
2260 theSysMessenger_.addSysMsg(
"*", theWebUsers_.getUserWithLock()
2261 ==
"" ? tmpUserWithLock +
" has unlocked ots."
2262 : theWebUsers_.getUserWithLock()
2263 +
" has locked ots.");
2265 else if (Command ==
"getStateMachine")
2268 std::vector<toolbox::fsm::State> states;
2269 states = theStateMachine_.getStates();
2272 std::string transName;
2273 std::string transParameter;
2274 for (
unsigned int i = 0; i < states.size(); ++i)
2276 stateStr[0] = states[i];
2277 DOMElement* stateParent = xmldoc.addTextElementToData(
"state", stateStr);
2279 xmldoc.addTextElementToParent(
"state_name", theStateMachine_.getStateName(states[i]), stateParent);
2284 std::map<std::string, toolbox::fsm::State, std::less<std::string> >
2285 trans = theStateMachine_.getTransitions(states[i]);
2286 std::set<std::string> actionNames = theStateMachine_.getInputs(states[i]);
2288 std::map<std::string, toolbox::fsm::State, std::less<std::string> >::iterator
2290 std::set<std::string>::iterator ait = actionNames.begin();
2291 for (; it != trans.end() && ait != actionNames.end(); ++it, ++ait)
2295 stateStr[0] = it->second;
2296 xmldoc.addTextElementToParent(
"state_transition", stateStr, stateParent);
2300 xmldoc.addTextElementToParent(
"state_transition_action", *ait, stateParent);
2302 transName = theStateMachine_.getTransitionName(states[i], *ait);
2305 xmldoc.addTextElementToParent(
"state_transition_name",
2306 transName, stateParent);
2307 transParameter = theStateMachine_.getTransitionParameter(states[i], *ait);
2310 xmldoc.addTextElementToParent(
"state_transition_parameter", transParameter, stateParent);
2315 else if (Command ==
"getCurrentState")
2317 xmldoc.addTextElementToData(
"current_state", theStateMachine_.getCurrentStateName());
2318 xmldoc.addTextElementToData(
"in_transition", theStateMachine_.isInTransition() ?
"1" :
"0");
2319 if (theStateMachine_.isInTransition())
2320 xmldoc.addTextElementToData(
"transition_progress", theProgressBar_.readPercentageString());
2322 xmldoc.addTextElementToData(
"transition_progress",
"100");
2326 sprintf(tmp,
"%lu",theStateMachine_.getTimeInState());
2327 xmldoc.addTextElementToData(
"time_in_state", tmp);
2335 std::string fsmName = CgiDataUtilities::getData(cgi,
"fsmName");
2343 if(!theStateMachine_.isInTransition())
2345 std::string stateMachineRunAlias =
"Run";
2348 ConfigurationTree configLinkNode = theConfigurationManager_->getSupervisorConfigurationNode(
2349 supervisorContextUID_, supervisorApplicationUID_);
2351 if(!configLinkNode.isDisconnected())
2355 ConfigurationTree fsmLinkNode = configLinkNode.getNode(
"LinkToStateMachineConfiguration");
2356 if(!fsmLinkNode.isDisconnected())
2357 stateMachineRunAlias =
2358 fsmLinkNode.getNode(fsmName +
"/RunDisplayAlias").getValue<std::string>();
2362 catch(std::runtime_error &e) { __MOUT_INFO__ << e.what() << std::endl; }
2363 catch(...) { __MOUT_ERR__ <<
"Unknown error. Should never happen." << std::endl; }
2370 xmldoc.addTextElementToData(
"stateMachineRunAlias", stateMachineRunAlias);
2375 if(theStateMachine_.getCurrentStateName() ==
"Running" ||
2376 theStateMachine_.getCurrentStateName() ==
"Paused")
2377 sprintf(tmp,
"Current %s Number: %u",stateMachineRunAlias.c_str(),getNextRunNumber(activeStateMachineName_)-1);
2379 sprintf(tmp,
"Next %s Number: %u",stateMachineRunAlias.c_str(),getNextRunNumber(fsmName));
2380 xmldoc.addTextElementToData(
"run_number", tmp);
2383 else if(Command ==
"getErrorInStateMatchine")
2385 xmldoc.addTextElementToData(
"FSM_Error", theStateMachine_.getErrorMessage());
2387 else if(Command ==
"getDesktopIcons")
2390 std::string iconFileName = ICON_FILE_NAME;
2391 std::ifstream iconFile;
2392 std::string iconList =
"";
2394 iconFile.open(iconFileName.c_str());
2398 __MOUT__ <<
"Error opening file: "<< iconFileName << std::endl;
2402 if(iconFile.is_open())
2404 __MOUT__ <<
"Opened File: " << iconFileName << std::endl;
2405 while(std::getline(iconFile, line))
2409 __MOUT__ << iconList << std::endl;
2414 xmldoc.addTextElementToData(
"iconList", iconList);
2417 else if(Command ==
"launchConfig")
2419 if(userPermissions != 255)
2421 __MOUT__ <<
"Insufficient Permissions" << std::endl;
2425 __MOUT__ <<
"Self-destruct." << std::endl;
2430 else if(Command ==
"resetUserTooltips")
2432 WebUsers::resetAllUserTooltips(theWebUsers_.getUsersUsername(uid));
2435 __MOUT__ <<
"Command Request, " << Command <<
", not recognized." << std::endl;
2440 xmldoc.outputXmlDocument((std::ostringstream*) out,
false,
true);
2448 xoap::MessageReference Supervisor::supervisorGetUserInfo(
2449 xoap::MessageReference message)
2450 throw (xoap::exception::Exception)
2453 parameters.addParameter(
"CookieCode");
2454 receive(message, parameters);
2455 std::string cookieCode = parameters.getValue(
"CookieCode");
2457 std::string username, displayName;
2458 uint64_t activeSessionIndex;
2460 theWebUsers_.getUserInfoForCookie(cookieCode, &username, &displayName,
2461 &activeSessionIndex);
2468 retParameters.addParameter(
"Username", username);
2469 retParameters.addParameter(
"DisplayName", displayName);
2471 sprintf(tmpStr,
"%lu", activeSessionIndex);
2472 retParameters.addParameter(
"ActiveSessionIndex", tmpStr);
2474 return SOAPUtilities::makeSOAPMessageReference(
"UserInfoResponse",
2481 xoap::MessageReference Supervisor::supervisorCookieCheck(xoap::MessageReference message)
2482 throw (xoap::exception::Exception)
2488 parameters.addParameter(
"CookieCode");
2489 parameters.addParameter(
"RefreshOption");
2490 receive(message, parameters);
2491 std::string cookieCode = parameters.getValue(
"CookieCode");
2492 std::string refreshOption = parameters.getValue(
"RefreshOption");
2496 uint8_t userPermissions = 0;
2497 std::string userWithLock =
"";
2498 theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions, 0,
2499 "0", refreshOption ==
"1", &userWithLock);
2505 retParameters.addParameter(
"CookieCode", cookieCode);
2507 sprintf(tmp,
"%d", userPermissions);
2508 retParameters.addParameter(
"Permissions", tmp);
2509 retParameters.addParameter(
"UserWithLock", userWithLock);
2513 return SOAPUtilities::makeSOAPMessageReference(
"CookieResponse",
2520 xoap::MessageReference Supervisor::supervisorGetActiveUsers(
2521 xoap::MessageReference message)
2522 throw (xoap::exception::Exception)
2524 __MOUT__ << std::endl;
2527 parameters(
"UserList", theWebUsers_.getActiveUsersString());
2528 return SOAPUtilities::makeSOAPMessageReference(
"ActiveUserResponse",
2536 xoap::MessageReference Supervisor::supervisorSystemMessage(
2537 xoap::MessageReference message)
2538 throw (xoap::exception::Exception)
2541 parameters.addParameter(
"ToUser");
2542 parameters.addParameter(
"Message");
2543 receive(message, parameters);
2545 __MOUT__ <<
"toUser: " << parameters.getValue(
"ToUser").substr(
2546 0, 10) <<
", message: " << parameters.getValue(
"Message").substr(0,
2549 theSysMessenger_.addSysMsg(parameters.getValue(
"ToUser"),
2550 parameters.getValue(
"Message"));
2551 return SOAPUtilities::makeSOAPMessageReference(
"SystemMessageResponse");
2558 xoap::MessageReference Supervisor::supervisorSystemLogbookEntry(
2559 xoap::MessageReference message)
2560 throw (xoap::exception::Exception)
2563 parameters.addParameter(
"EntryText");
2564 receive(message, parameters);
2566 __MOUT__ <<
"EntryText: " << parameters.getValue(
"EntryText").substr(
2567 0, 10) << std::endl;
2569 makeSystemLogbookEntry(parameters.getValue(
"EntryText"));
2571 return SOAPUtilities::makeSOAPMessageReference(
"SystemLogbookResponse");
2579 xoap::MessageReference Supervisor::supervisorLastConfigGroupRequest(
2580 xoap::MessageReference message)
2581 throw (xoap::exception::Exception)
2584 parameters.addParameter(
"ActionOfLastGroup");
2585 receive(message, parameters);
2587 return Supervisor::lastConfigGroupRequestHandler(parameters);
2596 xoap::MessageReference Supervisor::lastConfigGroupRequestHandler(
2599 std::string action = parameters.getValue(
"ActionOfLastGroup");
2600 __MOUT__ <<
"ActionOfLastGroup: " << action.substr(
2601 0, 10) << std::endl;
2603 std::string fileName =
"";
2604 if(action ==
"Configured")
2605 fileName = FSM_LAST_CONFIGURED_GROUP_ALIAS_FILE;
2606 else if(action ==
"Started")
2607 fileName = FSM_LAST_STARTED_GROUP_ALIAS_FILE;
2610 __MOUT_ERR__ <<
"Invalid last group action requested." << std::endl;
2611 return SOAPUtilities::makeSOAPMessageReference(
"LastConfigGroupResponseFailure");
2613 std::string timeString;
2615 loadGroupNameAndKey(fileName,timeString);
2619 retParameters.addParameter(
"GroupName", theGroup.first);
2620 retParameters.addParameter(
"GroupKey", theGroup.second.toString());
2621 retParameters.addParameter(
"GroupAction", action);
2622 retParameters.addParameter(
"GroupActionTime", timeString);
2625 return SOAPUtilities::makeSOAPMessageReference(
"LastConfigGroupResponse",
2636 unsigned int Supervisor::getNextRunNumber(
const std::string &fsmNameIn)
2638 std::string runNumberFileName = RUN_NUMBER_PATH +
"/";
2639 std::string fsmName = fsmNameIn ==
""?activeStateMachineName_:fsmNameIn;
2641 for(
unsigned int i=0;i<fsmName.size();++i)
2642 if( (fsmName[i] >=
'a' && fsmName[i] <=
'z') ||
2643 (fsmName[i] >=
'A' && fsmName[i] <=
'Z') ||
2644 (fsmName[i] >=
'0' && fsmName[i] <=
'9'))
2645 runNumberFileName += fsmName[i];
2646 runNumberFileName += RUN_NUMBER_FILE_NAME;
2649 std::ifstream runNumberFile(runNumberFileName.c_str());
2650 if (!runNumberFile.is_open())
2652 __MOUT__ <<
"Can't open file: " << runNumberFileName << std::endl;
2654 __MOUT__ <<
"Creating file and setting Run Number to 1: " << runNumberFileName << std::endl;
2655 FILE *fp = fopen(runNumberFileName.c_str(),
"w");
2659 runNumberFile.open(runNumberFileName.c_str());
2660 if(!runNumberFile.is_open())
2662 __MOUT__ <<
"Can't create file: " << runNumberFileName << std::endl;
2663 throw std::runtime_error(
"Error.");
2666 std::string runNumberString;
2667 runNumberFile >> runNumberString;
2668 runNumberFile.close();
2669 return atoi(runNumberString.c_str());
2673 bool Supervisor::setNextRunNumber(
unsigned int runNumber,
const std::string &fsmNameIn)
2675 std::string runNumberFileName = RUN_NUMBER_PATH +
"/";
2676 std::string fsmName = fsmNameIn ==
""?activeStateMachineName_:fsmNameIn;
2678 for(
unsigned int i=0;i<fsmName.size();++i)
2679 if( (fsmName[i] >=
'a' && fsmName[i] <=
'z') ||
2680 (fsmName[i] >=
'A' && fsmName[i] <=
'Z') ||
2681 (fsmName[i] >=
'0' && fsmName[i] <=
'9'))
2682 runNumberFileName += fsmName[i];
2683 runNumberFileName += RUN_NUMBER_FILE_NAME;
2684 __MOUT__ <<
"runNumberFileName: " << runNumberFileName << std::endl;
2686 std::ofstream runNumberFile(runNumberFileName.c_str());
2687 if (!runNumberFile.is_open())
2689 __MOUT__ <<
"Can't open file: " << runNumberFileName << std::endl;
2690 throw std::runtime_error(
"Error.");
2692 std::stringstream runNumberStream;
2693 runNumberStream << runNumber;
2694 runNumberFile << runNumberStream.str().c_str();
2695 runNumberFile.close();
2705 std::pair<std::string ,
2707 std::string &returnedTimeString)
2709 std::string fullPath = FSM_LAST_GROUP_ALIAS_PATH +
"/" + fileName;
2711 FILE *groupFile = fopen(fullPath.c_str(),
"r");
2714 __MOUT__ <<
"Can't open file: " << fullPath << std::endl;
2716 __MOUT__ <<
"Returning empty groupName and key -1" << std::endl;
2718 return std::pair<std::string ,
2724 std::pair<std::string ,
2727 fgets(line,500,groupFile);
2728 theGroup.first = line;
2730 fgets(line,500,groupFile);
2732 sscanf(line,
"%d",&key);
2733 theGroup.second = key;
2735 fgets(line,500,groupFile);
2737 sscanf(line,
"%ld",×tamp);
2739 ::localtime_r(×tamp, &tmstruct);
2740 ::strftime(line, 30,
"%c %Z", &tmstruct);
2741 returnedTimeString = line;
2745 __MOUT__ <<
"theGroup.first= " << theGroup.first <<
2746 " theGroup.second= " << theGroup.second << std::endl;
2752 void Supervisor::saveGroupNameAndKey(
const std::pair<std::string ,
2754 const std::string &fileName)
2756 std::string fullPath = FSM_LAST_GROUP_ALIAS_PATH +
"/" + fileName;
2758 std::ofstream groupFile(fullPath.c_str());
2759 if (!groupFile.is_open())
2761 __SS__ <<
"Can't open file: " << fullPath << std::endl;
2762 __MOUT_ERR__ <<
"\n" << ss.str();
2763 throw std::runtime_error(
"Error.\n" + ss.str());
2765 std::stringstream outss;
2766 outss << theGroup.first <<
"\n" << theGroup.second <<
"\n" << time(0);
2767 groupFile << outss.str().c_str();