1 #include "otsdaq/CoreSupervisors/CoreSupervisorBase.h"
9 const std::string CoreSupervisorBase::WORK_LOOP_DONE =
"Done";
10 const std::string CoreSupervisorBase::WORK_LOOP_WORKING =
"Working";
13 CoreSupervisorBase::CoreSupervisorBase(xdaq::ApplicationStub* stub)
14 : xdaq::Application(stub)
23 , stateMachineWorkLoopManager_(toolbox::task::bind(
25 , stateMachineSemaphore_(toolbox::BSem::FULL)
26 , theRemoteWebUsers_(this,
29 __SUP_COUT__ <<
"Constructor." << __E__;
33 xgi::bind(
this, &CoreSupervisorBase::defaultPageWrapper,
"Default");
34 xgi::bind(
this, &CoreSupervisorBase::requestWrapper,
"Request");
37 this, &CoreSupervisorBase::stateMachineXgiHandler,
"StateMachineXgiHandler");
40 &CoreSupervisorBase::stateMachineStateRequest,
41 "StateMachineStateRequest",
44 &CoreSupervisorBase::stateMachineErrorMessageRequest,
45 "StateMachineErrorMessageRequest",
48 &CoreSupervisorBase::workLoopStatusRequestWrapper,
49 "WorkLoopStatusRequest",
52 &CoreSupervisorBase::applicationStatusRequest,
53 "ApplicationStatusRequest",
56 &CoreSupervisorBase::TRACESupervisorRequest,
57 "TRACESupervisorRequest",
60 __SUP_COUT__ <<
"Constructed. getpid()=" << getpid() <<
" gettid()=" << gettid()
65 CoreSupervisorBase::~CoreSupervisorBase(
void)
67 __SUP_COUT__ <<
"Destructor." << __E__;
69 __SUP_COUT__ <<
"Destructed." << __E__;
73 void CoreSupervisorBase::destroy(
void)
75 __SUP_COUT__ <<
"Destroying..." << __E__;
76 for(
auto& it : theStateMachineImplementation_)
79 theStateMachineImplementation_.clear();
84 void CoreSupervisorBase::defaultPageWrapper(xgi::Input* in, xgi::Output* out)
92 __SUP_COUT__ <<
"Supervisor class " << supervisorClass_ << __E__;
94 std::stringstream pagess;
95 pagess <<
"/WebPath/html/" << supervisorClassNoNamespace_
96 <<
".html?urn=" << this->getApplicationDescriptor()->getLocalId();
98 __SUP_COUT__ <<
"Default page = " << pagess.str() << __E__;
100 *out <<
"<!DOCTYPE HTML><html lang='en'><frameset col='100%' row='100%'><frame src='"
101 << pagess.str() <<
"'></frameset></html>";
107 void CoreSupervisorBase::requestWrapper(xgi::Input* in, xgi::Output* out)
110 out->getHTTPResponseHeader().addHeader(
111 "Access-Control-Allow-Origin",
113 out->getHTTPResponseHeader().addHeader(
"Pragma",
"no-cache");
115 cgicc::Cgicc cgiIn(in);
118 __SUP_COUTT__ <<
"requestType " << requestType
119 <<
" files: " << cgiIn.getFiles().size() << __E__;
128 cgiIn, out, &xmlOut, CorePropertySupervisorBase::allSupervisorInfo_, userInfo))
131 if(requestType ==
"GetUserDisplayName")
133 __COUTV__(userInfo.displayName_);
134 xmlOut.addTextElementToData(
"DisplayName", userInfo.displayName_);
137 !userInfo.NoXmlWhiteSpace_ );
145 if(!userInfo.automatedCommand_)
146 __SUP_COUT__ <<
"requestType: " << requestType << __E__;
148 if(userInfo.NonXMLRequestType_)
154 catch(
const std::runtime_error& e)
156 __SUP_SS__ <<
"An error was encountered handling requestType '" << requestType
157 <<
"':" << e.what() << __E__;
158 __SUP_COUT_ERR__ <<
"\n" << ss.str();
162 __SUP_SS__ <<
"An unknown error was encountered handling requestType '"
163 << requestType <<
".' "
164 <<
"Please check the printouts to debug." << __E__;
169 catch(
const std::exception& e)
171 ss <<
"Exception message: " << e.what();
176 __SUP_COUT_ERR__ <<
"\n" << ss.str();
182 std::chrono::steady_clock::time_point requestStart = std::chrono::steady_clock::now();
183 time_t requestStartTime = time(0);
188 request(requestType, cgiIn, xmlOut, userInfo);
190 catch(
const std::runtime_error& e)
192 __SUP_SS__ <<
"An error was encountered handling requestType '" << requestType
193 <<
"':" << e.what() << __E__;
194 __SUP_COUT_ERR__ <<
"\n" << ss.str();
195 xmlOut.addTextElementToData(
"Error", ss.str());
199 __SUP_SS__ <<
"An unknown error was encountered handling requestType '"
200 << requestType <<
".' "
201 <<
"Please check the printouts to debug." << __E__;
206 catch(
const std::exception& e)
208 ss <<
"Exception message: " << e.what();
213 __SUP_COUT_ERR__ <<
"\n" << ss.str();
214 xmlOut.addTextElementToData(
"Error", ss.str());
216 __SUP_COUTT__ <<
"Request '" << requestType
217 <<
"' time: " << artdaq::TimeUtils::GetElapsedTime(requestStart)
223 size_t numberOfChildren =
224 xmlOut.getRootDataElement()->getChildNodes()->getLength();
225 if(numberOfChildren &&
226 xmlOut.getRootDataElement()->getChildNodes()->item(0)->getNodeType() !=
227 xercesc::DOMNode::TEXT_NODE)
228 numberOfChildren += xmlOut.getRootDataElement()
234 __SUP_COUTT__ <<
"Number of '" << requestType
235 <<
"' xml data element children: " << numberOfChildren << __E__;
237 __SUP_COUTT__ <<
"Request '" << requestType
238 <<
"' time: " << artdaq::TimeUtils::GetElapsedTime(requestStart)
246 !userInfo.NoXmlWhiteSpace_ ,
262 __SUP_COUTT__ <<
"Total '" << requestType <<
"' xml request time: "
263 << artdaq::TimeUtils::GetElapsedTime(requestStart) <<
" = "
264 << time(0) - requestStartTime << __E__;
266 catch(
const std::runtime_error& e)
268 __SUP_SS__ <<
"An error was encountered handling HTTP request:" << e.what() << __E__;
269 __SUP_COUT_ERR__ <<
"\n" << ss.str();
274 __SUP_SS__ <<
"An unknown error was encountered HTTP request. "
275 <<
"Please check the printouts to debug." << __E__;
280 catch(
const std::exception& e)
282 ss <<
"Exception message: " << e.what();
287 __SUP_COUT_ERR__ <<
"\n" << ss.str();
302 __SUP_SS__ <<
"This is the empty Core Supervisor request. Supervisors should "
303 "override this function."
305 __SUP_COUT__ << ss.str();
306 xmlOut.addTextElementToData(
"Error", ss.str());
368 __SUP_COUT__ <<
"This is the empty Core Supervisor non-xml request. Supervisors "
369 "should override this function."
371 out <<
"This is the empty Core Supervisor non-xml request. Supervisors should "
372 "override this function."
382 xoap::MessageReference CoreSupervisorBase::stateMachineXoapHandler(
383 xoap::MessageReference message)
385 __SUP_COUT__ <<
"Soap Handler!" << __E__;
386 stateMachineWorkLoopManager_.removeProcessedRequests();
388 __SUP_COUT__ <<
"Done - Soap Handler!" << __E__;
394 xoap::MessageReference CoreSupervisorBase::workLoopStatusRequestWrapper(
395 xoap::MessageReference message)
398 return workLoopStatusRequest(message);
402 xoap::MessageReference CoreSupervisorBase::workLoopStatusRequest(
403 xoap::MessageReference )
406 return SOAPUtilities::makeSOAPMessageReference(CoreSupervisorBase::WORK_LOOP_DONE);
410 xoap::MessageReference CoreSupervisorBase::applicationStatusRequest(
411 xoap::MessageReference )
416 std::to_string(getpid()) +
":" + std::to_string(gettid()) +
":" +
417 theStateMachine_.getCurrentStateName());
419 const std::string& err = theStateMachine_.getErrorMessage();
431 if(theStateMachine_.isInTransition() ||
432 RunControlStateMachine::theProgressBar_.read() < 100)
437 retParameters.addParameter(
"Status",
438 theStateMachine_.getCurrentTransitionName());
442 retParameters.addParameter(
"Status",
443 theStateMachine_.getProvenanceStateName());
447 retParameters.addParameter(
"Status", theStateMachine_.getCurrentStateName());
450 retParameters.addParameter(
452 (theStateMachine_.getCurrentStateName() ==
"Paused" ?
"Soft-Error:::"
456 retParameters.addParameter(
457 "Progress", RunControlStateMachine::theProgressBar_.readPercentageString());
458 retParameters.addParameter(
463 __SUP_COUTTV__(CorePropertySupervisorBase::isFirstAppInContext());
464 if(CorePropertySupervisorBase::isFirstAppInContext())
466 uint64_t availableLogSpaceKB =
467 CorePropertySupervisorBase::getAvailableLogSpaceKB();
468 uint64_t availableDataSpaceKB =
469 CorePropertySupervisorBase::getAvailableDataSpaceKB();
471 retParameters.addParameter(
"AvailableLogSpaceKB",
472 std::to_string(availableLogSpaceKB));
473 retParameters.addParameter(
"AvailableDataSpaceKB",
474 std::to_string(availableDataSpaceKB));
478 retParameters.addParameter(
"AvailableLogSpaceKB",
"0");
479 retParameters.addParameter(
"AvailableDataSpaceKB",
"0");
482 auto subappInfo = getSubappInfo();
483 retParameters.addParameter(
"Subapps",
484 SupervisorInfo::serializeSubappInfos(subappInfo));
486 return SOAPUtilities::makeSOAPMessageReference(
"applicationStatusRequestReply",
498 unsigned int cnt = 0;
517 if(!theStateMachine_.isInTransition() &&
518 (theStateMachine_.getCurrentStateName() ==
519 RunControlStateMachine::HALTED_STATE_NAME ||
520 theStateMachine_.getCurrentStateName() ==
521 RunControlStateMachine::INITIAL_STATE_NAME))
523 detail = std::string(
"Uptime: ") +
525 CorePropertySupervisorBase::getSupervisorUptime())) +
526 ", Time-in-state: " +
532 for(
const auto& fsm : CoreSupervisorBase::theStateMachineImplementation_)
534 std::string fsmProgressDetail = fsm->getStatusProgressDetail();
535 if(fsmProgressDetail.size())
537 ((cnt++) ?
":" :
"") +
542 __SUP_COUTVS__(20, detail);
545 if(!detail.size() && RunControlStateMachine::getLastCommand() !=
"")
547 detail =
"Last Command: " + RunControlStateMachine::getLastCommand();
548 if(RunControlStateMachine::getLastCommand() ==
549 RunControlStateMachine::CONFIGURE_TRANSITION_NAME)
550 detail +=
" w/" + RunControlStateMachine::getLastAttemptedConfigureGroup();
557 bool CoreSupervisorBase::stateMachineThread(toolbox::task::WorkLoop* workLoop)
559 stateMachineSemaphore_.take();
560 __SUP_COUT__ <<
"Re-sending message..."
561 << SOAPUtilities::translate(
562 stateMachineWorkLoopManager_.getMessage(workLoop))
565 std::string reply =
send(this->getApplicationDescriptor(),
566 stateMachineWorkLoopManager_.getMessage(workLoop));
567 stateMachineWorkLoopManager_.report(workLoop, reply, 100,
true);
568 __SUP_COUT__ <<
"Done with message" << __E__;
569 stateMachineSemaphore_.give();
577 xoap::MessageReference CoreSupervisorBase::stateMachineStateRequest(
578 xoap::MessageReference )
580 __SUP_COUT__ <<
"theStateMachine_.getCurrentStateName() = "
581 << theStateMachine_.getCurrentStateName() << __E__;
582 return SOAPUtilities::makeSOAPMessageReference(
583 theStateMachine_.getCurrentStateName());
587 xoap::MessageReference CoreSupervisorBase::stateMachineErrorMessageRequest(
588 xoap::MessageReference )
591 __SUP_COUT__ <<
"theStateMachine_.getErrorMessage() = "
592 << theStateMachine_.getErrorMessage() << __E__;
595 retParameters.addParameter(
"ErrorMessage", theStateMachine_.getErrorMessage());
596 return SOAPUtilities::makeSOAPMessageReference(
"stateMachineErrorMessageRequestReply",
603 __SUP_COUT__ <<
"CoreSupervisorBase::stateInitial" << __E__;
609 __SUP_COUT__ <<
"CoreSupervisorBase::stateHalted" << __E__;
615 __SUP_COUT__ <<
"CoreSupervisorBase::stateRunning" << __E__;
621 __SUP_COUT__ <<
"CoreSupervisorBase::stateConfigured" << __E__;
627 __SUP_COUT__ <<
"CoreSupervisorBase::statePaused" << __E__;
631 void CoreSupervisorBase::inError(toolbox::fsm::FiniteStateMachine& )
634 __SUP_COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName()
640 void CoreSupervisorBase::enteringError(toolbox::Event::Reference event)
646 toolbox::fsm::FailedEvent& failedEvent =
647 dynamic_cast<toolbox::fsm::FailedEvent&
>(*event);
648 std::ostringstream error;
649 error <<
"Failure performing transition from " << failedEvent.getFromState() <<
" to "
650 << failedEvent.getToState()
651 <<
" exception: " << failedEvent.getException().what();
652 __SUP_COUT_ERR__ << error.str() << __E__;
657 void CoreSupervisorBase::preStateMachineExecutionLoop(
void)
659 RunControlStateMachine::clearIterationWork();
660 RunControlStateMachine::clearSubIterationWork();
662 stateMachinesIterationWorkCount_ = 0;
664 if(RunControlStateMachine::getIterationIndex() == 0 &&
665 RunControlStateMachine::getSubIterationIndex() == 0)
669 subIterationWorkStateMachineIndex_ = -1;
676 __SUP_COUT__ <<
"Iteration " << RunControlStateMachine::getIterationIndex() <<
"."
677 << RunControlStateMachine::getSubIterationIndex() <<
"("
678 << subIterationWorkStateMachineIndex_ <<
")" << __E__;
682 void CoreSupervisorBase::preStateMachineExecution(
unsigned int i)
684 if(i >= theStateMachineImplementation_.size())
686 __SUP_SS__ <<
"State Machine " << i <<
" not found!" << __E__;
690 theStateMachineImplementation_[i]->VStateMachine::setIterationIndex(
691 RunControlStateMachine::getIterationIndex());
692 theStateMachineImplementation_[i]->VStateMachine::setSubIterationIndex(
693 RunControlStateMachine::getSubIterationIndex());
695 theStateMachineImplementation_[i]->VStateMachine::clearIterationWork();
696 theStateMachineImplementation_[i]->VStateMachine::clearSubIterationWork();
699 <<
"theStateMachineImplementation Iteration "
700 << theStateMachineImplementation_[i]->VStateMachine::getIterationIndex() <<
"."
701 << theStateMachineImplementation_[i]->VStateMachine::getSubIterationIndex()
706 void CoreSupervisorBase::postStateMachineExecution(
unsigned int i)
708 if(i >= theStateMachineImplementation_.size())
710 __SUP_SS__ <<
"State Machine " << i <<
" not found!" << __E__;
715 if(theStateMachineImplementation_[i]->VStateMachine::getSubIterationWork())
717 subIterationWorkStateMachineIndex_ = i;
718 RunControlStateMachine::indicateSubIterationWork();
720 __SUP_COUT__ <<
"State machine " << i
721 <<
" is flagged for another sub-iteration..." << __E__;
726 !theStateMachineImplementation_[i]->VStateMachine::getIterationWork();
730 __SUP_COUT__ <<
"State machine " << i
731 <<
" is flagged for another iteration..." << __E__;
732 RunControlStateMachine::indicateIterationWork();
734 ++stateMachinesIterationWorkCount_;
740 void CoreSupervisorBase::postStateMachineExecutionLoop(
void)
742 if(RunControlStateMachine::subIterationWorkFlag_)
743 __SUP_COUT__ <<
"State machine implementation "
744 << subIterationWorkStateMachineIndex_
745 <<
" is flagged for another sub-iteration..." << __E__;
746 else if(RunControlStateMachine::iterationWorkFlag_)
748 << stateMachinesIterationWorkCount_
749 <<
" state machine implementation(s) flagged for another iteration..."
752 __SUP_COUT__ <<
"Done configuration all state machine implementations..."
757 void CoreSupervisorBase::configureInit(
void)
761 if(!(RunControlStateMachine::getIterationIndex() == 0 &&
762 RunControlStateMachine::getSubIterationIndex() == 0))
765 __SUP_COUT__ <<
"configureInit()" << __E__;
768 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
770 .getValue(
"ConfigurationTableGroupName"),
771 TableGroupKey(SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
773 .getValue(
"ConfigurationTableGroupKey")));
775 __SUP_COUT__ <<
"Configuration table group name: " << theGroup.first
776 <<
" key: " << theGroup.second << __E__;
779 StringMacros::systemVariables_[
"ActiveStateMachine"][
"name"] =
780 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
782 .getValue(
"ActiveStateMachineName");
783 StringMacros::systemVariables_[
"ActiveStateMachine"][
"windowName"] =
784 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
786 .getValue(
"ActiveStateMachineWindowName");
787 StringMacros::systemVariables_[
"ActiveStateMachine"][
"runAlias"] =
788 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
790 .getValue(
"ActiveStateMachineRunAlias");
794 std::map<std::string ,
TableVersion> mergeInTables, overrideTables;
797 std::string subsystemCommonList;
800 subsystemCommonList =
801 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
803 .getValue(
"SubsystemCommonList");
807 __COUT__ <<
"Ignoring missing 'SubsystemCommonList' parameter." << __E__;
810 if(!subsystemCommonList.empty())
812 subsystemCommonList =
814 __COUT__ <<
"Transition parameter SubsystemCommonList: "
815 << subsystemCommonList << __E__;
822 std::string subsystemCommonOverrideList;
825 subsystemCommonOverrideList =
826 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
828 .getValue(
"SubsystemCommonOverrideList");
832 __COUT__ <<
"Ignoring missing 'SubsystemCommonOverrideList' parameter."
836 if(!subsystemCommonOverrideList.empty())
838 subsystemCommonOverrideList =
840 __COUT__ <<
"Transition parameter SubsystemCommonOverrideList: "
841 << subsystemCommonOverrideList << __E__;
865 ConfigurationManager::LoadGroupType::ALL_TYPES,
871 catch(
const std::runtime_error& e)
873 __SS__ <<
"Error loading table group '" << theGroup.first <<
"("
874 << theGroup.second <<
")! \n"
875 << e.what() << __E__;
876 __SUP_COUT_ERR__ << ss.str();
880 theStateMachine_.setErrorMessage(ss.str());
881 throw toolbox::fsm::exception::Exception(
884 "CoreSupervisorBase::configureInit" ,
891 __SS__ <<
"Unknown error loading table group '" << theGroup.first <<
"("
892 << theGroup.second <<
")!" << __E__;
897 catch(
const std::exception& e)
899 ss <<
"Exception message: " << e.what();
904 __SUP_COUT_ERR__ << ss.str();
908 theStateMachine_.setErrorMessage(ss.str());
909 throw toolbox::fsm::exception::Exception(
912 "CoreSupervisorBase::configureInit" ,
920 void CoreSupervisorBase::transitionConfiguring(toolbox::Event::Reference )
922 __SUP_COUT__ <<
"transitionConfiguring()" << __E__;
924 CoreSupervisorBase::configureInit();
926 CoreSupervisorBase::transitionConfiguringFSMs();
928 __SUP_COUT__ <<
"Configured." << __E__;
932 void CoreSupervisorBase::transitionConfiguringFSMs()
939 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
940 preStateMachineExecutionLoop();
941 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
944 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
945 i != subIterationWorkStateMachineIndex_)
951 preStateMachineExecution(i);
952 theStateMachineImplementation_[i]->parentSupervisor_ =
954 theStateMachineImplementation_[i]->configure();
957 postStateMachineExecution(i);
959 postStateMachineExecutionLoop();
961 catch(
const std::runtime_error& e)
963 __SUP_SS__ <<
"Error was caught while configuring: " << e.what() << __E__;
964 __SUP_COUT_ERR__ <<
"\n" << ss.str();
965 theStateMachine_.setErrorMessage(ss.str());
966 throw toolbox::fsm::exception::Exception(
969 "CoreSupervisorBase::transitionConfiguringFSMs" ,
977 <<
"Unknown error was caught while configuring. Please checked the logs."
983 catch(
const std::exception& e)
985 ss <<
"Exception message: " << e.what();
990 __SUP_COUT_ERR__ <<
"\n" << ss.str();
991 theStateMachine_.setErrorMessage(ss.str());
992 throw toolbox::fsm::exception::Exception(
995 "CoreSupervisorBase::transitionConfiguringFSMs" ,
1007 const std::string transitionName =
"Halting";
1010 __SUP_COUT__ << transitionName <<
" all state machine implementations..."
1012 preStateMachineExecutionLoop();
1013 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1016 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1017 i != subIterationWorkStateMachineIndex_)
1023 preStateMachineExecution(i);
1024 theStateMachineImplementation_[i]->halt();
1027 postStateMachineExecution(i);
1029 postStateMachineExecutionLoop();
1031 catch(
const std::runtime_error& e)
1034 if(theStateMachine_.getProvenanceStateName() ==
1035 RunControlStateMachine::FAILED_STATE_NAME ||
1036 theStateMachine_.getProvenanceStateName() ==
1037 RunControlStateMachine::HALTED_STATE_NAME)
1039 __SUP_COUT_INFO__ <<
"Error was caught while halting (but ignoring because "
1040 "previous state was '"
1041 << theStateMachine_.getProvenanceStateName()
1042 <<
"'): " << e.what() << __E__;
1046 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1048 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1049 theStateMachine_.setErrorMessage(ss.str());
1050 throw toolbox::fsm::exception::Exception(
1051 "Transition Error" ,
1053 "CoreSupervisorBase::transition" + transitionName ,
1062 if(theStateMachine_.getProvenanceStateName() ==
1063 RunControlStateMachine::FAILED_STATE_NAME ||
1064 theStateMachine_.getProvenanceStateName() ==
1065 RunControlStateMachine::HALTED_STATE_NAME)
1067 __SUP_COUT_INFO__ <<
"Unknown error was caught while halting (but ignoring "
1068 "because previous state was '"
1069 << theStateMachine_.getProvenanceStateName() <<
"')."
1074 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1075 <<
". Please checked the logs." << __E__;
1080 catch(
const std::exception& e)
1082 ss <<
"Exception message: " << e.what();
1087 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1088 theStateMachine_.setErrorMessage(ss.str());
1089 throw toolbox::fsm::exception::Exception(
1090 "Transition Error" ,
1092 "CoreSupervisorBase::transition" + transitionName ,
1105 __SUP_COUT__ <<
"transitionInitializing" << __E__;
1107 CorePropertySupervisorBase::resetPropertiesAreSetup();
1118 void CoreSupervisorBase::transitionPausing(toolbox::Event::Reference )
1120 const std::string transitionName =
"Pausing";
1123 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1124 preStateMachineExecutionLoop();
1125 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1128 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1129 i != subIterationWorkStateMachineIndex_)
1135 preStateMachineExecution(i);
1136 theStateMachineImplementation_[i]->pause();
1139 postStateMachineExecution(i);
1141 postStateMachineExecutionLoop();
1143 catch(
const std::runtime_error& e)
1145 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1147 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1148 theStateMachine_.setErrorMessage(ss.str());
1149 throw toolbox::fsm::exception::Exception(
1150 "Transition Error" ,
1152 "CoreSupervisorBase::transition" + transitionName ,
1159 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1160 <<
". Please checked the logs." << __E__;
1165 catch(
const std::exception& e)
1167 ss <<
"Exception message: " << e.what();
1172 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1173 theStateMachine_.setErrorMessage(ss.str());
1174 throw toolbox::fsm::exception::Exception(
1175 "Transition Error" ,
1177 "CoreSupervisorBase::transition" + transitionName ,
1185 void CoreSupervisorBase::transitionResuming(toolbox::Event::Reference )
1187 const std::string transitionName =
"Resuming";
1190 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1191 preStateMachineExecutionLoop();
1192 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1195 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1196 i != subIterationWorkStateMachineIndex_)
1202 preStateMachineExecution(i);
1203 theStateMachineImplementation_[i]->resume();
1206 postStateMachineExecution(i);
1208 postStateMachineExecutionLoop();
1210 catch(
const std::runtime_error& e)
1212 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1214 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1215 theStateMachine_.setErrorMessage(ss.str());
1216 throw toolbox::fsm::exception::Exception(
1217 "Transition Error" ,
1219 "CoreSupervisorBase::transition" + transitionName ,
1226 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1227 <<
". Please checked the logs." << __E__;
1232 catch(
const std::exception& e)
1234 ss <<
"Exception message: " << e.what();
1239 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1240 theStateMachine_.setErrorMessage(ss.str());
1241 throw toolbox::fsm::exception::Exception(
1242 "Transition Error" ,
1244 "CoreSupervisorBase::transition" + transitionName ,
1252 void CoreSupervisorBase::transitionStarting(toolbox::Event::Reference )
1254 const std::string transitionName =
"Starting";
1255 const std::string runNumber =
1256 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
1258 .getValue(
"RunNumber");
1261 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1262 preStateMachineExecutionLoop();
1263 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1266 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1267 i != subIterationWorkStateMachineIndex_)
1273 preStateMachineExecution(i);
1274 theStateMachineImplementation_[i]->start(runNumber);
1278 postStateMachineExecution(i);
1280 postStateMachineExecutionLoop();
1282 catch(
const std::runtime_error& e)
1284 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1286 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1287 theStateMachine_.setErrorMessage(ss.str());
1288 throw toolbox::fsm::exception::Exception(
1289 "Transition Error" ,
1291 "CoreSupervisorBase::transition" + transitionName ,
1298 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1299 <<
". Please checked the logs." << __E__;
1304 catch(
const std::exception& e)
1306 ss <<
"Exception message: " << e.what();
1311 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1312 theStateMachine_.setErrorMessage(ss.str());
1313 throw toolbox::fsm::exception::Exception(
1314 "Transition Error" ,
1316 "CoreSupervisorBase::transition" + transitionName ,
1324 void CoreSupervisorBase::transitionStopping(toolbox::Event::Reference )
1326 const std::string transitionName =
"Stopping";
1329 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1330 preStateMachineExecutionLoop();
1331 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1334 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1335 i != subIterationWorkStateMachineIndex_)
1341 preStateMachineExecution(i);
1342 theStateMachineImplementation_[i]->stop();
1345 postStateMachineExecution(i);
1347 postStateMachineExecutionLoop();
1349 catch(
const std::runtime_error& e)
1351 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1353 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1354 theStateMachine_.setErrorMessage(ss.str());
1355 throw toolbox::fsm::exception::Exception(
1356 "Transition Error" ,
1358 "CoreSupervisorBase::transition" + transitionName ,
1365 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1366 <<
". Please checked the logs." << __E__;
1371 catch(
const std::exception& e)
1373 ss <<
"Exception message: " << e.what();
1378 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1379 theStateMachine_.setErrorMessage(ss.str());
1380 throw toolbox::fsm::exception::Exception(
1381 "Transition Error" ,
1383 "CoreSupervisorBase::transition" + transitionName ,
1396 bool isPauseException,
1397 bool isStopException)
1401 __SUP_COUT_ERR__ <<
"Sending Supervisor Async STOP Running Exception... \n"
1402 << errorMessage << __E__;
1403 else if(isPauseException)
1404 __SUP_COUT_ERR__ <<
"Sending Supervisor Async SOFT Running Error... \n"
1405 << errorMessage << __E__;
1407 __SUP_COUT_ERR__ <<
"Sending Supervisor Async Running Error... \n"
1408 << errorMessage << __E__;
1410 theStateMachine_.setErrorMessage(errorMessage);
1412 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* gatewaySupervisor =
1416 parameters.addParameter(
"ErrorMessage", errorMessage);
1418 xoap::MessageReference replyMessage = SOAPMessenger::sendWithSOAPReply(
1420 isStopException ?
"AsyncStopException"
1421 : (isPauseException ?
"AsyncPauseException" :
"AsyncError"),
1424 std::stringstream replyMessageSStream;
1425 replyMessageSStream << SOAPUtilities::translate(replyMessage);
1426 __SUP_COUT__ <<
"Received... " << replyMessageSStream.str() << std::endl;
1428 if(replyMessageSStream.str().find(
"Fault") != std::string::npos)
1430 __SUP_COUT_ERR__ <<
"Failure to indicate fault to Gateway..." << __E__;
1434 catch(
const xdaq::exception::Exception& e)
1438 <<
"SOAP message failure indicating Supervisor asynchronous running STOP "
1439 "exception back to Gateway: "
1440 << e.what() << __E__;
1441 else if(isPauseException)
1443 <<
"SOAP message failure indicating Supervisor asynchronous running SOFT "
1444 "exception back to Gateway: "
1445 << e.what() << __E__;
1447 __SUP_COUT__ <<
"SOAP message failure indicating Supervisor asynchronous running "
1448 "error back to Gateway: "
1449 << e.what() << __E__;
1456 <<
"Unknown error encounter indicating Supervisor asynchronous running "
1457 "STOP exception back to Gateway."
1459 else if(isPauseException)
1461 <<
"Unknown error encounter indicating Supervisor asynchronous running "
1462 "SOFT error back to Gateway."
1466 <<
"Unknown error encounter indicating Supervisor asynchronous running "
1467 "error back to Gateway."
1473 xoap::MessageReference CoreSupervisorBase::TRACESupervisorRequest(
1474 xoap::MessageReference message)
1476 return CorePropertySupervisorBase::TRACESupervisorRequest(message);
static std::string getOrPostData(cgicc::Cgicc &cgi, const std::string &needle)
static std::string getData(cgicc::Cgicc &cgi, const std::string &needle)
void loadTableGroup(const std::string &tableGroupName, const TableGroupKey &tableGroupKey, bool doActivate=false, std::map< std::string, TableVersion > *groupMembers=0, ProgressBar *progressBar=0, std::string *accumulateWarnings=0, std::string *groupComment=0, std::string *groupAuthor=0, std::string *groupCreateTime=0, bool doNotLoadMember=false, std::string *groupTypeString=0, std::map< std::string, std::string > *groupAliases=0, ConfigurationManager::LoadGroupType groupTypeToLoad=ConfigurationManager::LoadGroupType::ALL_TYPES, bool ignoreVersionTracking=false, std::map< std::string, TableVersion > mergeInTables={}, std::map< std::string, TableVersion > overrideTables={})
void getRequestUserInfo(WebUsers::RequestUserInfo &requestUserInfo)
virtual void transitionHalting(toolbox::Event::Reference event)
virtual void stateInitial(toolbox::fsm::FiniteStateMachine &fsm)
void stateMachineXgiHandler(xgi::Input *in, xgi::Output *out)
State Machine request handlers.
virtual void request(const std::string &requestType, cgicc::Cgicc &cgiIn, HttpXmlDocument &xmlOut, const WebUsers::RequestUserInfo &userInfo)
virtual void stateConfigured(toolbox::fsm::FiniteStateMachine &fsm)
virtual std::string getStatusProgressDetail(void)
virtual void statePaused(toolbox::fsm::FiniteStateMachine &fsm)
virtual void stateRunning(toolbox::fsm::FiniteStateMachine &fsm)
virtual void transitionInitializing(toolbox::Event::Reference event)
virtual void defaultPage(xgi::Input *in, xgi::Output *out)
virtual void nonXmlRequest(const std::string &requestType, cgicc::Cgicc &cgiIn, std::ostream &out, const WebUsers::RequestUserInfo &userInfo)
std::vector< bool > stateMachinesIterationDone_
for managing transition iterations
void sendAsyncExceptionToGateway(const std::string &errMsg, bool isPauseException, bool isStopException)
virtual void stateHalted(toolbox::fsm::FiniteStateMachine &fsm)
time_t getTimeInState(void) const
void outputXmlDocument(std::ostringstream *out, bool dispStdOut=false, bool allowWhiteSpace=false, bool printErrors=false)
bool xmlRequestToGateway(cgicc::Cgicc &cgi, std::ostringstream *out, HttpXmlDocument *xmldoc, const AllSupervisorInfo &allSupervisorInfo, WebUsers::RequestUserInfo &userInfo)
std::string send(XDAQ_CONST_CALL xdaq::ApplicationDescriptor *d, xoap::MessageReference message)
XDAQ_CONST_CALL xdaq::ApplicationDescriptor * getDescriptor(void) const
Getters ----------------—.
HttpXmlDocument processRequest(cgicc::Cgicc &cgi)
defines used also by OtsConfigurationWizardSupervisor
void INIT_MF(const char *name)
static std::string mapToString(const std::map< std::string, T > &mapToReturn, const std::string &primaryDelimeter=", ", const std::string &secondaryDelimeter=": ")
static void getMapFromString(const std::string &inputString, std::map< S, T > &mapToReturn, const std::set< char > &pairPairDelimiter={',', '|', '&'}, const std::set< char > &nameValueDelimiter={'=', ':'}, const std::set< char > &whitespace={' ', '\t', '\n', '\r'})
getMapFromString ~
static std::string getTimeDurationString(const time_t durationInSeconds=time(0))
static std::string decodeURIComponent(const std::string &data)