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__ "GatewaySupervisor"
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_ ("")
63 INIT_MF(
"Supervisor");
64 __COUT__ << std::endl;
67 mkdir((FSM_LAST_GROUP_ALIAS_PATH).c_str(), 0755);
68 mkdir((RUN_NUMBER_PATH).c_str(), 0755);
70 securityType_ = theWebUsers_.getSecurity();
72 __COUT__ <<
"Security: " << securityType_ << std::endl;
74 xgi::bind(
this, &Supervisor::Default,
"Default");
75 xgi::bind(
this, &Supervisor::loginRequest,
"LoginRequest");
76 xgi::bind(
this, &Supervisor::request,
"Request");
77 xgi::bind(
this, &Supervisor::stateMachineXgiHandler,
"StateMachineXgiHandler");
78 xgi::bind(
this, &Supervisor::infoRequestHandler,
"InfoRequestHandler");
79 xgi::bind(
this, &Supervisor::infoRequestResultHandler,
"InfoRequestResultHandler");
80 xgi::bind(
this, &Supervisor::tooltipRequest,
"TooltipRequest");
82 xoap::bind(
this, &Supervisor::supervisorCookieCheck,
"SupervisorCookieCheck", XDAQ_NS_URI);
83 xoap::bind(
this, &Supervisor::supervisorGetActiveUsers,
"SupervisorGetActiveUsers", XDAQ_NS_URI);
84 xoap::bind(
this, &Supervisor::supervisorSystemMessage,
"SupervisorSystemMessage", XDAQ_NS_URI);
85 xoap::bind(
this, &Supervisor::supervisorGetUserInfo,
"SupervisorGetUserInfo", XDAQ_NS_URI);
86 xoap::bind(
this, &Supervisor::supervisorSystemLogbookEntry,
"SupervisorSystemLogbookEntry", XDAQ_NS_URI);
87 xoap::bind(
this, &Supervisor::supervisorLastConfigGroupRequest,
"SupervisorLastConfigGroupRequest", XDAQ_NS_URI);
103 Supervisor::~Supervisor(
void)
105 delete theConfigurationManager_;
106 makeSystemLogbookEntry(
"ots halted.");
110 void Supervisor::init(
void)
113 theSupervisorDescriptorInfo_.init(getApplicationContext());
114 theSupervisorsInfo_.init(theSupervisorDescriptorInfo_);
116 supervisorGuiHasBeenLoaded_ =
false;
120 supervisorContextUID_ = contextConfiguration->getContextUID(
121 getApplicationContext()->getContextDescriptor()->getURL()
123 __COUT__ <<
"Context UID:" << supervisorContextUID_ << std::endl;
125 supervisorApplicationUID_ = contextConfiguration->getApplicationUID(
126 getApplicationContext()->getContextDescriptor()->getURL(),
127 getApplicationDescriptor()->getLocalId()
130 __COUT__ <<
"Application UID:" << supervisorApplicationUID_ << std::endl;
132 ConfigurationTree configLinkNode = theConfigurationManager_->getSupervisorConfigurationNode(
133 supervisorContextUID_, supervisorApplicationUID_);
138 std::string supervisorUID;
139 if(!configLinkNode.isDisconnected())
140 supervisorUID = configLinkNode.getValue();
142 supervisorUID = ViewColumnInfo::DATATYPE_LINK_DEFAULT;
144 __COUT__ <<
"Supervisor UID:" << supervisorUID << std::endl;
148 void Supervisor::URLDisplayThread(Supervisor *supervisorPtr)
150 INIT_MF(
"Supervisor");
156 std::this_thread::sleep_for (std::chrono::seconds(2));
157 std:: cout << __COUT_HDR_FL__ <<
"\n*********************************************************************" << std::endl;
158 std:: cout << __COUT_HDR_FL__ <<
"\n\n"
159 << supervisorPtr->getApplicationContext()->getContextDescriptor()->getURL()
161 <<
"/urn:xdaq-application:lid="
162 << supervisorPtr->getApplicationDescriptor()->getLocalId() <<
"/"
163 <<
"\n" << std::endl;
164 std:: cout << __COUT_HDR_FL__ <<
"\n*********************************************************************" << std::endl;
173 void Supervisor::makeSystemLogbookEntry(std::string entryText)
175 __COUT__ <<
"Making System Logbook Entry: " << entryText << std::endl;
178 if(!theSupervisorDescriptorInfo_.getLogbookDescriptor())
180 __COUT__ <<
"Just kidding... Logbook Descriptor not found." << std:: endl;
186 std::string replace[] =
187 {
"\"",
"'",
"&",
"<",
">",
"\n",
" "};
189 {
"%22",
"%27",
"%26",
"%3C",
"%3E",
"%0A%0D",
"%20%20"};
194 for(
int i=0;i<numOfKeys;++i)
196 while((f=entryText.find(replace[i])) != std::string::npos)
198 entryText = entryText.substr(0,f) + with[i] + entryText.substr(f+replace[i].length());
209 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(theSupervisorDescriptorInfo_.getLogbookDescriptor(),
"MakeSystemLogbookEntry",parameters);
214 receive(retMsg, retParameters);
216 __COUT__ <<
"Returned Status: " << retParameters.getValue(
"Status") << std::endl;
221 void Supervisor::Default(xgi::Input* in, xgi::Output* out)
222 throw (xgi::exception::Exception)
225 if (!supervisorGuiHasBeenLoaded_ && (supervisorGuiHasBeenLoaded_ =
true))
226 makeSystemLogbookEntry(
"ots started.");
229 "<!DOCTYPE HTML><html lang='en'><head><title>ots</title>" <<
232 "<link rel='apple-touch-icon' sizes='57x57' href='/WebPath/images/otsdaqIcons/apple-icon-57x57.png'>\
233 <link rel='apple-touch-icon' sizes='60x60' href='/WebPath/images/otsdaqIcons/apple-icon-60x60.png'>\
234 <link rel='apple-touch-icon' sizes='72x72' href='/WebPath/images/otsdaqIcons/apple-icon-72x72.png'>\
235 <link rel='apple-touch-icon' sizes='76x76' href='/WebPath/images/otsdaqIcons/apple-icon-76x76.png'>\
236 <link rel='apple-touch-icon' sizes='114x114' href='/WebPath/images/otsdaqIcons/apple-icon-114x114.png'>\
237 <link rel='apple-touch-icon' sizes='120x120' href='/WebPath/images/otsdaqIcons/apple-icon-120x120.png'>\
238 <link rel='apple-touch-icon' sizes='144x144' href='/WebPath/images/otsdaqIcons/apple-icon-144x144.png'>\
239 <link rel='apple-touch-icon' sizes='152x152' href='/WebPath/images/otsdaqIcons/apple-icon-152x152.png'>\
240 <link rel='apple-touch-icon' sizes='180x180' href='/WebPath/images/otsdaqIcons/apple-icon-180x180.png'>\
241 <link rel='icon' type='image/png' sizes='192x192' href='/WebPath/images/otsdaqIcons/android-icon-192x192.png'>\
242 <link rel='icon' type='image/png' sizes='32x32' href='/WebPath/images/otsdaqIcons/favicon-32x32.png'>\
243 <link rel='icon' type='image/png' sizes='96x96' href='/WebPath/images/otsdaqIcons/favicon-96x96.png'>\
244 <link rel='icon' type='image/png' sizes='16x16' href='/WebPath/images/otsdaqIcons/favicon-16x16.png'>\
245 <link rel='manifest' href='/WebPath/images/otsdaqIcons/manifest.json'>\
246 <meta name='msapplication-TileColor' content='#ffffff'>\
247 <meta name='msapplication-TileImage' content='/ms-icon-144x144.png'>\
248 <meta name='theme-color' content='#ffffff'>" <<
251 "<frameset col='100%' row='100%'>" <<
252 "<frame src='/WebPath/html/Supervisor.html?urn=" <<
253 this->getApplicationDescriptor()->getLocalId() <<
"=securityType=" <<
254 securityType_ <<
"'></frameset></html>";
260 void Supervisor::stateMachineXgiHandler(xgi::Input* in, xgi::Output* out)
261 throw (xgi::exception::Exception)
264 if(VERBOSE_MUTEX) __COUT__ <<
"Waiting for FSM access" << std::endl;
265 std::lock_guard<std::mutex> lock(stateMachineAccessMutex_);
266 if(VERBOSE_MUTEX) __COUT__ <<
"Have FSM access" << std::endl;
268 cgicc::Cgicc cgi(in);
270 uint8_t userPermissions;
272 std::string userWithLock;
273 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
274 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions,
275 &uid,
"0", 1, &userWithLock))
281 std::string command = CgiDataUtilities::getData(cgi,
"StateMachine");
284 std::string username =
"";
285 username = theWebUsers_.getUsersUsername(uid);
286 if (userWithLock !=
"" && userWithLock != username)
288 *out << WebUsers::REQ_USER_LOCKOUT_RESPONSE;
289 __COUT__ <<
"User " << username <<
" is locked out. " << userWithLock <<
" has lock." << std::endl;
295 std::string fsmName = CgiDataUtilities::getData(cgi,
"fsmName");
296 std::string fsmWindowName = CgiDataUtilities::getData(cgi,
"fsmWindowName");
297 fsmWindowName = CgiDataUtilities::decodeURIComponent(fsmWindowName);
298 std::string currentState = theStateMachine_.getCurrentStateName();
301 if (theStateMachine_.isInTransition())
303 __SS__ <<
"Error - Can not accept request because the State Machine is already in transition!" << std::endl;
304 __COUT_ERR__ <<
"\n" << ss.str();
306 xmldoc.addTextElementToData(
"state_tranisition_attempted",
"0");
307 xmldoc.addTextElementToData(
"state_tranisition_attempted_err",
309 xmldoc.outputXmlDocument((std::ostringstream*) out,
false,
true);
313 __COUT__ <<
"Check for Handled by theIterator_" << std::endl;
316 if((activeStateMachineWindowName_ ==
"" ||
317 activeStateMachineWindowName_ ==
"iterator") &&
318 theIterator_.handleCommandRequest(xmldoc,command,fsmWindowName))
320 __COUT__ <<
"Handled by theIterator_" << std::endl;
321 xmldoc.outputXmlDocument((std::ostringstream*) out,
false);
332 if(activeStateMachineName_ !=
"" &&
333 activeStateMachineName_ != fsmName)
335 __COUT__ <<
"currentState = " <<
336 currentState << std::endl;
337 if(currentState !=
"Halted" &&
338 currentState !=
"Initial")
342 __SS__ <<
"Error - Can not accept request because the State Machine " <<
343 "with window name '" <<
344 activeStateMachineWindowName_ <<
"' (UID: " <<
345 activeStateMachineName_ <<
") "
347 "in control of State Machine progress. ";
348 ss <<
"\n\nIn order for this State Machine with window name '" <<
349 fsmWindowName <<
"' (UID: " << fsmName <<
") "
350 "to control progress, please transition to Halted using the active " <<
351 "State Machine '" << activeStateMachineWindowName_ <<
".'" << std::endl;
352 __COUT_ERR__ <<
"\n" << ss.str();
354 xmldoc.addTextElementToData(
"state_tranisition_attempted",
"0");
355 xmldoc.addTextElementToData(
"state_tranisition_attempted_err",
357 xmldoc.outputXmlDocument((std::ostringstream*) out,
false,
true);
362 activeStateMachineName_ =
"";
363 activeStateMachineWindowName_ =
"";
372 std::vector<std::string> parameters;
373 if(command ==
"Configure")
374 parameters.push_back(CgiDataUtilities::postData(cgi,
"ConfigurationAlias"));
375 attemptStateMachineTransition(&xmldoc,out,command,fsmName,fsmWindowName,
376 username,parameters);
379 std::string Supervisor::attemptStateMachineTransition(
381 const std::string& command,
382 const std::string& fsmName,
const std::string& fsmWindowName,
383 const std::string& username,
384 const std::vector<std::string>& commandParameters)
386 std::string errorStr =
"";
388 std::string currentState = theStateMachine_.getCurrentStateName();
389 __COUT__ <<
"State Machine command = " << command << std::endl;
390 __COUT__ <<
"fsmName = " << fsmName << std::endl;
391 __COUT__ <<
"fsmWindowName = " << fsmWindowName << std::endl;
392 __COUT__ <<
"activeStateMachineName_ = " << activeStateMachineName_ << std::endl;
395 if (command ==
"Configure")
397 if(currentState !=
"Halted")
399 __SS__ <<
"Error - Can only transition to Configured if the current " <<
400 "state is Halted. Perhaps your state machine is out of sync." <<
402 __COUT_ERR__ <<
"\n" << ss.str();
405 if(xmldoc) xmldoc->addTextElementToData(
"state_tranisition_attempted",
"0");
406 if(xmldoc) xmldoc->addTextElementToData(
"state_tranisition_attempted_err",
408 if(out) xmldoc->outputXmlDocument((std::ostringstream*) out,
false,
true);
415 if(!commandParameters.size())
417 __SS__ <<
"Error - Can only transition to Configured if a Configuration Alias parameter is provided." <<
419 __COUT_ERR__ <<
"\n" << ss.str();
422 if(xmldoc) xmldoc->addTextElementToData(
"state_tranisition_attempted",
"0");
423 if(xmldoc) xmldoc->addTextElementToData(
"state_tranisition_attempted_err",
425 if(out) xmldoc->outputXmlDocument((std::ostringstream*) out,
false,
true);
430 parameters.addParameter(
"ConfigurationAlias",
431 commandParameters[0]);
433 std::string configurationAlias = parameters.getValue(
"ConfigurationAlias");
434 __COUT__ <<
"Configure --> Name: ConfigurationAlias Value: " <<
435 configurationAlias << std::endl;
438 std::string fn = FSM_LAST_GROUP_ALIAS_PATH + FSM_LAST_GROUP_ALIAS_FILE_START +
439 username +
"." + FSM_USERS_PREFERENCES_FILETYPE;
441 __COUT__ <<
"Save FSM preferences: " << fn << std::endl;
442 FILE *fp = fopen(fn.c_str(),
"w");
445 __SS__ << (
"Could not open file: " + fn) << std::endl;
446 __COUT_ERR__ << ss.str();
447 throw std::runtime_error(ss.str());
449 fprintf(fp,
"FSM_last_configuration_alias %s",configurationAlias.c_str());
452 activeStateMachineName_ = fsmName;
453 activeStateMachineWindowName_ = fsmWindowName;
455 else if (command ==
"Start")
457 if(currentState !=
"Configured")
459 __SS__ <<
"Error - Can only transition to Configured if the current " <<
460 "state is Halted. Perhaps your state machine is out of sync. " <<
461 "(Likely the server was restarted or another user changed the state)" <<
463 __COUT_ERR__ <<
"\n" << ss.str();
466 if(xmldoc) xmldoc->addTextElementToData(
"state_tranisition_attempted",
"0");
467 if(xmldoc) xmldoc->addTextElementToData(
"state_tranisition_attempted_err",
469 if(out) xmldoc->outputXmlDocument((std::ostringstream*) out,
false,
true);
474 unsigned int runNumber = getNextRunNumber();
475 parameters.addParameter(
"RunNumber", runNumber);
476 setNextRunNumber(++runNumber);
479 xoap::MessageReference message = SOAPUtilities::makeSOAPMessageReference(
480 command, parameters);
482 xoap::MessageReference reply = stateMachineXoapHandler(message);
486 if(xmldoc) xmldoc->addTextElementToData(
"state_tranisition_attempted",
"1");
487 if(out) xmldoc->outputXmlDocument((std::ostringstream*) out,
false);
488 __COUT__ <<
"FSM state transition launched!" << std::endl;
494 void Supervisor::stateMachineResultXgiHandler(xgi::Input* in, xgi::Output* out)
495 throw (xgi::exception::Exception)
497 cgicc::Cgicc cgi(in);
498 __COUT__ <<
"Xgi Request!" << std::endl;
500 uint8_t userPermissions;
501 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
502 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode,
511 std::string command = CgiDataUtilities::getData(cgi,
"StateMachine");
532 xoap::MessageReference message = SOAPUtilities::makeSOAPMessageReference(
533 CgiDataUtilities::getData(cgi,
"StateMachine"), parameters);
535 xoap::MessageReference reply = stateMachineResultXoapHandler(message);
539 __COUT__ <<
"Done - Xgi Request!" << std::endl;
543 xoap::MessageReference Supervisor::stateMachineXoapHandler(xoap::MessageReference message)
544 throw (xoap::exception::Exception)
546 __COUT__ <<
"Soap Handler!" << std::endl;
547 stateMachineWorkLoopManager_.removeProcessedRequests();
548 stateMachineWorkLoopManager_.processRequest(message);
549 __COUT__ <<
"Done - Soap Handler!" << std::endl;
554 xoap::MessageReference Supervisor::stateMachineResultXoapHandler(
555 xoap::MessageReference message)
556 throw (xoap::exception::Exception)
558 __COUT__ <<
"Soap Handler!" << std::endl;
561 __COUT__ <<
"Done - Soap Handler!" << std::endl;
566 bool Supervisor::stateMachineThread(toolbox::task::WorkLoop* workLoop)
568 stateMachineSemaphore_.take();
569 __COUT__ <<
"Re-sending message..." << SOAPUtilities::translate( stateMachineWorkLoopManager_.getMessage(workLoop)).getCommand() << std::endl;
570 std::string reply = send(
571 theSupervisorDescriptorInfo_.getSupervisorDescriptor(),
572 stateMachineWorkLoopManager_.getMessage(workLoop));
573 stateMachineWorkLoopManager_.report(workLoop, reply, 100,
true);
575 __COUT__ <<
"Done with message. Reply = " << reply << std::endl;
576 stateMachineSemaphore_.give();
580 __SS__ <<
"Failure to send Workloop transition command! Unrecognized transition name." << std::endl;
581 __COUT_ERR__ << ss.str();
582 __MOUT_ERR__ << ss.str();
593 void Supervisor::infoRequestHandler(xgi::Input* in, xgi::Output* out)
594 throw (xgi::exception::Exception)
596 __COUT__ <<
"Starting to Request!" << std::endl;
597 cgicc::Cgicc cgi(in);
602 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
603 uint8_t userPermissions;
604 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions))
617 HttpXmlDocument tmpDoc = infoRequestWorkLoopManager_.processRequest(cgi);
619 xmldoc.copyDataChildren(tmpDoc);
621 xmldoc.outputXmlDocument((std::ostringstream*) out,
false);
625 void Supervisor::infoRequestResultHandler(xgi::Input* in, xgi::Output* out)
626 throw (xgi::exception::Exception)
628 __COUT__ <<
"Starting ask!" << std::endl;
629 cgicc::Cgicc cgi(in);
634 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
635 uint8_t userPermissions;
636 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions))
645 infoRequestWorkLoopManager_.getRequestResult(cgi, xmldoc);
648 xmldoc.outputXmlDocument((std::ostringstream*) out,
false);
650 __COUT__ <<
"Done asking!" << std::endl;
654 bool Supervisor::infoRequestThread(toolbox::task::WorkLoop* workLoop)
659 infoRequestSemaphore_.take();
663 for (
unsigned long long i = 0; i < 100000000; i++)
666 vectorTest_.push_back(counterTest_);
669 infoRequestWorkLoopManager_.report(workLoop,
670 "RESULT: This is the best result ever", 50,
false);
671 std::string workLoopName = workLoop->getName();
672 __COUT__ << workLoopName <<
" test: " << counterTest_
673 <<
" vector size: " << vectorTest_.size() << std::endl;
674 wait(400,
"InfoRequestThread ----- locked");
675 infoRequestSemaphore_.give();
677 wait(200,
"InfoRequestThread");
679 infoRequestSemaphore_.take();
683 for (
unsigned long long i = 0; i < 100000000; i++)
686 vectorTest_.push_back(counterTest_);
689 wait(400,
"InfoRequestThread ----- locked");
690 __COUT__ << workLoopName <<
" test: " << counterTest_ <<
" vector size: " << vectorTest_.size() << std::endl;
691 infoRequestSemaphore_.give();
694 infoRequestWorkLoopManager_.report(workLoop,
695 theStateMachine_.getCurrentStateName(), 100,
true);
702 void Supervisor::stateInitial(toolbox::fsm::FiniteStateMachine & fsm)
703 throw (toolbox::fsm::exception::Exception)
705 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
711 void Supervisor::statePaused(toolbox::fsm::FiniteStateMachine & fsm)
712 throw (toolbox::fsm::exception::Exception)
714 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
730 void Supervisor::stateRunning(toolbox::fsm::FiniteStateMachine & fsm)
731 throw (toolbox::fsm::exception::Exception)
734 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
750 void Supervisor::stateHalted(toolbox::fsm::FiniteStateMachine& fsm)
751 throw (toolbox::fsm::exception::Exception)
753 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
754 __COUT__ <<
"Fsm is in transition? " << (theStateMachine_.isInTransition()?
"yes":
"no") << std::endl;
780 void Supervisor::stateConfigured(toolbox::fsm::FiniteStateMachine & fsm)
781 throw (toolbox::fsm::exception::Exception)
849 void Supervisor::inError(toolbox::fsm::FiniteStateMachine & fsm)
850 throw (toolbox::fsm::exception::Exception)
852 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
857 void Supervisor::enteringError(toolbox::Event::Reference e)
858 throw (toolbox::fsm::exception::Exception)
860 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
863 toolbox::fsm::FailedEvent& failedEvent =
dynamic_cast<toolbox::fsm::FailedEvent&
> (*e);
864 __SS__ <<
"\nFailure performing transition from " << failedEvent.getFromState() <<
"-" <<
865 theStateMachine_.getStateName(failedEvent.getFromState()) <<
866 " to " << failedEvent.getToState() <<
"-" <<
867 theStateMachine_.getStateName(failedEvent.getToState()) <<
868 ".\n\nException:\n" << failedEvent.getException().what() << std::endl;
869 __COUT_ERR__ <<
"\n" << ss.str();
871 theStateMachine_.setErrorMessage(ss.str());
884 void Supervisor::getSupervisorsStatus(
void)
885 throw (toolbox::fsm::exception::Exception)
887 theSupervisorsInfo_.getSupervisorInfo().setStatus(
888 theStateMachine_.getCurrentStateName());
892 for (
auto& it : theSupervisorDescriptorInfo_.getFEDescriptors())
896 std::string state = send(it.second,
897 "StateMachineStateRequest");
899 theSupervisorsInfo_.getFESupervisorInfo(it.first).setStatus(
902 __COUT__ <<
"FESupervisor instance " << it.first <<
" is in FSM state " <<
904 __COUT__ <<
"Look! Here's a FEW! @@@" << std::endl;
906 catch (xdaq::exception::Exception& e)
908 __COUT_WARN__ <<
"Could not retrieve status from FESupervisor instance " <<
909 it.first <<
"." << std::endl;
930 for (
auto& it : theSupervisorDescriptorInfo_.getARTDAQFEDataManagerDescriptors())
934 std::string state = send(it.second,
935 "StateMachineStateRequest");
936 theSupervisorsInfo_.getARTDAQFEDataManagerSupervisorInfo(it.first).setStatus(
938 __COUT__ <<
"getARTDAQFEDataManagerDescriptors instance " << it.first <<
" is in FSM state " << state << std::endl;
939 __COUT__ <<
"Look! Here's a FER! @@@" << std::endl;
941 catch (xdaq::exception::Exception& e)
943 __COUT_WARN__ <<
"Could not retrieve status from getARTDAQFEDataManagerDescriptors instance " <<
944 it.first <<
"." << std::endl;
947 for (
auto& it : theSupervisorDescriptorInfo_.getARTDAQDataManagerDescriptors())
951 std::string state = send(it.second,
952 "StateMachineStateRequest");
953 theSupervisorsInfo_.getARTDAQDataManagerSupervisorInfo(it.first).setStatus(
955 __COUT__ <<
"getARTDAQDataManagerSupervisorInfo instance " << it.first <<
" is in FSM state " << state << std::endl;
956 __COUT__ <<
"Look! Here's a FER! @@@" << std::endl;
958 catch (xdaq::exception::Exception& e)
960 __COUT_WARN__ <<
"Could not retrieve status from getARTDAQDataManagerSupervisorInfo instance " <<
961 it.first <<
"." << std::endl;
965 catch (xdaq::exception::Exception& e)
967 __COUT_WARN__ <<
"No FESupervisor found in the \"daq\" group in the Configuration XML file."
974 void Supervisor::transitionConfiguring(toolbox::Event::Reference e)
975 throw (toolbox::fsm::exception::Exception)
979 theProgressBar_.step();
981 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
983 std::string systemAlias = SOAPUtilities::translate(
984 theStateMachine_.getCurrentMessage()).getParameters().getValue(
"ConfigurationAlias");
986 __COUT__ <<
"Transition parameter: " << systemAlias << std::endl;
988 theProgressBar_.step();
993 theConfigurationManager_->init();
997 __SS__ <<
"\nTransition to Configuring interrupted! " <<
998 "The Configuration Manager could not be initialized." << std::endl;
1000 __COUT_ERR__ <<
"\n" << ss.str();
1001 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
1005 theProgressBar_.step();
1010 theConfigurationGroup_ = theConfigurationManager_->getConfigurationGroupFromAlias(systemAlias);
1014 __COUT_INFO__ <<
"Exception occurred" << std::endl;
1017 theProgressBar_.step();
1019 if(theConfigurationGroup_.second.isInvalid())
1021 __SS__ <<
"\nTransition to Configuring interrupted! System Alias " <<
1022 systemAlias <<
" could not be translated to a group name and key." << std::endl;
1024 __COUT_ERR__ <<
"\n" << ss.str();
1025 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
1029 theProgressBar_.step();
1031 __COUT__ <<
"Configuration group name: " << theConfigurationGroup_.first <<
" key: " <<
1032 theConfigurationGroup_.second << std::endl;
1036 std::stringstream ss;
1037 ss <<
"Configuring '" << systemAlias <<
"' which translates to " <<
1038 theConfigurationGroup_.first <<
" (" << theConfigurationGroup_.second <<
").";
1039 makeSystemLogbookEntry(ss.str());
1042 theProgressBar_.step();
1047 theConfigurationManager_->loadConfigurationGroup(theConfigurationGroup_.first, theConfigurationGroup_.second,
true);
1051 tmpCfgMgr.activateConfigurationGroup(theConfigurationGroup_.first, theConfigurationGroup_.second);
1055 __SS__ <<
"\nTransition to Configuring interrupted! System Alias " <<
1056 systemAlias <<
" was translated to " << theConfigurationGroup_.first <<
1057 " (" << theConfigurationGroup_.second <<
") but could not be loaded and initialized." << std::endl;
1058 ss <<
"\n\nTo debug this problem, try activating this group in the Configuration GUI " <<
1059 " and detailed errors will be shown." << std::endl;
1060 __COUT_ERR__ <<
"\n" << ss.str();
1061 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
1067 ConfigurationTree configLinkNode = theConfigurationManager_->getSupervisorConfigurationNode(
1068 supervisorContextUID_, supervisorApplicationUID_);
1069 if(!configLinkNode.isDisconnected())
1074 bool dumpConfiguration =
true;
1075 std::string dumpFilePath, dumpFileRadix, dumpFormat;
1078 ConfigurationTree fsmLinkNode = configLinkNode.getNode(
"LinkToStateMachineConfiguration").
1079 getNode(activeStateMachineName_);
1080 dumpConfiguration = fsmLinkNode.getNode(
"EnableConfigurationDumpOnConfigureTransition").
1082 dumpFilePath = fsmLinkNode.getNode(
"ConfigurationDumpOnConfigureFilePath").getValue<std::string>();
1083 dumpFileRadix = fsmLinkNode.getNode(
"ConfigurationDumpOnConfigureFileRadix").getValue<std::string>();
1084 dumpFormat = fsmLinkNode.getNode(
"ConfigurationDumpOnConfigureFormat").getValue<std::string>();
1087 catch(std::runtime_error &e)
1089 __COUT_INFO__ <<
"FSM configuration dump Link disconnected." << std::endl;
1090 dumpConfiguration =
false;
1093 if(dumpConfiguration)
1096 theConfigurationManager_->dumpActiveConfiguration(
1101 std::to_string(time(0)) +
1108 catch(std::runtime_error &e) {
1109 __SS__ <<
"\nTransition to Configuring interrupted! There was an error identified " <<
1110 "during the configuration dump attempt:\n\n " <<
1111 e.what() << std::endl;
1112 __COUT_ERR__ <<
"\n" << ss.str();
1113 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
1117 __SS__ <<
"\nTransition to Configuring interrupted! There was an error identified " <<
1118 "during the configuration dump attempt.\n\n " <<
1120 __COUT_ERR__ <<
"\n" << ss.str();
1121 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
1127 theProgressBar_.step();
1129 parameters.addParameter(
"ConfigurationGroupName", theConfigurationGroup_.first);
1130 parameters.addParameter(
"ConfigurationGroupKey", theConfigurationGroup_.second.toString());
1133 xoap::MessageReference message = theStateMachine_.getCurrentMessage();
1134 SOAPUtilities::addParameters(message,parameters);
1135 broadcastMessage(message);
1136 theProgressBar_.step();
1141 saveGroupNameAndKey(theConfigurationGroup_,FSM_LAST_CONFIGURED_GROUP_ALIAS_FILE);
1143 __COUT__ <<
"Done" << std::endl;
1144 theProgressBar_.complete();
1148 void Supervisor::transitionHalting(toolbox::Event::Reference e)
1149 throw (toolbox::fsm::exception::Exception)
1151 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
1153 makeSystemLogbookEntry(
"Run halting.");
1155 broadcastMessage(theStateMachine_.getCurrentMessage());
1159 void Supervisor::transitionInitializing(toolbox::Event::Reference e)
1160 throw (toolbox::fsm::exception::Exception)
1162 __COUT__ << theStateMachine_.getCurrentStateName() << std::endl;
1165 getSupervisorsStatus();
1167 if(!broadcastMessage(theStateMachine_.getCurrentMessage()))
1169 __COUT__ <<
"I can't Initialize the supervisors!" << std::endl;
1172 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
1173 __COUT__ <<
"Fsm current transition: " << theStateMachine_.getCurrentTransitionName(e->type()) << std::endl;
1174 __COUT__ <<
"Fsm final state: " << theStateMachine_.getTransitionFinalStateName(e->type()) << std::endl;
1178 void Supervisor::transitionPausing(toolbox::Event::Reference e)
1179 throw (toolbox::fsm::exception::Exception)
1181 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
1183 makeSystemLogbookEntry(
"Run pausing.");
1185 broadcastMessage(theStateMachine_.getCurrentMessage());
1189 void Supervisor::transitionResuming(toolbox::Event::Reference e)
1190 throw (toolbox::fsm::exception::Exception)
1192 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
1194 makeSystemLogbookEntry(
"Run resuming.");
1196 broadcastMessage(theStateMachine_.getCurrentMessage());
1200 void Supervisor::transitionStarting(toolbox::Event::Reference e)
1201 throw (toolbox::fsm::exception::Exception)
1203 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
1206 receive(theStateMachine_.getCurrentMessage(), parameters);
1208 std::string runNumber = parameters.getValue(
"RunNumber");
1209 __COUT__ << runNumber << std::endl;
1213 ConfigurationTree configLinkNode = theConfigurationManager_->getSupervisorConfigurationNode(
1214 supervisorContextUID_, supervisorApplicationUID_);
1215 if(!configLinkNode.isDisconnected())
1219 bool dumpConfiguration =
true;
1220 std::string dumpFilePath, dumpFileRadix, dumpFormat;
1223 ConfigurationTree fsmLinkNode = configLinkNode.getNode(
"LinkToStateMachineConfiguration").
1224 getNode(activeStateMachineName_);
1225 dumpConfiguration = fsmLinkNode.getNode(
"EnableConfigurationDumpOnRunTransition").
1227 dumpFilePath = fsmLinkNode.getNode(
"ConfigurationDumpOnRunFilePath").getValue<std::string>();
1228 dumpFileRadix = fsmLinkNode.getNode(
"ConfigurationDumpOnRunFileRadix").getValue<std::string>();
1229 dumpFormat = fsmLinkNode.getNode(
"ConfigurationDumpOnRunFormat").getValue<std::string>();
1231 catch(std::runtime_error &e)
1233 __COUT_INFO__ <<
"FSM configuration dump Link disconnected." << std::endl;
1234 dumpConfiguration =
false;
1237 if(dumpConfiguration)
1240 theConfigurationManager_->dumpActiveConfiguration(
1247 std::to_string(time(0)) +
1254 catch(std::runtime_error &e) {
1255 __SS__ <<
"\nTransition to Running interrupted! There was an error identified " <<
1256 "during the configuration dump attempt:\n\n " <<
1257 e.what() << std::endl;
1258 __COUT_ERR__ <<
"\n" << ss.str();
1259 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
1263 __SS__ <<
"\nTransition to Running interrupted! There was an error identified " <<
1264 "during the configuration dump attempt.\n\n " <<
1266 __COUT_ERR__ <<
"\n" << ss.str();
1267 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
1274 makeSystemLogbookEntry(
"Run " + runNumber +
" starting.");
1276 broadcastMessage(theStateMachine_.getCurrentMessage());
1279 saveGroupNameAndKey(theConfigurationGroup_,FSM_LAST_STARTED_GROUP_ALIAS_FILE);
1283 void Supervisor::transitionStopping(toolbox::Event::Reference e)
1284 throw (toolbox::fsm::exception::Exception)
1286 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
1288 makeSystemLogbookEntry(
"Run stopping.");
1290 broadcastMessage(theStateMachine_.getCurrentMessage());
1298 bool Supervisor::broadcastMessage(xoap::MessageReference message)
1299 throw (toolbox::fsm::exception::Exception)
1301 std::string command = SOAPUtilities::translate(message).getCommand();
1302 bool proceed =
true;
1307 for(
auto& it: theSupervisorDescriptorInfo_.getFEDescriptors())
1309 RunControlStateMachine::theProgressBar_.step();
1310 __COUT__ <<
"Sending message to FESupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1311 __COUT__ <<
"Sending message to FESupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1312 __COUT__ <<
"Sending message to FESupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1313 __COUT__ <<
"Sending message to FESupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1314 __COUT__ <<
"Sending message to FESupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1318 reply = send(it.second, message);
1320 catch(
const xdaq::exception::Exception &e)
1323 __SS__ <<
"Can NOT " << command <<
" FESupervisors, instance = " << it.first <<
".\n\n" <<
1324 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
1325 __COUT_ERR__ << ss.str();
1326 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1330 if (reply != command +
"Done")
1334 __SS__ <<
"Can NOT " << command <<
" FESupervisor, instance = " << it.first <<
".\n\n" <<
1336 __COUT_ERR__ << ss.str() << std::endl;
1338 __COUT__ <<
"Getting error message..." << std::endl;
1339 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference(
"StateMachineErrorMessageRequest"));
1341 parameters.addParameter(
"ErrorMessage");
1342 SOAPMessenger::receive(errorMessage, parameters);
1343 __COUT_ERR__ <<
"errorMessage = " << parameters.getValue(
"ErrorMessage") << std::endl;
1344 ss <<
"\n\nError Message: " << parameters.getValue(
"ErrorMessage") << std::endl;
1345 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1351 __COUT__ <<
"FESupervisor supervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1355 for(
auto& it: theSupervisorDescriptorInfo_.getDTCDescriptors())
1357 RunControlStateMachine::theProgressBar_.step();
1358 __COUT__ <<
"Sending message to DTCSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1359 __COUT__ <<
"Sending message to DTCSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1360 __COUT__ <<
"Sending message to DTCSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1361 __COUT__ <<
"Sending message to DTCSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1362 __COUT__ <<
"Sending message to DTCSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1366 reply = send(it.second, message);
1368 catch(
const xdaq::exception::Exception &e)
1371 __SS__ <<
"Can NOT " << command <<
" DTCSupervisors, instance = " << it.first <<
".\n\n" <<
1372 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
1373 __COUT_ERR__ << ss.str();
1374 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1378 if (reply != command +
"Response")
1382 __SS__ <<
"Can NOT " << command <<
" DTCSupervisor, instance = " << it.first <<
".\n\n" <<
1384 __COUT_ERR__ << ss.str() << std::endl;
1389 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1395 __COUT__ <<
"DTCSupervisor supervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1400 for(
auto& it: theSupervisorDescriptorInfo_.getDataManagerDescriptors())
1402 RunControlStateMachine::theProgressBar_.step();
1403 __COUT__ <<
"Sending message to DataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1404 __COUT__ <<
"Sending message to DataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1405 __COUT__ <<
"Sending message to DataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1406 __COUT__ <<
"Sending message to DataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1407 __COUT__ <<
"Sending message to DataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1411 reply = send(it.second, message);
1413 catch(
const xdaq::exception::Exception &e)
1416 __SS__ <<
"Can NOT " << command <<
" DataManagerSupervisors, instance = " << it.first <<
".\n\n" <<
1417 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
1418 __COUT_ERR__ << ss.str();
1419 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1423 if (reply != command +
"Done")
1425 __SS__ <<
"Can NOT " << command <<
" DataManagerSupervisor, instance = " << it.first <<
".\n\n" <<
1427 __COUT_ERR__ << ss.str() << std::endl;
1428 __COUT__ <<
"Getting error message..." << std::endl;
1429 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference(
"StateMachineErrorMessageRequest"));
1431 parameters.addParameter(
"ErrorMessage");
1432 SOAPMessenger::receive(errorMessage, parameters);
1433 __COUT_ERR__ <<
"errorMessage = " << parameters.getValue(
"ErrorMessage") << std::endl;
1434 ss <<
"\n\nError Message: " << parameters.getValue(
"ErrorMessage") << std::endl;
1435 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1440 __COUT__ <<
"DataManagerSupervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1445 for (
auto& it: theSupervisorDescriptorInfo_.getFEDataManagerDescriptors())
1447 RunControlStateMachine::theProgressBar_.step();
1448 __COUT__ <<
"Sending message to FEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1449 __COUT__ <<
"Sending message to FEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1450 __COUT__ <<
"Sending message to FEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1451 __COUT__ <<
"Sending message to FEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1452 __COUT__ <<
"Sending message to FEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1456 reply = send(it.second, message);
1458 catch(
const xdaq::exception::Exception &e)
1461 __SS__ <<
"Can NOT " << command <<
" FEDataManagerSupervisors, instance = " << it.first <<
".\n\n" <<
1462 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
1463 __COUT_ERR__ << ss.str();
1464 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1468 if (reply != command +
"Done")
1470 __SS__ <<
"Can NOT " << command <<
" FEDataManagerSupervisor, instance = " << it.first <<
".\n\n" <<
1472 __COUT_ERR__ << ss.str() << std::endl;
1473 __COUT__ <<
"Getting error message..." << std::endl;
1474 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference(
"StateMachineErrorMessageRequest"));
1476 parameters.addParameter(
"ErrorMessage");
1477 SOAPMessenger::receive(errorMessage, parameters);
1478 __COUT_ERR__ <<
"errorMessage = " << parameters.getValue(
"ErrorMessage") << std::endl;
1479 ss <<
"\n\nError Message: " << parameters.getValue(
"ErrorMessage") << std::endl;
1480 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1485 __COUT__ <<
"FEDataManagerSupervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1490 for(
auto& it: theSupervisorDescriptorInfo_.getVisualDescriptors())
1492 RunControlStateMachine::theProgressBar_.step();
1493 __COUT__ <<
"Sending message to VisualSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1494 __COUT__ <<
"Sending message to VisualSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1495 __COUT__ <<
"Sending message to VisualSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1496 __COUT__ <<
"Sending message to VisualSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1497 __COUT__ <<
"Sending message to VisualSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1502 reply = send(it.second, message);
1504 catch(
const xdaq::exception::Exception &e)
1507 __SS__ <<
"Can NOT " << command <<
" VisualSupervisor, instance = " << it.first <<
".\n\n" <<
1508 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
1509 __COUT_ERR__ << ss.str();
1510 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1515 if (reply != command +
"Done")
1517 __SS__ <<
"Can NOT " << command <<
" VisualSupervisor, instance = " << it.first <<
".\n\n" <<
1519 __COUT_ERR__ << ss.str() << std::endl;
1520 __COUT__ <<
"Getting error message..." << std::endl;
1521 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference(
"StateMachineErrorMessageRequest"));
1523 parameters.addParameter(
"ErrorMessage");
1524 SOAPMessenger::receive(errorMessage, parameters);
1525 __COUT_ERR__ <<
"errorMessage = " << parameters.getValue(
"ErrorMessage") << std::endl;
1526 ss <<
"\n\nError Message: " << parameters.getValue(
"ErrorMessage") << std::endl;
1527 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1532 __COUT__ <<
"VisualSupervisor supervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1540 bool artdaqRestarted =
false;
1541 bool artdaqWasRestarted =
false;
1543 RunControlStateMachine::theProgressBar_.step();
1544 if(command ==
"Halt" || command ==
"Initialize")
1554 __COUT__ <<
"Extracting target context hostnames... " << std::endl;
1555 std::vector<std::string> hostnames;
1558 theConfigurationManager_->init();
1562 auto contexts = contextConfiguration->getContexts();
1564 for(
const auto& context: contexts)
1566 if(!context.status_)
continue;
1570 for(i=0;i<context.address_.size();++i)
1571 if(context.address_[i] ==
'/')
1573 hostnames.push_back(context.address_.substr(j));
1574 __COUT__ <<
"hostname = " << hostnames.back() << std::endl;
1579 __SS__ <<
"\nTransition to Configuring interrupted! " <<
1580 "The Configuration Manager could not be initialized." << std::endl;
1582 __COUT_ERR__ <<
"\n" << ss.str();
1584 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
1587 for(
const auto& hostname: hostnames)
1589 std::string fn = (std::string(getenv(
"SERVICE_DATA_PATH")) +
1590 "/StartOTS_action_" + hostname +
".cmd");
1591 FILE* fp = fopen(fn.c_str(),
"w");
1594 fprintf(fp,
"RESET_MPI");
1598 __COUT_ERR__ <<
"Unable to open command file: " << fn << std::endl;
1612 artdaqRestarted =
true;
1615 message = SOAPUtilities::makeSOAPMessageReference(
1616 "Initialize", parameters);
1617 command = SOAPUtilities::translate(message).getCommand();
1618 __COUT__ <<
"command now is " << command << std::endl;
1620 RunControlStateMachine::theProgressBar_.step();
1623 int MAX_ARTDAQ_RESTARTS = 10;
1624 int ARTDAQ_RESTART_DELAY = 2;
1625 int artdaqRestartCount = 0;
1626 bool preArtdaqProceed = proceed;
1629 if(artdaqWasRestarted)
1631 ++artdaqRestartCount;
1632 proceed = preArtdaqProceed;
1633 if(artdaqRestartCount < MAX_ARTDAQ_RESTARTS)
1634 artdaqWasRestarted =
false;
1635 for(
int i=0;i<ARTDAQ_RESTART_DELAY;++i)
1638 __COUT_INFO__ <<
"Waiting on artdaq reboot... " << i <<
" for " << artdaqRestartCount <<
"x" << std::endl;
1643 for(
auto& it: theSupervisorDescriptorInfo_.getARTDAQFEDataManagerDescriptors())
1645 RunControlStateMachine::theProgressBar_.step();
1646 __COUT__ <<
"Sending message to ARTDAQFEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1647 __COUT__ <<
"Sending message to ARTDAQFEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1648 __COUT__ <<
"Sending message to ARTDAQFEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1649 __COUT__ <<
"Sending message to ARTDAQFEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1650 __COUT__ <<
"Sending message to ARTDAQFEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1654 reply = send(it.second, message);
1655 if (reply != command +
"Done")
1657 __SS__ <<
"Can NOT " << command <<
" ARTDAQFEDataManagerSupervisor, instance = " << it.first <<
".\n\n" <<
1659 __COUT_ERR__ << ss.str() << std::endl;
1660 __COUT__ <<
"Getting error message..." << std::endl;
1661 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference(
"StateMachineErrorMessageRequest"));
1663 parameters.addParameter(
"ErrorMessage");
1664 SOAPMessenger::receive(errorMessage, parameters);
1665 __COUT_ERR__ <<
"errorMessage = " << parameters.getValue(
"ErrorMessage") << std::endl;
1666 ss <<
"\n\nError Message: " << parameters.getValue(
"ErrorMessage") << std::endl;
1667 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1672 __COUT__ <<
"ARTDAQFEDataManagerSupervisors supervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1675 catch(
const xdaq::exception::Exception &e)
1677 if(artdaqRestarted && !artdaqWasRestarted)
1679 artdaqWasRestarted =
true;
1685 __SS__ <<
"Can NOT " << command <<
" ARTDAQFEDataManagerSupervisor, instance = " << it.first <<
".\n\n" <<
1686 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
1687 __COUT_ERR__ << ss.str();
1688 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1692 catch(
const toolbox::fsm::exception::Exception &e)
1694 if(artdaqRestarted && !artdaqWasRestarted)
1696 artdaqWasRestarted =
true;
1712 for(
auto& it: theSupervisorDescriptorInfo_.getARTDAQDataManagerDescriptors())
1714 RunControlStateMachine::theProgressBar_.step();
1715 __COUT__ <<
"Sending message to ARTDAQDataManagerSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1716 __COUT__ <<
"Sending message to ARTDAQDataManagerSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1717 __COUT__ <<
"Sending message to ARTDAQDataManagerSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1718 __COUT__ <<
"Sending message to ARTDAQDataManagerSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1719 __COUT__ <<
"Sending message to ARTDAQDataManagerSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1722 reply = send(it.second, message);
1723 if (reply != command +
"Done")
1725 __SS__ <<
"Can NOT " << command <<
" ARTDAQDataManagerSupervisor, instance = " << it.first <<
".\n\n" <<
1727 __COUT_ERR__ << ss.str() << std::endl;
1728 __COUT__ <<
"Getting error message..." << std::endl;
1729 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference(
"StateMachineErrorMessageRequest"));
1731 parameters.addParameter(
"ErrorMessage");
1732 SOAPMessenger::receive(errorMessage, parameters);
1733 __COUT_ERR__ <<
"errorMessage = " << parameters.getValue(
"ErrorMessage") << std::endl;
1734 ss <<
"\n\nError Message: " << parameters.getValue(
"ErrorMessage") << std::endl;
1735 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1740 __COUT__ <<
"ARTDAQDataManagerSupervisor supervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1743 catch(
const xdaq::exception::Exception &e)
1745 if(artdaqRestarted && !artdaqWasRestarted)
1747 artdaqWasRestarted =
true;
1753 __SS__ <<
"Can NOT " << command <<
" ARTDAQDataManagerSupervisor, instance = " << it.first <<
".\n\n" <<
1754 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
1755 __COUT_ERR__ << ss.str();
1756 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1760 catch(
const toolbox::fsm::exception::Exception &e)
1762 if(artdaqRestarted && !artdaqWasRestarted)
1764 artdaqWasRestarted =
true;
1773 for(
auto& it: theSupervisorDescriptorInfo_.getARTDAQBuilderDescriptors())
1775 RunControlStateMachine::theProgressBar_.step();
1776 __COUT__ <<
"Sending message to ARTDAQBuilderSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1777 __COUT__ <<
"Sending message to ARTDAQBuilderSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1778 __COUT__ <<
"Sending message to ARTDAQBuilderSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1779 __COUT__ <<
"Sending message to ARTDAQBuilderSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1780 __COUT__ <<
"Sending message to ARTDAQBuilderSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1784 reply = send(it.second, message);
1785 if (reply != command +
"Done")
1787 __SS__ <<
"Can NOT " << command <<
" ARTDAQBuilderSupervisor, instance = " << it.first <<
".\n\n" <<
1789 __COUT_ERR__ << ss.str() << std::endl;
1790 __COUT__ <<
"Getting error message..." << std::endl;
1791 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference(
"StateMachineErrorMessageRequest"));
1793 parameters.addParameter(
"ErrorMessage");
1794 SOAPMessenger::receive(errorMessage, parameters);
1795 __COUT_ERR__ <<
"errorMessage = " << parameters.getValue(
"ErrorMessage") << std::endl;
1796 ss <<
"\n\nError Message: " << parameters.getValue(
"ErrorMessage") << std::endl;
1797 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1802 __COUT__ <<
"ARTDAQBuilderSupervisor supervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1805 catch(
const xdaq::exception::Exception &e)
1807 if(artdaqRestarted && !artdaqWasRestarted)
1809 artdaqWasRestarted =
true;
1815 __SS__ <<
"Can NOT " << command <<
" ARTDAQBuilderSupervisor, instance = " << it.first <<
".\n\n" <<
1816 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
1817 __COUT_ERR__ << ss.str();
1818 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1822 catch(
const toolbox::fsm::exception::Exception &e)
1824 if(artdaqRestarted && !artdaqWasRestarted)
1826 artdaqWasRestarted =
true;
1835 for(
auto& it: theSupervisorDescriptorInfo_.getARTDAQAggregatorDescriptors())
1837 RunControlStateMachine::theProgressBar_.step();
1838 __COUT__ <<
"Sending message to ARTDAQAggregatorSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1839 __COUT__ <<
"Sending message to ARTDAQAggregatorSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1840 __COUT__ <<
"Sending message to ARTDAQAggregatorSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1841 __COUT__ <<
"Sending message to ARTDAQAggregatorSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1842 __COUT__ <<
"Sending message to ARTDAQAggregatorSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1846 reply = send(it.second, message);
1847 if (reply != command +
"Done")
1849 __SS__ <<
"Can NOT " << command <<
" ARTDAQAggregatorSupervisor, instance = " << it.first <<
".\n\n" <<
1851 __COUT_ERR__ << ss.str() << std::endl;
1852 __COUT__ <<
"Getting error message..." << std::endl;
1853 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference(
"StateMachineErrorMessageRequest"));
1855 parameters.addParameter(
"ErrorMessage");
1856 SOAPMessenger::receive(errorMessage, parameters);
1857 __COUT_ERR__ <<
"errorMessage = " << parameters.getValue(
"ErrorMessage") << std::endl;
1858 ss <<
"\n\nError Message: " << parameters.getValue(
"ErrorMessage") << std::endl;
1859 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1864 __COUT__ <<
"ARTDAQAggregatorSupervisor supervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1867 catch(
const xdaq::exception::Exception &e)
1869 if(artdaqRestarted && !artdaqWasRestarted)
1871 artdaqWasRestarted =
true;
1877 __SS__ <<
"Can NOT " << command <<
" ARTDAQAggregatorSupervisor, instance = " << it.first <<
".\n\n" <<
1878 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
1879 __COUT_ERR__ << ss.str();
1880 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1884 catch(
const toolbox::fsm::exception::Exception &e)
1886 if(artdaqRestarted && !artdaqWasRestarted)
1888 artdaqWasRestarted =
true;
1900 void Supervisor::wait(
int milliseconds, std::string who)
const
1902 for (
int s = 1; s <= milliseconds; s++)
1907 __COUT__ << s <<
" msecs " << who << std::endl;
1916 void Supervisor::loginRequest(xgi::Input * in, xgi::Output * out)
1917 throw (xgi::exception::Exception)
1919 cgicc::Cgicc cgi(in);
1920 std::string Command = CgiDataUtilities::getData(cgi,
"RequestType");
1921 __COUT__ <<
"*** Login RequestType = " << Command << std::endl;
1930 std::vector<std::string> loggedOutUsernames;
1931 theWebUsers_.cleanupExpiredEntries(&loggedOutUsernames);
1932 for (
unsigned int i = 0; i < loggedOutUsernames.size(); ++i)
1933 makeSystemLogbookEntry(loggedOutUsernames[i] +
" login timed out.");
1935 if (Command ==
"sessionId")
1942 std::string uuid = CgiDataUtilities::postData(cgi,
"uuid");
1944 std::string sid = theWebUsers_.createNewLoginSession(uuid);
1946 __COUT__ <<
"uuid = " << uuid << std::endl;
1947 __COUT__ <<
"SessionId = " << sid.substr(0, 10) << std::endl;
1950 else if (Command ==
"checkCookie")
1954 std::string jumbledUser;
1955 std::string cookieCode;
1965 uuid = CgiDataUtilities::postData(cgi,
"uuid");
1966 jumbledUser = CgiDataUtilities::postData(cgi,
"ju");
1967 cookieCode = CgiDataUtilities::postData(cgi,
"cc");
1969 __COUT__ <<
"uuid = " << uuid << std::endl;
1970 __COUT__ <<
"Cookie Code = " << cookieCode.substr(0, 10) << std::endl;
1971 __COUT__ <<
"jumbledUser = " << jumbledUser.substr(0, 10) << std::endl;
1974 uid = theWebUsers_.isCookieCodeActiveForLogin(uuid, cookieCode,
1977 if (uid == theWebUsers_.NOT_FOUND_IN_DATABASE)
1979 __COUT__ <<
"cookieCode invalid" << std::endl;
1984 __COUT__ <<
"cookieCode is good." << std::endl;
1989 theWebUsers_.insertSettingsForUser(uid, &xmldoc);
1991 xmldoc.outputXmlDocument((std::ostringstream*) out);
1994 else if (Command ==
"login")
2005 std::string uuid = CgiDataUtilities::postData(cgi,
"uuid");
2006 std::string newAccountCode = CgiDataUtilities::postData(cgi,
"nac");
2007 std::string jumbledUser = CgiDataUtilities::postData(cgi,
"ju");
2008 std::string jumbledPw = CgiDataUtilities::postData(cgi,
"jp");
2010 __COUT__ <<
"jumbledUser = " << jumbledUser.substr(0, 10) << std::endl;
2011 __COUT__ <<
"jumbledPw = " << jumbledPw.substr(0, 10) << std::endl;
2012 __COUT__ <<
"uuid = " << uuid << std::endl;
2013 __COUT__ <<
"nac =-" << newAccountCode <<
"-" << std::endl;
2015 uint64_t uid = theWebUsers_.attemptActiveSession(uuid, jumbledUser,
2016 jumbledPw, newAccountCode);
2019 if (uid == theWebUsers_.NOT_FOUND_IN_DATABASE)
2021 __COUT__ <<
"cookieCode invalid" << std::endl;
2023 if (newAccountCode !=
"1")
2024 newAccountCode =
"0";
2027 __COUT__ <<
"new cookieCode = " << newAccountCode.substr(0, 10) << std::endl;
2031 theWebUsers_.insertSettingsForUser(uid, &xmldoc);
2035 if (uid != theWebUsers_.NOT_FOUND_IN_DATABASE)
2037 uint64_t asCnt = theWebUsers_.getActiveSessionCountForUser(uid) - 1;
2039 sprintf(asStr,
"%lu", asCnt);
2040 xmldoc.addTextElementToData(
"user_active_session_count", asStr);
2043 xmldoc.outputXmlDocument((std::ostringstream*) out);
2046 makeSystemLogbookEntry(
2047 theWebUsers_.getUsersUsername(uid) +
" logged in.");
2049 else if (Command ==
"cert")
2060 std::string uuid = CgiDataUtilities::postData(cgi,
"uuid");
2061 std::string jumbledEmail = cgicc::form_urldecode(CgiDataUtilities::getData(cgi,
"httpsUser"));
2062 std::string username =
"";
2063 std::string cookieCode =
"";
2065 __COUT__ <<
"CERTIFICATE LOGIN REUEST RECEVIED!!!" << std::endl;
2066 __COUT__ <<
"jumbledEmail = " << jumbledEmail << std::endl;
2067 __COUT__ <<
"uuid = " << uuid << std::endl;
2069 uint64_t uid = theWebUsers_.attemptActiveSessionWithCert(uuid, jumbledEmail,
2070 cookieCode, username);
2073 if (uid == theWebUsers_.NOT_FOUND_IN_DATABASE)
2075 __COUT__ <<
"cookieCode invalid" << std::endl;
2077 if (cookieCode !=
"1")
2081 __COUT__ <<
"new cookieCode = " << cookieCode.substr(0, 10) << std::endl;
2085 theWebUsers_.insertSettingsForUser(uid, &xmldoc);
2089 if (uid != theWebUsers_.NOT_FOUND_IN_DATABASE)
2091 uint64_t asCnt = theWebUsers_.getActiveSessionCountForUser(uid) - 1;
2093 sprintf(asStr,
"%lu", asCnt);
2094 xmldoc.addTextElementToData(
"user_active_session_count", asStr);
2097 xmldoc.outputXmlDocument((std::ostringstream*) out);
2100 makeSystemLogbookEntry(
2101 theWebUsers_.getUsersUsername(uid) +
" logged in.");
2103 else if (Command ==
"logout")
2105 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
2106 std::string logoutOthers = CgiDataUtilities::postData(cgi,
2109 __COUT__ <<
"Cookie Code = " << cookieCode.substr(0, 10) << std::endl;
2110 __COUT__ <<
"logoutOthers = " << logoutOthers << std::endl;
2113 if (theWebUsers_.cookieCodeLogout(cookieCode, logoutOthers ==
"1", &uid)
2114 != theWebUsers_.NOT_FOUND_IN_DATABASE)
2118 if (!theWebUsers_.isUserIdActive(uid))
2119 makeSystemLogbookEntry(
2120 theWebUsers_.getUsersUsername(uid) +
" logged out.");
2125 __COUT__ << __LINE__ <<
"\tInvalid Command" << std::endl;
2131 void Supervisor::tooltipRequest(xgi::Input * in, xgi::Output * out)
2132 throw (xgi::exception::Exception)
2134 cgicc::Cgicc cgi(in);
2136 std::string Command = CgiDataUtilities::getData(cgi,
"RequestType");
2137 __COUT__ <<
"Tooltip RequestType = " << Command << std::endl;
2143 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
2144 uint8_t userPermissions;
2147 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions,
2158 if(Command ==
"check")
2160 WebUsers::tooltipCheckForUsername(
2161 theWebUsers_.getUsersUsername(uid),
2163 CgiDataUtilities::getData(cgi,
"srcFile"),
2164 CgiDataUtilities::getData(cgi,
"srcFunc"),
2165 CgiDataUtilities::getData(cgi,
"srcId"));
2167 else if(Command ==
"setNeverShow")
2169 WebUsers::tooltipSetNeverShowForUsername(
2170 theWebUsers_.getUsersUsername(uid),
2172 CgiDataUtilities::getData(cgi,
"srcFile"),
2173 CgiDataUtilities::getData(cgi,
"srcFunc"),
2174 CgiDataUtilities::getData(cgi,
"srcId"),
2175 CgiDataUtilities::getData(cgi,
"doNeverShow") ==
"1"?
true:
false,
2176 CgiDataUtilities::getData(cgi,
"temporarySilence") ==
"1"?
true:
false);
2180 __COUT__ <<
"Command Request, " << Command <<
", not recognized." << std::endl;
2182 xmldoc.outputXmlDocument((std::ostringstream*) out,
false,
true);
2186 void Supervisor::request(xgi::Input * in, xgi::Output * out)
2187 throw (xgi::exception::Exception)
2190 if(VERBOSE_MUTEX) __COUT__ <<
"Waiting for FSM access" << std::endl;
2191 std::lock_guard<std::mutex> lock(stateMachineAccessMutex_);
2192 if(VERBOSE_MUTEX) __COUT__ <<
"Have FSM access" << std::endl;
2194 cgicc::Cgicc cgi(in);
2196 std::string Command = CgiDataUtilities::getData(cgi,
"RequestType");
2203 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
2204 uint8_t userPermissions;
2206 std::string userWithLock;
2207 bool refreshCookie = Command !=
"getSystemMessages" &&
2208 Command !=
"getCurrentState" &&
2209 Command !=
"gatewayLaunchOTS" &&
2210 Command !=
"gatewayLaunchWiz";
2212 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions,
2247 if (Command ==
"getSettings")
2249 std::string accounts = CgiDataUtilities::getData(cgi,
"accounts");
2251 __COUT__ <<
"Get Settings Request" << std::endl;
2252 __COUT__ <<
"accounts = " << accounts << std::endl;
2253 theWebUsers_.insertSettingsForUser(uid, &xmldoc, accounts ==
"1");
2255 else if (Command ==
"setSettings")
2257 std::string bgcolor = CgiDataUtilities::postData(cgi,
"bgcolor");
2258 std::string dbcolor = CgiDataUtilities::postData(cgi,
"dbcolor");
2259 std::string wincolor = CgiDataUtilities::postData(cgi,
"wincolor");
2260 std::string layout = CgiDataUtilities::postData(cgi,
"layout");
2261 std::string syslayout = CgiDataUtilities::postData(cgi,
"syslayout");
2263 __COUT__ <<
"Set Settings Request" << std::endl;
2264 __COUT__ <<
"bgcolor = " << bgcolor << std::endl;
2265 __COUT__ <<
"dbcolor = " << dbcolor << std::endl;
2266 __COUT__ <<
"wincolor = " << wincolor << std::endl;
2267 __COUT__ <<
"layout = " << layout << std::endl;
2268 __COUT__ <<
"syslayout = " << syslayout << std::endl;
2269 theWebUsers_.changeSettingsForUser(uid, bgcolor, dbcolor, wincolor,
2271 theWebUsers_.insertSettingsForUser(uid, &xmldoc,
true);
2273 else if (Command ==
"accountSettings")
2275 std::string type = CgiDataUtilities::postData(cgi,
"type");
2278 if (type ==
"updateAccount")
2280 else if (type ==
"createAccount")
2282 else if (type ==
"deleteAccount")
2285 std::string username = CgiDataUtilities::postData(cgi,
"username");
2286 std::string displayname = CgiDataUtilities::postData(cgi,
2288 std::string email = CgiDataUtilities::postData(cgi,
"useremail");
2289 std::string permissions = CgiDataUtilities::postData(cgi,
2291 std::string accounts = CgiDataUtilities::getData(cgi,
"accounts");
2293 __COUT__ <<
"accountSettings Request" << std::endl;
2294 __COUT__ <<
"type = " << type <<
" - " << type_int << std::endl;
2295 __COUT__ <<
"username = " << username << std::endl;
2296 __COUT__ <<
"useremail = " << email << std::endl;
2297 __COUT__ <<
"displayname = " << displayname << std::endl;
2298 __COUT__ <<
"permissions = " << permissions << std::endl;
2300 theWebUsers_.modifyAccountSettings(uid, type_int, username, displayname,email,
2303 __COUT__ <<
"accounts = " << accounts << std::endl;
2305 theWebUsers_.insertSettingsForUser(uid, &xmldoc, accounts ==
"1");
2307 else if(Command ==
"stateMatchinePreferences")
2309 std::string set = CgiDataUtilities::getData(cgi,
"set");
2310 const std::string DEFAULT_FSM_VIEW =
"Default_FSM_View";
2312 theWebUsers_.setGenericPreference(uid, DEFAULT_FSM_VIEW,
2313 CgiDataUtilities::getData(cgi, DEFAULT_FSM_VIEW));
2315 theWebUsers_.getGenericPreference(uid, DEFAULT_FSM_VIEW, &xmldoc);
2317 else if(Command ==
"getAliasList")
2319 std::string username = theWebUsers_.getUsersUsername(uid);
2320 std::string fsmName = CgiDataUtilities::getData(cgi,
"fsmName");
2321 __COUT__ <<
"fsmName = " << fsmName << std::endl;
2323 std::string stateMachineAliasFilter =
"*";
2325 std::map<std::string ,
2327 theConfigurationManager_->getGroupAliasesConfiguration();
2331 ConfigurationTree configLinkNode = theConfigurationManager_->getSupervisorConfigurationNode(
2332 supervisorContextUID_, supervisorApplicationUID_);
2334 if(!configLinkNode.isDisconnected())
2338 ConfigurationTree fsmLinkNode = configLinkNode.getNode(
"LinkToStateMachineConfiguration");
2339 if(!fsmLinkNode.isDisconnected())
2340 stateMachineAliasFilter =
2341 fsmLinkNode.getNode(fsmName +
"/SystemAliasFilter").getValue<std::string>();
2343 __COUT_INFO__ <<
"FSM Link disconnected." << std::endl;
2345 catch(std::runtime_error &e) { __COUT_INFO__ << e.what() << std::endl; }
2346 catch(...) { __COUT_ERR__ <<
"Unknown error. Should never happen." << std::endl; }
2349 __COUT_INFO__ <<
"FSM Link disconnected." << std::endl;
2351 __COUT__ <<
"stateMachineAliasFilter = " << stateMachineAliasFilter << std::endl;
2358 bool invertFilter = stateMachineAliasFilter.size() && stateMachineAliasFilter[0] ==
'!';
2359 std::vector<std::string> filterArr;
2362 if(invertFilter) ++i;
2365 while((f = stateMachineAliasFilter.find(
'*',i)) != std::string::npos)
2367 tmp = stateMachineAliasFilter.substr(i,f-i);
2369 filterArr.push_back(tmp);
2374 if(i <= stateMachineAliasFilter.size())
2376 tmp = stateMachineAliasFilter.substr(i);
2377 filterArr.push_back(tmp);
2385 for(
auto& aliasMapPair : aliasMap)
2391 if(filterArr.size() == 1)
2393 if(filterArr[0] !=
"" &&
2394 filterArr[0] !=
"*" &&
2395 aliasMapPair.first != filterArr[0])
2396 filterMatch =
false;
2401 for(f=0;f<filterArr.size();++f)
2403 if(!filterArr[f].size())
continue;
2407 if((i = aliasMapPair.first.find(filterArr[f])) != 0)
2409 filterMatch =
false;
2413 else if(f == filterArr.size()-1)
2415 if(aliasMapPair.first.rfind(filterArr[f]) !=
2416 aliasMapPair.first.size() - filterArr[f].size())
2418 filterMatch =
false;
2422 else if((i = aliasMapPair.first.find(filterArr[f])) ==
2425 filterMatch =
false;
2431 if(invertFilter) filterMatch = !filterMatch;
2435 if(!filterMatch)
continue;
2437 xmldoc.addTextElementToData(
"config_alias", aliasMapPair.first);
2438 xmldoc.addTextElementToData(
"config_key",
2439 ConfigurationGroupKey::getFullGroupString(aliasMapPair.second.first,
2440 aliasMapPair.second.second).c_str());
2442 std::string groupComment, groupAuthor, groupCreationTime;
2445 theConfigurationManager_->loadConfigurationGroup(
2446 aliasMapPair.second.first,aliasMapPair.second.second,
2448 &groupComment, &groupAuthor, &groupCreationTime,
false );
2450 xmldoc.addTextElementToData(
"config_comment", groupComment);
2451 xmldoc.addTextElementToData(
"config_author", groupAuthor);
2452 xmldoc.addTextElementToData(
"config_create_time", groupCreationTime);
2456 __COUT_WARN__ <<
"Failed to load group metadata." << std::endl;
2462 std::string fn = FSM_LAST_GROUP_ALIAS_PATH + FSM_LAST_GROUP_ALIAS_FILE_START +
2463 username +
"." + FSM_USERS_PREFERENCES_FILETYPE;
2464 __COUT__ <<
"Load preferences: " << fn << std::endl;
2465 FILE *fp = fopen(fn.c_str(),
"r");
2468 char tmpLastAlias[500];
2469 fscanf(fp,
"%*s %s",tmpLastAlias);
2470 __COUT__ <<
"tmpLastAlias: " << tmpLastAlias << std::endl;
2472 xmldoc.addTextElementToData(
"UserLastConfigAlias",tmpLastAlias);
2476 else if (Command ==
"getFecList")
2478 xmldoc.addTextElementToData(
"fec_list",
"");
2480 for (
unsigned int i = 0; i< theSupervisorDescriptorInfo_.getFEDescriptors().size(); ++i)
2482 xmldoc.addTextElementToParent(
"fec_url",
2483 theSupervisorDescriptorInfo_.getFEURL(i),
"fec_list");
2484 xmldoc.addTextElementToParent(
2486 theSupervisorDescriptorInfo_.getFEDescriptor(i)->getURN(),
2490 else if (Command ==
"getSystemMessages")
2492 xmldoc.addTextElementToData(
"systemMessages",
2493 theSysMessenger_.getSysMsg(
2494 theWebUsers_.getUsersDisplayName(uid)));
2496 xmldoc.addTextElementToData(
"username_with_lock",
2497 theWebUsers_.getUserWithLock());
2501 else if (Command ==
"setUserWithLock")
2503 std::string username = CgiDataUtilities::postData(cgi,
"username");
2504 std::string lock = CgiDataUtilities::postData(cgi,
"lock");
2505 std::string accounts = CgiDataUtilities::getData(cgi,
"accounts");
2507 __COUT__ << Command << std::endl;
2508 __COUT__ <<
"username " << username << std::endl;
2509 __COUT__ <<
"lock " << lock << std::endl;
2510 __COUT__ <<
"accounts " << accounts << std::endl;
2511 __COUT__ <<
"uid " << uid << std::endl;
2513 std::string tmpUserWithLock = theWebUsers_.getUserWithLock();
2514 if(!theWebUsers_.setUserWithLock(uid, lock ==
"1", username))
2515 xmldoc.addTextElementToData(
"server_alert",
2516 std::string(
"Set user lock action failed. You must have valid permissions and ") +
2517 "locking user must be currently logged in.");
2519 theWebUsers_.insertSettingsForUser(uid, &xmldoc, accounts ==
"1");
2521 if (tmpUserWithLock != theWebUsers_.getUserWithLock())
2522 theSysMessenger_.addSysMsg(
"*", theWebUsers_.getUserWithLock()
2523 ==
"" ? tmpUserWithLock +
" has unlocked ots."
2524 : theWebUsers_.getUserWithLock()
2525 +
" has locked ots.");
2527 else if (Command ==
"getStateMachine")
2530 std::vector<toolbox::fsm::State> states;
2531 states = theStateMachine_.getStates();
2534 std::string transName;
2535 std::string transParameter;
2538 for (
unsigned int i = 0; i < states.size(); ++i)
2540 stateStr[0] = states[i];
2541 DOMElement* stateParent = xmldoc.addTextElementToData(
"state", stateStr);
2543 xmldoc.addTextElementToParent(
"state_name", theStateMachine_.getStateName(states[i]), stateParent);
2548 std::map<std::string, toolbox::fsm::State, std::less<std::string> >
2549 trans = theStateMachine_.getTransitions(states[i]);
2550 std::set<std::string> actionNames = theStateMachine_.getInputs(states[i]);
2552 std::map<std::string, toolbox::fsm::State, std::less<std::string> >::iterator it =
2554 std::set<std::string>::iterator ait = actionNames.begin();
2562 for (; it != trans.end() && ait != actionNames.end(); ++it, ++ait)
2564 stateStr[0] = it->second;
2566 if(stateStr[0] ==
'R')
2569 xmldoc.addTextElementToParent(
"state_transition", stateStr, stateParent);
2573 xmldoc.addTextElementToParent(
"state_transition_action", *ait, stateParent);
2575 transName = theStateMachine_.getTransitionName(states[i], *ait);
2578 xmldoc.addTextElementToParent(
"state_transition_name",
2579 transName, stateParent);
2580 transParameter = theStateMachine_.getTransitionParameter(states[i], *ait);
2583 xmldoc.addTextElementToParent(
"state_transition_parameter", transParameter, stateParent);
2586 else if(stateStr[0] ==
'C')
2589 xmldoc.addTextElementToParent(
"state_transition", stateStr, stateParent);
2593 xmldoc.addTextElementToParent(
"state_transition_action", *ait, stateParent);
2595 transName = theStateMachine_.getTransitionName(states[i], *ait);
2598 xmldoc.addTextElementToParent(
"state_transition_name",
2599 transName, stateParent);
2600 transParameter = theStateMachine_.getTransitionParameter(states[i], *ait);
2603 xmldoc.addTextElementToParent(
"state_transition_parameter", transParameter, stateParent);
2610 ait = actionNames.begin();
2613 for (; it != trans.end() && ait != actionNames.end(); ++it, ++ait)
2617 stateStr[0] = it->second;
2619 if(stateStr[0] ==
'R')
2621 else if(stateStr[0] ==
'C')
2624 xmldoc.addTextElementToParent(
"state_transition", stateStr, stateParent);
2628 xmldoc.addTextElementToParent(
"state_transition_action", *ait, stateParent);
2630 transName = theStateMachine_.getTransitionName(states[i], *ait);
2633 xmldoc.addTextElementToParent(
"state_transition_name",
2634 transName, stateParent);
2635 transParameter = theStateMachine_.getTransitionParameter(states[i], *ait);
2638 xmldoc.addTextElementToParent(
"state_transition_parameter", transParameter, stateParent);
2643 else if (Command ==
"getStateMachineNames")
2646 ConfigurationTree configLinkNode = theConfigurationManager_->getSupervisorConfigurationNode(
2647 supervisorContextUID_, supervisorApplicationUID_);
2651 auto fsmNodes = configLinkNode.getNode(
2652 "LinkToStateMachineConfiguration").getChildren();
2653 for(
const auto& fsmNode:fsmNodes)
2654 xmldoc.addTextElementToData(
"stateMachineName", fsmNode.first);
2658 __COUT__ <<
"Caught exception, assuming no valid FSM names." << std::endl;
2659 xmldoc.addTextElementToData(
"stateMachineName",
"");
2662 else if (Command ==
"getIterationPlanStatus")
2665 theIterator_.handleCommandRequest(xmldoc,Command,
"");
2667 else if (Command ==
"getCurrentState")
2669 xmldoc.addTextElementToData(
"current_state", theStateMachine_.getCurrentStateName());
2670 xmldoc.addTextElementToData(
"in_transition", theStateMachine_.isInTransition() ?
"1" :
"0");
2671 if (theStateMachine_.isInTransition())
2672 xmldoc.addTextElementToData(
"transition_progress", theProgressBar_.readPercentageString());
2674 xmldoc.addTextElementToData(
"transition_progress",
"100");
2678 sprintf(tmp,
"%lu",theStateMachine_.getTimeInState());
2679 xmldoc.addTextElementToData(
"time_in_state", tmp);
2688 std::string fsmName = CgiDataUtilities::getData(cgi,
"fsmName");
2696 if(!theStateMachine_.isInTransition())
2698 std::string stateMachineRunAlias =
"Run";
2701 ConfigurationTree configLinkNode = theConfigurationManager_->getSupervisorConfigurationNode(
2702 supervisorContextUID_, supervisorApplicationUID_);
2704 if(!configLinkNode.isDisconnected())
2708 ConfigurationTree fsmLinkNode = configLinkNode.getNode(
"LinkToStateMachineConfiguration");
2709 if(!fsmLinkNode.isDisconnected())
2710 stateMachineRunAlias =
2711 fsmLinkNode.getNode(fsmName +
"/RunDisplayAlias").getValue<std::string>();
2715 catch(std::runtime_error &e)
2723 __COUT_ERR__ <<
"Unknown error. Should never happen." << std::endl;
2725 __COUT_INFO__ <<
"No state machine Run alias. Ignoring and assuming alias of '" <<
2726 stateMachineRunAlias <<
".'" << std::endl;
2734 xmldoc.addTextElementToData(
"stateMachineRunAlias", stateMachineRunAlias);
2740 if(theStateMachine_.getCurrentStateName() ==
"Running" ||
2741 theStateMachine_.getCurrentStateName() ==
"Paused")
2742 sprintf(tmp,
"Current %s Number: %u",stateMachineRunAlias.c_str(),getNextRunNumber(activeStateMachineName_)-1);
2744 sprintf(tmp,
"Next %s Number: %u",stateMachineRunAlias.c_str(),getNextRunNumber(fsmName));
2745 xmldoc.addTextElementToData(
"run_number", tmp);
2748 else if(Command ==
"getErrorInStateMatchine")
2750 xmldoc.addTextElementToData(
"FSM_Error", theStateMachine_.getErrorMessage());
2752 else if(Command ==
"getDesktopIcons")
2755 std::string iconFileName = ICON_FILE_NAME;
2756 std::ifstream iconFile;
2757 std::string iconList =
"";
2759 iconFile.open(iconFileName.c_str());
2763 __COUT__ <<
"Error opening file: "<< iconFileName << std::endl;
2767 if(iconFile.is_open())
2769 __COUT__ <<
"Getting Desktop Icons - opened file: " << iconFileName << std::endl;
2770 while(std::getline(iconFile, line))
2779 xmldoc.addTextElementToData(
"iconList", iconList);
2782 else if(Command ==
"gatewayLaunchOTS" || Command ==
"gatewayLaunchWiz")
2786 if(userPermissions != 255)
2788 __COUT__ <<
"Insufficient Permissions" << std::endl;
2792 __COUT_WARN__ << Command <<
" command received! " << std::endl;
2793 __MOUT_WARN__ << Command <<
" command received! " << std::endl;
2797 theWebUsers_.saveActiveSessions();
2800 __COUT_INFO__ <<
"Launching... " << std::endl;
2803 __COUT__ <<
"Extracting target context hostnames... " << std::endl;
2804 std::vector<std::string> hostnames;
2807 theConfigurationManager_->init();
2811 auto contexts = contextConfiguration->getContexts();
2813 for(
const auto& context: contexts)
2815 if(!context.status_)
continue;
2819 for(i=0;i<context.address_.size();++i)
2820 if(context.address_[i] ==
'/')
2822 hostnames.push_back(context.address_.substr(j));
2823 __COUT__ <<
"hostname = " << hostnames.back() << std::endl;
2828 __SS__ <<
"\nRelaunch of otsdaq interrupted! " <<
2829 "The Configuration Manager could not be initialized." << std::endl;
2831 __COUT_ERR__ <<
"\n" << ss.str();
2835 for(
const auto& hostname: hostnames)
2837 std::string fn = (std::string(getenv(
"SERVICE_DATA_PATH")) +
2838 "/StartOTS_action_" + hostname +
".cmd");
2839 FILE* fp = fopen(fn.c_str(),
"w");
2842 if(Command ==
"gatewayLaunchOTS")
2843 fprintf(fp,
"LAUNCH_OTS");
2844 else if(Command ==
"gatewayLaunchWiz")
2845 fprintf(fp,
"LAUNCH_WIZ");
2850 __COUT_ERR__ <<
"Unable to open command file: " << fn << std::endl;
2854 else if(Command ==
"resetUserTooltips")
2856 WebUsers::resetAllUserTooltips(theWebUsers_.getUsersUsername(uid));
2859 __COUT__ <<
"Command Request, " << Command <<
", not recognized." << std::endl;
2864 xmldoc.outputXmlDocument((std::ostringstream*) out,
false,
true);
2872 xoap::MessageReference Supervisor::supervisorGetUserInfo(
2873 xoap::MessageReference message)
2874 throw (xoap::exception::Exception)
2877 parameters.addParameter(
"CookieCode");
2878 receive(message, parameters);
2879 std::string cookieCode = parameters.getValue(
"CookieCode");
2881 std::string username, displayName;
2882 uint64_t activeSessionIndex;
2884 theWebUsers_.getUserInfoForCookie(cookieCode, &username, &displayName,
2885 &activeSessionIndex);
2892 retParameters.addParameter(
"Username", username);
2893 retParameters.addParameter(
"DisplayName", displayName);
2895 sprintf(tmpStr,
"%lu", activeSessionIndex);
2896 retParameters.addParameter(
"ActiveSessionIndex", tmpStr);
2898 return SOAPUtilities::makeSOAPMessageReference(
"UserInfoResponse",
2905 xoap::MessageReference Supervisor::supervisorCookieCheck(xoap::MessageReference message)
2906 throw (xoap::exception::Exception)
2912 parameters.addParameter(
"CookieCode");
2913 parameters.addParameter(
"RefreshOption");
2914 receive(message, parameters);
2915 std::string cookieCode = parameters.getValue(
"CookieCode");
2916 std::string refreshOption = parameters.getValue(
"RefreshOption");
2920 uint8_t userPermissions = 0;
2921 std::string userWithLock =
"";
2922 theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions, 0,
2923 "0", refreshOption ==
"1", &userWithLock);
2929 retParameters.addParameter(
"CookieCode", cookieCode);
2931 sprintf(tmp,
"%d", userPermissions);
2932 retParameters.addParameter(
"Permissions", tmp);
2933 retParameters.addParameter(
"UserWithLock", userWithLock);
2937 return SOAPUtilities::makeSOAPMessageReference(
"CookieResponse",
2944 xoap::MessageReference Supervisor::supervisorGetActiveUsers(
2945 xoap::MessageReference message)
2946 throw (xoap::exception::Exception)
2948 __COUT__ << std::endl;
2951 parameters(
"UserList", theWebUsers_.getActiveUsersString());
2952 return SOAPUtilities::makeSOAPMessageReference(
"ActiveUserResponse",
2960 xoap::MessageReference Supervisor::supervisorSystemMessage(
2961 xoap::MessageReference message)
2962 throw (xoap::exception::Exception)
2965 parameters.addParameter(
"ToUser");
2966 parameters.addParameter(
"Message");
2967 receive(message, parameters);
2969 __COUT__ <<
"toUser: " << parameters.getValue(
"ToUser").substr(
2970 0, 10) <<
", message: " << parameters.getValue(
"Message").substr(0,
2973 theSysMessenger_.addSysMsg(parameters.getValue(
"ToUser"),
2974 parameters.getValue(
"Message"));
2975 return SOAPUtilities::makeSOAPMessageReference(
"SystemMessageResponse");
2982 xoap::MessageReference Supervisor::supervisorSystemLogbookEntry(
2983 xoap::MessageReference message)
2984 throw (xoap::exception::Exception)
2987 parameters.addParameter(
"EntryText");
2988 receive(message, parameters);
2990 __COUT__ <<
"EntryText: " << parameters.getValue(
"EntryText").substr(
2991 0, 10) << std::endl;
2993 makeSystemLogbookEntry(parameters.getValue(
"EntryText"));
2995 return SOAPUtilities::makeSOAPMessageReference(
"SystemLogbookResponse");
3003 xoap::MessageReference Supervisor::supervisorLastConfigGroupRequest(
3004 xoap::MessageReference message)
3005 throw (xoap::exception::Exception)
3008 parameters.addParameter(
"ActionOfLastGroup");
3009 receive(message, parameters);
3011 return Supervisor::lastConfigGroupRequestHandler(parameters);
3020 xoap::MessageReference Supervisor::lastConfigGroupRequestHandler(
3023 std::string action = parameters.getValue(
"ActionOfLastGroup");
3024 __COUT__ <<
"ActionOfLastGroup: " << action.substr(
3025 0, 10) << std::endl;
3027 std::string fileName =
"";
3028 if(action ==
"Configured")
3029 fileName = FSM_LAST_CONFIGURED_GROUP_ALIAS_FILE;
3030 else if(action ==
"Started")
3031 fileName = FSM_LAST_STARTED_GROUP_ALIAS_FILE;
3034 __COUT_ERR__ <<
"Invalid last group action requested." << std::endl;
3035 return SOAPUtilities::makeSOAPMessageReference(
"LastConfigGroupResponseFailure");
3037 std::string timeString;
3039 loadGroupNameAndKey(fileName,timeString);
3043 retParameters.addParameter(
"GroupName", theGroup.first);
3044 retParameters.addParameter(
"GroupKey", theGroup.second.toString());
3045 retParameters.addParameter(
"GroupAction", action);
3046 retParameters.addParameter(
"GroupActionTime", timeString);
3049 return SOAPUtilities::makeSOAPMessageReference(
"LastConfigGroupResponse",
3060 unsigned int Supervisor::getNextRunNumber(
const std::string &fsmNameIn)
3062 std::string runNumberFileName = RUN_NUMBER_PATH +
"/";
3063 std::string fsmName = fsmNameIn ==
""?activeStateMachineName_:fsmNameIn;
3065 for(
unsigned int i=0;i<fsmName.size();++i)
3066 if( (fsmName[i] >=
'a' && fsmName[i] <=
'z') ||
3067 (fsmName[i] >=
'A' && fsmName[i] <=
'Z') ||
3068 (fsmName[i] >=
'0' && fsmName[i] <=
'9'))
3069 runNumberFileName += fsmName[i];
3070 runNumberFileName += RUN_NUMBER_FILE_NAME;
3073 std::ifstream runNumberFile(runNumberFileName.c_str());
3074 if (!runNumberFile.is_open())
3076 __COUT__ <<
"Can't open file: " << runNumberFileName << std::endl;
3078 __COUT__ <<
"Creating file and setting Run Number to 1: " << runNumberFileName << std::endl;
3079 FILE *fp = fopen(runNumberFileName.c_str(),
"w");
3083 runNumberFile.open(runNumberFileName.c_str());
3084 if(!runNumberFile.is_open())
3086 __SS__ <<
"Error. Can't create file: " << runNumberFileName << std::endl;
3087 __COUT_ERR__ << ss.str();
3088 throw std::runtime_error(ss.str());
3091 std::string runNumberString;
3092 runNumberFile >> runNumberString;
3093 runNumberFile.close();
3094 return atoi(runNumberString.c_str());
3098 bool Supervisor::setNextRunNumber(
unsigned int runNumber,
const std::string &fsmNameIn)
3100 std::string runNumberFileName = RUN_NUMBER_PATH +
"/";
3101 std::string fsmName = fsmNameIn ==
""?activeStateMachineName_:fsmNameIn;
3103 for(
unsigned int i=0;i<fsmName.size();++i)
3104 if( (fsmName[i] >=
'a' && fsmName[i] <=
'z') ||
3105 (fsmName[i] >=
'A' && fsmName[i] <=
'Z') ||
3106 (fsmName[i] >=
'0' && fsmName[i] <=
'9'))
3107 runNumberFileName += fsmName[i];
3108 runNumberFileName += RUN_NUMBER_FILE_NAME;
3109 __COUT__ <<
"runNumberFileName: " << runNumberFileName << std::endl;
3111 std::ofstream runNumberFile(runNumberFileName.c_str());
3112 if (!runNumberFile.is_open())
3114 __SS__ <<
"Can't open file: " << runNumberFileName << std::endl;
3115 __COUT__ << ss.str();
3116 throw std::runtime_error(ss.str());
3118 std::stringstream runNumberStream;
3119 runNumberStream << runNumber;
3120 runNumberFile << runNumberStream.str().c_str();
3121 runNumberFile.close();
3131 std::pair<std::string ,
3133 std::string &returnedTimeString)
3135 std::string fullPath = FSM_LAST_GROUP_ALIAS_PATH +
"/" + fileName;
3137 FILE *groupFile = fopen(fullPath.c_str(),
"r");
3140 __COUT__ <<
"Can't open file: " << fullPath << std::endl;
3142 __COUT__ <<
"Returning empty groupName and key -1" << std::endl;
3144 return std::pair<std::string ,
3150 std::pair<std::string ,
3153 fgets(line,500,groupFile);
3154 theGroup.first = line;
3156 fgets(line,500,groupFile);
3158 sscanf(line,
"%d",&key);
3159 theGroup.second = key;
3161 fgets(line,500,groupFile);
3163 sscanf(line,
"%ld",×tamp);
3165 ::localtime_r(×tamp, &tmstruct);
3166 ::strftime(line, 30,
"%c %Z", &tmstruct);
3167 returnedTimeString = line;
3171 __COUT__ <<
"theGroup.first= " << theGroup.first <<
3172 " theGroup.second= " << theGroup.second << std::endl;
3178 void Supervisor::saveGroupNameAndKey(
const std::pair<std::string ,
3180 const std::string &fileName)
3182 std::string fullPath = FSM_LAST_GROUP_ALIAS_PATH +
"/" + fileName;
3184 std::ofstream groupFile(fullPath.c_str());
3185 if (!groupFile.is_open())
3187 __SS__ <<
"Error. Can't open file: " << fullPath << std::endl;
3188 __COUT_ERR__ <<
"\n" << ss.str();
3189 throw std::runtime_error(ss.str());
3191 std::stringstream outss;
3192 outss << theGroup.first <<
"\n" << theGroup.second <<
"\n" << time(0);
3193 groupFile << outss.str().c_str();