00001 #include "otsdaq-core/ConfigurationInterface/ConfigurationManagerRW.h"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include<dirent.h>
00026
00027 using namespace ots;
00028
00029
00030 #undef __MF_SUBJECT__
00031 #define __MF_SUBJECT__ "ConfigurationManagerRW"
00032
00033 #define CONFIGURATION_INFO_PATH std::string(getenv("CONFIGURATION_INFO_PATH")) + "/"
00034 #define CONFIGURATION_INFO_EXT "Info.xml"
00035
00036
00037
00038 ConfigurationManagerRW::ConfigurationManagerRW(std::string username)
00039 : ConfigurationManager(username)
00040 {
00041 __COUT__ << "Using Config Mgr with Write Access! (for " << username << ")" << std::endl;
00042
00043
00044
00045 theInterface_ = ConfigurationInterface::getInstance(false);
00046
00047 }
00048
00049
00050
00051
00052
00053
00054
00055 const std::map<std::string, ConfigurationInfo>& ConfigurationManagerRW::getAllConfigurationInfo(
00056 bool refresh, std::string *accumulatedErrors, const std::string &errorFilterName)
00057 {
00058
00059
00060 if(accumulatedErrors) *accumulatedErrors = "";
00061
00062 if(!refresh) return allConfigurationInfo_;
00063
00064
00065 allConfigurationInfo_.clear();
00066 allGroupInfo_.clear();
00067
00068 ConfigurationBase* configuration;
00069
00070
00071
00072
00073 __COUT__ << "======================================================== getAllConfigurationInfo start" << std::endl;
00074 __COUT__ << "Refreshing all! Extracting list of Configuration tables..." << std::endl;
00075 DIR *pDIR;
00076 struct dirent *entry;
00077 std::string path = CONFIGURATION_INFO_PATH;
00078 char fileExt[] = CONFIGURATION_INFO_EXT;
00079 const unsigned char MIN_CONFIG_NAME_SZ = 3;
00080 if( (pDIR=opendir( path.c_str() )) != 0 )
00081 {
00082 while((entry = readdir(pDIR)) != 0)
00083 {
00084
00085 if(strlen(entry->d_name) < strlen(fileExt)+MIN_CONFIG_NAME_SZ)
00086 continue;
00087
00088
00089 if( strcmp(
00090 &(entry->d_name[strlen(entry->d_name) - strlen(fileExt)]),
00091 fileExt) != 0)
00092 continue;
00093
00094
00095 entry->d_name[strlen(entry->d_name) - strlen(fileExt)] = '\0';
00096
00097
00098
00099
00100 configuration = 0;
00101
00102 try
00103 {
00104 theInterface_->get(configuration,
00105 entry->d_name,
00106 0, 0,
00107 true);
00108 }
00109 catch(cet::exception)
00110 {
00111 if(configuration) delete configuration;
00112 configuration = 0;
00113
00114 __COUT__ << "Skipping! No valid class found for... " << entry->d_name << "\n";
00115 continue;
00116 }
00117 catch(std::runtime_error &e)
00118 {
00119 if(configuration) delete configuration;
00120 configuration = 0;
00121
00122 __COUT__ << "Skipping! No valid class found for... " << entry->d_name << "\n";
00123 __COUT__ << "Error: " << e.what() << std::endl;
00124
00125
00126
00127
00128
00129 if(accumulatedErrors)
00130 {
00131
00132 if(errorFilterName == "" ||
00133 errorFilterName == entry->d_name)
00134 {
00135 *accumulatedErrors += std::string("\nIn table '") + entry->d_name +
00136 "'..." + e.what();
00137
00138 __SS__ << "Attempting to allow illegal columns!" << std::endl;
00139 *accumulatedErrors += ss.str();
00140 }
00141
00142
00143 __COUT__ << "Attempting to allow illegal columns!" << std::endl;
00144
00145
00146 std::string returnedAccumulatedErrors;
00147 try
00148 {
00149
00150 configuration = new ConfigurationBase(entry->d_name, &returnedAccumulatedErrors);
00151 }
00152 catch(...)
00153 {
00154 __COUT__ << "Skipping! Allowing illegal columns didn't work either... " <<
00155 entry->d_name << "\n";
00156 continue;
00157 }
00158 __COUT__ << "Error (but allowed): " << returnedAccumulatedErrors << std::endl;
00159
00160 if(errorFilterName == "" ||
00161 errorFilterName == entry->d_name)
00162 *accumulatedErrors += std::string("\nIn table '") + entry->d_name +
00163 "'..." + returnedAccumulatedErrors;
00164 }
00165 else
00166 continue;
00167 }
00168
00169
00170
00171 if(nameToConfigurationMap_[entry->d_name])
00172 {
00173
00174 std::set<ConfigurationVersion> versions =
00175 nameToConfigurationMap_[entry->d_name]->getStoredVersions();
00176 for(auto &version:versions)
00177 if(version.isTemporaryVersion())
00178 {
00179 __COUT__ << "copying tmp = " << version << std::endl;
00180
00181 try
00182 {
00183 nameToConfigurationMap_[entry->d_name]->setActiveView(version);
00184 configuration->copyView(
00185 nameToConfigurationMap_[entry->d_name]->getView(),
00186 version,
00187 username_);
00188 }
00189 catch(...)
00190 {}
00191 }
00192
00193 delete nameToConfigurationMap_[entry->d_name];
00194 nameToConfigurationMap_[entry->d_name] = 0;
00195 }
00196
00197 nameToConfigurationMap_[entry->d_name] = configuration;
00198
00199 allConfigurationInfo_[entry->d_name].configurationPtr_ = configuration;
00200 allConfigurationInfo_[entry->d_name].versions_ = theInterface_->getVersions(configuration);
00201
00202
00203
00204 std::set<ConfigurationVersion> versions =
00205 nameToConfigurationMap_[entry->d_name]->getStoredVersions();
00206 for(auto &version:versions)
00207 if(version.isTemporaryVersion())
00208 {
00209 __COUT__ << "surviving tmp = " << version << std::endl;
00210 allConfigurationInfo_[entry->d_name].versions_.emplace(version);
00211 }
00212 }
00213 closedir(pDIR);
00214 }
00215 __COUT__ << "Extracting list of Configuration tables complete" << std::endl;
00216
00217
00218 init(accumulatedErrors);
00219
00220 __COUT__ << "======================================================== getAllConfigurationInfo end" << std::endl;
00221
00222
00223
00224 {
00225 std::set<std::string > configGroups = theInterface_->getAllConfigurationGroupNames();
00226 __COUT__ << "Number of Groups: " << configGroups.size() << std::endl;
00227
00228 ConfigurationGroupKey key;
00229 std::string name;
00230 for(const auto& fullName:configGroups)
00231 {
00232 ConfigurationGroupKey::getGroupNameAndKey(fullName,name,key);
00233 cacheGroupKey(name,key);
00234 }
00235
00236
00237 for(auto& groupInfo:allGroupInfo_)
00238 {
00239 try
00240 {
00241 loadConfigurationGroup(
00242 groupInfo.first ,
00243 groupInfo.second.getLatestKey(),
00244 false ,
00245 &groupInfo.second.latestKeyMemberMap_ ,
00246 0 ,0 ,
00247 &groupInfo.second.latestKeyGroupComment_,
00248 &groupInfo.second.latestKeyGroupAuthor_,
00249 &groupInfo.second.latestKeyGroupCreationTime_,
00250 true ,
00251 &groupInfo.second.latestKeyGroupTypeString_);
00252 }
00253 catch(...)
00254 {
00255 __COUT_WARN__ << "Error occurred loading latest group info into cache for '" <<
00256 groupInfo.first << "'..." << __E__;
00257 groupInfo.second.latestKeyGroupComment_ = "UNKNOWN";
00258 groupInfo.second.latestKeyGroupAuthor_ = "UNKNOWN";
00259 groupInfo.second.latestKeyGroupCreationTime_ = "0";
00260 groupInfo.second.latestKeyGroupTypeString_ = "UNKNOWN";
00261 }
00262 }
00263 }
00264 return allConfigurationInfo_;
00265 }
00266
00267
00268
00269
00270 std::map<std::string,std::map<std::string,ConfigurationVersion> >
00271 ConfigurationManagerRW::getActiveVersionAliases(void) const
00272 {
00273 __COUT__ << "getActiveVersionAliases()" << std::endl;
00274 std::map<std::string,std::map<std::string,ConfigurationVersion> > retMap;
00275
00276 std::map<std::string, ConfigurationVersion> activeVersions = getActiveVersions();
00277 std::string versionAliasesTableName = "VersionAliasesConfiguration";
00278 if(activeVersions.find(versionAliasesTableName) == activeVersions.end())
00279 {
00280 __SS__ << "Active version of VersionAliases missing!" <<
00281 "Make sure you have a valid active Backbone Group." << std::endl;
00282 __COUT_WARN__ << "\n" << ss.str();
00283 return retMap;
00284 }
00285
00286 __COUT__ << "activeVersions[\"VersionAliasesConfiguration\"]=" <<
00287 activeVersions[versionAliasesTableName] << std::endl;
00288
00289
00290 if(!ConfigurationInterface::isVersionTrackingEnabled())
00291 for(const auto &tableInfo:allConfigurationInfo_)
00292 for(const auto &version:tableInfo.second.versions_)
00293 if(version.isScratchVersion())
00294 retMap[tableInfo.first][ConfigurationManager::SCRATCH_VERSION_ALIAS] =
00295 ConfigurationVersion(ConfigurationVersion::SCRATCH);
00296
00297 std::vector<std::pair<std::string,ConfigurationTree> > aliasNodePairs =
00298 getNode(versionAliasesTableName).getChildren();
00299
00300
00301
00302
00303 std::string configName, versionAlias;
00304 for(auto& aliasNodePair:aliasNodePairs)
00305 {
00306 configName = aliasNodePair.second.getNode(
00307 "ConfigurationName").getValueAsString();
00308 versionAlias = aliasNodePair.second.getNode(
00309 "VersionAlias").getValueAsString();
00310
00311 if(retMap.find(configName) != retMap.end() &&
00312 retMap[configName].find(versionAlias) != retMap[configName].end())
00313 continue;
00314
00315
00316 retMap[configName][versionAlias] = ConfigurationVersion(
00317 aliasNodePair.second.getNode("Version").getValueAsString());
00318 }
00319
00320 return retMap;
00321 }
00322
00323
00324
00325
00326
00327 void ConfigurationManagerRW::activateConfigurationGroup(const std::string &configGroupName,
00328 ConfigurationGroupKey configGroupKey, std::string *accumulatedTreeErrors)
00329 {
00330 loadConfigurationGroup(configGroupName,configGroupKey,
00331 true,
00332 0,
00333 0,
00334 accumulatedTreeErrors);
00335
00336 if(accumulatedTreeErrors &&
00337 *accumulatedTreeErrors != "")
00338 {
00339 __COUT_ERR__ << "Errors were accumulated so de-activating group: " <<
00340 configGroupName << " (" << configGroupKey << ")" << std::endl;
00341 try
00342 { destroyConfigurationGroup(configGroupName,true); }
00343 catch(...){}
00344 }
00345
00346 __COUT_INFO__ << "Updating persistent active groups to " <<
00347 ConfigurationManager::ACTIVE_GROUP_FILENAME << " ..." << std::endl;
00348 __MOUT_INFO__ << "Updating persistent active groups to " <<
00349 ConfigurationManager::ACTIVE_GROUP_FILENAME << " ..." << std::endl;
00350
00351 std::string fn = ConfigurationManager::ACTIVE_GROUP_FILENAME;
00352 FILE *fp = fopen(fn.c_str(),"w");
00353 if(!fp)
00354 {
00355 __SS__ << "Fatal Error! Unable to open the file " <<
00356 ConfigurationManager::ACTIVE_GROUP_FILENAME << " for editing! Is there a permissions problem?" << std::endl;
00357 __COUT_ERR__ << ss.str();
00358 throw std::runtime_error(ss.str());
00359 return;
00360 }
00361
00362 __COUT_INFO__ << "Active Context: " << theContextGroup_ << "(" <<
00363 (theContextGroupKey_?theContextGroupKey_->toString().c_str():"-1") << ")" << std::endl;
00364 __COUT_INFO__ << "Active Backbone: " << theBackboneGroup_ << "(" <<
00365 (theBackboneGroupKey_?theBackboneGroupKey_->toString().c_str():"-1") << ")" << std::endl;
00366 __COUT_INFO__ << "Active Iterate: " << theIterateGroup_ << "(" <<
00367 (theIterateGroupKey_?theIterateGroupKey_->toString().c_str():"-1") << ")" << std::endl;
00368 __COUT_INFO__ << "Active Configuration: " << theConfigurationGroup_ << "(" <<
00369 (theConfigurationGroupKey_?theConfigurationGroupKey_->toString().c_str():"-1") << ")" << std::endl;
00370
00371 __MOUT_INFO__ << "Active Context: " << theContextGroup_ << "(" <<
00372 (theContextGroupKey_?theContextGroupKey_->toString().c_str():"-1") << ")" << std::endl;
00373 __MOUT_INFO__ << "Active Backbone: " << theBackboneGroup_ << "(" <<
00374 (theBackboneGroupKey_?theBackboneGroupKey_->toString().c_str():"-1") << ")" << std::endl;
00375 __MOUT_INFO__ << "Active Iterate: " << theIterateGroup_ << "(" <<
00376 (theIterateGroupKey_?theIterateGroupKey_->toString().c_str():"-1") << ")" << std::endl;
00377 __MOUT_INFO__ << "Active Configuration: " << theConfigurationGroup_ << "(" <<
00378 (theConfigurationGroupKey_?theConfigurationGroupKey_->toString().c_str():"-1") << ")" << std::endl;
00379
00380 fprintf(fp,"%s\n",theContextGroup_.c_str());
00381 fprintf(fp,"%s\n",theContextGroupKey_?theContextGroupKey_->toString().c_str():"-1");
00382 fprintf(fp,"%s\n",theBackboneGroup_.c_str());
00383 fprintf(fp,"%s\n",theBackboneGroupKey_?theBackboneGroupKey_->toString().c_str():"-1");
00384 fprintf(fp,"%s\n",theIterateGroup_.c_str());
00385 fprintf(fp,"%s\n",theIterateGroupKey_?theIterateGroupKey_->toString().c_str():"-1");
00386 fprintf(fp,"%s\n",theConfigurationGroup_.c_str());
00387 fprintf(fp,"%s\n",theConfigurationGroupKey_?theConfigurationGroupKey_->toString().c_str():"-1");
00388 fclose(fp);
00389 }
00390
00391
00392
00393
00394
00395 ConfigurationVersion ConfigurationManagerRW::createTemporaryBackboneView(ConfigurationVersion sourceViewVersion)
00396 {
00397 __COUT_INFO__ << "Creating temporary backbone view from version " <<
00398 sourceViewVersion << std::endl;
00399
00400
00401 ConfigurationVersion tmpVersion = ConfigurationVersion::getNextTemporaryVersion();
00402 ConfigurationVersion retTmpVersion;
00403 auto backboneMemberNames = ConfigurationManager::getBackboneMemberNames();
00404 for (auto& name : backboneMemberNames)
00405 {
00406 retTmpVersion = ConfigurationManager::getConfigurationByName(name)->getNextTemporaryVersion();
00407 if(retTmpVersion < tmpVersion)
00408 tmpVersion = retTmpVersion;
00409 }
00410
00411 __COUT__ << "Common temporary backbone version found as " <<
00412 tmpVersion << std::endl;
00413
00414
00415 for (auto& name : backboneMemberNames)
00416 {
00417 retTmpVersion = getConfigurationByName(name)->createTemporaryView(sourceViewVersion, tmpVersion);
00418 if(retTmpVersion != tmpVersion)
00419 {
00420 __SS__ << "Failure! Temporary view requested was " <<
00421 tmpVersion << ". Mismatched temporary view created: " << retTmpVersion << std::endl;
00422 __COUT_ERR__ << ss.str();
00423 throw std::runtime_error(ss.str());
00424 }
00425 }
00426
00427 return tmpVersion;
00428 }
00429
00430
00431
00432
00433 ConfigurationBase* ConfigurationManagerRW::getConfigurationByName(const std::string &configurationName)
00434 {
00435 if(nameToConfigurationMap_.find(configurationName) == nameToConfigurationMap_.end())
00436 {
00437 __SS__ << "Configuration not found with name: " << configurationName << std::endl;
00438 size_t f;
00439 if((f=configurationName.find(' ')) != std::string::npos)
00440 ss << "There was a space character found in the configuration name needle at position " <<
00441 f << " in the string (was this intended?). " << std::endl;
00442 __COUT_ERR__ << "\n" << ss.str();
00443 throw std::runtime_error(ss.str());
00444 }
00445 return nameToConfigurationMap_[configurationName];
00446 }
00447
00448
00449
00450
00451
00452
00453 ConfigurationBase* ConfigurationManagerRW::getVersionedConfigurationByName(const std::string &configurationName,
00454 ConfigurationVersion version, bool looseColumnMatching)
00455 {
00456 auto it = nameToConfigurationMap_.find(configurationName);
00457 if(it == nameToConfigurationMap_.end())
00458 {
00459 __SS__ << "\nCan not find configuration named '" <<
00460 configurationName <<
00461 "'\n\n\n\nYou need to load the configuration before it can be used." <<
00462 "It probably is missing from the member list of the Configuration Group that was loaded?\n\n\n\n\n"
00463 << std::endl;
00464 throw std::runtime_error(ss.str());
00465 }
00466 ConfigurationBase* configuration = it->second;
00467 theInterface_->get(configuration, configurationName, 0 , 0,
00468 false,
00469 version,
00470 false,
00471 looseColumnMatching);
00472 return configuration;
00473 }
00474
00475
00476
00477
00478 ConfigurationVersion ConfigurationManagerRW::saveNewConfiguration(
00479 const std::string &configurationName,
00480 ConfigurationVersion temporaryVersion,
00481 bool makeTemporary)
00482
00483 {
00484 ConfigurationVersion newVersion(temporaryVersion);
00485
00486
00487 ConfigurationBase *config = getConfigurationByName(configurationName);
00488 config->getTemporaryView(temporaryVersion)->setAuthor(username_);
00489
00490
00491 if(!makeTemporary)
00492 newVersion = theInterface_->saveNewVersion(config, temporaryVersion);
00493 else
00494 config->setActiveView(newVersion);
00495
00496
00497 while(!makeTemporary && !newVersion.isScratchVersion() &&
00498 allConfigurationInfo_[configurationName].versions_.find(newVersion) !=
00499 allConfigurationInfo_[configurationName].versions_.end())
00500 {
00501 __COUT_ERR__ << "What happenened!?? ERROR::: new persistent version v" << newVersion <<
00502 " already exists!? How is it possible? Retrace your steps and tell an admin." << std::endl;
00503
00504
00505 temporaryVersion = config->createTemporaryView(newVersion);
00506
00507 if(newVersion.isTemporaryVersion())
00508 newVersion = temporaryVersion;
00509 else
00510 newVersion = ConfigurationVersion::getNextVersion(newVersion);
00511
00512 __COUT_WARN__ << "Attempting to recover and use v" << newVersion << std::endl;
00513
00514
00515 if(!makeTemporary)
00516 newVersion = theInterface_->saveNewVersion(config, temporaryVersion, newVersion);
00517 else
00518 config->setActiveView(newVersion);
00519 }
00520
00521 if(newVersion.isInvalid())
00522 {
00523 __SS__ << "Something went wrong saving the new version v" << newVersion <<
00524 ". What happened?! (duplicates? database error?)" << std::endl;
00525 __COUT_ERR__ << "\n" << ss.str();
00526 throw std::runtime_error(ss.str());
00527 }
00528
00529
00530 allConfigurationInfo_[configurationName].versions_.insert(newVersion);
00531
00532 __COUT__ << "New version added to info " << newVersion << std::endl;
00533
00534 return newVersion;
00535 }
00536
00537
00538
00539
00540
00541
00542 void ConfigurationManagerRW::eraseTemporaryVersion(const std::string &configurationName,
00543 ConfigurationVersion targetVersion)
00544 {
00545 ConfigurationBase* config = getConfigurationByName(configurationName);
00546
00547 config->trimTemporary(targetVersion);
00548
00549
00550 if(allConfigurationInfo_.find(configurationName) ==
00551 allConfigurationInfo_.end()) return;
00552
00553
00554 if(targetVersion.isInvalid())
00555 {
00556
00557 for(auto it = allConfigurationInfo_[configurationName].versions_.begin();
00558 it != allConfigurationInfo_[configurationName].versions_.end(); )
00559 {
00560 if(it->isTemporaryVersion())
00561 {
00562 __COUT__ << "Removing version info: " << *it << std::endl;
00563 allConfigurationInfo_[configurationName].versions_.erase(it++);
00564 }
00565 else
00566 ++it;
00567 }
00568 }
00569 else
00570 {
00571 __COUT__ << "Removing version info: " << targetVersion << std::endl;
00572 auto it = allConfigurationInfo_[configurationName].versions_.find(targetVersion);
00573 if(it == allConfigurationInfo_[configurationName].versions_.end())
00574 {
00575 __COUT__ << "Target version was not found in info versions..." << std::endl;
00576 return;
00577 }
00578 allConfigurationInfo_[configurationName].versions_.erase(
00579 allConfigurationInfo_[configurationName].versions_.find(targetVersion));
00580 __COUT__ << "Target version was erased from info." << std::endl;
00581 }
00582 }
00583
00584
00585
00586
00587
00588
00589 void ConfigurationManagerRW::clearCachedVersions(const std::string &configurationName)
00590 {
00591 ConfigurationBase* config = getConfigurationByName(configurationName);
00592
00593 config->trimCache(0);
00594 }
00595
00596
00597
00598
00599
00600
00601 void ConfigurationManagerRW::clearAllCachedVersions()
00602 {
00603 for(auto configInfo: allConfigurationInfo_)
00604 configInfo.second.configurationPtr_->trimCache(0);
00605 }
00606
00607
00608
00609 ConfigurationVersion ConfigurationManagerRW::copyViewToCurrentColumns(const std::string &configurationName,
00610 ConfigurationVersion sourceVersion)
00611 {
00612 getConfigurationByName(configurationName)->reset();
00613
00614
00615
00616 ConfigurationBase *config = getVersionedConfigurationByName(configurationName,
00617 ConfigurationVersion(sourceVersion), true);
00618
00619
00620 ConfigurationVersion newTemporaryVersion = config->copyView(config->getView(),
00621 ConfigurationVersion(),username_);
00622
00623
00624 allConfigurationInfo_[configurationName].versions_.insert(newTemporaryVersion);
00625
00626 return newTemporaryVersion;
00627 }
00628
00629
00630
00631 void ConfigurationManagerRW::cacheGroupKey(const std::string &groupName,
00632 ConfigurationGroupKey key)
00633 {
00634 allGroupInfo_[groupName].keys_.emplace(key);
00635 }
00636
00637
00638
00639
00640
00641 const GroupInfo& ConfigurationManagerRW::getGroupInfo(const std::string &groupName)
00642 {
00643
00644
00645
00646
00647
00648
00649 auto it = allGroupInfo_.find(groupName);
00650 if(it == allGroupInfo_.end())
00651 {
00652 __SS__ << "Group name '" << groupName << "' not found in group info! (creating empty info)" << __E__;
00653 __COUT_WARN__ << ss.str();
00654
00655 return allGroupInfo_[groupName];
00656 }
00657 return it->second;
00658 }
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669 ConfigurationGroupKey ConfigurationManagerRW::findConfigurationGroup(const std::string &groupName,
00670 const std::map<std::string, ConfigurationVersion> &groupMemberMap)
00671 {
00672
00673
00674
00675
00676
00677
00678
00679
00680 const GroupInfo& groupInfo = getGroupInfo(groupName);
00681
00682
00683
00684 std::map<std::string , ConfigurationVersion > compareToMemberMap;
00685 bool isDifferent;
00686
00687 const unsigned int MAX_DEPTH_TO_CHECK = 20;
00688 unsigned int keyMinToCheck = 0;
00689
00690 if(groupInfo.keys_.size())
00691 keyMinToCheck = groupInfo.keys_.rbegin()->key();
00692 if(keyMinToCheck > MAX_DEPTH_TO_CHECK)
00693 {
00694 keyMinToCheck -= MAX_DEPTH_TO_CHECK;
00695 __COUT__ << "Checking groups back to key... " << keyMinToCheck << std::endl;
00696 }
00697 else
00698 {
00699 keyMinToCheck = 0;
00700 __COUT__ << "Checking all groups." << std::endl;
00701 }
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727 std::string fullName;
00728 for(const auto& key: groupInfo.keys_)
00729 {
00730
00731
00732 if(key.key() < keyMinToCheck) continue;
00733
00734
00735
00736
00737 fullName = ConfigurationGroupKey::getFullGroupString(groupName,key);
00738
00739 __COUT__ << "checking group... " << fullName << std::endl;
00740 compareToMemberMap = theInterface_->getConfigurationGroupMembers(fullName);
00741
00742 isDifferent = false;
00743 for(auto &memberPair: groupMemberMap)
00744 {
00745
00746 if(compareToMemberMap.find(memberPair.first) == compareToMemberMap.end() ||
00747 memberPair.second != compareToMemberMap[memberPair.first])
00748 {
00749
00750 isDifferent = true;
00751 break;
00752 }
00753 }
00754 if(isDifferent) continue;
00755
00756
00757 if(groupMemberMap.size() != compareToMemberMap.size()) continue;
00758
00759 __COUT__ << "Found exact match with key: " << key << std::endl;
00760
00761 return key;
00762 }
00763 __COUT__ << "No match found - this group is new!" << std::endl;
00764
00765 return ConfigurationGroupKey();
00766 }
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776 ConfigurationGroupKey ConfigurationManagerRW::saveNewConfigurationGroup(
00777 const std::string &groupName,
00778 std::map<std::string, ConfigurationVersion> &groupMembers,
00779 const std::string &groupComment)
00780 {
00781
00782
00783
00784
00785
00786
00787
00788 if(groupMembers.size() == 0)
00789 {
00790 __SS__ << "Empty group member list. Can not create a group without members!" << std::endl;
00791 __COUT_ERR__ << ss.str();
00792 throw std::runtime_error(ss.str());
00793 }
00794
00795
00796 ConfigurationGroupKey newKey;
00797
00798
00799
00800
00801 {
00802 std::set<ConfigurationGroupKey> keys = theInterface_->getKeys(groupName);
00803 if(keys.size())
00804 newKey = ConfigurationGroupKey::getNextKey(*(keys.crbegin()));
00805 else
00806 newKey = ConfigurationGroupKey::getDefaultKey();
00807 }
00808
00809 __COUT__ << "New Key for group: " << groupName << " found as " << newKey << std::endl;
00810
00811
00812
00813 std::map<std::string, ConfigurationInfo> allCfgInfo = getAllConfigurationInfo();
00814 for(auto &memberPair : groupMembers )
00815 {
00816
00817 if(allCfgInfo.find(memberPair.first) == allCfgInfo.end())
00818 {
00819 __COUT_ERR__ << "Group member \"" << memberPair.first << "\" not found in configuration!";
00820
00821 if(groupMetadataTable_.getConfigurationName() ==
00822 memberPair.first)
00823 {
00824 __COUT_WARN__ << "Looks like this is the groupMetadataTable_. " <<
00825 "Note that this table is added to the member map when groups are saved." <<
00826 "It should not be part of member map when calling this function." << std::endl;
00827 __COUT__ << "Attempting to recover." << std::endl;
00828 groupMembers.erase(groupMembers.find(memberPair.first));
00829 }
00830 else
00831 {
00832 __SS__ << ("Group member not found!") << std::endl;
00833 __COUT_ERR__ << ss.str();
00834 throw std::runtime_error(ss.str());
00835 }
00836 }
00837
00838 if(allCfgInfo[memberPair.first].versions_.find(memberPair.second) ==
00839 allCfgInfo[memberPair.first].versions_.end())
00840 {
00841 __SS__ << "Group member \"" << memberPair.first << "\" version \"" <<
00842 memberPair.second << "\" not found in configuration!";
00843 __COUT_ERR__ << ss.str();
00844 throw std::runtime_error(ss.str());
00845 }
00846 }
00847
00848
00849 try
00850 {
00851
00852
00853 __COUT__ << username_ << " " << time(0) << " " << groupComment << std::endl;
00854
00855 groupMetadataTable_.getViewP()->setValue(groupComment,0,1);
00856 groupMetadataTable_.getViewP()->setValue(username_,0,2);
00857 groupMetadataTable_.getViewP()->setValue(time(0),0,3);
00858
00859
00860 groupMetadataTable_.getViewP()->setVersion(
00861 ConfigurationVersion::getNextVersion(theInterface_->findLatestVersion(&groupMetadataTable_))
00862 );
00863
00864
00865
00866 theInterface_->saveActiveVersion(&groupMetadataTable_);
00867
00868
00869 groupMembers[groupMetadataTable_.getConfigurationName()] =
00870 groupMetadataTable_.getViewVersion();
00871
00872 theInterface_->saveConfigurationGroup(groupMembers,
00873 ConfigurationGroupKey::getFullGroupString(groupName,newKey));
00874 __COUT__ << "Created config group: " << groupName << ":" << newKey << std::endl;
00875 }
00876 catch(std::runtime_error &e)
00877 {
00878 __COUT_ERR__ << "Failed to create config group: " << groupName << ":" << newKey << std::endl;
00879 __COUT_ERR__ << "\n\n" << e.what() << std::endl;
00880 throw;
00881 }
00882 catch(...)
00883 {
00884 __COUT_ERR__ << "Failed to create config group: " << groupName << ":" << newKey << std::endl;
00885 throw;
00886 }
00887
00888
00889
00890 cacheGroupKey(groupName,newKey);
00891
00892
00893 return newKey;
00894 }
00895
00896
00897
00898
00899
00900 ConfigurationVersion ConfigurationManagerRW::saveNewBackbone(ConfigurationVersion temporaryVersion)
00901 {
00902 __COUT_INFO__ << "Creating new backbone from temporary version " <<
00903 temporaryVersion << std::endl;
00904
00905
00906 ConfigurationVersion newVersion(ConfigurationVersion::DEFAULT);
00907 ConfigurationVersion retNewVersion;
00908 auto backboneMemberNames = ConfigurationManager::getBackboneMemberNames();
00909 for (auto& name : backboneMemberNames)
00910 {
00911 retNewVersion = ConfigurationManager::getConfigurationByName(name)->getNextVersion();
00912 __COUT__ << "New version for backbone member (" << name << "): " <<
00913 retNewVersion << std::endl;
00914 if(retNewVersion > newVersion)
00915 newVersion = retNewVersion;
00916 }
00917
00918 __COUT__ << "Common new backbone version found as " <<
00919 newVersion << std::endl;
00920
00921
00922 for (auto& name : backboneMemberNames)
00923 {
00924
00925 retNewVersion = getConfigurationInterface()->saveNewVersion(
00926 getConfigurationByName(name), temporaryVersion, newVersion);
00927 if(retNewVersion != newVersion)
00928 {
00929 __SS__ << "Failure! New view requested was " <<
00930 newVersion << ". Mismatched new view created: " << retNewVersion << std::endl;
00931 __COUT_ERR__ << ss.str();
00932 throw std::runtime_error(ss.str());
00933 }
00934 }
00935
00936 return newVersion;
00937 }
00938
00939
00940 void ConfigurationManagerRW::testXDAQContext()
00941 {
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094 try
01095 {
01096 __COUT__ << "Loading config..." << std::endl;
01097 loadConfigurationGroup("FETest",ConfigurationGroupKey(2));
01098 ConfigurationTree t = getNode("/FEConfiguration/DEFAULT/FrontEndType");
01099
01100 std::string v;
01101
01102 __COUT__ << std::endl;
01103 t.getValue(v);
01104 __COUT__ << "Value: " << v << std::endl;
01105 __COUT__ << "Value index: " << t.getValue<int>() << std::endl;
01106
01107 return;
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144 }
01145 catch(...)
01146 {
01147 __COUT__ << "Failed to load config..." << std::endl;
01148 }
01149
01150
01151 }
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164