00001 #include "otsdaq-core/Supervisor/Supervisor.h"
00002 #include "otsdaq-core/MessageFacility/MessageFacility.h"
00003 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
00004 #include "otsdaq-core/XmlUtilities/HttpXmlDocument.h"
00005 #include "otsdaq-core/CgiDataUtilities/CgiDataUtilities.h"
00006 #include "otsdaq-core/SOAPUtilities/SOAPUtilities.h"
00007 #include "otsdaq-core/SOAPUtilities/SOAPCommand.h"
00008
00009 #include "otsdaq-core/WorkLoopManager/WorkLoopManager.h"
00010 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
00011 #include "otsdaq-core/ConfigurationInterface/ConfigurationManagerRW.h"
00012 #include "otsdaq-core/ConfigurationPluginDataFormats/XDAQContextConfiguration.h"
00013 #include <cgicc/HTMLClasses.h>
00014 #include <cgicc/HTTPCookie.h>
00015 #include <cgicc/HTMLDoctype.h>
00016 #include <cgicc/HTTPHeader.h>
00017 #include <xgi/Utils.h>
00018
00019 #include <xoap/Method.h>
00020 #include <xdaq/NamespaceURI.h>
00021 #include <toolbox/task/WorkLoopFactory.h>
00022 #include <toolbox/fsm/FailedEvent.h>
00023
00024 #include <fstream>
00025 #include <thread>
00026 #include <chrono>
00027 #include <sys/stat.h>
00028
00029 using namespace ots;
00030
00031
00032 #define ICON_FILE_NAME std::string(getenv("SERVICE_DATA_PATH")) + "/OtsWizardData/iconList.dat"
00033 #define RUN_NUMBER_PATH std::string(getenv("SERVICE_DATA_PATH")) + "/RunNumber/"
00034 #define RUN_NUMBER_FILE_NAME "NextRunNumber.txt"
00035 #define FSM_LAST_GROUP_ALIAS_PATH std::string(getenv("SERVICE_DATA_PATH")) + "/RunControlData/"
00036 #define FSM_LAST_GROUP_ALIAS_FILE_START std::string("FSMLastGroupAlias-")
00037 #define FSM_USERS_PREFERENCES_FILETYPE "pref"
00038
00039
00040 #undef __MF_SUBJECT__
00041 #define __MF_SUBJECT__ "OmniSuper"
00042
00043
00044 XDAQ_INSTANTIATOR_IMPL(Supervisor)
00045
00046
00047
00048 Supervisor::Supervisor(xdaq::ApplicationStub * s) throw (xdaq::exception::Exception)
00049 :xdaq::Application (s)
00050 ,SOAPMessenger (this)
00051 ,RunControlStateMachine ("Supervisor")
00052 ,outputDir_ ("")
00053 ,theConfigurationManager_ (new ConfigurationManager)
00054
00055 ,stateMachineWorkLoopManager_(toolbox::task::bind(this, &Supervisor::stateMachineThread,"StateMachine"))
00056 ,stateMachineSemaphore_ (toolbox::BSem::FULL)
00057 ,infoRequestWorkLoopManager_ (toolbox::task::bind(this, &Supervisor::infoRequestThread, "InfoRequest"))
00058 ,infoRequestSemaphore_ (toolbox::BSem::FULL)
00059 , activeStateMachineName_ ("")
00060 ,counterTest_ (0)
00061 {
00062 INIT_MF("Supervisor");
00063 __MOUT__ << std::endl;
00064
00065
00066 mkdir((FSM_LAST_GROUP_ALIAS_PATH).c_str(), 0755);
00067 mkdir((RUN_NUMBER_PATH).c_str(), 0755);
00068
00069 securityType_ = theWebUsers_.getSecurity();
00070
00071 __MOUT__ << "Security: " << securityType_ << std::endl;
00072
00073 xgi::bind(this, &Supervisor::Default, "Default");
00074 xgi::bind(this, &Supervisor::loginRequest, "LoginRequest");
00075 xgi::bind(this, &Supervisor::request, "Request");
00076 xgi::bind(this, &Supervisor::stateMachineXgiHandler, "StateMachineXgiHandler");
00077 xgi::bind(this, &Supervisor::infoRequestHandler, "InfoRequestHandler");
00078 xgi::bind(this, &Supervisor::infoRequestResultHandler, "InfoRequestResultHandler");
00079 xgi::bind(this, &Supervisor::tooltipRequest, "TooltipRequest");
00080
00081 xoap::bind(this, &Supervisor::supervisorCookieCheck, "SupervisorCookieCheck", XDAQ_NS_URI);
00082 xoap::bind(this, &Supervisor::supervisorGetActiveUsers, "SupervisorGetActiveUsers", XDAQ_NS_URI);
00083 xoap::bind(this, &Supervisor::supervisorSystemMessage, "SupervisorSystemMessage", XDAQ_NS_URI);
00084 xoap::bind(this, &Supervisor::supervisorGetUserInfo, "SupervisorGetUserInfo", XDAQ_NS_URI);
00085 xoap::bind(this, &Supervisor::supervisorSystemLogbookEntry, "SupervisorSystemLogbookEntry", XDAQ_NS_URI);
00086 xoap::bind(this, &Supervisor::supervisorLastConfigGroupRequest, "SupervisorLastConfigGroupRequest", XDAQ_NS_URI);
00087
00088
00089
00090
00091
00092
00093
00094 init();
00095
00096
00097
00098 }
00099
00100
00101
00102 Supervisor::~Supervisor(void)
00103 {
00104 delete theConfigurationManager_;
00105 makeSystemLogbookEntry("ots halted.");
00106 }
00107
00108
00109 void Supervisor::init(void)
00110 {
00111
00112 theSupervisorDescriptorInfo_.init(getApplicationContext());
00113 theSupervisorsInfo_.init(theSupervisorDescriptorInfo_);
00114
00115 supervisorGuiHasBeenLoaded_ = false;
00116
00117 const XDAQContextConfiguration* contextConfiguration = theConfigurationManager_->__GET_CONFIG__(XDAQContextConfiguration);
00118
00119 supervisorContextUID_ = contextConfiguration->getContextUID(
00120 getApplicationContext()->getContextDescriptor()->getURL()
00121 );
00122 __MOUT__ << "Context UID:" << supervisorContextUID_ << std::endl;
00123
00124 supervisorApplicationUID_ = contextConfiguration->getApplicationUID(
00125 getApplicationContext()->getContextDescriptor()->getURL(),
00126 getApplicationDescriptor()->getLocalId()
00127 );
00128
00129 __MOUT__ << "Application UID:" << supervisorApplicationUID_ << std::endl;
00130
00131 ConfigurationTree configLinkNode = theConfigurationManager_->getSupervisorConfigurationNode(
00132 supervisorContextUID_, supervisorApplicationUID_);
00133
00134
00135
00136
00137 std::string supervisorUID;
00138 if(!configLinkNode.isDisconnected())
00139 supervisorUID = configLinkNode.getValue();
00140 else
00141 supervisorUID = ViewColumnInfo::DATATYPE_LINK_DEFAULT;
00142
00143 __MOUT__ << "Supervisor UID:" << supervisorUID << std::endl;
00144 }
00145
00146
00147 void Supervisor::URLDisplayThread(Supervisor *supervisorPtr)
00148 {
00149 INIT_MF("Supervisor");
00150
00151
00152 int i = 0;
00153 for (; i < 5; ++i)
00154 {
00155 std::this_thread::sleep_for (std::chrono::seconds(2));
00156 std:: cout << __COUT_HDR_FL__ << "\n*********************************************************************" << std::endl;
00157 std:: cout << __COUT_HDR_FL__ << "\n\n"
00158 << supervisorPtr->getApplicationContext()->getContextDescriptor()->getURL()
00159
00160 << "/urn:xdaq-application:lid="
00161 << supervisorPtr->getApplicationDescriptor()->getLocalId() << "/"
00162 << "\n" << std::endl;
00163 std:: cout << __COUT_HDR_FL__ << "\n*********************************************************************" << std::endl;
00164 }
00165 }
00166
00167
00168
00169
00170
00172 void Supervisor::makeSystemLogbookEntry(std::string entryText)
00173 {
00174 __MOUT__ << "Making System Logbook Entry: " << entryText << std::endl;
00175
00176
00177 if(!theSupervisorDescriptorInfo_.getLogbookDescriptor())
00178 {
00179 __MOUT__ << "Just kidding... Logbook Descriptor not found." << std:: endl;
00180 return;
00181 }
00182
00183
00184 {
00185 std::string replace[] =
00186 {"\"", "'", "&", "<", ">", "\n", " "};
00187 std::string with[] =
00188 {"%22","%27", "%26", "%3C", "%3E", "%0A%0D", "%20%20"};
00189
00190 int numOfKeys = 7;
00191
00192 size_t f;
00193 for(int i=0;i<numOfKeys;++i)
00194 {
00195 while((f=entryText.find(replace[i])) != std::string::npos)
00196 {
00197 entryText = entryText.substr(0,f) + with[i] + entryText.substr(f+replace[i].length());
00198
00199 }
00200 }
00201 }
00202
00203
00204 SOAPParameters parameters("EntryText",entryText);
00205
00206
00207
00208 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(theSupervisorDescriptorInfo_.getLogbookDescriptor(), "MakeSystemLogbookEntry",parameters);
00209
00210 SOAPParameters retParameters("Status");
00211
00212
00213 receive(retMsg, retParameters);
00214
00215 __MOUT__ << "Returned Status: " << retParameters.getValue("Status") << std::endl;
00216
00217 }
00218
00219
00220 void Supervisor::Default(xgi::Input* in, xgi::Output* out)
00221 throw (xgi::exception::Exception)
00222 {
00223
00224 if (!supervisorGuiHasBeenLoaded_ && (supervisorGuiHasBeenLoaded_ = true))
00225 makeSystemLogbookEntry("ots started.");
00226
00227 *out <<
00228 "<!DOCTYPE HTML><html lang='en'><head><title>ots</title>" <<
00229
00230
00231 "<link rel='apple-touch-icon' sizes='57x57' href='/WebPath/images/otsdaqIcons/apple-icon-57x57.png'>\
00232 <link rel='apple-touch-icon' sizes='60x60' href='/WebPath/images/otsdaqIcons/apple-icon-60x60.png'>\
00233 <link rel='apple-touch-icon' sizes='72x72' href='/WebPath/images/otsdaqIcons/apple-icon-72x72.png'>\
00234 <link rel='apple-touch-icon' sizes='76x76' href='/WebPath/images/otsdaqIcons/apple-icon-76x76.png'>\
00235 <link rel='apple-touch-icon' sizes='114x114' href='/WebPath/images/otsdaqIcons/apple-icon-114x114.png'>\
00236 <link rel='apple-touch-icon' sizes='120x120' href='/WebPath/images/otsdaqIcons/apple-icon-120x120.png'>\
00237 <link rel='apple-touch-icon' sizes='144x144' href='/WebPath/images/otsdaqIcons/apple-icon-144x144.png'>\
00238 <link rel='apple-touch-icon' sizes='152x152' href='/WebPath/images/otsdaqIcons/apple-icon-152x152.png'>\
00239 <link rel='apple-touch-icon' sizes='180x180' href='/WebPath/images/otsdaqIcons/apple-icon-180x180.png'>\
00240 <link rel='icon' type='image/png' sizes='192x192' href='/WebPath/images/otsdaqIcons/android-icon-192x192.png'>\
00241 <link rel='icon' type='image/png' sizes='32x32' href='/WebPath/images/otsdaqIcons/favicon-32x32.png'>\
00242 <link rel='icon' type='image/png' sizes='96x96' href='/WebPath/images/otsdaqIcons/favicon-96x96.png'>\
00243 <link rel='icon' type='image/png' sizes='16x16' href='/WebPath/images/otsdaqIcons/favicon-16x16.png'>\
00244 <link rel='manifest' href='/WebPath/images/otsdaqIcons/manifest.json'>\
00245 <meta name='msapplication-TileColor' content='#ffffff'>\
00246 <meta name='msapplication-TileImage' content='/ms-icon-144x144.png'>\
00247 <meta name='theme-color' content='#ffffff'>" <<
00248
00249 "</head>" <<
00250 "<frameset col='100%' row='100%'>" <<
00251 "<frame src='/WebPath/html/Supervisor.html?urn=" <<
00252 this->getApplicationDescriptor()->getLocalId() << "=securityType=" <<
00253 securityType_ << "'></frameset></html>";
00254 }
00255
00256
00257
00258
00259 void Supervisor::stateMachineXgiHandler(xgi::Input* in, xgi::Output* out)
00260 throw (xgi::exception::Exception)
00261 {
00262 cgicc::Cgicc cgi(in);
00263
00264 uint8_t userPermissions;
00265 uint64_t uid;
00266 std::string userWithLock;
00267 std::string cookieCode = CgiDataUtilities::postData(cgi, "CookieCode");
00268 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions,
00269 &uid, "0", 1, &userWithLock))
00270 {
00271 *out << cookieCode;
00272 return;
00273 }
00274
00275
00276 std::string username = "";
00277 username = theWebUsers_.getUsersUsername(uid);
00278 if (userWithLock != "" && userWithLock != username)
00279 {
00280 *out << WebUsers::REQ_USER_LOCKOUT_RESPONSE;
00281 __MOUT__ << "User " << username << " is locked out. " << userWithLock << " has lock." << std::endl;
00282 return;
00283 }
00284
00285
00286 HttpXmlDocument xmldoc(cookieCode);
00287 std::string command = CgiDataUtilities::getData(cgi, "StateMachine");
00288 std::string fsmName = CgiDataUtilities::getData(cgi, "fsmName");
00289 std::string fsmWindowName = CgiDataUtilities::getData(cgi, "fsmWindowName");
00290 fsmWindowName = CgiDataUtilities::decodeURIComponent(fsmWindowName);
00291 std::string currentState = theStateMachine_.getCurrentStateName();
00292
00293 __MOUT__ << "fsmName = " << fsmName << std::endl;
00294 __MOUT__ << "fsmWindowName = " << fsmWindowName << std::endl;
00295 __MOUT__ << "activeStateMachineName_ = " << activeStateMachineName_ << std::endl;
00296
00297
00298 if (theStateMachine_.isInTransition())
00299 {
00300 __SS__ << "Error - Can not accept request since State Machine is already in transition!" << std::endl;
00301 __MOUT_ERR__ << "\n" << ss.str();
00302
00303 xmldoc.addTextElementToData("state_tranisition_attempted", "0");
00304 xmldoc.addTextElementToData("state_tranisition_attempted_err",
00305 ss.str());
00306 xmldoc.outputXmlDocument((std::ostringstream*) out, false, true);
00307 return;
00308 }
00309
00311
00312
00313
00314
00315
00316 if(activeStateMachineName_ != "" &&
00317 activeStateMachineName_ != fsmName)
00318 {
00319 __MOUT__ << "currentState = " <<
00320 currentState << std::endl;
00321 if(currentState != "Halted" &&
00322 currentState != "Initial")
00323 {
00324
00325
00326 __SS__ << "Error - Can not accept request since State Machine " <<
00327 "with window name '" <<
00328 activeStateMachineWindowName_ << "' (UID: " <<
00329 activeStateMachineName_ << ") "
00330 "is currently " <<
00331 "in control of State Machine progress. ";
00332 ss << "\n\nIn order for this State Machine with window name '" <<
00333 fsmWindowName << "' (UID: " << fsmName << ") "
00334 "to control progress, please transition to Halted using the active " <<
00335 "State Machine '" << activeStateMachineWindowName_ << ".'" << std::endl;
00336 __MOUT_ERR__ << "\n" << ss.str();
00337
00338 xmldoc.addTextElementToData("state_tranisition_attempted", "0");
00339 xmldoc.addTextElementToData("state_tranisition_attempted_err",
00340 ss.str());
00341 xmldoc.outputXmlDocument((std::ostringstream*) out, false, true);
00342 return;
00343 }
00344 else
00345 {
00346 activeStateMachineName_ = "";
00347 activeStateMachineWindowName_ = "";
00348 }
00349 }
00350
00351
00352
00353
00354 SOAPParameters parameters;
00355 if (command == "Configure")
00356 {
00357 if(currentState != "Halted")
00358 {
00359 __SS__ << "Error - Can only transition to Configured if the current " <<
00360 "state is Halted. Perhaps your state machine is out of sync." <<
00361 std::endl;
00362 __MOUT_ERR__ << "\n" << ss.str();
00363
00364 xmldoc.addTextElementToData("state_tranisition_attempted", "0");
00365 xmldoc.addTextElementToData("state_tranisition_attempted_err",
00366 ss.str());
00367 xmldoc.outputXmlDocument((std::ostringstream*) out, false, true);
00368 return;
00369 }
00370
00371
00372
00373 parameters.addParameter("ConfigurationAlias",
00374 CgiDataUtilities::postData(cgi, "ConfigurationAlias"));
00375
00376 std::string configurationAlias = parameters.getValue("ConfigurationAlias");
00377 __MOUT__ << "Configure --> Name: ConfigurationAlias Value: " <<
00378 configurationAlias << std::endl;
00379
00380
00381 std::string fn = FSM_LAST_GROUP_ALIAS_PATH + FSM_LAST_GROUP_ALIAS_FILE_START +
00382 username + "." + FSM_USERS_PREFERENCES_FILETYPE;
00383
00384 __MOUT__ << "Save FSM preferences: " << fn << std::endl;
00385 FILE *fp = fopen(fn.c_str(),"w");
00386 if(!fp)
00387 throw std::runtime_error("Could not open file: " + fn);
00388 fprintf(fp,"FSM_last_configuration_alias %s",configurationAlias.c_str());
00389 fclose(fp);
00390
00391 activeStateMachineName_ = fsmName;
00392 activeStateMachineWindowName_ = fsmWindowName;
00393 }
00394 else if (command == "Start")
00395 {
00396 if(currentState != "Configured")
00397 {
00398 __SS__ << "Error - Can only transition to Configured if the current " <<
00399 "state is Halted. Perhaps your state machine is out of sync. " <<
00400 "(Likely the server was restarted or another user changed the state)" <<
00401 std::endl;
00402 __MOUT_ERR__ << "\n" << ss.str();
00403
00404 xmldoc.addTextElementToData("state_tranisition_attempted", "0");
00405 xmldoc.addTextElementToData("state_tranisition_attempted_err",
00406 ss.str());
00407 xmldoc.outputXmlDocument((std::ostringstream*) out, false, true);
00408 return;
00409 }
00410
00411 unsigned int runNumber = getNextRunNumber();
00412 parameters.addParameter("RunNumber", runNumber);
00413 setNextRunNumber(++runNumber);
00414 }
00415
00416 xoap::MessageReference message = SOAPUtilities::makeSOAPMessageReference(
00417 command, parameters);
00418
00419 xoap::MessageReference reply = stateMachineXoapHandler(message);
00420
00421
00422
00423 xmldoc.addTextElementToData("state_tranisition_attempted", "1");
00424 xmldoc.outputXmlDocument((std::ostringstream*) out, false);
00425 __MOUT__ << "Done - Xgi Request!" << std::endl;
00426 }
00427
00428
00429 void Supervisor::stateMachineResultXgiHandler(xgi::Input* in, xgi::Output* out)
00430 throw (xgi::exception::Exception)
00431 {
00432 cgicc::Cgicc cgi(in);
00433 __MOUT__ << "Xgi Request!" << std::endl;
00434
00435 uint8_t userPermissions;
00436 std::string cookieCode = CgiDataUtilities::postData(cgi, "CookieCode");
00437 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode,
00438 &userPermissions))
00439 {
00440 *out << cookieCode;
00441 return;
00442 }
00443
00444 HttpXmlDocument xmldoc(cookieCode);
00445
00446 std::string command = CgiDataUtilities::getData(cgi, "StateMachine");
00447
00448 SOAPParameters parameters;
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467 xoap::MessageReference message = SOAPUtilities::makeSOAPMessageReference(
00468 CgiDataUtilities::getData(cgi, "StateMachine"), parameters);
00469
00470 xoap::MessageReference reply = stateMachineResultXoapHandler(message);
00471
00472
00473
00474 __MOUT__ << "Done - Xgi Request!" << std::endl;
00475 }
00476
00477
00478 xoap::MessageReference Supervisor::stateMachineXoapHandler(xoap::MessageReference message)
00479 throw (xoap::exception::Exception)
00480 {
00481 __MOUT__ << "Soap Handler!" << std::endl;
00482 stateMachineWorkLoopManager_.removeProcessedRequests();
00483 stateMachineWorkLoopManager_.processRequest(message);
00484 __MOUT__ << "Done - Soap Handler!" << std::endl;
00485 return message;
00486 }
00487
00488
00489 xoap::MessageReference Supervisor::stateMachineResultXoapHandler(
00490 xoap::MessageReference message)
00491 throw (xoap::exception::Exception)
00492 {
00493 __MOUT__ << "Soap Handler!" << std::endl;
00494
00495
00496 __MOUT__ << "Done - Soap Handler!" << std::endl;
00497 return message;
00498 }
00499
00500
00501 bool Supervisor::stateMachineThread(toolbox::task::WorkLoop* workLoop)
00502 {
00503 stateMachineSemaphore_.take();
00504 __MOUT__ << "Re-sending message..." << SOAPUtilities::translate( stateMachineWorkLoopManager_.getMessage(workLoop)).getCommand() << std::endl;
00505 std::string reply = send(
00506 theSupervisorDescriptorInfo_.getSupervisorDescriptor(),
00507 stateMachineWorkLoopManager_.getMessage(workLoop));
00508 stateMachineWorkLoopManager_.report(workLoop, reply, 100, true);
00509
00510 __MOUT__ << "Done with message" << std::endl;
00511 stateMachineSemaphore_.give();
00512 return false;
00513
00514 }
00515
00516
00517
00518
00519
00520
00521 void Supervisor::infoRequestHandler(xgi::Input* in, xgi::Output* out)
00522 throw (xgi::exception::Exception)
00523 {
00524 __MOUT__ << "Starting to Request!" << std::endl;
00525 cgicc::Cgicc cgi(in);
00526
00527
00528
00529
00530 std::string cookieCode = CgiDataUtilities::postData(cgi, "CookieCode");
00531 uint8_t userPermissions;
00532 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions))
00533 {
00534 *out << cookieCode;
00535 return;
00536 }
00537
00538
00539 HttpXmlDocument xmldoc(cookieCode);
00540
00541
00542
00543
00544
00545 HttpXmlDocument tmpDoc = infoRequestWorkLoopManager_.processRequest(cgi);
00546
00547 xmldoc.copyDataChildren(tmpDoc);
00548
00549 xmldoc.outputXmlDocument((std::ostringstream*) out, false);
00550 }
00551
00552
00553 void Supervisor::infoRequestResultHandler(xgi::Input* in, xgi::Output* out)
00554 throw (xgi::exception::Exception)
00555 {
00556 __MOUT__ << "Starting ask!" << std::endl;
00557 cgicc::Cgicc cgi(in);
00558
00559
00560
00561
00562 std::string cookieCode = CgiDataUtilities::postData(cgi, "CookieCode");
00563 uint8_t userPermissions;
00564 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions))
00565 {
00566 *out << cookieCode;
00567 return;
00568 }
00569
00570
00571 HttpXmlDocument xmldoc(cookieCode);
00572
00573 infoRequestWorkLoopManager_.getRequestResult(cgi, xmldoc);
00574
00575
00576 xmldoc.outputXmlDocument((std::ostringstream*) out, false);
00577
00578 __MOUT__ << "Done asking!" << std::endl;
00579 }
00580
00581
00582 bool Supervisor::infoRequestThread(toolbox::task::WorkLoop* workLoop)
00583 {
00584
00585
00586
00587 infoRequestSemaphore_.take();
00588
00589 vectorTest_.clear();
00590
00591 for (unsigned long long i = 0; i < 100000000; i++)
00592 {
00593 counterTest_ += 2;
00594 vectorTest_.push_back(counterTest_);
00595 }
00596
00597 infoRequestWorkLoopManager_.report(workLoop,
00598 "RESULT: This is the best result ever", 50, false);
00599 std::string workLoopName = workLoop->getName();
00600 __MOUT__ << workLoopName << " test: " << counterTest_
00601 << " vector size: " << vectorTest_.size() << std::endl;
00602 wait(400, "InfoRequestThread ----- locked");
00603 infoRequestSemaphore_.give();
00604
00605 wait(200, "InfoRequestThread");
00606
00607 infoRequestSemaphore_.take();
00608
00609 vectorTest_.clear();
00610
00611 for (unsigned long long i = 0; i < 100000000; i++)
00612 {
00613 counterTest_ += 2;
00614 vectorTest_.push_back(counterTest_);
00615 }
00616
00617 wait(400, "InfoRequestThread ----- locked");
00618 __MOUT__ << workLoopName << " test: " << counterTest_ << " vector size: " << vectorTest_.size() << std::endl;
00619 infoRequestSemaphore_.give();
00620
00621
00622 infoRequestWorkLoopManager_.report(workLoop,
00623 theStateMachine_.getCurrentStateName(), 100, true);
00624
00625 return false;
00626
00627 }
00628
00629
00630 void Supervisor::stateInitial(toolbox::fsm::FiniteStateMachine & fsm)
00631 throw (toolbox::fsm::exception::Exception)
00632 {
00633 __MOUT__ << "Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
00634
00635
00636 }
00637
00638
00639 void Supervisor::statePaused(toolbox::fsm::FiniteStateMachine & fsm)
00640 throw (toolbox::fsm::exception::Exception)
00641 {
00642 __MOUT__ << "Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655 }
00656
00657
00658 void Supervisor::stateRunning(toolbox::fsm::FiniteStateMachine & fsm)
00659 throw (toolbox::fsm::exception::Exception)
00660 {
00661
00662 __MOUT__ << "Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675 }
00676
00677
00678 void Supervisor::stateHalted(toolbox::fsm::FiniteStateMachine& fsm)
00679 throw (toolbox::fsm::exception::Exception)
00680 {
00681 __MOUT__ << "Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
00682 __MOUT__ << "Fsm is in transition?" << theStateMachine_.isInTransition() << std::endl;
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705 }
00706
00707
00708 void Supervisor::stateConfigured(toolbox::fsm::FiniteStateMachine & fsm)
00709 throw (toolbox::fsm::exception::Exception)
00710 {
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744 }
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777 void Supervisor::inError(toolbox::fsm::FiniteStateMachine & fsm)
00778 throw (toolbox::fsm::exception::Exception)
00779 {
00780 __MOUT__ << "Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
00781
00782 }
00783
00784
00785 void Supervisor::enteringError(toolbox::Event::Reference e)
00786 throw (toolbox::fsm::exception::Exception)
00787 {
00788 __MOUT__ << "Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
00789
00790
00791 toolbox::fsm::FailedEvent& failedEvent = dynamic_cast<toolbox::fsm::FailedEvent&> (*e);
00792 __SS__ << "\nFailure performing transition from " << failedEvent.getFromState() << "-" <<
00793 theStateMachine_.getStateName(failedEvent.getFromState()) <<
00794 " to " << failedEvent.getToState() << "-" <<
00795 theStateMachine_.getStateName(failedEvent.getToState()) <<
00796 ".\n\nException:\n" << failedEvent.getException().what() << std::endl;
00797 __MOUT_ERR__ << "\n" << ss.str();
00798
00799 theStateMachine_.setErrorMessage(ss.str());
00800
00801
00802
00803
00804
00805
00806 }
00807
00811
00812 void Supervisor::getSupervisorsStatus(void)
00813 throw (toolbox::fsm::exception::Exception)
00814 {
00815 theSupervisorsInfo_.getSupervisorInfo().setStatus(
00816 theStateMachine_.getCurrentStateName());
00817
00818 try
00819 {
00820 SupervisorDescriptors::const_iterator it =
00821 theSupervisorDescriptorInfo_.getFEDescriptors().begin();
00822 for (; it != theSupervisorDescriptorInfo_.getFEDescriptors().end();
00823 it++)
00824 {
00825 try
00826 {
00827 std::string state = send(it->second,
00828 "StateMachineStateRequest");
00829
00830 theSupervisorsInfo_.getFESupervisorInfo(it->first).setStatus(
00831 state);
00832
00833 __MOUT__ << "PixelFESupervisor instance " << it->first << " is in FSM state " << state << std::endl;
00834 __MOUT__ << "Look! Here's a FEW! @@@" << std::endl;
00835 }
00836 catch (xdaq::exception::Exception& e)
00837 {
00838
00839 }
00840 }
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859 for (auto& it : theSupervisorDescriptorInfo_.getARTDAQFEDataManagerDescriptors())
00860 {
00861 try
00862 {
00863 std::string state = send(it.second,
00864 "StateMachineStateRequest");
00865 theSupervisorsInfo_.getARTDAQFEDataManagerSupervisorInfo(it.first).setStatus(
00866 state);
00867 __MOUT__ << "PixelFERSupervisor instance " << it.first << " is in FSM state " << state << std::endl;
00868 __MOUT__ << "Look! Here's a FER! @@@" << std::endl;
00869 }
00870 catch (xdaq::exception::Exception& e)
00871 {
00872
00873 }
00874 }
00875 for (auto& it : theSupervisorDescriptorInfo_.getARTDAQDataManagerDescriptors())
00876 {
00877 try
00878 {
00879 std::string state = send(it.second,
00880 "StateMachineStateRequest");
00881 theSupervisorsInfo_.getARTDAQDataManagerSupervisorInfo(it.first).setStatus(
00882 state);
00883 __MOUT__ << "PixelFERSupervisor instance " << it.first << " is in FSM state " << state << std::endl;
00884 __MOUT__ << "Look! Here's a FER! @@@" << std::endl;
00885 }
00886 catch (xdaq::exception::Exception& e)
00887 {
00888
00889 }
00890 }
00891 }
00892 catch (xdaq::exception::Exception& e)
00893 {
00894 __MOUT__
00895 << "No PixelFESupervisor found in the \"daq\" group in the Configuration XML file."
00896 << std::endl;
00897
00898 }
00899
00900 }
00901
00902
00903 void Supervisor::transitionConfiguring(toolbox::Event::Reference e)
00904 throw (toolbox::fsm::exception::Exception)
00905 {
00906
00907
00908 theProgressBar_.step();
00909
00910 __MOUT__ << "Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
00911
00912 std::string systemAlias = SOAPUtilities::translate(
00913 theStateMachine_.getCurrentMessage()).getParameters().getValue("ConfigurationAlias");
00914
00915 __MOUT__ << "Transition parameter: " << systemAlias << std::endl;
00916
00917 theProgressBar_.step();
00918
00919
00920 try
00921 {
00922 theConfigurationManager_->init();
00923 }
00924 catch(...)
00925 {
00926 __SS__ << "\nTransition to Configuring interrupted! " <<
00927 "The Configuration Manager could not be initialized." << std::endl;
00928
00929 __MOUT_ERR__ << "\n" << ss.str();
00930 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
00931 return;
00932 }
00933
00934 theProgressBar_.step();
00935
00936
00937 try
00938 {
00939 theConfigurationGroup_ = theConfigurationManager_->getConfigurationGroupFromAlias(systemAlias);
00940 }
00941 catch(...)
00942 {
00943 __MOUT_INFO__ << "Exception occurred" << std::endl;
00944 }
00945
00946 theProgressBar_.step();
00947
00948 if(theConfigurationGroup_.second.isInvalid())
00949 {
00950 __SS__ << "\nTransition to Configuring interrupted! System Alias " <<
00951 systemAlias << " could not be translated to a group name and key." << std::endl;
00952
00953 __MOUT_ERR__ << "\n" << ss.str();
00954 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
00955 return;
00956 }
00957
00958 theProgressBar_.step();
00959
00960 __MOUT__ << "Configuration group name: " << theConfigurationGroup_.first << " key: " <<
00961 theConfigurationGroup_.second << std::endl;
00962
00963
00964 {
00965 std::stringstream ss;
00966 ss << "Configuring '" << systemAlias << "' which translates to " <<
00967 theConfigurationGroup_.first << " (" << theConfigurationGroup_.second << ").";
00968 makeSystemLogbookEntry(ss.str());
00969 }
00970
00971 theProgressBar_.step();
00972
00973
00974 try
00975 {
00976 theConfigurationManager_->loadConfigurationGroup(theConfigurationGroup_.first, theConfigurationGroup_.second, true);
00977
00978
00979 ConfigurationManagerRW tmpCfgMgr("TheSupervisor");
00980 tmpCfgMgr.activateConfigurationGroup(theConfigurationGroup_.first, theConfigurationGroup_.second);
00981 }
00982 catch(...)
00983 {
00984 __SS__ << "\nTransition to Configuring interrupted! System Alias " <<
00985 systemAlias << " was translated to " << theConfigurationGroup_.first <<
00986 " (" << theConfigurationGroup_.second << ") but could not be loaded and initialized." << std::endl;
00987 ss << "\n\nTo debug this problem, try activating this group in the Configuration GUI " <<
00988 " and detailed errors will be shown." << std::endl;
00989 __MOUT_ERR__ << "\n" << ss.str();
00990 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
00991 return;
00992 }
00993
00994
00995 {
00996 ConfigurationTree configLinkNode = theConfigurationManager_->getSupervisorConfigurationNode(
00997 supervisorContextUID_, supervisorApplicationUID_);
00998 if(!configLinkNode.isDisconnected())
00999 {
01000 try
01001 {
01002 ConfigurationTree fsmLinkNode = configLinkNode.getNode("LinkToStateMachineConfiguration");
01003 if(!fsmLinkNode.isDisconnected() &&
01004 fsmLinkNode.getNode(activeStateMachineName_ +
01005 "/EnableConfigurationDumpOnConfigureTransition").getValue<bool>())
01006 {
01007
01008 theConfigurationManager_->dumpActiveConfiguration(
01009 fsmLinkNode.getNode(activeStateMachineName_ +
01010 "/ConfigurationDumpOnConfigureFilePath").getValue<std::string>() +
01011 "/" +
01012 fsmLinkNode.getNode(activeStateMachineName_ +
01013 "/ConfigurationDumpOnConfigureFileRadix").getValue<std::string>() +
01014 "_" +
01015 std::to_string(time(0)) +
01016 ".dump",
01017 fsmLinkNode.getNode(activeStateMachineName_ +
01018 "/ConfigurationDumpOnConfigureFormat").getValue<std::string>()
01019 );
01020 }
01021 else
01022 __MOUT_INFO__ << "FSM Link disconnected." << std::endl;
01023 }
01024 catch(std::runtime_error &e) {
01025 __SS__ << "\nTransition to Configuring interrupted! There was an error identified " <<
01026 "during the configuration dump attempt:\n\n " <<
01027 e.what() << std::endl;
01028 __MOUT_ERR__ << "\n" << ss.str();
01029 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
01030 return;
01031 }
01032 catch(...) {
01033 __SS__ << "\nTransition to Configuring interrupted! There was an error identified " <<
01034 "during the configuration dump attempt.\n\n " <<
01035 std::endl;
01036 __MOUT_ERR__ << "\n" << ss.str();
01037 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
01038 return;
01039 }
01040
01041 }
01042 }
01043
01044 theProgressBar_.step();
01045 SOAPParameters parameters;
01046 parameters.addParameter("ConfigurationGroupName", theConfigurationGroup_.first);
01047 parameters.addParameter("ConfigurationGroupKey", theConfigurationGroup_.second.toString());
01048
01049
01050 xoap::MessageReference message = theStateMachine_.getCurrentMessage();
01051 SOAPUtilities::addParameters(message,parameters);
01052 broadcastMessage(message);
01053 theProgressBar_.step();
01054
01055
01056
01057
01058 saveGroupNameAndKey(theConfigurationGroup_,FSM_LAST_CONFIGURED_GROUP_ALIAS_FILE);
01059
01060 __MOUT__ << "Done" << std::endl;
01061 theProgressBar_.complete();
01062 }
01063
01064
01065 void Supervisor::transitionHalting(toolbox::Event::Reference e)
01066 throw (toolbox::fsm::exception::Exception)
01067 {
01068 __MOUT__ << "Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
01069
01070 makeSystemLogbookEntry("Run halting.");
01071
01072 broadcastMessage(theStateMachine_.getCurrentMessage());
01073 }
01074
01075
01076 void Supervisor::transitionInitializing(toolbox::Event::Reference e)
01077 throw (toolbox::fsm::exception::Exception)
01078 {
01079 __MOUT__ << theStateMachine_.getCurrentStateName() << std::endl;
01080
01081
01082 getSupervisorsStatus();
01083
01084 if(!broadcastMessage(theStateMachine_.getCurrentMessage()))
01085 {
01086 __MOUT__ << "I can't Initialize the supervisors!" << std::endl;
01087 }
01088
01089 __MOUT__ << "Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
01090 __MOUT__ << "Fsm current transition: " << theStateMachine_.getCurrentTransitionName(e->type()) << std::endl;
01091 __MOUT__ << "Fsm final state: " << theStateMachine_.getTransitionFinalStateName(e->type()) << std::endl;
01092 }
01093
01094
01095 void Supervisor::transitionPausing(toolbox::Event::Reference e)
01096 throw (toolbox::fsm::exception::Exception)
01097 {
01098 __MOUT__ << "Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
01099
01100 makeSystemLogbookEntry("Run pausing.");
01101
01102 broadcastMessage(theStateMachine_.getCurrentMessage());
01103 }
01104
01105
01106 void Supervisor::transitionResuming(toolbox::Event::Reference e)
01107 throw (toolbox::fsm::exception::Exception)
01108 {
01109 __MOUT__ << "Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
01110
01111 makeSystemLogbookEntry("Run resuming.");
01112
01113 broadcastMessage(theStateMachine_.getCurrentMessage());
01114 }
01115
01116
01117 void Supervisor::transitionStarting(toolbox::Event::Reference e)
01118 throw (toolbox::fsm::exception::Exception)
01119 {
01120 __MOUT__ << "Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
01121
01122 SOAPParameters parameters("RunNumber");
01123 receive(theStateMachine_.getCurrentMessage(), parameters);
01124
01125 std::string runNumber = parameters.getValue("RunNumber");
01126 __MOUT__ << runNumber << std::endl;
01127
01128
01129 {
01130 ConfigurationTree configLinkNode = theConfigurationManager_->getSupervisorConfigurationNode(
01131 supervisorContextUID_, supervisorApplicationUID_);
01132 if(!configLinkNode.isDisconnected())
01133 {
01134 try
01135 {
01136 ConfigurationTree fsmLinkNode = configLinkNode.getNode("LinkToStateMachineConfiguration");
01137 if(!fsmLinkNode.isDisconnected() &&
01138 fsmLinkNode.getNode(activeStateMachineName_ +
01139 "/EnableConfigurationDumpOnRunTransition").getValue<bool>())
01140 {
01141
01142 theConfigurationManager_->dumpActiveConfiguration(
01143 fsmLinkNode.getNode(activeStateMachineName_ +
01144 "/ConfigurationDumpOnRunFilePath").getValue<std::string>() +
01145 "/" +
01146 fsmLinkNode.getNode(activeStateMachineName_ +
01147 "/ConfigurationDumpOnRunFileRadix").getValue<std::string>() +
01148 "_Run" +
01149 runNumber +
01150 "_" +
01151 std::to_string(time(0)) +
01152 ".dump",
01153 fsmLinkNode.getNode(activeStateMachineName_ +
01154 "/ConfigurationDumpOnRunFormat").getValue<std::string>()
01155 );
01156 }
01157 else
01158 __MOUT_INFO__ << "FSM Link disconnected." << std::endl;
01159 }
01160 catch(std::runtime_error &e) {
01161 __SS__ << "\nTransition to Configuring interrupted! There was an error identified " <<
01162 "during the configuration dump attempt:\n\n " <<
01163 e.what() << std::endl;
01164 __MOUT_ERR__ << "\n" << ss.str();
01165 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
01166 return;
01167 }
01168 catch(...) {
01169 __SS__ << "\nTransition to Configuring interrupted! There was an error identified " <<
01170 "during the configuration dump attempt.\n\n " <<
01171 std::endl;
01172 __MOUT_ERR__ << "\n" << ss.str();
01173 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
01174 return;
01175 }
01176
01177 }
01178 }
01179
01180
01181 makeSystemLogbookEntry("Run " + runNumber + " starting.");
01182
01183 broadcastMessage(theStateMachine_.getCurrentMessage());
01184
01185
01186 saveGroupNameAndKey(theConfigurationGroup_,FSM_LAST_STARTED_GROUP_ALIAS_FILE);
01187 }
01188
01189
01190 void Supervisor::transitionStopping(toolbox::Event::Reference e)
01191 throw (toolbox::fsm::exception::Exception)
01192 {
01193 __MOUT__ << "Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
01194
01195 makeSystemLogbookEntry("Run stopping.");
01196
01197 broadcastMessage(theStateMachine_.getCurrentMessage());
01198 }
01199
01203
01204
01205 bool Supervisor::broadcastMessage(xoap::MessageReference message)
01206 throw (toolbox::fsm::exception::Exception)
01207 {
01208 std::string command = SOAPUtilities::translate(message).getCommand();
01209 bool proceed = true;
01210 std::string reply;
01211
01212
01213
01214 for(auto& it: theSupervisorDescriptorInfo_.getFEDescriptors())
01215 {
01216 RunControlStateMachine::theProgressBar_.step();
01217 __MOUT__ << "Sending message to FESupervisors: " << it.second->getLocalId() << " : " << command << std::endl;
01218 __MOUT__ << "Sending message to FESupervisors: " << it.second->getLocalId() << " : " << command << std::endl;
01219 __MOUT__ << "Sending message to FESupervisors: " << it.second->getLocalId() << " : " << command << std::endl;
01220 __MOUT__ << "Sending message to FESupervisors: " << it.second->getLocalId() << " : " << command << std::endl;
01221 __MOUT__ << "Sending message to FESupervisors: " << it.second->getLocalId() << " : " << command << std::endl;
01222
01223 try
01224 {
01225 reply = send(it.second, message);
01226 }
01227 catch(const xdaq::exception::Exception &e)
01228 {
01229
01230 __SS__ << "Can NOT " << command << " FESupervisors, instance = " << it.first << ".\n\n" <<
01231 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
01232 __MOUT_ERR__ << ss.str();
01233 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
01234 proceed = false;
01235 }
01236
01237 if (reply != command + "Done")
01238 {
01239
01240
01241 __SS__ << "Can NOT " << command << " FESupervisor, instance = " << it.first << ".\n\n" <<
01242 reply;
01243 __MOUT_ERR__ << ss.str() << std::endl;
01244
01245 __MOUT__ << "Getting error message..." << std::endl;
01246 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference("StateMachineErrorMessageRequest"));
01247 SOAPParameters parameters;
01248 parameters.addParameter("ErrorMessage");
01249 SOAPMessenger::receive(errorMessage, parameters);
01250 __MOUT_ERR__ << "errorMessage = " << parameters.getValue("ErrorMessage") << std::endl;
01251 ss << "\n\nError Message: " << parameters.getValue("ErrorMessage") << std::endl;
01252 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
01253 proceed = false;
01254
01255 }
01256 else
01257 {
01258 __MOUT__ << "FESupervisor supervisor " << (it.first) << " was " << command << "'d correctly!" << std::endl;
01259 }
01260 }
01261
01262
01263 for(auto& it: theSupervisorDescriptorInfo_.getDataManagerDescriptors())
01264 {
01265 RunControlStateMachine::theProgressBar_.step();
01266 __MOUT__ << "Sending message to DataManagerSupervisors: " << it.second->getLocalId() << " : " << command << std::endl;
01267 __MOUT__ << "Sending message to DataManagerSupervisors: " << it.second->getLocalId() << " : " << command << std::endl;
01268 __MOUT__ << "Sending message to DataManagerSupervisors: " << it.second->getLocalId() << " : " << command << std::endl;
01269 __MOUT__ << "Sending message to DataManagerSupervisors: " << it.second->getLocalId() << " : " << command << std::endl;
01270 __MOUT__ << "Sending message to DataManagerSupervisors: " << it.second->getLocalId() << " : " << command << std::endl;
01271
01272 try
01273 {
01274 reply = send(it.second, message);
01275 }
01276 catch(const xdaq::exception::Exception &e)
01277 {
01278
01279 __SS__ << "Can NOT " << command << " DataManagerSupervisors, instance = " << it.first << ".\n\n" <<
01280 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
01281 __MOUT_ERR__ << ss.str();
01282 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
01283 proceed = false;
01284 }
01285
01286 if (reply != command + "Done")
01287 {
01288 __SS__ << "Can NOT " << command << " DataManagerSupervisor, instance = " << it.first << ".\n\n" <<
01289 reply;
01290 __MOUT_ERR__ << ss.str() << std::endl;
01291 __MOUT__ << "Getting error message..." << std::endl;
01292 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference("StateMachineErrorMessageRequest"));
01293 SOAPParameters parameters;
01294 parameters.addParameter("ErrorMessage");
01295 SOAPMessenger::receive(errorMessage, parameters);
01296 __MOUT_ERR__ << "errorMessage = " << parameters.getValue("ErrorMessage") << std::endl;
01297 ss << "\n\nError Message: " << parameters.getValue("ErrorMessage") << std::endl;
01298 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
01299 proceed = false;
01300 }
01301 else
01302 {
01303 __MOUT__ << "DataManagerSupervisor " << (it.first) << " was " << command << "'d correctly!" << std::endl;
01304 }
01305 }
01306
01307
01308 for (auto& it: theSupervisorDescriptorInfo_.getFEDataManagerDescriptors())
01309 {
01310 RunControlStateMachine::theProgressBar_.step();
01311 __MOUT__ << "Sending message to FEDataManagerSupervisors: " << it.second->getLocalId() << " : " << command << std::endl;
01312 __MOUT__ << "Sending message to FEDataManagerSupervisors: " << it.second->getLocalId() << " : " << command << std::endl;
01313 __MOUT__ << "Sending message to FEDataManagerSupervisors: " << it.second->getLocalId() << " : " << command << std::endl;
01314 __MOUT__ << "Sending message to FEDataManagerSupervisors: " << it.second->getLocalId() << " : " << command << std::endl;
01315 __MOUT__ << "Sending message to FEDataManagerSupervisors: " << it.second->getLocalId() << " : " << command << std::endl;
01316
01317 try
01318 {
01319 reply = send(it.second, message);
01320 }
01321 catch(const xdaq::exception::Exception &e)
01322 {
01323
01324 __SS__ << "Can NOT " << command << " FEDataManagerSupervisors, instance = " << it.first << ".\n\n" <<
01325 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
01326 __MOUT_ERR__ << ss.str();
01327 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
01328 proceed = false;
01329 }
01330
01331 if (reply != command + "Done")
01332 {
01333 __SS__ << "Can NOT " << command << " FEDataManagerSupervisor, instance = " << it.first << ".\n\n" <<
01334 reply;
01335 __MOUT_ERR__ << ss.str() << std::endl;
01336 __MOUT__ << "Getting error message..." << std::endl;
01337 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference("StateMachineErrorMessageRequest"));
01338 SOAPParameters parameters;
01339 parameters.addParameter("ErrorMessage");
01340 SOAPMessenger::receive(errorMessage, parameters);
01341 __MOUT_ERR__ << "errorMessage = " << parameters.getValue("ErrorMessage") << std::endl;
01342 ss << "\n\nError Message: " << parameters.getValue("ErrorMessage") << std::endl;
01343 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
01344 proceed = false;
01345 }
01346 else
01347 {
01348 __MOUT__ << "FEDataManagerSupervisor " << (it.first) << " was " << command << "'d correctly!" << std::endl;
01349 }
01350 }
01351
01352
01353 for(auto& it: theSupervisorDescriptorInfo_.getVisualDescriptors())
01354 {
01355 RunControlStateMachine::theProgressBar_.step();
01356 __MOUT__ << "Sending message to VisualSupervisor: " << it.second->getLocalId() << " : " << command << std::endl;
01357 __MOUT__ << "Sending message to VisualSupervisor: " << it.second->getLocalId() << " : " << command << std::endl;
01358 __MOUT__ << "Sending message to VisualSupervisor: " << it.second->getLocalId() << " : " << command << std::endl;
01359 __MOUT__ << "Sending message to VisualSupervisor: " << it.second->getLocalId() << " : " << command << std::endl;
01360 __MOUT__ << "Sending message to VisualSupervisor: " << it.second->getLocalId() << " : " << command << std::endl;
01361
01362
01363 try
01364 {
01365 reply = send(it.second, message);
01366 }
01367 catch(const xdaq::exception::Exception &e)
01368 {
01369
01370 __SS__ << "Can NOT " << command << " VisualSupervisor, instance = " << it.first << ".\n\n" <<
01371 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
01372 __MOUT_ERR__ << ss.str();
01373 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
01374 proceed = false;
01375 }
01376
01377
01378 if (reply != command + "Done")
01379 {
01380 __SS__ << "Can NOT " << command << " VisualSupervisor, instance = " << it.first << ".\n\n" <<
01381 reply;
01382 __MOUT_ERR__ << ss.str() << std::endl;
01383 __MOUT__ << "Getting error message..." << std::endl;
01384 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference("StateMachineErrorMessageRequest"));
01385 SOAPParameters parameters;
01386 parameters.addParameter("ErrorMessage");
01387 SOAPMessenger::receive(errorMessage, parameters);
01388 __MOUT_ERR__ << "errorMessage = " << parameters.getValue("ErrorMessage") << std::endl;
01389 ss << "\n\nError Message: " << parameters.getValue("ErrorMessage") << std::endl;
01390 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
01391 proceed = false;
01392 }
01393 else
01394 {
01395 __MOUT__ << "VisualSupervisor supervisor " << (it.first) << " was " << command << "'d correctly!" << std::endl;
01396 }
01397 }
01398
01399
01400
01401
01402
01403 bool artdaqRestarted = false;
01404 bool artdaqWasRestarted = false;
01405
01406 RunControlStateMachine::theProgressBar_.step();
01407 if(command == "Halt" || command == "Initialize")
01408 {
01409
01410
01411
01412
01413
01414 FILE *fp = fopen((std::string(getenv("SERVICE_DATA_PATH")) +
01415 "/StartOTS_action.cmd").c_str(),"w");
01416 if(fp)
01417 {
01418 fprintf(fp,"RESET_MPI");
01419 fclose(fp);
01420
01421 }
01422
01423 artdaqRestarted = true;
01424
01425 SOAPParameters parameters;
01426 message = SOAPUtilities::makeSOAPMessageReference(
01427 "Initialize", parameters);
01428 command = SOAPUtilities::translate(message).getCommand();
01429 __MOUT__ << "command now is " << command << std::endl;
01430 }
01431 RunControlStateMachine::theProgressBar_.step();
01432
01433
01434 int MAX_ARTDAQ_RESTARTS = 10;
01435 int ARTDAQ_RESTART_DELAY = 2;
01436 int artdaqRestartCount = 0;
01437 bool preArtdaqProceed = proceed;
01438
01439 ARTDAQ_RETRY:
01440 if(artdaqWasRestarted)
01441 {
01442 ++artdaqRestartCount;
01443 proceed = preArtdaqProceed;
01444 if(artdaqRestartCount < MAX_ARTDAQ_RESTARTS)
01445 artdaqWasRestarted = false;
01446 for(int i=0;i<ARTDAQ_RESTART_DELAY;++i)
01447 {
01448 sleep(1);
01449 __MOUT_INFO__ << "Waiting on artdaq reboot... " << i << " for " << artdaqRestartCount << "x" << std::endl;
01450 }
01451 }
01452
01453
01454 for(auto& it: theSupervisorDescriptorInfo_.getARTDAQFEDataManagerDescriptors())
01455 {
01456 RunControlStateMachine::theProgressBar_.step();
01457 __MOUT__ << "Sending message to ARTDAQFEDataManagerSupervisors: " << it.second->getLocalId() << " : " << command << std::endl;
01458 __MOUT__ << "Sending message to ARTDAQFEDataManagerSupervisors: " << it.second->getLocalId() << " : " << command << std::endl;
01459 __MOUT__ << "Sending message to ARTDAQFEDataManagerSupervisors: " << it.second->getLocalId() << " : " << command << std::endl;
01460 __MOUT__ << "Sending message to ARTDAQFEDataManagerSupervisors: " << it.second->getLocalId() << " : " << command << std::endl;
01461 __MOUT__ << "Sending message to ARTDAQFEDataManagerSupervisors: " << it.second->getLocalId() << " : " << command << std::endl;
01462
01463 try
01464 {
01465 reply = send(it.second, message);
01466 if (reply != command + "Done")
01467 {
01468 __SS__ << "Can NOT " << command << " ARTDAQFEDataManagerSupervisor, instance = " << it.first << ".\n\n" <<
01469 reply;
01470 __MOUT_ERR__ << ss.str() << std::endl;
01471 __MOUT__ << "Getting error message..." << std::endl;
01472 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference("StateMachineErrorMessageRequest"));
01473 SOAPParameters parameters;
01474 parameters.addParameter("ErrorMessage");
01475 SOAPMessenger::receive(errorMessage, parameters);
01476 __MOUT_ERR__ << "errorMessage = " << parameters.getValue("ErrorMessage") << std::endl;
01477 ss << "\n\nError Message: " << parameters.getValue("ErrorMessage") << std::endl;
01478 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
01479 proceed = false;
01480 }
01481 else
01482 {
01483 __MOUT__ << "ARTDAQFEDataManagerSupervisors supervisor " << (it.first) << " was " << command << "'d correctly!" << std::endl;
01484 }
01485 }
01486 catch(const xdaq::exception::Exception &e)
01487 {
01488 if(artdaqRestarted && !artdaqWasRestarted)
01489 {
01490 artdaqWasRestarted = true;
01491 goto ARTDAQ_RETRY;
01492 }
01493 else
01494 {
01495
01496 __SS__ << "Can NOT " << command << " ARTDAQFEDataManagerSupervisor, instance = " << it.first << ".\n\n" <<
01497 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
01498 __MOUT_ERR__ << ss.str();
01499 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
01500 proceed = false;
01501 }
01502 }
01503 catch(const toolbox::fsm::exception::Exception &e)
01504 {
01505 if(artdaqRestarted && !artdaqWasRestarted)
01506 {
01507 artdaqWasRestarted = true;
01508 goto ARTDAQ_RETRY;
01509 }
01510 else
01511 throw;
01512 }
01513 }
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523 for(auto& it: theSupervisorDescriptorInfo_.getARTDAQDataManagerDescriptors())
01524 {
01525 RunControlStateMachine::theProgressBar_.step();
01526 __MOUT__ << "Sending message to ARTDAQDataManagerSupervisor: " << it.second->getLocalId() << " : " << command << std::endl;
01527 __MOUT__ << "Sending message to ARTDAQDataManagerSupervisor: " << it.second->getLocalId() << " : " << command << std::endl;
01528 __MOUT__ << "Sending message to ARTDAQDataManagerSupervisor: " << it.second->getLocalId() << " : " << command << std::endl;
01529 __MOUT__ << "Sending message to ARTDAQDataManagerSupervisor: " << it.second->getLocalId() << " : " << command << std::endl;
01530 __MOUT__ << "Sending message to ARTDAQDataManagerSupervisor: " << it.second->getLocalId() << " : " << command << std::endl;
01531 try
01532 {
01533 reply = send(it.second, message);
01534 if (reply != command + "Done")
01535 {
01536 __SS__ << "Can NOT " << command << " ARTDAQDataManagerSupervisor, instance = " << it.first << ".\n\n" <<
01537 reply;
01538 __MOUT_ERR__ << ss.str() << std::endl;
01539 __MOUT__ << "Getting error message..." << std::endl;
01540 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference("StateMachineErrorMessageRequest"));
01541 SOAPParameters parameters;
01542 parameters.addParameter("ErrorMessage");
01543 SOAPMessenger::receive(errorMessage, parameters);
01544 __MOUT_ERR__ << "errorMessage = " << parameters.getValue("ErrorMessage") << std::endl;
01545 ss << "\n\nError Message: " << parameters.getValue("ErrorMessage") << std::endl;
01546 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
01547 proceed = false;
01548 }
01549 else
01550 {
01551 __MOUT__ << "ARTDAQDataManagerSupervisor supervisor " << (it.first) << " was " << command << "'d correctly!" << std::endl;
01552 }
01553 }
01554 catch(const xdaq::exception::Exception &e)
01555 {
01556 if(artdaqRestarted && !artdaqWasRestarted)
01557 {
01558 artdaqWasRestarted = true;
01559 goto ARTDAQ_RETRY;
01560 }
01561 else
01562 {
01563
01564 __SS__ << "Can NOT " << command << " ARTDAQDataManagerSupervisor, instance = " << it.first << ".\n\n" <<
01565 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
01566 __MOUT_ERR__ << ss.str();
01567 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
01568 proceed = false;
01569 }
01570 }
01571 catch(const toolbox::fsm::exception::Exception &e)
01572 {
01573 if(artdaqRestarted && !artdaqWasRestarted)
01574 {
01575 artdaqWasRestarted = true;
01576 goto ARTDAQ_RETRY;
01577 }
01578 else
01579 throw;
01580 }
01581 }
01582
01583
01584 for(auto& it: theSupervisorDescriptorInfo_.getARTDAQBuilderDescriptors())
01585 {
01586 RunControlStateMachine::theProgressBar_.step();
01587 __MOUT__ << "Sending message to ARTDAQBuilderSupervisor: " << it.second->getLocalId() << " : " << command << std::endl;
01588 __MOUT__ << "Sending message to ARTDAQBuilderSupervisor: " << it.second->getLocalId() << " : " << command << std::endl;
01589 __MOUT__ << "Sending message to ARTDAQBuilderSupervisor: " << it.second->getLocalId() << " : " << command << std::endl;
01590 __MOUT__ << "Sending message to ARTDAQBuilderSupervisor: " << it.second->getLocalId() << " : " << command << std::endl;
01591 __MOUT__ << "Sending message to ARTDAQBuilderSupervisor: " << it.second->getLocalId() << " : " << command << std::endl;
01592
01593 try
01594 {
01595 reply = send(it.second, message);
01596 if (reply != command + "Done")
01597 {
01598 __SS__ << "Can NOT " << command << " ARTDAQBuilderSupervisor, instance = " << it.first << ".\n\n" <<
01599 reply;
01600 __MOUT_ERR__ << ss.str() << std::endl;
01601 __MOUT__ << "Getting error message..." << std::endl;
01602 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference("StateMachineErrorMessageRequest"));
01603 SOAPParameters parameters;
01604 parameters.addParameter("ErrorMessage");
01605 SOAPMessenger::receive(errorMessage, parameters);
01606 __MOUT_ERR__ << "errorMessage = " << parameters.getValue("ErrorMessage") << std::endl;
01607 ss << "\n\nError Message: " << parameters.getValue("ErrorMessage") << std::endl;
01608 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
01609 proceed = false;
01610 }
01611 else
01612 {
01613 __MOUT__ << "ARTDAQBuilderSupervisor supervisor " << (it.first) << " was " << command << "'d correctly!" << std::endl;
01614 }
01615 }
01616 catch(const xdaq::exception::Exception &e)
01617 {
01618 if(artdaqRestarted && !artdaqWasRestarted)
01619 {
01620 artdaqWasRestarted = true;
01621 goto ARTDAQ_RETRY;
01622 }
01623 else
01624 {
01625
01626 __SS__ << "Can NOT " << command << " ARTDAQBuilderSupervisor, instance = " << it.first << ".\n\n" <<
01627 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
01628 __MOUT_ERR__ << ss.str();
01629 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
01630 proceed = false;
01631 }
01632 }
01633 catch(const toolbox::fsm::exception::Exception &e)
01634 {
01635 if(artdaqRestarted && !artdaqWasRestarted)
01636 {
01637 artdaqWasRestarted = true;
01638 goto ARTDAQ_RETRY;
01639 }
01640 else
01641 throw;
01642 }
01643 }
01644
01645
01646 for(auto& it: theSupervisorDescriptorInfo_.getARTDAQAggregatorDescriptors())
01647 {
01648 RunControlStateMachine::theProgressBar_.step();
01649 __MOUT__ << "Sending message to ARTDAQAggregatorSupervisor: " << it.second->getLocalId() << " : " << command << std::endl;
01650 __MOUT__ << "Sending message to ARTDAQAggregatorSupervisor: " << it.second->getLocalId() << " : " << command << std::endl;
01651 __MOUT__ << "Sending message to ARTDAQAggregatorSupervisor: " << it.second->getLocalId() << " : " << command << std::endl;
01652 __MOUT__ << "Sending message to ARTDAQAggregatorSupervisor: " << it.second->getLocalId() << " : " << command << std::endl;
01653 __MOUT__ << "Sending message to ARTDAQAggregatorSupervisor: " << it.second->getLocalId() << " : " << command << std::endl;
01654
01655 try
01656 {
01657 reply = send(it.second, message);
01658 if (reply != command + "Done")
01659 {
01660 __SS__ << "Can NOT " << command << " ARTDAQAggregatorSupervisor, instance = " << it.first << ".\n\n" <<
01661 reply;
01662 __MOUT_ERR__ << ss.str() << std::endl;
01663 __MOUT__ << "Getting error message..." << std::endl;
01664 xoap::MessageReference errorMessage = sendWithSOAPReply(it.second, SOAPUtilities::makeSOAPMessageReference("StateMachineErrorMessageRequest"));
01665 SOAPParameters parameters;
01666 parameters.addParameter("ErrorMessage");
01667 SOAPMessenger::receive(errorMessage, parameters);
01668 __MOUT_ERR__ << "errorMessage = " << parameters.getValue("ErrorMessage") << std::endl;
01669 ss << "\n\nError Message: " << parameters.getValue("ErrorMessage") << std::endl;
01670 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
01671 proceed = false;
01672 }
01673 else
01674 {
01675 __MOUT__ << "ARTDAQAggregatorSupervisor supervisor " << (it.first) << " was " << command << "'d correctly!" << std::endl;
01676 }
01677 }
01678 catch(const xdaq::exception::Exception &e)
01679 {
01680 if(artdaqRestarted && !artdaqWasRestarted)
01681 {
01682 artdaqWasRestarted = true;
01683 goto ARTDAQ_RETRY;
01684 }
01685 else
01686 {
01687
01688 __SS__ << "Can NOT " << command << " ARTDAQAggregatorSupervisor, instance = " << it.first << ".\n\n" <<
01689 "Xoap failure. Did the target Supervisor crash? Try restarting re-initializing or restarting otsdaq." << std::endl;
01690 __MOUT_ERR__ << ss.str();
01691 XCEPT_RAISE(toolbox::fsm::exception::Exception, ss.str());
01692 proceed = false;
01693 }
01694 }
01695 catch(const toolbox::fsm::exception::Exception &e)
01696 {
01697 if(artdaqRestarted && !artdaqWasRestarted)
01698 {
01699 artdaqWasRestarted = true;
01700 goto ARTDAQ_RETRY;
01701 }
01702 else
01703 throw;
01704 }
01705 }
01706
01707 return proceed;
01708 }
01709
01710
01711 void Supervisor::wait(int milliseconds, std::string who) const
01712 {
01713 for (int s = 1; s <= milliseconds; s++)
01714 {
01715 usleep(1000);
01716
01717 if (s % 100 == 0)
01718 __MOUT__ << s << " msecs " << who << std::endl;
01719 }
01720 }
01721
01722
01723
01724
01725
01726
01727 void Supervisor::loginRequest(xgi::Input * in, xgi::Output * out)
01728 throw (xgi::exception::Exception)
01729 {
01730 cgicc::Cgicc cgi(in);
01731 std::string Command = CgiDataUtilities::getData(cgi, "RequestType");
01732
01733 __MOUT__ << Command << std::endl;
01734
01735
01736
01737
01738
01739
01740
01741
01742 std::vector<std::string> loggedOutUsernames;
01743 theWebUsers_.cleanupExpiredEntries(&loggedOutUsernames);
01744 for (unsigned int i = 0; i < loggedOutUsernames.size(); ++i)
01745 makeSystemLogbookEntry(loggedOutUsernames[i] + " login timed out.");
01746
01747 if (Command == "sessionId")
01748 {
01749
01750
01751
01752
01753
01754 std::string uuid = CgiDataUtilities::postData(cgi, "uuid");
01755
01756 std::string sid = theWebUsers_.createNewLoginSession(uuid);
01757
01758 __MOUT__ << "uuid = " << uuid << std::endl;
01759 __MOUT__ << "SessionId = " << sid.substr(0, 10) << std::endl;
01760 *out << sid;
01761 }
01762 else if (Command == "checkCookie")
01763 {
01764 uint64_t uid;
01765 std::string uuid;
01766 std::string jumbledUser;
01767 std::string cookieCode;
01768
01769
01770
01771
01772
01773
01774
01775
01776
01777 uuid = CgiDataUtilities::postData(cgi, "uuid");
01778 jumbledUser = CgiDataUtilities::postData(cgi, "ju");
01779 cookieCode = CgiDataUtilities::postData(cgi, "cc");
01780
01781 __MOUT__ << "Cookie Code = " << cookieCode.substr(0, 10) << std::endl;
01782 __MOUT__ << "jumbledUser = " << jumbledUser.substr(0, 10) << std::endl;
01783 __MOUT__ << "uuid = " << uuid << std::endl;
01784
01785
01786 uid = theWebUsers_.isCookieCodeActiveForLogin(uuid, cookieCode,
01787 jumbledUser);
01788
01789 if (uid == theWebUsers_.NOT_FOUND_IN_DATABASE)
01790 {
01791 __MOUT__ << "cookieCode invalid" << std::endl;
01792 jumbledUser = "";
01793 cookieCode = "0";
01794 }
01795
01796
01797 HttpXmlDocument xmldoc(cookieCode, jumbledUser);
01798
01799 theWebUsers_.insertSettingsForUser(uid, &xmldoc);
01800
01801 xmldoc.outputXmlDocument((std::ostringstream*) out);
01802
01803 }
01804 else if (Command == "login")
01805 {
01806
01807
01808
01809
01810
01811
01812
01813
01814
01815 std::string uuid = CgiDataUtilities::postData(cgi, "uuid");
01816 std::string newAccountCode = CgiDataUtilities::postData(cgi, "nac");
01817 std::string jumbledUser = CgiDataUtilities::postData(cgi, "ju");
01818 std::string jumbledPw = CgiDataUtilities::postData(cgi, "jp");
01819
01820 __MOUT__ << "jumbledUser = " << jumbledUser.substr(0, 10) << std::endl;
01821 __MOUT__ << "jumbledPw = " << jumbledPw.substr(0, 10) << std::endl;
01822 __MOUT__ << "uuid = " << uuid << std::endl;
01823 __MOUT__ << "nac =-" << newAccountCode << "-" << std::endl;
01824
01825 uint64_t uid = theWebUsers_.attemptActiveSession(uuid, jumbledUser,
01826 jumbledPw, newAccountCode);
01827
01828
01829 if (uid == theWebUsers_.NOT_FOUND_IN_DATABASE)
01830 {
01831 __MOUT__ << "cookieCode invalid" << std::endl;
01832 jumbledUser = "";
01833 if (newAccountCode != "1")
01834 newAccountCode = "0";
01835 }
01836
01837 __MOUT__ << "new cookieCode = " << newAccountCode.substr(0, 10) << std::endl;
01838
01839 HttpXmlDocument xmldoc(newAccountCode, jumbledUser);
01840
01841 theWebUsers_.insertSettingsForUser(uid, &xmldoc);
01842
01843
01844
01845 if (uid != theWebUsers_.NOT_FOUND_IN_DATABASE)
01846 {
01847 uint64_t asCnt = theWebUsers_.getActiveSessionCountForUser(uid) - 1;
01848 char asStr[20];
01849 sprintf(asStr, "%lu", asCnt);
01850 xmldoc.addTextElementToData("user_active_session_count", asStr);
01851 }
01852
01853 xmldoc.outputXmlDocument((std::ostringstream*) out);
01854
01855
01856 makeSystemLogbookEntry(
01857 theWebUsers_.getUsersUsername(uid) + " logged in.");
01858 }
01859 else if (Command == "logout")
01860 {
01861 std::string cookieCode = CgiDataUtilities::postData(cgi, "CookieCode");
01862 std::string logoutOthers = CgiDataUtilities::postData(cgi,
01863 "LogoutOthers");
01864
01865 __MOUT__ << "Cookie Code = " << cookieCode.substr(0, 10) << std::endl;
01866 __MOUT__ << "logoutOthers = " << logoutOthers << std::endl;
01867
01868 uint64_t uid;
01869 if (theWebUsers_.cookieCodeLogout(cookieCode, logoutOthers == "1", &uid)
01870 != theWebUsers_.NOT_FOUND_IN_DATABASE)
01871 {
01872
01873
01874 if (!theWebUsers_.isUserIdActive(uid))
01875 makeSystemLogbookEntry(
01876 theWebUsers_.getUsersUsername(uid) + " logged out.");
01877 }
01878 }
01879 else
01880 {
01881 __MOUT__ << __LINE__ << "\tInvalid Command" << std::endl;
01882 *out << "0";
01883 }
01884 }
01885
01886
01887 void Supervisor::tooltipRequest(xgi::Input * in, xgi::Output * out)
01888 throw (xgi::exception::Exception)
01889 {
01890 cgicc::Cgicc cgi(in);
01891
01892 std::string Command = CgiDataUtilities::getData(cgi, "RequestType");
01893 __MOUT__ << Command << std::endl;
01894
01895
01896
01897
01898
01899 std::string cookieCode = CgiDataUtilities::postData(cgi, "CookieCode");
01900 uint8_t userPermissions;
01901 uint64_t uid;
01902
01903 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions,
01904 &uid, "0", false))
01905 {
01906 *out << cookieCode;
01907 return;
01908 }
01909
01910
01911
01912 HttpXmlDocument xmldoc(cookieCode);
01913
01914 if(Command == "check")
01915 {
01916 WebUsers::tooltipCheckForUsername(
01917 theWebUsers_.getUsersUsername(uid),
01918 &xmldoc,
01919 CgiDataUtilities::getData(cgi, "srcFile"),
01920 CgiDataUtilities::getData(cgi, "srcFunc"),
01921 CgiDataUtilities::getData(cgi, "srcId"));
01922 }
01923 else if(Command == "setNeverShow")
01924 {
01925 WebUsers::tooltipSetNeverShowForUsername(
01926 theWebUsers_.getUsersUsername(uid),
01927 &xmldoc,
01928 CgiDataUtilities::getData(cgi, "srcFile"),
01929 CgiDataUtilities::getData(cgi, "srcFunc"),
01930 CgiDataUtilities::getData(cgi, "srcId"),
01931 CgiDataUtilities::getData(cgi, "doNeverShow") == "1"?true:false,
01932 CgiDataUtilities::getData(cgi, "temporarySilence") == "1"?true:false);
01933
01934 }
01935 else
01936 __MOUT__ << "Command Request, " << Command << ", not recognized." << std::endl;
01937
01938 xmldoc.outputXmlDocument((std::ostringstream*) out, false, true);
01939 }
01940
01941
01942 void Supervisor::request(xgi::Input * in, xgi::Output * out)
01943 throw (xgi::exception::Exception)
01944 {
01945 cgicc::Cgicc cgi(in);
01946
01947 std::string Command = CgiDataUtilities::getData(cgi, "RequestType");
01948
01949
01950
01951
01952
01953
01954 std::string cookieCode = CgiDataUtilities::postData(cgi, "CookieCode");
01955 uint8_t userPermissions;
01956 uint64_t uid;
01957 std::string userWithLock;
01958
01959 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions,
01960 &uid, "0", Command != "getSystemMessages", &userWithLock))
01961 {
01962 *out << cookieCode;
01963 return;
01964 }
01965
01966
01967
01968
01969
01970
01971
01972
01973
01974
01975
01976
01977
01978
01979
01980
01981
01982
01983
01984
01985 HttpXmlDocument xmldoc(cookieCode);
01986
01987 if (Command == "getSettings")
01988 {
01989 std::string accounts = CgiDataUtilities::getData(cgi, "accounts");
01990
01991 __MOUT__ << "Get Settings Request" << std::endl;
01992 __MOUT__ << "accounts = " << accounts << std::endl;
01993 theWebUsers_.insertSettingsForUser(uid, &xmldoc, accounts == "1");
01994 }
01995 else if (Command == "setSettings")
01996 {
01997 std::string bgcolor = CgiDataUtilities::postData(cgi, "bgcolor");
01998 std::string dbcolor = CgiDataUtilities::postData(cgi, "dbcolor");
01999 std::string wincolor = CgiDataUtilities::postData(cgi, "wincolor");
02000 std::string layout = CgiDataUtilities::postData(cgi, "layout");
02001 std::string syslayout = CgiDataUtilities::postData(cgi, "syslayout");
02002
02003 __MOUT__ << "Set Settings Request" << std::endl;
02004 __MOUT__ << "bgcolor = " << bgcolor << std::endl;
02005 __MOUT__ << "dbcolor = " << dbcolor << std::endl;
02006 __MOUT__ << "wincolor = " << wincolor << std::endl;
02007 __MOUT__ << "layout = " << layout << std::endl;
02008 __MOUT__ << "syslayout = " << syslayout << std::endl;
02009 theWebUsers_.changeSettingsForUser(uid, bgcolor, dbcolor, wincolor,
02010 layout, syslayout);
02011 theWebUsers_.insertSettingsForUser(uid, &xmldoc, true);
02012 }
02013 else if (Command == "accountSettings")
02014 {
02015 std::string type = CgiDataUtilities::postData(cgi, "type");
02016 int type_int = -1;
02017
02018 if (type == "updateAccount")
02019 type_int = 0;
02020 else if (type == "createAccount")
02021 type_int = 1;
02022 else if (type == "deleteAccount")
02023 type_int = 2;
02024
02025 std::string username = CgiDataUtilities::postData(cgi, "username");
02026 std::string displayname = CgiDataUtilities::postData(cgi,
02027 "displayname");
02028 std::string permissions = CgiDataUtilities::postData(cgi,
02029 "permissions");
02030 std::string accounts = CgiDataUtilities::getData(cgi, "accounts");
02031
02032 __MOUT__ << "accountSettings Request" << std::endl;
02033 __MOUT__ << "type = " << type << " - " << type_int << std::endl;
02034 __MOUT__ << "username = " << username << std::endl;
02035 __MOUT__ << "displayname = " << displayname << std::endl;
02036 __MOUT__ << "permissions = " << permissions << std::endl;
02037
02038 theWebUsers_.modifyAccountSettings(uid, type_int, username, displayname,
02039 permissions);
02040
02041 __MOUT__ << "accounts = " << accounts << std::endl;
02042
02043 theWebUsers_.insertSettingsForUser(uid, &xmldoc, accounts == "1");
02044 }
02045 else if(Command == "stateMatchinePreferences")
02046 {
02047 std::string set = CgiDataUtilities::getData(cgi, "set");
02048 const std::string DEFAULT_FSM_VIEW = "Default_FSM_View";
02049 if(set == "1")
02050 theWebUsers_.setGenericPreference(uid, DEFAULT_FSM_VIEW,
02051 CgiDataUtilities::getData(cgi, DEFAULT_FSM_VIEW));
02052 else
02053 theWebUsers_.getGenericPreference(uid, DEFAULT_FSM_VIEW, &xmldoc);
02054 }
02055 else if(Command == "getAliasList")
02056 {
02057 std::string username = theWebUsers_.getUsersUsername(uid);
02058 std::string fsmName = CgiDataUtilities::getData(cgi, "fsmName");
02059 __MOUT__ << "fsmName = " << fsmName << std::endl;
02060
02061 std::string stateMachineAliasFilter = "*";
02062
02063 std::map<std::string ,
02064 std::pair<std::string , ConfigurationGroupKey> > aliasMap =
02065 theConfigurationManager_->getGroupAliasesConfiguration();
02066
02067
02068
02069 ConfigurationTree configLinkNode = theConfigurationManager_->getSupervisorConfigurationNode(
02070 supervisorContextUID_, supervisorApplicationUID_);
02071
02072 if(!configLinkNode.isDisconnected())
02073 {
02074 try
02075 {
02076 ConfigurationTree fsmLinkNode = configLinkNode.getNode("LinkToStateMachineConfiguration");
02077 if(!fsmLinkNode.isDisconnected())
02078 stateMachineAliasFilter =
02079 fsmLinkNode.getNode(fsmName + "/SystemAliasFilter").getValue<std::string>();
02080 else
02081 __MOUT_INFO__ << "FSM Link disconnected." << std::endl;
02082 }
02083 catch(std::runtime_error &e) { __MOUT_INFO__ << e.what() << std::endl; }
02084 catch(...) { __MOUT_ERR__ << "Unknown error. Should never happen." << std::endl; }
02085 }
02086 else
02087 __MOUT_INFO__ << "FSM Link disconnected." << std::endl;
02088
02089 __MOUT__ << "stateMachineAliasFilter = " << stateMachineAliasFilter << std::endl;
02090
02091
02092
02093
02094
02095 {
02096 bool invertFilter = stateMachineAliasFilter.size() && stateMachineAliasFilter[0] == '!';
02097 std::vector<std::string> filterArr;
02098
02099 size_t i = 0;
02100 if(invertFilter) ++i;
02101 size_t f;
02102 std::string tmp;
02103 while((f = stateMachineAliasFilter.find('*',i)) != std::string::npos)
02104 {
02105 tmp = stateMachineAliasFilter.substr(i,f-i);
02106 i = f+1;
02107 filterArr.push_back(tmp);
02108
02109
02110
02111 }
02112 if(i <= stateMachineAliasFilter.size())
02113 {
02114 tmp = stateMachineAliasFilter.substr(i);
02115 filterArr.push_back(tmp);
02116
02117 }
02118
02119
02120 bool filterMatch;
02121
02122
02123 for(auto& aliasMapPair : aliasMap)
02124 {
02125
02126
02127 filterMatch = true;
02128
02129 if(filterArr.size() == 1)
02130 {
02131 if(filterArr[0] != "" &&
02132 filterArr[0] != "*" &&
02133 aliasMapPair.first != filterArr[0])
02134 filterMatch = false;
02135 }
02136 else
02137 {
02138 i = -1;
02139 for(f=0;f<filterArr.size();++f)
02140 {
02141 if(!filterArr[f].size()) continue;
02142
02143 if(f == 0)
02144 {
02145 if((i = aliasMapPair.first.find(filterArr[f])) != 0)
02146 {
02147 filterMatch = false;
02148 break;
02149 }
02150 }
02151 else if(f == filterArr.size()-1)
02152 {
02153 if(aliasMapPair.first.rfind(filterArr[f]) !=
02154 aliasMapPair.first.size() - filterArr[f].size())
02155 {
02156 filterMatch = false;
02157 break;
02158 }
02159 }
02160 else if((i = aliasMapPair.first.find(filterArr[f])) ==
02161 std::string::npos)
02162 {
02163 filterMatch = false;
02164 break;
02165 }
02166 }
02167 }
02168
02169 if(invertFilter) filterMatch = !filterMatch;
02170
02171
02172
02173 if(!filterMatch) continue;
02174
02175 xmldoc.addTextElementToData("config_alias", aliasMapPair.first);
02176 xmldoc.addTextElementToData("config_key",
02177 ConfigurationGroupKey::getFullGroupString(aliasMapPair.second.first,
02178 aliasMapPair.second.second).c_str());
02179
02180 std::string groupComment, groupAuthor, groupCreationTime;
02181 try
02182 {
02183 theConfigurationManager_->loadConfigurationGroup(
02184 aliasMapPair.second.first,aliasMapPair.second.second,
02185 false,0,0,
02186 &groupComment, &groupAuthor, &groupCreationTime, false );
02187
02188 xmldoc.addTextElementToData("config_comment", groupComment);
02189 xmldoc.addTextElementToData("config_author", groupAuthor);
02190 xmldoc.addTextElementToData("config_create_time", groupCreationTime);
02191 }
02192 catch(...)
02193 {
02194 __MOUT_WARN__ << "Failed to load group metadata." << std::endl;
02195 }
02196 }
02197 }
02198
02199
02200 std::string fn = FSM_LAST_GROUP_ALIAS_PATH + FSM_LAST_GROUP_ALIAS_FILE_START +
02201 username + "." + FSM_USERS_PREFERENCES_FILETYPE;
02202 __MOUT__ << "Load preferences: " << fn << std::endl;
02203 FILE *fp = fopen(fn.c_str(),"r");
02204 if(fp)
02205 {
02206 char tmpLastAlias[500];
02207 fscanf(fp,"%*s %s",tmpLastAlias);
02208 __MOUT__ << "tmpLastAlias: " << tmpLastAlias << std::endl;
02209
02210 xmldoc.addTextElementToData("UserLastConfigAlias",tmpLastAlias);
02211 fclose(fp);
02212 }
02213 }
02214 else if (Command == "getFecList")
02215 {
02216 xmldoc.addTextElementToData("fec_list", "");
02217
02218 for (unsigned int i = 0; i< theSupervisorDescriptorInfo_.getFEDescriptors().size(); ++i)
02219 {
02220 xmldoc.addTextElementToParent("fec_url",
02221 theSupervisorDescriptorInfo_.getFEURL(i), "fec_list");
02222 xmldoc.addTextElementToParent(
02223 "fec_urn",
02224 theSupervisorDescriptorInfo_.getFEDescriptor(i)->getURN(),
02225 "fec_list");
02226 }
02227 }
02228 else if (Command == "getSystemMessages")
02229 {
02230 xmldoc.addTextElementToData("systemMessages",
02231 theSysMessenger_.getSysMsg(
02232 theWebUsers_.getUsersDisplayName(uid)));
02233
02234 xmldoc.addTextElementToData("username_with_lock",
02235 theWebUsers_.getUserWithLock());
02236
02237
02238 }
02239 else if (Command == "setUserWithLock")
02240 {
02241 std::string username = CgiDataUtilities::postData(cgi, "username");
02242 std::string lock = CgiDataUtilities::postData(cgi, "lock");
02243 std::string accounts = CgiDataUtilities::getData(cgi, "accounts");
02244
02245 __MOUT__ << Command << std::endl;
02246 __MOUT__ << "username " << username << std::endl;
02247 __MOUT__ << "lock " << lock << std::endl;
02248 __MOUT__ << "accounts " << accounts << std::endl;
02249 __MOUT__ << "uid " << uid << std::endl;
02250
02251 std::string tmpUserWithLock = theWebUsers_.getUserWithLock();
02252 if(!theWebUsers_.setUserWithLock(uid, lock == "1", username))
02253 xmldoc.addTextElementToData("server_alert",
02254 std::string("Set user lock action failed. You must have valid permissions and ") +
02255 "locking user must be currently logged in.");
02256
02257 theWebUsers_.insertSettingsForUser(uid, &xmldoc, accounts == "1");
02258
02259 if (tmpUserWithLock != theWebUsers_.getUserWithLock())
02260 theSysMessenger_.addSysMsg("*", theWebUsers_.getUserWithLock()
02261 == "" ? tmpUserWithLock + " has unlocked ots."
02262 : theWebUsers_.getUserWithLock()
02263 + " has locked ots.");
02264 }
02265 else if (Command == "getStateMachine")
02266 {
02267
02268 std::vector<toolbox::fsm::State> states;
02269 states = theStateMachine_.getStates();
02270 char stateStr[2];
02271 stateStr[1] = '\0';
02272 std::string transName;
02273 std::string transParameter;
02274 for (unsigned int i = 0; i < states.size(); ++i)
02275 {
02276 stateStr[0] = states[i];
02277 DOMElement* stateParent = xmldoc.addTextElementToData("state", stateStr);
02278
02279 xmldoc.addTextElementToParent("state_name", theStateMachine_.getStateName(states[i]), stateParent);
02280
02281
02282
02283
02284 std::map<std::string, toolbox::fsm::State, std::less<std::string> >
02285 trans = theStateMachine_.getTransitions(states[i]);
02286 std::set<std::string> actionNames = theStateMachine_.getInputs(states[i]);
02287
02288 std::map<std::string, toolbox::fsm::State, std::less<std::string> >::iterator
02289 it = trans.begin();
02290 std::set<std::string>::iterator ait = actionNames.begin();
02291 for (; it != trans.end() && ait != actionNames.end(); ++it, ++ait)
02292 {
02293
02294
02295 stateStr[0] = it->second;
02296 xmldoc.addTextElementToParent("state_transition", stateStr, stateParent);
02297
02298
02299
02300 xmldoc.addTextElementToParent("state_transition_action", *ait, stateParent);
02301
02302 transName = theStateMachine_.getTransitionName(states[i], *ait);
02303
02304
02305 xmldoc.addTextElementToParent("state_transition_name",
02306 transName, stateParent);
02307 transParameter = theStateMachine_.getTransitionParameter(states[i], *ait);
02308
02309
02310 xmldoc.addTextElementToParent("state_transition_parameter", transParameter, stateParent);
02311 }
02312 }
02313
02314 }
02315 else if (Command == "getCurrentState")
02316 {
02317 xmldoc.addTextElementToData("current_state", theStateMachine_.getCurrentStateName());
02318 xmldoc.addTextElementToData("in_transition", theStateMachine_.isInTransition() ? "1" : "0");
02319 if (theStateMachine_.isInTransition())
02320 xmldoc.addTextElementToData("transition_progress", theProgressBar_.readPercentageString());
02321 else
02322 xmldoc.addTextElementToData("transition_progress", "100");
02323
02324
02325 char tmp[20];
02326 sprintf(tmp,"%lu",theStateMachine_.getTimeInState());
02327 xmldoc.addTextElementToData("time_in_state", tmp);
02328
02329
02330
02331
02332
02333
02335 std::string fsmName = CgiDataUtilities::getData(cgi, "fsmName");
02336
02337
02338
02339
02340
02341
02342
02343 if(!theStateMachine_.isInTransition())
02344 {
02345 std::string stateMachineRunAlias = "Run";
02346
02347
02348 ConfigurationTree configLinkNode = theConfigurationManager_->getSupervisorConfigurationNode(
02349 supervisorContextUID_, supervisorApplicationUID_);
02350
02351 if(!configLinkNode.isDisconnected())
02352 {
02353 try
02354 {
02355 ConfigurationTree fsmLinkNode = configLinkNode.getNode("LinkToStateMachineConfiguration");
02356 if(!fsmLinkNode.isDisconnected())
02357 stateMachineRunAlias =
02358 fsmLinkNode.getNode(fsmName + "/RunDisplayAlias").getValue<std::string>();
02359
02360
02361 }
02362 catch(std::runtime_error &e) { __MOUT_INFO__ << e.what() << std::endl; }
02363 catch(...) { __MOUT_ERR__ << "Unknown error. Should never happen." << std::endl; }
02364 }
02365
02366
02367
02368
02369
02370 xmldoc.addTextElementToData("stateMachineRunAlias", stateMachineRunAlias);
02372
02373
02374
02375 if(theStateMachine_.getCurrentStateName() == "Running" ||
02376 theStateMachine_.getCurrentStateName() == "Paused")
02377 sprintf(tmp,"Current %s Number: %u",stateMachineRunAlias.c_str(),getNextRunNumber(activeStateMachineName_)-1);
02378 else
02379 sprintf(tmp,"Next %s Number: %u",stateMachineRunAlias.c_str(),getNextRunNumber(fsmName));
02380 xmldoc.addTextElementToData("run_number", tmp);
02381 }
02382 }
02383 else if(Command == "getErrorInStateMatchine")
02384 {
02385 xmldoc.addTextElementToData("FSM_Error", theStateMachine_.getErrorMessage());
02386 }
02387 else if(Command == "getDesktopIcons")
02388 {
02389
02390 std::string iconFileName = ICON_FILE_NAME;
02391 std::ifstream iconFile;
02392 std::string iconList = "";
02393 std::string line;
02394 iconFile.open(iconFileName.c_str());
02395
02396 if(!iconFile)
02397 {
02398 __MOUT__ << "Error opening file: "<< iconFileName << std::endl;
02399 system("pause");
02400 return;
02401 }
02402 if(iconFile.is_open())
02403 {
02404 __MOUT__ << "Opened File: " << iconFileName << std::endl;
02405 while(std::getline(iconFile, line))
02406 {
02407 iconList = line;
02408 }
02409 __MOUT__ << iconList << std::endl;
02410
02411
02412 iconFile.close();
02413 }
02414 xmldoc.addTextElementToData("iconList", iconList);
02415
02416 }
02417 else if(Command == "launchConfig")
02418 {
02419 if(userPermissions != 255)
02420 {
02421 __MOUT__ << "Insufficient Permissions" << std::endl;
02422 }
02423 else
02424 {
02425 __MOUT__ << "Self-destruct." << std::endl;
02426
02427
02428 }
02429 }
02430 else if(Command == "resetUserTooltips")
02431 {
02432 WebUsers::resetAllUserTooltips(theWebUsers_.getUsersUsername(uid));
02433 }
02434 else
02435 __MOUT__ << "Command Request, " << Command << ", not recognized." << std::endl;
02436
02437
02438
02439
02440 xmldoc.outputXmlDocument((std::ostringstream*) out, false, true);
02441
02442
02443 }
02444
02445
02446
02447
02448 xoap::MessageReference Supervisor::supervisorGetUserInfo(
02449 xoap::MessageReference message)
02450 throw (xoap::exception::Exception)
02451 {
02452 SOAPParameters parameters;
02453 parameters.addParameter("CookieCode");
02454 receive(message, parameters);
02455 std::string cookieCode = parameters.getValue("CookieCode");
02456
02457 std::string username, displayName;
02458 uint64_t activeSessionIndex;
02459
02460 theWebUsers_.getUserInfoForCookie(cookieCode, &username, &displayName,
02461 &activeSessionIndex);
02462
02463
02464
02465
02466
02467 SOAPParameters retParameters;
02468 retParameters.addParameter("Username", username);
02469 retParameters.addParameter("DisplayName", displayName);
02470 char tmpStr[100];
02471 sprintf(tmpStr, "%lu", activeSessionIndex);
02472 retParameters.addParameter("ActiveSessionIndex", tmpStr);
02473
02474 return SOAPUtilities::makeSOAPMessageReference("UserInfoResponse",
02475 retParameters);
02476 }
02477
02478
02479
02480
02481 xoap::MessageReference Supervisor::supervisorCookieCheck(xoap::MessageReference message)
02482 throw (xoap::exception::Exception)
02483 {
02484
02485
02486
02487 SOAPParameters parameters;
02488 parameters.addParameter("CookieCode");
02489 parameters.addParameter("RefreshOption");
02490 receive(message, parameters);
02491 std::string cookieCode = parameters.getValue("CookieCode");
02492 std::string refreshOption = parameters.getValue("RefreshOption");
02493
02494
02495
02496 uint8_t userPermissions = 0;
02497 std::string userWithLock = "";
02498 theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions, 0,
02499 "0", refreshOption == "1", &userWithLock);
02500
02501
02502
02503
02504 SOAPParameters retParameters;
02505 retParameters.addParameter("CookieCode", cookieCode);
02506 char tmp[5];
02507 sprintf(tmp, "%d", userPermissions);
02508 retParameters.addParameter("Permissions", tmp);
02509 retParameters.addParameter("UserWithLock", userWithLock);
02510
02511
02512
02513 return SOAPUtilities::makeSOAPMessageReference("CookieResponse",
02514 retParameters);
02515 }
02516
02517
02518
02519
02520 xoap::MessageReference Supervisor::supervisorGetActiveUsers(
02521 xoap::MessageReference message)
02522 throw (xoap::exception::Exception)
02523 {
02524 __MOUT__ << std::endl;
02525
02526 SOAPParameters
02527 parameters("UserList", theWebUsers_.getActiveUsersString());
02528 return SOAPUtilities::makeSOAPMessageReference("ActiveUserResponse",
02529 parameters);
02530 }
02531
02532
02533
02534
02535
02536 xoap::MessageReference Supervisor::supervisorSystemMessage(
02537 xoap::MessageReference message)
02538 throw (xoap::exception::Exception)
02539 {
02540 SOAPParameters parameters;
02541 parameters.addParameter("ToUser");
02542 parameters.addParameter("Message");
02543 receive(message, parameters);
02544
02545 __MOUT__ << "toUser: " << parameters.getValue("ToUser").substr(
02546 0, 10) << ", message: " << parameters.getValue("Message").substr(0,
02547 10) << std::endl;
02548
02549 theSysMessenger_.addSysMsg(parameters.getValue("ToUser"),
02550 parameters.getValue("Message"));
02551 return SOAPUtilities::makeSOAPMessageReference("SystemMessageResponse");
02552 }
02553
02554
02555
02556
02557
02558 xoap::MessageReference Supervisor::supervisorSystemLogbookEntry(
02559 xoap::MessageReference message)
02560 throw (xoap::exception::Exception)
02561 {
02562 SOAPParameters parameters;
02563 parameters.addParameter("EntryText");
02564 receive(message, parameters);
02565
02566 __MOUT__ << "EntryText: " << parameters.getValue("EntryText").substr(
02567 0, 10) << std::endl;
02568
02569 makeSystemLogbookEntry(parameters.getValue("EntryText"));
02570
02571 return SOAPUtilities::makeSOAPMessageReference("SystemLogbookResponse");
02572 }
02573
02574
02575
02576
02577
02578
02579 xoap::MessageReference Supervisor::supervisorLastConfigGroupRequest(
02580 xoap::MessageReference message)
02581 throw (xoap::exception::Exception)
02582 {
02583 SOAPParameters parameters;
02584 parameters.addParameter("ActionOfLastGroup");
02585 receive(message, parameters);
02586
02587 return Supervisor::lastConfigGroupRequestHandler(parameters);
02588 }
02589
02590
02591
02592
02593
02594
02595
02596 xoap::MessageReference Supervisor::lastConfigGroupRequestHandler(
02597 const SOAPParameters ¶meters)
02598 {
02599 std::string action = parameters.getValue("ActionOfLastGroup");
02600 __MOUT__ << "ActionOfLastGroup: " << action.substr(
02601 0, 10) << std::endl;
02602
02603 std::string fileName = "";
02604 if(action == "Configured")
02605 fileName = FSM_LAST_CONFIGURED_GROUP_ALIAS_FILE;
02606 else if(action == "Started")
02607 fileName = FSM_LAST_STARTED_GROUP_ALIAS_FILE;
02608 else
02609 {
02610 __MOUT_ERR__ << "Invalid last group action requested." << std::endl;
02611 return SOAPUtilities::makeSOAPMessageReference("LastConfigGroupResponseFailure");
02612 }
02613 std::string timeString;
02614 std::pair<std::string , ConfigurationGroupKey> theGroup =
02615 loadGroupNameAndKey(fileName,timeString);
02616
02617
02618 SOAPParameters retParameters;
02619 retParameters.addParameter("GroupName", theGroup.first);
02620 retParameters.addParameter("GroupKey", theGroup.second.toString());
02621 retParameters.addParameter("GroupAction", action);
02622 retParameters.addParameter("GroupActionTime", timeString);
02623
02624
02625 return SOAPUtilities::makeSOAPMessageReference("LastConfigGroupResponse",
02626 retParameters);
02627 }
02628
02629
02630
02631
02632
02633
02634
02635
02636 unsigned int Supervisor::getNextRunNumber(const std::string &fsmNameIn)
02637 {
02638 std::string runNumberFileName = RUN_NUMBER_PATH + "/";
02639 std::string fsmName = fsmNameIn == ""?activeStateMachineName_:fsmNameIn;
02640
02641 for(unsigned int i=0;i<fsmName.size();++i)
02642 if( (fsmName[i] >= 'a' && fsmName[i] <= 'z') ||
02643 (fsmName[i] >= 'A' && fsmName[i] <= 'Z') ||
02644 (fsmName[i] >= '0' && fsmName[i] <= '9'))
02645 runNumberFileName += fsmName[i];
02646 runNumberFileName += RUN_NUMBER_FILE_NAME;
02647
02648
02649 std::ifstream runNumberFile(runNumberFileName.c_str());
02650 if (!runNumberFile.is_open())
02651 {
02652 __MOUT__ << "Can't open file: " << runNumberFileName << std::endl;
02653
02654 __MOUT__ << "Creating file and setting Run Number to 1: " << runNumberFileName << std::endl;
02655 FILE *fp = fopen(runNumberFileName.c_str(),"w");
02656 fprintf(fp,"1");
02657 fclose(fp);
02658
02659 runNumberFile.open(runNumberFileName.c_str());
02660 if(!runNumberFile.is_open())
02661 {
02662 __MOUT__ << "Can't create file: " << runNumberFileName << std::endl;
02663 throw std::runtime_error("Error.");
02664 }
02665 }
02666 std::string runNumberString;
02667 runNumberFile >> runNumberString;
02668 runNumberFile.close();
02669 return atoi(runNumberString.c_str());
02670 }
02671
02672
02673 bool Supervisor::setNextRunNumber(unsigned int runNumber, const std::string &fsmNameIn)
02674 {
02675 std::string runNumberFileName = RUN_NUMBER_PATH + "/";
02676 std::string fsmName = fsmNameIn == ""?activeStateMachineName_:fsmNameIn;
02677
02678 for(unsigned int i=0;i<fsmName.size();++i)
02679 if( (fsmName[i] >= 'a' && fsmName[i] <= 'z') ||
02680 (fsmName[i] >= 'A' && fsmName[i] <= 'Z') ||
02681 (fsmName[i] >= '0' && fsmName[i] <= '9'))
02682 runNumberFileName += fsmName[i];
02683 runNumberFileName += RUN_NUMBER_FILE_NAME;
02684 __MOUT__ << "runNumberFileName: " << runNumberFileName << std::endl;
02685
02686 std::ofstream runNumberFile(runNumberFileName.c_str());
02687 if (!runNumberFile.is_open())
02688 {
02689 __MOUT__ << "Can't open file: " << runNumberFileName << std::endl;
02690 throw std::runtime_error("Error.");
02691 }
02692 std::stringstream runNumberStream;
02693 runNumberStream << runNumber;
02694 runNumberFile << runNumberStream.str().c_str();
02695 runNumberFile.close();
02696 return true;
02697 }
02698
02699
02700
02701
02702
02703
02704
02705 std::pair<std::string ,
02706 ConfigurationGroupKey> Supervisor::loadGroupNameAndKey(const std::string &fileName,
02707 std::string &returnedTimeString)
02708 {
02709 std::string fullPath = FSM_LAST_GROUP_ALIAS_PATH + "/" + fileName;
02710
02711 FILE *groupFile = fopen(fullPath.c_str(),"r");
02712 if (!groupFile)
02713 {
02714 __MOUT__ << "Can't open file: " << fullPath << std::endl;
02715
02716 __MOUT__ << "Returning empty groupName and key -1" << std::endl;
02717
02718 return std::pair<std::string ,
02719 ConfigurationGroupKey>("",ConfigurationGroupKey());
02720 }
02721
02722 char line[500];
02723
02724 std::pair<std::string ,
02725 ConfigurationGroupKey> theGroup;
02726
02727 fgets(line,500,groupFile);
02728 theGroup.first = line;
02729
02730 fgets(line,500,groupFile);
02731 int key;
02732 sscanf(line,"%d",&key);
02733 theGroup.second = key;
02734
02735 fgets(line,500,groupFile);
02736 time_t timestamp;
02737 sscanf(line,"%ld",×tamp);
02738 struct tm tmstruct;
02739 ::localtime_r(×tamp, &tmstruct);
02740 ::strftime(line, 30, "%c %Z", &tmstruct);
02741 returnedTimeString = line;
02742 fclose(groupFile);
02743
02744
02745 __MOUT__ << "theGroup.first= " << theGroup.first <<
02746 " theGroup.second= " << theGroup.second << std::endl;
02747
02748 return theGroup;
02749 }
02750
02751
02752 void Supervisor::saveGroupNameAndKey(const std::pair<std::string ,
02753 ConfigurationGroupKey> &theGroup,
02754 const std::string &fileName)
02755 {
02756 std::string fullPath = FSM_LAST_GROUP_ALIAS_PATH + "/" + fileName;
02757
02758 std::ofstream groupFile(fullPath.c_str());
02759 if (!groupFile.is_open())
02760 {
02761 __SS__ << "Can't open file: " << fullPath << std::endl;
02762 __MOUT_ERR__ << "\n" << ss.str();
02763 throw std::runtime_error("Error.\n" + ss.str());
02764 }
02765 std::stringstream outss;
02766 outss << theGroup.first << "\n" << theGroup.second << "\n" << time(0);
02767 groupFile << outss.str().c_str();
02768 groupFile.close();
02769 }
02770
02771
02772
02774
02775
02778
02779
02780
02781
02782
02783
02784
02785
02786
02787
02788
02789
02790
02791
02792
02793
02794
02795
02796
02797
02798
02799
02800
02801
02802
02803
02804