CMS 3D CMS Logo

ConnectionPool.cc
Go to the documentation of this file.
2 #include "DbConnectionString.h"
3 #include "IDbAuthentication.h"
4 #include "SessionImpl.h"
5 #include "IOVSchema.h"
6 #include "CoralMsgReporter.h"
7 //
10 // CMSSW includes
12 // coral includes
13 #include "RelationalAccess/ConnectionService.h"
14 #include "RelationalAccess/IAuthenticationService.h"
15 #include "RelationalAccess/IWebCacheControl.h"
16 #include "RelationalAccess/ISessionProxy.h"
17 #include "RelationalAccess/IConnectionServiceConfiguration.h"
18 #include "CoralKernel/Context.h"
19 #include "CoralKernel/IProperty.h"
20 #include "CoralKernel/IPropertyManager.h"
21 
22 namespace cond {
23 
24  namespace persistency {
25 
29  coral::MessageStream::installMsgReporter(m_msgReporter);
30  configure();
31  }
32 
34 
36 
37  void ConnectionPool::setAuthenticationSystem(int authSysCode) { m_authSys = authSysCode; }
38 
40 
42 
43  void ConnectionPool::setParameters(const edm::ParameterSet& connectionPset) {
44  //set the connection parameters from a ParameterSet
45  //if a parameter is not defined, keep the values already set in the data members
46  //(i.e. default if no other setters called, or the ones currently available)
47  setAuthenticationPath(connectionPset.getUntrackedParameter<std::string>("authenticationPath", m_authPath));
48  setAuthenticationSystem(connectionPset.getUntrackedParameter<int>("authenticationSystem", m_authSys));
50  int messageLevel =
51  connectionPset.getUntrackedParameter<int>("messageLevel", 0); //0 corresponds to Error level, current default
52  coral::MsgLevel level = m_messageLevel;
53  switch (messageLevel) {
54  case 0:
56  break;
57  case 1:
58  level = coral::Warning;
59  break;
60  case 2:
61  level = coral::Info;
62  break;
63  case 3:
65  break;
66  default:
68  }
70  setLogging(connectionPset.getUntrackedParameter<bool>("logging", m_loggingEnabled));
71  }
72 
74 
75  void ConnectionPool::configure(coral::IConnectionServiceConfiguration& coralConfig) {
76  coralConfig.disablePoolAutomaticCleanUp();
77  coralConfig.disableConnectionSharing();
78  // message streaming
79  coral::MessageStream::setMsgVerbosity(m_messageLevel);
81 
82  // authentication
83  m_authenticationService = std::string("CORAL/Services/EnvironmentAuthenticationService");
85  // authentication
86  if (authPath.empty()) {
87  // first try to check the env...
88  const char* authEnv = std::getenv(cond::auth::COND_AUTH_PATH);
89  if (authEnv) {
90  authPath += authEnv;
91  }
92  }
93  int authSys = m_authSys;
94  // first attempt, look at the env...
95  const char* authSysEnv = std::getenv(cond::auth::COND_AUTH_SYS);
96  if (authSysEnv) {
97  authSys = ::atoi(authSysEnv);
98  }
99  if (authSys != CondDbKey && authSys != CoralXMLFile) {
100  // take the default
101  authSys = CondDbKey;
102  }
103  std::string servName("");
104  if (authSys == CondDbKey) {
105  if (authPath.empty()) {
106  const char* authEnv = std::getenv("HOME");
107  if (authEnv) {
108  authPath += authEnv;
109  }
110  }
111  servName = "COND/Services/RelationalAuthenticationService";
112  } else if (authSys == CoralXMLFile) {
113  if (authPath.empty()) {
114  authPath = ".";
115  }
116  servName = "COND/Services/XMLAuthenticationService";
117  }
118  if (!authPath.empty()) {
119  m_authenticationService = servName;
120  coral::Context::instance().PropertyManager().property(cond::auth::COND_AUTH_PATH_PROPERTY)->set(authPath);
122  }
123 
124  coralConfig.setAuthenticationService(m_authenticationService);
125  }
126 
128  coral::ConnectionService connServ;
129  configure(connServ.configuration());
130  }
131 
132  std::shared_ptr<coral::ISessionProxy> ConnectionPool::createCoralSession(const std::string& connectionString,
133  const std::string& transactionId,
134  bool writeCapable) {
135  coral::ConnectionService connServ;
136  //all sessions opened with this connection service will share the same frontier security option.
137  std::pair<std::string, std::string> fullConnectionPars =
139  if (!fullConnectionPars.second.empty()) {
140  //all sessions opened with this connection service will share the same TTL settings for TAG, IOV, and PAYLOAD tables.
141  connServ.webCacheControl().setTableTimeToLive(fullConnectionPars.second, TAG::tname, 1);
142  connServ.webCacheControl().setTableTimeToLive(fullConnectionPars.second, IOV::tname, 1);
143  connServ.webCacheControl().setTableTimeToLive(fullConnectionPars.second, PAYLOAD::tname, 3);
144  }
145 
146  return std::shared_ptr<coral::ISessionProxy>(
147  connServ.connect(fullConnectionPars.first,
149  writeCapable ? coral::Update : coral::ReadOnly));
150  }
151 
153  const std::string& transactionId,
154  bool writeCapable) {
155  std::shared_ptr<coral::ISessionProxy> coralSession =
156  createCoralSession(connectionString, transactionId, writeCapable);
157 
158  std::string principalName("");
159  if (!m_authenticationService.empty()) {
160  // need to hard-code somewhere the target name...
161  if (m_authenticationService == "COND/Services/RelationalAuthenticationService") {
162  coral::IHandle<coral::IAuthenticationService> authSvc =
163  coral::Context::instance().query<coral::IAuthenticationService>(m_authenticationService);
164  IDbAuthentication* dbAuth = dynamic_cast<IDbAuthentication*>(authSvc.get());
165  principalName = dbAuth->principalName();
166  }
167  }
168 
169  return Session(std::make_shared<SessionImpl>(coralSession, connectionString, principalName));
170  }
171 
173  return createSession(connectionString, "", writeCapable);
174  }
175 
177  const std::string& transactionId) {
178  return createSession(connectionString, transactionId);
179  }
180 
181  std::shared_ptr<coral::ISessionProxy> ConnectionPool::createCoralSession(const std::string& connectionString,
182  bool writeCapable) {
183  return createCoralSession(connectionString, "", writeCapable);
184  }
185 
187 
189 
190  } // namespace persistency
191 } // namespace cond
personalPlayback.level
level
Definition: personalPlayback.py:22
lumi_dqm_sourceclient-live_cfg.authPath
authPath
Definition: lumi_dqm_sourceclient-live_cfg.py:33
cond::persistency::ConnectionPool::m_pluginManager
cond::CoralServiceManager * m_pluginManager
Definition: ConnectionPool.h:74
cond::auth::COND_READER_ROLE
static constexpr const char *const COND_READER_ROLE
Definition: Auth.h:18
cond::persistency::ConnectionPool::~ConnectionPool
~ConnectionPool()
Definition: ConnectionPool.cc:33
cond::persistency::ConnectionPool::setFrontierSecurity
void setFrontierSecurity(const std::string &signature)
Definition: ConnectionPool.cc:39
cond::persistency::CoralMsgReporter
Definition: CoralMsgReporter.h:31
ConnectionPool.h
IDbAuthentication.h
IOVSchema.h
logger
Definition: logger.py:1
cond::persistency::ConnectionPool::createCoralSession
std::shared_ptr< coral::ISessionProxy > createCoralSession(const std::string &connectionString, bool writeCapable=false)
Definition: ConnectionPool.cc:181
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
cond::persistency::IDbAuthentication::principalName
virtual std::string principalName()=0
cond::persistency::ConnectionPool::isLoggingEnabled
bool isLoggingEnabled() const
Definition: ConnectionPool.cc:73
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
CoralServiceManager.h
cond::persistency::ConnectionPool::createSession
Session createSession(const std::string &connectionString, bool writeCapable=false)
Definition: ConnectionPool.cc:172
cond::persistency::ConnectionPool::setLogDestination
void setLogDestination(Logger &logger)
Definition: ConnectionPool.cc:188
cond::persistency::Logger
Definition: Logger.h:85
cond::auth::COND_WRITER_ROLE
static constexpr const char *const COND_WRITER_ROLE
Definition: Auth.h:17
cond::auth::COND_AUTH_SYS
static constexpr const char *const COND_AUTH_SYS
Definition: Auth.h:12
cond::CoralServiceManager
Definition: CoralServiceManager.h:25
Debug
const bool Debug
Definition: CosmicMuonParameters.h:12
DbConnectionString.h
cond::persistency::TAG::tname
static constexpr char const * tname
Definition: IOVSchema.h:13
SessionImpl.h
cond::persistency::CoralXMLFile
Definition: ConnectionPool.h:32
cond::persistency::ConnectionPool::m_messageLevel
coral::MsgLevel m_messageLevel
Definition: ConnectionPool.h:67
cond::persistency::getConnectionParams
std::pair< std::string, std::string > getConnectionParams(const std::string &connectionString, const std::string &transactionId, const std::string &signature)
Definition: DbConnectionString.cc:39
cond::persistency::ConnectionPool::setAuthenticationSystem
void setAuthenticationSystem(int authSysCode)
Definition: ConnectionPool.cc:37
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond
Definition: plugin.cc:23
cond::persistency::ConnectionPool::m_frontierSecurity
std::string m_frontierSecurity
Definition: ConnectionPool.h:72
beam_dqm_sourceclient-live_cfg.messageLevel
messageLevel
Definition: beam_dqm_sourceclient-live_cfg.py:369
cond::persistency::IOV::tname
static constexpr char const * tname
Definition: IOVSchema.h:110
cond::persistency::ConnectionPool::setMessageVerbosity
void setMessageVerbosity(coral::MsgLevel level)
Definition: ConnectionPool.cc:186
edm::ParameterSet
Definition: ParameterSet.h:47
signature
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined signature
Definition: Activities.doc:4
CoralMsgReporter.h
cond::persistency::ConnectionPool::m_msgReporter
CoralMsgReporter * m_msgReporter
Definition: ConnectionPool.h:68
cond::persistency::CondDbKey
Definition: ConnectionPool.h:32
cond::persistency::IDbAuthentication
Definition: IDbAuthentication.h:10
cond::persistency::Session
Definition: Session.h:63
leef::Error
edm::ErrorSummaryEntry Error
Definition: LogErrorEventFilter.cc:29
cond::persistency::ConnectionPool::setAuthenticationPath
void setAuthenticationPath(const std::string &p)
Definition: ConnectionPool.cc:35
cond::persistency::CoralMsgReporter::subscribe
void subscribe(Logger &logger)
Definition: CoralMsgReporter.cc:143
cond::persistency::ConnectionPool::setParameters
void setParameters(const edm::ParameterSet &connectionPset)
Definition: ConnectionPool.cc:43
cond::persistency::ConnectionPool::configure
void configure()
Definition: ConnectionPool.cc:127
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
cond::auth::COND_AUTH_PATH
static constexpr const char *const COND_AUTH_PATH
Definition: Auth.h:11
cond::persistency::ConnectionPool::m_authPath
std::string m_authPath
Definition: ConnectionPool.h:64
cond::persistency::ConnectionPool::m_loggingEnabled
bool m_loggingEnabled
Definition: ConnectionPool.h:69
cond::auth::COND_AUTH_PATH_PROPERTY
static constexpr const char *const COND_AUTH_PATH_PROPERTY
Definition: Auth.h:43
cond::persistency::ConnectionPool::setLogging
void setLogging(bool flag)
Definition: ConnectionPool.cc:41
cond::persistency::CoralMsgReporter::setOutputLevel
void setOutputLevel(coral::MsgLevel lvl) override
Modify output level.
Definition: CoralMsgReporter.cc:88
cond::persistency::ConnectionPool::ConnectionPool
ConnectionPool()
Definition: ConnectionPool.cc:26
Auth.h
cond::persistency::ConnectionPool::createReadOnlySession
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
Definition: ConnectionPool.cc:176
ParameterSet.h
cond::persistency::PAYLOAD::tname
static constexpr char const * tname
Definition: IOVSchema.h:73
l1RCTOmdsFedVectorProducer_cfi.connectionString
connectionString
Definition: l1RCTOmdsFedVectorProducer_cfi.py:4
cond::persistency::ConnectionPool::m_authSys
int m_authSys
Definition: ConnectionPool.h:65
cond::persistency::ConnectionPool::m_authenticationService
std::string m_authenticationService
Definition: ConnectionPool.h:66
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116