CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DbConnectionConfiguration.cc
Go to the documentation of this file.
1 //local includes
5 // CMSSW includes
7 //#include "FWCore/MessageLogger/interface/MessageLogger.h"
8 // coral includes
9 #include "RelationalAccess/IConnectionServiceConfiguration.h"
10 #include "CoralKernel/Context.h"
11 #include "CoralKernel/IProperty.h"
12 #include "CoralKernel/IPropertyManager.h"
13 // externals
14 #include <boost/filesystem/operations.hpp>
15 
16 std::vector<cond::DbConnectionConfiguration>&
18  static std::vector<DbConnectionConfiguration> s_defaultConfigurations;
19  // coral default
20  s_defaultConfigurations.push_back( cond::DbConnectionConfiguration() );
21  // cms default
22  s_defaultConfigurations.push_back( cond::DbConnectionConfiguration( false, 0, false, 10, 60, false, "", "", coral::Error, coral::monitor::Off, false ) );
23  // prod default
24  s_defaultConfigurations.push_back( cond::DbConnectionConfiguration( false, 0, false, 10, 60, false, "", "", coral::Error, coral::monitor::Off, false ) );
25  // tool default
26  s_defaultConfigurations.push_back( cond::DbConnectionConfiguration( false, 0, false, 10, 60, false, "", "",coral::Error, coral::monitor::Off, false ) );
27  // web default
28  s_defaultConfigurations.push_back( cond::DbConnectionConfiguration( false, 0, false, 10, 60, false, "", "",coral::Error, coral::monitor::Off, false ) );
29  return s_defaultConfigurations;
30 }
31 
33  m_connectionSharing(false,false),
34  m_connectionTimeOut(false,0),
35  m_readOnlySessionOnUpdateConnections(false,false),
36  m_connectionRetrialPeriod(false,0),
37  m_connectionRetrialTimeOut(false,0),
38  m_poolAutomaticCleanUp(false,false),
39  m_authPath(""),
40  m_authSys(0),
41  m_transactionId(),
42  m_messageLevel(coral::Error),
43  m_monitoringLevel(coral::monitor::Off),
44  m_SQLMonitoring(false),
45  m_pluginManager(new CoralServiceManager){
46 }
47 
49  int connectionTimeOut,
50  bool readOnlySessionOnUpdateConnections,
51  int connectionRetrialPeriod,
52  int connectionRetrialTimeOut,
53  bool poolAutomaticCleanUp,
54  const::std::string& authenticationPath,
55  const::std::string& transactionId,
56  coral::MsgLevel msgLev,
57  coral::monitor::Level monitorLev,
58  bool SQLMonitoring ):
59  m_connectionSharing(true,connectionSharing),
60  m_connectionTimeOut(true,connectionTimeOut),
61  m_readOnlySessionOnUpdateConnections(true,readOnlySessionOnUpdateConnections),
62  m_connectionRetrialPeriod(true,connectionRetrialPeriod),
63  m_connectionRetrialTimeOut(true,connectionRetrialTimeOut),
64  m_poolAutomaticCleanUp(true,poolAutomaticCleanUp),
65  m_authPath(authenticationPath),
66  m_authSys(0),
67  m_transactionId(transactionId),
68  m_messageLevel(msgLev),
69  m_monitoringLevel(monitorLev),
70  m_SQLMonitoring(SQLMonitoring),
71  m_pluginManager(new CoralServiceManager){
72 }
73 
75  m_connectionSharing(rhs.m_connectionSharing),
76  m_connectionTimeOut(rhs.m_connectionTimeOut),
77  m_readOnlySessionOnUpdateConnections(rhs.m_readOnlySessionOnUpdateConnections),
78  m_connectionRetrialPeriod(rhs.m_connectionRetrialPeriod),
79  m_connectionRetrialTimeOut(rhs.m_connectionRetrialTimeOut),
80  m_poolAutomaticCleanUp(rhs.m_poolAutomaticCleanUp),
81  m_authPath(rhs.m_authPath),
82  m_authSys(rhs.m_authSys),
83  m_transactionId(rhs.m_transactionId),
84  m_messageLevel(rhs.m_messageLevel),
85  m_monitoringLevel(rhs.m_monitoringLevel),
86  m_SQLMonitoring(rhs.m_SQLMonitoring),
87  m_pluginManager(new CoralServiceManager){
88 }
89 
91  delete m_pluginManager;
92 }
93 
96  m_connectionSharing = rhs.m_connectionSharing;
97  m_connectionTimeOut = rhs.m_connectionTimeOut;
98  m_readOnlySessionOnUpdateConnections = rhs.m_readOnlySessionOnUpdateConnections;
99  m_connectionRetrialPeriod = rhs.m_connectionRetrialPeriod;
100  m_connectionRetrialTimeOut = rhs.m_connectionRetrialTimeOut;
101  m_poolAutomaticCleanUp = rhs.m_poolAutomaticCleanUp;
102  m_authPath = rhs.m_authPath;
103  m_authSys = rhs.m_authSys;
104  m_transactionId=rhs.m_transactionId;
105  m_messageLevel = rhs.m_messageLevel;
106  m_monitoringLevel = rhs.m_monitoringLevel;
107  m_SQLMonitoring = rhs.m_SQLMonitoring;
108  return *this;
109 }
110 
112  std::string authPath = connectionPset.getUntrackedParameter<std::string>("authenticationPath","");
113  setAuthenticationPath(authPath);
114  int authSysPar = connectionPset.getUntrackedParameter<int>("authenticationSystem",0);
115  setAuthenticationSystem( authSysPar );
116  setTransactionId(connectionPset.getUntrackedParameter<std::string>("transactionId",""));
117  int messageLevel = connectionPset.getUntrackedParameter<int>("messageLevel",0);
118  coral::MsgLevel level = coral::Error;
119  switch (messageLevel) {
120  case 0 :
121  level = coral::Error;
122  break;
123  case 1:
124  level = coral::Warning;
125  break;
126  case 2:
127  level = coral::Info;
128  break;
129  case 3:
130  level = coral::Debug;
131  break;
132  default:
133  level = coral::Error;
134  }
135  setMessageLevel(level);
136  bool enableConnectionSharing = connectionPset.getUntrackedParameter<bool>("enableConnectionSharing",true);
137  setConnectionSharing( enableConnectionSharing );
138  int connectionTimeOut = connectionPset.getUntrackedParameter<int>("connectionTimeOut",600);
139  setConnectionTimeOut( connectionTimeOut );
140  bool enableReadOnlySessionOnUpdateConnection = connectionPset.getUntrackedParameter<bool>("enableReadOnlySessionOnUpdateConnection",true);
141  setReadOnlySessionOnUpdateConnections( enableReadOnlySessionOnUpdateConnection );
142  int connectionRetrialPeriod = connectionPset.getUntrackedParameter<int>("connectionRetrialPeriod",30);
143  setConnectionRetrialPeriod( connectionRetrialPeriod );
144  int connectionRetrialTimeOut = connectionPset.getUntrackedParameter<int>("connectionRetrialTimeOut",180);
145  setConnectionRetrialTimeOut( connectionRetrialTimeOut );
146  bool enablePoolAutomaticCleanUp = connectionPset.getUntrackedParameter<bool>("enablePoolAutomaticCleanUp",false);
147  setPoolAutomaticCleanUp( enablePoolAutomaticCleanUp );
148  //int idleConnectionCleanupPeriod = connectionPset.getUntrackedParameter<int>("idleConnectionCleanupPeriod",300);
149 }
150 
152  m_connectionSharing.first = true;
153  m_connectionSharing.second = flag;
154 }
155 
157  m_connectionTimeOut.first = true;
158  m_connectionTimeOut.second = timeOut;
159 }
160 
162  m_readOnlySessionOnUpdateConnections.first = true;
163  m_readOnlySessionOnUpdateConnections.second = flag;
164 }
165 
167  m_connectionRetrialPeriod.first = true;
168  m_connectionRetrialPeriod.second = period;
169 }
170 
172  m_connectionRetrialTimeOut.first = true;
173  m_connectionRetrialTimeOut.second = timeout;
174 }
175 
177  m_poolAutomaticCleanUp.first = true;
178  m_poolAutomaticCleanUp.second = flag;
179 }
180 
182  m_authPath = p;
183 }
184 
186  m_authSys = authSysCode;
187 }
188 
190  m_transactionId=tid;
191 }
192 
194  m_messageLevel = l;
195 }
196 
198 {
199  m_monitoringLevel = l;
200 }
201 
202 
204  m_SQLMonitoring = flag;
205 }
206 
207 void cond::DbConnectionConfiguration::configure( coral::IConnectionServiceConfiguration& coralConfig) const
208 {
209  // message streaming
210  coral::MessageStream::setMsgVerbosity( m_messageLevel );
211  std::string authServiceName("CORAL/Services/EnvironmentAuthenticationService");
212  std::string authPath = m_authPath;
213  // authentication
214  if( authPath.empty() ){
215  // first try to check the env...
216  const char* authEnv = ::getenv( Auth::COND_AUTH_PATH );
217  if(authEnv){
218  authPath += authEnv;
219  }
220  }
221  int authSys = m_authSys;
222  // first attempt, look at the env...
223  const char* authSysEnv = ::getenv( Auth::COND_AUTH_SYS );
224  if( authSysEnv ){
225  authSys = ::atoi( authSysEnv );
226  }
227  if( authSys != CondDbKey && authSys != CoralXMLFile ){
228  // take the default
229  authSys = CondDbKey;
230  }
231  std::string servName("");
232  if( authSys == CondDbKey ){
233  if( authPath.empty() ){
234  const char* authEnv = ::getenv("HOME");
235  if(authEnv){
236  authPath += authEnv;
237  }
238  }
239  servName = "COND/Services/RelationalAuthenticationService";
240  //edm::LogInfo("DbSessionInfo") << "Authentication using Keys";
241  } else if( authSys == CoralXMLFile ){
242  if( authPath.empty() ){
243  authPath = ".";
244  }
245  servName = "COND/Services/XMLAuthenticationService";
246  //edm::LogInfo("DbSessionInfo") << "Authentication using XML File";
247  }
248  if( !authPath.empty() ){
249  authServiceName = servName;
250  coral::Context::instance().PropertyManager().property(Auth::COND_AUTH_PATH_PROPERTY)->set(authPath);
251  coral::Context::instance().loadComponent( authServiceName, m_pluginManager );
252  }
253  coralConfig.setAuthenticationService( authServiceName );
254  // connection sharing
255  if(m_connectionSharing.first)
256  {
257  if(m_connectionSharing.second) coralConfig.enableConnectionSharing();
258  else coralConfig.disableConnectionSharing();
259  }
260  // connection timeout
261  if(m_connectionTimeOut.first)
262  {
263  coralConfig.setConnectionTimeOut(m_connectionTimeOut.second);
264  }
265  // read only session on update connection
266  if(m_readOnlySessionOnUpdateConnections.first)
267  {
268  if(m_readOnlySessionOnUpdateConnections.second) coralConfig.enableReadOnlySessionOnUpdateConnections();
269  else coralConfig.disableReadOnlySessionOnUpdateConnections();
270  }
271  // pool automatic clean up
272  if(m_poolAutomaticCleanUp.first)
273  {
274  if(m_poolAutomaticCleanUp.second) coralConfig.enablePoolAutomaticCleanUp();
275  else coralConfig.disablePoolAutomaticCleanUp();
276  }
277  // connection retrial period
278  if(m_connectionRetrialPeriod.first)
279  {
280  coralConfig.setConnectionRetrialPeriod( m_connectionRetrialPeriod.second );
281  }
282  // connection retrial timeout
283  if( m_connectionRetrialTimeOut.first)
284  {
285  coralConfig.setConnectionRetrialTimeOut(m_connectionRetrialTimeOut.second );
286  }
287  // monitoring level
288  coralConfig.setMonitoringLevel( m_monitoringLevel );
289  // SQL monitoring
290  if( m_SQLMonitoring )
291  {
292  std::string pluginName("COND/Services/SQLMonitoringService");
293  coral::Context::instance().loadComponent( pluginName, m_pluginManager );
294  coralConfig.setMonitoringLevel(coral::monitor::Trace);
295  }
296 
297 }
298 
300 {
301  return m_connectionSharing.second;
302 }
303 
305  return m_connectionTimeOut.second;
306 }
307 
309  return m_readOnlySessionOnUpdateConnections.second;
310 }
311 
313  return m_connectionRetrialPeriod.second;
314 }
315 
317  return m_connectionRetrialTimeOut.second;
318 }
319 
321  return m_poolAutomaticCleanUp.second;
322 }
323 
325 {
326  return m_authPath;
327 }
328 
330  return m_transactionId;
331 }
332 
333 
335 {
336  return m_messageLevel;
337 }
338 
340 {
341  return m_SQLMonitoring;
342 }
343 
DbConnectionConfiguration & operator=(const DbConnectionConfiguration &rhs)
T getUntrackedParameter(std::string const &, T const &) const
long int flag
Definition: mlp_lapack.h:47
const std::string & transactionId() const
void setTransactionId(std::string const &tid)
static PFTauRenderPlugin instance
std::pair< bool, bool > m_poolAutomaticCleanUp
static const std::string COND_AUTH_PATH_PROPERTY
Definition: Auth.h:27
void setParameters(const edm::ParameterSet &connectionPset)
std::pair< bool, int > m_connectionRetrialTimeOut
static const char * COND_AUTH_SYS
Definition: Auth.h:13
void configure(coral::IConnectionServiceConfiguration &coralConfig) const
std::pair< bool, int > m_connectionRetrialPeriod
std::pair< bool, bool > m_readOnlySessionOnUpdateConnections
std::pair< bool, bool > m_connectionSharing
static const char * COND_AUTH_PATH
Definition: Auth.h:12
void setAuthenticationPath(const std::string &p)
const std::string & authenticationPath() const
static std::vector< DbConnectionConfiguration > & defaultConfigurations()
tuple level
Definition: testEve_cfg.py:34
void setMonitoringLevel(coral::monitor::Level l)
const bool Debug