1 #include "otsdaq-core/GatewaySupervisor/GatewaySupervisor.h"
2 #include "otsdaq-core/CgiDataUtilities/CgiDataUtilities.h"
3 #include "otsdaq-core/Macros/CoutMacros.h"
4 #include "otsdaq-core/MessageFacility/MessageFacility.h"
5 #include "otsdaq-core/SOAPUtilities/SOAPCommand.h"
6 #include "otsdaq-core/SOAPUtilities/SOAPUtilities.h"
7 #include "otsdaq-core/XmlUtilities/HttpXmlDocument.h"
9 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
10 #include "otsdaq-core/ConfigurationInterface/ConfigurationManagerRW.h"
11 #include "otsdaq-core/GatewaySupervisor/ARTDAQCommandable.h"
12 #include "otsdaq-core/TablePlugins/DesktopIconTable.h"
13 #include "otsdaq-core/TablePlugins/XDAQContextTable.h"
14 #include "otsdaq-core/WorkLoopManager/WorkLoopManager.h"
16 #include "otsdaq-core/NetworkUtilities/TransceiverSocket.h"
18 #include <cgicc/HTMLClasses.h>
19 #include <cgicc/HTMLDoctype.h>
20 #include <cgicc/HTTPCookie.h>
21 #include <cgicc/HTTPHeader.h>
22 #include <xgi/Utils.h>
24 #include <toolbox/fsm/FailedEvent.h>
25 #include <toolbox/task/WorkLoopFactory.h>
26 #include <xdaq/NamespaceURI.h>
27 #include <xoap/Method.h>
36 #define RUN_NUMBER_PATH std::string(__ENV__("SERVICE_DATA_PATH")) + "/RunNumber/"
37 #define RUN_NUMBER_FILE_NAME "NextRunNumber.txt"
38 #define FSM_LAST_GROUP_ALIAS_PATH \
39 std::string(__ENV__("SERVICE_DATA_PATH")) + "/RunControlData/"
40 #define FSM_LAST_GROUP_ALIAS_FILE_START std::string("FSMLastGroupAlias-")
41 #define FSM_USERS_PREFERENCES_FILETYPE "pref"
44 #define __MF_SUBJECT__ "GatewaySupervisor"
50 : xdaq::Application(s)
56 , theArtdaqCommandable_(this)
57 , stateMachineWorkLoopManager_(toolbox::task::bind(
58 this, &GatewaySupervisor::stateMachineThread, "StateMachine"))
59 , stateMachineSemaphore_(toolbox::BSem::FULL)
60 , infoRequestWorkLoopManager_(
61 toolbox::task::bind(this, &GatewaySupervisor::infoRequestThread, "InfoRequest"))
62 , infoRequestSemaphore_(toolbox::BSem::FULL)
63 , activeStateMachineName_("")
65 , broadcastCommandMessageIndex_(0)
66 , broadcastIterationBreakpoint_(
70 INIT_MF(
"GatewaySupervisor");
74 mkdir((std::string(__ENV__(
"SERVICE_DATA_PATH"))).c_str(), 0755);
75 mkdir((FSM_LAST_GROUP_ALIAS_PATH).c_str(), 0755);
76 mkdir((RUN_NUMBER_PATH).c_str(), 0755);
78 securityType_ = theWebUsers_.getSecurity();
80 __COUT__ <<
"Security: " << securityType_ << __E__;
82 xgi::bind(
this, &GatewaySupervisor::Default,
"Default");
83 xgi::bind(
this, &GatewaySupervisor::loginRequest,
"LoginRequest");
84 xgi::bind(
this, &GatewaySupervisor::request,
"Request");
85 xgi::bind(
this, &GatewaySupervisor::stateMachineXgiHandler,
"StateMachineXgiHandler");
87 &GatewaySupervisor::stateMachineIterationBreakpoint,
88 "StateMachineIterationBreakpoint");
90 xgi::bind(
this, &GatewaySupervisor::infoRequestHandler,
"InfoRequestHandler");
92 this, &GatewaySupervisor::infoRequestResultHandler,
"InfoRequestResultHandler");
93 xgi::bind(
this, &GatewaySupervisor::tooltipRequest,
"TooltipRequest");
96 &GatewaySupervisor::supervisorCookieCheck,
97 "SupervisorCookieCheck",
100 &GatewaySupervisor::supervisorGetActiveUsers,
101 "SupervisorGetActiveUsers",
104 &GatewaySupervisor::supervisorSystemMessage,
105 "SupervisorSystemMessage",
110 &GatewaySupervisor::supervisorSystemLogbookEntry,
111 "SupervisorSystemLogbookEntry",
114 &GatewaySupervisor::supervisorLastConfigGroupRequest,
115 "SupervisorLastConfigGroupRequest",
130 GatewaySupervisor::~GatewaySupervisor(
void)
132 delete CorePropertySupervisorBase::theConfigurationManager_;
133 makeSystemLogbookEntry(
"ots halted.");
139 CorePropertySupervisorBase::indicateOtsAlive(properties);
143 void GatewaySupervisor::init(
void)
145 supervisorGuiHasBeenLoaded_ =
false;
176 bool enableStateChanges =
false;
179 enableStateChanges = CorePropertySupervisorBase::getSupervisorTableNode()
180 .getNode(
"EnableStateChangesOverUDP")
190 auto artdaqStateChangeEnabled =
191 CorePropertySupervisorBase::getSupervisorTableNode()
192 .getNode(
"EnableARTDAQCommanderPlugin")
194 if(artdaqStateChangeEnabled)
196 auto artdaqStateChangePort =
197 CorePropertySupervisorBase::getSupervisorTableNode()
198 .getNode(
"ARTDAQCommanderID")
200 auto artdaqStateChangePluginType =
201 CorePropertySupervisorBase::getSupervisorTableNode()
202 .getNode(
"ARTDAQCommanderType")
203 .getValue<std::string>();
204 theArtdaqCommandable_.init(artdaqStateChangePort,
205 artdaqStateChangePluginType);
213 if(enableStateChanges)
215 __COUT__ <<
"Enabling state changes over UDP..." << __E__;
218 [](GatewaySupervisor* s) { GatewaySupervisor::StateChangerWorkLoop(s); },
223 __COUT__ <<
"State changes over UDP are disabled." << __E__;
230 void GatewaySupervisor::StateChangerWorkLoop(GatewaySupervisor* theSupervisor)
233 theSupervisor->CorePropertySupervisorBase::getSupervisorTableNode();
235 std::string ipAddressForStateChangesOverUDP =
236 configLinkNode.getNode(
"IPAddressForStateChangesOverUDP").getValue<std::string>();
237 int portForStateChangesOverUDP =
238 configLinkNode.getNode(
"PortForStateChangesOverUDP").getValue<
int>();
239 bool acknowledgementEnabled =
240 configLinkNode.getNode(
"EnableAckForStateChangesOverUDP").getValue<
bool>();
249 portForStateChangesOverUDP);
257 __SS__ <<
"FATAL Console error. Could not initialize socket at ip '"
258 << ipAddressForStateChangesOverUDP <<
"' and port "
259 << portForStateChangesOverUDP
260 <<
". Perhaps it is already in use? Exiting State Changer "
261 "SOAPUtilities::receive loop."
263 __COUT__ << ss.str();
268 std::size_t commaPosition;
269 unsigned int commaCounter = 0;
270 std::size_t begin = 0;
272 std::string errorStr;
275 std::vector<std::string> parameters;
285 buffer, 0 , 1 ,
false ) !=
288 __COUT__ <<
"UDP State Changer packet received of size = " << buffer.size()
291 size_t nCommas = std::count(buffer.begin(), buffer.end(),
',');
294 __SS__ <<
"Unrecognized State Machine command :-" << buffer
295 <<
"-. Format is FiniteStateMachineName,Command,Parameter(s). "
296 "Where Parameter(s) is/are optional."
298 __COUT_INFO__ << ss.str();
299 __MOUT_INFO__ << ss.str();
304 while((commaPosition = buffer.find(
',', begin)) != std::string::npos ||
305 commaCounter == nCommas)
307 if(commaCounter == nCommas)
308 commaPosition = buffer.size();
309 if(commaCounter == 0)
310 fsmName = buffer.substr(begin, commaPosition - begin);
311 else if(commaCounter == 1)
312 command = buffer.substr(begin, commaPosition - begin);
314 parameters.push_back(buffer.substr(begin, commaPosition - begin));
315 __COUT__ <<
"Word: " << buffer.substr(begin, commaPosition - begin)
318 begin = commaPosition + 1;
328 if(theSupervisor->VERBOSE_MUTEX)
329 __COUT__ <<
"Waiting for FSM access" << __E__;
330 std::lock_guard<std::mutex> lock(theSupervisor->stateMachineAccessMutex_);
331 if(theSupervisor->VERBOSE_MUTEX)
332 __COUT__ <<
"Have FSM access" << __E__;
334 errorStr = theSupervisor->attemptStateMachineTransition(
339 WebUsers::DEFAULT_STATECHANGER_USERNAME ,
340 WebUsers::DEFAULT_STATECHANGER_USERNAME,
346 __SS__ <<
"UDP State Changer failed to execute command because of the "
349 __COUT_ERR__ << ss.str();
350 __MOUT_ERR__ << ss.str();
351 if(acknowledgementEnabled)
352 sock.acknowledge(errorStr,
true );
356 __SS__ <<
"Successfully executed state change command '" << command
358 __COUT_INFO__ << ss.str();
359 __MOUT_INFO__ << ss.str();
360 if(acknowledgementEnabled)
361 sock.acknowledge(
"Done",
true );
375 void GatewaySupervisor::makeSystemLogbookEntry(std::string entryText)
377 __COUT__ <<
"Making System Logbook Entry: " << entryText << __E__;
379 SupervisorInfoMap logbookInfoMap =
380 allSupervisorInfo_.getAllLogbookTypeSupervisorInfo();
382 if(logbookInfoMap.size() == 0)
384 __COUT__ <<
"No logbooks found! Here is entry: " << entryText << __E__;
385 __MOUT__ <<
"No logbooks found! Here is entry: " << entryText << __E__;
390 __COUT__ <<
"Making logbook entry: " << entryText << __E__;
391 __MOUT__ <<
"Making logbook entry: " << entryText << __E__;
396 std::string replace[] = {
"\"",
"'",
"&",
"<",
">",
"\n",
" "};
397 std::string with[] = {
"%22",
"%27",
"%26",
"%3C",
"%3E",
"%0A%0D",
"%20%20"};
402 for(
int i = 0; i < numOfKeys; ++i)
404 while((f = entryText.find(replace[i])) != std::string::npos)
406 entryText = entryText.substr(0, f) + with[i] +
407 entryText.substr(f + replace[i].length());
418 for(
auto& logbookInfo : logbookInfoMap)
420 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
421 logbookInfo.second.getDescriptor(),
"MakeSystemLogbookEntry", parameters);
426 SOAPUtilities::receive(retMsg, retParameters);
428 __COUT__ <<
"Returned Status: " << retParameters.getValue(
"Status")
434 void GatewaySupervisor::Default(xgi::Input* in, xgi::Output* out)
438 if(!supervisorGuiHasBeenLoaded_ &&
439 (supervisorGuiHasBeenLoaded_ =
441 makeSystemLogbookEntry(
"ots started.");
443 *out <<
"<!DOCTYPE HTML><html lang='en'><head><title>ots</title>" <<
446 "<link rel='apple-touch-icon' sizes='57x57' href='/WebPath/images/otsdaqIcons/apple-icon-57x57.png'>\
447 <link rel='apple-touch-icon' sizes='60x60' href='/WebPath/images/otsdaqIcons/apple-icon-60x60.png'>\
448 <link rel='apple-touch-icon' sizes='72x72' href='/WebPath/images/otsdaqIcons/apple-icon-72x72.png'>\
449 <link rel='apple-touch-icon' sizes='76x76' href='/WebPath/images/otsdaqIcons/apple-icon-76x76.png'>\
450 <link rel='apple-touch-icon' sizes='114x114' href='/WebPath/images/otsdaqIcons/apple-icon-114x114.png'>\
451 <link rel='apple-touch-icon' sizes='120x120' href='/WebPath/images/otsdaqIcons/apple-icon-120x120.png'>\
452 <link rel='apple-touch-icon' sizes='144x144' href='/WebPath/images/otsdaqIcons/apple-icon-144x144.png'>\
453 <link rel='apple-touch-icon' sizes='152x152' href='/WebPath/images/otsdaqIcons/apple-icon-152x152.png'>\
454 <link rel='apple-touch-icon' sizes='180x180' href='/WebPath/images/otsdaqIcons/apple-icon-180x180.png'>\
455 <link rel='icon' type='image/png' sizes='192x192' href='/WebPath/images/otsdaqIcons/android-icon-192x192.png'>\
456 <link rel='icon' type='image/png' sizes='32x32' href='/WebPath/images/otsdaqIcons/favicon-32x32.png'>\
457 <link rel='icon' type='image/png' sizes='96x96' href='/WebPath/images/otsdaqIcons/favicon-96x96.png'>\
458 <link rel='icon' type='image/png' sizes='16x16' href='/WebPath/images/otsdaqIcons/favicon-16x16.png'>\
459 <link rel='manifest' href='/WebPath/images/otsdaqIcons/manifest.json'>\
460 <meta name='msapplication-TileColor' content='#ffffff'>\
461 <meta name='msapplication-TileImage' content='/ms-icon-144x144.png'>\
462 <meta name='theme-color' content='#ffffff'>"
466 <<
"<frameset col='100%' row='100%'>"
467 <<
"<frame src='/WebPath/html/Desktop.html?urn="
468 << this->getApplicationDescriptor()->getLocalId()
469 <<
"&securityType=" << securityType_ <<
"'></frameset></html>";
476 void GatewaySupervisor::stateMachineIterationBreakpoint(xgi::Input* in,
477 xgi::Output* out)
try
479 cgicc::Cgicc cgiIn(in);
481 std::string requestType = CgiDataUtilities::getData(cgiIn,
"Request");
485 CgiDataUtilities::postData(cgiIn,
"CookieCode"));
487 CorePropertySupervisorBase::getRequestUserInfo(userInfo);
489 if(!theWebUsers_.xmlRequestOnGateway(cgiIn, out, &xmlOut, userInfo))
492 __COUTV__(requestType);
496 if(requestType ==
"get")
500 std::lock_guard<std::mutex> lock(broadcastIterationBreakpointMutex_);
501 v << broadcastIterationBreakpoint_;
504 xmlOut.addTextElementToData(
"iterationBreakpoint", v.str());
506 else if(requestType ==
"set")
508 unsigned int breakpointSetValue =
509 CgiDataUtilities::getDataAsInt(cgiIn,
"breakpointSetValue");
510 __COUTV__(breakpointSetValue);
513 std::lock_guard<std::mutex> lock(broadcastIterationBreakpointMutex_);
514 broadcastIterationBreakpoint_ = breakpointSetValue;
519 v << breakpointSetValue;
520 xmlOut.addTextElementToData(
"iterationBreakpoint", v.str());
524 __SS__ <<
"Unknown iteration breakpoint request type = " << requestType
529 catch(
const std::runtime_error& e)
531 __SS__ <<
"Error caught handling iteration breakpoint command: " << e.what()
533 __COUT_ERR__ << ss.str();
534 xmlOut.addTextElementToData(
"Error", ss.str());
538 __SS__ <<
"Unknown error caught handling iteration breakpoint command." << __E__;
539 __COUT_ERR__ << ss.str();
540 xmlOut.addTextElementToData(
"Error", ss.str());
543 xmlOut.outputXmlDocument((std::ostringstream*)out,
false,
true);
546 catch(
const std::runtime_error& e)
548 __SS__ <<
"Error caught handling iteration breakpoint command: " << e.what() << __E__;
549 __COUT_ERR__ << ss.str();
553 __SS__ <<
"Unknown error caught handling iteration breakpoint command." << __E__;
554 __COUT_ERR__ << ss.str();
558 void GatewaySupervisor::stateMachineXgiHandler(xgi::Input* in, xgi::Output* out)
564 __COUT__ <<
"Waiting for FSM access" << __E__;
565 std::lock_guard<std::mutex> lock(stateMachineAccessMutex_);
567 __COUT__ <<
"Have FSM access" << __E__;
569 cgicc::Cgicc cgiIn(in);
571 std::string command = CgiDataUtilities::getData(cgiIn,
"StateMachine");
572 std::string requestType =
573 "StateMachine" + command;
577 CgiDataUtilities::postData(cgiIn,
"CookieCode"));
579 CorePropertySupervisorBase::getRequestUserInfo(userInfo);
581 if(!theWebUsers_.xmlRequestOnGateway(cgiIn, out, &xmlOut, userInfo))
584 std::string fsmName = CgiDataUtilities::getData(cgiIn,
"fsmName");
585 std::string fsmWindowName = CgiDataUtilities::getData(cgiIn,
"fsmWindowName");
586 fsmWindowName = CgiDataUtilities::decodeURIComponent(fsmWindowName);
587 std::string currentState = theStateMachine_.getCurrentStateName();
589 __COUT__ <<
"Check for Handled by theIterator_" << __E__;
592 if((activeStateMachineWindowName_ ==
"" ||
593 activeStateMachineWindowName_ ==
"iterator") &&
594 theIterator_.handleCommandRequest(xmlOut, command, fsmWindowName))
596 __COUT__ <<
"Handled by theIterator_" << __E__;
597 xmlOut.outputXmlDocument((std::ostringstream*)out,
false);
602 if(theStateMachine_.isInTransition())
604 __SS__ <<
"Error - Can not accept request because the State Machine is already "
607 __COUT_ERR__ <<
"\n" << ss.str();
609 xmlOut.addTextElementToData(
"state_tranisition_attempted",
611 xmlOut.addTextElementToData(
612 "state_tranisition_attempted_err",
614 xmlOut.outputXmlDocument((std::ostringstream*)out,
false,
true);
624 if(activeStateMachineName_ !=
"" && activeStateMachineName_ != fsmName)
626 __COUT__ <<
"currentState = " << currentState << __E__;
627 if(currentState !=
"Halted" && currentState !=
"Initial")
631 __SS__ <<
"Error - Can not accept request because the State Machine "
632 <<
"with window name '" << activeStateMachineWindowName_
633 <<
"' (UID: " << activeStateMachineName_
636 <<
"in control of State Machine progress. ";
637 ss <<
"\n\nIn order for this State Machine with window name '"
638 << fsmWindowName <<
"' (UID: " << fsmName
640 "to control progress, please transition to Halted using the active "
641 <<
"State Machine '" << activeStateMachineWindowName_ <<
".'" << __E__;
642 __COUT_ERR__ <<
"\n" << ss.str();
644 xmlOut.addTextElementToData(
"state_tranisition_attempted",
646 xmlOut.addTextElementToData(
647 "state_tranisition_attempted_err",
649 xmlOut.outputXmlDocument((std::ostringstream*)out,
false,
true);
654 activeStateMachineName_ =
"";
655 activeStateMachineWindowName_ =
"";
661 std::vector<std::string> parameters;
663 if(command ==
"Configure")
664 parameters.push_back(CgiDataUtilities::postData(cgiIn,
"ConfigurationAlias"));
666 attemptStateMachineTransition(
667 &xmlOut, out, command, fsmName, fsmWindowName, userInfo.username_, parameters);
672 std::string GatewaySupervisor::attemptStateMachineTransition(
674 std::ostringstream* out,
675 const std::string& command,
676 const std::string& fsmName,
677 const std::string& fsmWindowName,
678 const std::string& username,
679 const std::vector<std::string>& commandParameters)
681 std::string errorStr =
"";
683 std::string currentState = theStateMachine_.getCurrentStateName();
684 __COUT__ <<
"State Machine command = " << command << __E__;
685 __COUT__ <<
"fsmName = " << fsmName << __E__;
686 __COUT__ <<
"fsmWindowName = " << fsmWindowName << __E__;
687 __COUT__ <<
"activeStateMachineName_ = " << activeStateMachineName_ << __E__;
688 __COUT__ <<
"command = " << command << __E__;
689 __COUT__ <<
"commandParameters.size = " << commandParameters.size() << __E__;
692 if(command ==
"Configure")
694 if(currentState !=
"Halted")
696 __SS__ <<
"Error - Can only transition to Configured if the current "
697 <<
"state is Halted. Perhaps your state machine is out of sync."
699 __COUT_ERR__ <<
"\n" << ss.str();
703 xmldoc->addTextElementToData(
704 "state_tranisition_attempted",
707 xmldoc->addTextElementToData(
708 "state_tranisition_attempted_err",
711 xmldoc->outputXmlDocument((std::ostringstream*)out,
720 if(commandParameters.size() == 0)
722 __SS__ <<
"Error - Can only transition to Configured if a Configuration "
723 "Alias parameter is provided."
725 __COUT_ERR__ <<
"\n" << ss.str();
729 xmldoc->addTextElementToData(
730 "state_tranisition_attempted",
733 xmldoc->addTextElementToData(
734 "state_tranisition_attempted_err",
737 xmldoc->outputXmlDocument((std::ostringstream*)out,
744 parameters.addParameter(
"ConfigurationAlias", commandParameters[0]);
746 std::string configurationAlias = parameters.getValue(
"ConfigurationAlias");
747 __COUT__ <<
"Configure --> Name: ConfigurationAlias Value: " << configurationAlias
751 std::string fn = FSM_LAST_GROUP_ALIAS_PATH + FSM_LAST_GROUP_ALIAS_FILE_START +
752 username +
"." + FSM_USERS_PREFERENCES_FILETYPE;
754 __COUT__ <<
"Save FSM preferences: " << fn << __E__;
755 FILE* fp = fopen(fn.c_str(),
"w");
758 __SS__ << (
"Could not open file: " + fn) << __E__;
759 __COUT_ERR__ << ss.str();
762 fprintf(fp,
"FSM_last_configuration_alias %s", configurationAlias.c_str());
765 activeStateMachineName_ = fsmName;
766 activeStateMachineWindowName_ = fsmWindowName;
768 else if(command ==
"Start")
770 if(currentState !=
"Configured")
773 <<
"Error - Can only transition to Configured if the current "
774 <<
"state is Halted. Perhaps your state machine is out of sync. "
775 <<
"(Likely the server was restarted or another user changed the state)"
777 __COUT_ERR__ <<
"\n" << ss.str();
781 xmldoc->addTextElementToData(
782 "state_tranisition_attempted",
785 xmldoc->addTextElementToData(
786 "state_tranisition_attempted_err",
789 xmldoc->outputXmlDocument((std::ostringstream*)out,
795 unsigned int runNumber;
796 if(commandParameters.size() == 0)
798 runNumber = getNextRunNumber();
799 setNextRunNumber(runNumber + 1);
803 runNumber = std::atoi(commandParameters[0].c_str());
805 parameters.addParameter(
"RunNumber", runNumber);
808 xoap::MessageReference message =
809 SOAPUtilities::makeSOAPMessageReference(command, parameters);
811 xoap::MessageReference reply = stateMachineXoapHandler(message);
816 xmldoc->addTextElementToData(
"state_tranisition_attempted",
819 xmldoc->outputXmlDocument((std::ostringstream*)out,
false);
820 __COUT__ <<
"FSM state transition launched!" << __E__;
822 stateMachineLastCommandInput_ = command;
879 xoap::MessageReference GatewaySupervisor::stateMachineXoapHandler(
880 xoap::MessageReference message)
883 __COUT__ <<
"Soap Handler!" << __E__;
884 stateMachineWorkLoopManager_.removeProcessedRequests();
885 stateMachineWorkLoopManager_.processRequest(message);
886 __COUT__ <<
"Done - Soap Handler!" << __E__;
908 bool GatewaySupervisor::stateMachineThread(toolbox::task::WorkLoop* workLoop)
910 stateMachineSemaphore_.take();
911 std::string command =
912 SOAPUtilities::translate(stateMachineWorkLoopManager_.getMessage(workLoop))
915 __COUT__ <<
"Propagating command '" << command <<
"'..." << __E__;
917 std::string reply = send(allSupervisorInfo_.getGatewayDescriptor(),
918 stateMachineWorkLoopManager_.getMessage(workLoop));
919 stateMachineWorkLoopManager_.report(workLoop, reply, 100,
true);
921 __COUT__ <<
"Done with command '" << command <<
".' Reply = " << reply << __E__;
922 stateMachineSemaphore_.give();
926 __SS__ <<
"Failure to send Workloop transition command '" << command
927 <<
"!' An error response '" << reply <<
"' was received." << __E__;
928 __COUT_ERR__ << ss.str();
929 __MOUT_ERR__ << ss.str();
942 void GatewaySupervisor::infoRequestHandler(xgi::Input* in, xgi::Output* out)
945 __COUT__ <<
"Starting to Request!" << __E__;
947 cgicc::Cgicc cgiIn(in);
948 std::string requestType =
949 "infoRequestHandler";
953 CgiDataUtilities::postData(cgiIn,
"CookieCode"));
955 CorePropertySupervisorBase::getRequestUserInfo(userInfo);
957 if(!theWebUsers_.xmlRequestOnGateway(cgiIn, out, &xmlOut, userInfo))
965 HttpXmlDocument tmpDoc = infoRequestWorkLoopManager_.processRequest(cgiIn);
967 xmlOut.copyDataChildren(tmpDoc);
969 xmlOut.outputXmlDocument((std::ostringstream*)out,
false);
973 void GatewaySupervisor::infoRequestResultHandler(xgi::Input* in, xgi::Output* out)
976 __COUT__ <<
"Starting ask!" << __E__;
977 cgicc::Cgicc cgi(in);
979 cgicc::Cgicc cgiIn(in);
980 std::string requestType =
981 "infoRequestResultHandler";
985 CgiDataUtilities::postData(cgiIn,
"CookieCode"));
987 CorePropertySupervisorBase::getRequestUserInfo(userInfo);
989 if(!theWebUsers_.xmlRequestOnGateway(cgiIn, out, &xmlOut, userInfo))
1007 infoRequestWorkLoopManager_.getRequestResult(cgiIn, xmlOut);
1010 xmlOut.outputXmlDocument((std::ostringstream*)out,
false);
1012 __COUT__ <<
"Done asking!" << __E__;
1016 bool GatewaySupervisor::infoRequestThread(toolbox::task::WorkLoop* workLoop)
1021 infoRequestSemaphore_.take();
1023 vectorTest_.clear();
1025 for(
unsigned long long i = 0; i < 100000000; i++)
1028 vectorTest_.push_back(counterTest_);
1031 infoRequestWorkLoopManager_.report(
1032 workLoop,
"RESULT: This is the best result ever", 50,
false);
1033 std::string workLoopName = workLoop->getName();
1034 __COUT__ << workLoopName <<
" test: " << counterTest_
1035 <<
" vector size: " << vectorTest_.size() << __E__;
1036 wait(400,
"InfoRequestThread ----- locked");
1037 infoRequestSemaphore_.give();
1039 wait(200,
"InfoRequestThread");
1041 infoRequestSemaphore_.take();
1043 vectorTest_.clear();
1045 for(
unsigned long long i = 0; i < 100000000; i++)
1048 vectorTest_.push_back(counterTest_);
1051 wait(400,
"InfoRequestThread ----- locked");
1052 __COUT__ << workLoopName <<
" test: " << counterTest_
1053 <<
" vector size: " << vectorTest_.size() << __E__;
1054 infoRequestSemaphore_.give();
1058 infoRequestWorkLoopManager_.report(
1059 workLoop, theStateMachine_.getCurrentStateName(), 100,
true);
1068 void GatewaySupervisor::stateInitial(toolbox::fsm::FiniteStateMachine& fsm)
1071 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << __E__;
1079 void GatewaySupervisor::statePaused(toolbox::fsm::FiniteStateMachine& fsm)
1082 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << __E__;
1101 void GatewaySupervisor::stateRunning(toolbox::fsm::FiniteStateMachine& fsm)
1104 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << __E__;
1123 void GatewaySupervisor::stateHalted(toolbox::fsm::FiniteStateMachine& fsm)
1126 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << __E__;
1127 __COUT__ <<
"Fsm is in transition? "
1128 << (theStateMachine_.isInTransition() ?
"yes" :
"no") << __E__;
1157 void GatewaySupervisor::stateConfigured(toolbox::fsm::FiniteStateMachine& fsm)
1231 void GatewaySupervisor::inError(toolbox::fsm::FiniteStateMachine& fsm)
1235 <<
"Fsm current state: "
1244 void GatewaySupervisor::enteringError(toolbox::Event::Reference e)
1246 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << __E__;
1249 toolbox::fsm::FailedEvent& failedEvent =
dynamic_cast<toolbox::fsm::FailedEvent&
>(*e);
1254 if(RunControlStateMachine::asyncFailureReceived_)
1256 ss <<
"\nAn asynchronous failure was encountered."
1257 <<
".\n\nException:\n"
1258 << failedEvent.getException().what() << __E__;
1259 RunControlStateMachine::asyncFailureReceived_ =
false;
1263 ss <<
"\nFailure performing transition from " << failedEvent.getFromState() <<
"-"
1264 << theStateMachine_.getStateName(failedEvent.getFromState()) <<
" to "
1265 << failedEvent.getToState() <<
"-"
1266 << theStateMachine_.getStateName(failedEvent.getToState())
1267 <<
".\n\nException:\n"
1268 << failedEvent.getException().what() << __E__;
1271 __COUT_ERR__ <<
"\n" << ss.str();
1272 theStateMachine_.setErrorMessage(ss.str());
1275 broadcastMessage(SOAPUtilities::makeSOAPMessageReference(
"Error"));
1279 void GatewaySupervisor::checkForAsyncError()
1281 if(RunControlStateMachine::asyncFailureReceived_)
1283 __COUTV__(RunControlStateMachine::asyncFailureReceived_);
1285 XCEPT_RAISE(toolbox::fsm::exception::Exception,
1286 RunControlStateMachine::getErrorMessage());
1296 void GatewaySupervisor::transitionConfiguring(toolbox::Event::Reference e)
1298 checkForAsyncError();
1300 RunControlStateMachine::theProgressBar_.step();
1302 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << __E__;
1304 std::string systemAlias =
1305 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
1307 .getValue(
"ConfigurationAlias");
1309 __COUT__ <<
"Transition parameter: " << systemAlias << __E__;
1311 RunControlStateMachine::theProgressBar_.step();
1315 CorePropertySupervisorBase::theConfigurationManager_
1320 __SS__ <<
"\nTransition to Configuring interrupted! "
1321 <<
"The Configuration Manager could not be initialized." << __E__;
1323 __COUT_ERR__ <<
"\n" << ss.str();
1324 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1328 RunControlStateMachine::theProgressBar_.step();
1333 theConfigurationTableGroup_ =
1334 CorePropertySupervisorBase::theConfigurationManager_->getTableGroupFromAlias(
1339 __COUT_INFO__ <<
"Exception occurred" << __E__;
1342 RunControlStateMachine::theProgressBar_.step();
1344 if(theConfigurationTableGroup_.second.isInvalid())
1346 __SS__ <<
"\nTransition to Configuring interrupted! System Alias " << systemAlias
1347 <<
" could not be translated to a group name and key." << __E__;
1349 __COUT_ERR__ <<
"\n" << ss.str();
1350 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1354 RunControlStateMachine::theProgressBar_.step();
1356 __COUT__ <<
"Configuration table group name: " << theConfigurationTableGroup_.first
1357 <<
" key: " << theConfigurationTableGroup_.second << __E__;
1361 std::stringstream ss;
1362 ss <<
"Configuring '" << systemAlias <<
"' which translates to "
1363 << theConfigurationTableGroup_.first <<
" ("
1364 << theConfigurationTableGroup_.second <<
").";
1365 makeSystemLogbookEntry(ss.str());
1368 RunControlStateMachine::theProgressBar_.step();
1373 CorePropertySupervisorBase::theConfigurationManager_->loadTableGroup(
1374 theConfigurationTableGroup_.first,
1375 theConfigurationTableGroup_.second,
1378 __COUT__ <<
"Done loading Configuration Alias." << __E__;
1382 tmpCfgMgr.activateTableGroup(theConfigurationTableGroup_.first,
1383 theConfigurationTableGroup_.second);
1385 __COUT__ <<
"Done activating Configuration Alias." << __E__;
1389 __SS__ <<
"\nTransition to Configuring interrupted! System Alias " << systemAlias
1390 <<
" was translated to " << theConfigurationTableGroup_.first <<
" ("
1391 << theConfigurationTableGroup_.second
1392 <<
") but could not be loaded and initialized." << __E__;
1393 ss <<
"\n\nTo debug this problem, try activating this group in the Configuration "
1395 <<
" and detailed errors will be shown." << __E__;
1396 __COUT_ERR__ <<
"\n" << ss.str();
1397 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1404 CorePropertySupervisorBase::theConfigurationManager_->getSupervisorTableNode(
1405 supervisorContextUID_, supervisorApplicationUID_);
1406 if(!configLinkNode.isDisconnected())
1410 bool dumpConfiguration =
true;
1411 std::string dumpFilePath, dumpFileRadix, dumpFormat;
1415 configLinkNode.getNode(
"LinkToStateMachineTable")
1416 .getNode(activeStateMachineName_);
1419 .getNode(
"EnableConfigurationDumpOnConfigureTransition")
1422 fsmLinkNode.getNode(
"ConfigurationDumpOnConfigureFilePath")
1423 .getValue<std::string>();
1425 fsmLinkNode.getNode(
"ConfigurationDumpOnConfigureFileRadix")
1426 .getValue<std::string>();
1427 dumpFormat = fsmLinkNode.getNode(
"ConfigurationDumpOnConfigureFormat")
1428 .getValue<std::string>();
1430 catch(std::runtime_error& e)
1432 __COUT_INFO__ <<
"FSM configuration dump Link disconnected." << __E__;
1433 dumpConfiguration =
false;
1436 if(dumpConfiguration)
1439 CorePropertySupervisorBase::theConfigurationManager_
1440 ->dumpActiveConfiguration(dumpFilePath +
"/" + dumpFileRadix +
1441 "_" + std::to_string(time(0)) +
1446 catch(std::runtime_error& e)
1448 __SS__ <<
"\nTransition to Configuring interrupted! There was an error "
1450 <<
"during the configuration dump attempt:\n\n " << e.what()
1452 __COUT_ERR__ <<
"\n" << ss.str();
1453 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1458 __SS__ <<
"\nTransition to Configuring interrupted! There was an error "
1460 <<
"during the configuration dump attempt.\n\n " << __E__;
1461 __COUT_ERR__ <<
"\n" << ss.str();
1462 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1468 RunControlStateMachine::theProgressBar_.step();
1470 parameters.addParameter(
"ConfigurationTableGroupName",
1471 theConfigurationTableGroup_.first);
1472 parameters.addParameter(
"ConfigurationTableGroupKey",
1473 theConfigurationTableGroup_.second.toString());
1477 __COUT__ <<
"Initializing Macro Maker." << __E__;
1478 xoap::MessageReference message =
1479 SOAPUtilities::makeSOAPMessageReference(
"FECommunication");
1482 parameters.addParameter(
"type",
"initFElist");
1483 parameters.addParameter(
"groupName", theConfigurationTableGroup_.first);
1484 parameters.addParameter(
"groupKey",
1485 theConfigurationTableGroup_.second.toString());
1486 SOAPUtilities::addParameters(message, parameters);
1488 __COUT__ <<
"Sending FE communication: " << SOAPUtilities::translate(message)
1492 SOAPMessenger::send(CorePropertySupervisorBase::allSupervisorInfo_
1493 .getAllMacroMakerTypeSupervisorInfo()
1495 ->second.getDescriptor(),
1498 __COUT__ <<
"Macro Maker init reply: " << reply << __E__;
1499 if(reply ==
"Error")
1501 __SS__ <<
"\nTransition to Configuring interrupted! There was an error "
1502 "identified initializing Macro Maker.\n\n "
1504 __COUT_ERR__ <<
"\n" << ss.str();
1505 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1513 xoap::MessageReference message = theStateMachine_.getCurrentMessage();
1514 SOAPUtilities::addParameters(message, parameters);
1515 broadcastMessage(message);
1516 RunControlStateMachine::theProgressBar_.step();
1521 saveGroupNameAndKey(theConfigurationTableGroup_,
1522 FSM_LAST_CONFIGURED_GROUP_ALIAS_FILE);
1524 __COUT__ <<
"Done configuring." << __E__;
1525 RunControlStateMachine::theProgressBar_.complete();
1529 void GatewaySupervisor::transitionHalting(toolbox::Event::Reference e)
1531 checkForAsyncError();
1533 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << __E__;
1535 makeSystemLogbookEntry(
"Run halting.");
1537 broadcastMessage(theStateMachine_.getCurrentMessage());
1541 void GatewaySupervisor::transitionShuttingDown(toolbox::Event::Reference e)
1544 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << __E__;
1546 RunControlStateMachine::theProgressBar_.step();
1547 makeSystemLogbookEntry(
"System shutting down.");
1548 RunControlStateMachine::theProgressBar_.step();
1551 GatewaySupervisor::launchStartOTSCommand(
1552 "OTS_APP_SHUTDOWN", CorePropertySupervisorBase::theConfigurationManager_);
1553 RunControlStateMachine::theProgressBar_.step();
1557 for(
int i = 0; i < 5; ++i)
1560 RunControlStateMachine::theProgressBar_.step();
1565 void GatewaySupervisor::transitionStartingUp(toolbox::Event::Reference e)
1568 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << __E__;
1570 RunControlStateMachine::theProgressBar_.step();
1571 makeSystemLogbookEntry(
"System starting up.");
1572 RunControlStateMachine::theProgressBar_.step();
1575 GatewaySupervisor::launchStartOTSCommand(
1576 "OTS_APP_STARTUP", CorePropertySupervisorBase::theConfigurationManager_);
1577 RunControlStateMachine::theProgressBar_.step();
1581 for(
int i = 0; i < 10; ++i)
1584 RunControlStateMachine::theProgressBar_.step();
1589 void GatewaySupervisor::transitionInitializing(toolbox::Event::Reference e)
1592 __COUT__ << theStateMachine_.getCurrentStateName() << __E__;
1594 broadcastMessage(theStateMachine_.getCurrentMessage());
1596 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << __E__;
1597 __COUT__ <<
"Fsm current transition: "
1598 << theStateMachine_.getCurrentTransitionName(e->type()) << __E__;
1599 __COUT__ <<
"Fsm final state: "
1600 << theStateMachine_.getTransitionFinalStateName(e->type()) << __E__;
1604 void GatewaySupervisor::transitionPausing(toolbox::Event::Reference e)
1606 checkForAsyncError();
1608 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << __E__;
1610 makeSystemLogbookEntry(
"Run pausing.");
1613 if(RunControlStateMachine::asyncSoftFailureReceived_)
1615 __COUT_ERR__ <<
"Broadcasting pause for async SOFT error!" << __E__;
1616 broadcastMessage(SOAPUtilities::makeSOAPMessageReference(
"Pause"));
1619 broadcastMessage(theStateMachine_.getCurrentMessage());
1623 void GatewaySupervisor::transitionResuming(toolbox::Event::Reference e)
1625 if(RunControlStateMachine::asyncSoftFailureReceived_)
1628 __COUT_INFO__ <<
"Clearing async SOFT error!" << __E__;
1629 RunControlStateMachine::asyncSoftFailureReceived_ =
false;
1632 checkForAsyncError();
1634 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << __E__;
1636 makeSystemLogbookEntry(
"Run resuming.");
1638 broadcastMessage(theStateMachine_.getCurrentMessage());
1642 void GatewaySupervisor::transitionStarting(toolbox::Event::Reference e)
1644 if(RunControlStateMachine::asyncSoftFailureReceived_)
1647 __COUT_INFO__ <<
"Clearing async SOFT error!" << __E__;
1648 RunControlStateMachine::asyncSoftFailureReceived_ =
false;
1651 checkForAsyncError();
1653 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << __E__;
1656 SOAPUtilities::receive(theStateMachine_.getCurrentMessage(), parameters);
1658 std::string runNumber = parameters.getValue(
"RunNumber");
1659 __COUTV__(runNumber);
1664 CorePropertySupervisorBase::theConfigurationManager_->getSupervisorTableNode(
1665 supervisorContextUID_, supervisorApplicationUID_);
1666 if(!configLinkNode.isDisconnected())
1670 bool dumpConfiguration =
true;
1671 std::string dumpFilePath, dumpFileRadix, dumpFormat;
1675 configLinkNode.getNode(
"LinkToStateMachineTable")
1676 .getNode(activeStateMachineName_);
1678 fsmLinkNode.getNode(
"EnableConfigurationDumpOnRunTransition")
1680 dumpFilePath = fsmLinkNode.getNode(
"ConfigurationDumpOnRunFilePath")
1681 .getValue<std::string>();
1682 dumpFileRadix = fsmLinkNode.getNode(
"ConfigurationDumpOnRunFileRadix")
1683 .getValue<std::string>();
1684 dumpFormat = fsmLinkNode.getNode(
"ConfigurationDumpOnRunFormat")
1685 .getValue<std::string>();
1687 catch(std::runtime_error& e)
1689 __COUT_INFO__ <<
"FSM configuration dump Link disconnected." << __E__;
1690 dumpConfiguration =
false;
1693 if(dumpConfiguration)
1696 CorePropertySupervisorBase::theConfigurationManager_
1697 ->dumpActiveConfiguration(dumpFilePath +
"/" + dumpFileRadix +
1698 "_Run" + runNumber +
"_" +
1699 std::to_string(time(0)) +
".dump",
1703 catch(std::runtime_error& e)
1705 __SS__ <<
"\nTransition to Running interrupted! There was an error "
1707 <<
"during the configuration dump attempt:\n\n " << e.what()
1709 __COUT_ERR__ <<
"\n" << ss.str();
1710 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1715 __SS__ <<
"\nTransition to Running interrupted! There was an error "
1717 <<
"during the configuration dump attempt.\n\n " << __E__;
1718 __COUT_ERR__ <<
"\n" << ss.str();
1719 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1725 makeSystemLogbookEntry(
"Run " + runNumber +
" starting.");
1727 broadcastMessage(theStateMachine_.getCurrentMessage());
1730 saveGroupNameAndKey(theConfigurationTableGroup_, FSM_LAST_STARTED_GROUP_ALIAS_FILE);
1734 void GatewaySupervisor::transitionStopping(toolbox::Event::Reference e)
1736 checkForAsyncError();
1738 __COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << __E__;
1740 makeSystemLogbookEntry(
"Run stopping.");
1742 broadcastMessage(theStateMachine_.getCurrentMessage());
1755 bool GatewaySupervisor::handleBroadcastMessageTarget(
const SupervisorInfo& appInfo,
1756 xoap::MessageReference message,
1757 const std::string& command,
1758 const unsigned int& iteration,
1760 unsigned int threadIndex)
1762 unsigned int subIteration = 0;
1763 bool subIterationsDone =
false;
1764 bool iterationsDone =
true;
1766 while(!subIterationsDone)
1768 __COUT__ <<
"Broadcast thread " << threadIndex <<
"\t"
1769 <<
"Supervisor instance = '" << appInfo.getName()
1770 <<
"' [LID=" << appInfo.getId() <<
"] in Context '"
1771 << appInfo.getContextName() <<
"' [URL=" << appInfo.getURL()
1772 <<
"] Command = " << command << __E__;
1774 subIterationsDone =
true;
1775 RunControlStateMachine::theProgressBar_.step();
1781 parameters.addParameter(
"subIterationIndex", subIteration);
1782 SOAPUtilities::addParameters(message, parameters);
1785 if(iteration || subIteration)
1786 __COUT__ <<
"Broadcast thread " << threadIndex <<
"\t"
1787 <<
"Adding iteration parameters " << iteration <<
"." << subIteration
1790 RunControlStateMachine::theProgressBar_.step();
1792 if(iteration == 0 && subIteration == 0)
1794 for(
unsigned int j = 0; j < 4; ++j)
1795 __COUT__ <<
"Broadcast thread " << threadIndex <<
"\t"
1796 <<
"Sending message to Supervisor " << appInfo.getName()
1797 <<
" [LID=" << appInfo.getId() <<
"]: " << command << __E__;
1801 if(subIteration == 0)
1803 for(
unsigned int j = 0; j < 4; ++j)
1804 __COUT__ <<
"Broadcast thread " << threadIndex <<
"\t"
1805 <<
"Sending message to Supervisor " << appInfo.getName()
1806 <<
" [LID=" << appInfo.getId() <<
"]: " << command
1807 <<
" (iteration: " << iteration <<
")" << __E__;
1811 for(
unsigned int j = 0; j < 4; ++j)
1812 __COUT__ <<
"Broadcast thread " << threadIndex <<
"\t"
1813 <<
"Sending message to Supervisor " << appInfo.getName()
1814 <<
" [LID=" << appInfo.getId() <<
"]: " << command
1815 <<
" (iteration: " << iteration
1816 <<
", sub-iteration: " << subIteration <<
")" << __E__;
1824 std::lock_guard<std::mutex> lock(broadcastCommandMessageIndexMutex_);
1825 parameters.addParameter(
"commandId", broadcastCommandMessageIndex_++);
1827 SOAPUtilities::addParameters(message, parameters);
1830 __COUT__ <<
"Broadcast thread " << threadIndex <<
"\t"
1831 <<
"Sending... \t" << SOAPUtilities::translate(message) << std::endl;
1835 reply = send(appInfo.getDescriptor(), message);
1837 catch(
const xdaq::exception::Exception& e)
1840 __SS__ <<
"Error! Gateway Supervisor can NOT " << command
1841 <<
" Supervisor instance = '" << appInfo.getName()
1842 <<
"' [LID=" << appInfo.getId() <<
"] in Context '"
1843 << appInfo.getContextName() <<
"' [URL=" << appInfo.getURL()
1845 <<
"Xoap message failure. Did the target Supervisor crash? Try "
1846 "re-initializing or restarting otsdaq."
1848 __COUT_ERR__ << ss.str();
1849 __MOUT_ERR__ << ss.str();
1853 __COUT__ <<
"Broadcast thread " << threadIndex <<
"\t"
1854 <<
"Try again.." << __E__;
1859 parameters.addParameter(
"retransmission",
"1");
1860 SOAPUtilities::addParameters(message, parameters);
1867 std::lock_guard<std::mutex> lock(
1868 broadcastCommandMessageIndexMutex_);
1869 parameters.addParameter(
"commandId",
1870 broadcastCommandMessageIndex_++);
1872 SOAPUtilities::addParameters(message, parameters);
1875 __COUT__ <<
"Broadcast thread " << threadIndex <<
"\t"
1876 <<
"Re-Sending... " << SOAPUtilities::translate(message)
1879 reply = send(appInfo.getDescriptor(), message);
1881 catch(
const xdaq::exception::Exception& e)
1883 __COUT__ <<
"Broadcast thread " << threadIndex <<
"\t"
1884 <<
"Second try failed.." << __E__;
1885 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1887 __COUT__ <<
"Broadcast thread " << threadIndex <<
"\t"
1888 <<
"2nd try passed.." << __E__;
1891 __COUT__ <<
"Broadcast thread " << threadIndex <<
"\t"
1892 <<
"Reply received = " << reply << __E__;
1894 if((reply != command +
"Done") && (reply != command +
"Response") &&
1895 (reply != command +
"Iterate") && (reply != command +
"SubIterate"))
1897 __SS__ <<
"Error! Gateway Supervisor can NOT " << command
1898 <<
" Supervisor instance = '" << appInfo.getName()
1899 <<
"' [LID=" << appInfo.getId() <<
"] in Context '"
1900 << appInfo.getContextName() <<
"' [URL=" << appInfo.getURL()
1903 __COUT_ERR__ << ss.str() << __E__;
1904 __MOUT_ERR__ << ss.str() << __E__;
1906 __COUT__ <<
"Broadcast thread " << threadIndex <<
"\t"
1907 <<
"Getting error message..." << __E__;
1910 xoap::MessageReference errorMessage =
1911 sendWithSOAPReply(appInfo.getDescriptor(),
1912 SOAPUtilities::makeSOAPMessageReference(
1913 "StateMachineErrorMessageRequest"));
1915 parameters.addParameter(
"ErrorMessage");
1916 SOAPUtilities::receive(errorMessage, parameters);
1918 std::string error = parameters.getValue(
"ErrorMessage");
1921 std::stringstream err;
1922 err <<
"Unknown error from Supervisor instance = '"
1923 << appInfo.getName() <<
"' [LID=" << appInfo.getId()
1924 <<
"] in Context '" << appInfo.getContextName()
1925 <<
"' [URL=" << appInfo.getURL()
1926 <<
"]. If the problem persists or is repeatable, please notify "
1931 __SS__ <<
"Received error from Supervisor instance = '"
1932 << appInfo.getName() <<
"' [LID=" << appInfo.getId()
1933 <<
"] in Context '" << appInfo.getContextName()
1934 <<
"' [URL=" << appInfo.getURL()
1935 <<
"].\n\n Error Message = " << error << __E__;
1937 __COUT_ERR__ << ss.str() << __E__;
1938 __MOUT_ERR__ << ss.str() << __E__;
1940 if(command ==
"Error")
1944 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1946 catch(
const xdaq::exception::Exception& e)
1949 __SS__ <<
"Error! Gateway Supervisor failed to read error message from "
1950 "Supervisor instance = '"
1951 << appInfo.getName() <<
"' [LID=" << appInfo.getId()
1952 <<
"] in Context '" << appInfo.getContextName()
1953 <<
"' [URL=" << appInfo.getURL() <<
"].\n\n"
1954 <<
"Xoap message failure. Did the target Supervisor crash? Try "
1955 "re-initializing or restarting otsdaq."
1957 __COUT_ERR__ << ss.str();
1958 __MOUT_ERR__ << ss.str();
1959 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
1962 else if(reply == command +
"Iterate")
1969 iterationsDone =
false;
1970 __COUT__ <<
"Broadcast thread " << threadIndex <<
"\t"
1971 <<
"Supervisor instance = '" << appInfo.getName()
1972 <<
"' [LID=" << appInfo.getId() <<
"] in Context '"
1973 << appInfo.getContextName() <<
"' [URL=" << appInfo.getURL()
1974 <<
"] flagged for another iteration to " << command
1975 <<
"... (iteration: " << iteration <<
")" << __E__;
1978 else if(reply == command +
"SubIterate")
1985 subIterationsDone =
false;
1986 __COUT__ <<
"Broadcast thread " << threadIndex <<
"\t"
1987 <<
"Supervisor instance = '" << appInfo.getName()
1988 <<
"' [LID=" << appInfo.getId() <<
"] in Context '"
1989 << appInfo.getContextName() <<
"' [URL=" << appInfo.getURL()
1990 <<
"] flagged for another sub-iteration to " << command
1991 <<
"... (iteration: " << iteration
1992 <<
", sub-iteration: " << subIteration <<
")" << __E__;
1996 __COUT__ <<
"Broadcast thread " << threadIndex <<
"\t"
1997 <<
"Supervisor instance = '" << appInfo.getName()
1998 <<
"' [LID=" << appInfo.getId() <<
"] in Context '"
1999 << appInfo.getContextName() <<
"' [URL=" << appInfo.getURL()
2000 <<
"] was " << command <<
"'d correctly!" << __E__;
2004 __COUT__ <<
"Broadcast thread " << threadIndex <<
"\t"
2005 <<
"Completed sub-iteration: " << subIteration << __E__;
2010 return iterationsDone;
2018 void GatewaySupervisor::broadcastMessageThread(
2019 GatewaySupervisor* supervisorPtr,
2020 GatewaySupervisor::BroadcastThreadStruct* threadStruct)
2022 __COUT__ <<
"Broadcast thread " << threadStruct->threadIndex_ <<
"\t"
2023 <<
"starting..." << __E__;
2025 while(!threadStruct->exitThread_)
2031 std::lock_guard<std::mutex> lock(threadStruct->threadMutex);
2032 if(threadStruct->workToDo_)
2034 __COUT__ <<
"Broadcast thread " << threadStruct->threadIndex_ <<
"\t"
2035 <<
"starting work..." << __E__;
2039 if(supervisorPtr->handleBroadcastMessageTarget(
2040 threadStruct->getAppInfo(),
2041 threadStruct->getMessage(),
2042 threadStruct->getCommand(),
2043 threadStruct->getIteration(),
2044 threadStruct->getReply(),
2045 threadStruct->threadIndex_))
2046 threadStruct->getIterationsDone() =
true;
2048 catch(toolbox::fsm::exception::Exception
const& e)
2050 __COUT__ <<
"Broadcast thread " << threadStruct->threadIndex_ <<
"\t"
2051 <<
"going into error: " << e.what() << __E__;
2053 threadStruct->getReply() = e.what();
2054 threadStruct->error_ =
true;
2055 threadStruct->workToDo_ =
false;
2056 threadStruct->working_ =
false;
2060 if(!threadStruct->getIterationsDone())
2062 __COUT__ <<
"Broadcast thread " << threadStruct->threadIndex_ <<
"\t"
2063 <<
"flagged for another iteration." << __E__;
2066 std::lock_guard<std::mutex> lock(
2067 supervisorPtr->broadcastIterationsDoneMutex_);
2068 supervisorPtr->broadcastIterationsDone_ =
false;
2071 __COUT__ <<
"Broadcast thread " << threadStruct->threadIndex_ <<
"\t"
2072 <<
"done with work." << __E__;
2074 threadStruct->workToDo_ =
false;
2079 __COUT__ <<
"Broadcast thread " << threadStruct->threadIndex_ <<
"\t"
2080 <<
"exited." << __E__;
2081 threadStruct->working_ =
false;
2089 void GatewaySupervisor::broadcastMessage(xoap::MessageReference message)
2091 RunControlStateMachine::theProgressBar_.step();
2094 allSupervisorInfo_.setSupervisorStatus(
this, theStateMachine_.getCurrentStateName());
2096 std::string command = SOAPUtilities::translate(message).getCommand();
2099 broadcastIterationsDone_ =
false;
2102 std::vector<std::vector<const SupervisorInfo*>> orderedSupervisors;
2106 orderedSupervisors = allSupervisorInfo_.getOrderedSupervisorDescriptors(command);
2108 catch(
const std::runtime_error& e)
2110 __SS__ <<
"Error getting supervisor priority. Was there a change in the context?"
2111 <<
" Remember, if the context was changed, it is safest to relaunch "
2113 << e.what() << __E__;
2114 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
2117 RunControlStateMachine::theProgressBar_.step();
2121 GatewaySupervisor::BroadcastMessageIterationsDoneStruct supervisorIterationsDone;
2124 for(
const auto& vectorAtPriority : orderedSupervisors)
2125 supervisorIterationsDone.push(
2126 vectorAtPriority.size());
2130 unsigned int iteration = 0;
2131 unsigned int subIteration;
2132 unsigned int iterationBreakpoint;
2137 xoap::MessageReference originalMessage =
2138 SOAPUtilities::makeSOAPMessageReference(SOAPUtilities::translate(message));
2140 __COUT__ <<
"=========> Broadcasting state machine command = " << command << __E__;
2142 unsigned int numberOfThreads = 1;
2146 numberOfThreads = CorePropertySupervisorBase::getSupervisorTableNode()
2147 .getNode(
"NumberOfStateMachineBroadcastThreads")
2148 .getValue<
unsigned int>();
2153 __COUT__ <<
"Number of threads not in configuration, so defaulting to "
2154 << numberOfThreads << __E__;
2159 if(numberOfThreads == 1)
2160 numberOfThreads = 0;
2162 __COUTV__(numberOfThreads);
2164 std::vector<GatewaySupervisor::BroadcastThreadStruct> broadcastThreadStructs(
2169 for(
unsigned int i = 0; i < numberOfThreads; ++i)
2171 broadcastThreadStructs[i].threadIndex_ = i;
2174 [](GatewaySupervisor* supervisorPtr,
2175 GatewaySupervisor::BroadcastThreadStruct* threadStruct) {
2176 GatewaySupervisor::broadcastMessageThread(supervisorPtr, threadStruct);
2179 &broadcastThreadStructs[i])
2183 RunControlStateMachine::theProgressBar_.step();
2191 broadcastIterationsDone_ =
true;
2194 std::lock_guard<std::mutex> lock(broadcastIterationBreakpointMutex_);
2195 iterationBreakpoint = broadcastIterationBreakpoint_;
2198 if(iterationBreakpoint < (
unsigned int)-1)
2199 __COUT__ <<
"Iteration breakpoint currently is " << iterationBreakpoint
2201 if(iteration >= iterationBreakpoint)
2203 broadcastIterationsDone_ =
false;
2204 __COUT__ <<
"Waiting at transition breakpoint - iteration = " << iteration
2206 usleep(5 * 1000 * 1000 );
2211 __COUT__ <<
"Starting iteration: " << iteration << __E__;
2213 for(
unsigned int i = 0; i < supervisorIterationsDone.size(); ++i)
2215 for(
unsigned int j = 0; j < supervisorIterationsDone.size(i); ++j)
2217 checkForAsyncError();
2219 if(supervisorIterationsDone[i][j])
2225 message = SOAPUtilities::makeSOAPMessageReference(
2226 SOAPUtilities::translate(originalMessage));
2233 parameters.addParameter(
"iterationIndex", iteration);
2234 SOAPUtilities::addParameters(message, parameters);
2240 assignedJob =
false;
2243 for(
unsigned int k = 0; k < numberOfThreads; ++k)
2245 if(!broadcastThreadStructs[k].workToDo_)
2249 __COUT__ <<
"Giving work to thread " << k << __E__;
2251 std::lock_guard<std::mutex> lock(
2252 broadcastThreadStructs[k].threadMutex);
2253 broadcastThreadStructs[k].setMessage(
2258 supervisorIterationsDone[i][j]);
2266 __COUT__ <<
"No free broadcast threads, "
2267 <<
"waiting for an available thread..." << __E__;
2268 usleep(100 * 1000 );
2270 }
while(!assignedJob);
2274 if(handleBroadcastMessageTarget(
2275 appInfo, message, command, iteration, reply))
2276 supervisorIterationsDone[i][j] =
true;
2278 broadcastIterationsDone_ =
false;
2288 <<
"Done with priority level. Waiting for threads to finish..."
2294 for(
unsigned int i = 0; i < numberOfThreads; ++i)
2295 if(broadcastThreadStructs[i].workToDo_)
2298 __COUT__ <<
"Still waiting on thread " << i <<
"..."
2300 usleep(100 * 1000 );
2303 else if(broadcastThreadStructs[i].error_)
2305 __COUT__ <<
"Found thread in error! Throwing state "
2307 << broadcastThreadStructs[i].getReply() << __E__;
2308 XCEPT_RAISE(toolbox::fsm::exception::Exception,
2309 broadcastThreadStructs[i].getReply());
2312 __COUT__ <<
"All threads done with priority level work." << __E__;
2323 if(iteration || !broadcastIterationsDone_)
2324 __COUT__ <<
"Completed iteration: " << iteration << __E__;
2327 }
while(!broadcastIterationsDone_);
2329 RunControlStateMachine::theProgressBar_.step();
2333 __COUT__ <<
"Exception caught, exiting broadcast threads..." << __E__;
2340 for(
unsigned int i = 0; i < numberOfThreads; ++i)
2341 broadcastThreadStructs[i].exitThread_ =
true;
2342 usleep(100 * 1000 );
2349 __COUT__ <<
"All transitions completed. Wrapping up, exiting broadcast threads..."
2358 for(
unsigned int i = 0; i < numberOfThreads; ++i)
2359 broadcastThreadStructs[i].exitThread_ =
true;
2360 usleep(100 * 1000 );
2363 __COUT__ <<
"Broadcast complete." << __E__;
2367 void GatewaySupervisor::wait(
int milliseconds, std::string who)
const
2369 for(
int s = 1; s <= milliseconds; s++)
2374 __COUT__ << s <<
" msecs " << who << __E__;
2383 void GatewaySupervisor::loginRequest(xgi::Input* in, xgi::Output* out)
2385 __COUT__ <<
"Start" << __E__;
2386 cgicc::Cgicc cgi(in);
2387 std::string Command = CgiDataUtilities::getData(cgi,
"RequestType");
2388 __COUT__ <<
"*** Login RequestType = " << Command << __E__;
2397 std::vector<std::string> loggedOutUsernames;
2398 theWebUsers_.cleanupExpiredEntries(&loggedOutUsernames);
2399 for(
unsigned int i = 0; i < loggedOutUsernames.size();
2401 makeSystemLogbookEntry(loggedOutUsernames[i] +
" login timed out.");
2403 if(Command ==
"sessionId")
2412 std::string uuid = CgiDataUtilities::postData(cgi,
"uuid");
2414 std::string sid = theWebUsers_.createNewLoginSession(
2415 uuid, cgi.getEnvironment().getRemoteAddr() );
2421 else if(Command ==
"checkCookie")
2425 std::string jumbledUser;
2426 std::string cookieCode;
2437 uuid = CgiDataUtilities::postData(cgi,
"uuid");
2438 jumbledUser = CgiDataUtilities::postData(cgi,
"ju");
2439 cookieCode = CgiDataUtilities::postData(cgi,
"cc");
2447 uid = theWebUsers_.isCookieCodeActiveForLogin(
2452 if(uid == theWebUsers_.NOT_FOUND_IN_DATABASE)
2454 __COUT__ <<
"cookieCode invalid" << __E__;
2459 __COUT__ <<
"cookieCode is good." << __E__;
2464 theWebUsers_.insertSettingsForUser(uid, &xmldoc);
2466 xmldoc.outputXmlDocument((std::ostringstream*)out);
2468 else if(Command ==
"login")
2479 std::string uuid = CgiDataUtilities::postData(cgi,
"uuid");
2480 std::string newAccountCode = CgiDataUtilities::postData(cgi,
"nac");
2481 std::string jumbledUser = CgiDataUtilities::postData(cgi,
"ju");
2482 std::string jumbledPw = CgiDataUtilities::postData(cgi,
"jp");
2489 uint64_t uid = theWebUsers_.attemptActiveSession(
2494 cgi.getEnvironment()
2497 if(uid == theWebUsers_.NOT_FOUND_IN_DATABASE)
2499 __COUT__ <<
"Login invalid." << __E__;
2501 if(newAccountCode !=
"1")
2502 newAccountCode =
"0";
2505 makeSystemLogbookEntry(theWebUsers_.getUsersUsername(uid) +
" logged in.");
2511 theWebUsers_.insertSettingsForUser(uid, &xmldoc);
2515 if(uid != theWebUsers_.NOT_FOUND_IN_DATABASE)
2517 uint64_t asCnt = theWebUsers_.getActiveSessionCountForUser(uid) -
2520 sprintf(asStr,
"%lu", asCnt);
2521 xmldoc.addTextElementToData(
"user_active_session_count", asStr);
2524 xmldoc.outputXmlDocument((std::ostringstream*)out);
2526 else if(Command ==
"cert")
2537 std::string uuid = CgiDataUtilities::postData(cgi,
"uuid");
2538 std::string jumbledEmail =
2539 cgicc::form_urldecode(CgiDataUtilities::getData(cgi,
"httpsUser"));
2540 std::string username =
"";
2541 std::string cookieCode =
"";
2547 uint64_t uid = theWebUsers_.attemptActiveSessionWithCert(
2552 cgi.getEnvironment()
2555 if(uid == theWebUsers_.NOT_FOUND_IN_DATABASE)
2557 __COUT__ <<
"cookieCode invalid" << __E__;
2559 if(cookieCode !=
"1")
2563 makeSystemLogbookEntry(theWebUsers_.getUsersUsername(uid) +
" logged in.");
2569 theWebUsers_.insertSettingsForUser(uid, &xmldoc);
2573 if(uid != theWebUsers_.NOT_FOUND_IN_DATABASE)
2575 uint64_t asCnt = theWebUsers_.getActiveSessionCountForUser(uid) -
2578 sprintf(asStr,
"%lu", asCnt);
2579 xmldoc.addTextElementToData(
"user_active_session_count", asStr);
2582 xmldoc.outputXmlDocument((std::ostringstream*)out);
2584 else if(Command ==
"logout")
2586 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
2587 std::string logoutOthers = CgiDataUtilities::postData(cgi,
"LogoutOthers");
2593 if(theWebUsers_.cookieCodeLogout(cookieCode,
2594 logoutOthers ==
"1",
2596 cgi.getEnvironment().getRemoteAddr()) !=
2597 theWebUsers_.NOT_FOUND_IN_DATABASE)
2601 if(!theWebUsers_.isUserIdActive(uid))
2602 makeSystemLogbookEntry(theWebUsers_.getUsersUsername(uid) +
2608 __COUT__ <<
"Invalid Command" << __E__;
2612 __COUT__ <<
"Done" << __E__;
2616 void GatewaySupervisor::tooltipRequest(xgi::Input* in, xgi::Output* out)
2618 __COUT__ <<
"Start" << __E__;
2619 cgicc::Cgicc cgi(in);
2621 std::string Command = CgiDataUtilities::getData(cgi,
"RequestType");
2622 __COUT__ <<
"Tooltip RequestType = " << Command << __E__;
2629 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
2632 if(!theWebUsers_.cookieCodeIsActiveForRequest(
2633 cookieCode, 0 , &uid,
"0" ,
false ))
2643 if(Command ==
"check")
2645 WebUsers::tooltipCheckForUsername(theWebUsers_.getUsersUsername(uid),
2647 CgiDataUtilities::getData(cgi,
"srcFile"),
2648 CgiDataUtilities::getData(cgi,
"srcFunc"),
2649 CgiDataUtilities::getData(cgi,
"srcId"));
2651 else if(Command ==
"setNeverShow")
2653 WebUsers::tooltipSetNeverShowForUsername(
2654 theWebUsers_.getUsersUsername(uid),
2656 CgiDataUtilities::getData(cgi,
"srcFile"),
2657 CgiDataUtilities::getData(cgi,
"srcFunc"),
2658 CgiDataUtilities::getData(cgi,
"srcId"),
2659 CgiDataUtilities::getData(cgi,
"doNeverShow") ==
"1" ?
true :
false,
2660 CgiDataUtilities::getData(cgi,
"temporarySilence") ==
"1" ?
true :
false);
2663 __COUT__ <<
"Command Request, " << Command <<
", not recognized." << __E__;
2665 xmldoc.outputXmlDocument((std::ostringstream*)out,
false,
true);
2667 __COUT__ <<
"Done" << __E__;
2674 void GatewaySupervisor::setSupervisorPropertyDefaults()
2676 CorePropertySupervisorBase::setSupervisorProperty(
2677 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.UserPermissionsThreshold,
2678 std::string() +
"*=1 | gatewayLaunchOTS=-1 | gatewayLaunchWiz=-1");
2684 void GatewaySupervisor::forceSupervisorPropertyValues()
2690 CorePropertySupervisorBase::setSupervisorProperty(
2691 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.AutomatedRequestTypes,
2692 "getSystemMessages | getCurrentState | getIterationPlanStatus");
2693 CorePropertySupervisorBase::setSupervisorProperty(
2694 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.RequireUserLockRequestTypes,
2695 "gatewayLaunchOTS | gatewayLaunchWiz");
2701 void GatewaySupervisor::request(xgi::Input* in, xgi::Output* out)
2709 __COUT__ <<
"Waiting for FSM access" << __E__;
2710 std::lock_guard<std::mutex> lock(stateMachineAccessMutex_);
2712 __COUT__ <<
"Have FSM access" << __E__;
2714 cgicc::Cgicc cgiIn(in);
2716 std::string requestType = CgiDataUtilities::getData(cgiIn,
"RequestType");
2720 CgiDataUtilities::postData(cgiIn,
"CookieCode"));
2722 CorePropertySupervisorBase::getRequestUserInfo(userInfo);
2724 if(!theWebUsers_.xmlRequestOnGateway(cgiIn, out, &xmlOut, userInfo))
2751 if(requestType ==
"getSettings")
2753 std::string accounts = CgiDataUtilities::getData(cgiIn,
"accounts");
2755 __COUT__ <<
"Get Settings Request" << __E__;
2756 __COUT__ <<
"accounts = " << accounts << __E__;
2757 theWebUsers_.insertSettingsForUser(userInfo.uid_, &xmlOut, accounts ==
"1");
2759 else if(requestType ==
"setSettings")
2761 std::string bgcolor = CgiDataUtilities::postData(cgiIn,
"bgcolor");
2762 std::string dbcolor = CgiDataUtilities::postData(cgiIn,
"dbcolor");
2763 std::string wincolor = CgiDataUtilities::postData(cgiIn,
"wincolor");
2764 std::string layout = CgiDataUtilities::postData(cgiIn,
"layout");
2765 std::string syslayout = CgiDataUtilities::postData(cgiIn,
"syslayout");
2767 __COUT__ <<
"Set Settings Request" << __E__;
2768 __COUT__ <<
"bgcolor = " << bgcolor << __E__;
2769 __COUT__ <<
"dbcolor = " << dbcolor << __E__;
2770 __COUT__ <<
"wincolor = " << wincolor << __E__;
2771 __COUT__ <<
"layout = " << layout << __E__;
2772 __COUT__ <<
"syslayout = " << syslayout << __E__;
2774 theWebUsers_.changeSettingsForUser(
2775 userInfo.uid_, bgcolor, dbcolor, wincolor, layout, syslayout);
2776 theWebUsers_.insertSettingsForUser(
2777 userInfo.uid_, &xmlOut,
true);
2779 else if(requestType ==
"accountSettings")
2781 std::string type = CgiDataUtilities::postData(
2785 if(type ==
"updateAccount")
2787 else if(type ==
"createAccount")
2789 else if(type ==
"deleteAccount")
2792 std::string username = CgiDataUtilities::postData(cgiIn,
"username");
2793 std::string displayname = CgiDataUtilities::postData(cgiIn,
"displayname");
2794 std::string email = CgiDataUtilities::postData(cgiIn,
"useremail");
2795 std::string permissions = CgiDataUtilities::postData(cgiIn,
"permissions");
2796 std::string accounts = CgiDataUtilities::getData(cgiIn,
"accounts");
2798 __COUT__ <<
"accountSettings Request" << __E__;
2799 __COUT__ <<
"type = " << type <<
" - " << type_int << __E__;
2800 __COUT__ <<
"username = " << username << __E__;
2801 __COUT__ <<
"useremail = " << email << __E__;
2802 __COUT__ <<
"displayname = " << displayname << __E__;
2803 __COUT__ <<
"permissions = " << permissions << __E__;
2805 theWebUsers_.modifyAccountSettings(
2806 userInfo.uid_, type_int, username, displayname, email, permissions);
2808 __COUT__ <<
"accounts = " << accounts << __E__;
2810 theWebUsers_.insertSettingsForUser(userInfo.uid_, &xmlOut, accounts ==
"1");
2812 else if(requestType ==
"stateMatchinePreferences")
2814 std::string set = CgiDataUtilities::getData(cgiIn,
"set");
2815 const std::string DEFAULT_FSM_VIEW =
"Default_FSM_View";
2817 theWebUsers_.setGenericPreference(
2820 CgiDataUtilities::getData(cgiIn, DEFAULT_FSM_VIEW));
2822 theWebUsers_.getGenericPreference(
2823 userInfo.uid_, DEFAULT_FSM_VIEW, &xmlOut);
2825 else if(requestType ==
"getAliasList")
2827 std::string username = theWebUsers_.getUsersUsername(userInfo.uid_);
2828 std::string fsmName = CgiDataUtilities::getData(cgiIn,
"fsmName");
2829 __COUT__ <<
"fsmName = " << fsmName << __E__;
2831 std::string stateMachineAliasFilter =
"*";
2833 std::map<std::string ,
2835 aliasMap = CorePropertySupervisorBase::theConfigurationManager_
2836 ->getActiveGroupAliases();
2840 CorePropertySupervisorBase::theConfigurationManager_
2841 ->getSupervisorTableNode(supervisorContextUID_,
2842 supervisorApplicationUID_);
2844 if(!configLinkNode.isDisconnected())
2849 configLinkNode.getNode(
"LinkToStateMachineTable");
2850 if(!fsmLinkNode.isDisconnected())
2851 stateMachineAliasFilter =
2852 fsmLinkNode.getNode(fsmName +
"/SystemAliasFilter")
2853 .getValue<std::string>();
2855 __COUT_INFO__ <<
"FSM Link disconnected." << __E__;
2857 catch(std::runtime_error& e)
2859 __COUT_INFO__ << e.what() << __E__;
2863 __COUT_ERR__ <<
"Unknown error. Should never happen." << __E__;
2867 __COUT_INFO__ <<
"FSM Link disconnected." << __E__;
2869 __COUT__ <<
"stateMachineAliasFilter = " << stateMachineAliasFilter << __E__;
2876 stateMachineAliasFilter.size() && stateMachineAliasFilter[0] ==
'!';
2877 std::vector<std::string> filterArr;
2884 while((f = stateMachineAliasFilter.find(
'*', i)) != std::string::npos)
2886 tmp = stateMachineAliasFilter.substr(i, f - i);
2888 filterArr.push_back(tmp);
2892 if(i <= stateMachineAliasFilter.size())
2894 tmp = stateMachineAliasFilter.substr(i);
2895 filterArr.push_back(tmp);
2901 for(
auto& aliasMapPair : aliasMap)
2907 if(filterArr.size() == 1)
2909 if(filterArr[0] !=
"" && filterArr[0] !=
"*" &&
2910 aliasMapPair.first != filterArr[0])
2911 filterMatch =
false;
2916 for(f = 0; f < filterArr.size(); ++f)
2918 if(!filterArr[f].size())
2923 if((i = aliasMapPair.first.find(filterArr[f])) != 0)
2925 filterMatch =
false;
2930 filterArr.size() - 1)
2932 if(aliasMapPair.first.rfind(filterArr[f]) !=
2933 aliasMapPair.first.size() - filterArr[f].size())
2935 filterMatch =
false;
2939 else if((i = aliasMapPair.first.find(filterArr[f])) ==
2942 filterMatch =
false;
2949 filterMatch = !filterMatch;
2956 xmlOut.addTextElementToData(
"config_alias", aliasMapPair.first);
2957 xmlOut.addTextElementToData(
2959 TableGroupKey::getFullGroupString(aliasMapPair.second.first,
2960 aliasMapPair.second.second)
2963 std::string groupComment, groupAuthor, groupCreationTime;
2966 CorePropertySupervisorBase::theConfigurationManager_
2967 ->loadTableGroup(aliasMapPair.second.first,
2968 aliasMapPair.second.second,
2978 xmlOut.addTextElementToData(
"config_comment", groupComment);
2979 xmlOut.addTextElementToData(
"config_author", groupAuthor);
2980 xmlOut.addTextElementToData(
"config_create_time",
2985 __COUT_WARN__ <<
"Failed to load group metadata." << __E__;
2991 std::string fn = FSM_LAST_GROUP_ALIAS_PATH + FSM_LAST_GROUP_ALIAS_FILE_START +
2992 username +
"." + FSM_USERS_PREFERENCES_FILETYPE;
2993 __COUT__ <<
"Load preferences: " << fn << __E__;
2994 FILE* fp = fopen(fn.c_str(),
"r");
2997 char tmpLastAlias[500];
2998 fscanf(fp,
"%*s %s", tmpLastAlias);
2999 __COUT__ <<
"tmpLastAlias: " << tmpLastAlias << __E__;
3001 xmlOut.addTextElementToData(
"UserLastConfigAlias", tmpLastAlias);
3005 else if(requestType ==
"getFecList")
3007 xmlOut.addTextElementToData(
"fec_list",
"");
3009 for(
auto it : allSupervisorInfo_.getAllFETypeSupervisorInfo())
3011 xmlOut.addTextElementToParent(
"fec_url", it.second.getURL(),
"fec_list");
3012 xmlOut.addTextElementToParent(
3013 "fec_urn", std::to_string(it.second.getId()),
"fec_list");
3016 else if(requestType ==
"getSystemMessages")
3018 xmlOut.addTextElementToData(
3020 theSystemMessenger_.getSystemMessage(
3021 theWebUsers_.getUsersDisplayName(userInfo.uid_)));
3023 xmlOut.addTextElementToData(
3024 "username_with_lock",
3025 theWebUsers_.getUserWithLock());
3029 else if(requestType ==
"setUserWithLock")
3031 std::string username = CgiDataUtilities::postData(cgiIn,
"username");
3032 std::string lock = CgiDataUtilities::postData(cgiIn,
"lock");
3033 std::string accounts = CgiDataUtilities::getData(cgiIn,
"accounts");
3035 __COUT__ << requestType << __E__;
3036 __COUT__ <<
"username " << username << __E__;
3037 __COUT__ <<
"lock " << lock << __E__;
3038 __COUT__ <<
"accounts " << accounts << __E__;
3039 __COUT__ <<
"userInfo.uid_ " << userInfo.uid_ << __E__;
3041 std::string tmpUserWithLock = theWebUsers_.getUserWithLock();
3042 if(!theWebUsers_.setUserWithLock(userInfo.uid_, lock ==
"1", username))
3043 xmlOut.addTextElementToData(
3045 std::string(
"Set user lock action failed. You must have valid "
3046 "permissions and ") +
3047 "locking user must be currently logged in.");
3049 theWebUsers_.insertSettingsForUser(userInfo.uid_, &xmlOut, accounts ==
"1");
3051 if(tmpUserWithLock !=
3054 theSystemMessenger_.addSystemMessage(
3056 theWebUsers_.getUserWithLock() ==
""
3057 ? tmpUserWithLock +
" has unlocked ots."
3058 : theWebUsers_.getUserWithLock() +
" has locked ots.");
3060 else if(requestType ==
"getStateMachine")
3063 std::vector<toolbox::fsm::State> states;
3064 states = theStateMachine_.getStates();
3067 std::string transName;
3068 std::string transParameter;
3071 for(
unsigned int i = 0; i < states.size(); ++i)
3073 stateStr[0] = states[i];
3074 DOMElement* stateParent = xmlOut.addTextElementToData(
"state", stateStr);
3076 xmlOut.addTextElementToParent(
3077 "state_name", theStateMachine_.getStateName(states[i]), stateParent);
3084 std::map<std::string, toolbox::fsm::State, std::less<std::string>> trans =
3085 theStateMachine_.getTransitions(states[i]);
3086 std::set<std::string> actionNames = theStateMachine_.getInputs(states[i]);
3088 std::map<std::string, toolbox::fsm::State, std::less<std::string>>::
3089 iterator it = trans.begin();
3090 std::set<std::string>::iterator ait = actionNames.begin();
3098 for(; it != trans.end() && ait != actionNames.end(); ++it, ++ait)
3100 stateStr[0] = it->second;
3102 if(stateStr[0] ==
'R')
3105 xmlOut.addTextElementToParent(
3106 "state_transition", stateStr, stateParent);
3110 xmlOut.addTextElementToParent(
3111 "state_transition_action", *ait, stateParent);
3113 transName = theStateMachine_.getTransitionName(states[i], *ait);
3116 xmlOut.addTextElementToParent(
3117 "state_transition_name", transName, stateParent);
3119 theStateMachine_.getTransitionParameter(states[i], *ait);
3122 xmlOut.addTextElementToParent(
3123 "state_transition_parameter", transParameter, stateParent);
3126 else if(stateStr[0] ==
'C')
3129 xmlOut.addTextElementToParent(
3130 "state_transition", stateStr, stateParent);
3134 xmlOut.addTextElementToParent(
3135 "state_transition_action", *ait, stateParent);
3137 transName = theStateMachine_.getTransitionName(states[i], *ait);
3140 xmlOut.addTextElementToParent(
3141 "state_transition_name", transName, stateParent);
3143 theStateMachine_.getTransitionParameter(states[i], *ait);
3146 xmlOut.addTextElementToParent(
3147 "state_transition_parameter", transParameter, stateParent);
3154 ait = actionNames.begin();
3157 for(; it != trans.end() && ait != actionNames.end(); ++it, ++ait)
3161 stateStr[0] = it->second;
3163 if(stateStr[0] ==
'R')
3165 else if(stateStr[0] ==
'C')
3168 xmlOut.addTextElementToParent(
3169 "state_transition", stateStr, stateParent);
3173 xmlOut.addTextElementToParent(
3174 "state_transition_action", *ait, stateParent);
3176 transName = theStateMachine_.getTransitionName(states[i], *ait);
3179 xmlOut.addTextElementToParent(
3180 "state_transition_name", transName, stateParent);
3182 theStateMachine_.getTransitionParameter(states[i], *ait);
3185 xmlOut.addTextElementToParent(
3186 "state_transition_parameter", transParameter, stateParent);
3190 else if(requestType ==
"getStateMachineNames")
3194 CorePropertySupervisorBase::theConfigurationManager_
3195 ->getSupervisorTableNode(supervisorContextUID_,
3196 supervisorApplicationUID_);
3201 configLinkNode.getNode(
"LinkToStateMachineTable").getChildren();
3202 for(
const auto& fsmNode : fsmNodes)
3203 xmlOut.addTextElementToData(
"stateMachineName", fsmNode.first);
3207 __COUT__ <<
"Caught exception, assuming no valid FSM names." << __E__;
3208 xmlOut.addTextElementToData(
"stateMachineName",
"");
3211 else if(requestType ==
"getIterationPlanStatus")
3214 theIterator_.handleCommandRequest(xmlOut, requestType,
"");
3216 else if(requestType ==
"getCurrentState")
3218 xmlOut.addTextElementToData(
"current_state",
3219 theStateMachine_.getCurrentStateName());
3220 xmlOut.addTextElementToData(
"in_transition",
3221 theStateMachine_.isInTransition() ?
"1" :
"0");
3222 if(theStateMachine_.isInTransition())
3223 xmlOut.addTextElementToData(
3224 "transition_progress",
3225 RunControlStateMachine::theProgressBar_.readPercentageString());
3227 xmlOut.addTextElementToData(
"transition_progress",
"100");
3230 sprintf(tmp,
"%lu", theStateMachine_.getTimeInState());
3231 xmlOut.addTextElementToData(
"time_in_state", tmp);
3238 std::string fsmName = CgiDataUtilities::getData(cgiIn,
"fsmName");
3247 if(!theStateMachine_.isInTransition())
3249 std::string stateMachineRunAlias =
"Run";
3253 CorePropertySupervisorBase::theConfigurationManager_
3254 ->getSupervisorTableNode(supervisorContextUID_,
3255 supervisorApplicationUID_);
3257 if(!configLinkNode.isDisconnected())
3262 configLinkNode.getNode(
"LinkToStateMachineTable");
3263 if(!fsmLinkNode.isDisconnected())
3264 stateMachineRunAlias =
3265 fsmLinkNode.getNode(fsmName +
"/RunDisplayAlias")
3266 .getValue<std::string>();
3270 catch(std::runtime_error& e)
3279 __COUT_ERR__ <<
"Unknown error. Should never happen." << __E__;
3281 __COUT_INFO__ <<
"No state machine Run alias. Ignoring and "
3282 "assuming alias of '"
3283 << stateMachineRunAlias <<
".'" << __E__;
3292 xmlOut.addTextElementToData(
"stateMachineRunAlias", stateMachineRunAlias);
3296 if(theStateMachine_.getCurrentStateName() ==
"Running" ||
3297 theStateMachine_.getCurrentStateName() ==
"Paused")
3300 "Current %s Number: %u",
3301 stateMachineRunAlias.c_str(),
3302 getNextRunNumber(activeStateMachineName_) - 1);
3304 if(RunControlStateMachine::asyncSoftFailureReceived_)
3308 xmlOut.addTextElementToData(
3309 "soft_error", RunControlStateMachine::getErrorMessage());
3314 "Next %s Number: %u",
3315 stateMachineRunAlias.c_str(),
3316 getNextRunNumber(fsmName));
3317 xmlOut.addTextElementToData(
"run_number", tmp);
3320 else if(requestType ==
"cancelStateMachineTransition")
3322 __SS__ <<
"State transition was cancelled by user!" << __E__;
3323 __MCOUT__(ss.str());
3324 RunControlStateMachine::theStateMachine_.setErrorMessage(ss.str());
3325 RunControlStateMachine::asyncFailureReceived_ =
true;
3327 else if(requestType ==
"getErrorInStateMatchine")
3329 xmlOut.addTextElementToData(
"FSM_Error", theStateMachine_.getErrorMessage());
3331 else if(requestType ==
"getDesktopIcons")
3338 CorePropertySupervisorBase::theConfigurationManager_->__GET_CONFIG__(
3340 std::vector<DesktopIconTable::DesktopIcon> icons =
3341 iconTable->getAllDesktopIcons();
3343 std::string iconString =
"";
3358 std::map<std::string, WebUsers::permissionLevel_t> userPermissionLevelsMap =
3359 theWebUsers_.getPermissionsForUser(userInfo.uid_);
3360 std::map<std::string, WebUsers::permissionLevel_t>
3361 iconPermissionThresholdsMap;
3363 bool firstIcon =
true;
3364 for(
const auto& icon : icons)
3366 __COUTV__(icon.caption_);
3367 __COUTV__(icon.permissionThresholdString_);
3369 CorePropertySupervisorBase::extractPermissionsMapFromString(
3370 icon.permissionThresholdString_, iconPermissionThresholdsMap);
3372 if(!CorePropertySupervisorBase::doPermissionsGrantAccess(
3373 userPermissionLevelsMap, iconPermissionThresholdsMap))
3384 iconString += icon.caption_;
3385 iconString +=
"," + icon.alternateText_;
3387 "," + std::string(icon.enforceOneWindowInstance_ ?
"1" :
"0");
3389 "," + std::string(
"1");
3393 iconString +=
"," + icon.imageURL_;
3394 iconString +=
"," + icon.windowContentURL_;
3395 iconString +=
"," + icon.folderPath_;
3397 __COUTV__(iconString);
3399 xmlOut.addTextElementToData(
"iconList", iconString);
3401 else if(requestType ==
"gatewayLaunchOTS" || requestType ==
"gatewayLaunchWiz")
3405 __COUT_WARN__ << requestType <<
" requestType received! " << __E__;
3406 __MOUT_WARN__ << requestType <<
" requestType received! " << __E__;
3409 theWebUsers_.saveActiveSessions();
3413 if(requestType ==
"gatewayLaunchOTS")
3414 GatewaySupervisor::launchStartOTSCommand(
3415 "LAUNCH_OTS", CorePropertySupervisorBase::theConfigurationManager_);
3416 else if(requestType ==
"gatewayLaunchWiz")
3417 GatewaySupervisor::launchStartOTSCommand(
3418 "LAUNCH_WIZ", CorePropertySupervisorBase::theConfigurationManager_);
3420 else if(requestType ==
"resetUserTooltips")
3422 WebUsers::resetAllUserTooltips(theWebUsers_.getUsersUsername(userInfo.uid_));
3426 __SS__ <<
"requestType Request, " << requestType <<
", not recognized."
3431 catch(
const std::runtime_error& e)
3433 __SS__ <<
"An error was encountered handling requestType '" << requestType
3434 <<
"':" << e.what() << __E__;
3435 __COUT__ <<
"\n" << ss.str();
3436 xmlOut.addTextElementToData(
"Error", ss.str());
3440 __SS__ <<
"An unknown error was encountered handling requestType '" << requestType
3442 <<
"Please check the printouts to debug." << __E__;
3443 __COUT__ <<
"\n" << ss.str();
3444 xmlOut.addTextElementToData(
"Error", ss.str());
3448 xmlOut.outputXmlDocument(
3449 (std::ostringstream*)out,
3460 void GatewaySupervisor::launchStartOTSCommand(
const std::string& command,
3463 __COUT__ <<
"launch StartOTS Command = " << command << __E__;
3464 __COUT__ <<
"Extracting target context hostnames... " << __E__;
3466 std::vector<std::string> hostnames;
3473 auto contexts = contextTable->getContexts();
3475 for(
const auto& context : contexts)
3477 if(!context.status_)
3482 for(i = 0; i < context.address_.size(); ++i)
3483 if(context.address_[i] ==
'/')
3485 hostnames.push_back(context.address_.substr(j));
3486 __COUT__ <<
"StartOTS.sh hostname = " << hostnames.back() << __E__;
3491 __SS__ <<
"\nRelaunch of otsdaq interrupted! "
3492 <<
"The Configuration Manager could not be initialized." << __E__;
3497 for(
const auto& hostname : hostnames)
3499 std::string fn = (std::string(__ENV__(
"SERVICE_DATA_PATH")) +
3500 "/StartOTS_action_" + hostname +
".cmd");
3501 FILE* fp = fopen(fn.c_str(),
"w");
3504 fprintf(fp, command.c_str());
3509 __SS__ <<
"Unable to open command file: " << fn << __E__;
3517 for(
const auto& hostname : hostnames)
3519 std::string fn = (std::string(__ENV__(
"SERVICE_DATA_PATH")) +
3520 "/StartOTS_action_" + hostname +
".cmd");
3521 FILE* fp = fopen(fn.c_str(),
"r");
3525 fgets(line, 100, fp);
3528 if(strcmp(line, command.c_str()) == 0)
3530 __SS__ <<
"The command looks to have been ignored by " << hostname
3531 <<
". Is StartOTS.sh still running on that node?" << __E__;
3538 __SS__ <<
"Unable to open command file for verification: " << fn << __E__;
3547 xoap::MessageReference GatewaySupervisor::supervisorCookieCheck(
3548 xoap::MessageReference message)
3555 parameters.addParameter(
"CookieCode");
3556 parameters.addParameter(
"RefreshOption");
3557 parameters.addParameter(
"IPAddress");
3558 SOAPUtilities::receive(message, parameters);
3559 std::string cookieCode = parameters.getValue(
"CookieCode");
3560 std::string refreshOption =
3561 parameters.getValue(
"RefreshOption");
3563 std::string ipAddress =
3564 parameters.getValue(
"IPAddress");
3570 std::map<std::string , WebUsers::permissionLevel_t>
3571 userGroupPermissionsMap;
3572 std::string userWithLock =
"";
3573 uint64_t activeSessionIndex, uid;
3574 theWebUsers_.cookieCodeIsActiveForRequest(cookieCode,
3575 &userGroupPermissionsMap,
3578 refreshOption ==
"1",
3580 &activeSessionIndex);
3586 retParameters.addParameter(
"CookieCode", cookieCode);
3587 retParameters.addParameter(
3588 "Permissions", StringMacros::mapToString(userGroupPermissionsMap).c_str());
3589 retParameters.addParameter(
"UserWithLock", userWithLock);
3590 retParameters.addParameter(
"Username", theWebUsers_.getUsersUsername(uid));
3591 retParameters.addParameter(
"DisplayName", theWebUsers_.getUsersDisplayName(uid));
3592 sprintf(tmpStringForConversions_,
"%lu", activeSessionIndex);
3593 retParameters.addParameter(
"ActiveSessionIndex", tmpStringForConversions_);
3597 return SOAPUtilities::makeSOAPMessageReference(
"CookieResponse", retParameters);
3603 xoap::MessageReference GatewaySupervisor::supervisorGetActiveUsers(
3604 xoap::MessageReference message)
3609 SOAPParameters parameters(
"UserList", theWebUsers_.getActiveUsersString());
3610 return SOAPUtilities::makeSOAPMessageReference(
"ActiveUserResponse", parameters);
3617 xoap::MessageReference GatewaySupervisor::supervisorSystemMessage(
3618 xoap::MessageReference message)
3622 parameters.addParameter(
"ToUser");
3623 parameters.addParameter(
"Message");
3624 SOAPUtilities::receive(message, parameters);
3626 __COUT__ <<
"toUser: " << parameters.getValue(
"ToUser").substr(0, 10)
3627 <<
", message: " << parameters.getValue(
"Message").substr(0, 10) << __E__;
3629 theSystemMessenger_.addSystemMessage(parameters.getValue(
"ToUser"),
3630 parameters.getValue(
"Message"));
3631 return SOAPUtilities::makeSOAPMessageReference(
"SystemMessageResponse");
3638 xoap::MessageReference GatewaySupervisor::supervisorSystemLogbookEntry(
3639 xoap::MessageReference message)
3643 parameters.addParameter(
"EntryText");
3644 SOAPUtilities::receive(message, parameters);
3646 __COUT__ <<
"EntryText: " << parameters.getValue(
"EntryText").substr(0, 10) << __E__;
3648 makeSystemLogbookEntry(parameters.getValue(
"EntryText"));
3650 return SOAPUtilities::makeSOAPMessageReference(
"SystemLogbookResponse");
3658 xoap::MessageReference GatewaySupervisor::supervisorLastConfigGroupRequest(
3659 xoap::MessageReference message)
3663 parameters.addParameter(
"ActionOfLastGroup");
3664 SOAPUtilities::receive(message, parameters);
3666 return GatewaySupervisor::lastConfigGroupRequestHandler(parameters);
3675 xoap::MessageReference GatewaySupervisor::lastConfigGroupRequestHandler(
3678 std::string action = parameters.getValue(
"ActionOfLastGroup");
3679 __COUT__ <<
"ActionOfLastGroup: " << action.substr(0, 10) << __E__;
3681 std::string fileName =
"";
3682 if(action ==
"Configured")
3683 fileName = FSM_LAST_CONFIGURED_GROUP_ALIAS_FILE;
3684 else if(action ==
"Started")
3685 fileName = FSM_LAST_STARTED_GROUP_ALIAS_FILE;
3688 __COUT_ERR__ <<
"Invalid last group action requested." << __E__;
3689 return SOAPUtilities::makeSOAPMessageReference(
"LastConfigGroupResponseFailure");
3691 std::string timeString;
3693 loadGroupNameAndKey(fileName, timeString);
3697 retParameters.addParameter(
"GroupName", theGroup.first);
3698 retParameters.addParameter(
"GroupKey", theGroup.second.toString());
3699 retParameters.addParameter(
"GroupAction", action);
3700 retParameters.addParameter(
"GroupActionTime", timeString);
3702 return SOAPUtilities::makeSOAPMessageReference(
"LastConfigGroupResponse",
3713 unsigned int GatewaySupervisor::getNextRunNumber(
const std::string& fsmNameIn)
3715 std::string runNumberFileName = RUN_NUMBER_PATH +
"/";
3716 std::string fsmName = fsmNameIn ==
"" ? activeStateMachineName_ : fsmNameIn;
3718 for(
unsigned int i = 0; i < fsmName.size(); ++i)
3719 if((fsmName[i] >=
'a' && fsmName[i] <=
'z') ||
3720 (fsmName[i] >=
'A' && fsmName[i] <=
'Z') ||
3721 (fsmName[i] >=
'0' && fsmName[i] <=
'9'))
3722 runNumberFileName += fsmName[i];
3723 runNumberFileName += RUN_NUMBER_FILE_NAME;
3726 std::ifstream runNumberFile(runNumberFileName.c_str());
3727 if(!runNumberFile.is_open())
3729 __COUT__ <<
"Can't open file: " << runNumberFileName << __E__;
3731 __COUT__ <<
"Creating file and setting Run Number to 1: " << runNumberFileName
3733 FILE* fp = fopen(runNumberFileName.c_str(),
"w");
3737 runNumberFile.open(runNumberFileName.c_str());
3738 if(!runNumberFile.is_open())
3740 __SS__ <<
"Error. Can't create file: " << runNumberFileName << __E__;
3741 __COUT_ERR__ << ss.str();
3745 std::string runNumberString;
3746 runNumberFile >> runNumberString;
3747 runNumberFile.close();
3748 return atoi(runNumberString.c_str());
3752 bool GatewaySupervisor::setNextRunNumber(
unsigned int runNumber,
3753 const std::string& fsmNameIn)
3755 std::string runNumberFileName = RUN_NUMBER_PATH +
"/";
3756 std::string fsmName = fsmNameIn ==
"" ? activeStateMachineName_ : fsmNameIn;
3758 for(
unsigned int i = 0; i < fsmName.size(); ++i)
3759 if((fsmName[i] >=
'a' && fsmName[i] <=
'z') ||
3760 (fsmName[i] >=
'A' && fsmName[i] <=
'Z') ||
3761 (fsmName[i] >=
'0' && fsmName[i] <=
'9'))
3762 runNumberFileName += fsmName[i];
3763 runNumberFileName += RUN_NUMBER_FILE_NAME;
3764 __COUT__ <<
"runNumberFileName: " << runNumberFileName << __E__;
3766 std::ofstream runNumberFile(runNumberFileName.c_str());
3767 if(!runNumberFile.is_open())
3769 __SS__ <<
"Can't open file: " << runNumberFileName << __E__;
3770 __COUT__ << ss.str();
3773 std::stringstream runNumberStream;
3774 runNumberStream << runNumber;
3775 runNumberFile << runNumberStream.str().c_str();
3776 runNumberFile.close();
3787 GatewaySupervisor::loadGroupNameAndKey(
const std::string& fileName,
3788 std::string& returnedTimeString)
3790 std::string fullPath = FSM_LAST_GROUP_ALIAS_PATH +
"/" + fileName;
3792 FILE* groupFile = fopen(fullPath.c_str(),
"r");
3795 __COUT__ <<
"Can't open file: " << fullPath << __E__;
3797 __COUT__ <<
"Returning empty groupName and key -1" << __E__;
3799 return std::pair<std::string ,
TableGroupKey>(
"", TableGroupKey());
3806 fgets(line, 500, groupFile);
3807 theGroup.first = line;
3809 fgets(line, 500, groupFile);
3811 sscanf(line,
"%d", &key);
3812 theGroup.second = key;
3814 fgets(line, 500, groupFile);
3816 sscanf(line,
"%ld", ×tamp);
3820 returnedTimeString = StringMacros::getTimestampString(timestamp);
3823 __COUT__ <<
"theGroup.first= " << theGroup.first
3824 <<
" theGroup.second= " << theGroup.second << __E__;
3830 void GatewaySupervisor::saveGroupNameAndKey(
3831 const std::pair<std::string /*group name*/, TableGroupKey>& theGroup,
3832 const std::string& fileName)
3834 std::string fullPath = FSM_LAST_GROUP_ALIAS_PATH +
"/" + fileName;
3836 std::ofstream groupFile(fullPath.c_str());
3837 if(!groupFile.is_open())
3839 __SS__ <<
"Error. Can't open file: " << fullPath << __E__;
3840 __COUT_ERR__ <<
"\n" << ss.str();
3843 std::stringstream outss;
3844 outss << theGroup.first <<
"\n" << theGroup.second <<
"\n" << time(0);
3845 groupFile << outss.str().c_str();