00001 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
00002 #include "otsdaq-core/ConfigurationInterface/ConfigurationInterface.h"
00003 #include "otsdaq-core/ConfigurationDataFormats/ConfigurationGroupKey.h"
00004 #include "otsdaq-core/ProgressBar/ProgressBar.h"
00005
00006 #include <fstream>
00007
00008
00009 using namespace ots;
00010
00011
00012 #undef __MF_SUBJECT__
00013 #define __MF_SUBJECT__ "ConfigurationManager"
00014
00015 const std::string ConfigurationManager::READONLY_USER = "READONLY_USER";
00016
00017 const std::string ConfigurationManager::XDAQ_CONTEXT_CONFIG_NAME = "XDAQContextConfiguration";
00018
00019
00020 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";
00021 const std::string ConfigurationManager::ALIAS_VERSION_PREAMBLE = "ALIAS:";
00022 const std::string ConfigurationManager::SCRATCH_VERSION_ALIAS = "Scratch";
00023
00024 #define CORE_TABLE_INFO_FILENAME ((getenv("SERVICE_DATA_PATH") == NULL)?(std::string(getenv("USER_DATA"))+"/ServiceData"):(std::string(getenv("SERVICE_DATA_PATH")))) + "/CoreTableInfoNames.dat"
00025
00026
00027 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT = "Context";
00028 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE = "Backbone";
00029 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE = "Iterate";
00030 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION = "Configuration";
00031
00032
00033
00034 ConfigurationManager::ConfigurationManager()
00035 : username_ (ConfigurationManager::READONLY_USER)
00036 , theInterface_ (0)
00037 , theConfigurationGroupKey_ (0)
00038 , theContextGroupKey_ (0)
00039 , theBackboneGroupKey_ (0)
00040 , theConfigurationGroup_ ("")
00041 , theContextGroup_ ("")
00042 , theBackboneGroup_ ("")
00043 , contextMemberNames_ ({XDAQ_CONTEXT_CONFIG_NAME,"XDAQApplicationConfiguration","XDAQApplicationPropertyConfiguration","DesktopIconConfiguration","MessageFacilityConfiguration","TheSupervisorConfiguration","StateMachineConfiguration","DesktopWindowParameterConfiguration"})
00044 , backboneMemberNames_ ({"GroupAliasesConfiguration","VersionAliasesConfiguration"})
00045 , iterateMemberNames_ ({"IterateConfiguration","IterationPlanConfiguration","IterationTargetConfiguration",
00046 "IterationCommandBeginLabelConfiguration","IterationCommandChooseFSMConfiguration","IterationCommandConfigureAliasConfiguration","IterationCommandConfigureGroupConfiguration","IterationCommandExecuteFEMacroConfiguration","IterationCommandExecuteMacroConfiguration","IterationCommandModifyGroupConfiguration","IterationCommandRepeatLabelConfiguration","IterationCommandRunConfiguration"})
00047 {
00048 theInterface_ = ConfigurationInterface::getInstance(false);
00049
00050
00051
00052 {
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 groupMetadataTable_.setConfigurationName(ConfigurationInterface::GROUP_METADATA_TABLE_NAME);
00063
00064 std::vector<ViewColumnInfo>* colInfo =
00065 groupMetadataTable_.getMockupViewP()->getColumnsInfoP();
00066
00067
00068 colInfo->push_back(ViewColumnInfo(
00069 ViewColumnInfo::TYPE_UID,
00070 "UnusedUID",
00071 "UNUSED_UID",
00072 ViewColumnInfo::DATATYPE_NUMBER,
00073 "",0
00074 ));
00075 colInfo->push_back(ViewColumnInfo(
00076 ViewColumnInfo::TYPE_COMMENT,
00077 "CommentDescription",
00078 "COMMENT_DESCRIPTION",
00079 ViewColumnInfo::DATATYPE_STRING,
00080 "",0
00081 ));
00082 colInfo->push_back(ViewColumnInfo(
00083 ViewColumnInfo::TYPE_AUTHOR,
00084 "GroupAuthor",
00085 "AUTHOR",
00086 ViewColumnInfo::DATATYPE_STRING,
00087 "",0
00088 ));
00089 colInfo->push_back(ViewColumnInfo(
00090 ViewColumnInfo::TYPE_TIMESTAMP,
00091 "GroupCreationTime",
00092 "GROUP_CREATION_TIME",
00093 ViewColumnInfo::DATATYPE_TIME,
00094 "",0
00095 ));
00096 auto tmpVersion = groupMetadataTable_.createTemporaryView();
00097 groupMetadataTable_.setActiveView(tmpVersion);
00098
00099 groupMetadataTable_.getViewP()->addRow();
00100 }
00101
00102
00103 {
00104 FILE * fp = fopen((CORE_TABLE_INFO_FILENAME).c_str(),"w");
00105 if(fp)
00106 {
00107 for(const auto &name:contextMemberNames_)
00108 fprintf(fp,"%s\n",name.c_str());
00109 for(const auto &name:backboneMemberNames_)
00110 fprintf(fp,"%s\n",name.c_str());
00111 for(const auto &name:iterateMemberNames_)
00112 fprintf(fp,"%s\n",name.c_str());
00113 fclose(fp);
00114 }
00115 else
00116 {
00117 __SS__ << "Failed to open core table info file: " << CORE_TABLE_INFO_FILENAME << std::endl;
00118 __COUT_ERR__ << "\n" << ss.str();
00119 throw std::runtime_error(ss.str());
00120 }
00121 }
00122
00123 init();
00124 }
00125
00126
00127 ConfigurationManager::ConfigurationManager(const std::string& username)
00128 : ConfigurationManager ()
00129 {
00130 username_ = username;
00131 }
00132
00133
00134 ConfigurationManager::~ConfigurationManager()
00135 {
00136 destroy();
00137 }
00138
00139
00140
00141
00142
00143 void ConfigurationManager::init(std::string *accumulatedErrors)
00144 {
00145 if(accumulatedErrors) *accumulatedErrors = "";
00146
00147
00148
00149
00150 if(theInterface_->getMode() == false)
00151 {
00152 try
00153 {
00154 restoreActiveConfigurationGroups(accumulatedErrors?true:false);
00155 }
00156 catch(std::runtime_error &e)
00157 {
00158 if(accumulatedErrors) *accumulatedErrors = e.what();
00159 else throw;
00160 }
00161 }
00162 }
00163
00164
00165
00166
00167
00168
00169 void ConfigurationManager::restoreActiveConfigurationGroups(bool throwErrors)
00170 {
00171 destroyConfigurationGroup("",true);
00172
00173 std::string fn = ACTIVE_GROUP_FILENAME;
00174 FILE *fp = fopen(fn.c_str(),"r");
00175
00176 __COUT__ << "ACTIVE_GROUP_FILENAME = " << ACTIVE_GROUP_FILENAME << std::endl;
00177 __COUT__ << "ARTDAQ_DATABASE_URI = " << std::string(getenv("ARTDAQ_DATABASE_URI")) << std::endl;
00178
00179 if(!fp) return;
00180
00181
00182
00183 char tmp[500];
00184 char strVal[500];
00185
00186 std::string groupName;
00187 std::string errorStr = "";
00188 bool skip;
00189
00190 __SS__;
00191
00192 while(fgets(tmp,500,fp))
00193 {
00194
00195
00196 skip = false;
00197 sscanf(tmp,"%s",strVal);
00198 for(unsigned int j=0;j<strlen(strVal);++j)
00199 if(!(
00200 (strVal[j] >= 'a' && strVal[j] <= 'z') ||
00201 (strVal[j] >= 'A' && strVal[j] <= 'Z') ||
00202 (strVal[j] >= '0' && strVal[j] <= '9')))
00203 {
00204 strVal[j] = '\0';
00205 __COUT_INFO__ << "Illegal character found, so skipping!" << std::endl;
00206
00207 skip = true;
00208 break;
00209 }
00210
00211 if(skip) continue;
00212
00213 groupName = strVal;
00214 fgets(tmp,500,fp);
00215 sscanf(tmp,"%s",strVal);
00216
00217 for(unsigned int j=0;j<strlen(strVal);++j)
00218 if(!(
00219 (strVal[j] >= '0' && strVal[j] <= '9')))
00220 {
00221 strVal[j] = '\0';
00222 __COUT_INFO__ << "Illegal character found, so skipping!" << std::endl;
00223
00224 skip = true;
00225 break;
00226 }
00227
00228 try
00229 {
00230 ConfigurationGroupKey::getFullGroupString(groupName,ConfigurationGroupKey(strVal));
00231 }
00232 catch(...)
00233 {
00234 __COUT__ << "illegal group accorging to ConfigurationGroupKey::getFullGroupString..." << std::endl;
00235 skip = true;
00236 }
00237
00238 if(skip) continue;
00239
00240 try
00241 {
00242
00243 loadConfigurationGroup(groupName,ConfigurationGroupKey(strVal),true);
00244 }
00245 catch(std::runtime_error &e)
00246 {
00247 ss << "Failed to load config group in ConfigurationManager::init() with name '" <<
00248 groupName << "_v" << strVal << "'" << std::endl;
00249 ss << e.what() << std::endl;
00250
00251 errorStr += ss.str();
00252 }
00253 catch(...)
00254 {
00255 ss << "Failed to load config group in ConfigurationManager::init() with name '" <<
00256 groupName << "_v" << strVal << "'" << std::endl;
00257
00258 errorStr += ss.str();
00259 }
00260 }
00261
00262 fclose(fp);
00263
00264 if(throwErrors && errorStr != "")
00265 {
00266 __COUT_INFO__ << "\n" << ss.str();
00267 throw std::runtime_error(errorStr);
00268 }
00269 }
00270
00271
00272
00273
00274
00275
00276 void ConfigurationManager::destroyConfigurationGroup(const std::string& theGroup, bool onlyDeactivate)
00277 {
00278
00279 bool isContext = theGroup == "" || theGroup == theContextGroup_;
00280 bool isBackbone = theGroup == "" || theGroup == theBackboneGroup_;
00281 bool isIterate = theGroup == "" || theGroup == theIterateGroup_;
00282 bool isConfiguration = theGroup == "" || theGroup == theConfigurationGroup_;
00283
00284 if(!isContext && !isBackbone && !isIterate && !isConfiguration)
00285 {
00286 __SS__ << "Invalid configuration group to destroy: " << theGroup << std::endl;
00287 __COUT_ERR__ << ss.str();
00288 throw std::runtime_error(ss.str());
00289 }
00290
00291 std::string dbgHeader = onlyDeactivate?"Deactivating":"Destroying";
00292 if(theGroup != "")
00293 {
00294 if(isContext)
00295 __COUT__ << dbgHeader << " Context group: " << theGroup << std::endl;
00296 if(isBackbone)
00297 __COUT__ << dbgHeader << " Backbone group: " << theGroup << std::endl;
00298 if(isIterate)
00299 __COUT__ << dbgHeader << " Iterate group: " << theGroup << std::endl;
00300 if(isConfiguration)
00301 __COUT__ << dbgHeader << " Configuration group: " << theGroup << std::endl;
00302 }
00303
00304 std::set<std::string>::const_iterator contextFindIt, backboneFindIt, iterateFindIt;
00305 for(auto it = nameToConfigurationMap_.begin(); it != nameToConfigurationMap_.end(); )
00306 {
00307 contextFindIt = contextMemberNames_.find(it->first);
00308 backboneFindIt = backboneMemberNames_.find(it->first);
00309 iterateFindIt = iterateMemberNames_.find(it->first);
00310 if(theGroup == "" || (
00311 (isContext && contextFindIt != contextMemberNames_.end()) ||
00312 (isBackbone && backboneFindIt != backboneMemberNames_.end()) ||
00313 (isIterate && iterateFindIt != iterateMemberNames_.end()) ||
00314 (!isContext && !isBackbone &&
00315 contextFindIt == contextMemberNames_.end() &&
00316 backboneFindIt == backboneMemberNames_.end()&&
00317 iterateFindIt == iterateMemberNames_.end())))
00318 {
00319
00320
00321
00322
00323
00324 if(onlyDeactivate)
00325 {
00326 it->second->deactivate();
00327 ++it;
00328 }
00329 else
00330 {
00331 delete it->second;
00332 nameToConfigurationMap_.erase(it++);
00333 }
00334 }
00335 else
00336 ++it;
00337 }
00338
00339 if(isConfiguration)
00340 {
00341 theConfigurationGroup_ = "";
00342 if(theConfigurationGroupKey_ != 0)
00343 {
00344 __COUT__ << "Destroying Configuration Key: " << *theConfigurationGroupKey_ << std::endl;
00345 theConfigurationGroupKey_.reset();
00346 }
00347
00348
00349 }
00350 if(isBackbone)
00351 {
00352 theBackboneGroup_ = "";
00353 if(theBackboneGroupKey_ != 0)
00354 {
00355 __COUT__ << "Destroying Backbone Key: " << *theBackboneGroupKey_ << std::endl;
00356 theBackboneGroupKey_.reset();
00357 }
00358 }
00359 if(isIterate)
00360 {
00361 theIterateGroup_ = "";
00362 if(theIterateGroupKey_ != 0)
00363 {
00364 __COUT__ << "Destroying Iterate Key: " << *theIterateGroupKey_ << std::endl;
00365 theIterateGroupKey_.reset();
00366 }
00367 }
00368 if(isContext)
00369 {
00370 theContextGroup_ = "";
00371 if(theContextGroupKey_ != 0)
00372 {
00373 __COUT__ << "Destroying Context Key: " << *theContextGroupKey_ << std::endl;
00374 theContextGroupKey_.reset();
00375 }
00376 }
00377 }
00378
00379
00380 void ConfigurationManager::destroy(void)
00381 {
00382
00383
00384
00385 destroyConfigurationGroup();
00386 }
00387
00388
00389
00390
00391
00392
00393
00394
00395 const std::string& ConfigurationManager::convertGroupTypeIdToName(int groupTypeId)
00396 {
00397 return groupTypeId==CONTEXT_TYPE?
00398 ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT:
00399 (groupTypeId==BACKBONE_TYPE?
00400 ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE:
00401 (groupTypeId==ITERATE_TYPE?
00402 ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE:
00403 ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION));
00404 }
00405
00406
00407
00408
00409
00410
00411
00412
00413 int ConfigurationManager::getTypeOfGroup(
00414 const std::map<std::string /*name*/, ConfigurationVersion /*version*/> &memberMap)
00415 {
00416
00417 bool isContext = true;
00418 bool isBackbone = true;
00419 bool isIterate = true;
00420 bool inGroup;
00421 bool inContext = false;
00422 bool inBackbone = false;
00423 bool inIterate = false;
00424 unsigned int matchCount = 0;
00425
00426 for(auto &memberPair:memberMap)
00427 {
00428
00430 inGroup = false;
00431 for(auto &contextMemberString:contextMemberNames_)
00432 if(memberPair.first == contextMemberString)
00433 {
00434 inGroup = true;
00435 inContext = true;
00436 ++matchCount;
00437 break;
00438 }
00439 if(!inGroup)
00440 {
00441 isContext = false;
00442 if(inContext)
00443 {
00444 __SS__ << "This group is an incomplete match to a Context group.\n";
00445 __COUT_ERR__ << "\n" << ss.str();
00446 ss << "\nTo be a Context group, the members must exactly match" <<
00447 "the following members:\n";
00448 int i = 0;
00449 for(auto &memberName:contextMemberNames_)
00450 ss << ++i << ". " << memberName << "\n";
00451 throw std::runtime_error(ss.str());
00452 }
00453 }
00454
00456 inGroup = false;
00457 for(auto &backboneMemberString:backboneMemberNames_)
00458 if(memberPair.first == backboneMemberString)
00459 {
00460 inGroup = true;
00461 inBackbone = true;
00462 ++matchCount;
00463 break;
00464 }
00465 if(!inGroup)
00466 {
00467 isBackbone = false;
00468 if(inBackbone)
00469 {
00470 __SS__ << "This group is an incomplete match to a Backbone group.\n";
00471 __COUT_ERR__ << "\n" << ss.str();
00472 ss << "\nTo be a Backbone group, the members must exactly match" <<
00473 "the following members:\n";
00474 int i = 0;
00475 for(auto &memberName:backboneMemberNames_)
00476 ss << ++i << ". " << memberName << "\n";
00477
00478 throw std::runtime_error(ss.str());
00479 }
00480 }
00481
00483 inGroup = false;
00484 for(auto &iterateMemberString:iterateMemberNames_)
00485 if(memberPair.first == iterateMemberString)
00486 {
00487 inGroup = true;
00488 inIterate = true;
00489 ++matchCount;
00490 break;
00491 }
00492 if(!inGroup)
00493 {
00494 isIterate = false;
00495 if(inIterate)
00496 {
00497 __SS__ << "This group is an incomplete match to a Iterate group.\n";
00498 __COUT_ERR__ << "\n" << ss.str();
00499 ss << "\nTo be a Iterate group, the members must exactly match" <<
00500 "the following members:\n";
00501 int i = 0;
00502 for(auto &memberName:iterateMemberNames_)
00503 ss << ++i << ". " << memberName << "\n";
00504
00505 throw std::runtime_error(ss.str());
00506 }
00507 }
00508 }
00509
00510 if(isContext && matchCount != contextMemberNames_.size())
00511 {
00512 __SS__ << "This group is an incomplete match to a Context group: " <<
00513 " Size=" << matchCount << " but should be " << contextMemberNames_.size() <<
00514 std::endl;
00515 __COUT_ERR__ << "\n" << ss.str();
00516 ss << "\nThe members currently are...\n";
00517 int i = 0;
00518 for(auto &memberPair:memberMap)
00519 ss << ++i << ". " << memberPair.first << "\n";
00520 ss << "\nThe expected Context members are...\n";
00521 i = 0;
00522 for(auto &memberName:contextMemberNames_)
00523 ss << ++i << ". " << memberName << "\n";
00524
00525 throw std::runtime_error(ss.str());
00526 }
00527
00528 if(isBackbone && matchCount != backboneMemberNames_.size())
00529 {
00530 __SS__ << "This group is an incomplete match to a Backbone group: " <<
00531 " Size=" << matchCount << " but should be " << backboneMemberNames_.size() <<
00532 std::endl;
00533 __COUT_ERR__ << "\n" << ss.str();
00534 ss << "\nThe members currently are...\n";
00535 int i = 0;
00536 for(auto &memberPair:memberMap)
00537 ss << ++i << ". " << memberPair.first << "\n";
00538 ss << "\nThe expected Backbone members are...\n";
00539 i = 0;
00540 for(auto &memberName:backboneMemberNames_)
00541 ss << ++i << ". " << memberName << "\n";
00542
00543 throw std::runtime_error(ss.str());
00544 }
00545
00546 if(isIterate && matchCount != iterateMemberNames_.size())
00547 {
00548 __SS__ << "This group is an incomplete match to a Iterate group: " <<
00549 " Size=" << matchCount << " but should be " << backboneMemberNames_.size() <<
00550 std::endl;
00551 __COUT_ERR__ << "\n" << ss.str();
00552 ss << "\nThe members currently are...\n";
00553 int i = 0;
00554 for(auto &memberPair:memberMap)
00555 ss << ++i << ". " << memberPair.first << "\n";
00556 ss << "\nThe expected Iterate members are...\n";
00557 i = 0;
00558 for(auto &memberName:iterateMemberNames_)
00559 ss << ++i << ". " << memberName << "\n";
00560
00561 throw std::runtime_error(ss.str());
00562 }
00563
00564 return isContext?CONTEXT_TYPE:(isBackbone?BACKBONE_TYPE:(isIterate?ITERATE_TYPE:CONFIGURATION_TYPE));
00565 }
00566
00567
00568
00569
00570 const std::string& ConfigurationManager::getTypeNameOfGroup(
00571 const std::map<std::string /*name*/, ConfigurationVersion /*version*/> &memberMap)
00572 {
00573 return convertGroupTypeIdToName(getTypeOfGroup(memberMap));
00574 }
00575
00576
00577
00578
00579
00580 void ConfigurationManager::dumpActiveConfiguration(
00581 const std::string &filePath, const std::string &dumpType) const
00582 {
00583 time_t rawtime = time(0);
00584 __COUT__ << "filePath = " << filePath << std::endl;
00585 __COUT__ << "dumpType = " << dumpType << std::endl;
00586
00587
00588 std::ofstream fs;
00589 fs.open(filePath, std::fstream::out | std::fstream::trunc);
00590
00591 std::ostream *out;
00592
00593
00594 if(fs.is_open())
00595 out = &fs;
00596 else
00597 out = &(std::cout);
00598
00599
00600 (*out) << "#################################" << std::endl;
00601 (*out) << "This is an ots configuration dump.\n\n" << std::endl;
00602 (*out) << "Source database is $ARTDAQ_DATABASE_URI = \t" << getenv("ARTDAQ_DATABASE_URI") << std::endl;
00603 (*out) << "\nOriginal location of dump: \t" << filePath << std::endl;
00604 (*out) << "Type of dump: \t" << dumpType << std::endl;
00605 (*out) << "Linux time for dump: \t" << rawtime << std::endl;
00606
00607 {
00608 struct tm * timeinfo = localtime (&rawtime);
00609 char buffer [100];
00610 strftime(buffer,100,"%c %Z",timeinfo);
00611 (*out) << "Display time for dump: \t" << buffer << std::endl;
00612 }
00613
00614
00615
00616
00617
00618
00619
00620
00621 auto localDumpActiveGroups = [](const ConfigurationManager *cfgMgr, std::ostream *out) {
00622 std::map<std::string, std::pair<std::string, ConfigurationGroupKey>> activeGroups =
00623 cfgMgr->getActiveConfigurationGroups();
00624
00625 (*out) << "\n\n************************" << std::endl;
00626 (*out) << "Active Groups:" << std::endl;
00627 for(auto &group:activeGroups)
00628 {
00629 (*out) << "\t" << group.first << " := " <<
00630 group.second.first << " (" <<
00631 group.second.second << ")" << std::endl;
00632 }
00633 };
00634
00635 auto localDumpActiveTables = [](const ConfigurationManager *cfgMgr, std::ostream *out) {
00636 std::map<std::string, ConfigurationVersion> activeTables =
00637 cfgMgr->getActiveVersions();
00638
00639 (*out) << "\n\n************************" << std::endl;
00640 (*out) << "Active Tables:" << std::endl;
00641 (*out) << "Active Tables count = " << activeTables.size() << std::endl;
00642
00643 unsigned int i = 0;
00644 for(auto &table:activeTables)
00645 {
00646 (*out) << "\t" << ++i << ". " << table.first << "-v" <<
00647 table.second << std::endl;
00648 }
00649 };
00650
00651 auto localDumpActiveGroupMembers = [](const ConfigurationManager *cfgMgr, std::ostream *out) {
00652 std::map<std::string, std::pair<std::string, ConfigurationGroupKey>> activeGroups =
00653 cfgMgr->getActiveConfigurationGroups();
00654 (*out) << "\n\n************************" << std::endl;
00655 (*out) << "Active Group Members:" << std::endl;
00656 int tableCount = 0;
00657 for(auto &group:activeGroups)
00658 {
00659 (*out) << "\t" << group.first << " := " <<
00660 group.second.first << " (" <<
00661 group.second.second << ")" << std::endl;
00662
00663 std::map<std::string , ConfigurationVersion > memberMap =
00664 cfgMgr->theInterface_->getConfigurationGroupMembers(
00665 ConfigurationGroupKey::getFullGroupString(
00666 group.second.first,
00667 group.second.second));
00668
00669 (*out) << "\tMember table count = " << memberMap.size() << std::endl;
00670 tableCount += memberMap.size();
00671
00672 unsigned int i = 0;
00673 for(auto &member:memberMap)
00674 {
00675 (*out) << "\t\t" << ++i << ". " << member.first << "-v" <<
00676 member.second << std::endl;
00677 }
00678 }
00679 (*out) << "\nActive Group Members total table count = " << tableCount << std::endl;
00680 };
00681
00682 auto localDumpActiveTableContents = [](const ConfigurationManager *cfgMgr, std::ostream *out) {
00683 std::map<std::string, ConfigurationVersion> activeTables =
00684 cfgMgr->getActiveVersions();
00685
00686 (*out) << "\n\n************************" << std::endl;
00687 (*out) << "Active Table Contents (table count = " << activeTables.size()
00688 << "):" << std::endl;
00689 unsigned int i = 0;
00690 for(auto &table:activeTables)
00691 {
00692 (*out) << "\n\n==============================================================================" << std::endl;
00693 (*out) << "==============================================================================" << std::endl;
00694 (*out) << "\t" << ++i << ". " << table.first << "-v" <<
00695 table.second << std::endl;
00696
00697 cfgMgr->nameToConfigurationMap_.find(table.first)->second->print(*out);
00698 }
00699 };
00700
00701
00702
00703 if(dumpType == "GroupKeys")
00704 {
00705 localDumpActiveGroups(this,out);
00706 }
00707 else if(dumpType == "TableVersions")
00708 {
00709 localDumpActiveTables(this,out);
00710 }
00711 else if(dumpType == "GroupKeysAndTableVersions")
00712 {
00713 localDumpActiveGroups(this,out);
00714 localDumpActiveTables(this,out);
00715 }
00716 else if(dumpType == "All")
00717 {
00718 localDumpActiveGroups(this,out);
00719 localDumpActiveGroupMembers(this,out);
00720 localDumpActiveTables(this,out);
00721 localDumpActiveTableContents(this,out);
00722 }
00723 else
00724 {
00725 __SS__ << "Invalid dump type '" << dumpType <<
00726 "' given during dumpActiveConfiguration(). Valid types are as follows:\n" <<
00727
00728
00729 "GroupKeys" << ", " <<
00730 "TableVersions" << ", " <<
00731 "GroupsKeysAndTableVersions" << ", " <<
00732 "All" <<
00733
00734 "\n\nPlease change the State Machine configuration to a valid dump type." <<
00735 std::endl;
00736 throw std::runtime_error(ss.str());
00737 }
00738
00739 if(fs.is_open())
00740 fs.close();
00741 }
00742
00743
00744
00745
00746
00747 void ConfigurationManager::loadMemberMap(
00748 const std::map<std::string /*name*/, ConfigurationVersion /*version*/> &memberMap)
00749 {
00750 ConfigurationBase *tmpConfigBasePtr;
00751
00752
00753 for(auto &memberPair:memberMap)
00754 {
00755
00756
00757
00758
00759
00760
00761
00762
00763 tmpConfigBasePtr = 0;
00764 if(nameToConfigurationMap_.find(memberPair.first) != nameToConfigurationMap_.end())
00765 tmpConfigBasePtr = nameToConfigurationMap_[memberPair.first];
00766
00767 theInterface_->get(tmpConfigBasePtr,
00768 memberPair.first,
00769 0,
00770 0,
00771 false,
00772 memberPair.second,
00773 false
00774 );
00775
00776 nameToConfigurationMap_[memberPair.first] = tmpConfigBasePtr;
00777 if(nameToConfigurationMap_[memberPair.first]->getViewP())
00778 {
00779
00780 }
00781 else
00782 {
00783 __SS__ << nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
00784 ": View version not activated properly!";
00785 throw std::runtime_error(ss.str());
00786 }
00787 }
00788 }
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805 std::map<std::string, ConfigurationVersion> ConfigurationManager::loadConfigurationGroup(
00806 const std::string &configGroupName,
00807 ConfigurationGroupKey configGroupKey,
00808 bool doActivate,
00809 ProgressBar *progressBar,
00810 std::string *accumulatedTreeErrors,
00811 std::string *groupComment,
00812 std::string *groupAuthor,
00813 std::string *groupCreateTime,
00814 bool doNotLoadMember,
00815 std::string *groupTypeString)
00816 {
00817 if(accumulatedTreeErrors) *accumulatedTreeErrors = "";
00818 if(groupComment) *groupComment = "";
00819 if(groupAuthor) *groupAuthor = "";
00820 if(groupCreateTime) *groupCreateTime = "";
00821 if(groupTypeString) *groupTypeString = "";
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835 __COUT_INFO__ << "Loading Configuration Group: " << configGroupName <<
00836 "(" << configGroupKey << ")" << std::endl;
00837
00838 std::map<std::string , ConfigurationVersion > memberMap =
00839 theInterface_->getConfigurationGroupMembers(
00840 ConfigurationGroupKey::getFullGroupString(configGroupName,configGroupKey),
00841 true);
00842
00843
00844 if(progressBar) progressBar->step();
00845
00846
00847 auto metaTablePair = memberMap.find(groupMetadataTable_.getConfigurationName());
00848 if(metaTablePair !=
00849 memberMap.end())
00850 {
00851
00852
00853
00854 while(groupMetadataTable_.getView().getNumberOfRows())
00855 groupMetadataTable_.getViewP()->deleteRow(0);
00856 theInterface_->fill(&groupMetadataTable_,metaTablePair->second);
00857
00858 if(groupMetadataTable_.getView().getNumberOfRows() != 1)
00859 {
00860 groupMetadataTable_.print();
00861 __SS__ << "groupMetadataTable_ has wrong number of rows! Must be 1." << std::endl;
00862 __COUT_ERR__ << "\n" << ss.str();
00863 throw std::runtime_error(ss.str());
00864 }
00865
00866
00867 memberMap.erase(metaTablePair);
00868
00869
00870 if(groupComment) *groupComment = groupMetadataTable_.getView().getValueAsString(0,1);
00871 if(groupAuthor) *groupAuthor = groupMetadataTable_.getView().getValueAsString(0,2);
00872 if(groupCreateTime) *groupCreateTime = groupMetadataTable_.getView().getValueAsString(0,3);
00873 }
00874
00875 if(progressBar) progressBar->step();
00876
00877 __COUT__ << "memberMap loaded size = " << memberMap.size() << std::endl;
00878
00879 int groupType = -1;
00880 if(groupTypeString)
00881 {
00882 groupType = getTypeOfGroup(memberMap);
00883 *groupTypeString = convertGroupTypeIdToName(groupType);
00884 }
00885
00886 if(doNotLoadMember) return memberMap;
00887
00888 if(doActivate)
00889 __COUT__ << "------------------------------------- loadConfigurationGroup start" << std::endl;
00890
00891
00892
00893 if(!groupTypeString) groupType = getTypeOfGroup(memberMap);
00894
00895 if(doActivate)
00896 {
00897 std::string groupToDeactivate =
00898 groupType==CONTEXT_TYPE?theContextGroup_:
00899 (groupType==BACKBONE_TYPE?theBackboneGroup_:
00900 (groupType==ITERATE_TYPE?
00901 theIterateGroup_:theConfigurationGroup_));
00902
00903
00904 if(groupToDeactivate != "")
00905 {
00906 __COUT__ << "groupToDeactivate '" << groupToDeactivate << "'" << std::endl;
00907 destroyConfigurationGroup(groupToDeactivate,true);
00908 }
00909
00910
00911
00912
00913
00914 }
00915
00916 if(progressBar) progressBar->step();
00917
00918
00919
00920
00921 loadMemberMap(memberMap);
00922
00923 if(progressBar) progressBar->step();
00924
00925 if(accumulatedTreeErrors)
00926 {
00927 __COUT__ << "Checking chosen group for tree errors..." << std::endl;
00928
00929 getChildren(&memberMap, accumulatedTreeErrors);
00930 if(*accumulatedTreeErrors != "")
00931 {
00932 __COUT_ERR__ << "Errors detected while loading Configuration Group: " << configGroupName <<
00933 "(" << configGroupKey << "). Aborting." << std::endl;
00934 return memberMap;
00935 }
00936 }
00937
00938 if(progressBar) progressBar->step();
00939
00940
00941
00942 if(doActivate)
00943 for(auto &memberPair:memberMap)
00944 {
00945
00946 if(ConfigurationInterface::isVersionTrackingEnabled() &&
00947 memberPair.second.isScratchVersion())
00948 {
00949 __SS__ << "Error while activating member Table '" <<
00950 nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
00951 "-v" << memberPair.second <<
00952 " for Configuration Group '" << configGroupName <<
00953 "(" << configGroupKey << ")'. When version tracking is enabled, Scratch views" <<
00954 " are not allowed! Please only use unique, persistent versions when version tracking is enabled."
00955 << std::endl;
00956 __COUT_ERR__ << "\n" << ss.str();
00957 throw std::runtime_error(ss.str());
00958 }
00959
00960
00961
00962
00963 try
00964 {
00965 nameToConfigurationMap_[memberPair.first]->init(this);
00966 }
00967 catch(std::runtime_error& e)
00968 {
00969 __SS__ << "Error detected calling " <<
00970 nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
00971 ".init()!\n\n " << e.what() << std::endl;
00972 throw std::runtime_error(ss.str());
00973 }
00974 catch(...)
00975 {
00976 __SS__ << "Error detected calling " <<
00977 nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
00978 ".init()!\n\n " << std::endl;
00979 throw std::runtime_error(ss.str());
00980 }
00981
00982 }
00983
00984 if(progressBar) progressBar->step();
00985
00986
00987
00988
00989
00990 if(doActivate)
00991 {
00992 if(groupType == CONTEXT_TYPE)
00993 {
00994 __COUT_INFO__ << "Type=Context, Group loaded: " << configGroupName <<
00995 "(" << configGroupKey << ")" << std::endl;
00996 theContextGroup_ = configGroupName;
00997 theContextGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(new ConfigurationGroupKey(configGroupKey));
00998 }
00999 else if(groupType == BACKBONE_TYPE)
01000 {
01001 __COUT_INFO__ << "Type=Backbone, Group loaded: " << configGroupName <<
01002 "(" << configGroupKey << ")" << std::endl;
01003 theBackboneGroup_ = configGroupName;
01004 theBackboneGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(new ConfigurationGroupKey(configGroupKey));
01005 }
01006 else if(groupType == ITERATE_TYPE)
01007 {
01008 __COUT_INFO__ << "Type=Iterate, Group loaded: " << configGroupName <<
01009 "(" << configGroupKey << ")" << std::endl;
01010 theIterateGroup_ = configGroupName;
01011 theIterateGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(new ConfigurationGroupKey(configGroupKey));
01012 }
01013 else
01014 {
01015 __COUT_INFO__ << "Type=Configuration, Group loaded: " << configGroupName <<
01016 "(" << configGroupKey << ")" << std::endl;
01017 theConfigurationGroup_ = configGroupName;
01018 theConfigurationGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(new ConfigurationGroupKey(configGroupKey));
01019 }
01020 }
01021
01022 if(progressBar) progressBar->step();
01023
01024 if(doActivate)
01025 __COUT__ << "------------------------------------- loadConfigurationGroup end" << std::endl;
01026
01027 return memberMap;
01028 }
01029
01030
01031
01032
01033
01034
01035
01036
01037 std::map<std::string, std::pair<std::string, ConfigurationGroupKey> > ConfigurationManager::getActiveConfigurationGroups(void) const
01038 {
01039
01040 std::map<std::string, std::pair<std::string, ConfigurationGroupKey> > retMap;
01041
01042 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT] =
01043 std::pair<std::string,ConfigurationGroupKey>(theContextGroup_ ,theContextGroupKey_ ?*theContextGroupKey_ : ConfigurationGroupKey());
01044 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE] =
01045 std::pair<std::string,ConfigurationGroupKey>(theBackboneGroup_ ,theBackboneGroupKey_ ?*theBackboneGroupKey_ : ConfigurationGroupKey());
01046 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE] =
01047 std::pair<std::string,ConfigurationGroupKey>(theIterateGroup_ ,theIterateGroupKey_ ?*theIterateGroupKey_ : ConfigurationGroupKey());
01048 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION] =
01049 std::pair<std::string,ConfigurationGroupKey>(theConfigurationGroup_,theConfigurationGroupKey_?*theConfigurationGroupKey_: ConfigurationGroupKey());
01050 return retMap;
01051 }
01052
01053
01054 const std::string& ConfigurationManager::getActiveGroupName(const std::string& type) const
01055 {
01056 if(type == "" || type == ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION)
01057 return theConfigurationGroup_;
01058 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT)
01059 return theContextGroup_;
01060 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE)
01061 return theBackboneGroup_;
01062 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE)
01063 return theIterateGroup_;
01064
01065 __SS__ << "Invalid type requested '" << type << "'" << std::endl;
01066 __COUT_ERR__ << ss.str();
01067 throw std::runtime_error(ss.str());
01068 }
01069
01070
01071 ConfigurationGroupKey ConfigurationManager::getActiveGroupKey(const std::string& type) const
01072 {
01073 if(type == "" || type == ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION)
01074 return theConfigurationGroupKey_?*theConfigurationGroupKey_: ConfigurationGroupKey();
01075 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT)
01076 return theContextGroupKey_ ?*theContextGroupKey_ : ConfigurationGroupKey();
01077 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE)
01078 return theBackboneGroupKey_ ?*theBackboneGroupKey_ : ConfigurationGroupKey();
01079 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE)
01080 return theIterateGroupKey_ ?*theIterateGroupKey_ : ConfigurationGroupKey();
01081
01082 __SS__ << "Invalid type requested '" << type << "'" << std::endl;
01083 __COUT_ERR__ << ss.str();
01084 throw std::runtime_error(ss.str());
01085 }
01086
01087
01088
01089 ConfigurationTree ConfigurationManager::getSupervisorConfigurationNode(
01090 const std::string &contextUID, const std::string &applicationUID) const
01091 {
01092 return getNode(
01093 "/" + getConfigurationByName(XDAQ_CONTEXT_CONFIG_NAME)->getConfigurationName() +
01094 "/" + contextUID +
01095 "/LinkToApplicationConfiguration/" + applicationUID +
01096 "/LinkToSupervisorConfiguration");
01097 }
01098
01099
01100 ConfigurationTree ConfigurationManager::getNode(const std::string& nodeString,
01101 bool doNotThrowOnBrokenUIDLinks) const
01102 {
01103
01104
01105
01106 if(nodeString.length() < 1)
01107 {
01108 __SS__ << ("Invalid empty node name") << std::endl;
01109 __COUT_ERR__ << ss.str();
01110 throw std::runtime_error(ss.str());
01111 }
01112
01113
01114 unsigned int startingIndex = 0;
01115 while(startingIndex < nodeString.length() &&
01116 nodeString[startingIndex] == '/') ++startingIndex;
01117
01118 std::string nodeName = nodeString.substr(startingIndex, nodeString.find('/',startingIndex)-startingIndex);
01119
01120 if(nodeName.length() < 1)
01121 {
01122 __SS__ << "Invalid node name: " << nodeName << std::endl;
01123 __COUT_ERR__ << ss.str();
01124 throw std::runtime_error(ss.str());
01125 }
01126
01127 std::string childPath = nodeString.substr(nodeName.length() + startingIndex);
01128
01129
01130
01131 ConfigurationTree configTree(this, getConfigurationByName(nodeName));
01132
01133 if(childPath.length() > 1)
01134 return configTree.getNode(childPath,doNotThrowOnBrokenUIDLinks);
01135 else
01136 return configTree;
01137 }
01138
01139
01140
01141 std::string ConfigurationManager::getFirstPathToNode(const ConfigurationTree &node, const std::string &startPath) const
01142
01143 {
01144 std::string path = "/";
01145 return path;
01146 }
01147
01148
01149
01150
01151
01152
01153
01154 std::vector<std::pair<std::string,ConfigurationTree> > ConfigurationManager::getChildren(
01155 std::map<std::string, ConfigurationVersion> *memberMap,
01156 std::string *accumulatedTreeErrors) const
01157 {
01158 std::vector<std::pair<std::string,ConfigurationTree> > retMap;
01159 if(accumulatedTreeErrors) *accumulatedTreeErrors = "";
01160
01161 if(!memberMap || memberMap->empty())
01162 {
01163 for(auto &configPair:nameToConfigurationMap_)
01164 {
01165
01166
01167 if(configPair.second->isActive())
01168 {
01169 ConfigurationTree newNode(this, configPair.second);
01170
01171
01172 if(accumulatedTreeErrors)
01173 {
01174 try
01175 {
01176 std::vector<std::pair<std::string,ConfigurationTree> > newNodeChildren =
01177 newNode.getChildren();
01178 for(auto &newNodeChild: newNodeChildren)
01179 {
01180 std::vector<std::pair<std::string,ConfigurationTree> > twoDeepChildren =
01181 newNodeChild.second.getChildren();
01182
01183 for(auto &twoDeepChild: twoDeepChildren)
01184 {
01185
01186
01187 if(twoDeepChild.second.isLinkNode() &&
01188 twoDeepChild.second.isDisconnected() &&
01189 twoDeepChild.second.getDisconnectedTableName() !=
01190 ViewColumnInfo::DATATYPE_LINK_DEFAULT)
01191 *accumulatedTreeErrors += "\n\nAt node '" +
01192 configPair.first + "' with entry UID '" +
01193 newNodeChild.first + "' there is a disconnected child node at link column '" +
01194 twoDeepChild.first + "'" +
01195 " that points to table named '" +
01196 twoDeepChild.second.getDisconnectedTableName() +
01197 "' ...";
01198 }
01199 }
01200 }
01201 catch(std::runtime_error &e)
01202 {
01203 *accumulatedTreeErrors += "\n\nAt node '" +
01204 configPair.first + "' error detected descending through children:\n" +
01205 e.what();
01206 }
01207 }
01208
01209 retMap.push_back(std::pair<std::string,ConfigurationTree>(configPair.first,
01210 newNode));
01211 }
01212
01213
01214 }
01215 }
01216 else
01217 {
01218
01219 for(auto &memberPair: *memberMap)
01220 {
01221 auto mapIt = nameToConfigurationMap_.find(memberPair.first);
01222 if(mapIt == nameToConfigurationMap_.end())
01223 {
01224 __SS__ << "Get Children with member map requires a child '" <<
01225 memberPair.first << "' that is not present!" << std::endl;
01226 throw std::runtime_error(ss.str());
01227 }
01228 if(!(*mapIt).second->isActive())
01229 {
01230 __SS__ << "Get Children with member map requires a child '" <<
01231 memberPair.first << "' that is not active!" << std::endl;
01232 throw std::runtime_error(ss.str());
01233 }
01234
01235 ConfigurationTree newNode(this, (*mapIt).second);
01236
01237 if(accumulatedTreeErrors)
01238 {
01239 try
01240 {
01241 std::vector<std::pair<std::string,ConfigurationTree> > newNodeChildren =
01242 newNode.getChildren();
01243 for(auto &newNodeChild: newNodeChildren)
01244 {
01245 std::vector<std::pair<std::string,ConfigurationTree> > twoDeepChildren =
01246 newNodeChild.second.getChildren();
01247
01248 for(auto &twoDeepChild: twoDeepChildren)
01249 {
01250
01251
01252 if(twoDeepChild.second.isLinkNode() &&
01253 twoDeepChild.second.isDisconnected() &&
01254 twoDeepChild.second.getDisconnectedTableName() !=
01255 ViewColumnInfo::DATATYPE_LINK_DEFAULT)
01256 {
01257 *accumulatedTreeErrors += "\n\nAt node '" +
01258 memberPair.first + "' with entry UID '" +
01259 newNodeChild.first + "' there is a disconnected child node at link column '" +
01260 twoDeepChild.first + "'" +
01261 " that points to table named '" +
01262 twoDeepChild.second.getDisconnectedTableName() +
01263 "' ...";
01264
01265
01266
01267 bool found = false;
01268 for(auto &searchMemberPair: *memberMap)
01269 if(searchMemberPair.first ==
01270 twoDeepChild.second.getDisconnectedTableName())
01271 { found = true; break;}
01272 if(!found)
01273 *accumulatedTreeErrors +=
01274 std::string("\nNote: It may be safe to ignore this error ") +
01275 "since the link's target table " +
01276 twoDeepChild.second.getDisconnectedTableName() +
01277 " is not a member of this group (and may not be loaded yet).";
01278 }
01279 }
01280 }
01281 }
01282 catch(std::runtime_error &e)
01283 {
01284 *accumulatedTreeErrors += "\n\nAt node '" +
01285 memberPair.first + "' error detected descending through children:\n" +
01286 e.what();
01287 }
01288 }
01289
01290 retMap.push_back(std::pair<std::string,ConfigurationTree>(memberPair.first,
01291 newNode));
01292 }
01293 }
01294
01295 return retMap;
01296 }
01297
01298
01299
01300
01301
01302
01303 const ConfigurationBase* ConfigurationManager::getConfigurationByName(const std::string &configurationName) const
01304 {
01305 std::map<std::string, ConfigurationBase*>::const_iterator it;
01306 if((it = nameToConfigurationMap_.find(configurationName)) == nameToConfigurationMap_.end())
01307 {
01308 __SS__ << "\n\nCan not find configuration named '" <<
01309 configurationName <<
01310 "'\n\n\n\nYou need to load the configuration before it can be used." <<
01311 " It probably is missing from the member list of the Configuration Group that was loaded.\n" <<
01312 "\nYou may need to enter wiz mode to remedy the situation, use the following:\n" <<
01313 "\n\t StartOTS.sh --wiz" <<
01314 "\n\n\n\n"
01315 << std::endl;
01316
01317
01318
01319 throw std::runtime_error(ss.str());
01320 }
01321 return it->second;
01322 }
01323
01324
01325
01326
01327
01328 ConfigurationGroupKey ConfigurationManager::loadConfigurationBackbone()
01329 {
01330 if(!theBackboneGroupKey_)
01331 {
01332 __COUT_WARN__ << "getConfigurationGroupKey() Failed! No active backbone currently." << std::endl;
01333 return ConfigurationGroupKey();
01334 }
01335
01336
01337 loadConfigurationGroup(theBackboneGroup_,*theBackboneGroupKey_);
01338
01339 return *theBackboneGroupKey_;
01340 }
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357 std::pair<std::string, ConfigurationGroupKey> ConfigurationManager::getConfigurationGroupFromAlias(
01358 std::string systemAlias, ProgressBar* progressBar)
01359 {
01360
01361
01362
01363
01364
01365
01366
01367
01368 if(progressBar) progressBar->step();
01369
01370 if(systemAlias.find("GROUP:") == 0)
01371 {
01372 if(progressBar) progressBar->step();
01373
01374 unsigned int i = strlen("GROUP:");
01375 unsigned int j = systemAlias.find(':',i);
01376
01377 if(progressBar) progressBar->step();
01378 if(j>i)
01379 return std::pair<std::string, ConfigurationGroupKey>(
01380 systemAlias.substr(i,j-i),
01381 ConfigurationGroupKey(systemAlias.substr(j+1)));
01382 else
01383 return std::pair<std::string, ConfigurationGroupKey>("",ConfigurationGroupKey());
01384 }
01385
01386
01387 loadConfigurationBackbone();
01388
01389 if(progressBar) progressBar->step();
01390
01391 try
01392 {
01393
01394 ConfigurationTree entry = getNode("GroupAliasesConfiguration").getNode(systemAlias);
01395
01396 if(progressBar) progressBar->step();
01397
01398 return std::pair<std::string, ConfigurationGroupKey>(entry.getNode("GroupName").getValueAsString(), ConfigurationGroupKey(entry.getNode("GroupKey").getValueAsString()));
01399 }
01400 catch(...)
01401 {}
01402
01403
01404
01405 if(progressBar) progressBar->step();
01406
01407 return std::pair<std::string, ConfigurationGroupKey>("",ConfigurationGroupKey());
01408 }
01409
01410
01411
01412 std::map<std::string, std::pair<std::string, ConfigurationGroupKey> > ConfigurationManager::getGroupAliasesConfiguration(void)
01413 {
01414 restoreActiveConfigurationGroups();
01415
01416
01417 std::map<std::string ,
01418 std::pair<std::string , ConfigurationGroupKey> > retMap;
01419
01420 std::vector<std::pair<std::string,ConfigurationTree> > entries = getNode("GroupAliasesConfiguration").getChildren();
01421 for(auto &entryPair: entries)
01422 {
01423 retMap[entryPair.first] = std::pair<std::string, ConfigurationGroupKey>(
01424 entryPair.second.getNode("GroupName").getValueAsString(),
01425 ConfigurationGroupKey(entryPair.second.getNode("GroupKey").getValueAsString()));
01426
01427 }
01428 return retMap;
01429 }
01430
01431
01432
01433 std::map<std::string, ConfigurationVersion> ConfigurationManager::getActiveVersions(void) const
01434 {
01435 std::map<std::string, ConfigurationVersion> retMap;
01436 for(auto &config:nameToConfigurationMap_)
01437 {
01438
01439
01440
01441 if(config.second && config.second->isActive())
01442 {
01443
01444 retMap.insert(std::pair<std::string, ConfigurationVersion>(config.first, config.second->getViewVersion()));
01445 }
01446 }
01447 return retMap;
01448 }
01449
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472 std::shared_ptr<ConfigurationGroupKey> ConfigurationManager::makeTheConfigurationGroupKey(ConfigurationGroupKey key)
01473 {
01474 if(theConfigurationGroupKey_)
01475 {
01476 if(*theConfigurationGroupKey_ != key)
01477 destroyConfigurationGroup();
01478 else
01479 return theConfigurationGroupKey_;
01480 }
01481 return std::shared_ptr<ConfigurationGroupKey>(new ConfigurationGroupKey(key));
01482 }
01483
01484
01485 std::string ConfigurationManager::encodeURIComponent(const std::string &sourceStr)
01486 {
01487 std::string retStr = "";
01488 char encodeStr[4];
01489 for(const auto &c:sourceStr)
01490 if(
01491 (c >= 'a' && c <= 'z') ||
01492 (c >= 'A' && c <= 'Z') ||
01493 (c >= '0' && c <= '9') )
01494 retStr += c;
01495 else
01496 {
01497 sprintf(encodeStr,"%%%2.2X",c);
01498 retStr += encodeStr;
01499 }
01500 return retStr;
01501 }
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511