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(
461 auto subappInfo = getSubappInfo();
462 retParameters.addParameter(
"Subapps",
463 SupervisorInfo::serializeSubappInfos(subappInfo));
465 return SOAPUtilities::makeSOAPMessageReference(
"applicationStatusRequestReply",
477 unsigned int cnt = 0;
496 if(!theStateMachine_.isInTransition() &&
497 (theStateMachine_.getCurrentStateName() ==
498 RunControlStateMachine::HALTED_STATE_NAME ||
499 theStateMachine_.getCurrentStateName() ==
500 RunControlStateMachine::INITIAL_STATE_NAME))
502 detail = std::string(
"Uptime: ") +
504 CorePropertySupervisorBase::getSupervisorUptime())) +
505 ", Time-in-state: " +
511 for(
const auto& fsm : CoreSupervisorBase::theStateMachineImplementation_)
513 std::string fsmProgressDetail = fsm->getStatusProgressDetail();
514 if(fsmProgressDetail.size())
516 ((cnt++) ?
":" :
"") +
521 __SUP_COUTVS__(20, detail);
524 if(!detail.size() && RunControlStateMachine::getLastCommand() !=
"")
526 detail =
"Last Command: " + RunControlStateMachine::getLastCommand();
527 if(RunControlStateMachine::getLastCommand() ==
528 RunControlStateMachine::CONFIGURE_TRANSITION_NAME)
529 detail +=
" w/" + RunControlStateMachine::getLastAttemptedConfigureGroup();
536 bool CoreSupervisorBase::stateMachineThread(toolbox::task::WorkLoop* workLoop)
538 stateMachineSemaphore_.take();
539 __SUP_COUT__ <<
"Re-sending message..."
540 << SOAPUtilities::translate(
541 stateMachineWorkLoopManager_.getMessage(workLoop))
544 std::string reply =
send(this->getApplicationDescriptor(),
545 stateMachineWorkLoopManager_.getMessage(workLoop));
546 stateMachineWorkLoopManager_.report(workLoop, reply, 100,
true);
547 __SUP_COUT__ <<
"Done with message" << __E__;
548 stateMachineSemaphore_.give();
556 xoap::MessageReference CoreSupervisorBase::stateMachineStateRequest(
557 xoap::MessageReference )
559 __SUP_COUT__ <<
"theStateMachine_.getCurrentStateName() = "
560 << theStateMachine_.getCurrentStateName() << __E__;
561 return SOAPUtilities::makeSOAPMessageReference(
562 theStateMachine_.getCurrentStateName());
566 xoap::MessageReference CoreSupervisorBase::stateMachineErrorMessageRequest(
567 xoap::MessageReference )
570 __SUP_COUT__ <<
"theStateMachine_.getErrorMessage() = "
571 << theStateMachine_.getErrorMessage() << __E__;
574 retParameters.addParameter(
"ErrorMessage", theStateMachine_.getErrorMessage());
575 return SOAPUtilities::makeSOAPMessageReference(
"stateMachineErrorMessageRequestReply",
582 __SUP_COUT__ <<
"CoreSupervisorBase::stateInitial" << __E__;
588 __SUP_COUT__ <<
"CoreSupervisorBase::stateHalted" << __E__;
594 __SUP_COUT__ <<
"CoreSupervisorBase::stateRunning" << __E__;
600 __SUP_COUT__ <<
"CoreSupervisorBase::stateConfigured" << __E__;
606 __SUP_COUT__ <<
"CoreSupervisorBase::statePaused" << __E__;
610 void CoreSupervisorBase::inError(toolbox::fsm::FiniteStateMachine& )
613 __SUP_COUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName()
619 void CoreSupervisorBase::enteringError(toolbox::Event::Reference event)
625 toolbox::fsm::FailedEvent& failedEvent =
626 dynamic_cast<toolbox::fsm::FailedEvent&
>(*event);
627 std::ostringstream error;
628 error <<
"Failure performing transition from " << failedEvent.getFromState() <<
" to "
629 << failedEvent.getToState()
630 <<
" exception: " << failedEvent.getException().what();
631 __SUP_COUT_ERR__ << error.str() << __E__;
636 void CoreSupervisorBase::preStateMachineExecutionLoop(
void)
638 RunControlStateMachine::clearIterationWork();
639 RunControlStateMachine::clearSubIterationWork();
641 stateMachinesIterationWorkCount_ = 0;
643 if(RunControlStateMachine::getIterationIndex() == 0 &&
644 RunControlStateMachine::getSubIterationIndex() == 0)
648 subIterationWorkStateMachineIndex_ = -1;
655 __SUP_COUT__ <<
"Iteration " << RunControlStateMachine::getIterationIndex() <<
"."
656 << RunControlStateMachine::getSubIterationIndex() <<
"("
657 << subIterationWorkStateMachineIndex_ <<
")" << __E__;
661 void CoreSupervisorBase::preStateMachineExecution(
unsigned int i)
663 if(i >= theStateMachineImplementation_.size())
665 __SUP_SS__ <<
"State Machine " << i <<
" not found!" << __E__;
669 theStateMachineImplementation_[i]->VStateMachine::setIterationIndex(
670 RunControlStateMachine::getIterationIndex());
671 theStateMachineImplementation_[i]->VStateMachine::setSubIterationIndex(
672 RunControlStateMachine::getSubIterationIndex());
674 theStateMachineImplementation_[i]->VStateMachine::clearIterationWork();
675 theStateMachineImplementation_[i]->VStateMachine::clearSubIterationWork();
678 <<
"theStateMachineImplementation Iteration "
679 << theStateMachineImplementation_[i]->VStateMachine::getIterationIndex() <<
"."
680 << theStateMachineImplementation_[i]->VStateMachine::getSubIterationIndex()
685 void CoreSupervisorBase::postStateMachineExecution(
unsigned int i)
687 if(i >= theStateMachineImplementation_.size())
689 __SUP_SS__ <<
"State Machine " << i <<
" not found!" << __E__;
694 if(theStateMachineImplementation_[i]->VStateMachine::getSubIterationWork())
696 subIterationWorkStateMachineIndex_ = i;
697 RunControlStateMachine::indicateSubIterationWork();
699 __SUP_COUT__ <<
"State machine " << i
700 <<
" is flagged for another sub-iteration..." << __E__;
705 !theStateMachineImplementation_[i]->VStateMachine::getIterationWork();
709 __SUP_COUT__ <<
"State machine " << i
710 <<
" is flagged for another iteration..." << __E__;
711 RunControlStateMachine::indicateIterationWork();
713 ++stateMachinesIterationWorkCount_;
719 void CoreSupervisorBase::postStateMachineExecutionLoop(
void)
721 if(RunControlStateMachine::subIterationWorkFlag_)
722 __SUP_COUT__ <<
"State machine implementation "
723 << subIterationWorkStateMachineIndex_
724 <<
" is flagged for another sub-iteration..." << __E__;
725 else if(RunControlStateMachine::iterationWorkFlag_)
727 << stateMachinesIterationWorkCount_
728 <<
" state machine implementation(s) flagged for another iteration..."
731 __SUP_COUT__ <<
"Done configuration all state machine implementations..."
736 void CoreSupervisorBase::transitionConfiguring(toolbox::Event::Reference )
738 __SUP_COUT__ <<
"transitionConfiguring" << __E__;
741 if(RunControlStateMachine::getIterationIndex() == 0 &&
742 RunControlStateMachine::getSubIterationIndex() == 0)
745 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
747 .getValue(
"ConfigurationTableGroupName"),
748 TableGroupKey(SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
750 .getValue(
"ConfigurationTableGroupKey")));
752 __SUP_COUT__ <<
"Configuration table group name: " << theGroup.first
753 <<
" key: " << theGroup.second << __E__;
771 ConfigurationManager::LoadGroupType::ALL_TYPES,
774 catch(
const std::runtime_error& e)
776 __SS__ <<
"Error loading table group '" << theGroup.first <<
"("
777 << theGroup.second <<
")! \n"
778 << e.what() << __E__;
779 __SUP_COUT_ERR__ << ss.str();
783 theStateMachine_.setErrorMessage(ss.str());
784 throw toolbox::fsm::exception::Exception(
787 "CoreSupervisorBase::transitionConfiguring" ,
794 __SS__ <<
"Unknown error loading table group '" << theGroup.first <<
"("
795 << theGroup.second <<
")!" << __E__;
800 catch(
const std::exception& e)
802 ss <<
"Exception message: " << e.what();
807 __SUP_COUT_ERR__ << ss.str();
811 theStateMachine_.setErrorMessage(ss.str());
812 throw toolbox::fsm::exception::Exception(
815 "CoreSupervisorBase::transitionConfiguring" ,
822 CoreSupervisorBase::transitionConfiguringFSMs();
824 __SUP_COUT__ <<
"Configured." << __E__;
828 void CoreSupervisorBase::transitionConfiguringFSMs()
835 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
836 preStateMachineExecutionLoop();
837 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
840 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
841 i != subIterationWorkStateMachineIndex_)
847 preStateMachineExecution(i);
848 theStateMachineImplementation_[i]->parentSupervisor_ =
850 theStateMachineImplementation_[i]->configure();
853 postStateMachineExecution(i);
855 postStateMachineExecutionLoop();
857 catch(
const std::runtime_error& e)
859 __SUP_SS__ <<
"Error was caught while configuring: " << e.what() << __E__;
860 __SUP_COUT_ERR__ <<
"\n" << ss.str();
861 theStateMachine_.setErrorMessage(ss.str());
862 throw toolbox::fsm::exception::Exception(
865 "CoreSupervisorBase::transitionConfiguring" ,
873 <<
"Unknown error was caught while configuring. Please checked the logs."
879 catch(
const std::exception& e)
881 ss <<
"Exception message: " << e.what();
886 __SUP_COUT_ERR__ <<
"\n" << ss.str();
887 theStateMachine_.setErrorMessage(ss.str());
888 throw toolbox::fsm::exception::Exception(
891 "CoreSupervisorBase::transitionConfiguring" ,
903 const std::string transitionName =
"Halting";
906 __SUP_COUT__ << transitionName <<
" all state machine implementations..."
908 preStateMachineExecutionLoop();
909 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
912 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
913 i != subIterationWorkStateMachineIndex_)
919 preStateMachineExecution(i);
920 theStateMachineImplementation_[i]->halt();
923 postStateMachineExecution(i);
925 postStateMachineExecutionLoop();
927 catch(
const std::runtime_error& e)
930 if(theStateMachine_.getProvenanceStateName() ==
931 RunControlStateMachine::FAILED_STATE_NAME)
933 __SUP_COUT_INFO__ <<
"Error was caught while halting (but ignoring because "
934 "previous state was '"
935 << RunControlStateMachine::FAILED_STATE_NAME
936 <<
"'): " << e.what() << __E__;
940 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
942 __SUP_COUT_ERR__ <<
"\n" << ss.str();
943 theStateMachine_.setErrorMessage(ss.str());
944 throw toolbox::fsm::exception::Exception(
947 "CoreSupervisorBase::transition" + transitionName ,
956 if(theStateMachine_.getProvenanceStateName() ==
957 RunControlStateMachine::FAILED_STATE_NAME)
959 __SUP_COUT_INFO__ <<
"Unknown error was caught while halting (but ignoring "
960 "because previous state was '"
961 << RunControlStateMachine::FAILED_STATE_NAME <<
"')."
966 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
967 <<
". Please checked the logs." << __E__;
972 catch(
const std::exception& e)
974 ss <<
"Exception message: " << e.what();
979 __SUP_COUT_ERR__ <<
"\n" << ss.str();
980 theStateMachine_.setErrorMessage(ss.str());
981 throw toolbox::fsm::exception::Exception(
984 "CoreSupervisorBase::transition" + transitionName ,
997 __SUP_COUT__ <<
"transitionInitializing" << __E__;
999 CorePropertySupervisorBase::resetPropertiesAreSetup();
1010 void CoreSupervisorBase::transitionPausing(toolbox::Event::Reference )
1012 const std::string transitionName =
"Pausing";
1015 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1016 preStateMachineExecutionLoop();
1017 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1020 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1021 i != subIterationWorkStateMachineIndex_)
1027 preStateMachineExecution(i);
1028 theStateMachineImplementation_[i]->pause();
1031 postStateMachineExecution(i);
1033 postStateMachineExecutionLoop();
1035 catch(
const std::runtime_error& e)
1037 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1039 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1040 theStateMachine_.setErrorMessage(ss.str());
1041 throw toolbox::fsm::exception::Exception(
1042 "Transition Error" ,
1044 "CoreSupervisorBase::transition" + transitionName ,
1051 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1052 <<
". Please checked the logs." << __E__;
1057 catch(
const std::exception& e)
1059 ss <<
"Exception message: " << e.what();
1064 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1065 theStateMachine_.setErrorMessage(ss.str());
1066 throw toolbox::fsm::exception::Exception(
1067 "Transition Error" ,
1069 "CoreSupervisorBase::transition" + transitionName ,
1077 void CoreSupervisorBase::transitionResuming(toolbox::Event::Reference )
1079 const std::string transitionName =
"Resuming";
1082 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1083 preStateMachineExecutionLoop();
1084 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1087 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1088 i != subIterationWorkStateMachineIndex_)
1094 preStateMachineExecution(i);
1095 theStateMachineImplementation_[i]->resume();
1098 postStateMachineExecution(i);
1100 postStateMachineExecutionLoop();
1102 catch(
const std::runtime_error& e)
1104 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1106 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1107 theStateMachine_.setErrorMessage(ss.str());
1108 throw toolbox::fsm::exception::Exception(
1109 "Transition Error" ,
1111 "CoreSupervisorBase::transition" + transitionName ,
1118 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1119 <<
". Please checked the logs." << __E__;
1124 catch(
const std::exception& e)
1126 ss <<
"Exception message: " << e.what();
1131 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1132 theStateMachine_.setErrorMessage(ss.str());
1133 throw toolbox::fsm::exception::Exception(
1134 "Transition Error" ,
1136 "CoreSupervisorBase::transition" + transitionName ,
1144 void CoreSupervisorBase::transitionStarting(toolbox::Event::Reference )
1146 const std::string transitionName =
"Starting";
1147 const std::string runNumber =
1148 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
1150 .getValue(
"RunNumber");
1153 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1154 preStateMachineExecutionLoop();
1155 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1158 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1159 i != subIterationWorkStateMachineIndex_)
1165 preStateMachineExecution(i);
1166 theStateMachineImplementation_[i]->start(runNumber);
1170 postStateMachineExecution(i);
1172 postStateMachineExecutionLoop();
1174 catch(
const std::runtime_error& e)
1176 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1178 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1179 theStateMachine_.setErrorMessage(ss.str());
1180 throw toolbox::fsm::exception::Exception(
1181 "Transition Error" ,
1183 "CoreSupervisorBase::transition" + transitionName ,
1190 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1191 <<
". Please checked the logs." << __E__;
1196 catch(
const std::exception& e)
1198 ss <<
"Exception message: " << e.what();
1203 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1204 theStateMachine_.setErrorMessage(ss.str());
1205 throw toolbox::fsm::exception::Exception(
1206 "Transition Error" ,
1208 "CoreSupervisorBase::transition" + transitionName ,
1216 void CoreSupervisorBase::transitionStopping(toolbox::Event::Reference )
1218 const std::string transitionName =
"Stopping";
1221 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1222 preStateMachineExecutionLoop();
1223 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1226 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1227 i != subIterationWorkStateMachineIndex_)
1233 preStateMachineExecution(i);
1234 theStateMachineImplementation_[i]->stop();
1237 postStateMachineExecution(i);
1239 postStateMachineExecutionLoop();
1241 catch(
const std::runtime_error& e)
1243 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1245 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1246 theStateMachine_.setErrorMessage(ss.str());
1247 throw toolbox::fsm::exception::Exception(
1248 "Transition Error" ,
1250 "CoreSupervisorBase::transition" + transitionName ,
1257 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1258 <<
". Please checked the logs." << __E__;
1263 catch(
const std::exception& e)
1265 ss <<
"Exception message: " << e.what();
1270 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1271 theStateMachine_.setErrorMessage(ss.str());
1272 throw toolbox::fsm::exception::Exception(
1273 "Transition Error" ,
1275 "CoreSupervisorBase::transition" + transitionName ,
1288 bool isPauseException,
1289 bool isStopException)
1293 __SUP_COUT_ERR__ <<
"Sending Supervisor Async STOP Running Exception... \n"
1294 << errorMessage << __E__;
1295 else if(isPauseException)
1296 __SUP_COUT_ERR__ <<
"Sending Supervisor Async SOFT Running Error... \n"
1297 << errorMessage << __E__;
1299 __SUP_COUT_ERR__ <<
"Sending Supervisor Async Running Error... \n"
1300 << errorMessage << __E__;
1302 theStateMachine_.setErrorMessage(errorMessage);
1304 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* gatewaySupervisor =
1308 parameters.addParameter(
"ErrorMessage", errorMessage);
1310 xoap::MessageReference replyMessage = SOAPMessenger::sendWithSOAPReply(
1312 isStopException ?
"AsyncStopException"
1313 : (isPauseException ?
"AsyncPauseException" :
"AsyncError"),
1316 std::stringstream replyMessageSStream;
1317 replyMessageSStream << SOAPUtilities::translate(replyMessage);
1318 __SUP_COUT__ <<
"Received... " << replyMessageSStream.str() << std::endl;
1320 if(replyMessageSStream.str().find(
"Fault") != std::string::npos)
1322 __SUP_COUT_ERR__ <<
"Failure to indicate fault to Gateway..." << __E__;
1326 catch(
const xdaq::exception::Exception& e)
1330 <<
"SOAP message failure indicating Supervisor asynchronous running STOP "
1331 "exception back to Gateway: "
1332 << e.what() << __E__;
1333 else if(isPauseException)
1335 <<
"SOAP message failure indicating Supervisor asynchronous running SOFT "
1336 "exception back to Gateway: "
1337 << e.what() << __E__;
1339 __SUP_COUT__ <<
"SOAP message failure indicating Supervisor asynchronous running "
1340 "error back to Gateway: "
1341 << e.what() << __E__;
1348 <<
"Unknown error encounter indicating Supervisor asynchronous running "
1349 "STOP exception back to Gateway."
1351 else if(isPauseException)
1353 <<
"Unknown error encounter indicating Supervisor asynchronous running "
1354 "SOFT error back to Gateway."
1358 <<
"Unknown error encounter indicating Supervisor asynchronous running "
1359 "error back to Gateway."
1365 xoap::MessageReference CoreSupervisorBase::TRACESupervisorRequest(
1366 xoap::MessageReference message)
1368 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, 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)
void INIT_MF(const char *name)
static std::string getTimeDurationString(const time_t durationInSeconds=time(0))