otsdaq  3.04.02
CoreSupervisorBase.cc
1 #include "otsdaq/CoreSupervisors/CoreSupervisorBase.h"
2 
3 #include <iostream>
4 
5 using namespace ots;
6 
7 // XDAQ_INSTANTIATOR_IMPL(CoreSupervisorBase)
8 
9 const std::string CoreSupervisorBase::WORK_LOOP_DONE = "Done";
10 const std::string CoreSupervisorBase::WORK_LOOP_WORKING = "Working";
11 
12 //==============================================================================
13 CoreSupervisorBase::CoreSupervisorBase(xdaq::ApplicationStub* stub)
14  : xdaq::Application(stub)
15  , SOAPMessenger(this)
18  CorePropertySupervisorBase::allSupervisorInfo_.isWizardMode()
19  ? // set state machine name
20  CorePropertySupervisorBase::supervisorClassNoNamespace_
21  : CorePropertySupervisorBase::supervisorClassNoNamespace_ + ":" +
22  CorePropertySupervisorBase::getSupervisorUID())
23  , stateMachineWorkLoopManager_(toolbox::task::bind(
24  this, &CoreSupervisorBase::stateMachineThread, "StateMachine"))
25  , stateMachineSemaphore_(toolbox::BSem::FULL)
26  , theRemoteWebUsers_(this,
27  CorePropertySupervisorBase::getGatewaySupervisorDescriptor())
28 {
29  __SUP_COUT__ << "Constructor." << __E__;
30 
31  INIT_MF("." /*directory used is USER_DATA/LOG/.*/);
32 
33  xgi::bind(this, &CoreSupervisorBase::defaultPageWrapper, "Default");
34  xgi::bind(this, &CoreSupervisorBase::requestWrapper, "Request");
35 
36  xgi::bind(
37  this, &CoreSupervisorBase::stateMachineXgiHandler, "StateMachineXgiHandler");
38 
39  xoap::bind(this,
40  &CoreSupervisorBase::stateMachineStateRequest,
41  "StateMachineStateRequest",
42  XDAQ_NS_URI);
43  xoap::bind(this,
44  &CoreSupervisorBase::stateMachineErrorMessageRequest,
45  "StateMachineErrorMessageRequest",
46  XDAQ_NS_URI);
47  xoap::bind(this,
48  &CoreSupervisorBase::workLoopStatusRequestWrapper,
49  "WorkLoopStatusRequest",
50  XDAQ_NS_URI);
51  xoap::bind(this,
52  &CoreSupervisorBase::applicationStatusRequest,
53  "ApplicationStatusRequest",
54  XDAQ_NS_URI);
55  xoap::bind(this,
56  &CoreSupervisorBase::TRACESupervisorRequest,
57  "TRACESupervisorRequest",
58  XDAQ_NS_URI);
59 
60  __SUP_COUT__ << "Constructed. getpid()=" << getpid() << " gettid()=" << gettid()
61  << __E__;
62 } // end constructor
63 
64 //==============================================================================
65 CoreSupervisorBase::~CoreSupervisorBase(void)
66 {
67  __SUP_COUT__ << "Destructor." << __E__;
68  destroy();
69  __SUP_COUT__ << "Destructed." << __E__;
70 } // end destructor()
71 
72 //==============================================================================
73 void CoreSupervisorBase::destroy(void)
74 {
75  __SUP_COUT__ << "Destroying..." << __E__;
76  for(auto& it : theStateMachineImplementation_)
77  delete it;
78 
79  theStateMachineImplementation_.clear();
80 } // end destroy()
81 
82 //==============================================================================
84 void CoreSupervisorBase::defaultPageWrapper(xgi::Input* in, xgi::Output* out)
85 {
86  return defaultPage(in, out);
87 }
88 
89 //==============================================================================
90 void CoreSupervisorBase::defaultPage(xgi::Input* /*in*/, xgi::Output* out)
91 {
92  __SUP_COUT__ << "Supervisor class " << supervisorClass_ << __E__;
93 
94  std::stringstream pagess;
95  pagess << "/WebPath/html/" << supervisorClassNoNamespace_
96  << ".html?urn=" << this->getApplicationDescriptor()->getLocalId();
97 
98  __SUP_COUT__ << "Default page = " << pagess.str() << __E__;
99 
100  *out << "<!DOCTYPE HTML><html lang='en'><frameset col='100%' row='100%'><frame src='"
101  << pagess.str() << "'></frameset></html>";
102 } // end defaultPage()
103 
104 //==============================================================================
107 void CoreSupervisorBase::requestWrapper(xgi::Input* in, xgi::Output* out)
108 try
109 {
110  out->getHTTPResponseHeader().addHeader(
111  "Access-Control-Allow-Origin",
112  "*"); // to avoid block by blocked by CORS policy of browser
113  out->getHTTPResponseHeader().addHeader("Pragma", "no-cache");
114 
115  cgicc::Cgicc cgiIn(in);
116  std::string requestType = CgiDataUtilities::getData(cgiIn, "RequestType");
117 
118  __SUP_COUTT__ << "requestType " << requestType
119  << " files: " << cgiIn.getFiles().size() << __E__;
120 
121  HttpXmlDocument xmlOut;
122  WebUsers::RequestUserInfo userInfo(
123  requestType, CgiDataUtilities::getOrPostData(cgiIn, "CookieCode"));
124 
126 
127  if(!theRemoteWebUsers_.xmlRequestToGateway(
128  cgiIn, out, &xmlOut, CorePropertySupervisorBase::allSupervisorInfo_, userInfo))
129  return; // access failed
130 
131  if(requestType == "GetUserDisplayName")
132  {
133  __COUTV__(userInfo.displayName_);
134  xmlOut.addTextElementToData("DisplayName", userInfo.displayName_);
135  xmlOut.outputXmlDocument((std::ostringstream*)out,
136  false /*print to cout*/,
137  !userInfo.NoXmlWhiteSpace_ /*allow whitespace*/);
138  return;
139  }
140 
141  // done checking cookieCode, sequence, userWithLock, and permissions access all in one
142  // shot!
143  //**** end LOGIN GATEWAY CODE ***//
144 
145  if(!userInfo.automatedCommand_)
146  __SUP_COUT__ << "requestType: " << requestType << __E__;
147 
148  if(userInfo.NonXMLRequestType_)
149  {
150  try
151  {
152  nonXmlRequest(requestType, cgiIn, *out, userInfo);
153  }
154  catch(const std::runtime_error& e)
155  {
156  __SUP_SS__ << "An error was encountered handling requestType '" << requestType
157  << "':" << e.what() << __E__;
158  __SUP_COUT_ERR__ << "\n" << ss.str();
159  }
160  catch(...)
161  {
162  __SUP_SS__ << "An unknown error was encountered handling requestType '"
163  << requestType << ".' "
164  << "Please check the printouts to debug." << __E__;
165  try
166  {
167  throw;
168  } //one more try to printout extra info
169  catch(const std::exception& e)
170  {
171  ss << "Exception message: " << e.what();
172  }
173  catch(...)
174  {
175  }
176  __SUP_COUT_ERR__ << "\n" << ss.str();
177  }
178  return;
179  }
180  // else xml request type
181 
182  std::chrono::steady_clock::time_point requestStart = std::chrono::steady_clock::now();
183  time_t requestStartTime = time(0);
184 
185  try
186  {
187  // call derived class' request()
188  request(requestType, cgiIn, xmlOut, userInfo);
189  }
190  catch(const std::runtime_error& e)
191  {
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());
196  }
197  catch(...)
198  {
199  __SUP_SS__ << "An unknown error was encountered handling requestType '"
200  << requestType << ".' "
201  << "Please check the printouts to debug." << __E__;
202  try
203  {
204  throw;
205  } //one more try to printout extra info
206  catch(const std::exception& e)
207  {
208  ss << "Exception message: " << e.what();
209  }
210  catch(...)
211  {
212  }
213  __SUP_COUT_ERR__ << "\n" << ss.str();
214  xmlOut.addTextElementToData("Error", ss.str());
215  }
216  __SUP_COUTT__ << "Request '" << requestType
217  << "' time: " << artdaq::TimeUtils::GetElapsedTime(requestStart)
218  << __E__;
219 
220  // used to print xml errors only if there are a reasonable number of children
221  if(TTEST(1)) //now just check child size if debugging
222  {
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()
229  ->getChildNodes()
230  ->item(0)
231  ->getChildNodes()
232  ->getLength();
233 
234  __SUP_COUTT__ << "Number of '" << requestType
235  << "' xml data element children: " << numberOfChildren << __E__;
236 
237  __SUP_COUTT__ << "Request '" << requestType
238  << "' time: " << artdaq::TimeUtils::GetElapsedTime(requestStart)
239  << __E__;
240  }
241  //Note: the above XML-children-count only looks at depth 1, if there are too many nodes (including deeper nodes) then outputing the xml will be slow (4K nodes takes ~2 seconds)
242 
243  // return xml doc holding server response to request
244  xmlOut.outputXmlDocument((std::ostringstream*)out,
245  false /*print to cout*/,
246  !userInfo.NoXmlWhiteSpace_ /*allow whitespace*/,
247  true /* printErrors */); // report any errors encountered
248 
249  // __SUP_COUTT__ << "Request '" << requestType
250  // << "' time: " << artdaq::TimeUtils::GetElapsedTime(requestStart)
251  // << __E__;
252  // std::stringstream oss;
253  // xmlOut.outputXmlDocument((std::ostringstream*)&oss,
254  // false /*print to cout*/,
255  // !userInfo.NoXmlWhiteSpace_ /*allow whitespace*/,
256  // true /* printErrors */);
257  // __SUP_COUTT__ << "Request '" << requestType
258  // << "' time: " << artdaq::TimeUtils::GetElapsedTime(requestStart)
259  // << __E__;
260  // __SUP_COUTV__(oss.str());
261 
262  __SUP_COUTT__ << "Total '" << requestType << "' xml request time: "
263  << artdaq::TimeUtils::GetElapsedTime(requestStart) << " = "
264  << time(0) - requestStartTime << __E__;
265 } // end requestWrapper()
266 catch(const std::runtime_error& e)
267 {
268  __SUP_SS__ << "An error was encountered handling HTTP request:" << e.what() << __E__;
269  __SUP_COUT_ERR__ << "\n" << ss.str();
270  throw;
271 }
272 catch(...)
273 {
274  __SUP_SS__ << "An unknown error was encountered HTTP request. "
275  << "Please check the printouts to debug." << __E__;
276  try
277  {
278  throw;
279  } //one more try to printout extra info
280  catch(const std::exception& e)
281  {
282  ss << "Exception message: " << e.what();
283  }
284  catch(...)
285  {
286  }
287  __SUP_COUT_ERR__ << "\n" << ss.str();
288  throw;
289 } // end requestWrapper() error handling
290 
291 //==============================================================================
297 void CoreSupervisorBase::request(const std::string& /*requestType*/,
298  cgicc::Cgicc& /*cgiIn*/,
299  HttpXmlDocument& xmlOut,
300  const WebUsers::RequestUserInfo& /*userInfo*/)
301 {
302  __SUP_SS__ << "This is the empty Core Supervisor request. Supervisors should "
303  "override this function."
304  << __E__;
305  __SUP_COUT__ << ss.str();
306  xmlOut.addTextElementToData("Error", ss.str());
307  return;
308 
309  // KEEP:
310  // here are some possibly interesting example lines of code for overriding
311  // supervisors
312  //
313  // try
314  //{
315  //
316  // if(requestType == "savePlanCommandSequence")
317  // {
318  // std::string planName = CgiDataUtilities::getData(cgiIn,"planName");
320  // CgiDataUtilities::postData(cgiIn,"commands");
322  //
323  // cgiIn.getFiles()
324  // __SUP_COUT__ << "planName: " << planName << __E__;
325  // __SUP_COUTV__(commands);
326  //
327  //
328  // }
329  // else
330  // {
331  // __SUP_SS__ << "requestType '" << requestType << "' request not recognized." <<
332  // __E__;
333  // __SUP_SS_THROW__;
334  // }
335  // xmlOut.addTextElementToData("Error",
336  // "request encountered an error!");
337  //}
338  // catch(const std::runtime_error& e)
339  // {
340  // __SUP_SS__ << "An error was encountered handling requestType '" << requestType
341  //<< "':" << e.what() << __E__;
342  // __SUP_COUT_ERR__ << "\n" << ss.str();
343  // xmlOut.addTextElementToData("Error", ss.str());
344  // }
345  // catch(...)
346  // {
347  // __SUP_SS__ << "An unknown error was encountered handling requestType '" <<
348  // requestType << ".' " << "Please check the printouts to debug." <<
349  //__E__;
350  // __SUP_COUT_ERR__ << "\n" << ss.str();
351  // xmlOut.addTextElementToData("Error", ss.str());
352  // }
353  // END KEEP.
354 
355 } // end request()
356 
357 //==============================================================================
363 void CoreSupervisorBase::nonXmlRequest(const std::string& /*requestType*/,
364  cgicc::Cgicc& /*cgiIn*/,
365  std::ostream& out,
366  const WebUsers::RequestUserInfo& /*userInfo*/)
367 {
368  __SUP_COUT__ << "This is the empty Core Supervisor non-xml request. Supervisors "
369  "should override this function."
370  << __E__;
371  out << "This is the empty Core Supervisor non-xml request. Supervisors should "
372  "override this function."
373  << __E__;
374 } // end nonXmlRequest()
375 
376 //==============================================================================
377 void CoreSupervisorBase::stateMachineXgiHandler(xgi::Input* /*in*/, xgi::Output* /*out*/)
378 {
379 }
380 
381 //==============================================================================
382 xoap::MessageReference CoreSupervisorBase::stateMachineXoapHandler(
383  xoap::MessageReference message)
384 {
385  __SUP_COUT__ << "Soap Handler!" << __E__;
386  stateMachineWorkLoopManager_.removeProcessedRequests();
387  stateMachineWorkLoopManager_.processRequest(message);
388  __SUP_COUT__ << "Done - Soap Handler!" << __E__;
389  return message;
390 } // end stateMachineXoapHandler()
391 
392 //==============================================================================
394 xoap::MessageReference CoreSupervisorBase::workLoopStatusRequestWrapper(
395  xoap::MessageReference message)
396 {
397  // this should have an override for monitoring work loops being done
398  return workLoopStatusRequest(message);
399 } // end workLoopStatusRequest()
400 
401 //==============================================================================
402 xoap::MessageReference CoreSupervisorBase::workLoopStatusRequest(
403  xoap::MessageReference /*message*/)
404 {
405  // this should have an override for monitoring work loops being done
406  return SOAPUtilities::makeSOAPMessageReference(CoreSupervisorBase::WORK_LOOP_DONE);
407 } // end workLoopStatusRequest()
408 
409 //==============================================================================
410 xoap::MessageReference CoreSupervisorBase::applicationStatusRequest(
411  xoap::MessageReference /*message*/)
412 {
413  // send back status and progress parameters
414 
415  __SUP_COUTVS__(20,
416  std::to_string(getpid()) + ":" + std::to_string(gettid()) + ":" +
417  theStateMachine_.getCurrentStateName());
418 
419  const std::string& err = theStateMachine_.getErrorMessage();
420  // std::string status = err == "" ? (theStateMachine_.isInTransition() ? theStateMachine_.getProvenanceStateName() : theStateMachine_.getCurrentStateName())
421  // : (theStateMachine_.getCurrentStateName() == "Paused" ? "Soft-Error:::" : "Error:::") + err;
422 
423  // __SUP_COUTV__(theStateMachine_.isInTransition());
424  // __SUP_COUTV__(theStateMachine_.getProvenanceStateName());
425  // __SUP_COUTV__(theStateMachine_.getCurrentStateName());
426  // __SUP_COUTV__(RunControlStateMachine::theProgressBar_.readPercentageString());
427 
428  SOAPParameters retParameters;
429  if(err == "")
430  {
431  if(theStateMachine_.isInTransition() ||
432  RunControlStateMachine::theProgressBar_.read() < 100)
433  {
434  // attempt to get transition name, otherwise give provenance state
435  try
436  {
437  retParameters.addParameter("Status",
438  theStateMachine_.getCurrentTransitionName());
439  }
440  catch(...)
441  {
442  retParameters.addParameter("Status",
443  theStateMachine_.getProvenanceStateName());
444  }
445  }
446  else
447  retParameters.addParameter("Status", theStateMachine_.getCurrentStateName());
448  }
449  else
450  retParameters.addParameter(
451  "Status",
452  (theStateMachine_.getCurrentStateName() == "Paused" ? "Soft-Error:::"
453  : "Error:::") +
454  err);
455 
456  retParameters.addParameter(
457  "Progress", RunControlStateMachine::theProgressBar_.readPercentageString());
458  retParameters.addParameter(
459  "Detail",
460  getStatusProgressDetail()); // call virtual progress detail string generation
461 
462  //return available disk space if first app in context
463  __SUP_COUTTV__(CorePropertySupervisorBase::isFirstAppInContext());
464  if(CorePropertySupervisorBase::isFirstAppInContext())
465  {
466  uint64_t availableLogSpaceKB =
467  CorePropertySupervisorBase::getAvailableLogSpaceKB();
468  uint64_t availableDataSpaceKB =
469  CorePropertySupervisorBase::getAvailableDataSpaceKB();
470 
471  retParameters.addParameter("AvailableLogSpaceKB",
472  std::to_string(availableLogSpaceKB));
473  retParameters.addParameter("AvailableDataSpaceKB",
474  std::to_string(availableDataSpaceKB));
475  }
476  else // just return 0 since not responsible for disk space
477  {
478  retParameters.addParameter("AvailableLogSpaceKB", "0");
479  retParameters.addParameter("AvailableDataSpaceKB", "0");
480  }
481 
482  auto subappInfo = getSubappInfo();
483  retParameters.addParameter("Subapps",
484  SupervisorInfo::serializeSubappInfos(subappInfo));
485 
486  return SOAPUtilities::makeSOAPMessageReference("applicationStatusRequestReply",
487  retParameters);
488 } // end applicationStatusRequest()
489 
490 //==============================================================================
496 {
497  std::string detail;
498  unsigned int cnt = 0;
499 
500  /*
501  //__SUP_COUT__ << "Checking..." << CoreSupervisorBase::theStateMachineImplementation_.size() << __E__;
502  for(const auto& fsm : CoreSupervisorBase::theStateMachineImplementation_)
503  {
504  //__SUP_COUT__ << "Checking..." << __E__;
505  try
506  {
507  VStateMachine* testFSM = dynamic_cast<VStateMachine*>(fsm);
508  }
509  catch(...)
510  {
511  __SUP_COUT__ << "getStatusProgressDetail() VStateMachine testFSM Failed..." << __E__;
512  throw;
513  }
514  }
515  */
516 
517  if(!theStateMachine_.isInTransition() &&
518  (theStateMachine_.getCurrentStateName() ==
519  RunControlStateMachine::HALTED_STATE_NAME ||
520  theStateMachine_.getCurrentStateName() ==
521  RunControlStateMachine::INITIAL_STATE_NAME))
522  {
523  detail = std::string("Uptime: ") +
524  StringMacros::encodeURIComponent(StringMacros::getTimeDurationString(
525  CorePropertySupervisorBase::getSupervisorUptime())) +
526  ", Time-in-state: " +
527  StringMacros::encodeURIComponent(StringMacros::getTimeDurationString(
528  theStateMachine_.getTimeInState()));
529  return detail;
530  }
531 
532  for(const auto& fsm : CoreSupervisorBase::theStateMachineImplementation_)
533  {
534  std::string fsmProgressDetail = fsm->getStatusProgressDetail();
535  if(fsmProgressDetail.size())
536  detail +=
537  ((cnt++) ? ":" : "") +
538  fsmProgressDetail; // StringMacros::encodeURIComponent(fsmProgressDetail);
539  }
540 
541  if(detail.size())
542  __SUP_COUTVS__(20, detail);
543 
544  // if empty detail, give last command
545  if(!detail.size() && RunControlStateMachine::getLastCommand() != "")
546  {
547  detail = "Last Command: " + RunControlStateMachine::getLastCommand();
548  if(RunControlStateMachine::getLastCommand() ==
549  RunControlStateMachine::CONFIGURE_TRANSITION_NAME)
550  detail += " w/" + RunControlStateMachine::getLastAttemptedConfigureGroup();
551  }
552 
553  return detail;
554 } // end getStatusProgressDetail()
555 
556 //==============================================================================
557 bool CoreSupervisorBase::stateMachineThread(toolbox::task::WorkLoop* workLoop)
558 {
559  stateMachineSemaphore_.take();
560  __SUP_COUT__ << "Re-sending message..."
561  << SOAPUtilities::translate(
562  stateMachineWorkLoopManager_.getMessage(workLoop))
563  .getCommand()
564  << __E__;
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();
570  return false; // execute once and automatically remove the workloop so in
571  // WorkLoopManager the try workLoop->remove(job_) could be commented
572  // out return true;//go on and then you must do the
573  // workLoop->remove(job_) in WorkLoopManager
574 } // end stateMachineThread()
575 
576 //==============================================================================
577 xoap::MessageReference CoreSupervisorBase::stateMachineStateRequest(
578  xoap::MessageReference /*message*/)
579 {
580  __SUP_COUT__ << "theStateMachine_.getCurrentStateName() = "
581  << theStateMachine_.getCurrentStateName() << __E__;
582  return SOAPUtilities::makeSOAPMessageReference(
583  theStateMachine_.getCurrentStateName());
584 }
585 
586 //==============================================================================
587 xoap::MessageReference CoreSupervisorBase::stateMachineErrorMessageRequest(
588  xoap::MessageReference /*message*/)
589 
590 {
591  __SUP_COUT__ << "theStateMachine_.getErrorMessage() = "
592  << theStateMachine_.getErrorMessage() << __E__;
593 
594  SOAPParameters retParameters;
595  retParameters.addParameter("ErrorMessage", theStateMachine_.getErrorMessage());
596  return SOAPUtilities::makeSOAPMessageReference("stateMachineErrorMessageRequestReply",
597  retParameters);
598 } // end stateMachineErrorMessageRequest()
599 
600 //==============================================================================
601 void CoreSupervisorBase::stateInitial(toolbox::fsm::FiniteStateMachine& /*fsm*/)
602 {
603  __SUP_COUT__ << "CoreSupervisorBase::stateInitial" << __E__;
604 }
605 
606 //==============================================================================
607 void CoreSupervisorBase::stateHalted(toolbox::fsm::FiniteStateMachine& /*fsm*/)
608 {
609  __SUP_COUT__ << "CoreSupervisorBase::stateHalted" << __E__;
610 }
611 
612 //==============================================================================
613 void CoreSupervisorBase::stateRunning(toolbox::fsm::FiniteStateMachine& /*fsm*/)
614 {
615  __SUP_COUT__ << "CoreSupervisorBase::stateRunning" << __E__;
616 }
617 
618 //==============================================================================
619 void CoreSupervisorBase::stateConfigured(toolbox::fsm::FiniteStateMachine& /*fsm*/)
620 {
621  __SUP_COUT__ << "CoreSupervisorBase::stateConfigured" << __E__;
622 }
623 
624 //==============================================================================
625 void CoreSupervisorBase::statePaused(toolbox::fsm::FiniteStateMachine& /*fsm*/)
626 {
627  __SUP_COUT__ << "CoreSupervisorBase::statePaused" << __E__;
628 }
629 
630 //==============================================================================
631 void CoreSupervisorBase::inError(toolbox::fsm::FiniteStateMachine& /*fsm*/)
632 
633 {
634  __SUP_COUT__ << "Fsm current state: " << theStateMachine_.getCurrentStateName()
635  << __E__;
636  // rcmsStateNotifier_.stateChanged("Error", "");
637 }
638 
639 //==============================================================================
640 void CoreSupervisorBase::enteringError(toolbox::Event::Reference event)
641 
642 {
643  // __SUP_COUT__<< "Fsm current state: " << theStateMachine_.getCurrentStateName()
644  // << "\n\nError Message: " <<
645  // theStateMachine_.getErrorMessage() << __E__;
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__;
653  // diagService_->reportError(errstr.str(),DIAGERROR);
654 }
655 
656 //==============================================================================
657 void CoreSupervisorBase::preStateMachineExecutionLoop(void)
658 {
659  RunControlStateMachine::clearIterationWork();
660  RunControlStateMachine::clearSubIterationWork();
661 
662  stateMachinesIterationWorkCount_ = 0;
663 
664  if(RunControlStateMachine::getIterationIndex() == 0 &&
665  RunControlStateMachine::getSubIterationIndex() == 0)
666  {
667  // reset vector for iterations done on first iteration
668 
669  subIterationWorkStateMachineIndex_ = -1; // clear sub iteration work index
670 
671  stateMachinesIterationDone_.resize(theStateMachineImplementation_.size());
672  for(unsigned int i = 0; i < stateMachinesIterationDone_.size(); ++i)
673  stateMachinesIterationDone_[i] = false;
674  }
675  else
676  __SUP_COUT__ << "Iteration " << RunControlStateMachine::getIterationIndex() << "."
677  << RunControlStateMachine::getSubIterationIndex() << "("
678  << subIterationWorkStateMachineIndex_ << ")" << __E__;
679 }
680 
681 //==============================================================================
682 void CoreSupervisorBase::preStateMachineExecution(unsigned int i)
683 {
684  if(i >= theStateMachineImplementation_.size())
685  {
686  __SUP_SS__ << "State Machine " << i << " not found!" << __E__;
687  __SUP_SS_THROW__;
688  }
689 
690  theStateMachineImplementation_[i]->VStateMachine::setIterationIndex(
691  RunControlStateMachine::getIterationIndex());
692  theStateMachineImplementation_[i]->VStateMachine::setSubIterationIndex(
693  RunControlStateMachine::getSubIterationIndex());
694 
695  theStateMachineImplementation_[i]->VStateMachine::clearIterationWork();
696  theStateMachineImplementation_[i]->VStateMachine::clearSubIterationWork();
697 
698  __SUP_COUT__
699  << "theStateMachineImplementation Iteration "
700  << theStateMachineImplementation_[i]->VStateMachine::getIterationIndex() << "."
701  << theStateMachineImplementation_[i]->VStateMachine::getSubIterationIndex()
702  << __E__;
703 }
704 
705 //==============================================================================
706 void CoreSupervisorBase::postStateMachineExecution(unsigned int i)
707 {
708  if(i >= theStateMachineImplementation_.size())
709  {
710  __SUP_SS__ << "State Machine " << i << " not found!" << __E__;
711  __SUP_SS_THROW__;
712  }
713 
714  // sub-iteration has priority
715  if(theStateMachineImplementation_[i]->VStateMachine::getSubIterationWork())
716  {
717  subIterationWorkStateMachineIndex_ = i;
718  RunControlStateMachine::indicateSubIterationWork();
719 
720  __SUP_COUT__ << "State machine " << i
721  << " is flagged for another sub-iteration..." << __E__;
722  }
723  else
724  {
726  !theStateMachineImplementation_[i]->VStateMachine::getIterationWork();
727 
729  {
730  __SUP_COUT__ << "State machine " << i
731  << " is flagged for another iteration..." << __E__;
732  RunControlStateMachine::indicateIterationWork(); // mark not done at
733  // CoreSupervisorBase level
734  ++stateMachinesIterationWorkCount_; // increment still working count
735  }
736  }
737 } // end postStateMachineExecution()
738 
739 //==============================================================================
740 void CoreSupervisorBase::postStateMachineExecutionLoop(void)
741 {
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_)
747  __SUP_COUT__
748  << stateMachinesIterationWorkCount_
749  << " state machine implementation(s) flagged for another iteration..."
750  << __E__;
751  else
752  __SUP_COUT__ << "Done configuration all state machine implementations..."
753  << __E__;
754 } // end postStateMachineExecutionLoop()
755 
756 //==============================================================================
757 void CoreSupervisorBase::transitionConfiguring(toolbox::Event::Reference /*event*/)
758 {
759  __SUP_COUT__ << "transitionConfiguring" << __E__;
760 
761  // activate the configuration tree (the first iteration)
762  if(RunControlStateMachine::getIterationIndex() == 0 &&
763  RunControlStateMachine::getSubIterationIndex() == 0)
764  {
765  std::pair<std::string /*group name*/, TableGroupKey> theGroup(
766  SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
767  .getParameters()
768  .getValue("ConfigurationTableGroupName"),
769  TableGroupKey(SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
770  .getParameters()
771  .getValue("ConfigurationTableGroupKey")));
772 
773  __SUP_COUT__ << "Configuration table group name: " << theGroup.first
774  << " key: " << theGroup.second << __E__;
775 
776  try
777  {
778  //disable version tracking to accept untracked versions to be selected by the FSM transition source
779  theConfigurationManager_->loadTableGroup(
780  theGroup.first,
781  theGroup.second,
782  true /*doActivate*/,
783  0,
784  0,
785  0,
786  0,
787  0,
788  0,
789  false,
790  0,
791  0,
792  ConfigurationManager::LoadGroupType::ALL_TYPES,
793  true /*ignoreVersionTracking*/);
794  }
795  catch(const std::runtime_error& e)
796  {
797  __SS__ << "Error loading table group '" << theGroup.first << "("
798  << theGroup.second << ")! \n"
799  << e.what() << __E__;
800  __SUP_COUT_ERR__ << ss.str();
801  // ExceptionHandler(ExceptionHandlerRethrow::no, ss.str());
802 
803  //__SS_THROW_ONLY__;
804  theStateMachine_.setErrorMessage(ss.str());
805  throw toolbox::fsm::exception::Exception(
806  "Transition Error" /*name*/,
807  ss.str() /* message*/,
808  "CoreSupervisorBase::transitionConfiguring" /*module*/,
809  __LINE__ /*line*/,
810  __FUNCTION__ /*function*/
811  );
812  }
813  catch(...)
814  {
815  __SS__ << "Unknown error loading table group '" << theGroup.first << "("
816  << theGroup.second << ")!" << __E__;
817  try
818  {
819  throw;
820  } //one more try to printout extra info
821  catch(const std::exception& e)
822  {
823  ss << "Exception message: " << e.what();
824  }
825  catch(...)
826  {
827  }
828  __SUP_COUT_ERR__ << ss.str();
829  // ExceptionHandler(ExceptionHandlerRethrow::no, ss.str());
830 
831  //__SS_THROW_ONLY__;
832  theStateMachine_.setErrorMessage(ss.str());
833  throw toolbox::fsm::exception::Exception(
834  "Transition Error" /*name*/,
835  ss.str() /* message*/,
836  "CoreSupervisorBase::transitionConfiguring" /*module*/,
837  __LINE__ /*line*/,
838  __FUNCTION__ /*function*/
839  );
840  }
841  }
842 
843  CoreSupervisorBase::transitionConfiguringFSMs();
844 
845  __SUP_COUT__ << "Configured." << __E__;
846 } // end transitionConfiguring()
847 
848 //==============================================================================
849 void CoreSupervisorBase::transitionConfiguringFSMs()
850 {
851  // Now that the configuration manager has all the necessary configurations,
852  // create all objects that depend on the configuration (the first iteration)
853 
854  try
855  {
856  __SUP_COUT__ << "Configuring all state machine implementations..." << __E__;
857  preStateMachineExecutionLoop();
858  for(unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
859  {
860  // if one state machine is doing a sub-iteration, then target that one
861  if(subIterationWorkStateMachineIndex_ != (unsigned int)-1 &&
862  i != subIterationWorkStateMachineIndex_)
863  continue; // skip those not in the sub-iteration
864 
866  continue; // skip state machines already done
867 
868  preStateMachineExecution(i);
869  theStateMachineImplementation_[i]->parentSupervisor_ =
870  this; // for backwards compatibility, kept out of configure parameters
871  theStateMachineImplementation_[i]->configure(); // e.g. for FESupervisor,
872  // this is configure of
873  // FEVInterfacesManager
874  postStateMachineExecution(i);
875  }
876  postStateMachineExecutionLoop();
877  }
878  catch(const std::runtime_error& e)
879  {
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(
884  "Transition Error" /*name*/,
885  ss.str() /* message*/,
886  "CoreSupervisorBase::transitionConfiguring" /*module*/,
887  __LINE__ /*line*/,
888  __FUNCTION__ /*function*/
889  );
890  }
891  catch(...)
892  {
893  __SUP_SS__
894  << "Unknown error was caught while configuring. Please checked the logs."
895  << __E__;
896  try
897  {
898  throw;
899  } //one more try to printout extra info
900  catch(const std::exception& e)
901  {
902  ss << "Exception message: " << e.what();
903  }
904  catch(...)
905  {
906  }
907  __SUP_COUT_ERR__ << "\n" << ss.str();
908  theStateMachine_.setErrorMessage(ss.str());
909  throw toolbox::fsm::exception::Exception(
910  "Transition Error" /*name*/,
911  ss.str() /* message*/,
912  "CoreSupervisorBase::transitionConfiguring" /*module*/,
913  __LINE__ /*line*/,
914  __FUNCTION__ /*function*/
915  );
916  }
917 } // end transitionConfiguringFSMs()
918 
919 //==============================================================================
922 void CoreSupervisorBase::transitionHalting(toolbox::Event::Reference /*event*/)
923 {
924  const std::string transitionName = "Halting";
925  try
926  {
927  __SUP_COUT__ << transitionName << " all state machine implementations..."
928  << __E__;
929  preStateMachineExecutionLoop();
930  for(unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
931  {
932  // if one state machine is doing a sub-iteration, then target that one
933  if(subIterationWorkStateMachineIndex_ != (unsigned int)-1 &&
934  i != subIterationWorkStateMachineIndex_)
935  continue; // skip those not in the sub-iteration
936 
938  continue; // skip state machines already done
939 
940  preStateMachineExecution(i);
941  theStateMachineImplementation_[i]->halt(); // e.g. for FESupervisor, this is
942  // transition of
943  // FEVInterfacesManager
944  postStateMachineExecution(i);
945  }
946  postStateMachineExecutionLoop();
947  }
948  catch(const std::runtime_error& e)
949  {
950  // if halting from Failed state, then ignore errors
951  if(theStateMachine_.getProvenanceStateName() ==
952  RunControlStateMachine::FAILED_STATE_NAME)
953  {
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__;
958  }
959  else // if not previously in Failed state, then fail
960  {
961  __SUP_SS__ << "Error was caught while " << transitionName << ": " << e.what()
962  << __E__;
963  __SUP_COUT_ERR__ << "\n" << ss.str();
964  theStateMachine_.setErrorMessage(ss.str());
965  throw toolbox::fsm::exception::Exception(
966  "Transition Error" /*name*/,
967  ss.str() /* message*/,
968  "CoreSupervisorBase::transition" + transitionName /*module*/,
969  __LINE__ /*line*/,
970  __FUNCTION__ /*function*/
971  );
972  }
973  }
974  catch(...)
975  {
976  // if halting from Failed state, then ignore errors
977  if(theStateMachine_.getProvenanceStateName() ==
978  RunControlStateMachine::FAILED_STATE_NAME)
979  {
980  __SUP_COUT_INFO__ << "Unknown error was caught while halting (but ignoring "
981  "because previous state was '"
982  << RunControlStateMachine::FAILED_STATE_NAME << "')."
983  << __E__;
984  }
985  else // if not previously in Failed state, then fail
986  {
987  __SUP_SS__ << "Unknown error was caught while " << transitionName
988  << ". Please checked the logs." << __E__;
989  try
990  {
991  throw;
992  } //one more try to printout extra info
993  catch(const std::exception& e)
994  {
995  ss << "Exception message: " << e.what();
996  }
997  catch(...)
998  {
999  }
1000  __SUP_COUT_ERR__ << "\n" << ss.str();
1001  theStateMachine_.setErrorMessage(ss.str());
1002  throw toolbox::fsm::exception::Exception(
1003  "Transition Error" /*name*/,
1004  ss.str() /* message*/,
1005  "CoreSupervisorBase::transition" + transitionName /*module*/,
1006  __LINE__ /*line*/,
1007  __FUNCTION__ /*function*/
1008  );
1009  }
1010  }
1011 } // end transitionHalting()
1012 
1013 //==============================================================================
1016 void CoreSupervisorBase::transitionInitializing(toolbox::Event::Reference /*event*/)
1017 {
1018  __SUP_COUT__ << "transitionInitializing" << __E__;
1019 
1020  CorePropertySupervisorBase::resetPropertiesAreSetup(); // indicate need to re-load
1021  // user properties
1022 
1023  // Note: Do not initialize the state machine implementations...
1024  // do any initializing in configure
1025  // This allows re-instantiation at each configure time.
1026  // for(auto& it: theStateMachineImplementation_)
1027  // it->initialize();
1028 } // end transitionInitializing()
1029 
1030 //==============================================================================
1031 void CoreSupervisorBase::transitionPausing(toolbox::Event::Reference /*event*/)
1032 {
1033  const std::string transitionName = "Pausing";
1034  try
1035  {
1036  __SUP_COUT__ << "Configuring all state machine implementations..." << __E__;
1037  preStateMachineExecutionLoop();
1038  for(unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1039  {
1040  // if one state machine is doing a sub-iteration, then target that one
1041  if(subIterationWorkStateMachineIndex_ != (unsigned int)-1 &&
1042  i != subIterationWorkStateMachineIndex_)
1043  continue; // skip those not in the sub-iteration
1044 
1046  continue; // skip state machines already done
1047 
1048  preStateMachineExecution(i);
1049  theStateMachineImplementation_[i]->pause(); // e.g. for FESupervisor, this is
1050  // transition of
1051  // FEVInterfacesManager
1052  postStateMachineExecution(i);
1053  }
1054  postStateMachineExecutionLoop();
1055  }
1056  catch(const std::runtime_error& e)
1057  {
1058  __SUP_SS__ << "Error was caught while " << transitionName << ": " << e.what()
1059  << __E__;
1060  __SUP_COUT_ERR__ << "\n" << ss.str();
1061  theStateMachine_.setErrorMessage(ss.str());
1062  throw toolbox::fsm::exception::Exception(
1063  "Transition Error" /*name*/,
1064  ss.str() /* message*/,
1065  "CoreSupervisorBase::transition" + transitionName /*module*/,
1066  __LINE__ /*line*/,
1067  __FUNCTION__ /*function*/
1068  );
1069  }
1070  catch(...)
1071  {
1072  __SUP_SS__ << "Unknown error was caught while " << transitionName
1073  << ". Please checked the logs." << __E__;
1074  try
1075  {
1076  throw;
1077  } //one more try to printout extra info
1078  catch(const std::exception& e)
1079  {
1080  ss << "Exception message: " << e.what();
1081  }
1082  catch(...)
1083  {
1084  }
1085  __SUP_COUT_ERR__ << "\n" << ss.str();
1086  theStateMachine_.setErrorMessage(ss.str());
1087  throw toolbox::fsm::exception::Exception(
1088  "Transition Error" /*name*/,
1089  ss.str() /* message*/,
1090  "CoreSupervisorBase::transition" + transitionName /*module*/,
1091  __LINE__ /*line*/,
1092  __FUNCTION__ /*function*/
1093  );
1094  }
1095 } // end transitionPausing()
1096 
1097 //==============================================================================
1098 void CoreSupervisorBase::transitionResuming(toolbox::Event::Reference /*event*/)
1099 {
1100  const std::string transitionName = "Resuming";
1101  try
1102  {
1103  __SUP_COUT__ << "Configuring all state machine implementations..." << __E__;
1104  preStateMachineExecutionLoop();
1105  for(unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1106  {
1107  // if one state machine is doing a sub-iteration, then target that one
1108  if(subIterationWorkStateMachineIndex_ != (unsigned int)-1 &&
1109  i != subIterationWorkStateMachineIndex_)
1110  continue; // skip those not in the sub-iteration
1111 
1113  continue; // skip state machines already done
1114 
1115  preStateMachineExecution(i);
1116  theStateMachineImplementation_[i]->resume(); // e.g. for FESupervisor, this
1117  // is transition of
1118  // FEVInterfacesManager
1119  postStateMachineExecution(i);
1120  }
1121  postStateMachineExecutionLoop();
1122  }
1123  catch(const std::runtime_error& e)
1124  {
1125  __SUP_SS__ << "Error was caught while " << transitionName << ": " << e.what()
1126  << __E__;
1127  __SUP_COUT_ERR__ << "\n" << ss.str();
1128  theStateMachine_.setErrorMessage(ss.str());
1129  throw toolbox::fsm::exception::Exception(
1130  "Transition Error" /*name*/,
1131  ss.str() /* message*/,
1132  "CoreSupervisorBase::transition" + transitionName /*module*/,
1133  __LINE__ /*line*/,
1134  __FUNCTION__ /*function*/
1135  );
1136  }
1137  catch(...)
1138  {
1139  __SUP_SS__ << "Unknown error was caught while " << transitionName
1140  << ". Please checked the logs." << __E__;
1141  try
1142  {
1143  throw;
1144  } //one more try to printout extra info
1145  catch(const std::exception& e)
1146  {
1147  ss << "Exception message: " << e.what();
1148  }
1149  catch(...)
1150  {
1151  }
1152  __SUP_COUT_ERR__ << "\n" << ss.str();
1153  theStateMachine_.setErrorMessage(ss.str());
1154  throw toolbox::fsm::exception::Exception(
1155  "Transition Error" /*name*/,
1156  ss.str() /* message*/,
1157  "CoreSupervisorBase::transition" + transitionName /*module*/,
1158  __LINE__ /*line*/,
1159  __FUNCTION__ /*function*/
1160  );
1161  }
1162 } // end transitionResuming()
1163 
1164 //==============================================================================
1165 void CoreSupervisorBase::transitionStarting(toolbox::Event::Reference /*event*/)
1166 {
1167  const std::string transitionName = "Starting";
1168  const std::string runNumber =
1169  SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
1170  .getParameters()
1171  .getValue("RunNumber");
1172  try
1173  {
1174  __SUP_COUT__ << "Configuring all state machine implementations..." << __E__;
1175  preStateMachineExecutionLoop();
1176  for(unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1177  {
1178  // if one state machine is doing a sub-iteration, then target that one
1179  if(subIterationWorkStateMachineIndex_ != (unsigned int)-1 &&
1180  i != subIterationWorkStateMachineIndex_)
1181  continue; // skip those not in the sub-iteration
1182 
1184  continue; // skip state machines already done
1185 
1186  preStateMachineExecution(i);
1187  theStateMachineImplementation_[i]->start(runNumber); // e.g. for
1188  // FESupervisor, this is
1189  // transition of
1190  // FEVInterfacesManager
1191  postStateMachineExecution(i);
1192  }
1193  postStateMachineExecutionLoop();
1194  }
1195  catch(const std::runtime_error& e)
1196  {
1197  __SUP_SS__ << "Error was caught while " << transitionName << ": " << e.what()
1198  << __E__;
1199  __SUP_COUT_ERR__ << "\n" << ss.str();
1200  theStateMachine_.setErrorMessage(ss.str());
1201  throw toolbox::fsm::exception::Exception(
1202  "Transition Error" /*name*/,
1203  ss.str() /* message*/,
1204  "CoreSupervisorBase::transition" + transitionName /*module*/,
1205  __LINE__ /*line*/,
1206  __FUNCTION__ /*function*/
1207  );
1208  }
1209  catch(...)
1210  {
1211  __SUP_SS__ << "Unknown error was caught while " << transitionName
1212  << ". Please checked the logs." << __E__;
1213  try
1214  {
1215  throw;
1216  } //one more try to printout extra info
1217  catch(const std::exception& e)
1218  {
1219  ss << "Exception message: " << e.what();
1220  }
1221  catch(...)
1222  {
1223  }
1224  __SUP_COUT_ERR__ << "\n" << ss.str();
1225  theStateMachine_.setErrorMessage(ss.str());
1226  throw toolbox::fsm::exception::Exception(
1227  "Transition Error" /*name*/,
1228  ss.str() /* message*/,
1229  "CoreSupervisorBase::transition" + transitionName /*module*/,
1230  __LINE__ /*line*/,
1231  __FUNCTION__ /*function*/
1232  );
1233  }
1234 } // end transitionStarting()
1235 
1236 //==============================================================================
1237 void CoreSupervisorBase::transitionStopping(toolbox::Event::Reference /*event*/)
1238 {
1239  const std::string transitionName = "Stopping";
1240  try
1241  {
1242  __SUP_COUT__ << "Configuring all state machine implementations..." << __E__;
1243  preStateMachineExecutionLoop();
1244  for(unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
1245  {
1246  // if one state machine is doing a sub-iteration, then target that one
1247  if(subIterationWorkStateMachineIndex_ != (unsigned int)-1 &&
1248  i != subIterationWorkStateMachineIndex_)
1249  continue; // skip those not in the sub-iteration
1250 
1252  continue; // skip state machines already done
1253 
1254  preStateMachineExecution(i);
1255  theStateMachineImplementation_[i]->stop(); // e.g. for FESupervisor, this is
1256  // transition of
1257  // FEVInterfacesManager
1258  postStateMachineExecution(i);
1259  }
1260  postStateMachineExecutionLoop();
1261  }
1262  catch(const std::runtime_error& e)
1263  {
1264  __SUP_SS__ << "Error was caught while " << transitionName << ": " << e.what()
1265  << __E__;
1266  __SUP_COUT_ERR__ << "\n" << ss.str();
1267  theStateMachine_.setErrorMessage(ss.str());
1268  throw toolbox::fsm::exception::Exception(
1269  "Transition Error" /*name*/,
1270  ss.str() /* message*/,
1271  "CoreSupervisorBase::transition" + transitionName /*module*/,
1272  __LINE__ /*line*/,
1273  __FUNCTION__ /*function*/
1274  );
1275  }
1276  catch(...)
1277  {
1278  __SUP_SS__ << "Unknown error was caught while " << transitionName
1279  << ". Please checked the logs." << __E__;
1280  try
1281  {
1282  throw;
1283  } //one more try to printout extra info
1284  catch(const std::exception& e)
1285  {
1286  ss << "Exception message: " << e.what();
1287  }
1288  catch(...)
1289  {
1290  }
1291  __SUP_COUT_ERR__ << "\n" << ss.str();
1292  theStateMachine_.setErrorMessage(ss.str());
1293  throw toolbox::fsm::exception::Exception(
1294  "Transition Error" /*name*/,
1295  ss.str() /* message*/,
1296  "CoreSupervisorBase::transition" + transitionName /*module*/,
1297  __LINE__ /*line*/,
1298  __FUNCTION__ /*function*/
1299  );
1300  }
1301 } // end transitionStopping()
1302 
1303 //==============================================================================
1308 void CoreSupervisorBase::sendAsyncExceptionToGateway(const std::string& errorMessage,
1309  bool isPauseException,
1310  bool isStopException)
1311 try
1312 {
1313  if(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__;
1319  else
1320  __SUP_COUT_ERR__ << "Sending Supervisor Async Running Error... \n"
1321  << errorMessage << __E__;
1322 
1323  theStateMachine_.setErrorMessage(errorMessage);
1324 
1325  XDAQ_CONST_CALL xdaq::ApplicationDescriptor* gatewaySupervisor =
1326  allSupervisorInfo_.getGatewayInfo().getDescriptor();
1327 
1328  SOAPParameters parameters;
1329  parameters.addParameter("ErrorMessage", errorMessage);
1330 
1331  xoap::MessageReference replyMessage = SOAPMessenger::sendWithSOAPReply(
1332  gatewaySupervisor,
1333  isStopException ? "AsyncStopException"
1334  : (isPauseException ? "AsyncPauseException" : "AsyncError"),
1335  parameters);
1336 
1337  std::stringstream replyMessageSStream;
1338  replyMessageSStream << SOAPUtilities::translate(replyMessage);
1339  __SUP_COUT__ << "Received... " << replyMessageSStream.str() << std::endl;
1340 
1341  if(replyMessageSStream.str().find("Fault") != std::string::npos)
1342  {
1343  __SUP_COUT_ERR__ << "Failure to indicate fault to Gateway..." << __E__;
1344  throw;
1345  }
1346 }
1347 catch(const xdaq::exception::Exception& e)
1348 {
1349  if(isStopException)
1350  __SUP_COUT__
1351  << "SOAP message failure indicating Supervisor asynchronous running STOP "
1352  "exception back to Gateway: "
1353  << e.what() << __E__;
1354  else if(isPauseException)
1355  __SUP_COUT__
1356  << "SOAP message failure indicating Supervisor asynchronous running SOFT "
1357  "exception back to Gateway: "
1358  << e.what() << __E__;
1359  else
1360  __SUP_COUT__ << "SOAP message failure indicating Supervisor asynchronous running "
1361  "error back to Gateway: "
1362  << e.what() << __E__;
1363  throw; // rethrow and hope error is noticed
1364 }
1365 catch(...)
1366 {
1367  if(isStopException)
1368  __SUP_COUT__
1369  << "Unknown error encounter indicating Supervisor asynchronous running "
1370  "STOP exception back to Gateway."
1371  << __E__;
1372  else if(isPauseException)
1373  __SUP_COUT__
1374  << "Unknown error encounter indicating Supervisor asynchronous running "
1375  "SOFT error back to Gateway."
1376  << __E__;
1377  else
1378  __SUP_COUT__
1379  << "Unknown error encounter indicating Supervisor asynchronous running "
1380  "error back to Gateway."
1381  << __E__;
1382  throw; // rethrow and hope error is noticed
1383 } // end SendAsyncErrorToGateway()
1384 
1385 //==============================================================================
1386 xoap::MessageReference CoreSupervisorBase::TRACESupervisorRequest(
1387  xoap::MessageReference message)
1388 {
1389  return CorePropertySupervisorBase::TRACESupervisorRequest(message);
1390 } // end TRACESupervisorRequest()
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))