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