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