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);
185 std::stringstream xmlDataSs;
189 request(requestType, cgiIn, xmlOut, userInfo);
191 catch(
const std::runtime_error& e)
193 __SUP_SS__ <<
"An error was encountered handling requestType '" << requestType
194 <<
"':" << e.what() << __E__;
195 __SUP_COUT_ERR__ <<
"\n" << ss.str();
196 xmlOut.addTextElementToData(
"Error", ss.str());
200 __SUP_SS__ <<
"An unknown error was encountered handling requestType '"
201 << requestType <<
".' "
202 <<
"Please check the printouts to debug." << __E__;
207 catch(
const std::exception& e)
209 ss <<
"Exception message: " << e.what();
214 __SUP_COUT_ERR__ <<
"\n" << ss.str();
215 xmlOut.addTextElementToData(
"Error", ss.str());
217 __SUP_COUTT__ <<
"Request '" << requestType
218 <<
"' time: " << artdaq::TimeUtils::GetElapsedTime(requestStart)
223 size_t numberOfChildren = xmlOut.getRootDataElement()->getChildNodes()->getLength();
224 if(numberOfChildren &&
225 xmlOut.getRootDataElement()->getChildNodes()->item(0)->getNodeType() !=
226 xercesc::DOMNode::TEXT_NODE)
227 numberOfChildren += xmlOut.getRootDataElement()
233 __SUP_COUTT__ <<
"Number of xml data element children: " << numberOfChildren << __E__;
235 if(numberOfChildren < 1000)
237 unsigned int occurance = 0;
241 __SUP_COUT_ERR__ <<
"'" << requestType <<
"' ERROR encountered: " << err
245 __SUP_COUTT__ <<
"Elapsed time after error check: "
246 << artdaq::TimeUtils::GetElapsedTime(requestStart) << __E__;
254 !userInfo.NoXmlWhiteSpace_ );
256 __SUP_COUTT__ <<
"Total xml request time: "
257 << artdaq::TimeUtils::GetElapsedTime(requestStart) <<
" = "
258 << time(0) - requestStartTime << __E__;
260 catch(
const std::runtime_error& e)
262 __SUP_SS__ <<
"An error was encountered handling HTTP request:" << e.what() << __E__;
263 __SUP_COUT_ERR__ <<
"\n" << ss.str();
268 __SUP_SS__ <<
"An unknown error was encountered HTTP request. "
269 <<
"Please check the printouts to debug." << __E__;
274 catch(
const std::exception& e)
276 ss <<
"Exception message: " << e.what();
281 __SUP_COUT_ERR__ <<
"\n" << ss.str();
296 __SUP_SS__ <<
"This is the empty Core Supervisor request. Supervisors should "
297 "override this function."
299 __SUP_COUT__ << ss.str();
300 xmlOut.addTextElementToData(
"Error", ss.str());
362 __SUP_COUT__ <<
"This is the empty Core Supervisor non-xml request. Supervisors "
363 "should override this function."
365 out <<
"This is the empty Core Supervisor non-xml request. Supervisors should "
366 "override this function."
376 xoap::MessageReference CoreSupervisorBase::stateMachineXoapHandler(
377 xoap::MessageReference message)
379 __SUP_COUT__ <<
"Soap Handler!" << __E__;
380 stateMachineWorkLoopManager_.removeProcessedRequests();
382 __SUP_COUT__ <<
"Done - Soap Handler!" << __E__;
388 xoap::MessageReference CoreSupervisorBase::workLoopStatusRequestWrapper(
389 xoap::MessageReference message)
392 return workLoopStatusRequest(message);
396 xoap::MessageReference CoreSupervisorBase::workLoopStatusRequest(
397 xoap::MessageReference )
400 return SOAPUtilities::makeSOAPMessageReference(CoreSupervisorBase::WORK_LOOP_DONE);
404 xoap::MessageReference CoreSupervisorBase::applicationStatusRequest(
405 xoap::MessageReference )
410 std::to_string(getpid()) +
":" + std::to_string(gettid()) +
":" +
411 theStateMachine_.getCurrentStateName());
413 const std::string& err = theStateMachine_.getErrorMessage();
425 if(theStateMachine_.isInTransition() ||
426 RunControlStateMachine::theProgressBar_.read() < 100)
431 retParameters.addParameter(
"Status",
432 theStateMachine_.getCurrentTransitionName());
436 retParameters.addParameter(
"Status",
437 theStateMachine_.getProvenanceStateName());
441 retParameters.addParameter(
"Status", theStateMachine_.getCurrentStateName());
444 retParameters.addParameter(
446 (theStateMachine_.getCurrentStateName() ==
"Paused" ?
"Soft-Error:::"
450 retParameters.addParameter(
451 "Progress", RunControlStateMachine::theProgressBar_.readPercentageString());
452 retParameters.addParameter(
455 auto subappInfo = getSubappInfo();
456 retParameters.addParameter(
"Subapps",
457 SupervisorInfo::serializeSubappInfos(subappInfo));
459 return SOAPUtilities::makeSOAPMessageReference(
"applicationStatusRequestReply",
471 unsigned int cnt = 0;
490 if(!theStateMachine_.isInTransition() &&
491 (theStateMachine_.getCurrentStateName() ==
492 RunControlStateMachine::HALTED_STATE_NAME ||
493 theStateMachine_.getCurrentStateName() ==
494 RunControlStateMachine::INITIAL_STATE_NAME))
496 detail = std::string(
"Uptime: ") +
498 CorePropertySupervisorBase::getSupervisorUptime())) +
499 ", Time-in-state: " +
505 for(
const auto& fsm : CoreSupervisorBase::theStateMachineImplementation_)
507 std::string fsmProgressDetail = fsm->getStatusProgressDetail();
508 if(fsmProgressDetail.size())
510 ((cnt++) ?
":" :
"") +
515 __SUP_COUTVS__(20, detail);
518 if(!detail.size() && RunControlStateMachine::getLastCommand() !=
"")
520 detail =
"Last Command: " + RunControlStateMachine::getLastCommand();
521 if(RunControlStateMachine::getLastCommand() ==
522 RunControlStateMachine::CONFIGURE_TRANSITION_NAME)
523 detail +=
" w/" + RunControlStateMachine::getLastAttemptedConfigureGroup();
530 bool CoreSupervisorBase::stateMachineThread(toolbox::task::WorkLoop* workLoop)
532 stateMachineSemaphore_.take();
533 __SUP_COUT__ <<
"Re-sending message..."
534 << SOAPUtilities::translate(
535 stateMachineWorkLoopManager_.getMessage(workLoop))
538 std::string reply =
send(this->getApplicationDescriptor(),
539 stateMachineWorkLoopManager_.getMessage(workLoop));
540 stateMachineWorkLoopManager_.report(workLoop, reply, 100,
true);
541 __SUP_COUT__ <<
"Done with message" << __E__;
542 stateMachineSemaphore_.give();
550 xoap::MessageReference CoreSupervisorBase::stateMachineStateRequest(
551 xoap::MessageReference )
553 __SUP_COUT__ <<
"theStateMachine_.getCurrentStateName() = "
554 << theStateMachine_.getCurrentStateName() << __E__;
555 return SOAPUtilities::makeSOAPMessageReference(
556 theStateMachine_.getCurrentStateName());
560 xoap::MessageReference CoreSupervisorBase::stateMachineErrorMessageRequest(
561 xoap::MessageReference )
564 __SUP_COUT__ <<
"theStateMachine_.getErrorMessage() = "
565 << theStateMachine_.getErrorMessage() << __E__;
568 retParameters.addParameter(
"ErrorMessage", theStateMachine_.getErrorMessage());
569 return SOAPUtilities::makeSOAPMessageReference(
"stateMachineErrorMessageRequestReply",
576 __SUP_COUT__ <<
"CoreSupervisorBase::stateInitial" << __E__;
582 __SUP_COUT__ <<
"CoreSupervisorBase::stateHalted" << __E__;
588 __SUP_COUT__ <<
"CoreSupervisorBase::stateRunning" << __E__;
594 __SUP_COUT__ <<
"CoreSupervisorBase::stateConfigured" << __E__;
600 __SUP_COUT__ <<
"CoreSupervisorBase::statePaused" << __E__;
604 void CoreSupervisorBase::inError(toolbox::fsm::FiniteStateMachine& )
607 __SUP_COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName()
613 void CoreSupervisorBase::enteringError(toolbox::Event::Reference event)
619 toolbox::fsm::FailedEvent& failedEvent =
620 dynamic_cast<toolbox::fsm::FailedEvent&
>(*event);
621 std::ostringstream error;
622 error <<
"Failure performing transition from " << failedEvent.getFromState() <<
" to "
623 << failedEvent.getToState()
624 <<
" exception: " << failedEvent.getException().what();
625 __SUP_COUT_ERR__ << error.str() << __E__;
630 void CoreSupervisorBase::preStateMachineExecutionLoop(
void)
632 RunControlStateMachine::clearIterationWork();
633 RunControlStateMachine::clearSubIterationWork();
635 stateMachinesIterationWorkCount_ = 0;
637 if(RunControlStateMachine::getIterationIndex() == 0 &&
638 RunControlStateMachine::getSubIterationIndex() == 0)
642 subIterationWorkStateMachineIndex_ = -1;
649 __SUP_COUT__ <<
"Iteration " << RunControlStateMachine::getIterationIndex() <<
"."
650 << RunControlStateMachine::getSubIterationIndex() <<
"("
651 << subIterationWorkStateMachineIndex_ <<
")" << __E__;
655 void CoreSupervisorBase::preStateMachineExecution(
unsigned int i)
657 if(i >= theStateMachineImplementation_.size())
659 __SUP_SS__ <<
"State Machine " << i <<
" not found!" << __E__;
663 theStateMachineImplementation_[i]->VStateMachine::setIterationIndex(
664 RunControlStateMachine::getIterationIndex());
665 theStateMachineImplementation_[i]->VStateMachine::setSubIterationIndex(
666 RunControlStateMachine::getSubIterationIndex());
668 theStateMachineImplementation_[i]->VStateMachine::clearIterationWork();
669 theStateMachineImplementation_[i]->VStateMachine::clearSubIterationWork();
672 <<
"theStateMachineImplementation Iteration "
673 << theStateMachineImplementation_[i]->VStateMachine::getIterationIndex() <<
"."
674 << theStateMachineImplementation_[i]->VStateMachine::getSubIterationIndex()
679 void CoreSupervisorBase::postStateMachineExecution(
unsigned int i)
681 if(i >= theStateMachineImplementation_.size())
683 __SUP_SS__ <<
"State Machine " << i <<
" not found!" << __E__;
688 if(theStateMachineImplementation_[i]->VStateMachine::getSubIterationWork())
690 subIterationWorkStateMachineIndex_ = i;
691 RunControlStateMachine::indicateSubIterationWork();
693 __SUP_COUT__ <<
"State machine " << i
694 <<
" is flagged for another sub-iteration..." << __E__;
699 !theStateMachineImplementation_[i]->VStateMachine::getIterationWork();
703 __SUP_COUT__ <<
"State machine " << i
704 <<
" is flagged for another iteration..." << __E__;
705 RunControlStateMachine::indicateIterationWork();
707 ++stateMachinesIterationWorkCount_;
713 void CoreSupervisorBase::postStateMachineExecutionLoop(
void)
715 if(RunControlStateMachine::subIterationWorkFlag_)
716 __SUP_COUT__ <<
"State machine implementation "
717 << subIterationWorkStateMachineIndex_
718 <<
" is flagged for another sub-iteration..." << __E__;
719 else if(RunControlStateMachine::iterationWorkFlag_)
721 << stateMachinesIterationWorkCount_
722 <<
" state machine implementation(s) flagged for another iteration..."
725 __SUP_COUT__ <<
"Done configuration all state machine implementations..."
730 void CoreSupervisorBase::transitionConfiguring(toolbox::Event::Reference )
732 __SUP_COUT__ <<
"transitionConfiguring" << __E__;
735 if(RunControlStateMachine::getIterationIndex() == 0 &&
736 RunControlStateMachine::getSubIterationIndex() == 0)
739 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
741 .getValue(
"ConfigurationTableGroupName"),
742 TableGroupKey(SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
744 .getValue(
"ConfigurationTableGroupKey")));
746 __SUP_COUT__ <<
"Configuration table group name: " << theGroup.first
747 <<
" key: " << theGroup.second << __E__;
765 ConfigurationManager::LoadGroupType::ALL_TYPES,
768 catch(
const std::runtime_error& e)
770 __SS__ <<
"Error loading table group '" << theGroup.first <<
"("
771 << theGroup.second <<
")! \n"
772 << e.what() << __E__;
773 __SUP_COUT_ERR__ << ss.str();
777 theStateMachine_.setErrorMessage(ss.str());
778 throw toolbox::fsm::exception::Exception(
781 "CoreSupervisorBase::transitionConfiguring" ,
788 __SS__ <<
"Unknown error loading table group '" << theGroup.first <<
"("
789 << theGroup.second <<
")!" << __E__;
794 catch(
const std::exception& e)
796 ss <<
"Exception message: " << e.what();
801 __SUP_COUT_ERR__ << ss.str();
805 theStateMachine_.setErrorMessage(ss.str());
806 throw toolbox::fsm::exception::Exception(
809 "CoreSupervisorBase::transitionConfiguring" ,
816 CoreSupervisorBase::transitionConfiguringFSMs();
818 __SUP_COUT__ <<
"Configured." << __E__;
822 void CoreSupervisorBase::transitionConfiguringFSMs()
829 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
830 preStateMachineExecutionLoop();
831 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
834 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
835 i != subIterationWorkStateMachineIndex_)
841 preStateMachineExecution(i);
842 theStateMachineImplementation_[i]->parentSupervisor_ =
844 theStateMachineImplementation_[i]->configure();
847 postStateMachineExecution(i);
849 postStateMachineExecutionLoop();
851 catch(
const std::runtime_error& e)
853 __SUP_SS__ <<
"Error was caught while configuring: " << e.what() << __E__;
854 __SUP_COUT_ERR__ <<
"\n" << ss.str();
855 theStateMachine_.setErrorMessage(ss.str());
856 throw toolbox::fsm::exception::Exception(
859 "CoreSupervisorBase::transitionConfiguring" ,
867 <<
"Unknown error was caught while configuring. Please checked the logs."
873 catch(
const std::exception& e)
875 ss <<
"Exception message: " << e.what();
880 __SUP_COUT_ERR__ <<
"\n" << ss.str();
881 theStateMachine_.setErrorMessage(ss.str());
882 throw toolbox::fsm::exception::Exception(
885 "CoreSupervisorBase::transitionConfiguring" ,
897 const std::string transitionName =
"Halting";
900 __SUP_COUT__ << transitionName <<
" all state machine implementations..."
902 preStateMachineExecutionLoop();
903 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
906 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
907 i != subIterationWorkStateMachineIndex_)
913 preStateMachineExecution(i);
914 theStateMachineImplementation_[i]->halt();
917 postStateMachineExecution(i);
919 postStateMachineExecutionLoop();
921 catch(
const std::runtime_error& e)
924 if(theStateMachine_.getProvenanceStateName() ==
925 RunControlStateMachine::FAILED_STATE_NAME)
927 __SUP_COUT_INFO__ <<
"Error was caught while halting (but ignoring because "
928 "previous state was '"
929 << RunControlStateMachine::FAILED_STATE_NAME
930 <<
"'): " << e.what() << __E__;
934 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
936 __SUP_COUT_ERR__ <<
"\n" << ss.str();
937 theStateMachine_.setErrorMessage(ss.str());
938 throw toolbox::fsm::exception::Exception(
941 "CoreSupervisorBase::transition" + transitionName ,
950 if(theStateMachine_.getProvenanceStateName() ==
951 RunControlStateMachine::FAILED_STATE_NAME)
953 __SUP_COUT_INFO__ <<
"Unknown error was caught while halting (but ignoring "
954 "because previous state was '"
955 << RunControlStateMachine::FAILED_STATE_NAME <<
"')."
960 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
961 <<
". Please checked the logs." << __E__;
966 catch(
const std::exception& e)
968 ss <<
"Exception message: " << e.what();
973 __SUP_COUT_ERR__ <<
"\n" << ss.str();
974 theStateMachine_.setErrorMessage(ss.str());
975 throw toolbox::fsm::exception::Exception(
978 "CoreSupervisorBase::transition" + transitionName ,
991 __SUP_COUT__ <<
"transitionInitializing" << __E__;
993 CorePropertySupervisorBase::resetPropertiesAreSetup();
1004 void CoreSupervisorBase::transitionPausing(toolbox::Event::Reference )
1006 const std::string transitionName =
"Pausing";
1009 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1010 preStateMachineExecutionLoop();
1011 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1014 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1015 i != subIterationWorkStateMachineIndex_)
1021 preStateMachineExecution(i);
1022 theStateMachineImplementation_[i]->pause();
1025 postStateMachineExecution(i);
1027 postStateMachineExecutionLoop();
1029 catch(
const std::runtime_error& e)
1031 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1033 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1034 theStateMachine_.setErrorMessage(ss.str());
1035 throw toolbox::fsm::exception::Exception(
1036 "Transition Error" ,
1038 "CoreSupervisorBase::transition" + transitionName ,
1045 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1046 <<
". Please checked the logs." << __E__;
1051 catch(
const std::exception& e)
1053 ss <<
"Exception message: " << e.what();
1058 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1059 theStateMachine_.setErrorMessage(ss.str());
1060 throw toolbox::fsm::exception::Exception(
1061 "Transition Error" ,
1063 "CoreSupervisorBase::transition" + transitionName ,
1071 void CoreSupervisorBase::transitionResuming(toolbox::Event::Reference )
1073 const std::string transitionName =
"Resuming";
1076 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1077 preStateMachineExecutionLoop();
1078 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1081 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1082 i != subIterationWorkStateMachineIndex_)
1088 preStateMachineExecution(i);
1089 theStateMachineImplementation_[i]->resume();
1092 postStateMachineExecution(i);
1094 postStateMachineExecutionLoop();
1096 catch(
const std::runtime_error& e)
1098 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1100 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1101 theStateMachine_.setErrorMessage(ss.str());
1102 throw toolbox::fsm::exception::Exception(
1103 "Transition Error" ,
1105 "CoreSupervisorBase::transition" + transitionName ,
1112 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1113 <<
". Please checked the logs." << __E__;
1118 catch(
const std::exception& e)
1120 ss <<
"Exception message: " << e.what();
1125 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1126 theStateMachine_.setErrorMessage(ss.str());
1127 throw toolbox::fsm::exception::Exception(
1128 "Transition Error" ,
1130 "CoreSupervisorBase::transition" + transitionName ,
1138 void CoreSupervisorBase::transitionStarting(toolbox::Event::Reference )
1140 const std::string transitionName =
"Starting";
1141 const std::string runNumber =
1142 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
1144 .getValue(
"RunNumber");
1147 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1148 preStateMachineExecutionLoop();
1149 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1152 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1153 i != subIterationWorkStateMachineIndex_)
1159 preStateMachineExecution(i);
1160 theStateMachineImplementation_[i]->start(runNumber);
1164 postStateMachineExecution(i);
1166 postStateMachineExecutionLoop();
1168 catch(
const std::runtime_error& e)
1170 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << 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 ,
1184 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1185 <<
". Please checked the logs." << __E__;
1190 catch(
const std::exception& e)
1192 ss <<
"Exception message: " << e.what();
1197 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1198 theStateMachine_.setErrorMessage(ss.str());
1199 throw toolbox::fsm::exception::Exception(
1200 "Transition Error" ,
1202 "CoreSupervisorBase::transition" + transitionName ,
1210 void CoreSupervisorBase::transitionStopping(toolbox::Event::Reference )
1212 const std::string transitionName =
"Stopping";
1215 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1216 preStateMachineExecutionLoop();
1217 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1220 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1221 i != subIterationWorkStateMachineIndex_)
1227 preStateMachineExecution(i);
1228 theStateMachineImplementation_[i]->stop();
1231 postStateMachineExecution(i);
1233 postStateMachineExecutionLoop();
1235 catch(
const std::runtime_error& e)
1237 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << 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 ,
1251 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1252 <<
". Please checked the logs." << __E__;
1257 catch(
const std::exception& e)
1259 ss <<
"Exception message: " << e.what();
1264 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1265 theStateMachine_.setErrorMessage(ss.str());
1266 throw toolbox::fsm::exception::Exception(
1267 "Transition Error" ,
1269 "CoreSupervisorBase::transition" + transitionName ,
1282 bool isPauseException,
1283 bool isStopException)
1287 __SUP_COUT_ERR__ <<
"Sending Supervisor Async STOP Running Exception... \n"
1288 << errorMessage << __E__;
1289 else if(isPauseException)
1290 __SUP_COUT_ERR__ <<
"Sending Supervisor Async SOFT Running Error... \n"
1291 << errorMessage << __E__;
1293 __SUP_COUT_ERR__ <<
"Sending Supervisor Async Running Error... \n"
1294 << errorMessage << __E__;
1296 theStateMachine_.setErrorMessage(errorMessage);
1298 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* gatewaySupervisor =
1302 parameters.addParameter(
"ErrorMessage", errorMessage);
1304 xoap::MessageReference replyMessage = SOAPMessenger::sendWithSOAPReply(
1306 isStopException ?
"AsyncStopException"
1307 : (isPauseException ?
"AsyncPauseException" :
"AsyncError"),
1310 std::stringstream replyMessageSStream;
1311 replyMessageSStream << SOAPUtilities::translate(replyMessage);
1312 __SUP_COUT__ <<
"Received... " << replyMessageSStream.str() << std::endl;
1314 if(replyMessageSStream.str().find(
"Fault") != std::string::npos)
1316 __SUP_COUT_ERR__ <<
"Failure to indicate fault to Gateway..." << __E__;
1320 catch(
const xdaq::exception::Exception& e)
1324 <<
"SOAP message failure indicating Supervisor asynchronous running STOP "
1325 "exception back to Gateway: "
1326 << e.what() << __E__;
1327 else if(isPauseException)
1329 <<
"SOAP message failure indicating Supervisor asynchronous running SOFT "
1330 "exception back to Gateway: "
1331 << e.what() << __E__;
1333 __SUP_COUT__ <<
"SOAP message failure indicating Supervisor asynchronous running "
1334 "error back to Gateway: "
1335 << e.what() << __E__;
1342 <<
"Unknown error encounter indicating Supervisor asynchronous running "
1343 "STOP exception back to Gateway."
1345 else if(isPauseException)
1347 <<
"Unknown error encounter indicating Supervisor asynchronous running "
1348 "SOFT error back to Gateway."
1352 <<
"Unknown error encounter indicating Supervisor asynchronous running "
1353 "error back to Gateway."
1359 xoap::MessageReference CoreSupervisorBase::TRACESupervisorRequest(
1360 xoap::MessageReference message)
1362 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 onlyLoadIfBackboneOrContext=ConfigurationManager::LoadGroupType::ALL_TYPES, bool ignoreVersionTracking=false)
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)
std::string getMatchingValue(const std::string &field, const unsigned int occurance=0)
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)
void INIT_MF(const char *name)
static std::string getTimeDurationString(const time_t durationInSeconds=time(0))