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_COUT__ <<
"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_COUT__ <<
"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::clearIterationWork();
696 RunControlStateMachine::clearSubIterationWork();
698 stateMachinesIterationWorkCount_ = 0;
700 if(RunControlStateMachine::getIterationIndex() == 0 &&
701 RunControlStateMachine::getSubIterationIndex() == 0)
705 subIterationWorkStateMachineIndex_ = -1;
712 __SUP_COUT__ <<
"Iteration " << RunControlStateMachine::getIterationIndex() <<
"."
713 << RunControlStateMachine::getSubIterationIndex() <<
"("
714 << subIterationWorkStateMachineIndex_ <<
")" << __E__;
718 void CoreSupervisorBase::preStateMachineExecution(
unsigned int i)
720 if(i >= theStateMachineImplementation_.size())
722 __SUP_SS__ <<
"State Machine " << i <<
" not found!" << __E__;
726 theStateMachineImplementation_[i]->VStateMachine::setIterationIndex(
727 RunControlStateMachine::getIterationIndex());
728 theStateMachineImplementation_[i]->VStateMachine::setSubIterationIndex(
729 RunControlStateMachine::getSubIterationIndex());
730 theStateMachineImplementation_[i]
731 ->VStateMachine::setSystemMinReadyForEventGenerationStartIteration(
732 RunControlStateMachine::getMinReadyForEventGenerationStartIteration());
734 theStateMachineImplementation_[i]->VStateMachine::clearIterationWork();
735 theStateMachineImplementation_[i]->VStateMachine::clearSubIterationWork();
738 <<
"theStateMachineImplementation Iteration "
739 << theStateMachineImplementation_[i]->VStateMachine::getIterationIndex() <<
"."
740 << theStateMachineImplementation_[i]->VStateMachine::getSubIterationIndex()
745 void CoreSupervisorBase::postStateMachineExecution(
unsigned int i)
747 if(i >= theStateMachineImplementation_.size())
749 __SUP_SS__ <<
"State Machine " << i <<
" not found!" << __E__;
754 if(theStateMachineImplementation_[i]->VStateMachine::getSubIterationWork())
756 subIterationWorkStateMachineIndex_ = i;
757 RunControlStateMachine::indicateSubIterationWork();
759 __SUP_COUT__ <<
"State machine " << i
760 <<
" is flagged for another sub-iteration..." << __E__;
765 !theStateMachineImplementation_[i]->VStateMachine::getIterationWork();
769 __SUP_COUT__ <<
"State machine " << i
770 <<
" is flagged for another iteration..." << __E__;
771 RunControlStateMachine::indicateIterationWork();
773 ++stateMachinesIterationWorkCount_;
779 void CoreSupervisorBase::postStateMachineExecutionLoop(
void)
781 if(RunControlStateMachine::subIterationWorkFlag_)
782 __SUP_COUT__ <<
"State machine implementation "
783 << subIterationWorkStateMachineIndex_
784 <<
" is flagged for another sub-iteration..." << __E__;
785 else if(RunControlStateMachine::iterationWorkFlag_)
787 << stateMachinesIterationWorkCount_
788 <<
" state machine implementation(s) flagged for another iteration..."
791 __SUP_COUT__ <<
"Done configuration all state machine implementations..."
796 void CoreSupervisorBase::configureInit(
void)
800 if(!(RunControlStateMachine::getIterationIndex() == 0 &&
801 RunControlStateMachine::getSubIterationIndex() == 0))
804 __SUP_COUT__ <<
"configureInit()" << __E__;
807 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
809 .getValue(
"ConfigurationTableGroupName"),
810 TableGroupKey(SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
812 .getValue(
"ConfigurationTableGroupKey")));
814 __SUP_COUT__ <<
"Configuration table group name: " << theGroup.first
815 <<
" key: " << theGroup.second << __E__;
818 StringMacros::systemVariables_[
"ActiveStateMachine"][
"name"] =
819 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
821 .getValue(
"ActiveStateMachineName");
822 StringMacros::systemVariables_[
"ActiveStateMachine"][
"windowName"] =
823 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
825 .getValue(
"ActiveStateMachineWindowName");
826 StringMacros::systemVariables_[
"ActiveStateMachine"][
"runAlias"] =
827 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
829 .getValue(
"ActiveStateMachineRunAlias");
833 std::map<std::string ,
TableVersion> mergeInTables, overrideTables;
836 std::string subsystemCommonList;
839 subsystemCommonList =
840 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
842 .getValue(
"SubsystemCommonList");
846 __COUT__ <<
"Ignoring missing 'SubsystemCommonList' parameter." << __E__;
849 if(!subsystemCommonList.empty())
851 subsystemCommonList =
853 __COUT__ <<
"Transition parameter SubsystemCommonList: "
854 << subsystemCommonList << __E__;
861 std::string subsystemCommonOverrideList;
864 subsystemCommonOverrideList =
865 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
867 .getValue(
"SubsystemCommonOverrideList");
871 __COUT__ <<
"Ignoring missing 'SubsystemCommonOverrideList' parameter."
875 if(!subsystemCommonOverrideList.empty())
877 subsystemCommonOverrideList =
879 __COUT__ <<
"Transition parameter SubsystemCommonOverrideList: "
880 << subsystemCommonOverrideList << __E__;
891 theConfigurationManager_);
906 ConfigurationManager::LoadGroupType::ALL_TYPES,
912 catch(
const std::runtime_error& e)
914 __SS__ <<
"Error loading table group '" << theGroup.first <<
"("
915 << theGroup.second <<
")! \n"
916 << e.what() << __E__;
917 __SUP_COUT_ERR__ << ss.str();
921 theStateMachine_.setErrorMessage(ss.str());
922 throw toolbox::fsm::exception::Exception(
925 "CoreSupervisorBase::configureInit" ,
932 __SS__ <<
"Unknown error loading table group '" << theGroup.first <<
"("
933 << theGroup.second <<
")!" << __E__;
938 catch(
const std::exception& e)
940 ss <<
"Exception message: " << e.what();
945 __SUP_COUT_ERR__ << ss.str();
949 theStateMachine_.setErrorMessage(ss.str());
950 throw toolbox::fsm::exception::Exception(
953 "CoreSupervisorBase::configureInit" ,
961 void CoreSupervisorBase::transitionConfiguring(toolbox::Event::Reference )
963 __SUP_COUT__ <<
"transitionConfiguring()" << __E__;
965 CoreSupervisorBase::configureInit();
967 CoreSupervisorBase::transitionConfiguringFSMs();
969 __SUP_COUT__ <<
"Configured." << __E__;
973 void CoreSupervisorBase::transitionConfiguringFSMs()
980 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
981 preStateMachineExecutionLoop();
982 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
985 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
986 i != subIterationWorkStateMachineIndex_)
992 preStateMachineExecution(i);
993 theStateMachineImplementation_[i]->parentSupervisor_ =
995 theStateMachineImplementation_[i]->configure();
998 postStateMachineExecution(i);
1000 postStateMachineExecutionLoop();
1002 catch(
const std::runtime_error& e)
1004 __SUP_SS__ <<
"Error was caught while configuring: " << e.what() << __E__;
1005 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1006 theStateMachine_.setErrorMessage(ss.str());
1007 throw toolbox::fsm::exception::Exception(
1008 "Transition Error" ,
1010 "CoreSupervisorBase::transitionConfiguringFSMs" ,
1018 <<
"Unknown error was caught while configuring. Please checked the logs."
1024 catch(
const std::exception& e)
1026 ss <<
"Exception message: " << e.what();
1031 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1032 theStateMachine_.setErrorMessage(ss.str());
1033 throw toolbox::fsm::exception::Exception(
1034 "Transition Error" ,
1036 "CoreSupervisorBase::transitionConfiguringFSMs" ,
1048 const std::string transitionName =
"Halting";
1051 __SUP_COUT__ << transitionName <<
" all state machine implementations..."
1053 preStateMachineExecutionLoop();
1054 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1057 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1058 i != subIterationWorkStateMachineIndex_)
1064 preStateMachineExecution(i);
1065 theStateMachineImplementation_[i]->halt();
1068 postStateMachineExecution(i);
1070 postStateMachineExecutionLoop();
1072 catch(
const std::runtime_error& e)
1075 if(theStateMachine_.getProvenanceStateName() ==
1076 RunControlStateMachine::FAILED_STATE_NAME ||
1077 theStateMachine_.getProvenanceStateName() ==
1078 RunControlStateMachine::HALTED_STATE_NAME)
1080 __SUP_COUT_INFO__ <<
"Error was caught while halting (but ignoring because "
1081 "previous state was '"
1082 << theStateMachine_.getProvenanceStateName()
1083 <<
"'): " << e.what() << __E__;
1087 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1089 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1090 theStateMachine_.setErrorMessage(ss.str());
1091 throw toolbox::fsm::exception::Exception(
1092 "Transition Error" ,
1094 "CoreSupervisorBase::transition" + transitionName ,
1103 if(theStateMachine_.getProvenanceStateName() ==
1104 RunControlStateMachine::FAILED_STATE_NAME ||
1105 theStateMachine_.getProvenanceStateName() ==
1106 RunControlStateMachine::HALTED_STATE_NAME)
1108 __SUP_COUT_INFO__ <<
"Unknown error was caught while halting (but ignoring "
1109 "because previous state was '"
1110 << theStateMachine_.getProvenanceStateName() <<
"')."
1115 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1116 <<
". Please checked the logs." << __E__;
1121 catch(
const std::exception& e)
1123 ss <<
"Exception message: " << e.what();
1128 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1129 theStateMachine_.setErrorMessage(ss.str());
1130 throw toolbox::fsm::exception::Exception(
1131 "Transition Error" ,
1133 "CoreSupervisorBase::transition" + transitionName ,
1146 __SUP_COUT__ <<
"transitionInitializing" << __E__;
1148 CorePropertySupervisorBase::resetPropertiesAreSetup();
1159 void CoreSupervisorBase::transitionPausing(toolbox::Event::Reference )
1161 const std::string transitionName =
"Pausing";
1164 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1165 preStateMachineExecutionLoop();
1166 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1169 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1170 i != subIterationWorkStateMachineIndex_)
1176 preStateMachineExecution(i);
1177 theStateMachineImplementation_[i]->pause();
1180 postStateMachineExecution(i);
1182 postStateMachineExecutionLoop();
1184 catch(
const std::runtime_error& e)
1186 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1188 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1189 theStateMachine_.setErrorMessage(ss.str());
1190 throw toolbox::fsm::exception::Exception(
1191 "Transition Error" ,
1193 "CoreSupervisorBase::transition" + transitionName ,
1200 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1201 <<
". Please checked the logs." << __E__;
1206 catch(
const std::exception& e)
1208 ss <<
"Exception message: " << e.what();
1213 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1214 theStateMachine_.setErrorMessage(ss.str());
1215 throw toolbox::fsm::exception::Exception(
1216 "Transition Error" ,
1218 "CoreSupervisorBase::transition" + transitionName ,
1226 void CoreSupervisorBase::transitionResuming(toolbox::Event::Reference )
1228 const std::string transitionName =
"Resuming";
1231 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1232 preStateMachineExecutionLoop();
1233 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1236 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1237 i != subIterationWorkStateMachineIndex_)
1243 preStateMachineExecution(i);
1244 theStateMachineImplementation_[i]->resume();
1247 postStateMachineExecution(i);
1249 postStateMachineExecutionLoop();
1251 catch(
const std::runtime_error& e)
1253 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1255 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1256 theStateMachine_.setErrorMessage(ss.str());
1257 throw toolbox::fsm::exception::Exception(
1258 "Transition Error" ,
1260 "CoreSupervisorBase::transition" + transitionName ,
1267 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1268 <<
". Please checked the logs." << __E__;
1273 catch(
const std::exception& e)
1275 ss <<
"Exception message: " << e.what();
1280 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1281 theStateMachine_.setErrorMessage(ss.str());
1282 throw toolbox::fsm::exception::Exception(
1283 "Transition Error" ,
1285 "CoreSupervisorBase::transition" + transitionName ,
1293 void CoreSupervisorBase::transitionStarting(toolbox::Event::Reference )
1295 const std::string transitionName =
"Starting";
1296 const std::string runNumber =
1297 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
1299 .getValue(
"RunNumber");
1302 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1303 preStateMachineExecutionLoop();
1304 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1307 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1308 i != subIterationWorkStateMachineIndex_)
1314 preStateMachineExecution(i);
1315 theStateMachineImplementation_[i]->start(runNumber);
1319 postStateMachineExecution(i);
1321 postStateMachineExecutionLoop();
1323 catch(
const std::runtime_error& e)
1325 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1327 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1328 theStateMachine_.setErrorMessage(ss.str());
1329 throw toolbox::fsm::exception::Exception(
1330 "Transition Error" ,
1332 "CoreSupervisorBase::transition" + transitionName ,
1339 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1340 <<
". Please checked the logs." << __E__;
1345 catch(
const std::exception& e)
1347 ss <<
"Exception message: " << e.what();
1352 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1353 theStateMachine_.setErrorMessage(ss.str());
1354 throw toolbox::fsm::exception::Exception(
1355 "Transition Error" ,
1357 "CoreSupervisorBase::transition" + transitionName ,
1365 void CoreSupervisorBase::transitionStopping(toolbox::Event::Reference )
1367 const std::string transitionName =
"Stopping";
1370 __SUP_COUT__ <<
"Configuring all state machine implementations..." << __E__;
1371 preStateMachineExecutionLoop();
1372 for(
unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1375 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
1376 i != subIterationWorkStateMachineIndex_)
1382 preStateMachineExecution(i);
1383 theStateMachineImplementation_[i]->stop();
1386 postStateMachineExecution(i);
1388 postStateMachineExecutionLoop();
1390 catch(
const std::runtime_error& e)
1392 __SUP_SS__ <<
"Error was caught while " << transitionName <<
": " << e.what()
1394 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1395 theStateMachine_.setErrorMessage(ss.str());
1396 throw toolbox::fsm::exception::Exception(
1397 "Transition Error" ,
1399 "CoreSupervisorBase::transition" + transitionName ,
1406 __SUP_SS__ <<
"Unknown error was caught while " << transitionName
1407 <<
". Please checked the logs." << __E__;
1412 catch(
const std::exception& e)
1414 ss <<
"Exception message: " << e.what();
1419 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1420 theStateMachine_.setErrorMessage(ss.str());
1421 throw toolbox::fsm::exception::Exception(
1422 "Transition Error" ,
1424 "CoreSupervisorBase::transition" + transitionName ,
1437 bool isPauseException,
1438 bool isStopException)
1442 __SUP_COUT_ERR__ <<
"Sending Supervisor Async STOP Running Exception... \n"
1443 << errorMessage << __E__;
1444 else if(isPauseException)
1445 __SUP_COUT_ERR__ <<
"Sending Supervisor Async SOFT Running Error... \n"
1446 << errorMessage << __E__;
1448 __SUP_COUT_ERR__ <<
"Sending Supervisor Async Running Error... \n"
1449 << errorMessage << __E__;
1451 theStateMachine_.setErrorMessage(errorMessage);
1453 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* gatewaySupervisor =
1457 parameters.addParameter(
"ErrorMessage", errorMessage);
1459 xoap::MessageReference replyMessage = SOAPMessenger::sendWithSOAPReply(
1461 isStopException ?
"AsyncStopException"
1462 : (isPauseException ?
"AsyncPauseException" :
"AsyncError"),
1465 std::stringstream replyMessageSStream;
1466 replyMessageSStream << SOAPUtilities::translate(replyMessage);
1467 __SUP_COUT__ <<
"Received... " << replyMessageSStream.str() << std::endl;
1469 if(replyMessageSStream.str().find(
"Fault") != std::string::npos)
1471 __SUP_COUT_ERR__ <<
"Failure to indicate fault to Gateway..." << __E__;
1475 catch(
const xdaq::exception::Exception& e)
1479 <<
"SOAP message failure indicating Supervisor asynchronous running STOP "
1480 "exception back to Gateway: "
1481 << e.what() << __E__;
1482 else if(isPauseException)
1484 <<
"SOAP message failure indicating Supervisor asynchronous running SOFT "
1485 "exception back to Gateway: "
1486 << e.what() << __E__;
1488 __SUP_COUT__ <<
"SOAP message failure indicating Supervisor asynchronous running "
1489 "error back to Gateway: "
1490 << e.what() << __E__;
1497 <<
"Unknown error encounter indicating Supervisor asynchronous running "
1498 "STOP exception back to Gateway."
1500 else if(isPauseException)
1502 <<
"Unknown error encounter indicating Supervisor asynchronous running "
1503 "SOFT error back to Gateway."
1507 <<
"Unknown error encounter indicating Supervisor asynchronous running "
1508 "error back to Gateway."
1514 xoap::MessageReference CoreSupervisorBase::TRACESupervisorRequest(
1515 xoap::MessageReference message)
1517 return CorePropertySupervisorBase::TRACESupervisorRequest(message);
static std::string getOrPostData(cgicc::Cgicc &cgi, const std::string &needle)
static std::string getData(cgicc::Cgicc &cgi, const std::string &needle)
void loadTableGroup(const std::string &tableGroupName, const TableGroupKey &tableGroupKey, bool doActivate=false, std::map< std::string, TableVersion > *groupMembers=0, ProgressBar *progressBar=0, std::string *accumulateWarnings=0, std::string *groupComment=0, std::string *groupAuthor=0, std::string *groupCreateTime=0, bool doNotLoadMember=false, std::string *groupTypeString=0, std::map< std::string, std::string > *groupAliases=0, ConfigurationManager::LoadGroupType groupTypeToLoad=ConfigurationManager::LoadGroupType::ALL_TYPES, bool ignoreVersionTracking=false, std::map< std::string, TableVersion > mergeInTables={}, std::map< std::string, TableVersion > overrideTables={})
void getRequestUserInfo(WebUsers::RequestUserInfo &requestUserInfo)
virtual void transitionHalting(toolbox::Event::Reference event)
virtual void stateInitial(toolbox::fsm::FiniteStateMachine &fsm)
void stateMachineXgiHandler(xgi::Input *in, xgi::Output *out)
State Machine request handlers.
virtual void request(const std::string &requestType, cgicc::Cgicc &cgiIn, HttpXmlDocument &xmlOut, const WebUsers::RequestUserInfo &userInfo)
virtual void stateConfigured(toolbox::fsm::FiniteStateMachine &fsm)
virtual std::string getStatusProgressDetail(void)
virtual void statePaused(toolbox::fsm::FiniteStateMachine &fsm)
virtual void stateRunning(toolbox::fsm::FiniteStateMachine &fsm)
virtual void transitionInitializing(toolbox::Event::Reference event)
virtual void defaultPage(xgi::Input *in, xgi::Output *out)
virtual void nonXmlRequest(const std::string &requestType, cgicc::Cgicc &cgiIn, std::ostream &out, const WebUsers::RequestUserInfo &userInfo)
std::vector< bool > stateMachinesIterationDone_
for managing transition iterations
void sendAsyncExceptionToGateway(const std::string &errMsg, bool isPauseException, bool isStopException)
virtual void stateHalted(toolbox::fsm::FiniteStateMachine &fsm)
time_t getTimeInState(void) const
void outputXmlDocument(std::ostringstream *out, bool dispStdOut=false, bool allowWhiteSpace=false, bool printErrors=false)
bool xmlRequestToGateway(cgicc::Cgicc &cgi, std::ostringstream *out, HttpXmlDocument *xmldoc, const AllSupervisorInfo &allSupervisorInfo, WebUsers::RequestUserInfo &userInfo)
std::string send(XDAQ_CONST_CALL xdaq::ApplicationDescriptor *d, xoap::MessageReference message)
XDAQ_CONST_CALL xdaq::ApplicationDescriptor * getDescriptor(void) const
Getters ----------------—.
HttpXmlDocument processRequest(cgicc::Cgicc &cgi)
defines used also by OtsConfigurationWizardSupervisor
void INIT_MF(const char *name)
static std::string mapToString(const std::map< std::string, T > &mapToReturn, const std::string &primaryDelimeter=", ", const std::string &secondaryDelimeter=": ")
static void getMapFromString(const std::string &inputString, std::map< S, T > &mapToReturn, const std::set< char > &pairPairDelimiter={',', '|', '&'}, const std::set< char > &nameValueDelimiter={'=', ':'}, const std::set< char > &whitespace={' ', '\t', '\n', '\r'})
getMapFromString ~
static std::string getTimeDurationString(const time_t durationInSeconds=time(0))
static std::string decodeURIComponent(const std::string &data)