CMS 3D CMS Logo

ConnectionPool.cc
Go to the documentation of this file.
2 #include "DbConnectionString.h"
3 #include "SessionImpl.h"
4 #include "IOVSchema.h"
5 //
8 // CMSSW includes
10 // coral includes
11 #include "RelationalAccess/ConnectionService.h"
12 #include "RelationalAccess/IWebCacheControl.h"
13 #include "RelationalAccess/ISessionProxy.h"
14 #include "RelationalAccess/IConnectionServiceConfiguration.h"
15 #include "CoralKernel/Context.h"
16 #include "CoralKernel/IProperty.h"
17 #include "CoralKernel/IPropertyManager.h"
18 // externals
19 #include <boost/filesystem/operations.hpp>
20 
21 namespace cond {
22 
23  namespace persistency {
24 
27  configure();
28  }
29 
31 
33 
34  void ConnectionPool::setAuthenticationSystem(int authSysCode) { m_authSys = authSysCode; }
35 
37 
39 
40  void ConnectionPool::setParameters(const edm::ParameterSet& connectionPset) {
41  //set the connection parameters from a ParameterSet
42  //if a parameter is not defined, keep the values already set in the data members
43  //(i.e. default if no other setters called, or the ones currently available)
44  setAuthenticationPath(connectionPset.getUntrackedParameter<std::string>("authenticationPath", m_authPath));
45  setAuthenticationSystem(connectionPset.getUntrackedParameter<int>("authenticationSystem", m_authSys));
47  int messageLevel =
48  connectionPset.getUntrackedParameter<int>("messageLevel", 0); //0 corresponds to Error level, current default
49  coral::MsgLevel level = m_messageLevel;
50  switch (messageLevel) {
51  case 0:
52  level = coral::Error;
53  break;
54  case 1:
55  level = coral::Warning;
56  break;
57  case 2:
58  level = coral::Info;
59  break;
60  case 3:
61  level = coral::Debug;
62  break;
63  default:
64  level = coral::Error;
65  }
66  setMessageVerbosity(level);
67  setLogging(connectionPset.getUntrackedParameter<bool>("logging", m_loggingEnabled));
68  }
69 
71 
72  void ConnectionPool::configure(coral::IConnectionServiceConfiguration& coralConfig) {
73  coralConfig.disablePoolAutomaticCleanUp();
74  coralConfig.disableConnectionSharing();
75  // message streaming
76  coral::MessageStream::setMsgVerbosity(m_messageLevel);
77  std::string authServiceName("CORAL/Services/EnvironmentAuthenticationService");
79  // authentication
80  if (authPath.empty()) {
81  // first try to check the env...
82  const char* authEnv = std::getenv(cond::auth::COND_AUTH_PATH);
83  if (authEnv) {
84  authPath += authEnv;
85  }
86  }
87  int authSys = m_authSys;
88  // first attempt, look at the env...
89  const char* authSysEnv = std::getenv(cond::auth::COND_AUTH_SYS);
90  if (authSysEnv) {
91  authSys = ::atoi(authSysEnv);
92  }
93  if (authSys != CondDbKey && authSys != CoralXMLFile) {
94  // take the default
95  authSys = CondDbKey;
96  }
97  std::string servName("");
98  if (authSys == CondDbKey) {
99  if (authPath.empty()) {
100  const char* authEnv = std::getenv("HOME");
101  if (authEnv) {
102  authPath += authEnv;
103  }
104  }
105  servName = "COND/Services/RelationalAuthenticationService";
106  } else if (authSys == CoralXMLFile) {
107  if (authPath.empty()) {
108  authPath = ".";
109  }
110  servName = "COND/Services/XMLAuthenticationService";
111  }
112  if (!authPath.empty()) {
113  authServiceName = servName;
114  coral::Context::instance().PropertyManager().property(cond::auth::COND_AUTH_PATH_PROPERTY)->set(authPath);
115  coral::Context::instance().loadComponent(authServiceName, m_pluginManager);
116  }
117 
118  coralConfig.setAuthenticationService(authServiceName);
119  }
120 
122  coral::ConnectionService connServ;
123  configure(connServ.configuration());
124  }
125 
126  std::shared_ptr<coral::ISessionProxy> ConnectionPool::createCoralSession(const std::string& connectionString,
127  const std::string& transactionId,
128  bool writeCapable) {
129  coral::ConnectionService connServ;
130  //all sessions opened with this connection service will share the same frontier security option.
131  std::pair<std::string, std::string> fullConnectionPars =
132  getConnectionParams(connectionString, transactionId, m_frontierSecurity);
133  if (!fullConnectionPars.second.empty()) {
134  //all sessions opened with this connection service will share the same TTL settings for TAG, IOV, and PAYLOAD tables.
135  connServ.webCacheControl().setTableTimeToLive(fullConnectionPars.second, TAG::tname, 1);
136  connServ.webCacheControl().setTableTimeToLive(fullConnectionPars.second, IOV::tname, 1);
137  connServ.webCacheControl().setTableTimeToLive(fullConnectionPars.second, PAYLOAD::tname, 3);
138  }
139 
140  return std::shared_ptr<coral::ISessionProxy>(
141  connServ.connect(fullConnectionPars.first,
143  writeCapable ? coral::Update : coral::ReadOnly));
144  }
145 
147  const std::string& transactionId,
148  bool writeCapable) {
149  std::shared_ptr<coral::ISessionProxy> coralSession =
150  createCoralSession(connectionString, transactionId, writeCapable);
151  return Session(std::make_shared<SessionImpl>(coralSession, connectionString));
152  }
153 
155  return createSession(connectionString, "", writeCapable);
156  }
157 
159  const std::string& transactionId) {
160  return createSession(connectionString, transactionId);
161  }
162 
163  std::shared_ptr<coral::ISessionProxy> ConnectionPool::createCoralSession(const std::string& connectionString,
164  bool writeCapable) {
165  return createCoralSession(connectionString, "", writeCapable);
166  }
167 
169 
170  } // namespace persistency
171 } // namespace cond
edm::ErrorSummaryEntry Error
T getUntrackedParameter(std::string const &, T const &) const
static PFTauRenderPlugin instance
static constexpr const char *const COND_AUTH_PATH
Definition: Auth.h:10
static constexpr const char *const COND_AUTH_PATH_PROPERTY
Definition: Auth.h:27
void setParameters(const edm::ParameterSet &connectionPset)
static char const * tname
Definition: IOVSchema.h:66
static char const * tname
Definition: IOVSchema.h:13
static constexpr const char *const COND_READER_ROLE
Definition: Auth.h:17
void setAuthenticationSystem(int authSysCode)
Session createSession(const std::string &connectionString, bool writeCapable=false)
void setMessageVerbosity(coral::MsgLevel level)
std::pair< std::string, std::string > getConnectionParams(const std::string &connectionString, const std::string &transactionId, const std::string &signature)
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:11
static constexpr const char *const COND_WRITER_ROLE
Definition: Auth.h:16
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
static char const * tname
Definition: IOVSchema.h:103
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)