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  setConnectionTimeout(connectionPset.getUntrackedParameter<int>("connectionTimeout", m_connectionTimeout));
71  setLogging(connectionPset.getUntrackedParameter<bool>("logging", m_loggingEnabled));
72  }
73 
75 
76  void ConnectionPool::configure(coral::IConnectionServiceConfiguration& coralConfig) {
77  coralConfig.disablePoolAutomaticCleanUp();
78  coralConfig.disableConnectionSharing();
79  coralConfig.setConnectionTimeOut(m_connectionTimeout);
80  // message streaming
81  coral::MessageStream::setMsgVerbosity(m_messageLevel);
83 
84  // authentication
85  m_authenticationService = std::string("CORAL/Services/EnvironmentAuthenticationService");
87  // authentication
88  if (authPath.empty()) {
89  // first try to check the env...
90  const char* authEnv = std::getenv(cond::auth::COND_AUTH_PATH);
91  if (authEnv) {
92  authPath += authEnv;
93  }
94  }
95  int authSys = m_authSys;
96  // first attempt, look at the env...
97  const char* authSysEnv = std::getenv(cond::auth::COND_AUTH_SYS);
98  if (authSysEnv) {
99  authSys = ::atoi(authSysEnv);
100  }
101  if (authSys != CondDbKey && authSys != CoralXMLFile) {
102  // take the default
103  authSys = CondDbKey;
104  }
105  std::string servName("");
106  if (authSys == CondDbKey) {
107  if (authPath.empty()) {
108  const char* authEnv = std::getenv("HOME");
109  if (authEnv) {
110  authPath += authEnv;
111  }
112  }
113  servName = "COND/Services/RelationalAuthenticationService";
114  } else if (authSys == CoralXMLFile) {
115  if (authPath.empty()) {
116  authPath = ".";
117  }
118  servName = "COND/Services/XMLAuthenticationService";
119  }
120  if (!authPath.empty()) {
121  m_authenticationService = servName;
122  coral::Context::instance().PropertyManager().property(cond::auth::COND_AUTH_PATH_PROPERTY)->set(authPath);
124  }
125 
126  coralConfig.setAuthenticationService(m_authenticationService);
127  }
128 
130  coral::ConnectionService connServ;
131  configure(connServ.configuration());
132  }
133 
134  std::shared_ptr<coral::ISessionProxy> ConnectionPool::createCoralSession(const std::string& connectionString,
135  const std::string& transactionId,
136  bool writeCapable) {
137  coral::ConnectionService connServ;
138  //all sessions opened with this connection service will share the same frontier security option.
139  std::pair<std::string, std::string> fullConnectionPars =
141  if (!fullConnectionPars.second.empty()) {
142  //all sessions opened with this connection service will share the same TTL settings for TAG, IOV, and PAYLOAD tables.
143  connServ.webCacheControl().setTableTimeToLive(fullConnectionPars.second, TAG::tname, 1);
144  connServ.webCacheControl().setTableTimeToLive(fullConnectionPars.second, IOV::tname, 1);
145  connServ.webCacheControl().setTableTimeToLive(fullConnectionPars.second, PAYLOAD::tname, 3);
146  }
147 
148  return std::shared_ptr<coral::ISessionProxy>(
149  connServ.connect(fullConnectionPars.first,
151  writeCapable ? coral::Update : coral::ReadOnly));
152  }
153 
155  const std::string& transactionId,
156  bool writeCapable) {
157  std::shared_ptr<coral::ISessionProxy> coralSession =
158  createCoralSession(connectionString, transactionId, writeCapable);
159 
160  std::string principalName("");
161  if (!m_authenticationService.empty()) {
162  // need to hard-code somewhere the target name...
163  if (m_authenticationService == "COND/Services/RelationalAuthenticationService") {
164  coral::IHandle<coral::IAuthenticationService> authSvc =
165  coral::Context::instance().query<coral::IAuthenticationService>(m_authenticationService);
166  IDbAuthentication* dbAuth = dynamic_cast<IDbAuthentication*>(authSvc.get());
167  principalName = dbAuth->principalName();
168  }
169  }
170 
171  return Session(std::make_shared<SessionImpl>(coralSession, connectionString, principalName));
172  }
173 
175  return createSession(connectionString, "", writeCapable);
176  }
177 
179  const std::string& transactionId) {
180  return createSession(connectionString, transactionId);
181  }
182 
183  std::shared_ptr<coral::ISessionProxy> ConnectionPool::createCoralSession(const std::string& connectionString,
184  bool writeCapable) {
185  return createCoralSession(connectionString, "", writeCapable);
186  }
187 
189 
191 
193 
194  } // namespace persistency
195 } // namespace cond
edm::ErrorSummaryEntry Error
void setLogDestination(Logger &logger)
double seconds()
static PFTauRenderPlugin instance
virtual std::string principalName()=0
static constexpr const char *const COND_AUTH_PATH
Definition: Auth.h:11
static constexpr const char *const COND_AUTH_PATH_PROPERTY
Definition: Auth.h:50
void setParameters(const edm::ParameterSet &connectionPset)
T getUntrackedParameter(std::string const &, T const &) const
static constexpr char const * tname
Definition: IOVSchema.h:73
static constexpr const char *const COND_READER_ROLE
Definition: Auth.h:18
static constexpr char const * tname
Definition: IOVSchema.h:13
void setAuthenticationSystem(int authSysCode)
Session createSession(const std::string &connectionString, bool writeCapable=false)
Definition: logger.py:1
void setMessageVerbosity(coral::MsgLevel level)
void setOutputLevel(coral::MsgLevel lvl) override
Modify output level.
std::pair< std::string, std::string > getConnectionParams(const std::string &connectionString, const std::string &transactionId, const std::string &signature)
static constexpr char const * tname
Definition: IOVSchema.h:110
Definition: plugin.cc:23
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
static constexpr const char *const COND_AUTH_SYS
Definition: Auth.h:12
static constexpr const char *const COND_WRITER_ROLE
Definition: Auth.h:17
cond::CoralServiceManager * m_pluginManager
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
void setAuthenticationPath(const std::string &p)
std::shared_ptr< coral::ISessionProxy > createCoralSession(const std::string &connectionString, bool writeCapable=false)
const bool Debug
void setFrontierSecurity(const std::string &signature)