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
4 // CMSSW includes
6 // coral includes
7 #include "RelationalAccess/IConnectionServiceConfiguration.h"
8 #include "CoralKernel/Context.h"
9 #include "CoralKernel/IProperty.h"
10 #include "CoralKernel/IPropertyManager.h"
11 // externals
12 #include <boost/filesystem/operations.hpp>
13 
14 
15 std::vector<cond::DbConnectionConfiguration>&
17  static std::vector<DbConnectionConfiguration> s_defaultConfigurations;
18  // coral default
19  s_defaultConfigurations.push_back( cond::DbConnectionConfiguration() );
20  // cms default
21  s_defaultConfigurations.push_back( cond::DbConnectionConfiguration( false, 0, false, 10, 60, false, "", "", coral::Error, coral::monitor::Off, false ) );
22  // prod default
23  s_defaultConfigurations.push_back( cond::DbConnectionConfiguration( false, 0, false, 10, 60, false, "", "", coral::Error, coral::monitor::Off, false ) );
24  // tool default
25  s_defaultConfigurations.push_back( cond::DbConnectionConfiguration( false, 0, false, 10, 60, false, "", "",coral::Error, coral::monitor::Off, false ) );
26  // web default
27  s_defaultConfigurations.push_back( cond::DbConnectionConfiguration( false, 0, false, 10, 60, false, "", "",coral::Error, coral::monitor::Off, false ) );
28  return s_defaultConfigurations;
29 }
30 
32  m_connectionSharing(false,false),
33  m_connectionTimeOut(false,0),
34  m_readOnlySessionOnUpdateConnections(false,false),
35  m_connectionRetrialPeriod(false,0),
36  m_connectionRetrialTimeOut(false,0),
37  m_poolAutomaticCleanUp(false,false),
38  m_authPath(),
39  m_transactionId(),
40  m_messageLevel(coral::Error),
41  m_monitoringLevel(coral::monitor::Off),
42  m_SQLMonitoring(false),
43  m_pluginManager(new CoralServiceManager){
44 }
45 
47  int connectionTimeOut,
48  bool readOnlySessionOnUpdateConnections,
49  int connectionRetrialPeriod,
50  int connectionRetrialTimeOut,
51  bool poolAutomaticCleanUp,
52  const::std::string& authenticationPath,
53  const::std::string& transactionId,
54  coral::MsgLevel msgLev,
55  coral::monitor::Level monitorLev,
56  bool SQLMonitoring ):
57  m_connectionSharing(true,connectionSharing),
58  m_connectionTimeOut(true,connectionTimeOut),
59  m_readOnlySessionOnUpdateConnections(true,readOnlySessionOnUpdateConnections),
60  m_connectionRetrialPeriod(true,connectionRetrialPeriod),
61  m_connectionRetrialTimeOut(true,connectionRetrialTimeOut),
62  m_poolAutomaticCleanUp(true,poolAutomaticCleanUp),
63  m_authPath(authenticationPath),
64  m_transactionId(transactionId),
65  m_messageLevel(msgLev),
66  m_monitoringLevel(monitorLev),
67  m_SQLMonitoring(SQLMonitoring),
68  m_pluginManager(new CoralServiceManager){
69 }
70 
72  m_connectionSharing(rhs.m_connectionSharing),
73  m_connectionTimeOut(rhs.m_connectionTimeOut),
74  m_readOnlySessionOnUpdateConnections(rhs.m_readOnlySessionOnUpdateConnections),
75  m_connectionRetrialPeriod(rhs.m_connectionRetrialPeriod),
76  m_connectionRetrialTimeOut(rhs.m_connectionRetrialTimeOut),
77  m_poolAutomaticCleanUp(rhs.m_poolAutomaticCleanUp),
78  m_authPath(rhs.m_authPath),
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_transactionId=rhs.m_transactionId;
100  m_messageLevel = rhs.m_messageLevel;
101  m_monitoringLevel = rhs.m_monitoringLevel;
102  m_SQLMonitoring = rhs.m_SQLMonitoring;
103  return *this;
104 }
105 
107  std::string authPath = connectionPset.getUntrackedParameter<std::string>("authenticationPath","");
108  setAuthenticationPath(authPath);
109  setTransactionId(connectionPset.getUntrackedParameter<std::string>("transactionId",""));
110  int messageLevel = connectionPset.getUntrackedParameter<int>("messageLevel",0);
111  coral::MsgLevel level = coral::Error;
112  switch (messageLevel) {
113  case 0 :
114  level = coral::Error;
115  break;
116  case 1:
117  level = coral::Warning;
118  break;
119  case 2:
120  level = coral::Info;
121  break;
122  case 3:
123  level = coral::Debug;
124  break;
125  default:
126  level = coral::Error;
127  }
128  setMessageLevel(level);
129  bool enableConnectionSharing = connectionPset.getUntrackedParameter<bool>("enableConnectionSharing",true);
130  setConnectionSharing( enableConnectionSharing );
131  int connectionTimeOut = connectionPset.getUntrackedParameter<int>("connectionTimeOut",600);
132  setConnectionTimeOut( connectionTimeOut );
133  bool enableReadOnlySessionOnUpdateConnection = connectionPset.getUntrackedParameter<bool>("enableReadOnlySessionOnUpdateConnection",true);
134  setReadOnlySessionOnUpdateConnections( enableReadOnlySessionOnUpdateConnection );
135  int connectionRetrialPeriod = connectionPset.getUntrackedParameter<int>("connectionRetrialPeriod",30);
136  setConnectionRetrialPeriod( connectionRetrialPeriod );
137  int connectionRetrialTimeOut = connectionPset.getUntrackedParameter<int>("connectionRetrialTimeOut",180);
138  setConnectionRetrialTimeOut( connectionRetrialTimeOut );
139  bool enablePoolAutomaticCleanUp = connectionPset.getUntrackedParameter<bool>("enablePoolAutomaticCleanUp",false);
140  setPoolAutomaticCleanUp( enablePoolAutomaticCleanUp );
141  //int idleConnectionCleanupPeriod = connectionPset.getUntrackedParameter<int>("idleConnectionCleanupPeriod",300);
142 }
143 
145  m_connectionSharing.first = true;
146  m_connectionSharing.second = flag;
147 }
148 
150  m_connectionTimeOut.first = true;
151  m_connectionTimeOut.second = timeOut;
152 }
153 
155  m_readOnlySessionOnUpdateConnections.first = true;
156  m_readOnlySessionOnUpdateConnections.second = flag;
157 }
158 
160  m_connectionRetrialPeriod.first = true;
161  m_connectionRetrialPeriod.second = period;
162 }
163 
165  m_connectionRetrialTimeOut.first = true;
166  m_connectionRetrialTimeOut.second = timeout;
167 }
168 
170  m_poolAutomaticCleanUp.first = true;
171  m_poolAutomaticCleanUp.second = flag;
172 }
173 
175  m_authPath = p;
176 }
177 
178 
180  m_transactionId=tid;
181 }
182 
184  m_messageLevel = l;
185 }
186 
188 {
189  m_monitoringLevel = l;
190 }
191 
192 
194  m_SQLMonitoring = flag;
195 }
196 
197 void cond::DbConnectionConfiguration::configure( coral::IConnectionServiceConfiguration& coralConfig) const
198 {
199  // message streaming
200  coral::MessageStream::setMsgVerbosity( m_messageLevel );
201  // authentication
202  std::string authServiceName("CORAL/Services/EnvironmentAuthenticationService");
203  if( !m_authPath.empty() )
204  {
205  authServiceName = "COND/Services/XMLAuthenticationService";
206  boost::filesystem::path boostAuthPath( m_authPath );
207  if(boost::filesystem::is_directory(boostAuthPath))
208  {
209  boostAuthPath /= boost::filesystem::path("authentication.xml");
210  }
211  std::string authFileName = boostAuthPath.string();
212  coral::Context::instance().PropertyManager().property("AuthenticationFile")->set(authFileName);
213  coral::Context::instance().loadComponent( authServiceName, m_pluginManager );
214  }
215  coralConfig.setAuthenticationService( authServiceName );
216  // connection sharing
217  if(m_connectionSharing.first)
218  {
219  if(m_connectionSharing.second) coralConfig.enableConnectionSharing();
220  else coralConfig.disableConnectionSharing();
221  }
222  // connection timeout
223  if(m_connectionTimeOut.first)
224  {
225  coralConfig.setConnectionTimeOut(m_connectionTimeOut.second);
226  }
227  // read only session on update connection
228  if(m_readOnlySessionOnUpdateConnections.first)
229  {
230  if(m_readOnlySessionOnUpdateConnections.second) coralConfig.enableReadOnlySessionOnUpdateConnections();
231  else coralConfig.disableReadOnlySessionOnUpdateConnections();
232  }
233  // pool automatic clean up
234  if(m_poolAutomaticCleanUp.first)
235  {
236  if(m_poolAutomaticCleanUp.second) coralConfig.enablePoolAutomaticCleanUp();
237  else coralConfig.disablePoolAutomaticCleanUp();
238  }
239  // connection retrial period
240  if(m_connectionRetrialPeriod.first)
241  {
242  coralConfig.setConnectionRetrialPeriod( m_connectionRetrialPeriod.second );
243  }
244  // connection retrial timeout
245  if( m_connectionRetrialTimeOut.first)
246  {
247  coralConfig.setConnectionRetrialTimeOut(m_connectionRetrialTimeOut.second );
248  }
249  // monitoring level
250  coralConfig.setMonitoringLevel( m_monitoringLevel );
251  // SQL monitoring
252  if( m_SQLMonitoring )
253  {
254  std::string pluginName("COND/Services/SQLMonitoringService");
255  coral::Context::instance().loadComponent( pluginName, m_pluginManager );
256  coralConfig.setMonitoringLevel(coral::monitor::Trace);
257  }
258 
259 }
260 
262 {
263  return m_connectionSharing.second;
264 }
265 
267  return m_connectionTimeOut.second;
268 }
269 
271  return m_readOnlySessionOnUpdateConnections.second;
272 }
273 
275  return m_connectionRetrialPeriod.second;
276 }
277 
279  return m_connectionRetrialTimeOut.second;
280 }
281 
283  return m_poolAutomaticCleanUp.second;
284 }
285 
287 {
288  return m_authPath;
289 }
290 
292  return m_transactionId;
293 }
294 
295 
297 {
298  return m_messageLevel;
299 }
300 
302 {
303  return m_SQLMonitoring;
304 }
305 
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)
std::pair< bool, bool > m_poolAutomaticCleanUp
void setParameters(const edm::ParameterSet &connectionPset)
std::pair< bool, int > m_connectionRetrialTimeOut
int path() const
Definition: HLTadd.h:3
void configure(coral::IConnectionServiceConfiguration &coralConfig) const
std::pair< bool, int > m_connectionRetrialPeriod
std::pair< bool, bool > m_readOnlySessionOnUpdateConnections
std::pair< bool, bool > m_connectionSharing
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