Skip to content

Commit

Permalink
Allow setting connect string from SiteLocalConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
wddgit committed Sep 22, 2020
1 parent 971b61e commit 529704b
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 54 deletions.
1 change: 1 addition & 0 deletions CondCore/ESSources/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<use name="FWCore/Catalog"/>
<use name="FWCore/Framework"/>
<use name="CondCore/ESSources"/>
<library file="*.cc" name="CondCoreESSourcesPlugins">
Expand Down
13 changes: 13 additions & 0 deletions CondCore/ESSources/plugins/CondDBESSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
#include "CondCore/ESSources/interface/DataProxy.h"

#include "CondCore/CondDB/interface/PayloadProxy.h"
#include "FWCore/Catalog/interface/SiteLocalConfig.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include <exception>

#include <iomanip>
Expand Down Expand Up @@ -123,6 +125,17 @@ CondDBESSource::CondDBESSource(const edm::ParameterSet& iConfig)
globaltag = iConfig.getParameter<std::string>("globaltag");
// the global tag _requires_ a connection string
m_connectionString = iConfig.getParameter<std::string>("connect");

if (!globaltag.empty()) {
edm::Service<edm::SiteLocalConfig> siteLocalConfig;
if (siteLocalConfig.isAvailable()) {
std::string const& localConnectPrefix = siteLocalConfig->localConnectPrefix();
std::string const& localConnectSuffix = siteLocalConfig->localConnectSuffix();
if (!localConnectPrefix.empty() && !localConnectSuffix.empty()) {
m_connectionString = localConnectPrefix + globaltag + localConnectSuffix;
}
}
}
} else if (iConfig.exists("connect")) // default connection string
m_connectionString = iConfig.getParameter<std::string>("connect");

Expand Down
2 changes: 2 additions & 0 deletions FWCore/Catalog/interface/SiteLocalConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ namespace edm {
virtual struct addrinfo const* statisticsDestination() const = 0;
virtual std::set<std::string> const* statisticsInfo() const = 0;
virtual std::string const& siteName(void) const = 0;
virtual std::string const& localConnectPrefix() const = 0;
virtual std::string const& localConnectSuffix() const = 0;

// implicit copy constructor
// implicit assignment operator
Expand Down
8 changes: 4 additions & 4 deletions FWCore/Catalog/test/FileLocator_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ namespace {
return nullptr;
}
std::set<std::string> const* statisticsInfo() const final { return nullptr; }
std::string const& siteName(void) const final {
static const std::string s_value = "TEST";
return s_value;
}
std::string const& siteName(void) const final { return m_emptyString; }
std::string const& localConnectPrefix() const final { return m_emptyString; }
std::string const& localConnectSuffix() const final { return m_emptyString; }

private:
std::vector<std::string> m_catalogs;
std::string m_emptyString;
};
} // namespace

Expand Down
23 changes: 22 additions & 1 deletion FWCore/Services/src/SiteLocalConfigService.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ namespace edm {
if (pset.exists("debugLevel")) {
m_debugLevel = pset.getUntrackedParameter<unsigned int>("debugLevel");
}
if (pset.exists("overrideLocalConnectPrefix")) {
m_localConnectPrefix = pset.getUntrackedParameter<std::string>("overrideLocalConnectPrefix");
}
if (pset.exists("overrideLocalConnectSuffix")) {
m_localConnectSuffix = pset.getUntrackedParameter<std::string>("overrideLocalConnectSuffix");
}
}

