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__;
852 theConfigurationManager_);
867 ConfigurationManager::LoadGroupType::ALL_TYPES,
873 catch(
const std::runtime_error& e)
875 __SS__ <<
"Error loading table group '" << theGroup.first <<
"("
876 << theGroup.second <<
")! \n"
877 << e.what() << __E__;
878 __SUP_COUT_ERR__ << ss.str();
882 theStateMachine_.setErrorMessage(ss.str());
883 throw toolbox::fsm::exception::Exception(
886 "CoreSupervisorBase::configureInit" ,
893 __SS__ <<
"Unknown error loading table group '" << theGroup.first <<
"("
894 << theGroup.second <<
")!" << __E__;
899 catch(
const std::exception& e)
901 ss <<
"Exception message: " << e.what();
906 __SUP_COUT_ERR__ << ss.str();
910 theStateMachine_.setErrorMessage(ss.str());
911 throw toolbox::fsm::exception::Exception(
914 "CoreSupervisorBase::configureInit" ,
922 void CoreSupervisorBase::transitionConfiguring(toolbox::Event::Reference )
924 __SUP_COUT__ <<
"transitionConfiguring()" << __E__;
926 CoreSupervisorBase::configureInit();
928 CoreSupervisorBase::transitionConfiguringFSMs();
930 __SUP_COUT__ <<
"Configured." << __E__;
934 void CoreSupervisorBase::transitionConfiguringFSMs()
941 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
942 preStateMachineExecutionLoop();
943 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
946 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
947 i != subIterationWorkStateMachineIndex_)
953 preStateMachineExecution(i);
954 theStateMachineImplementation_[i]->parentSupervisor_ =
956 theStateMachineImplementation_[i]->configure();
959 postStateMachineExecution(i);
961 postStateMachineExecutionLoop();
963 catch(
const std::runtime_error& e)
965 __SUP_SS__ <<
"Error was caught while configuring: " << e.what() << __E__;
966 __SUP_COUT_ERR__ <<
"\n" << ss.str();
967 theStateMachine_.setErrorMessage(ss.str());
968 throw toolbox::fsm::exception::Exception(
971 "CoreSupervisorBase::transitionConfiguringFSMs" ,
979 <<
"Unknown error was caught while configuring. Please checked the logs."
985 catch(
const std::exception& e)
987 ss <<
"Exception message: " << e.what();
992 __SUP_COUT_ERR__ <<
"\n" << ss.str();
993 theStateMachine_.setErrorMessage(ss.str());
994 throw toolbox::fsm::exception::Exception(
997 "CoreSupervisorBase::transitionConfiguringFSMs" ,
1009 const std::string transitionName =
"Halting";
1012 __SUP_COUT__ << transitionName <<
" all state machine implementations..."
1014 preStateMachineExecutionLoop();
1015 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1018 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1019 i != subIterationWorkStateMachineIndex_)
1025 preStateMachineExecution(i);
1026 theStateMachineImplementation_[i]->halt();
1029 postStateMachineExecution(i);
1031 postStateMachineExecutionLoop();
1033 catch(
const std::runtime_error& e)
1036 if(theStateMachine_.getProvenanceStateName() ==
1037 RunControlStateMachine::FAILED_STATE_NAME ||
1038 theStateMachine_.getProvenanceStateName() ==
1039 RunControlStateMachine::HALTED_STATE_NAME)
1041 __SUP_COUT_INFO__ <<
"Error was caught while halting (but ignoring because "
1042 "previous state was '"
1043 << theStateMachine_.getProvenanceStateName()
1044 <<
"'): " << e.what() << __E__;
1048 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1050 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1051 theStateMachine_.setErrorMessage(ss.str());
1052 throw toolbox::fsm::exception::Exception(
1053 "Transition Error" ,
1055 "CoreSupervisorBase::transition" + transitionName ,
1064 if(theStateMachine_.getProvenanceStateName() ==
1065 RunControlStateMachine::FAILED_STATE_NAME ||
1066 theStateMachine_.getProvenanceStateName() ==
1067 RunControlStateMachine::HALTED_STATE_NAME)
1069 __SUP_COUT_INFO__ <<
"Unknown error was caught while halting (but ignoring "
1070 "because previous state was '"
1071 << theStateMachine_.getProvenanceStateName() <<
"')."
1076 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1077 <<
". Please checked the logs." << __E__;
1082 catch(
const std::exception& e)
1084 ss <<
"Exception message: " << e.what();
1089 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1090 theStateMachine_.setErrorMessage(ss.str());
1091 throw toolbox::fsm::exception::Exception(
1092 "Transition Error" ,
1094 "CoreSupervisorBase::transition" + transitionName ,
1107 __SUP_COUT__ <<
"transitionInitializing" << __E__;
1109 CorePropertySupervisorBase::resetPropertiesAreSetup();
1120 void CoreSupervisorBase::transitionPausing(toolbox::Event::Reference )
1122 const std::string transitionName =
"Pausing";
1125 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1126 preStateMachineExecutionLoop();
1127 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1130 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1131 i != subIterationWorkStateMachineIndex_)
1137 preStateMachineExecution(i);
1138 theStateMachineImplementation_[i]->pause();
1141 postStateMachineExecution(i);
1143 postStateMachineExecutionLoop();
1145 catch(
const std::runtime_error& e)
1147 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1149 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1150 theStateMachine_.setErrorMessage(ss.str());
1151 throw toolbox::fsm::exception::Exception(
1152 "Transition Error" ,
1154 "CoreSupervisorBase::transition" + transitionName ,
1161 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1162 <<
". Please checked the logs." << __E__;
1167 catch(
const std::exception& e)
1169 ss <<
"Exception message: " << e.what();
1174 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1175 theStateMachine_.setErrorMessage(ss.str());
1176 throw toolbox::fsm::exception::Exception(
1177 "Transition Error" ,
1179 "CoreSupervisorBase::transition" + transitionName ,
1187 void CoreSupervisorBase::transitionResuming(toolbox::Event::Reference )
1189 const std::string transitionName =
"Resuming";
1192 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1193 preStateMachineExecutionLoop();
1194 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1197 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1198 i != subIterationWorkStateMachineIndex_)
1204 preStateMachineExecution(i);
1205 theStateMachineImplementation_[i]->resume();
1208 postStateMachineExecution(i);
1210 postStateMachineExecutionLoop();
1212 catch(
const std::runtime_error& e)
1214 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1216 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1217 theStateMachine_.setErrorMessage(ss.str());
1218 throw toolbox::fsm::exception::Exception(
1219 "Transition Error" ,
1221 "CoreSupervisorBase::transition" + transitionName ,
1228 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1229 <<
". Please checked the logs." << __E__;
1234 catch(
const std::exception& e)
1236 ss <<
"Exception message: " << e.what();
1241 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1242 theStateMachine_.setErrorMessage(ss.str());
1243 throw toolbox::fsm::exception::Exception(
1244 "Transition Error" ,
1246 "CoreSupervisorBase::transition" + transitionName ,
1254 void CoreSupervisorBase::transitionStarting(toolbox::Event::Reference )
1256 const std::string transitionName =
"Starting";
1257 const std::string runNumber =
1258 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
1260 .getValue(
"RunNumber");
1263 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1264 preStateMachineExecutionLoop();
1265 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1268 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1269 i != subIterationWorkStateMachineIndex_)
1275 preStateMachineExecution(i);
1276 theStateMachineImplementation_[i]->start(runNumber);
1280 postStateMachineExecution(i);
1282 postStateMachineExecutionLoop();
1284 catch(
const std::runtime_error& e)
1286 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1288 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1289 theStateMachine_.setErrorMessage(ss.str());
1290 throw toolbox::fsm::exception::Exception(
1291 "Transition Error" ,
1293 "CoreSupervisorBase::transition" + transitionName ,
1300 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1301 <<
". Please checked the logs." << __E__;
1306 catch(
const std::exception& e)
1308 ss <<
"Exception message: " << e.what();
1313 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1314 theStateMachine_.setErrorMessage(ss.str());
1315 throw toolbox::fsm::exception::Exception(
1316 "Transition Error" ,
1318 "CoreSupervisorBase::transition" + transitionName ,
1326 void CoreSupervisorBase::transitionStopping(toolbox::Event::Reference )
1328 const std::string transitionName =
"Stopping";
1331 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1332 preStateMachineExecutionLoop();
1333 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1336 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1337 i != subIterationWorkStateMachineIndex_)
1343 preStateMachineExecution(i);
1344 theStateMachineImplementation_[i]->stop();
1347 postStateMachineExecution(i);
1349 postStateMachineExecutionLoop();
1351 catch(
const std::runtime_error& e)
1353 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1355 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1356 theStateMachine_.setErrorMessage(ss.str());
1357 throw toolbox::fsm::exception::Exception(
1358 "Transition Error" ,
1360 "CoreSupervisorBase::transition" + transitionName ,
1367 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1368 <<
". Please checked the logs." << __E__;
1373 catch(
const std::exception& e)
1375 ss <<
"Exception message: " << e.what();
1380 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1381 theStateMachine_.setErrorMessage(ss.str());
1382 throw toolbox::fsm::exception::Exception(
1383 "Transition Error" ,
1385 "CoreSupervisorBase::transition" + transitionName ,
1398 bool isPauseException,
1399 bool isStopException)
1403 __SUP_COUT_ERR__ <<
"Sending Supervisor Async STOP Running Exception... \n"
1404 << errorMessage << __E__;
1405 else if(isPauseException)
1406 __SUP_COUT_ERR__ <<
"Sending Supervisor Async SOFT Running Error... \n"
1407 << errorMessage << __E__;
1409 __SUP_COUT_ERR__ <<
"Sending Supervisor Async Running Error... \n"
1410 << errorMessage << __E__;
1412 theStateMachine_.setErrorMessage(errorMessage);
1414 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* gatewaySupervisor =
1418 parameters.addParameter(
"ErrorMessage", errorMessage);
1420 xoap::MessageReference replyMessage = SOAPMessenger::sendWithSOAPReply(
1422 isStopException ?
"AsyncStopException"
1423 : (isPauseException ?
"AsyncPauseException" :
"AsyncError"),
1426 std::stringstream replyMessageSStream;
1427 replyMessageSStream << SOAPUtilities::translate(replyMessage);
1428 __SUP_COUT__ <<
"Received... " << replyMessageSStream.str() << std::endl;
1430 if(replyMessageSStream.str().find(
"Fault") != std::string::npos)
1432 __SUP_COUT_ERR__ <<
"Failure to indicate fault to Gateway..." << __E__;
1436 catch(
const xdaq::exception::Exception& e)
1440 <<
"SOAP message failure indicating Supervisor asynchronous running STOP "
1441 "exception back to Gateway: "
1442 << e.what() << __E__;
1443 else if(isPauseException)
1445 <<
"SOAP message failure indicating Supervisor asynchronous running SOFT "
1446 "exception back to Gateway: "
1447 << e.what() << __E__;
1449 __SUP_COUT__ <<
"SOAP message failure indicating Supervisor asynchronous running "
1450 "error back to Gateway: "
1451 << e.what() << __E__;
1458 <<
"Unknown error encounter indicating Supervisor asynchronous running "
1459 "STOP exception back to Gateway."
1461 else if(isPauseException)
1463 <<
"Unknown error encounter indicating Supervisor asynchronous running "
1464 "SOFT error back to Gateway."
1468 <<
"Unknown error encounter indicating Supervisor asynchronous running "
1469 "error back to Gateway."
1475 xoap::MessageReference CoreSupervisorBase::TRACESupervisorRequest(
1476 xoap::MessageReference message)
1478 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)