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::transitionConfiguring(toolbox::Event::Reference )
759 __SUP_COUT__ <<
"transitionConfiguring" << __E__;
762 if(RunControlStateMachine::getIterationIndex() == 0 &&
763 RunControlStateMachine::getSubIterationIndex() == 0)
766 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
768 .getValue(
"ConfigurationTableGroupName"),
769 TableGroupKey(SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
771 .getValue(
"ConfigurationTableGroupKey")));
773 __SUP_COUT__ <<
"Configuration table group name: " << theGroup.first
774 <<
" key: " << theGroup.second << __E__;
792 ConfigurationManager::LoadGroupType::ALL_TYPES,
795 catch(
const std::runtime_error& e)
797 __SS__ <<
"Error loading table group '" << theGroup.first <<
"("
798 << theGroup.second <<
")! \n"
799 << e.what() << __E__;
800 __SUP_COUT_ERR__ << ss.str();
804 theStateMachine_.setErrorMessage(ss.str());
805 throw toolbox::fsm::exception::Exception(
808 "CoreSupervisorBase::transitionConfiguring" ,
815 __SS__ <<
"Unknown error loading table group '" << theGroup.first <<
"("
816 << theGroup.second <<
")!" << __E__;
821 catch(
const std::exception& e)
823 ss <<
"Exception message: " << e.what();
828 __SUP_COUT_ERR__ << ss.str();
832 theStateMachine_.setErrorMessage(ss.str());
833 throw toolbox::fsm::exception::Exception(
836 "CoreSupervisorBase::transitionConfiguring" ,
843 CoreSupervisorBase::transitionConfiguringFSMs();
845 __SUP_COUT__ <<
"Configured." << __E__;
849 void CoreSupervisorBase::transitionConfiguringFSMs()
856 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
857 preStateMachineExecutionLoop();
858 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
861 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
862 i != subIterationWorkStateMachineIndex_)
868 preStateMachineExecution(i);
869 theStateMachineImplementation_[i]->parentSupervisor_ =
871 theStateMachineImplementation_[i]->configure();
874 postStateMachineExecution(i);
876 postStateMachineExecutionLoop();
878 catch(
const std::runtime_error& e)
880 __SUP_SS__ <<
"Error was caught while configuring: " << e.what() << __E__;
881 __SUP_COUT_ERR__ <<
"\n" << ss.str();
882 theStateMachine_.setErrorMessage(ss.str());
883 throw toolbox::fsm::exception::Exception(
886 "CoreSupervisorBase::transitionConfiguring" ,
894 <<
"Unknown error was caught while configuring. Please checked the logs."
900 catch(
const std::exception& e)
902 ss <<
"Exception message: " << e.what();
907 __SUP_COUT_ERR__ <<
"\n" << ss.str();
908 theStateMachine_.setErrorMessage(ss.str());
909 throw toolbox::fsm::exception::Exception(
912 "CoreSupervisorBase::transitionConfiguring" ,
924 const std::string transitionName =
"Halting";
927 __SUP_COUT__ << transitionName <<
" all state machine implementations..."
929 preStateMachineExecutionLoop();
930 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
933 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
934 i != subIterationWorkStateMachineIndex_)
940 preStateMachineExecution(i);
941 theStateMachineImplementation_[i]->halt();
944 postStateMachineExecution(i);
946 postStateMachineExecutionLoop();
948 catch(
const std::runtime_error& e)
951 if(theStateMachine_.getProvenanceStateName() ==
952 RunControlStateMachine::FAILED_STATE_NAME)
954 __SUP_COUT_INFO__ <<
"Error was caught while halting (but ignoring because "
955 "previous state was '"
956 << RunControlStateMachine::FAILED_STATE_NAME
957 <<
"'): " << e.what() << __E__;
961 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
963 __SUP_COUT_ERR__ <<
"\n" << ss.str();
964 theStateMachine_.setErrorMessage(ss.str());
965 throw toolbox::fsm::exception::Exception(
968 "CoreSupervisorBase::transition" + transitionName ,
977 if(theStateMachine_.getProvenanceStateName() ==
978 RunControlStateMachine::FAILED_STATE_NAME)
980 __SUP_COUT_INFO__ <<
"Unknown error was caught while halting (but ignoring "
981 "because previous state was '"
982 << RunControlStateMachine::FAILED_STATE_NAME <<
"')."
987 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
988 <<
". Please checked the logs." << __E__;
993 catch(
const std::exception& e)
995 ss <<
"Exception message: " << e.what();
1000 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1001 theStateMachine_.setErrorMessage(ss.str());
1002 throw toolbox::fsm::exception::Exception(
1003 "Transition Error" ,
1005 "CoreSupervisorBase::transition" + transitionName ,
1018 __SUP_COUT__ <<
"transitionInitializing" << __E__;
1020 CorePropertySupervisorBase::resetPropertiesAreSetup();
1031 void CoreSupervisorBase::transitionPausing(toolbox::Event::Reference )
1033 const std::string transitionName =
"Pausing";
1036 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1037 preStateMachineExecutionLoop();
1038 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1041 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1042 i != subIterationWorkStateMachineIndex_)
1048 preStateMachineExecution(i);
1049 theStateMachineImplementation_[i]->pause();
1052 postStateMachineExecution(i);
1054 postStateMachineExecutionLoop();
1056 catch(
const std::runtime_error& e)
1058 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1060 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1061 theStateMachine_.setErrorMessage(ss.str());
1062 throw toolbox::fsm::exception::Exception(
1063 "Transition Error" ,
1065 "CoreSupervisorBase::transition" + transitionName ,
1072 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1073 <<
". Please checked the logs." << __E__;
1078 catch(
const std::exception& e)
1080 ss <<
"Exception message: " << e.what();
1085 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1086 theStateMachine_.setErrorMessage(ss.str());
1087 throw toolbox::fsm::exception::Exception(
1088 "Transition Error" ,
1090 "CoreSupervisorBase::transition" + transitionName ,
1098 void CoreSupervisorBase::transitionResuming(toolbox::Event::Reference )
1100 const std::string transitionName =
"Resuming";
1103 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1104 preStateMachineExecutionLoop();
1105 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1108 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1109 i != subIterationWorkStateMachineIndex_)
1115 preStateMachineExecution(i);
1116 theStateMachineImplementation_[i]->resume();
1119 postStateMachineExecution(i);
1121 postStateMachineExecutionLoop();
1123 catch(
const std::runtime_error& e)
1125 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1127 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1128 theStateMachine_.setErrorMessage(ss.str());
1129 throw toolbox::fsm::exception::Exception(
1130 "Transition Error" ,
1132 "CoreSupervisorBase::transition" + transitionName ,
1139 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1140 <<
". Please checked the logs." << __E__;
1145 catch(
const std::exception& e)
1147 ss <<
"Exception message: " << e.what();
1152 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1153 theStateMachine_.setErrorMessage(ss.str());
1154 throw toolbox::fsm::exception::Exception(
1155 "Transition Error" ,
1157 "CoreSupervisorBase::transition" + transitionName ,
1165 void CoreSupervisorBase::transitionStarting(toolbox::Event::Reference )
1167 const std::string transitionName =
"Starting";
1168 const std::string runNumber =
1169 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
1171 .getValue(
"RunNumber");
1174 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1175 preStateMachineExecutionLoop();
1176 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1179 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1180 i != subIterationWorkStateMachineIndex_)
1186 preStateMachineExecution(i);
1187 theStateMachineImplementation_[i]->start(runNumber);
1191 postStateMachineExecution(i);
1193 postStateMachineExecutionLoop();
1195 catch(
const std::runtime_error& e)
1197 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1199 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1200 theStateMachine_.setErrorMessage(ss.str());
1201 throw toolbox::fsm::exception::Exception(
1202 "Transition Error" ,
1204 "CoreSupervisorBase::transition" + transitionName ,
1211 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1212 <<
". Please checked the logs." << __E__;
1217 catch(
const std::exception& e)
1219 ss <<
"Exception message: " << e.what();
1224 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1225 theStateMachine_.setErrorMessage(ss.str());
1226 throw toolbox::fsm::exception::Exception(
1227 "Transition Error" ,
1229 "CoreSupervisorBase::transition" + transitionName ,
1237 void CoreSupervisorBase::transitionStopping(toolbox::Event::Reference )
1239 const std::string transitionName =
"Stopping";
1242 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1243 preStateMachineExecutionLoop();
1244 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1247 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1248 i != subIterationWorkStateMachineIndex_)
1254 preStateMachineExecution(i);
1255 theStateMachineImplementation_[i]->stop();
1258 postStateMachineExecution(i);
1260 postStateMachineExecutionLoop();
1262 catch(
const std::runtime_error& e)
1264 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1266 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1267 theStateMachine_.setErrorMessage(ss.str());
1268 throw toolbox::fsm::exception::Exception(
1269 "Transition Error" ,
1271 "CoreSupervisorBase::transition" + transitionName ,
1278 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1279 <<
". Please checked the logs." << __E__;
1284 catch(
const std::exception& e)
1286 ss <<
"Exception message: " << e.what();
1291 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1292 theStateMachine_.setErrorMessage(ss.str());
1293 throw toolbox::fsm::exception::Exception(
1294 "Transition Error" ,
1296 "CoreSupervisorBase::transition" + transitionName ,
1309 bool isPauseException,
1310 bool isStopException)
1314 __SUP_COUT_ERR__ <<
"Sending Supervisor Async STOP Running Exception... \n"
1315 << errorMessage << __E__;
1316 else if(isPauseException)
1317 __SUP_COUT_ERR__ <<
"Sending Supervisor Async SOFT Running Error... \n"
1318 << errorMessage << __E__;
1320 __SUP_COUT_ERR__ <<
"Sending Supervisor Async Running Error... \n"
1321 << errorMessage << __E__;
1323 theStateMachine_.setErrorMessage(errorMessage);
1325 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* gatewaySupervisor =
1329 parameters.addParameter(
"ErrorMessage", errorMessage);
1331 xoap::MessageReference replyMessage = SOAPMessenger::sendWithSOAPReply(
1333 isStopException ?
"AsyncStopException"
1334 : (isPauseException ?
"AsyncPauseException" :
"AsyncError"),
1337 std::stringstream replyMessageSStream;
1338 replyMessageSStream << SOAPUtilities::translate(replyMessage);
1339 __SUP_COUT__ <<
"Received... " << replyMessageSStream.str() << std::endl;
1341 if(replyMessageSStream.str().find(
"Fault") != std::string::npos)
1343 __SUP_COUT_ERR__ <<
"Failure to indicate fault to Gateway..." << __E__;
1347 catch(
const xdaq::exception::Exception& e)
1351 <<
"SOAP message failure indicating Supervisor asynchronous running STOP "
1352 "exception back to Gateway: "
1353 << e.what() << __E__;
1354 else if(isPauseException)
1356 <<
"SOAP message failure indicating Supervisor asynchronous running SOFT "
1357 "exception back to Gateway: "
1358 << e.what() << __E__;
1360 __SUP_COUT__ <<
"SOAP message failure indicating Supervisor asynchronous running "
1361 "error back to Gateway: "
1362 << e.what() << __E__;
1369 <<
"Unknown error encounter indicating Supervisor asynchronous running "
1370 "STOP exception back to Gateway."
1372 else if(isPauseException)
1374 <<
"Unknown error encounter indicating Supervisor asynchronous running "
1375 "SOFT error back to Gateway."
1379 <<
"Unknown error encounter indicating Supervisor asynchronous running "
1380 "error back to Gateway."
1386 xoap::MessageReference CoreSupervisorBase::TRACESupervisorRequest(
1387 xoap::MessageReference message)
1389 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)
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 getTimeDurationString(const time_t durationInSeconds=time(0))