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;
171 __MOUT__ <<
"throwErrors: " << throwErrors << std::endl;
176 std::string groupName;
177 std::string errorStr =
"";
182 sscanf(tmp,
"%s",strVal);
185 sscanf(tmp,
"%s",strVal);
191 catch(std::runtime_error &e)
193 __SS__ <<
"Failed to load config group in ConfigurationManager::init() with name '" <<
194 groupName <<
"_v" << strVal <<
"'" << std::endl;
195 ss << e.what() << std::endl;
197 __MOUT_INFO__ <<
"\n" << ss.str();
198 errorStr += ss.str();
202 __SS__ <<
"Failed to load config group in ConfigurationManager::init() with name '" <<
203 groupName <<
"_v" << strVal <<
"'" << std::endl;
205 __MOUT_INFO__ <<
"\n" << ss.str();
206 errorStr += ss.str();
212 if(throwErrors && errorStr !=
"")
213 throw std::runtime_error(errorStr);
221 void ConfigurationManager::destroyConfigurationGroup(
const std::string& theGroup,
bool onlyDeactivate)
224 bool isContext = theGroup ==
"" || theGroup == theContextGroup_;
225 bool isBackbone = theGroup ==
"" || theGroup == theBackboneGroup_;
226 bool isConfiguration = theGroup ==
"" || theGroup == theConfigurationGroup_;
228 if(!isContext && !isBackbone && !isConfiguration)
230 __MOUT__ <<
"Invalid configuration group to destroy: " << theGroup << std::endl;
231 throw std::runtime_error(
"Invalid configuration group to destroy!");
234 std::string dbgHeader = onlyDeactivate?
"Deactivating":
"Destroying";
236 __MOUT__ << dbgHeader <<
" Context group: " << theGroup << std::endl;
238 __MOUT__ << dbgHeader <<
" Backbone group: " << theGroup << std::endl;
240 __MOUT__ << dbgHeader <<
" Configuration group: " << theGroup << std::endl;
243 std::set<std::string>::const_iterator contextFindIt, backboneFindIt;
244 for(
auto it = nameToConfigurationMap_.begin(); it != nameToConfigurationMap_.end(); )
246 contextFindIt = contextMemberNames_.find(it->first);
247 backboneFindIt = backboneMemberNames_.find(it->first);
248 if(theGroup ==
"" || ( (isContext && contextFindIt != contextMemberNames_.end()) ||
249 (isBackbone && backboneFindIt != backboneMemberNames_.end()) ||
250 (!isContext && !isBackbone &&
251 contextFindIt == contextMemberNames_.end() &&
252 backboneFindIt == backboneMemberNames_.end())))
261 it->second->deactivate();
267 nameToConfigurationMap_.erase(it++);
276 theConfigurationGroup_ =
"";
277 if(theConfigurationGroupKey_ != 0)
279 __MOUT__ <<
"Destroying Configuration Key: " << *theConfigurationGroupKey_ << std::endl;
280 theConfigurationGroupKey_.reset();
287 theBackboneGroup_ =
"";
288 if(theBackboneGroupKey_ != 0)
290 __MOUT__ <<
"Destroying Backbone Key: " << *theBackboneGroupKey_ << std::endl;
291 theBackboneGroupKey_.reset();
296 theContextGroup_ =
"";
297 if(theContextGroupKey_ != 0)
299 __MOUT__ <<
"Destroying Context Key: " << *theContextGroupKey_ << std::endl;
300 theContextGroupKey_.reset();
306 void ConfigurationManager::destroy(
void)
311 destroyConfigurationGroup();
321 const std::string& ConfigurationManager::convertGroupTypeIdToName(
int groupTypeId)
323 return groupTypeId==CONTEXT_TYPE?
324 ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT:
325 (groupTypeId==BACKBONE_TYPE?
326 ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE:
327 ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION);
336 int ConfigurationManager::getTypeOfGroup(
337 const std::string &configGroupName,
339 const std::map<std::string /*name*/, ConfigurationVersion /*version*/> &memberMap)
342 bool isContext =
true;
343 bool isBackbone =
true;
345 bool inContext =
false;
346 bool inBackbone =
false;
347 unsigned int matchCount = 0;
349 for(
auto &memberPair:memberMap)
353 for(
auto &contextMemberString:contextMemberNames_)
356 if(memberPair.first == contextMemberString)
368 __SS__ <<
"This group is an incomplete match to contextMemberNames_: " +
369 configGroupName +
"(" + configGroupKey.toString() +
")\n";
370 ss <<
"\nTo be a Context group, the members must exactly match" <<
371 "the following members:\n";
373 for(
auto &memberName:contextMemberNames_)
374 ss << ++i <<
". " << memberName <<
"\n";
375 __MOUT_ERR__ <<
"\n" << ss.str();
376 throw std::runtime_error(ss.str());
381 for(
auto &backboneMemberString:backboneMemberNames_)
384 if(memberPair.first == backboneMemberString)
396 __SS__ <<
"This group is an incomplete match to backboneMemberNames_: " +
397 configGroupName +
"(" + configGroupKey.toString() +
")\n";
398 ss <<
"\nTo be a Backbone group, the members must exactly match" <<
399 "the following members:\n";
401 for(
auto &memberName:backboneMemberNames_)
402 ss << ++i <<
". " << memberName <<
"\n";
403 __MOUT_ERR__ <<
"\n" << ss.str();
404 throw std::runtime_error(ss.str());
410 if(isContext && matchCount != contextMemberNames_.size())
412 __SS__ <<
"This group is an incomplete match to contextMemberNames_: " +
413 configGroupName +
"(" + configGroupKey.toString() +
")" +
414 " Size=" << matchCount <<
" but should be " << contextMemberNames_.size() <<
416 ss <<
"\nThe members currently are...\n";
418 for(
auto &memberPair:memberMap)
419 ss << ++i <<
". " << memberPair.first <<
"\n";
420 ss <<
"\nThe expected Context members are...\n";
422 for(
auto &memberName:contextMemberNames_)
423 ss << ++i <<
". " << memberName <<
"\n";
424 __MOUT_ERR__ <<
"\n" << ss.str();
425 throw std::runtime_error(ss.str());
428 if(isBackbone && matchCount != backboneMemberNames_.size())
430 __SS__ <<
"This group is an incomplete match to backboneMemberNames_: " +
431 configGroupName +
"(" + configGroupKey.toString() +
")" +
432 " Size=" << matchCount <<
" but should be " << backboneMemberNames_.size() <<
434 ss <<
"\nThe members currently are...\n";
436 for(
auto &memberPair:memberMap)
437 ss << ++i <<
". " << memberPair.first <<
"\n";
438 ss <<
"\nThe expected Backbone members are...\n";
440 for(
auto &memberName:backboneMemberNames_)
441 ss << ++i <<
". " << memberName <<
"\n";
442 __MOUT_ERR__ <<
"\n" << ss.str();
443 throw std::runtime_error(ss.str());
446 return isContext?CONTEXT_TYPE:(isBackbone?BACKBONE_TYPE:CONFIGURATION_TYPE);
455 const std::string& ConfigurationManager::getTypeNameOfGroup(
456 const std::string &configGroupName,
458 const std::map<std::string /*name*/, ConfigurationVersion /*version*/> &memberMap)
460 return convertGroupTypeIdToName(getTypeOfGroup(configGroupName, configGroupKey, memberMap));
466 void ConfigurationManager::dumpActiveConfiguration(
467 const std::string &filePath,
const std::string &dumpType)
const
469 time_t rawtime = time(0);
470 __MOUT__ <<
"filePath = " << filePath << std::endl;
471 __MOUT__ <<
"dumpType = " << dumpType << std::endl;
475 fs.open(filePath, std::fstream::out | std::fstream::trunc);
486 (*out) <<
"#################################" << std::endl;
487 (*out) <<
"This is an ots configuration dump.\n\n" << std::endl;
488 (*out) <<
"Source database is $ARTDAQ_DATABASE_URI = \t" << getenv(
"ARTDAQ_DATABASE_URI") << std::endl;
489 (*out) <<
"\nOriginal location of dump: \t" << filePath << std::endl;
490 (*out) <<
"Type of dump: \t" << dumpType << std::endl;
491 (*out) <<
"Linux time for dump: \t" << rawtime << std::endl;
494 struct tm * timeinfo = localtime (&rawtime);
496 strftime(buffer,100,
"%c %Z",timeinfo);
497 (*out) <<
"Display time for dump: \t" << buffer << std::endl;
508 std::map<std::string, std::pair<std::string, ConfigurationGroupKey>> activeGroups =
509 cfgMgr->getActiveConfigurationGroups();
511 (*out) <<
"\n\n************************" << std::endl;
512 (*out) <<
"Active Groups:" << std::endl;
513 for(
auto &group:activeGroups)
515 (*out) <<
"\t" << group.first <<
" := " <<
516 group.second.first <<
" (" <<
517 group.second.second <<
")" << std::endl;
522 std::map<std::string, ConfigurationVersion> activeTables =
523 cfgMgr->getActiveVersions();
525 (*out) <<
"\n\n************************" << std::endl;
526 (*out) <<
"Active Tables:" << std::endl;
527 (*out) <<
"Active Tables count = " << activeTables.size() << std::endl;
528 for(
auto &table:activeTables)
530 (*out) <<
"\t" << table.first <<
"-v" <<
531 table.second << std::endl;
536 std::map<std::string, std::pair<std::string, ConfigurationGroupKey>> activeGroups =
537 cfgMgr->getActiveConfigurationGroups();
538 (*out) <<
"\n\n************************" << std::endl;
539 (*out) <<
"Active Group Members:" << std::endl;
541 for(
auto &group:activeGroups)
543 (*out) <<
"\t" << group.first <<
" := " <<
544 group.second.first <<
" (" <<
545 group.second.second <<
")" << std::endl;
548 cfgMgr->theInterface_->getConfigurationGroupMembers(
549 ConfigurationGroupKey::getFullGroupString(
551 group.second.second));
553 (*out) <<
"\tMember count = " << memberMap.size() << std::endl;
554 tableCount += memberMap.size();
556 for(
auto &member:memberMap)
558 (*out) <<
"\t\t" << member.first <<
"-v" <<
559 member.second << std::endl;
562 (*out) <<
"Active Group Members total count = " << tableCount << std::endl;
566 std::map<std::string, ConfigurationVersion> activeTables =
567 cfgMgr->getActiveVersions();
569 (*out) <<
"\n\n************************" << std::endl;
570 (*out) <<
"Active Table Contents:" << std::endl;
571 for(
auto &table:activeTables)
573 (*out) <<
"\t" << table.first <<
"-v" <<
574 table.second << std::endl;
576 cfgMgr->nameToConfigurationMap_.find(table.first)->second->print(*out);
582 if(dumpType ==
"GroupKeys")
584 localDumpActiveGroups(
this,out);
586 else if(dumpType ==
"TableVersions")
588 localDumpActiveTables(
this,out);
590 else if(dumpType ==
"GroupKeysAndTableVersions")
592 localDumpActiveGroups(
this,out);
593 localDumpActiveTables(
this,out);
595 else if(dumpType ==
"All")
597 localDumpActiveGroups(
this,out);
598 localDumpActiveGroupMembers(
this,out);
599 localDumpActiveTables(
this,out);
600 localDumpActiveTableContents(
this,out);
604 __SS__ <<
"Invalid dump type '" << dumpType <<
605 "' given during dumpActiveConfiguration(). Valid types are as follows:\n" <<
608 "GroupKeys" <<
", " <<
609 "TableVersions" <<
", " <<
610 "GroupsKeysAndTableVersions" <<
", " <<
613 "\n\nPlease change the State Machine configuration to a valid dump type." <<
615 throw std::runtime_error(ss.str());
626 void ConfigurationManager::loadMemberMap(
627 const std::map<std::string /*name*/, ConfigurationVersion /*version*/> &memberMap)
632 for(
auto &memberPair:memberMap)
642 tmpConfigBasePtr = 0;
643 if(nameToConfigurationMap_.find(memberPair.first) != nameToConfigurationMap_.end())
644 tmpConfigBasePtr = nameToConfigurationMap_[memberPair.first];
646 theInterface_->get(tmpConfigBasePtr,
655 nameToConfigurationMap_[memberPair.first] = tmpConfigBasePtr;
656 if(nameToConfigurationMap_[memberPair.first]->getViewP())
662 __SS__ << nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
663 ": View version not activated properly!";
664 throw std::runtime_error(ss.str());
684 std::map<std::string, ConfigurationVersion> ConfigurationManager::loadConfigurationGroup(
685 const std::string &configGroupName,
689 std::string *accumulatedTreeErrors,
690 std::string *groupComment,
691 std::string *groupAuthor,
692 std::string *groupCreateTime,
693 bool doNotLoadMember)
695 if(accumulatedTreeErrors) *accumulatedTreeErrors =
"";
696 if(groupComment) *groupComment =
"";
697 if(groupAuthor) *groupAuthor =
"";
698 if(groupCreateTime) *groupCreateTime =
"";
712 __MOUT_INFO__ <<
"Loading Configuration Group: " << configGroupName <<
713 "(" << configGroupKey <<
")" << std::endl;
716 theInterface_->getConfigurationGroupMembers(
717 ConfigurationGroupKey::getFullGroupString(configGroupName,configGroupKey),
721 if(progressBar) progressBar->step();
724 auto metaTablePair = memberMap.find(groupMetadataTable_.getConfigurationName());
728 __MOUT__ <<
"Found group meta data. v" <<
729 metaTablePair->second << std::endl;
731 while(groupMetadataTable_.getView().getNumberOfRows())
732 groupMetadataTable_.getViewP()->deleteRow(0);
733 theInterface_->fill(&groupMetadataTable_,metaTablePair->second);
735 if(groupMetadataTable_.getView().getNumberOfRows() != 1)
737 groupMetadataTable_.print();
738 __SS__ <<
"groupMetadataTable_ has wrong number of rows! Must be 1." << std::endl;
739 __MOUT_ERR__ <<
"\n" << ss.str();
740 throw std::runtime_error(ss.str());
744 memberMap.erase(metaTablePair);
747 if(groupComment) *groupComment = groupMetadataTable_.getView().getValueAsString(0,1);
748 if(groupAuthor) *groupAuthor = groupMetadataTable_.getView().getValueAsString(0,2);
749 if(groupCreateTime) *groupCreateTime = groupMetadataTable_.getView().getValueAsString(0,3);
752 if(progressBar) progressBar->step();
754 __MOUT__ <<
"memberMap loaded size = " << memberMap.size() << std::endl;
756 if(doNotLoadMember)
return memberMap;
762 groupType = getTypeOfGroup(configGroupName,configGroupKey,memberMap);
764 std::string groupToDeactivate =
765 groupType==CONTEXT_TYPE?theContextGroup_:
766 (groupType==BACKBONE_TYPE?theBackboneGroup_:theConfigurationGroup_);
769 if(groupToDeactivate !=
"")
771 __MOUT__ <<
"groupToDeactivate '" << groupToDeactivate <<
"'" << std::endl;
772 destroyConfigurationGroup(groupToDeactivate,
true);
783 if(progressBar) progressBar->step();
785 __MOUT__ <<
"Activating chosen group:" << std::endl;
788 loadMemberMap(memberMap);
790 if(progressBar) progressBar->step();
792 if(accumulatedTreeErrors)
794 __MOUT__ <<
"Checking chosen group for tree errors..." << std::endl;
796 getChildren(&memberMap, accumulatedTreeErrors);
797 if(*accumulatedTreeErrors !=
"")
799 __MOUT_ERR__ <<
"Errors detected while loading Configuration Group: " << configGroupName <<
800 "(" << configGroupKey <<
"). Aborting." << std::endl;
805 if(progressBar) progressBar->step();
810 for(
auto &memberPair:memberMap)
813 if(ConfigurationInterface::isVersionTrackingEnabled() &&
814 memberPair.second.isScratchVersion())
816 __SS__ <<
"Error while activating member Table '" <<
817 nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
818 "-v" << memberPair.second <<
819 " for Configuration Group '" << configGroupName <<
820 "(" << configGroupKey <<
")'. When version tracking is enabled, Scratch views" <<
821 " are not allowed! Please only use unique, persistent versions when version tracking is enabled."
823 __MOUT_ERR__ <<
"\n" << ss.str();
824 throw std::runtime_error(ss.str());
832 nameToConfigurationMap_[memberPair.first]->init(
this);
834 catch(std::runtime_error& e)
836 __SS__ <<
"Error detected calling " <<
837 nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
838 ".init()!\n\n " << e.what() << std::endl;
839 throw std::runtime_error(ss.str());
843 __SS__ <<
"Error detected calling " <<
844 nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
845 ".init()!\n\n " << std::endl;
846 throw std::runtime_error(ss.str());
851 if(progressBar) progressBar->step();
859 if(groupType == CONTEXT_TYPE)
861 __MOUT_INFO__ <<
"Context Configuration Group loaded: " << configGroupName <<
862 "(" << configGroupKey <<
")" << std::endl;
863 theContextGroup_ = configGroupName;
864 theContextGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(
new ConfigurationGroupKey(configGroupKey));
866 else if(groupType == BACKBONE_TYPE)
868 __MOUT_INFO__ <<
"Backbone Configuration Group loaded: " << configGroupName <<
869 "(" << configGroupKey <<
")" << std::endl;
870 theBackboneGroup_ = configGroupName;
871 theBackboneGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(
new ConfigurationGroupKey(configGroupKey));
875 __MOUT_INFO__ <<
"The Configuration Group loaded: " << configGroupName <<
876 "(" << configGroupKey <<
")" << std::endl;
877 theConfigurationGroup_ = configGroupName;
878 theConfigurationGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(
new ConfigurationGroupKey(configGroupKey));
882 if(progressBar) progressBar->step();
883 __MOUT__ <<
"Load complete." << std::endl;
894 std::map<std::string, std::pair<std::string, ConfigurationGroupKey> > ConfigurationManager::getActiveConfigurationGroups(
void)
const
897 std::map<std::string, std::pair<std::string, ConfigurationGroupKey> > retMap;
899 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT] =
900 std::pair<std::string,ConfigurationGroupKey>(theContextGroup_ ,theContextGroupKey_ ?*theContextGroupKey_ :
ConfigurationGroupKey());
901 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE] =
902 std::pair<std::string,ConfigurationGroupKey>(theBackboneGroup_ ,theBackboneGroupKey_ ?*theBackboneGroupKey_ :
ConfigurationGroupKey());
903 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION] =
904 std::pair<std::string,ConfigurationGroupKey>(theConfigurationGroup_,theConfigurationGroupKey_?*theConfigurationGroupKey_:
ConfigurationGroupKey());
910 const std::string &contextUID,
const std::string &applicationUID)
const
913 "/" + getConfigurationByName(XDAQ_CONTEXT_CONFIG_NAME)->getConfigurationName() +
915 "/LinkToApplicationConfiguration/" + applicationUID +
916 "/LinkToSupervisorConfiguration");
920 ConfigurationTree ConfigurationManager::getNode(
const std::string& nodeString)
const
925 if(nodeString.length() < 1)
throw std::runtime_error(
"Invalid empty node name");
927 bool startingSlash = (nodeString[0] ==
'/');
929 std::string nodeName = nodeString.substr(startingSlash?1:0, nodeString.find(
'/',1)-(startingSlash?1:0));
931 if(nodeName.length() < 1)
throw std::runtime_error(
"Invalid node name: " + nodeName);
933 std::string childPath = nodeString.substr(nodeName.length() + (startingSlash?1:0));
938 if(childPath.length() > 1)
939 return configTree.getNode(childPath);
946 std::string ConfigurationManager::getFirstPathToNode(
const ConfigurationTree &node,
const std::string &startPath)
const
949 std::string path =
"/";
959 std::vector<std::pair<std::string,ConfigurationTree> > ConfigurationManager::getChildren(
960 std::map<std::string, ConfigurationVersion> *memberMap,
961 std::string *accumulatedTreeErrors)
const
963 std::vector<std::pair<std::string,ConfigurationTree> > retMap;
964 if(accumulatedTreeErrors) *accumulatedTreeErrors =
"";
966 if(!memberMap || memberMap->empty())
968 for(
auto &configPair:nameToConfigurationMap_)
972 if(configPair.second->isActive())
977 if(accumulatedTreeErrors)
981 std::vector<std::pair<std::string,ConfigurationTree> > newNodeChildren =
982 newNode.getChildren();
983 for(
auto &newNodeChild: newNodeChildren)
985 std::vector<std::pair<std::string,ConfigurationTree> > twoDeepChildren =
986 newNodeChild.second.getChildren();
988 for(
auto &twoDeepChild: twoDeepChildren)
992 if(twoDeepChild.second.isLinkNode() &&
993 twoDeepChild.second.isDisconnected() &&
994 twoDeepChild.second.getDisconnectedTableName() !=
995 ViewColumnInfo::DATATYPE_LINK_DEFAULT)
996 *accumulatedTreeErrors +=
"\n\nAt node '" +
997 configPair.first +
"' with entry UID '" +
998 newNodeChild.first +
"' there is a disconnected child node at link column '" +
999 twoDeepChild.first +
"'" +
1000 " that points to table named '" +
1001 twoDeepChild.second.getDisconnectedTableName() +
1006 catch(std::runtime_error &e)
1008 *accumulatedTreeErrors +=
"\n\nAt node '" +
1009 configPair.first +
"' error detected descending through children:\n" +
1014 retMap.push_back(std::pair<std::string,ConfigurationTree>(configPair.first,
1024 for(
auto &memberPair: *memberMap)
1026 auto mapIt = nameToConfigurationMap_.find(memberPair.first);
1027 if(mapIt == nameToConfigurationMap_.end())
1029 __SS__ <<
"Get Children with member map requires a child '" <<
1030 memberPair.first <<
"' that is not present!" << std::endl;
1031 throw std::runtime_error(ss.str());
1033 if(!(*mapIt).second->isActive())
1035 __SS__ <<
"Get Children with member map requires a child '" <<
1036 memberPair.first <<
"' that is not active!" << std::endl;
1037 throw std::runtime_error(ss.str());
1042 if(accumulatedTreeErrors)
1046 std::vector<std::pair<std::string,ConfigurationTree> > newNodeChildren =
1047 newNode.getChildren();
1048 for(
auto &newNodeChild: newNodeChildren)
1050 std::vector<std::pair<std::string,ConfigurationTree> > twoDeepChildren =
1051 newNodeChild.second.getChildren();
1053 for(
auto &twoDeepChild: twoDeepChildren)
1057 if(twoDeepChild.second.isLinkNode() &&
1058 twoDeepChild.second.isDisconnected() &&
1059 twoDeepChild.second.getDisconnectedTableName() !=
1060 ViewColumnInfo::DATATYPE_LINK_DEFAULT)
1062 *accumulatedTreeErrors +=
"\n\nAt node '" +
1063 memberPair.first +
"' with entry UID '" +
1064 newNodeChild.first +
"' there is a disconnected child node at link column '" +
1065 twoDeepChild.first +
"'" +
1066 " that points to table named '" +
1067 twoDeepChild.second.getDisconnectedTableName() +
1073 for(
auto &searchMemberPair: *memberMap)
1074 if(searchMemberPair.first ==
1075 twoDeepChild.second.getDisconnectedTableName())
1076 { found =
true;
break;}
1078 *accumulatedTreeErrors +=
1079 std::string(
"\nNote: It may be safe to ignore this error ") +
1080 "since the link's target table " +
1081 twoDeepChild.second.getDisconnectedTableName() +
1082 " is not a member of this group (and may not be loaded yet).";
1087 catch(std::runtime_error &e)
1089 *accumulatedTreeErrors +=
"\n\nAt node '" +
1090 memberPair.first +
"' error detected descending through children:\n" +
1095 retMap.push_back(std::pair<std::string,ConfigurationTree>(memberPair.first,
1108 const ConfigurationBase* ConfigurationManager::getConfigurationByName(
const std::string &configurationName)
const
1110 std::map<std::string, ConfigurationBase*>::const_iterator it;
1111 if((it = nameToConfigurationMap_.find(configurationName)) == nameToConfigurationMap_.end())
1113 __SS__ <<
"\n\nCan not find configuration named '" <<
1114 configurationName <<
1115 "'\n\n\n\nYou need to load the configuration before it can be used." <<
1116 " It probably is missing from the member list of the Configuration Group that was loaded.\n" <<
1117 "\nYou may need to enter wiz mode to remedy the situation, use the following:\n" <<
1118 "\n\t StartOTS.sh --wiz" <<
1121 throw std::runtime_error(ss.str());
1132 if(!theBackboneGroupKey_)
1134 __MOUT_WARN__ <<
"getConfigurationGroupKey() Failed! No active backbone currently." << std::endl;
1139 loadConfigurationGroup(theBackboneGroup_,*theBackboneGroupKey_);
1141 return *theBackboneGroupKey_;
1180 std::pair<std::string, ConfigurationGroupKey> ConfigurationManager::getConfigurationGroupFromAlias(std::string runType,
ProgressBar* progressBar)
1187 if(progressBar) progressBar->step();
1189 loadConfigurationBackbone();
1191 if(progressBar) progressBar->step();
1196 ConfigurationTree entry = getNode(
"GroupAliasesConfiguration").getNode(runType);
1197 return std::pair<std::string, ConfigurationGroupKey>(entry.getNode(
"GroupName").getValueAsString(),
ConfigurationGroupKey(entry.getNode(
"GroupKey").getValueAsString()));
1202 if(progressBar) progressBar->step();
1209 std::map<std::string, std::pair<std::string, ConfigurationGroupKey> > ConfigurationManager::getGroupAliasesConfiguration(
void)
1211 restoreActiveConfigurationGroups();
1214 std::map<std::string ,
1217 std::vector<std::pair<std::string,ConfigurationTree> > entries = getNode(
"GroupAliasesConfiguration").getChildren();
1218 for(
auto &entryPair: entries)
1220 retMap[entryPair.first] = std::pair<std::string, ConfigurationGroupKey>(
1221 entryPair.second.getNode(
"GroupName").getValueAsString(),
1230 std::map<std::string, ConfigurationVersion> ConfigurationManager::getActiveVersions(
void)
const
1232 std::map<std::string, ConfigurationVersion> retMap;
1233 for(
auto &config:nameToConfigurationMap_)
1238 if(config.second && config.second->isActive())
1241 retMap.insert(std::pair<std::string, ConfigurationVersion>(config.first, config.second->getViewVersion()));
1269 std::shared_ptr<ConfigurationGroupKey> ConfigurationManager::makeTheConfigurationGroupKey(
ConfigurationGroupKey key)
1271 if(theConfigurationGroupKey_)
1273 if(*theConfigurationGroupKey_ != key)
1274 destroyConfigurationGroup();
1276 return theConfigurationGroupKey_;
1282 std::string ConfigurationManager::encodeURIComponent(
const std::string &sourceStr)
1284 std::string retStr =
"";
1286 for(
const auto &c:sourceStr)
1288 (c >=
'a' && c <=
'z') ||
1289 (c >=
'A' && c <=
'Z') ||
1290 (c >=
'0' && c <=
'9') )
1294 sprintf(encodeStr,
"%%%2.2X",c);
1295 retStr += encodeStr;