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 &CoreSupervisorBase::minReadyForEventGenerationStartIterationRequest,
61 "MinReadyForEventGenerationStartIterationRequest",
64 &CoreSupervisorBase::minReadyForEventGenerationStartIterationRequest,
65 "MinReadyForEventGenerationStartIterationRequest",
68 __SUP_COUT__ <<
"Constructed. getpid()=" << getpid() <<
" gettid()=" << gettid()
73 CoreSupervisorBase::~CoreSupervisorBase(
void)
75 __SUP_COUT__ <<
"Destructor." << __E__;
77 __SUP_COUT__ <<
"Destructed." << __E__;
81 void CoreSupervisorBase::destroy(
void)
83 __SUP_COUT__ <<
"Destroying..." << __E__;
84 for(
auto& it : theStateMachineImplementation_)
87 theStateMachineImplementation_.clear();
92 void CoreSupervisorBase::defaultPageWrapper(xgi::Input* in, xgi::Output* out)
100 __SUP_COUT__ <<
"Supervisor class " << supervisorClass_ << __E__;
102 std::stringstream pagess;
103 pagess <<
"/WebPath/html/" << supervisorClassNoNamespace_
104 <<
".html?urn=" << this->getApplicationDescriptor()->getLocalId();
106 __SUP_COUT__ <<
"Default page = " << pagess.str() << __E__;
108 *out <<
"<!DOCTYPE HTML><html lang='en'><frameset col='100%' row='100%'><frame src='"
109 << pagess.str() <<
"'></frameset></html>";
115 void CoreSupervisorBase::requestWrapper(xgi::Input* in, xgi::Output* out)
118 out->getHTTPResponseHeader().addHeader(
119 "Access-Control-Allow-Origin",
121 out->getHTTPResponseHeader().addHeader(
"Pragma",
"no-cache");
123 cgicc::Cgicc cgiIn(in);
126 __SUP_COUTT__ <<
"requestType " << requestType
127 <<
" files: " << cgiIn.getFiles().size() << __E__;
136 cgiIn, out, &xmlOut, CorePropertySupervisorBase::allSupervisorInfo_, userInfo))
139 if(requestType ==
"GetUserDisplayName")
141 __COUTV__(userInfo.displayName_);
142 xmlOut.addTextElementToData(
"DisplayName", userInfo.displayName_);
145 !userInfo.NoXmlWhiteSpace_ );
153 if(!userInfo.automatedCommand_)
154 __SUP_COUTT__ <<
"DIAG ms=" << StringMacros::nowEpochMs()
155 <<
" requestType: " << requestType << __E__;
157 if(userInfo.NonXMLRequestType_)
163 catch(
const std::runtime_error& e)
165 __SUP_SS__ <<
"An error was encountered handling requestType '" << requestType
166 <<
"':" << e.what() << __E__;
167 __SUP_COUT_ERR__ <<
"\n" << ss.str();
171 __SUP_SS__ <<
"An unknown error was encountered handling requestType '"
172 << requestType <<
".' "
173 <<
"Please check the printouts to debug." << __E__;
178 catch(
const std::exception& e)
180 ss <<
"Exception message: " << e.what();
185 __SUP_COUT_ERR__ <<
"\n" << ss.str();
191 std::chrono::steady_clock::time_point requestStart = std::chrono::steady_clock::now();
192 time_t requestStartTime = time(0);
197 request(requestType, cgiIn, xmlOut, userInfo);
199 catch(
const std::runtime_error& e)
201 __SUP_SS__ <<
"An error was encountered handling requestType '" << requestType
202 <<
"':" << e.what() << __E__;
203 __SUP_COUT_ERR__ <<
"\n" << ss.str();
204 xmlOut.addTextElementToData(
"Error", ss.str());
208 __SUP_SS__ <<
"An unknown error was encountered handling requestType '"
209 << requestType <<
".' "
210 <<
"Please check the printouts to debug." << __E__;
215 catch(
const std::exception& e)
217 ss <<
"Exception message: " << e.what();
222 __SUP_COUT_ERR__ <<
"\n" << ss.str();
223 xmlOut.addTextElementToData(
"Error", ss.str());
225 __SUP_COUTT__ <<
"Request '" << requestType
226 <<
"' time: " << artdaq::TimeUtils::GetElapsedTime(requestStart)
232 size_t numberOfChildren =
233 xmlOut.getRootDataElement()->getChildNodes()->getLength();
234 if(numberOfChildren &&
235 xmlOut.getRootDataElement()->getChildNodes()->item(0)->getNodeType() !=
236 xercesc::DOMNode::TEXT_NODE)
237 numberOfChildren += xmlOut.getRootDataElement()
243 __SUP_COUTT__ <<
"Number of '" << requestType
244 <<
"' xml data element children: " << numberOfChildren << __E__;
246 __SUP_COUTT__ <<
"Request '" << requestType
247 <<
"' time: " << artdaq::TimeUtils::GetElapsedTime(requestStart)
255 !userInfo.NoXmlWhiteSpace_ ,
258 if(!userInfo.automatedCommand_)
259 __SUP_COUTT__ <<
"DIAG ms=" << StringMacros::nowEpochMs()
260 <<
" requestType: " << requestType <<
" response written, elapsed="
261 << artdaq::TimeUtils::GetElapsedTime(requestStart) <<
"s" << __E__;
276 __SUP_COUTT__ <<
"Total '" << requestType <<
"' xml request time: "
277 << artdaq::TimeUtils::GetElapsedTime(requestStart) <<
" = "
278 << time(0) - requestStartTime << __E__;
280 catch(
const std::runtime_error& e)
282 __SUP_SS__ <<
"An error was encountered handling HTTP request:" << e.what() << __E__;
283 __SUP_COUT_ERR__ <<
"\n" << ss.str();
288 __SUP_SS__ <<
"An unknown error was encountered HTTP request. "
289 <<
"Please check the printouts to debug." << __E__;
294 catch(
const std::exception& e)
296 ss <<
"Exception message: " << e.what();
301 __SUP_COUT_ERR__ <<
"\n" << ss.str();
316 __SUP_SS__ <<
"This is the empty Core Supervisor request. Supervisors should "
317 "override this function."
319 __SUP_COUT__ << ss.str();
320 xmlOut.addTextElementToData(
"Error", ss.str());
382 __SUP_COUT__ <<
"This is the empty Core Supervisor non-xml request. Supervisors "
383 "should override this function."
385 out <<
"This is the empty Core Supervisor non-xml request. Supervisors should "
386 "override this function."
396 xoap::MessageReference CoreSupervisorBase::stateMachineXoapHandler(
397 xoap::MessageReference message)
399 __SUP_COUT__ <<
"Soap Handler!" << __E__;
400 stateMachineWorkLoopManager_.removeProcessedRequests();
402 __SUP_COUT__ <<
"Done - Soap Handler!" << __E__;
408 xoap::MessageReference CoreSupervisorBase::workLoopStatusRequestWrapper(
409 xoap::MessageReference message)
412 return workLoopStatusRequest(message);
416 xoap::MessageReference CoreSupervisorBase::workLoopStatusRequest(
417 xoap::MessageReference )
420 return SOAPUtilities::makeSOAPMessageReference(CoreSupervisorBase::WORK_LOOP_DONE);
424 xoap::MessageReference CoreSupervisorBase::applicationStatusRequest(
425 xoap::MessageReference )
430 std::to_string(getpid()) +
":" + std::to_string(gettid()) +
":" +
431 theStateMachine_.getCurrentStateName());
433 const std::string& err = theStateMachine_.getErrorMessage();
445 if(theStateMachine_.isInTransition() ||
446 RunControlStateMachine::theProgressBar_.read() < 100)
451 retParameters.addParameter(
"Status",
452 theStateMachine_.getCurrentTransitionName());
456 retParameters.addParameter(
"Status",
457 theStateMachine_.getProvenanceStateName());
461 retParameters.addParameter(
"Status", theStateMachine_.getCurrentStateName());
464 retParameters.addParameter(
466 (theStateMachine_.getCurrentStateName() ==
"Paused" ?
"Soft-Error:::"
470 retParameters.addParameter(
471 "Progress", RunControlStateMachine::theProgressBar_.readPercentageString());
472 retParameters.addParameter(
477 __SUP_COUTVS__(19, CorePropertySupervisorBase::isFirstAppInContext());
478 if(CorePropertySupervisorBase::isFirstAppInContext())
480 uint64_t availableLogSpaceKB =
481 CorePropertySupervisorBase::getAvailableLogSpaceKB();
482 uint64_t availableDataSpaceKB =
483 CorePropertySupervisorBase::getAvailableDataSpaceKB();
485 retParameters.addParameter(
"AvailableLogSpaceKB",
486 std::to_string(availableLogSpaceKB));
487 retParameters.addParameter(
"AvailableDataSpaceKB",
488 std::to_string(availableDataSpaceKB));
492 retParameters.addParameter(
"AvailableLogSpaceKB",
"0");
493 retParameters.addParameter(
"AvailableDataSpaceKB",
"0");
496 auto subappInfo = getSubappInfo();
497 retParameters.addParameter(
"Subapps",
498 SupervisorInfo::serializeSubappInfos(subappInfo));
500 return SOAPUtilities::makeSOAPMessageReference(
"applicationStatusRequestReply",
505 xoap::MessageReference
506 CoreSupervisorBase::minReadyForEventGenerationStartIterationRequest(
507 xoap::MessageReference )
509 unsigned int maxIteration = 0;
510 for(
const auto& fsm : theStateMachineImplementation_)
512 unsigned int val = fsm->getMinReadyForEventGenerationStartIteration();
513 if(val > maxIteration)
517 __SUP_COUT__ <<
"MinReadyForEventGenerationStartIteration (aggregated max) = "
518 << maxIteration << __E__;
521 retParameters.addParameter(
"MinIteration", std::to_string(maxIteration));
522 return SOAPUtilities::makeSOAPMessageReference(
523 "MinReadyForEventGenerationStartIterationRequestReply", retParameters);
534 unsigned int cnt = 0;
553 if(!theStateMachine_.isInTransition() &&
554 (theStateMachine_.getCurrentStateName() ==
555 RunControlStateMachine::HALTED_STATE_NAME ||
556 theStateMachine_.getCurrentStateName() ==
557 RunControlStateMachine::INITIAL_STATE_NAME))
559 detail = std::string(
"Uptime: ") +
561 CorePropertySupervisorBase::getSupervisorUptime())) +
562 ", Time-in-state: " +
568 for(
const auto& fsm : CoreSupervisorBase::theStateMachineImplementation_)
570 std::string fsmProgressDetail = fsm->getStatusProgressDetail();
571 if(fsmProgressDetail.size())
573 ((cnt++) ?
":" :
"") +
578 __SUP_COUTVS__(20, detail);
581 if(!detail.size() && RunControlStateMachine::getLastCommand() !=
"")
583 detail =
"Last Command: " + RunControlStateMachine::getLastCommand();
584 if(RunControlStateMachine::getLastCommand() ==
585 RunControlStateMachine::CONFIGURE_TRANSITION_NAME)
586 detail +=
" w/" + RunControlStateMachine::getLastAttemptedConfigureGroup();
593 bool CoreSupervisorBase::stateMachineThread(toolbox::task::WorkLoop* workLoop)
595 stateMachineSemaphore_.take();
596 __SUP_COUT__ <<
"Re-sending message..."
597 << SOAPUtilities::translate(
598 stateMachineWorkLoopManager_.getMessage(workLoop))
601 std::string reply =
send(this->getApplicationDescriptor(),
602 stateMachineWorkLoopManager_.getMessage(workLoop));
603 stateMachineWorkLoopManager_.report(workLoop, reply, 100,
true);
604 __SUP_COUT__ <<
"Done with message" << __E__;
605 stateMachineSemaphore_.give();
613 xoap::MessageReference CoreSupervisorBase::stateMachineStateRequest(
614 xoap::MessageReference )
616 __SUP_COUT__ <<
"theStateMachine_.getCurrentStateName() = "
617 << theStateMachine_.getCurrentStateName() << __E__;
618 return SOAPUtilities::makeSOAPMessageReference(
619 theStateMachine_.getCurrentStateName());
623 xoap::MessageReference CoreSupervisorBase::stateMachineErrorMessageRequest(
624 xoap::MessageReference )
627 __SUP_COUT__ <<
"theStateMachine_.getErrorMessage() = "
628 << theStateMachine_.getErrorMessage() << __E__;
631 retParameters.addParameter(
"ErrorMessage", theStateMachine_.getErrorMessage());
632 return SOAPUtilities::makeSOAPMessageReference(
"stateMachineErrorMessageRequestReply",
639 __SUP_COUT__ <<
"CoreSupervisorBase::stateInitial" << __E__;
645 __SUP_COUT__ <<
"CoreSupervisorBase::stateHalted" << __E__;
651 __SUP_COUT__ <<
"CoreSupervisorBase::stateRunning" << __E__;
657 __SUP_COUT__ <<
"CoreSupervisorBase::stateConfigured" << __E__;
663 __SUP_COUT__ <<
"CoreSupervisorBase::statePaused" << __E__;
667 void CoreSupervisorBase::inError(toolbox::fsm::FiniteStateMachine& )
670 __SUP_COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName()
676 void CoreSupervisorBase::enteringError(toolbox::Event::Reference event)
682 toolbox::fsm::FailedEvent& failedEvent =
683 dynamic_cast<toolbox::fsm::FailedEvent&
>(*event);
684 std::ostringstream error;
685 error <<
"Failure performing transition from " << failedEvent.getFromState() <<
" to "
686 << failedEvent.getToState()
687 <<
" exception: " << failedEvent.getException().what();
688 __SUP_COUT_ERR__ << error.str() << __E__;
693 void CoreSupervisorBase::preStateMachineExecutionLoop(
void)
695 RunControlStateMachine::clearSubsystemIterationWork();
696 RunControlStateMachine::clearIterationWork();
697 RunControlStateMachine::clearSubIterationWork();
699 stateMachinesIterationWorkCount_ = 0;
705 subIterationWorkStateMachineIndex_ = -1;
712 lastSubsystemIterationIndexSeen_ =
713 RunControlStateMachine::getSubsystemIterationIndex();
717 __SUP_COUT__ <<
"SubsystemIteration "
718 << (RunControlStateMachine::isStandaloneSubsystem()
719 ? std::string(
"standalone")
724 << subIterationWorkStateMachineIndex_ <<
")" << __E__;
727 if(RunControlStateMachine::getSubsystemIterationIndex() !=
728 lastSubsystemIterationIndexSeen_)
730 lastSubsystemIterationIndexSeen_ =
731 RunControlStateMachine::getSubsystemIterationIndex();
740 void CoreSupervisorBase::preStateMachineExecution(
unsigned int i)
742 if(i >= theStateMachineImplementation_.size())
744 __SUP_SS__ <<
"State Machine " << i <<
" not found!" << __E__;
748 theStateMachineImplementation_[i]->VStateMachine::setSubsystemIterationIndex(
749 RunControlStateMachine::getSubsystemIterationIndex());
750 theStateMachineImplementation_[i]->VStateMachine::setIterationIndex(
751 RunControlStateMachine::getIterationIndex());
752 theStateMachineImplementation_[i]->VStateMachine::setSubIterationIndex(
753 RunControlStateMachine::getSubIterationIndex());
754 theStateMachineImplementation_[i]
755 ->VStateMachine::setSystemMinReadyForEventGenerationStartIteration(
756 RunControlStateMachine::getMinReadyForEventGenerationStartIteration());
758 theStateMachineImplementation_[i]->VStateMachine::clearSubsystemIterationWork();
759 theStateMachineImplementation_[i]->VStateMachine::clearIterationWork();
760 theStateMachineImplementation_[i]->VStateMachine::clearSubIterationWork();
763 <<
"theStateMachineImplementation Iteration "
764 << theStateMachineImplementation_[i]->VStateMachine::getIterationIndex() <<
"."
765 << theStateMachineImplementation_[i]->VStateMachine::getSubIterationIndex()
770 void CoreSupervisorBase::postStateMachineExecution(
unsigned int i)
772 if(i >= theStateMachineImplementation_.size())
774 __SUP_SS__ <<
"State Machine " << i <<
" not found!" << __E__;
779 if(theStateMachineImplementation_[i]->VStateMachine::getSubIterationWork())
781 subIterationWorkStateMachineIndex_ = i;
782 RunControlStateMachine::indicateSubIterationWork();
784 __SUP_COUT__ <<
"State machine " << i
785 <<
" is flagged for another sub-iteration..." << __E__;
787 else if(theStateMachineImplementation_[i]->VStateMachine::getIterationWork())
791 RunControlStateMachine::indicateIterationWork();
793 ++stateMachinesIterationWorkCount_;
795 __SUP_COUT__ <<
"State machine " << i <<
" is flagged for another iteration..."
798 else if(theStateMachineImplementation_[i]->VStateMachine::getSubsystemIterationWork())
804 RunControlStateMachine::indicateSubsystemIterationWork();
806 __SUP_COUT__ <<
"State machine " << i
807 <<
" is flagged for another subsystem-iteration..." << __E__;
817 void CoreSupervisorBase::postStateMachineExecutionLoop(
void)
819 if(RunControlStateMachine::subIterationWorkFlag_)
820 __SUP_COUT__ <<
"State machine implementation "
821 << subIterationWorkStateMachineIndex_
822 <<
" is flagged for another sub-iteration..." << __E__;
823 else if(RunControlStateMachine::iterationWorkFlag_)
825 << stateMachinesIterationWorkCount_
826 <<
" state machine implementation(s) flagged for another iteration..."
828 else if(RunControlStateMachine::subsystemIterationWorkFlag_)
829 __SUP_COUT__ <<
"State machine implementation(s) flagged for another "
830 "subsystem-iteration (cross-subsystem sync)..."
833 __SUP_COUT__ <<
"Done configuration all state machine implementations..."
838 void CoreSupervisorBase::configureInit(
bool attemptSkipIfGroupUnchanged )
845 __SUP_COUT__ <<
"configureInit()" << __E__;
848 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
850 .getValue(
"ConfigurationTableGroupName"),
851 TableGroupKey(SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
853 .getValue(
"ConfigurationTableGroupKey")));
855 __SUP_COUT__ <<
"Configuration table group name: " << theGroup.first
856 <<
" key: " << theGroup.second << __E__;
859 StringMacros::systemVariables_[
"ActiveStateMachine"][
"name"] =
860 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
862 .getValue(
"ActiveStateMachineName");
863 StringMacros::systemVariables_[
"ActiveStateMachine"][
"windowName"] =
864 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
866 .getValue(
"ActiveStateMachineWindowName");
867 StringMacros::systemVariables_[
"ActiveStateMachine"][
"runAlias"] =
868 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
870 .getValue(
"ActiveStateMachineRunAlias");
874 std::map<std::string ,
TableVersion> mergeInTables, overrideTables;
877 std::string subsystemCommonList;
880 subsystemCommonList =
881 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
883 .getValue(
"SubsystemCommonList");
887 __COUT__ <<
"Ignoring missing 'SubsystemCommonList' parameter." << __E__;
890 if(!subsystemCommonList.empty())
892 subsystemCommonList =
894 __COUT__ <<
"Transition parameter SubsystemCommonList: "
895 << subsystemCommonList << __E__;
902 std::string subsystemCommonOverrideList;
905 subsystemCommonOverrideList =
906 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
908 .getValue(
"SubsystemCommonOverrideList");
912 __COUT__ <<
"Ignoring missing 'SubsystemCommonOverrideList' parameter."
916 if(!subsystemCommonOverrideList.empty())
918 subsystemCommonOverrideList =
920 __COUT__ <<
"Transition parameter SubsystemCommonOverrideList: "
921 << subsystemCommonOverrideList << __E__;
935 if(attemptSkipIfGroupUnchanged && mergeInTables.empty() && overrideTables.empty() &&
937 theConfigurationManager_->getActiveGroupName(
938 ConfigurationManager::GroupType::CONFIGURATION_TYPE) == theGroup.first &&
939 theConfigurationManager_->getActiveGroupKey(
940 ConfigurationManager::GroupType::CONFIGURATION_TYPE) == theGroup.second)
942 bool haveScratchOrTemporaryMembers =
false;
943 for(
const auto& activeVersionPair : theConfigurationManager_->
getActiveVersions())
944 if(activeVersionPair.second.isScratchVersion() ||
945 activeVersionPair.second.isTemporaryVersion())
947 haveScratchOrTemporaryMembers =
true;
948 __SUP_COUT__ <<
"Not skipping activation: active member '"
949 << activeVersionPair.first
950 <<
"' has scratch/temporary version "
951 << activeVersionPair.second << __E__;
955 if(!haveScratchOrTemporaryMembers)
957 __SUP_COUT_INFO__ <<
"Skipping table group activation: group '"
958 << theGroup.first <<
"(" << theGroup.second
959 <<
")' is already active with no scratch/temporary "
960 "member versions and no merge-in/override lists."
969 theConfigurationManager_);
984 ConfigurationManager::LoadGroupType::ALL_TYPES,
990 catch(
const std::runtime_error& e)
992 __SS__ <<
"Error loading table group '" << theGroup.first <<
"("
993 << theGroup.second <<
")! \n"
994 << e.what() << __E__;
995 __SUP_COUT_ERR__ << ss.str();
999 theStateMachine_.setErrorMessage(ss.str());
1000 throw toolbox::fsm::exception::Exception(
1001 "Transition Error" ,
1003 "CoreSupervisorBase::configureInit" ,
1010 __SS__ <<
"Unknown error loading table group '" << theGroup.first <<
"("
1011 << theGroup.second <<
")!" << __E__;
1016 catch(
const std::exception& e)
1018 ss <<
"Exception message: " << e.what();
1023 __SUP_COUT_ERR__ << ss.str();
1027 theStateMachine_.setErrorMessage(ss.str());
1028 throw toolbox::fsm::exception::Exception(
1029 "Transition Error" ,
1031 "CoreSupervisorBase::configureInit" ,
1041 void CoreSupervisorBase::transitionConfiguring(toolbox::Event::Reference )
1043 __SUP_COUT__ <<
"transitionConfiguring()" << __E__;
1045 CoreSupervisorBase::configureInit(
true );
1047 CoreSupervisorBase::transitionConfiguringFSMs();
1049 __SUP_COUT__ <<
"Configured." << __E__;
1053 void CoreSupervisorBase::transitionConfiguringFSMs()
1060 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1061 preStateMachineExecutionLoop();
1062 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1065 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1066 i != subIterationWorkStateMachineIndex_)
1072 preStateMachineExecution(i);
1073 theStateMachineImplementation_[i]->parentSupervisor_ =
1075 theStateMachineImplementation_[i]->configure();
1078 postStateMachineExecution(i);
1080 postStateMachineExecutionLoop();
1082 catch(
const std::runtime_error& e)
1084 __SUP_SS__ <<
"Error was caught while configuring: " << e.what() << __E__;
1085 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1086 theStateMachine_.setErrorMessage(ss.str());
1087 throw toolbox::fsm::exception::Exception(
1088 "Transition Error" ,
1090 "CoreSupervisorBase::transitionConfiguringFSMs" ,
1098 <<
"Unknown error was caught while configuring. Please checked the logs."
1104 catch(
const std::exception& e)
1106 ss <<
"Exception message: " << e.what();
1111 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1112 theStateMachine_.setErrorMessage(ss.str());
1113 throw toolbox::fsm::exception::Exception(
1114 "Transition Error" ,
1116 "CoreSupervisorBase::transitionConfiguringFSMs" ,
1128 const std::string transitionName =
"Halting";
1131 __SUP_COUT__ << transitionName <<
" all state machine implementations..."
1133 preStateMachineExecutionLoop();
1134 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1137 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1138 i != subIterationWorkStateMachineIndex_)
1144 preStateMachineExecution(i);
1145 theStateMachineImplementation_[i]->halt();
1148 postStateMachineExecution(i);
1150 postStateMachineExecutionLoop();
1152 catch(
const std::runtime_error& e)
1155 if(theStateMachine_.getProvenanceStateName() ==
1156 RunControlStateMachine::FAILED_STATE_NAME ||
1157 theStateMachine_.getProvenanceStateName() ==
1158 RunControlStateMachine::HALTED_STATE_NAME)
1160 __SUP_COUT_INFO__ <<
"Error was caught while halting (but ignoring because "
1161 "previous state was '"
1162 << theStateMachine_.getProvenanceStateName()
1163 <<
"'): " << e.what() << __E__;
1167 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1169 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1170 theStateMachine_.setErrorMessage(ss.str());
1171 throw toolbox::fsm::exception::Exception(
1172 "Transition Error" ,
1174 "CoreSupervisorBase::transition" + transitionName ,
1183 if(theStateMachine_.getProvenanceStateName() ==
1184 RunControlStateMachine::FAILED_STATE_NAME ||
1185 theStateMachine_.getProvenanceStateName() ==
1186 RunControlStateMachine::HALTED_STATE_NAME)
1188 __SUP_COUT_INFO__ <<
"Unknown error was caught while halting (but ignoring "
1189 "because previous state was '"
1190 << theStateMachine_.getProvenanceStateName() <<
"')."
1195 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1196 <<
". Please checked the logs." << __E__;
1201 catch(
const std::exception& e)
1203 ss <<
"Exception message: " << e.what();
1208 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1209 theStateMachine_.setErrorMessage(ss.str());
1210 throw toolbox::fsm::exception::Exception(
1211 "Transition Error" ,
1213 "CoreSupervisorBase::transition" + transitionName ,
1226 __SUP_COUT__ <<
"transitionInitializing" << __E__;
1228 CorePropertySupervisorBase::resetPropertiesAreSetup();
1239 void CoreSupervisorBase::transitionPausing(toolbox::Event::Reference )
1241 const std::string transitionName =
"Pausing";
1244 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1245 preStateMachineExecutionLoop();
1246 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1249 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1250 i != subIterationWorkStateMachineIndex_)
1256 preStateMachineExecution(i);
1257 theStateMachineImplementation_[i]->pause();
1260 postStateMachineExecution(i);
1262 postStateMachineExecutionLoop();
1264 catch(
const std::runtime_error& e)
1266 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1268 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1269 theStateMachine_.setErrorMessage(ss.str());
1270 throw toolbox::fsm::exception::Exception(
1271 "Transition Error" ,
1273 "CoreSupervisorBase::transition" + transitionName ,
1280 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1281 <<
". Please checked the logs." << __E__;
1286 catch(
const std::exception& e)
1288 ss <<
"Exception message: " << e.what();
1293 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1294 theStateMachine_.setErrorMessage(ss.str());
1295 throw toolbox::fsm::exception::Exception(
1296 "Transition Error" ,
1298 "CoreSupervisorBase::transition" + transitionName ,
1306 void CoreSupervisorBase::transitionResuming(toolbox::Event::Reference )
1308 const std::string transitionName =
"Resuming";
1311 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1312 preStateMachineExecutionLoop();
1313 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1316 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1317 i != subIterationWorkStateMachineIndex_)
1323 preStateMachineExecution(i);
1324 theStateMachineImplementation_[i]->resume();
1327 postStateMachineExecution(i);
1329 postStateMachineExecutionLoop();
1331 catch(
const std::runtime_error& e)
1333 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1335 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1336 theStateMachine_.setErrorMessage(ss.str());
1337 throw toolbox::fsm::exception::Exception(
1338 "Transition Error" ,
1340 "CoreSupervisorBase::transition" + transitionName ,
1347 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1348 <<
". Please checked the logs." << __E__;
1353 catch(
const std::exception& e)
1355 ss <<
"Exception message: " << e.what();
1360 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1361 theStateMachine_.setErrorMessage(ss.str());
1362 throw toolbox::fsm::exception::Exception(
1363 "Transition Error" ,
1365 "CoreSupervisorBase::transition" + transitionName ,
1373 void CoreSupervisorBase::transitionStarting(toolbox::Event::Reference )
1375 const std::string transitionName =
"Starting";
1376 const std::string runNumber =
1377 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
1379 .getValue(
"RunNumber");
1382 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1383 preStateMachineExecutionLoop();
1384 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1387 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1388 i != subIterationWorkStateMachineIndex_)
1394 preStateMachineExecution(i);
1395 theStateMachineImplementation_[i]->start(runNumber);
1399 postStateMachineExecution(i);
1401 postStateMachineExecutionLoop();
1403 catch(
const std::runtime_error& e)
1405 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1407 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1408 theStateMachine_.setErrorMessage(ss.str());
1409 throw toolbox::fsm::exception::Exception(
1410 "Transition Error" ,
1412 "CoreSupervisorBase::transition" + transitionName ,
1419 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1420 <<
". Please checked the logs." << __E__;
1425 catch(
const std::exception& e)
1427 ss <<
"Exception message: " << e.what();
1432 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1433 theStateMachine_.setErrorMessage(ss.str());
1434 throw toolbox::fsm::exception::Exception(
1435 "Transition Error" ,
1437 "CoreSupervisorBase::transition" + transitionName ,
1445 void CoreSupervisorBase::transitionStopping(toolbox::Event::Reference )
1447 const std::string transitionName =
"Stopping";
1450 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1451 preStateMachineExecutionLoop();
1452 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1455 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1456 i != subIterationWorkStateMachineIndex_)
1462 preStateMachineExecution(i);
1463 theStateMachineImplementation_[i]->stop();
1466 postStateMachineExecution(i);
1468 postStateMachineExecutionLoop();
1470 catch(
const std::runtime_error& e)
1472 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1474 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1475 theStateMachine_.setErrorMessage(ss.str());
1476 throw toolbox::fsm::exception::Exception(
1477 "Transition Error" ,
1479 "CoreSupervisorBase::transition" + transitionName ,
1486 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1487 <<
". Please checked the logs." << __E__;
1492 catch(
const std::exception& e)
1494 ss <<
"Exception message: " << e.what();
1499 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1500 theStateMachine_.setErrorMessage(ss.str());
1501 throw toolbox::fsm::exception::Exception(
1502 "Transition Error" ,
1504 "CoreSupervisorBase::transition" + transitionName ,
1517 bool isPauseException,
1518 bool isStopException)
1522 __SUP_COUT_ERR__ <<
"Sending Supervisor Async STOP Running Exception... \n"
1523 << errorMessage << __E__;
1524 else if(isPauseException)
1525 __SUP_COUT_ERR__ <<
"Sending Supervisor Async SOFT Running Error... \n"
1526 << errorMessage << __E__;
1528 __SUP_COUT_ERR__ <<
"Sending Supervisor Async Running Error... \n"
1529 << errorMessage << __E__;
1531 theStateMachine_.setErrorMessage(errorMessage);
1533 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* gatewaySupervisor =
1537 parameters.addParameter(
"ErrorMessage", errorMessage);
1539 xoap::MessageReference replyMessage = SOAPMessenger::sendWithSOAPReply(
1541 isStopException ?
"AsyncStopException"
1542 : (isPauseException ?
"AsyncPauseException" :
"AsyncError"),
1545 std::stringstream replyMessageSStream;
1546 replyMessageSStream << SOAPUtilities::translate(replyMessage);
1547 __SUP_COUT__ <<
"Received... " << replyMessageSStream.str() << std::endl;
1549 if(replyMessageSStream.str().find(
"Fault") != std::string::npos)
1551 __SUP_COUT_ERR__ <<
"Failure to indicate fault to Gateway..." << __E__;
1555 catch(
const xdaq::exception::Exception& e)
1559 <<
"SOAP message failure indicating Supervisor asynchronous running STOP "
1560 "exception back to Gateway: "
1561 << e.what() << __E__;
1562 else if(isPauseException)
1564 <<
"SOAP message failure indicating Supervisor asynchronous running SOFT "
1565 "exception back to Gateway: "
1566 << e.what() << __E__;
1568 __SUP_COUT__ <<
"SOAP message failure indicating Supervisor asynchronous running "
1569 "error back to Gateway: "
1570 << e.what() << __E__;
1577 <<
"Unknown error encounter indicating Supervisor asynchronous running "
1578 "STOP exception back to Gateway."
1580 else if(isPauseException)
1582 <<
"Unknown error encounter indicating Supervisor asynchronous running "
1583 "SOFT error back to Gateway."
1587 <<
"Unknown error encounter indicating Supervisor asynchronous running "
1588 "error back to Gateway."
1594 xoap::MessageReference CoreSupervisorBase::TRACESupervisorRequest(
1595 xoap::MessageReference message)
1597 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)
std::map< std::string, TableVersion > getActiveVersions(void) const
getActiveVersions
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)
bool lastActivationHadMergeOrOverride_
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)
std::set< unsigned int > stateMachinesWaitingSubsystemIteration_
re-armed when the subsystem-iteration index changes
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)
bool isFirstIteration(void) const
true on the very first call of a transition (all indices at their starting value)
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)