1 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
2 #include "otsdaq-core/ConfigurationInterface/ConfigurationInterface.h"
3 #include "otsdaq-core/ConfigurationDataFormats/ConfigurationGroupKey.h"
4 #include "otsdaq-core/ProgressBar/ProgressBar.h"
13 #define __MF_SUBJECT__ "ConfigurationManager"
15 const std::string ConfigurationManager::READONLY_USER =
"READONLY_USER";
17 const std::string ConfigurationManager::XDAQ_CONTEXT_CONFIG_NAME =
"XDAQContextConfiguration";
20 const std::string ConfigurationManager::ACTIVE_GROUP_FILENAME = ((getenv(
"SERVICE_DATA_PATH") == NULL)?(std::string(getenv(
"USER_DATA"))+
"/ServiceData"):(std::string(getenv(
"SERVICE_DATA_PATH")))) +
"/ActiveConfigurationGroups.cfg";
21 const std::string ConfigurationManager::ALIAS_VERSION_PREAMBLE =
"ALIAS:";
22 const std::string ConfigurationManager::SCRATCH_VERSION_ALIAS =
"Scratch";
24 #define CORE_TABLE_INFO_FILENAME ((getenv("SERVICE_DATA_PATH") == NULL)?(std::string(getenv("USER_DATA"))+"/ServiceData"):(std::string(getenv("SERVICE_DATA_PATH")))) + "/CoreTableInfoNames.dat"
27 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT =
"Context";
28 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE =
"Backbone";
29 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION =
"Configuration";
33 ConfigurationManager::ConfigurationManager()
36 , theConfigurationGroupKey_ (0)
37 , theContextGroupKey_ (0)
38 , theBackboneGroupKey_ (0)
39 , theConfigurationGroup_ (
"")
40 , theContextGroup_ (
"")
41 , theBackboneGroup_ (
"")
42 , contextMemberNames_ ({XDAQ_CONTEXT_CONFIG_NAME,
"XDAQApplicationConfiguration",
"DesktopIconConfiguration",
"MessageFacilityConfiguration",
"TheSupervisorConfiguration",
"StateMachineConfiguration",
"DesktopWindowParameterConfiguration"})
43 , backboneMemberNames_ ({
"GroupAliasesConfiguration",
"VersionAliasesConfiguration"})
45 theInterface_ = ConfigurationInterface::getInstance(
false);
59 groupMetadataTable_.setConfigurationName(ConfigurationInterface::GROUP_METADATA_TABLE_NAME);
61 std::vector<ViewColumnInfo>* colInfo =
62 groupMetadataTable_.getMockupViewP()->getColumnsInfoP();
66 ViewColumnInfo::TYPE_UID,
69 ViewColumnInfo::DATATYPE_NUMBER,
73 ViewColumnInfo::TYPE_COMMENT,
75 "COMMENT_DESCRIPTION",
76 ViewColumnInfo::DATATYPE_STRING,
80 ViewColumnInfo::TYPE_AUTHOR,
83 ViewColumnInfo::DATATYPE_STRING,
87 ViewColumnInfo::TYPE_TIMESTAMP,
89 "GROUP_CREATION_TIME",
90 ViewColumnInfo::DATATYPE_TIME,
93 auto tmpVersion = groupMetadataTable_.createTemporaryView();
94 groupMetadataTable_.setActiveView(tmpVersion);
96 groupMetadataTable_.getViewP()->addRow();
101 FILE * fp = fopen((CORE_TABLE_INFO_FILENAME).c_str(),
"w");
104 for(
const auto &name:contextMemberNames_)
105 fprintf(fp,
"%s\n",name.c_str());
106 for(
const auto &name:backboneMemberNames_)
107 fprintf(fp,
"%s\n",name.c_str());
111 __MOUT__ <<
"Failed to open core table info file: " << CORE_TABLE_INFO_FILENAME << std::endl;
118 ConfigurationManager::ConfigurationManager(
const std::string& username)
121 username_ = username;
125 ConfigurationManager::~ConfigurationManager()
134 void ConfigurationManager::init(std::string *accumulatedErrors)
136 if(accumulatedErrors) *accumulatedErrors =
"";
141 if(theInterface_->getMode() ==
false)
145 restoreActiveConfigurationGroups(accumulatedErrors?
true:
false);
147 catch(std::runtime_error &e)
149 if(accumulatedErrors) *accumulatedErrors = e.what();
160 void ConfigurationManager::restoreActiveConfigurationGroups(
bool throwErrors)
162 destroyConfigurationGroup(
"",
true);
164 std::string fn = ACTIVE_GROUP_FILENAME;
165 FILE *fp = fopen(fn.c_str(),
"r");
167 __MOUT__ <<
"ACTIVE_GROUP_FILENAME = " << ACTIVE_GROUP_FILENAME << std::endl;
168 __MOUT__ <<
"ARTDAQ_DATABASE_URI = " << std::string(getenv(
"ARTDAQ_DATABASE_URI")) << std::endl;
172 __MOUT__ <<
"throwErrors: " << throwErrors << std::endl;
177 std::string groupName;
178 std::string errorStr =
"";
187 sscanf(tmp,
"%s",strVal);
188 for(
unsigned int j=0;j<strlen(strVal);++j)
190 (strVal[j] >=
'a' && strVal[j] <=
'z') ||
191 (strVal[j] >=
'A' && strVal[j] <=
'Z') ||
192 (strVal[j] >=
'0' && strVal[j] <=
'9')))
195 __MOUT_INFO__ <<
"Illegal character found, so skipping!" << std::endl;
205 sscanf(tmp,
"%s",strVal);
207 for(
unsigned int j=0;j<strlen(strVal);++j)
209 (strVal[j] >=
'0' && strVal[j] <=
'9')))
212 __MOUT_INFO__ <<
"Illegal character found, so skipping!" << std::endl;
225 catch(std::runtime_error &e)
227 ss <<
"Failed to load config group in ConfigurationManager::init() with name '" <<
228 groupName <<
"_v" << strVal <<
"'" << std::endl;
229 ss << e.what() << std::endl;
231 errorStr += ss.str();
235 ss <<
"Failed to load config group in ConfigurationManager::init() with name '" <<
236 groupName <<
"_v" << strVal <<
"'" << std::endl;
238 errorStr += ss.str();
244 if(throwErrors && errorStr !=
"")
246 __MOUT_INFO__ <<
"\n" << ss.str();
247 throw std::runtime_error(errorStr);
256 void ConfigurationManager::destroyConfigurationGroup(
const std::string& theGroup,
bool onlyDeactivate)
259 bool isContext = theGroup ==
"" || theGroup == theContextGroup_;
260 bool isBackbone = theGroup ==
"" || theGroup == theBackboneGroup_;
261 bool isConfiguration = theGroup ==
"" || theGroup == theConfigurationGroup_;
263 if(!isContext && !isBackbone && !isConfiguration)
265 __MOUT__ <<
"Invalid configuration group to destroy: " << theGroup << std::endl;
266 throw std::runtime_error(
"Invalid configuration group to destroy!");
269 std::string dbgHeader = onlyDeactivate?
"Deactivating":
"Destroying";
273 __MOUT__ << dbgHeader <<
" Context group: " << theGroup << std::endl;
275 __MOUT__ << dbgHeader <<
" Backbone group: " << theGroup << std::endl;
277 __MOUT__ << dbgHeader <<
" Configuration group: " << theGroup << std::endl;
280 std::set<std::string>::const_iterator contextFindIt, backboneFindIt;
281 for(
auto it = nameToConfigurationMap_.begin(); it != nameToConfigurationMap_.end(); )
283 contextFindIt = contextMemberNames_.find(it->first);
284 backboneFindIt = backboneMemberNames_.find(it->first);
285 if(theGroup ==
"" || ( (isContext && contextFindIt != contextMemberNames_.end()) ||
286 (isBackbone && backboneFindIt != backboneMemberNames_.end()) ||
287 (!isContext && !isBackbone &&
288 contextFindIt == contextMemberNames_.end() &&
289 backboneFindIt == backboneMemberNames_.end())))
298 it->second->deactivate();
304 nameToConfigurationMap_.erase(it++);
313 theConfigurationGroup_ =
"";
314 if(theConfigurationGroupKey_ != 0)
316 __MOUT__ <<
"Destroying Configuration Key: " << *theConfigurationGroupKey_ << std::endl;
317 theConfigurationGroupKey_.reset();
324 theBackboneGroup_ =
"";
325 if(theBackboneGroupKey_ != 0)
327 __MOUT__ <<
"Destroying Backbone Key: " << *theBackboneGroupKey_ << std::endl;
328 theBackboneGroupKey_.reset();
333 theContextGroup_ =
"";
334 if(theContextGroupKey_ != 0)
336 __MOUT__ <<
"Destroying Context Key: " << *theContextGroupKey_ << std::endl;
337 theContextGroupKey_.reset();
343 void ConfigurationManager::destroy(
void)
348 destroyConfigurationGroup();
358 const std::string& ConfigurationManager::convertGroupTypeIdToName(
int groupTypeId)
360 return groupTypeId==CONTEXT_TYPE?
361 ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT:
362 (groupTypeId==BACKBONE_TYPE?
363 ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE:
364 ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION);
373 int ConfigurationManager::getTypeOfGroup(
374 const std::map<std::string /*name*/, ConfigurationVersion /*version*/> &memberMap)
377 bool isContext =
true;
378 bool isBackbone =
true;
380 bool inContext =
false;
381 bool inBackbone =
false;
382 unsigned int matchCount = 0;
384 for(
auto &memberPair:memberMap)
388 for(
auto &contextMemberString:contextMemberNames_)
389 if(memberPair.first == contextMemberString)
401 __SS__ <<
"This group is an incomplete match to a Context group.\n";
402 ss <<
"\nTo be a Context group, the members must exactly match" <<
403 "the following members:\n";
405 for(
auto &memberName:contextMemberNames_)
406 ss << ++i <<
". " << memberName <<
"\n";
407 __MOUT_ERR__ <<
"\n" << ss.str();
408 throw std::runtime_error(ss.str());
413 for(
auto &backboneMemberString:backboneMemberNames_)
414 if(memberPair.first == backboneMemberString)
426 __SS__ <<
"This group is an incomplete match to a Backbone group.\n";
427 ss <<
"\nTo be a Backbone group, the members must exactly match" <<
428 "the following members:\n";
430 for(
auto &memberName:backboneMemberNames_)
431 ss << ++i <<
". " << memberName <<
"\n";
432 __MOUT_ERR__ <<
"\n" << ss.str();
433 throw std::runtime_error(ss.str());
439 if(isContext && matchCount != contextMemberNames_.size())
441 __SS__ <<
"This group is an incomplete match to a Context group: " <<
442 " Size=" << matchCount <<
" but should be " << contextMemberNames_.size() <<
444 ss <<
"\nThe members currently are...\n";
446 for(
auto &memberPair:memberMap)
447 ss << ++i <<
". " << memberPair.first <<
"\n";
448 ss <<
"\nThe expected Context members are...\n";
450 for(
auto &memberName:contextMemberNames_)
451 ss << ++i <<
". " << memberName <<
"\n";
452 __MOUT_ERR__ <<
"\n" << ss.str();
453 throw std::runtime_error(ss.str());
456 if(isBackbone && matchCount != backboneMemberNames_.size())
458 __SS__ <<
"This group is an incomplete match to a Backbone group: " <<
459 " Size=" << matchCount <<
" but should be " << backboneMemberNames_.size() <<
461 ss <<
"\nThe members currently are...\n";
463 for(
auto &memberPair:memberMap)
464 ss << ++i <<
". " << memberPair.first <<
"\n";
465 ss <<
"\nThe expected Backbone members are...\n";
467 for(
auto &memberName:backboneMemberNames_)
468 ss << ++i <<
". " << memberName <<
"\n";
469 __MOUT_ERR__ <<
"\n" << ss.str();
470 throw std::runtime_error(ss.str());
473 return isContext?CONTEXT_TYPE:(isBackbone?BACKBONE_TYPE:CONFIGURATION_TYPE);
482 const std::string& ConfigurationManager::getTypeNameOfGroup(
483 const std::map<std::string /*name*/, ConfigurationVersion /*version*/> &memberMap)
485 return convertGroupTypeIdToName(getTypeOfGroup(memberMap));
491 void ConfigurationManager::dumpActiveConfiguration(
492 const std::string &filePath,
const std::string &dumpType)
const
494 time_t rawtime = time(0);
495 __MOUT__ <<
"filePath = " << filePath << std::endl;
496 __MOUT__ <<
"dumpType = " << dumpType << std::endl;
500 fs.open(filePath, std::fstream::out | std::fstream::trunc);
511 (*out) <<
"#################################" << std::endl;
512 (*out) <<
"This is an ots configuration dump.\n\n" << std::endl;
513 (*out) <<
"Source database is $ARTDAQ_DATABASE_URI = \t" << getenv(
"ARTDAQ_DATABASE_URI") << std::endl;
514 (*out) <<
"\nOriginal location of dump: \t" << filePath << std::endl;
515 (*out) <<
"Type of dump: \t" << dumpType << std::endl;
516 (*out) <<
"Linux time for dump: \t" << rawtime << std::endl;
519 struct tm * timeinfo = localtime (&rawtime);
521 strftime(buffer,100,
"%c %Z",timeinfo);
522 (*out) <<
"Display time for dump: \t" << buffer << std::endl;
533 std::map<std::string, std::pair<std::string, ConfigurationGroupKey>> activeGroups =
534 cfgMgr->getActiveConfigurationGroups();
536 (*out) <<
"\n\n************************" << std::endl;
537 (*out) <<
"Active Groups:" << std::endl;
538 for(
auto &group:activeGroups)
540 (*out) <<
"\t" << group.first <<
" := " <<
541 group.second.first <<
" (" <<
542 group.second.second <<
")" << std::endl;
547 std::map<std::string, ConfigurationVersion> activeTables =
548 cfgMgr->getActiveVersions();
550 (*out) <<
"\n\n************************" << std::endl;
551 (*out) <<
"Active Tables:" << std::endl;
552 (*out) <<
"Active Tables count = " << activeTables.size() << std::endl;
555 for(
auto &table:activeTables)
557 (*out) <<
"\t" << ++i <<
". " << table.first <<
"-v" <<
558 table.second << std::endl;
563 std::map<std::string, std::pair<std::string, ConfigurationGroupKey>> activeGroups =
564 cfgMgr->getActiveConfigurationGroups();
565 (*out) <<
"\n\n************************" << std::endl;
566 (*out) <<
"Active Group Members:" << std::endl;
568 for(
auto &group:activeGroups)
570 (*out) <<
"\t" << group.first <<
" := " <<
571 group.second.first <<
" (" <<
572 group.second.second <<
")" << std::endl;
575 cfgMgr->theInterface_->getConfigurationGroupMembers(
576 ConfigurationGroupKey::getFullGroupString(
578 group.second.second));
580 (*out) <<
"\tMember table count = " << memberMap.size() << std::endl;
581 tableCount += memberMap.size();
584 for(
auto &member:memberMap)
586 (*out) <<
"\t\t" << ++i <<
". " << member.first <<
"-v" <<
587 member.second << std::endl;
590 (*out) <<
"\nActive Group Members total table count = " << tableCount << std::endl;
594 std::map<std::string, ConfigurationVersion> activeTables =
595 cfgMgr->getActiveVersions();
597 (*out) <<
"\n\n************************" << std::endl;
598 (*out) <<
"Active Table Contents (table count = " << activeTables.size()
599 <<
"):" << std::endl;
601 for(
auto &table:activeTables)
603 (*out) <<
"\n\n==============================================================================" << std::endl;
604 (*out) <<
"==============================================================================" << std::endl;
605 (*out) <<
"\t" << ++i <<
". " << table.first <<
"-v" <<
606 table.second << std::endl;
608 cfgMgr->nameToConfigurationMap_.find(table.first)->second->print(*out);
614 if(dumpType ==
"GroupKeys")
616 localDumpActiveGroups(
this,out);
618 else if(dumpType ==
"TableVersions")
620 localDumpActiveTables(
this,out);
622 else if(dumpType ==
"GroupKeysAndTableVersions")
624 localDumpActiveGroups(
this,out);
625 localDumpActiveTables(
this,out);
627 else if(dumpType ==
"All")
629 localDumpActiveGroups(
this,out);
630 localDumpActiveGroupMembers(
this,out);
631 localDumpActiveTables(
this,out);
632 localDumpActiveTableContents(
this,out);
636 __SS__ <<
"Invalid dump type '" << dumpType <<
637 "' given during dumpActiveConfiguration(). Valid types are as follows:\n" <<
640 "GroupKeys" <<
", " <<
641 "TableVersions" <<
", " <<
642 "GroupsKeysAndTableVersions" <<
", " <<
645 "\n\nPlease change the State Machine configuration to a valid dump type." <<
647 throw std::runtime_error(ss.str());
658 void ConfigurationManager::loadMemberMap(
659 const std::map<std::string /*name*/, ConfigurationVersion /*version*/> &memberMap)
664 for(
auto &memberPair:memberMap)
674 tmpConfigBasePtr = 0;
675 if(nameToConfigurationMap_.find(memberPair.first) != nameToConfigurationMap_.end())
676 tmpConfigBasePtr = nameToConfigurationMap_[memberPair.first];
678 theInterface_->get(tmpConfigBasePtr,
687 nameToConfigurationMap_[memberPair.first] = tmpConfigBasePtr;
688 if(nameToConfigurationMap_[memberPair.first]->getViewP())
694 __SS__ << nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
695 ": View version not activated properly!";
696 throw std::runtime_error(ss.str());
716 std::map<std::string, ConfigurationVersion> ConfigurationManager::loadConfigurationGroup(
717 const std::string &configGroupName,
721 std::string *accumulatedTreeErrors,
722 std::string *groupComment,
723 std::string *groupAuthor,
724 std::string *groupCreateTime,
725 bool doNotLoadMember,
726 std::string *groupTypeString)
728 if(accumulatedTreeErrors) *accumulatedTreeErrors =
"";
729 if(groupComment) *groupComment =
"";
730 if(groupAuthor) *groupAuthor =
"";
731 if(groupCreateTime) *groupCreateTime =
"";
732 if(groupTypeString) *groupTypeString =
"";
746 __MOUT_INFO__ <<
"Loading Configuration Group: " << configGroupName <<
747 "(" << configGroupKey <<
")" << std::endl;
750 theInterface_->getConfigurationGroupMembers(
751 ConfigurationGroupKey::getFullGroupString(configGroupName,configGroupKey),
755 if(progressBar) progressBar->step();
758 auto metaTablePair = memberMap.find(groupMetadataTable_.getConfigurationName());
765 while(groupMetadataTable_.getView().getNumberOfRows())
766 groupMetadataTable_.getViewP()->deleteRow(0);
767 theInterface_->fill(&groupMetadataTable_,metaTablePair->second);
769 if(groupMetadataTable_.getView().getNumberOfRows() != 1)
771 groupMetadataTable_.print();
772 __SS__ <<
"groupMetadataTable_ has wrong number of rows! Must be 1." << std::endl;
773 __MOUT_ERR__ <<
"\n" << ss.str();
774 throw std::runtime_error(ss.str());
778 memberMap.erase(metaTablePair);
781 if(groupComment) *groupComment = groupMetadataTable_.getView().getValueAsString(0,1);
782 if(groupAuthor) *groupAuthor = groupMetadataTable_.getView().getValueAsString(0,2);
783 if(groupCreateTime) *groupCreateTime = groupMetadataTable_.getView().getValueAsString(0,3);
786 if(progressBar) progressBar->step();
790 if(doNotLoadMember)
return memberMap;
795 groupType = getTypeOfGroup(memberMap);
796 if(groupTypeString) *groupTypeString = convertGroupTypeIdToName(groupType);
800 std::string groupToDeactivate =
801 groupType==CONTEXT_TYPE?theContextGroup_:
802 (groupType==BACKBONE_TYPE?theBackboneGroup_:theConfigurationGroup_);
805 if(groupToDeactivate !=
"")
807 __MOUT__ <<
"groupToDeactivate '" << groupToDeactivate <<
"'" << std::endl;
808 destroyConfigurationGroup(groupToDeactivate,
true);
817 if(progressBar) progressBar->step();
822 loadMemberMap(memberMap);
824 if(progressBar) progressBar->step();
826 if(accumulatedTreeErrors)
828 __MOUT__ <<
"Checking chosen group for tree errors..." << std::endl;
830 getChildren(&memberMap, accumulatedTreeErrors);
831 if(*accumulatedTreeErrors !=
"")
833 __MOUT_ERR__ <<
"Errors detected while loading Configuration Group: " << configGroupName <<
834 "(" << configGroupKey <<
"). Aborting." << std::endl;
839 if(progressBar) progressBar->step();
844 for(
auto &memberPair:memberMap)
847 if(ConfigurationInterface::isVersionTrackingEnabled() &&
848 memberPair.second.isScratchVersion())
850 __SS__ <<
"Error while activating member Table '" <<
851 nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
852 "-v" << memberPair.second <<
853 " for Configuration Group '" << configGroupName <<
854 "(" << configGroupKey <<
")'. When version tracking is enabled, Scratch views" <<
855 " are not allowed! Please only use unique, persistent versions when version tracking is enabled."
857 __MOUT_ERR__ <<
"\n" << ss.str();
858 throw std::runtime_error(ss.str());
866 nameToConfigurationMap_[memberPair.first]->init(
this);
868 catch(std::runtime_error& e)
870 __SS__ <<
"Error detected calling " <<
871 nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
872 ".init()!\n\n " << e.what() << std::endl;
873 throw std::runtime_error(ss.str());
877 __SS__ <<
"Error detected calling " <<
878 nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
879 ".init()!\n\n " << std::endl;
880 throw std::runtime_error(ss.str());
885 if(progressBar) progressBar->step();
893 if(groupType == CONTEXT_TYPE)
895 __MOUT_INFO__ <<
"Context Configuration Group loaded: " << configGroupName <<
896 "(" << configGroupKey <<
")" << std::endl;
897 theContextGroup_ = configGroupName;
898 theContextGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(
new ConfigurationGroupKey(configGroupKey));
900 else if(groupType == BACKBONE_TYPE)
902 __MOUT_INFO__ <<
"Backbone Configuration Group loaded: " << configGroupName <<
903 "(" << configGroupKey <<
")" << std::endl;
904 theBackboneGroup_ = configGroupName;
905 theBackboneGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(
new ConfigurationGroupKey(configGroupKey));
909 __MOUT_INFO__ <<
"The Configuration Group loaded: " << configGroupName <<
910 "(" << configGroupKey <<
")" << std::endl;
911 theConfigurationGroup_ = configGroupName;
912 theConfigurationGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(
new ConfigurationGroupKey(configGroupKey));
916 if(progressBar) progressBar->step();
928 std::map<std::string, std::pair<std::string, ConfigurationGroupKey> > ConfigurationManager::getActiveConfigurationGroups(
void)
const
931 std::map<std::string, std::pair<std::string, ConfigurationGroupKey> > retMap;
933 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT] =
934 std::pair<std::string,ConfigurationGroupKey>(theContextGroup_ ,theContextGroupKey_ ?*theContextGroupKey_ :
ConfigurationGroupKey());
935 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE] =
936 std::pair<std::string,ConfigurationGroupKey>(theBackboneGroup_ ,theBackboneGroupKey_ ?*theBackboneGroupKey_ :
ConfigurationGroupKey());
937 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION] =
938 std::pair<std::string,ConfigurationGroupKey>(theConfigurationGroup_,theConfigurationGroupKey_?*theConfigurationGroupKey_:
ConfigurationGroupKey());
944 const std::string &contextUID,
const std::string &applicationUID)
const
947 "/" + getConfigurationByName(XDAQ_CONTEXT_CONFIG_NAME)->getConfigurationName() +
949 "/LinkToApplicationConfiguration/" + applicationUID +
950 "/LinkToSupervisorConfiguration");
955 bool doNotThrowOnBrokenUIDLinks)
const
960 if(nodeString.length() < 1)
throw std::runtime_error(
"Invalid empty node name");
962 bool startingSlash = (nodeString[0] ==
'/');
964 std::string nodeName = nodeString.substr(startingSlash?1:0, nodeString.find(
'/',1)-(startingSlash?1:0));
966 if(nodeName.length() < 1)
throw std::runtime_error(
"Invalid node name: " + nodeName);
968 std::string childPath = nodeString.substr(nodeName.length() + (startingSlash?1:0));
974 if(childPath.length() > 1)
975 return configTree.getNode(childPath,doNotThrowOnBrokenUIDLinks);
982 std::string ConfigurationManager::getFirstPathToNode(
const ConfigurationTree &node,
const std::string &startPath)
const
985 std::string path =
"/";
995 std::vector<std::pair<std::string,ConfigurationTree> > ConfigurationManager::getChildren(
996 std::map<std::string, ConfigurationVersion> *memberMap,
997 std::string *accumulatedTreeErrors)
const
999 std::vector<std::pair<std::string,ConfigurationTree> > retMap;
1000 if(accumulatedTreeErrors) *accumulatedTreeErrors =
"";
1002 if(!memberMap || memberMap->empty())
1004 for(
auto &configPair:nameToConfigurationMap_)
1008 if(configPair.second->isActive())
1013 if(accumulatedTreeErrors)
1017 std::vector<std::pair<std::string,ConfigurationTree> > newNodeChildren =
1018 newNode.getChildren();
1019 for(
auto &newNodeChild: newNodeChildren)
1021 std::vector<std::pair<std::string,ConfigurationTree> > twoDeepChildren =
1022 newNodeChild.second.getChildren();
1024 for(
auto &twoDeepChild: twoDeepChildren)
1028 if(twoDeepChild.second.isLinkNode() &&
1029 twoDeepChild.second.isDisconnected() &&
1030 twoDeepChild.second.getDisconnectedTableName() !=
1031 ViewColumnInfo::DATATYPE_LINK_DEFAULT)
1032 *accumulatedTreeErrors +=
"\n\nAt node '" +
1033 configPair.first +
"' with entry UID '" +
1034 newNodeChild.first +
"' there is a disconnected child node at link column '" +
1035 twoDeepChild.first +
"'" +
1036 " that points to table named '" +
1037 twoDeepChild.second.getDisconnectedTableName() +
1042 catch(std::runtime_error &e)
1044 *accumulatedTreeErrors +=
"\n\nAt node '" +
1045 configPair.first +
"' error detected descending through children:\n" +
1050 retMap.push_back(std::pair<std::string,ConfigurationTree>(configPair.first,
1060 for(
auto &memberPair: *memberMap)
1062 auto mapIt = nameToConfigurationMap_.find(memberPair.first);
1063 if(mapIt == nameToConfigurationMap_.end())
1065 __SS__ <<
"Get Children with member map requires a child '" <<
1066 memberPair.first <<
"' that is not present!" << std::endl;
1067 throw std::runtime_error(ss.str());
1069 if(!(*mapIt).second->isActive())
1071 __SS__ <<
"Get Children with member map requires a child '" <<
1072 memberPair.first <<
"' that is not active!" << std::endl;
1073 throw std::runtime_error(ss.str());
1078 if(accumulatedTreeErrors)
1082 std::vector<std::pair<std::string,ConfigurationTree> > newNodeChildren =
1083 newNode.getChildren();
1084 for(
auto &newNodeChild: newNodeChildren)
1086 std::vector<std::pair<std::string,ConfigurationTree> > twoDeepChildren =
1087 newNodeChild.second.getChildren();
1089 for(
auto &twoDeepChild: twoDeepChildren)
1093 if(twoDeepChild.second.isLinkNode() &&
1094 twoDeepChild.second.isDisconnected() &&
1095 twoDeepChild.second.getDisconnectedTableName() !=
1096 ViewColumnInfo::DATATYPE_LINK_DEFAULT)
1098 *accumulatedTreeErrors +=
"\n\nAt node '" +
1099 memberPair.first +
"' with entry UID '" +
1100 newNodeChild.first +
"' there is a disconnected child node at link column '" +
1101 twoDeepChild.first +
"'" +
1102 " that points to table named '" +
1103 twoDeepChild.second.getDisconnectedTableName() +
1109 for(
auto &searchMemberPair: *memberMap)
1110 if(searchMemberPair.first ==
1111 twoDeepChild.second.getDisconnectedTableName())
1112 { found =
true;
break;}
1114 *accumulatedTreeErrors +=
1115 std::string(
"\nNote: It may be safe to ignore this error ") +
1116 "since the link's target table " +
1117 twoDeepChild.second.getDisconnectedTableName() +
1118 " is not a member of this group (and may not be loaded yet).";
1123 catch(std::runtime_error &e)
1125 *accumulatedTreeErrors +=
"\n\nAt node '" +
1126 memberPair.first +
"' error detected descending through children:\n" +
1131 retMap.push_back(std::pair<std::string,ConfigurationTree>(memberPair.first,
1144 const ConfigurationBase* ConfigurationManager::getConfigurationByName(
const std::string &configurationName)
const
1146 std::map<std::string, ConfigurationBase*>::const_iterator it;
1147 if((it = nameToConfigurationMap_.find(configurationName)) == nameToConfigurationMap_.end())
1149 __SS__ <<
"\n\nCan not find configuration named '" <<
1150 configurationName <<
1151 "'\n\n\n\nYou need to load the configuration before it can be used." <<
1152 " It probably is missing from the member list of the Configuration Group that was loaded.\n" <<
1153 "\nYou may need to enter wiz mode to remedy the situation, use the following:\n" <<
1154 "\n\t StartOTS.sh --wiz" <<
1160 throw std::runtime_error(ss.str());
1171 if(!theBackboneGroupKey_)
1173 __MOUT_WARN__ <<
"getConfigurationGroupKey() Failed! No active backbone currently." << std::endl;
1178 loadConfigurationGroup(theBackboneGroup_,*theBackboneGroupKey_);
1180 return *theBackboneGroupKey_;
1219 std::pair<std::string, ConfigurationGroupKey> ConfigurationManager::getConfigurationGroupFromAlias(std::string runType,
ProgressBar* progressBar)
1226 if(progressBar) progressBar->step();
1228 loadConfigurationBackbone();
1230 if(progressBar) progressBar->step();
1235 ConfigurationTree entry = getNode(
"GroupAliasesConfiguration").getNode(runType);
1236 return std::pair<std::string, ConfigurationGroupKey>(entry.getNode(
"GroupName").getValueAsString(),
ConfigurationGroupKey(entry.getNode(
"GroupKey").getValueAsString()));
1241 if(progressBar) progressBar->step();
1248 std::map<std::string, std::pair<std::string, ConfigurationGroupKey> > ConfigurationManager::getGroupAliasesConfiguration(
void)
1250 restoreActiveConfigurationGroups();
1253 std::map<std::string ,
1256 std::vector<std::pair<std::string,ConfigurationTree> > entries = getNode(
"GroupAliasesConfiguration").getChildren();
1257 for(
auto &entryPair: entries)
1259 retMap[entryPair.first] = std::pair<std::string, ConfigurationGroupKey>(
1260 entryPair.second.getNode(
"GroupName").getValueAsString(),
1269 std::map<std::string, ConfigurationVersion> ConfigurationManager::getActiveVersions(
void)
const
1271 std::map<std::string, ConfigurationVersion> retMap;
1272 for(
auto &config:nameToConfigurationMap_)
1277 if(config.second && config.second->isActive())
1280 retMap.insert(std::pair<std::string, ConfigurationVersion>(config.first, config.second->getViewVersion()));
1308 std::shared_ptr<ConfigurationGroupKey> ConfigurationManager::makeTheConfigurationGroupKey(
ConfigurationGroupKey key)
1310 if(theConfigurationGroupKey_)
1312 if(*theConfigurationGroupKey_ != key)
1313 destroyConfigurationGroup();
1315 return theConfigurationGroupKey_;
1321 std::string ConfigurationManager::encodeURIComponent(
const std::string &sourceStr)
1323 std::string retStr =
"";
1325 for(
const auto &c:sourceStr)
1327 (c >=
'a' && c <=
'z') ||
1328 (c >=
'A' && c <=
'Z') ||
1329 (c >=
'0' && c <=
'9') )
1333 sprintf(encodeStr,
"%%%2.2X",c);
1334 retStr += encodeStr;