Skip to content

Commit c06e922

Browse files
authored
Merge pull request cms-sw#31544 from wddgit/localConnectInSiteLocalConfig
Allow setting connect string from SiteLocalConfig
2 parents 6b7cf86 + f48be34 commit c06e922

15 files changed

+145
-62
lines changed

CondCore/ESSources/plugins/BuildFile.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<use name="FWCore/Catalog"/>
12
<use name="FWCore/Framework"/>
23
<use name="CondCore/ESSources"/>
34
<library file="*.cc" name="CondCoreESSourcesPlugins">

CondCore/ESSources/plugins/CondDBESSource.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
#include "CondCore/ESSources/interface/DataProxy.h"
2323

2424
#include "CondCore/CondDB/interface/PayloadProxy.h"
25+
#include "FWCore/Catalog/interface/SiteLocalConfig.h"
2526
#include "FWCore/ParameterSet/interface/ParameterSet.h"
2627
#include "FWCore/MessageLogger/interface/MessageLogger.h"
28+
#include "FWCore/ServiceRegistry/interface/Service.h"
2729
#include <exception>
2830

2931
#include <iomanip>
@@ -123,6 +125,17 @@ CondDBESSource::CondDBESSource(const edm::ParameterSet& iConfig)
123125
globaltag = iConfig.getParameter<std::string>("globaltag");
124126
// the global tag _requires_ a connection string
125127
m_connectionString = iConfig.getParameter<std::string>("connect");
128+
129+
if (!globaltag.empty()) {
130+
edm::Service<edm::SiteLocalConfig> siteLocalConfig;
131+
if (siteLocalConfig.isAvailable()) {
132+
if (siteLocalConfig->useLocalConnectString()) {
133+
std::string const& localConnectPrefix = siteLocalConfig->localConnectPrefix();
134+
std::string const& localConnectSuffix = siteLocalConfig->localConnectSuffix();
135+
m_connectionString = localConnectPrefix + globaltag + localConnectSuffix;
136+
}
137+
}
138+
}
126139
} else if (iConfig.exists("connect")) // default connection string
127140
m_connectionString = iConfig.getParameter<std::string>("connect");
128141

FWCore/Catalog/interface/SiteLocalConfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ namespace edm {
4747
virtual struct addrinfo const* statisticsDestination() const = 0;
4848
virtual std::set<std::string> const* statisticsInfo() const = 0;
4949
virtual std::string const& siteName(void) const = 0;
50+
virtual bool useLocalConnectString() const = 0;
51+
virtual std::string const& localConnectPrefix() const = 0;
52+
virtual std::string const& localConnectSuffix() const = 0;
5053

5154
// implicit copy constructor
5255
// implicit assignment operator

FWCore/Catalog/test/FileLocator_t.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "FWCore/ServiceRegistry/interface/ServiceRegistry.h"
55
#include <boost/filesystem.hpp>
66

7+
#include <string>
8+
79
#define CATCH_CONFIG_MAIN
810
#include "catch.hpp"
911

@@ -29,13 +31,14 @@ namespace {
2931
return nullptr;
3032
}
3133
std::set<std::string> const* statisticsInfo() const final { return nullptr; }
32-
std::string const& siteName(void) const final {
33-
static const std::string s_value = "TEST";
34-
return s_value;
35-
}
34+
std::string const& siteName(void) const final { return m_emptyString; }
35+
bool useLocalConnectString() const final { return false; }
36+
std::string const& localConnectPrefix() const final { return m_emptyString; }
37+
std::string const& localConnectSuffix() const final { return m_emptyString; }
3638

3739
private:
3840
std::vector<std::string> m_catalogs;
41+
std::string m_emptyString;
3942
};
4043
} // namespace
4144

FWCore/Services/bin/cmsGetFnConnect.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "FWCore/Utilities/interface/Exception.h"
1919
#include <iostream>
2020
#include <cstring>
21+
#include <memory>
2122