SiteLocalConfigService::~SiteLocalConfigService() {
Expand Down Expand Up @@ -259,6 +265,8 @@ namespace edm {
}

std::string const &SiteLocalConfigService::siteName() const { return m_siteName; }
std::string const &SiteLocalConfigService::localConnectPrefix() const { return m_localConnectPrefix; }
std::string const &SiteLocalConfigService::localConnectSuffix() const { return m_localConnectSuffix; }

void SiteLocalConfigService::parse(std::string const &url) {
tinyxml2::XMLDocument doc;
Expand All @@ -279,6 +287,9 @@ namespace edm {
// <frontier-connect>
// ... frontier-interpreted server/proxy xml ...
// </frontier-connect>
// <local-connect>
// <connectString prefix="anything1" suffix="anything2"/>
// </local-connect>
// </calib-data>
// <source-config>
// <cache-temp-dir name="/a/b/c"/>
Expand Down Expand Up @@ -329,8 +340,17 @@ namespace edm {
if (frontierConnect) {
m_frontierConnect = _toParenString(*frontierConnect);
}
auto localConnect = calibData->FirstChildElement("local-connect");
if (localConnect) {
auto connectString = localConnect->FirstChildElement("connectString");
if (connectString) {
m_localConnectPrefix = safe(connectString->Attribute("prefix"));
m_localConnectSuffix = safe(connectString->Attribute("suffix"));
}
}
}
}

// Parsing of the source config section
{
auto sourceConfig = site->FirstChildElement("source-config");
Expand Down Expand Up @@ -465,7 +485,8 @@ namespace edm {
->setComment(
"Provide an alternate listing of statistics to send (comma separated list; current options are 'dn' or "
"'nodn'). If left blank, all information is snet (including DNs).");

desc.addOptionalUntracked<std::string>("overrideLocalConnectPrefix");
desc.addOptionalUntracked<std::string>("overrideLocalConnectSuffix");
descriptions.add("SiteLocalConfigService", desc);
}
} // namespace service
Expand Down
4 changes: 4 additions & 0 deletions FWCore/Services/src/SiteLocalConfigService.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ namespace edm {
struct addrinfo const* statisticsDestination() const override;
std::set<std::string> const* statisticsInfo() const override;
std::string const& siteName() const override;
std::string const& localConnectPrefix() const override;
std::string const& localConnectSuffix() const override;

// implicit copy constructor
// implicit assignment operator
Expand Down Expand Up @@ -88,6 +90,8 @@ namespace edm {
std::set<std::string> m_statisticsInfo;
bool m_statisticsInfoAvail;
std::string m_siteName;
std::string m_localConnectPrefix;
std::string m_localConnectSuffix;
};

inline bool isProcessWideService(SiteLocalConfigService const*) { return true; }
Expand Down
61 changes: 16 additions & 45 deletions FWCore/Services/test/SiteLocalConfigServiceTester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
// Created: Tue Apr 20 16:51:38 CDT 2010
//

// system include files
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Catalog/interface/SiteLocalConfig.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Utilities/interface/Exception.h"

// user include files
#include <string>

namespace edmtest {
class SiteLocalConfigServiceTester : public edm::EDAnalyzer {
Expand All @@ -33,54 +33,23 @@ namespace edmtest {
unsigned int m_ttreeCacheSize;
std::vector<std::string> m_nativeProtocols;
bool m_valuesSet;
std::string m_expectedLocalConnectPrefix;
std::string m_expectedLocalConnectSuffix;
};
} // namespace edmtest

using namespace edmtest;

//
// constants, enums and typedefs
//

//
// static data member definitions
//

//
// constructors and destructor
//
SiteLocalConfigServiceTester::SiteLocalConfigServiceTester(const edm::ParameterSet& iPSet)
: m_cacheHint(iPSet.getUntrackedParameter<std::string>("sourceCacheHint")),
m_readHint(iPSet.getUntrackedParameter<std::string>("sourceReadHint")),
m_tempDir(iPSet.getUntrackedParameter<std::string>("sourceTempDir")),
m_ttreeCacheSize(iPSet.getUntrackedParameter<unsigned int>("sourceTTreeCacheSize")),
m_nativeProtocols(iPSet.getUntrackedParameter<std::vector<std::string> >("sourceNativeProtocols")),
m_valuesSet(iPSet.getUntrackedParameter<bool>("sourceValuesSet", true)) {}

// SiteLocalConfigServiceTester::SiteLocalConfigServiceTester(const SiteLocalConfigServiceTester& rhs)
// {
// // do actual copying here;
// }

//SiteLocalConfigServiceTester::~SiteLocalConfigServiceTester()
//{
//}

//
// assignment operators
//
// const SiteLocalConfigServiceTester& SiteLocalConfigServiceTester::operator=(const SiteLocalConfigServiceTester& rhs)
// {
// //An exception safe implementation is
// SiteLocalConfigServiceTester temp(rhs);
// swap(rhs);
//
// return *this;
// }
m_valuesSet(iPSet.getUntrackedParameter<bool>("sourceValuesSet", true)),
m_expectedLocalConnectPrefix(iPSet.getUntrackedParameter<std::string>("expectedLocalConnectPrefix")),
m_expectedLocalConnectSuffix(iPSet.getUntrackedParameter<std::string>("expectedLocalConnectSuffix")) {}

//
// member functions
//
static void throwNotSet(const char* iName) {
throw cms::Exception("TestFailure") << "The value " << iName << " should have been set but was not";
}
Expand Down Expand Up @@ -116,9 +85,7 @@ namespace {
}

} // namespace
//
// const member functions
//

void SiteLocalConfigServiceTester::analyze(const edm::Event&, const edm::EventSetup&) {
edm::Service<edm::SiteLocalConfig> pConfig;
if (m_valuesSet) {
Expand Down Expand Up @@ -148,10 +115,14 @@ void SiteLocalConfigServiceTester::analyze(const edm::Event&, const edm::EventSe
checkNotSet("sourceTTreeCacheSize", pConfig->sourceTTreeCacheSize());
checkNotSet("sourceNativeProtocols", pConfig->sourceNativeProtocols());
}
if (pConfig->localConnectPrefix() != m_expectedLocalConnectPrefix) {
throw cms::Exception("TestFailure") << "The value of localConnectPrefix is \"" << pConfig->localConnectPrefix()
<< "\" but we expected the value \"" << m_expectedLocalConnectPrefix << "\"";
}
if (pConfig->localConnectSuffix() != m_expectedLocalConnectSuffix) {
throw cms::Exception("TestFailure") << "The value of localConnectSuffix is \"" << pConfig->localConnectSuffix()
<< "\" but we expected the value \"" << m_expectedLocalConnectSuffix << "\"";
}
}

//
// static member functions
//

DEFINE_FWK_MODULE(SiteLocalConfigServiceTester);
3 changes: 3 additions & 0 deletions FWCore/Services/test/full-site-local-config.testfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<proxy url="http://cmsfrontier.dummy.foo:3128"/>
<proxy url="http://cmsfrontier.dummy.foo:3128"/>
</frontier-connect>
<local-connect>
<connectString prefix="Test:Prefix" suffix="Test.Suffix"/>
</local-connect>
</calib-data>
<source-config>
<cache-temp-dir name="/a/b/c"/>
Expand Down
3 changes: 3 additions & 0 deletions FWCore/Services/test/source-site-local-config.testfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<proxy url="http://cmsfrontier.dummy.foo:3128"/>
<proxy url="http://cmsfrontier.dummy.foo:3128"/>
</frontier-connect>
<local-connect>
<connectString prefix="Test:Prefix" suffix="Test.Suffix"/>
</local-connect>
</calib-data>
<source-config>
<cache-temp-dir name="/a/b/c"/>
Expand Down
6 changes: 6 additions & 0 deletions FWCore/Services/test/test_catch2_SiteLocalConfigService.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ TEST_CASE("Test SiteLocalConfigService", "[sitelocalconfig]") {
CHECK(slc.statisticsInfo()->size() == 1);
CHECK(slc.statisticsInfo()->find("dn") != slc.statisticsInfo()->end());
CHECK(slc.siteName() == "DUMMY");
REQUIRE(slc.localConnectPrefix() == "Test:Prefix");
REQUIRE(slc.localConnectSuffix() == "Test.Suffix");
}

SECTION("overrides") {
Expand All @@ -63,6 +65,8 @@ TEST_CASE("Test SiteLocalConfigService", "[sitelocalconfig]") {
pset.addUntrackedParameter<bool>("overridePrefetching", false);
pset.addUntrackedParameter<std::string>("overrideStatisticsDestination", "");
pset.addUntrackedParameter<std::vector<std::string> >("overrideStatisticsInfo", {{"nodn"}});
pset.addUntrackedParameter<std::string>("overrideLocalConnectPrefix", "OverridePrefix");
pset.addUntrackedParameter<std::string>("overrideLocalConnectSuffix", "OverrideSuffix");

edm::service::SiteLocalConfigService slc(pset);

Expand Down Expand Up @@ -90,5 +94,7 @@ TEST_CASE("Test SiteLocalConfigService", "[sitelocalconfig]") {
CHECK(slc.statisticsInfo()->size() == 1);
CHECK(slc.statisticsInfo()->find("nodn") != slc.statisticsInfo()->end());
CHECK(slc.siteName() == "DUMMY");
REQUIRE(slc.localConnectPrefix() == "OverridePrefix");
REQUIRE(slc.localConnectSuffix() == "OverrideSuffix");
}
}
4 changes: 3 additions & 1 deletion FWCore/Services/test/test_sitelocalconfig_no_source_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
sourceReadHint=cms.untracked.string(""),
sourceTTreeCacheSize=cms.untracked.uint32(0),
sourceNativeProtocols=cms.untracked.vstring(),
sourceValuesSet=cms.untracked.bool(False)
sourceValuesSet=cms.untracked.bool(False),
expectedLocalConnectPrefix = cms.untracked.string(""),
expectedLocalConnectSuffix = cms.untracked.string("")
)

process.o = cms.EndPath(process.tester)
10 changes: 8 additions & 2 deletions FWCore/Services/test/test_sitelocalconfig_override_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
sourceReadHint=cms.untracked.string("direct-unbuffered"),
sourceTTreeCacheSize=cms.untracked.uint32(0),
sourceNativeProtocols=cms.untracked.vstring("rfio"),
sourceValuesSet=cms.untracked.bool(True)
sourceValuesSet=cms.untracked.bool(True),
expectedLocalConnectPrefix = cms.untracked.string("TestOverride:Prefix"),
expectedLocalConnectSuffix = cms.untracked.string("TestOverride.Suffix")

)

process.o = cms.EndPath(process.tester)
Expand All @@ -20,4 +23,7 @@
overrideSourceCacheHintDir=cms.untracked.string("storage-only"),
overrideSourceReadHint=cms.untracked.string("direct-unbuffered"),
overrideSourceNativeProtocols=cms.untracked.vstring("rfio"),
overrideSourceTTreeCacheSize=cms.untracked.uint32(0)))
overrideSourceTTreeCacheSize=cms.untracked.uint32(0),
overrideLocalConnectPrefix = cms.untracked.string("TestOverride:Prefix"),
overrideLocalConnectSuffix = cms.untracked.string("TestOverride.Suffix")
))
4 changes: 3 additions & 1 deletion FWCore/Services/test/test_sitelocalconfig_source_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
sourceReadHint=cms.untracked.string("read-ahead-buffered"),
sourceTTreeCacheSize=cms.untracked.uint32(10000),
sourceNativeProtocols=cms.untracked.vstring("dcache","file"),
sourceValuesSet=cms.untracked.bool(True)
sourceValuesSet=cms.untracked.bool(True),
expectedLocalConnectPrefix = cms.untracked.string("Test:Prefix"),
expectedLocalConnectSuffix = cms.untracked.string("Test.Suffix")
)

process.o = cms.EndPath(process.tester)

0 comments on commit 529704b

Please sign in to comment.