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 to dump active configuration. File " << filePath << " 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
00845
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
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
00938
00939 if(!groupTypeString) groupType = getTypeOfGroup(memberMap);
00940
00941 if(doActivate)
00942 __COUT__ << "------------------------------------- init start \t [for all plug-ins in " <<
00943 convertGroupTypeIdToName(groupType) << " group '" <<
00944 configGroupName << "(" << configGroupKey << ")" << "']" << std::endl;
00945
00946 if(doActivate)
00947 {
00948 std::string groupToDeactivate =
00949 groupType==CONTEXT_TYPE?theContextGroup_:
00950 (groupType==BACKBONE_TYPE?theBackboneGroup_:
00951 (groupType==ITERATE_TYPE?
00952 theIterateGroup_:theConfigurationGroup_));
00953
00954
00955 if(groupToDeactivate != "")
00956 {
00957
00958 destroyConfigurationGroup(groupToDeactivate,true);
00959 }
00960
00961
00962
00963
00964
00965 }
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977 if(progressBar) progressBar->step();
00978
00979
00980
00981
00982 loadMemberMap(memberMap);
00983
00984 if(progressBar) progressBar->step();
00985
00986 if(accumulatedTreeErrors)
00987 {
00988
00989
00990 getChildren(&memberMap, accumulatedTreeErrors);
00991 if(*accumulatedTreeErrors != "")
00992 {
00993 __COUT_ERR__ << "Errors detected while loading Configuration Group: " << configGroupName <<
00994 "(" << configGroupKey << "). Aborting." << std::endl;
00995 return;
00996 }
00997 }
00998
00999 if(progressBar) progressBar->step();
01000
01001
01002
01003 if(doActivate)
01004 for(auto &memberPair:memberMap)
01005 {
01006
01007 if(ConfigurationInterface::isVersionTrackingEnabled() &&
01008 memberPair.second.isScratchVersion())
01009 {
01010 __SS__ << "Error while activating member Table '" <<
01011 nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
01012 "-v" << memberPair.second <<
01013 " for Configuration Group '" << configGroupName <<
01014 "(" << configGroupKey << ")'. When version tracking is enabled, Scratch views" <<
01015 " are not allowed! Please only use unique, persistent versions when version tracking is enabled."
01016 << std::endl;
01017 __COUT_ERR__ << "\n" << ss.str();
01018 throw std::runtime_error(ss.str());
01019 }
01020
01021
01022
01023
01024 try
01025 {
01026 nameToConfigurationMap_[memberPair.first]->init(this);
01027 }
01028 catch(std::runtime_error& e)
01029 {
01030 __SS__ << "Error detected calling " <<
01031 nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
01032 ".init()!\n\n " << e.what() << std::endl;
01033 throw std::runtime_error(ss.str());
01034 }
01035 catch(...)
01036 {
01037 __SS__ << "Error detected calling " <<
01038 nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
01039 ".init()!\n\n " << std::endl;
01040 throw std::runtime_error(ss.str());
01041 }
01042
01043 }
01044
01045 if(progressBar) progressBar->step();
01046
01047
01048
01049
01050
01051 if(doActivate)
01052 {
01053 if(groupType == CONTEXT_TYPE)
01054 {
01055
01056
01057 theContextGroup_ = configGroupName;
01058 theContextGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(new ConfigurationGroupKey(configGroupKey));
01059 }
01060 else if(groupType == BACKBONE_TYPE)
01061 {
01062
01063
01064 theBackboneGroup_ = configGroupName;
01065 theBackboneGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(new ConfigurationGroupKey(configGroupKey));
01066 }
01067 else if(groupType == ITERATE_TYPE)
01068 {
01069
01070
01071 theIterateGroup_ = configGroupName;
01072 theIterateGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(new ConfigurationGroupKey(configGroupKey));
01073 }
01074 else
01075 {
01076
01077
01078 theConfigurationGroup_ = configGroupName;
01079 theConfigurationGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(new ConfigurationGroupKey(configGroupKey));
01080 }
01081 }
01082
01083 if(progressBar) progressBar->step();
01084
01085 if(doActivate)
01086 __COUT__ << "------------------------------------- init complete \t [for all plug-ins in " <<
01087 convertGroupTypeIdToName(groupType) << " group '" <<
01088 configGroupName << "(" << configGroupKey << ")" << "']" << std::endl;
01089
01090 return;
01091 }
01092
01093
01094
01095
01096
01097
01098
01099
01100 std::map<std::string, std::pair<std::string, ConfigurationGroupKey> > ConfigurationManager::getActiveConfigurationGroups(void) const
01101 {
01102
01103 std::map<std::string, std::pair<std::string, ConfigurationGroupKey> > retMap;
01104
01105 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT] =
01106 std::pair<std::string,ConfigurationGroupKey>(theContextGroup_ ,theContextGroupKey_ ?*theContextGroupKey_ : ConfigurationGroupKey());
01107 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE] =
01108 std::pair<std::string,ConfigurationGroupKey>(theBackboneGroup_ ,theBackboneGroupKey_ ?*theBackboneGroupKey_ : ConfigurationGroupKey());
01109 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE] =
01110 std::pair<std::string,ConfigurationGroupKey>(theIterateGroup_ ,theIterateGroupKey_ ?*theIterateGroupKey_ : ConfigurationGroupKey());
01111 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION] =
01112 std::pair<std::string,ConfigurationGroupKey>(theConfigurationGroup_,theConfigurationGroupKey_?*theConfigurationGroupKey_: ConfigurationGroupKey());
01113 return retMap;
01114 }
01115
01116
01117 const std::string& ConfigurationManager::getActiveGroupName(const std::string& type) const
01118 {
01119 if(type == "" || type == ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION)
01120 return theConfigurationGroup_;
01121 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT)
01122 return theContextGroup_;
01123 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE)
01124 return theBackboneGroup_;
01125 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE)
01126 return theIterateGroup_;
01127
01128 __SS__ << "Invalid type requested '" << type << "'" << std::endl;
01129 __COUT_ERR__ << ss.str();
01130 throw std::runtime_error(ss.str());
01131 }
01132
01133
01134 ConfigurationGroupKey ConfigurationManager::getActiveGroupKey(const std::string& type) const
01135 {
01136 if(type == "" || type == ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION)
01137 return theConfigurationGroupKey_?*theConfigurationGroupKey_: ConfigurationGroupKey();
01138 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT)
01139 return theContextGroupKey_ ?*theContextGroupKey_ : ConfigurationGroupKey();
01140 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE)
01141 return theBackboneGroupKey_ ?*theBackboneGroupKey_ : ConfigurationGroupKey();
01142 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE)
01143 return theIterateGroupKey_ ?*theIterateGroupKey_ : ConfigurationGroupKey();
01144
01145 __SS__ << "Invalid type requested '" << type << "'" << std::endl;
01146 __COUT_ERR__ << ss.str();
01147 throw std::runtime_error(ss.str());
01148 }
01149
01150
01151 ConfigurationTree ConfigurationManager::getContextNode(
01152 const std::string &contextUID, const std::string &applicationUID) const
01153 {
01154 return getNode(
01155 "/" + getConfigurationByName(XDAQ_CONTEXT_CONFIG_NAME)->getConfigurationName() +
01156 "/" + contextUID);
01157 }
01158
01159
01160 ConfigurationTree ConfigurationManager::getSupervisorNode(
01161 const std::string &contextUID, const std::string &applicationUID) const
01162 {
01163 return getNode(
01164 "/" + getConfigurationByName(XDAQ_CONTEXT_CONFIG_NAME)->getConfigurationName() +
01165 "/" + contextUID +
01166 "/LinkToApplicationConfiguration/" + applicationUID);
01167 }
01168
01169
01170 ConfigurationTree ConfigurationManager::getSupervisorConfigurationNode(
01171 const std::string &contextUID, const std::string &applicationUID) const
01172 {
01173 return getNode(
01174 "/" + getConfigurationByName(XDAQ_CONTEXT_CONFIG_NAME)->getConfigurationName() +
01175 "/" + contextUID +
01176 "/LinkToApplicationConfiguration/" + applicationUID +
01177 "/LinkToSupervisorConfiguration");
01178 }
01179
01180
01181 ConfigurationTree ConfigurationManager::getNode(const std::string& nodeString,
01182 bool doNotThrowOnBrokenUIDLinks) const
01183 {
01184
01185
01186
01187 if(nodeString.length() < 1)
01188 {
01189 __SS__ << ("Invalid empty node name") << std::endl;
01190 __COUT_ERR__ << ss.str();
01191 throw std::runtime_error(ss.str());
01192 }
01193
01194
01195 unsigned int startingIndex = 0;
01196 while(startingIndex < nodeString.length() &&
01197 nodeString[startingIndex] == '/') ++startingIndex;
01198
01199 std::string nodeName = nodeString.substr(startingIndex, nodeString.find('/',startingIndex)-startingIndex);
01200
01201 if(nodeName.length() < 1)
01202 {
01203
01204 return ConfigurationTree(this,0);
01205
01206
01207
01208
01209 }
01210
01211 std::string childPath = nodeString.substr(nodeName.length() + startingIndex);
01212
01213
01214
01215 ConfigurationTree configTree(this, getConfigurationByName(nodeName));
01216
01217 if(childPath.length() > 1)
01218 return configTree.getNode(childPath,doNotThrowOnBrokenUIDLinks);
01219 else
01220 return configTree;
01221 }
01222
01223
01224
01225 std::string ConfigurationManager::getFirstPathToNode(const ConfigurationTree &node, const std::string &startPath) const
01226
01227 {
01228 std::string path = "/";
01229 return path;
01230 }
01231
01232
01233
01234
01235
01236
01237
01238 std::vector<std::pair<std::string,ConfigurationTree> > ConfigurationManager::getChildren(
01239 std::map<std::string, ConfigurationVersion> *memberMap,
01240 std::string *accumulatedTreeErrors) const
01241 {
01242 std::vector<std::pair<std::string,ConfigurationTree> > retMap;
01243 if(accumulatedTreeErrors) *accumulatedTreeErrors = "";
01244
01245 if(!memberMap || memberMap->empty())
01246 {
01247 for(auto &configPair:nameToConfigurationMap_)
01248 {
01249
01250
01251 if(configPair.second->isActive())
01252 {
01253 ConfigurationTree newNode(this, configPair.second);
01254
01255
01256 if(accumulatedTreeErrors)
01257 {
01258 try
01259 {
01260 std::vector<std::pair<std::string,ConfigurationTree> > newNodeChildren =
01261 newNode.getChildren();
01262 for(auto &newNodeChild: newNodeChildren)
01263 {
01264 std::vector<std::pair<std::string,ConfigurationTree> > twoDeepChildren =
01265 newNodeChild.second.getChildren();
01266
01267 for(auto &twoDeepChild: twoDeepChildren)
01268 {
01269
01270
01271 if(twoDeepChild.second.isLinkNode() &&
01272 twoDeepChild.second.isDisconnected() &&
01273 twoDeepChild.second.getDisconnectedTableName() !=
01274 ViewColumnInfo::DATATYPE_LINK_DEFAULT)
01275 *accumulatedTreeErrors += "\n\nAt node '" +
01276 configPair.first + "' with entry UID '" +
01277 newNodeChild.first + "' there is a disconnected child node at link column '" +
01278 twoDeepChild.first + "'" +
01279 " that points to table named '" +
01280 twoDeepChild.second.getDisconnectedTableName() +
01281 "' ...";
01282 }
01283 }
01284 }
01285 catch(std::runtime_error &e)
01286 {
01287 *accumulatedTreeErrors += "\n\nAt node '" +
01288 configPair.first + "' error detected descending through children:\n" +
01289 e.what();
01290 }
01291 }
01292
01293 retMap.push_back(std::pair<std::string,ConfigurationTree>(configPair.first,
01294 newNode));
01295 }
01296
01297
01298 }
01299 }
01300 else
01301 {
01302
01303 for(auto &memberPair: *memberMap)
01304 {
01305 auto mapIt = nameToConfigurationMap_.find(memberPair.first);
01306 if(mapIt == nameToConfigurationMap_.end())
01307 {
01308 __SS__ << "Get Children with member map requires a child '" <<
01309 memberPair.first << "' that is not present!" << std::endl;
01310 throw std::runtime_error(ss.str());
01311 }
01312 if(!(*mapIt).second->isActive())
01313 {
01314 __SS__ << "Get Children with member map requires a child '" <<
01315 memberPair.first << "' that is not active!" << std::endl;
01316 throw std::runtime_error(ss.str());
01317 }
01318
01319 ConfigurationTree newNode(this, (*mapIt).second);
01320
01321 if(accumulatedTreeErrors)
01322 {
01323 try
01324 {
01325 std::vector<std::pair<std::string,ConfigurationTree> > newNodeChildren =
01326 newNode.getChildren();
01327 for(auto &newNodeChild: newNodeChildren)
01328 {
01329 std::vector<std::pair<std::string,ConfigurationTree> > twoDeepChildren =
01330 newNodeChild.second.getChildren();
01331
01332 for(auto &twoDeepChild: twoDeepChildren)
01333 {
01334
01335
01336 if(twoDeepChild.second.isLinkNode() &&
01337 twoDeepChild.second.isDisconnected() &&
01338 twoDeepChild.second.getDisconnectedTableName() !=
01339 ViewColumnInfo::DATATYPE_LINK_DEFAULT)
01340 {
01341 *accumulatedTreeErrors += "\n\nAt node '" +
01342 memberPair.first + "' with entry UID '" +
01343 newNodeChild.first + "' there is a disconnected child node at link column '" +
01344 twoDeepChild.first + "'" +
01345 " that points to table named '" +
01346 twoDeepChild.second.getDisconnectedTableName() +
01347 "' ...";
01348
01349
01350
01351 bool found = false;
01352 for(auto &searchMemberPair: *memberMap)
01353 if(searchMemberPair.first ==
01354 twoDeepChild.second.getDisconnectedTableName())
01355 { found = true; break;}
01356 if(!found)
01357 *accumulatedTreeErrors +=
01358 std::string("\nNote: It may be safe to ignore this error ") +
01359 "since the link's target table " +
01360 twoDeepChild.second.getDisconnectedTableName() +
01361 " is not a member of this group (and may not be loaded yet).";
01362 }
01363 }
01364 }
01365 }
01366 catch(std::runtime_error &e)
01367 {
01368 *accumulatedTreeErrors += "\n\nAt node '" +
01369 memberPair.first + "' error detected descending through children:\n" +
01370 e.what();
01371 }
01372 }
01373
01374 retMap.push_back(std::pair<std::string,ConfigurationTree>(memberPair.first,
01375 newNode));
01376 }
01377 }
01378
01379 return retMap;
01380 }
01381
01382
01383
01384
01385
01386
01387 const ConfigurationBase* ConfigurationManager::getConfigurationByName(const std::string &configurationName) const
01388 {
01389 std::map<std::string, ConfigurationBase*>::const_iterator it;
01390 if((it = nameToConfigurationMap_.find(configurationName)) == nameToConfigurationMap_.end())
01391 {
01392 __SS__ << "\n\nCan not find configuration named '" <<
01393 configurationName <<
01394 "'\n\n\n\nYou need to load the configuration before it can be used." <<
01395 " It probably is missing from the member list of the Configuration Group that was loaded.\n" <<
01396 "\nYou may need to enter wiz mode to remedy the situation, use the following:\n" <<
01397 "\n\t StartOTS.sh --wiz" <<
01398 "\n\n\n\n"
01399 << std::endl;
01400
01401
01402
01403 throw std::runtime_error(ss.str());
01404 }
01405 return it->second;
01406 }
01407
01408
01409
01410
01411
01412 ConfigurationGroupKey ConfigurationManager::loadConfigurationBackbone()
01413 {
01414 if(!theBackboneGroupKey_)
01415 {
01416 __COUT_WARN__ << "getConfigurationGroupKey() Failed! No active backbone currently." << std::endl;
01417 return ConfigurationGroupKey();
01418 }
01419
01420
01421 loadConfigurationGroup(theBackboneGroup_,*theBackboneGroupKey_);
01422
01423 return *theBackboneGroupKey_;
01424 }
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441 std::pair<std::string, ConfigurationGroupKey> ConfigurationManager::getConfigurationGroupFromAlias(
01442 std::string systemAlias, ProgressBar* progressBar)
01443 {
01444
01445
01446
01447
01448
01449
01450
01451
01452 if(progressBar) progressBar->step();
01453
01454 if(systemAlias.find("GROUP:") == 0)
01455 {
01456 if(progressBar) progressBar->step();
01457
01458 unsigned int i = strlen("GROUP:");
01459 unsigned int j = systemAlias.find(':',i);
01460
01461 if(progressBar) progressBar->step();
01462 if(j>i)
01463 return std::pair<std::string, ConfigurationGroupKey>(
01464 systemAlias.substr(i,j-i),
01465 ConfigurationGroupKey(systemAlias.substr(j+1)));
01466 else
01467 return std::pair<std::string, ConfigurationGroupKey>("",ConfigurationGroupKey());
01468 }
01469
01470
01471 loadConfigurationBackbone();
01472
01473 if(progressBar) progressBar->step();
01474
01475 try
01476 {
01477
01478 ConfigurationTree entry = getNode("GroupAliasesConfiguration").getNode(systemAlias);
01479
01480 if(progressBar) progressBar->step();
01481
01482 return std::pair<std::string, ConfigurationGroupKey>(entry.getNode("GroupName").getValueAsString(), ConfigurationGroupKey(entry.getNode("GroupKey").getValueAsString()));
01483 }
01484 catch(...)
01485 {}
01486
01487
01488
01489 if(progressBar) progressBar->step();
01490
01491 return std::pair<std::string, ConfigurationGroupKey>("",ConfigurationGroupKey());
01492 }
01493
01494
01495
01496 std::map<std::string, std::pair<std::string, ConfigurationGroupKey> > ConfigurationManager::getGroupAliasesConfiguration(void)
01497 {
01498 restoreActiveConfigurationGroups();
01499
01500
01501 std::map<std::string ,
01502 std::pair<std::string , ConfigurationGroupKey> > retMap;
01503
01504 std::vector<std::pair<std::string,ConfigurationTree> > entries = getNode("GroupAliasesConfiguration").getChildren();
01505 for(auto &entryPair: entries)
01506 {
01507 retMap[entryPair.first] = std::pair<std::string, ConfigurationGroupKey>(
01508 entryPair.second.getNode("GroupName").getValueAsString(),
01509 ConfigurationGroupKey(entryPair.second.getNode("GroupKey").getValueAsString()));
01510
01511 }
01512 return retMap;
01513 }
01514
01515
01516
01517 std::map<std::string, ConfigurationVersion> ConfigurationManager::getActiveVersions(void) const
01518 {
01519 std::map<std::string, ConfigurationVersion> retMap;
01520 for(auto &config:nameToConfigurationMap_)
01521 {
01522
01523
01524
01525 if(config.second && config.second->isActive())
01526 {
01527
01528 retMap.insert(std::pair<std::string, ConfigurationVersion>(config.first, config.second->getViewVersion()));
01529 }
01530 }
01531 return retMap;
01532 }
01533
01535
01536
01537
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547
01548
01549
01550
01551
01552
01553
01554
01555
01556 std::shared_ptr<ConfigurationGroupKey> ConfigurationManager::makeTheConfigurationGroupKey(ConfigurationGroupKey key)
01557 {
01558 if(theConfigurationGroupKey_)
01559 {
01560 if(*theConfigurationGroupKey_ != key)
01561 destroyConfigurationGroup();
01562 else
01563 return theConfigurationGroupKey_;
01564 }
01565 return std::shared_ptr<ConfigurationGroupKey>(new ConfigurationGroupKey(key));
01566 }
01567
01568
01569 std::string ConfigurationManager::encodeURIComponent(const std::string &sourceStr)
01570 {
01571 std::string retStr = "";
01572 char encodeStr[4];
01573 for(const auto &c:sourceStr)
01574 if(
01575 (c >= 'a' && c <= 'z') ||
01576 (c >= 'A' && c <= 'Z') ||
01577 (c >= '0' && c <= '9') )
01578 retStr += c;
01579 else
01580 {
01581 sprintf(encodeStr,"%%%2.2X",c);
01582 retStr += encodeStr;
01583 }
01584 return retStr;
01585 }
01586
01587
01588 const std::set<std::string>& ConfigurationManager::getContextMemberNames()
01589 { return ConfigurationManager::contextMemberNames_; }
01590
01591 const std::set<std::string>& ConfigurationManager::getBackboneMemberNames()
01592 { return ConfigurationManager::backboneMemberNames_; }
01593
01594 const std::set<std::string>& ConfigurationManager::getIterateMemberNames()
01595 { return ConfigurationManager::iterateMemberNames_; }
01596
01597
01598
01599
01600
01601
01602
01603
01604
01605