2223
int main(int argc, char* argv[]) {
2324
if ((argc != 2) || (strncmp(argv[1], "frontier://", 11) != 0)) {

FWCore/Services/src/SiteLocalConfigService.cc

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ namespace edm {
132132
if (pset.exists("debugLevel")) {
133133
m_debugLevel = pset.getUntrackedParameter<unsigned int>("debugLevel");
134134
}
135+
if (pset.exists("overrideUseLocalConnectString")) {
136+
m_useLocalConnectString = pset.getUntrackedParameter<bool>("overrideUseLocalConnectString");
137+
}
138+
if (pset.exists("overrideLocalConnectPrefix")) {
139+
m_localConnectPrefix = pset.getUntrackedParameter<std::string>("overrideLocalConnectPrefix");
140+
}
141+
if (pset.exists("overrideLocalConnectSuffix")) {
142+
m_localConnectSuffix = pset.getUntrackedParameter<std::string>("overrideLocalConnectSuffix");
143+
}
135144
}
136145

137146
SiteLocalConfigService::~SiteLocalConfigService() {
@@ -259,6 +268,9 @@ namespace edm {
259268
}
260269

261270
std::string const &SiteLocalConfigService::siteName() const { return m_siteName; }
271+
bool SiteLocalConfigService::useLocalConnectString() const { return m_useLocalConnectString; }
272+
std::string const &SiteLocalConfigService::localConnectPrefix() const { return m_localConnectPrefix; }
273+
std::string const &SiteLocalConfigService::localConnectSuffix() const { return m_localConnectSuffix; }
262274

263275
void SiteLocalConfigService::parse(std::string const &url) {
264276
tinyxml2::XMLDocument doc;
@@ -279,6 +291,9 @@ namespace edm {
279291
// <frontier-connect>
280292
// ... frontier-interpreted server/proxy xml ...
281293
// </frontier-connect>
294+
// <local-connect>
295+
// <connectString prefix="anything1" suffix="anything2"/>
296+
// </local-connect>
282297
// </calib-data>
283298
// <source-config>
284299
// <cache-temp-dir name="/a/b/c"/>
@@ -329,8 +344,22 @@ namespace edm {
329344
if (frontierConnect) {
330345
m_frontierConnect = _toParenString(*frontierConnect);
331346
}
347+
auto localConnect = calibData->FirstChildElement("local-connect");
348+
if (localConnect) {
349+
if (frontierConnect) {
350+
throw cms::Exception("Illegal site local configuration")
351+
<< "It is illegal to include both frontier-connect and local-connect in the same XML file";
352+
}
353+
m_useLocalConnectString = true;
354+
auto connectString = localConnect->FirstChildElement("connectString");
355+
if (connectString) {
356+
m_localConnectPrefix = safe(connectString->Attribute("prefix"));
357+
m_localConnectSuffix = safe(connectString->Attribute("suffix"));
358+
}
359+
}
332360
}
333361
}
362+
334363
// Parsing of the source config section
335364
{
336365
auto sourceConfig = site->FirstChildElement("source-config");
@@ -465,7 +494,9 @@ namespace edm {
465494
->setComment(
466495
"Provide an alternate listing of statistics to send (comma separated list; current options are 'dn' or "
467496
"'nodn'). If left blank, all information is snet (including DNs).");
468-
497+
desc.addOptionalUntracked<bool>("overrideUseLocalConnectString");
498+
desc.addOptionalUntracked<std::string>("overrideLocalConnectPrefix");
499+
desc.addOptionalUntracked<std::string>("overrideLocalConnectSuffix");
469500
descriptions.add("SiteLocalConfigService", desc);
470501
}
471502
} // namespace service

FWCore/Services/src/SiteLocalConfigService.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ namespace edm {
4747
struct addrinfo const* statisticsDestination() const override;
4848
std::set<std::string> const* statisticsInfo() const override;
4949
std::string const& siteName() const override;
50+
bool useLocalConnectString() const override;
51+
std::string const& localConnectPrefix() const override;
52+
std::string const& localConnectSuffix() const override;
5053

5154
// implicit copy constructor
5255
// implicit assignment operator
@@ -88,6 +91,9 @@ namespace edm {
8891
std::set<std::string> m_statisticsInfo;
8992
bool m_statisticsInfoAvail;
9093
std::string m_siteName;
94+
bool m_useLocalConnectString = false;
95+
std::string m_localConnectPrefix;
96+
std::string m_localConnectSuffix;
9197
};
9298

9399
inline bool isProcessWideService(SiteLocalConfigService const*) { return true; }

FWCore/Services/test/SiteLocalConfigServiceTester.cc

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
// Created: Tue Apr 20 16:51:38 CDT 2010
1111
//
1212

13-
// system include files
1413
#include "FWCore/Framework/interface/EDAnalyzer.h"
14+
#include "FWCore/ParameterSet/interface/ParameterSet.h"
1515
#include "FWCore/ServiceRegistry/interface/Service.h"
1616
#include "FWCore/Catalog/interface/SiteLocalConfig.h"
1717
#include "FWCore/Framework/interface/MakerMacros.h"
1818
#include "FWCore/Utilities/interface/Exception.h"
1919

20-
// user include files
20+
#include <string>
2121

2222
namespace edmtest {
2323
class SiteLocalConfigServiceTester : public edm::EDAnalyzer {
@@ -33,54 +33,25 @@ namespace edmtest {
3333
unsigned int m_ttreeCacheSize;
3434
std::vector<std::string> m_nativeProtocols;
3535
bool m_valuesSet;
36+
bool m_expectedUseLocalConnectString;
37+
std::string m_expectedLocalConnectPrefix;
38+
std::string m_expectedLocalConnectSuffix;
3639
};
3740
} // namespace edmtest
3841

3942
using namespace edmtest;
4043

41-
//
42-
// constants, enums and typedefs
43-
//
44-
45-
//
46-
// static data member definitions
47-
//
48-
49-
//
50-
// constructors and destructor
51-
//
5244
SiteLocalConfigServiceTester::SiteLocalConfigServiceTester(const edm::ParameterSet& iPSet)
5345
: m_cacheHint(iPSet.getUntrackedParameter<std::string>("sourceCacheHint")),
5446
m_readHint(iPSet.getUntrackedParameter<std::string>("sourceReadHint")),
5547
m_tempDir(iPSet.getUntrackedParameter<std::string>("sourceTempDir")),
5648
m_ttreeCacheSize(iPSet.getUntrackedParameter<unsigned int>("sourceTTreeCacheSize")),
5749
m_nativeProtocols(iPSet.getUntrackedParameter<std::vector<std::string> >("sourceNativeProtocols")),
58-
m_valuesSet(iPSet.getUntrackedParameter<bool>("sourceValuesSet", true)) {}
59-
60-
// SiteLocalConfigServiceTester::SiteLocalConfigServiceTester(const SiteLocalConfigServiceTester& rhs)
61-
// {
62-
// // do actual copying here;
63-
// }
64-
65-
//SiteLocalConfigServiceTester::~SiteLocalConfigServiceTester()
66-
//{
67-
//}
68-
69-
//
70-
// assignment operators
71-
//
72-
// const SiteLocalConfigServiceTester& SiteLocalConfigServiceTester::operator=(const SiteLocalConfigServiceTester& rhs)
73-
// {
74-
// //An exception safe implementation is
75-
// SiteLocalConfigServiceTester temp(rhs);
76-
// swap(rhs);
77-
//
78-
// return *this;
79-
// }
50+
m_valuesSet(iPSet.getUntrackedParameter<bool>("sourceValuesSet", true)),
51+
m_expectedUseLocalConnectString(iPSet.getUntrackedParameter<bool>("expectedUseLocalConnectString")),
52+
m_expectedLocalConnectPrefix(iPSet.getUntrackedParameter<std::string>("expectedLocalConnectPrefix")),
53+
m_expectedLocalConnectSuffix(iPSet.getUntrackedParameter<std::string>("expectedLocalConnectSuffix")) {}
8054

81-
//
82-
// member functions
83-
//
8455
static void throwNotSet(const char* iName) {
8556
throw cms::Exception("TestFailure") << "The value " << iName << " should have been set but was not";
8657
}
@@ -116,9 +87,7 @@ namespace {
11687
}
11788

11889
} // namespace
119-
//
120-
// const member functions
121-
//
90+
12291
void SiteLocalConfigServiceTester::analyze(const edm::Event&, const edm::EventSetup&) {
12392
edm::Service<edm::SiteLocalConfig> pConfig;
12493
if (m_valuesSet) {
@@ -148,10 +117,24 @@ void SiteLocalConfigServiceTester::analyze(const edm::Event&, const edm::EventSe
148117
checkNotSet("sourceTTreeCacheSize", pConfig->sourceTTreeCacheSize());
149118
checkNotSet("sourceNativeProtocols", pConfig->sourceNativeProtocols());
150119
}
151-
}
152120

153-
//
154-
// static member functions
155-
//
121+
if (pConfig->useLocalConnectString() != m_expectedUseLocalConnectString) {
122+
throw cms::Exception("TestFailure") << "The value of useLocalConnectString is \""
123+
<< (pConfig->useLocalConnectString() ? std::string("true")
124+
: std::string("false"))
125+
<< "\" but we expected the value \""
126+
<< (m_expectedUseLocalConnectString ? std::string("true")
127+
: std::string("false"))
128+
<< "\"";
129+
}
130+
if (pConfig->localConnectPrefix() != m_expectedLocalConnectPrefix) {
131+
throw cms::Exception("TestFailure") << "The value of localConnectPrefix is \"" << pConfig->localConnectPrefix()
132+
<< "\" but we expected the value \"" << m_expectedLocalConnectPrefix << "\"";
133+
}
134+
if (pConfig->localConnectSuffix() != m_expectedLocalConnectSuffix) {
135+
throw cms::Exception("TestFailure") << "The value of localConnectSuffix is \"" << pConfig->localConnectSuffix()
136+
<< "\" but we expected the value \"" << m_expectedLocalConnectSuffix << "\"";
137+
}
138+
}
156139

157140
DEFINE_FWK_MODULE(SiteLocalConfigServiceTester);

FWCore/Services/test/full-site-local-config.testfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
<catalog url="trivialcatalog_file:/dummy/storage.xml?protocol=srm"/>
1010
</local-stage-out>
1111
<calib-data>
12-
<frontier-connect>
13-
<proxy url="http://cmsfrontier.dummy.foo:3128"/>
14-
<proxy url="http://cmsfrontier.dummy.foo:3128"/>
15-
</frontier-connect>
12+
<local-connect>
13+
<connectString prefix="Test:Prefix" suffix="Test.Suffix"/>
14+
</local-connect>
1615
</calib-data>
1716
<source-config>
1817
<cache-temp-dir name="/a/b/c"/>

FWCore/Services/test/source-site-local-config.testfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
<catalog url="trivialcatalog_file:/dummy/storage.xml?protocol=srm"/>
1010
</local-stage-out>
1111
<calib-data>
12-
<frontier-connect>
13-
<proxy url="http://cmsfrontier.dummy.foo:3128"/>
14-
<proxy url="http://cmsfrontier.dummy.foo:3128"/>
15-
</frontier-connect>
12+
<local-connect>
13+
<connectString prefix="Test:Prefix" suffix="Test.Suffix"/>
14+
</local-connect>
1615
</calib-data>
1716
<source-config>
1817
<cache-temp-dir name="/a/b/c"/>

0 commit comments

Comments
 (0)