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  delete m_pluginManager;
32  }
33 
35  m_authPath = p;
36  }
37 
38  void ConnectionPool::setAuthenticationSystem( int authSysCode ){
39  m_authSys = authSysCode;
40  }
41 
44  }
45 
48  }
49 
50  void ConnectionPool::setParameters( const edm::ParameterSet& connectionPset ){
51  //set the connection parameters from a ParameterSet
52  //if a parameter is not defined, keep the values already set in the data members
53  //(i.e. default if no other setters called, or the ones currently available)
54  setAuthenticationPath( connectionPset.getUntrackedParameter<std::string>( "authenticationPath", m_authPath ) );
55  setAuthenticationSystem( connectionPset.getUntrackedParameter<int>( "authenticationSystem", m_authSys ) );
57  int messageLevel = connectionPset.getUntrackedParameter<int>( "messageLevel", 0 ); //0 corresponds to Error level, current default
58  coral::MsgLevel level = m_messageLevel;
59  switch (messageLevel) {
60  case 0:
61  level = coral::Error;
62  break;
63  case 1:
64  level = coral::Warning;
65  break;
66  case 2:
67  level = coral::Info;
68  break;
69  case 3:
70  level = coral::Debug;
71  break;
72  default:
73  level = coral::Error;
74  }
75  setMessageVerbosity( level );
76  setLogging( connectionPset.getUntrackedParameter<bool>( "logging", m_loggingEnabled ) );
77  }
78 
80  return m_loggingEnabled;
81  }
82 
83  void ConnectionPool::configure( coral::IConnectionServiceConfiguration& coralConfig ){
84  coralConfig.disablePoolAutomaticCleanUp();
85  coralConfig.disableConnectionSharing();
86  // message streaming
87  coral::MessageStream::setMsgVerbosity( m_messageLevel );
88  std::string authServiceName( "CORAL/Services/EnvironmentAuthenticationService" );
90  // authentication
91  if( authPath.empty() ){
92  // first try to check the env...
93  const char* authEnv = ::getenv( cond::auth::COND_AUTH_PATH );
94  if(authEnv){
95  authPath += authEnv;
96  }
97  }
98  int authSys = m_authSys;
99  // first attempt, look at the env...
100  const char* authSysEnv = ::getenv( cond::auth::COND_AUTH_SYS );
101  if( authSysEnv ){
102  authSys = ::atoi( authSysEnv );
103  }
104  if( authSys !=CondDbKey && authSys != CoralXMLFile ){
105  // take the default
106  authSys = CondDbKey;
107  }
108  std::string servName( "" );
109  if( authSys == CondDbKey ){
110  if( authPath.empty() ){
111  const char* authEnv = ::getenv( "HOME" );
112  if(authEnv) {
113  authPath += authEnv;
114  }
115  }
116  servName = "COND/Services/RelationalAuthenticationService";
117  } else if( authSys == CoralXMLFile ){
118  if( authPath.empty() ){
119  authPath = ".";
120  }
121  servName = "COND/Services/XMLAuthenticationService";
122  }
123  if( !authPath.empty() ){
124  authServiceName = servName;
125  coral::Context::instance().PropertyManager().property(cond::auth::COND_AUTH_PATH_PROPERTY)->set(authPath);
126  coral::Context::instance().loadComponent( authServiceName, m_pluginManager );
127  }
128 
129  coralConfig.setAuthenticationService( authServiceName );
130  }
131 
133  coral::ConnectionService connServ;
134  configure( connServ.configuration() );
135  }
136 
137  std::shared_ptr<coral::ISessionProxy> ConnectionPool::createCoralSession( const std::string& connectionString,
138  const std::string& transactionId,
139  bool writeCapable ){
140  coral::ConnectionService connServ;
141  //all sessions opened with this connection service will share the same frontier security option.
142  std::pair<std::string,std::string> fullConnectionPars = getConnectionParams( connectionString, transactionId, m_frontierSecurity );
143  if( !fullConnectionPars.second.empty() ) {
144  //all sessions opened with this connection service will share the same TTL settings for TAG, IOV, and PAYLOAD tables.
145  connServ.webCacheControl().setTableTimeToLive( fullConnectionPars.second, TAG::tname, 1 );
146  connServ.webCacheControl().setTableTimeToLive( fullConnectionPars.second, IOV::tname, 1 );
147  connServ.webCacheControl().setTableTimeToLive( fullConnectionPars.second, PAYLOAD::tname, 3 );
148  }
149 
150  return std::shared_ptr<coral::ISessionProxy>( connServ.connect( fullConnectionPars.first,
152  writeCapable ? coral::Update : coral::ReadOnly ) );
153  }
154 
156  const std::string& transactionId,
157  bool writeCapable ){
158  std::shared_ptr<coral::ISessionProxy> coralSession = createCoralSession( connectionString, transactionId, writeCapable );
159  return Session( std::make_shared<SessionImpl>( coralSession, connectionString ));
160  }
161 
162  Session ConnectionPool::createSession( const std::string& connectionString, bool writeCapable ){
163  return createSession( connectionString, "", writeCapable );
164  }
165 
166  Session ConnectionPool::createReadOnlySession( const std::string& connectionString, const std::string& transactionId ){
167  return createSession( connectionString, transactionId );
168  }
169 
170  std::shared_ptr<coral::ISessionProxy> ConnectionPool::createCoralSession( const std::string& connectionString,
171  bool writeCapable ){
172  return createCoralSession( connectionString, "", writeCapable );
173  }
174 
177  }
178 
179 
180 
181  }
182 }
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:48
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:24
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:79
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)