CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
25  static const std::string POOL_IOV_TABLE_DATA("IOV_DATA");
26  static const std::string ORA_IOV_TABLE_1("ORA_C_COND_IOVSEQUENCE");
27  static const std::string ORA_IOV_TABLE_2("ORA_C_COND_IOVSEQU_A0");
28  static const std::string ORA_IOV_TABLE_3("ORA_C_COND_IOVSEQU_A1");
29 
32  configure();
33  }
34 
36  delete m_pluginManager;
37  }
38 
40  m_authPath = p;
41  }
42 
43  void ConnectionPool::setAuthenticationSystem( int authSysCode ){
44  m_authSys = authSysCode;
45  }
46 
47  void ConnectionPool::setLogging( bool flag ){
48  m_loggingEnabled = flag;
49  }
50 
51  void ConnectionPool::setParameters( const edm::ParameterSet& connectionPset ){
52  setAuthenticationPath( connectionPset.getUntrackedParameter<std::string>("authenticationPath","") );
53  setAuthenticationSystem( connectionPset.getUntrackedParameter<int>("authenticationSystem",0) );
54  int messageLevel = connectionPset.getUntrackedParameter<int>("messageLevel",0);
55  coral::MsgLevel level = coral::Error;
56  switch (messageLevel) {
57  case 0 :
58  level = coral::Error;
59  break;
60  case 1:
61  level = coral::Warning;
62  break;
63  case 2:
64  level = coral::Info;
65  break;
66  case 3:
67  level = coral::Debug;
68  break;
69  default:
70  level = coral::Error;
71  }
72  setMessageVerbosity(level);
73  setLogging( connectionPset.getUntrackedParameter<bool>("logging",false) );
74  }
75 
77  return m_loggingEnabled;
78  }
79 
80  void ConnectionPool::configure( coral::IConnectionServiceConfiguration& coralConfig){
81 
82  coralConfig.disablePoolAutomaticCleanUp();
83  coralConfig.disableConnectionSharing();
84  // message streaming
85  coral::MessageStream::setMsgVerbosity( m_messageLevel );
86  std::string authServiceName("CORAL/Services/EnvironmentAuthenticationService");
88  // authentication
89  if( authPath.empty() ){
90  // first try to check the env...
91  const char* authEnv = ::getenv( cond::Auth::COND_AUTH_PATH );
92  if(authEnv){
93  authPath += authEnv;
94  }
95  }
96  int authSys = m_authSys;
97  // first attempt, look at the env...
98  const char* authSysEnv = ::getenv( cond::Auth::COND_AUTH_SYS );
99  if( authSysEnv ){
100  authSys = ::atoi( authSysEnv );
101  }
102  if( authSys !=CondDbKey && authSys != CoralXMLFile ){
103  // take the default
104  authSys = CondDbKey;
105  }
106  std::string servName("");
107  if( authSys == CondDbKey ){
108  if( authPath.empty() ){
109  const char* authEnv = ::getenv("HOME");
110  if(authEnv){
111  authPath += authEnv;
112  }
113  }
114  servName = "COND/Services/RelationalAuthenticationService";
115  } else if( authSys == CoralXMLFile ){
116  if( authPath.empty() ){
117  authPath = ".";
118  }
119  servName = "COND/Services/XMLAuthenticationService";
120  }
121  if( !authPath.empty() ){
122  authServiceName = servName;
123  coral::Context::instance().PropertyManager().property(cond::Auth::COND_AUTH_PATH_PROPERTY)->set(authPath);
124  coral::Context::instance().loadComponent( authServiceName, m_pluginManager );
125  }
126 
127  coralConfig.setAuthenticationService( authServiceName );
128  }
129 
131  coral::ConnectionService connServ;
132  configure( connServ.configuration() );
133  }
134 
135  boost::shared_ptr<coral::ISessionProxy> ConnectionPool::createCoralSession( const std::string& connectionString,
136  const std::string& transactionId,
137  bool writeCapable ){
138  coral::ConnectionService connServ;
139  std::pair<std::string,std::string> fullConnectionPars = getConnectionParams( connectionString, transactionId );
140  if( !fullConnectionPars.second.empty() ) {
141  // the olds formats
142  connServ.webCacheControl().refreshTable( fullConnectionPars.second, POOL_IOV_TABLE_DATA );
143  connServ.webCacheControl().refreshTable( fullConnectionPars.second, ORA_IOV_TABLE_1 );
144  connServ.webCacheControl().refreshTable( fullConnectionPars.second, ORA_IOV_TABLE_2 );
145  connServ.webCacheControl().refreshTable( fullConnectionPars.second, ORA_IOV_TABLE_3 );
146  // the new schema...
147  connServ.webCacheControl().setTableTimeToLive( fullConnectionPars.second, TAG::tname, 1 );
148  connServ.webCacheControl().setTableTimeToLive( fullConnectionPars.second, IOV::tname, 1 );
149  connServ.webCacheControl().setTableTimeToLive( fullConnectionPars.second, PAYLOAD::tname, 3 );
150  }
151 
152  return boost::shared_ptr<coral::ISessionProxy>( connServ.connect( fullConnectionPars.first,
154  writeCapable?coral::Update:coral::ReadOnly ) );
155  }
156 
158  const std::string& transactionId,
159  bool writeCapable,
160  BackendType backType){
161  coral::ConnectionService connServ;
162  std::pair<std::string,std::string> fullConnectionPars = getConnectionParams( connectionString, transactionId );
163  if( !fullConnectionPars.second.empty() ) {
164  // the olds formats
165  connServ.webCacheControl().refreshTable( fullConnectionPars.second, POOL_IOV_TABLE_DATA );
166  connServ.webCacheControl().refreshTable( fullConnectionPars.second, ORA_IOV_TABLE_1 );
167  connServ.webCacheControl().refreshTable( fullConnectionPars.second, ORA_IOV_TABLE_2 );
168  connServ.webCacheControl().refreshTable( fullConnectionPars.second, ORA_IOV_TABLE_3 );
169  // the new schema...
170  connServ.webCacheControl().setTableTimeToLive( fullConnectionPars.second, TAG::tname, 1 );
171  connServ.webCacheControl().setTableTimeToLive( fullConnectionPars.second, IOV::tname, 1 );
172  connServ.webCacheControl().setTableTimeToLive( fullConnectionPars.second, PAYLOAD::tname, 3 );
173  }
174 
175  boost::shared_ptr<coral::ISessionProxy> coralSession = createCoralSession( connectionString, transactionId, writeCapable );
176 
177  BackendType bt;
178  auto it = m_dbTypes.find( connectionString);
179  if( it == m_dbTypes.end() ){
180  bt = checkBackendType( coralSession, connectionString );
181  if( bt == UNKNOWN_DB && writeCapable) bt = backType;
182  m_dbTypes.insert( std::make_pair( connectionString, bt ) );
183  } else {
184  bt = (BackendType) it->second;
185  }
186 
187  std::shared_ptr<SessionImpl> impl( new SessionImpl( coralSession, connectionString, bt ) );
188  return Session( impl );
189  }
190 
191  Session ConnectionPool::createSession( const std::string& connectionString, bool writeCapable, BackendType backType ){
192  return createSession( connectionString, "", writeCapable, backType );
193  }
194 
195  Session ConnectionPool::createReadOnlySession( const std::string& connectionString, const std::string& transactionId ){
196  return createSession( connectionString, transactionId );
197  }
198 
199  boost::shared_ptr<coral::ISessionProxy> ConnectionPool::createCoralSession( const std::string& connectionString,
200  bool writeCapable ){
201  return createCoralSession( connectionString, "", writeCapable );
202  }
203 
206  }
207 
208 
209 
210  }
211 }
static const std::string ORA_IOV_TABLE_1("ORA_C_COND_IOVSEQUENCE")
BackendType checkBackendType(boost::shared_ptr< coral::ISessionProxy > &coralSession, const std::string &connectionString)
Definition: SessionImpl.cc:63
T getUntrackedParameter(std::string const &, T const &) const
static PFTauRenderPlugin instance
boost::shared_ptr< coral::ISessionProxy > createCoralSession(const std::string &connectionString, bool writeCapable=false)
static const std::string COND_AUTH_PATH_PROPERTY
Definition: Auth.h:27
static const std::string ORA_IOV_TABLE_3("ORA_C_COND_IOVSEQU_A1")
void setParameters(const edm::ParameterSet &connectionPset)
static char const * tname
Definition: IOVSchema.h:48
std::pair< std::string, std::string > getConnectionParams(const std::string &connectionString, const std::string &transactionId)
static char const * tname
Definition: IOVSchema.h:13
void setAuthenticationSystem(int authSysCode)
static const char * COND_AUTH_SYS
Definition: Auth.h:13
Session createSession(const std::string &connectionString, bool writeCapable=false, BackendType backType=DEFAULT_DB)
static const std::string COND_WRITER_ROLE
Definition: Auth.h:18
void setMessageVerbosity(coral::MsgLevel level)
BackendType
Definition: Types.h:23
std::map< std::string, int > m_dbTypes
static const std::string COND_READER_ROLE
Definition: Auth.h:19
static const std::string POOL_IOV_TABLE_DATA("IOV_DATA")
static const char * COND_AUTH_PATH
Definition: Auth.h:12
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
tuple level
Definition: testEve_cfg.py:34
cond::CoralServiceManager * m_pluginManager
static const std::string ORA_IOV_TABLE_2("ORA_C_COND_IOVSEQU_A0")
static char const * tname
Definition: IOVSchema.h:79
void setAuthenticationPath(const std::string &p)
const bool Debug