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
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:76
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:183
cond::persistency::IDbAuthentication::principalName
virtual std::string principalName()=0
cond::persistency::ConnectionPool::isLoggingEnabled
bool isLoggingEnabled() const
Definition: ConnectionPool.cc:74
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:174
cond::persistency::ConnectionPool::setLogDestination
void setLogDestination(Logger &logger)
Definition: ConnectionPool.cc:192
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
seconds
double seconds()
SessionImpl.h
cond::persistency::CoralXMLFile
Definition: ConnectionPool.h:32
cond::persistency::ConnectionPool::m_messageLevel
coral::MsgLevel m_messageLevel
Definition: ConnectionPool.h:68
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
cond
Definition: plugin.cc:23
cond::persistency::ConnectionPool::m_frontierSecurity
std::string m_frontierSecurity
Definition: ConnectionPool.h:74
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:188
edm::ParameterSet
Definition: ParameterSet.h:47
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
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:70
cond::persistency::CondDbKey
Definition: ConnectionPool.h:32
cond::persistency::IDbAuthentication
Definition: IDbAuthentication.h:10
cond::persistency::Session
Definition: Session.h:63
cond::persistency::ConnectionPool::m_connectionTimeout
int m_connectionTimeout
Definition: ConnectionPool.h:69
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:129
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
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:65
cond::persistency::ConnectionPool::m_loggingEnabled
bool m_loggingEnabled
Definition: ConnectionPool.h:71
cond::auth::COND_AUTH_PATH_PROPERTY
static constexpr const char *const COND_AUTH_PATH_PROPERTY
Definition: Auth.h:50
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::setConnectionTimeout
void setConnectionTimeout(int seconds)
Definition: ConnectionPool.cc:190
cond::persistency::ConnectionPool::createReadOnlySession
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
Definition: ConnectionPool.cc:178
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:66
cond::persistency::ConnectionPool::m_authenticationService
std::string m_authenticationService
Definition: ConnectionPool.h:67
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:117