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