00001
00002 #include "CondCore/DBCommon/interface/DbConnectionConfiguration.h"
00003 #include "CondCore/DBCommon/interface/CoralServiceManager.h"
00004
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006
00007 #include "RelationalAccess/IConnectionServiceConfiguration.h"
00008 #include "CoralKernel/Context.h"
00009 #include "CoralKernel/IProperty.h"
00010 #include "CoralKernel/IPropertyManager.h"
00011
00012 #include <boost/filesystem/operations.hpp>
00013
00014
00015 std::vector<cond::DbConnectionConfiguration>&
00016 cond::DbConnectionConfiguration::defaultConfigurations(){
00017 static std::vector<DbConnectionConfiguration> s_defaultConfigurations;
00018
00019 s_defaultConfigurations.push_back( cond::DbConnectionConfiguration() );
00020
00021 s_defaultConfigurations.push_back( cond::DbConnectionConfiguration( false, 0, false, 10, 60, false, "", "", coral::Error, coral::monitor::Off, false ) );
00022
00023 s_defaultConfigurations.push_back( cond::DbConnectionConfiguration( false, 0, false, 10, 60, false, "", "", coral::Error, coral::monitor::Off, false ) );
00024
00025 s_defaultConfigurations.push_back( cond::DbConnectionConfiguration( false, 0, false, 10, 60, false, "", "",coral::Error, coral::monitor::Off, false ) );
00026
00027 s_defaultConfigurations.push_back( cond::DbConnectionConfiguration( false, 0, false, 10, 60, false, "", "",coral::Error, coral::monitor::Off, false ) );
00028 return s_defaultConfigurations;
00029 }
00030
00031 cond::DbConnectionConfiguration::DbConnectionConfiguration():
00032 m_connectionSharing(false,false),
00033 m_connectionTimeOut(false,0),
00034 m_readOnlySessionOnUpdateConnections(false,false),
00035 m_connectionRetrialPeriod(false,0),
00036 m_connectionRetrialTimeOut(false,0),
00037 m_poolAutomaticCleanUp(false,false),
00038 m_authPath(),
00039 m_transactionId(),
00040 m_messageLevel(coral::Error),
00041 m_monitoringLevel(coral::monitor::Off),
00042 m_SQLMonitoring(false),
00043 m_pluginManager(new CoralServiceManager){
00044 }
00045
00046 cond::DbConnectionConfiguration::DbConnectionConfiguration( bool connectionSharing,
00047 int connectionTimeOut,
00048 bool readOnlySessionOnUpdateConnections,
00049 int connectionRetrialPeriod,
00050 int connectionRetrialTimeOut,
00051 bool poolAutomaticCleanUp,
00052 const::std::string& authenticationPath,
00053 const::std::string& transactionId,
00054 coral::MsgLevel msgLev,
00055 coral::monitor::Level monitorLev,
00056 bool SQLMonitoring ):
00057 m_connectionSharing(true,connectionSharing),
00058 m_connectionTimeOut(true,connectionTimeOut),
00059 m_readOnlySessionOnUpdateConnections(true,readOnlySessionOnUpdateConnections),
00060 m_connectionRetrialPeriod(true,connectionRetrialPeriod),
00061 m_connectionRetrialTimeOut(true,connectionRetrialTimeOut),
00062 m_poolAutomaticCleanUp(true,poolAutomaticCleanUp),
00063 m_authPath(authenticationPath),
00064 m_transactionId(transactionId),
00065 m_messageLevel(msgLev),
00066 m_monitoringLevel(monitorLev),
00067 m_SQLMonitoring(SQLMonitoring),
00068 m_pluginManager(new CoralServiceManager){
00069 }
00070
00071 cond::DbConnectionConfiguration::DbConnectionConfiguration( const cond::DbConnectionConfiguration& rhs):
00072 m_connectionSharing(rhs.m_connectionSharing),
00073 m_connectionTimeOut(rhs.m_connectionTimeOut),
00074 m_readOnlySessionOnUpdateConnections(rhs.m_readOnlySessionOnUpdateConnections),
00075 m_connectionRetrialPeriod(rhs.m_connectionRetrialPeriod),
00076 m_connectionRetrialTimeOut(rhs.m_connectionRetrialTimeOut),
00077 m_poolAutomaticCleanUp(rhs.m_poolAutomaticCleanUp),
00078 m_authPath(rhs.m_authPath),
00079 m_transactionId(rhs.m_transactionId),
00080 m_messageLevel(rhs.m_messageLevel),
00081 m_monitoringLevel(rhs.m_monitoringLevel),
00082 m_SQLMonitoring(rhs.m_SQLMonitoring),
00083 m_pluginManager(new CoralServiceManager){
00084 }
00085
00086 cond::DbConnectionConfiguration::~DbConnectionConfiguration(){
00087 delete m_pluginManager;
00088 }
00089
00090 cond::DbConnectionConfiguration&
00091 cond::DbConnectionConfiguration::operator=( const cond::DbConnectionConfiguration& rhs){
00092 m_connectionSharing = rhs.m_connectionSharing;
00093 m_connectionTimeOut = rhs.m_connectionTimeOut;
00094 m_readOnlySessionOnUpdateConnections = rhs.m_readOnlySessionOnUpdateConnections;
00095 m_connectionRetrialPeriod = rhs.m_connectionRetrialPeriod;
00096 m_connectionRetrialTimeOut = rhs.m_connectionRetrialTimeOut;
00097 m_poolAutomaticCleanUp = rhs.m_poolAutomaticCleanUp;
00098 m_authPath = rhs.m_authPath;
00099 m_transactionId=rhs.m_transactionId;
00100 m_messageLevel = rhs.m_messageLevel;
00101 m_monitoringLevel = rhs.m_monitoringLevel;
00102 m_SQLMonitoring = rhs.m_SQLMonitoring;
00103 return *this;
00104 }
00105
00106 void cond::DbConnectionConfiguration::setParameters( const edm::ParameterSet& connectionPset ){
00107 std::string authPath = connectionPset.getUntrackedParameter<std::string>("authenticationPath","");
00108 setAuthenticationPath(authPath);
00109 setTransactionId(connectionPset.getUntrackedParameter<std::string>("transactionId",""));
00110 int messageLevel = connectionPset.getUntrackedParameter<int>("messageLevel",0);
00111 coral::MsgLevel level = coral::Error;
00112 switch (messageLevel) {
00113 case 0 :
00114 level = coral::Error;
00115 break;
00116 case 1:
00117 level = coral::Warning;
00118 break;
00119 case 2:
00120 level = coral::Info;
00121 break;
00122 case 3:
00123 level = coral::Debug;
00124 break;
00125 default:
00126 level = coral::Error;
00127 }
00128 setMessageLevel(level);
00129 bool enableConnectionSharing = connectionPset.getUntrackedParameter<bool>("enableConnectionSharing",true);
00130 setConnectionSharing( enableConnectionSharing );
00131 int connectionTimeOut = connectionPset.getUntrackedParameter<int>("connectionTimeOut",600);
00132 setConnectionTimeOut( connectionTimeOut );
00133 bool enableReadOnlySessionOnUpdateConnection = connectionPset.getUntrackedParameter<bool>("enableReadOnlySessionOnUpdateConnection",true);
00134 setReadOnlySessionOnUpdateConnections( enableReadOnlySessionOnUpdateConnection );
00135 int connectionRetrialPeriod = connectionPset.getUntrackedParameter<int>("connectionRetrialPeriod",30);
00136 setConnectionRetrialPeriod( connectionRetrialPeriod );
00137 int connectionRetrialTimeOut = connectionPset.getUntrackedParameter<int>("connectionRetrialTimeOut",180);
00138 setConnectionRetrialTimeOut( connectionRetrialTimeOut );
00139 bool enablePoolAutomaticCleanUp = connectionPset.getUntrackedParameter<bool>("enablePoolAutomaticCleanUp",false);
00140 setPoolAutomaticCleanUp( enablePoolAutomaticCleanUp );
00141
00142 }
00143
00144 void cond::DbConnectionConfiguration::setConnectionSharing( bool flag ){
00145 m_connectionSharing.first = true;
00146 m_connectionSharing.second = flag;
00147 }
00148
00149 void cond::DbConnectionConfiguration::setConnectionTimeOut( int timeOut ){
00150 m_connectionTimeOut.first = true;
00151 m_connectionTimeOut.second = timeOut;
00152 }
00153
00154 void cond::DbConnectionConfiguration::setReadOnlySessionOnUpdateConnections( bool flag ){
00155 m_readOnlySessionOnUpdateConnections.first = true;
00156 m_readOnlySessionOnUpdateConnections.second = flag;
00157 }
00158
00159 void cond::DbConnectionConfiguration::setConnectionRetrialPeriod( int period ){
00160 m_connectionRetrialPeriod.first = true;
00161 m_connectionRetrialPeriod.second = period;
00162 }
00163
00164 void cond::DbConnectionConfiguration::setConnectionRetrialTimeOut( int timeout ){
00165 m_connectionRetrialTimeOut.first = true;
00166 m_connectionRetrialTimeOut.second = timeout;
00167 }
00168
00169 void cond::DbConnectionConfiguration::setPoolAutomaticCleanUp( bool flag ){
00170 m_poolAutomaticCleanUp.first = true;
00171 m_poolAutomaticCleanUp.second = flag;
00172 }
00173
00174 void cond::DbConnectionConfiguration::setAuthenticationPath( const std::string& p ){
00175 m_authPath = p;
00176 }
00177
00178
00179 void cond::DbConnectionConfiguration::setTransactionId( std::string const & tid) {
00180 m_transactionId=tid;
00181 }
00182
00183 void cond::DbConnectionConfiguration::setMessageLevel( coral::MsgLevel l ) {
00184 m_messageLevel = l;
00185 }
00186
00187 void cond::DbConnectionConfiguration::setMonitoringLevel( coral::monitor::Level l)
00188 {
00189 m_monitoringLevel = l;
00190 }
00191
00192
00193 void cond::DbConnectionConfiguration::setSQLMonitoring( bool flag ){
00194 m_SQLMonitoring = flag;
00195 }
00196
00197 void cond::DbConnectionConfiguration::configure( coral::IConnectionServiceConfiguration& coralConfig) const
00198 {
00199
00200 coral::MessageStream::setMsgVerbosity( m_messageLevel );
00201
00202 std::string authServiceName("CORAL/Services/EnvironmentAuthenticationService");
00203 if( !m_authPath.empty() )
00204 {
00205 authServiceName = "COND/Services/XMLAuthenticationService";
00206 boost::filesystem::path boostAuthPath( m_authPath );
00207 if(boost::filesystem::is_directory(boostAuthPath))
00208 {
00209 boostAuthPath /= boost::filesystem::path("authentication.xml");
00210 }
00211 std::string authFileName = boostAuthPath.string();
00212 coral::Context::instance().PropertyManager().property("AuthenticationFile")->set(authFileName);
00213 coral::Context::instance().loadComponent( authServiceName, m_pluginManager );
00214 }
00215 coralConfig.setAuthenticationService( authServiceName );
00216
00217 if(m_connectionSharing.first)
00218 {
00219 if(m_connectionSharing.second) coralConfig.enableConnectionSharing();
00220 else coralConfig.disableConnectionSharing();
00221 }
00222
00223 if(m_connectionTimeOut.first)
00224 {
00225 coralConfig.setConnectionTimeOut(m_connectionTimeOut.second);
00226 }
00227
00228 if(m_readOnlySessionOnUpdateConnections.first)
00229 {
00230 if(m_readOnlySessionOnUpdateConnections.second) coralConfig.enableReadOnlySessionOnUpdateConnections();
00231 else coralConfig.disableReadOnlySessionOnUpdateConnections();
00232 }
00233
00234 if(m_poolAutomaticCleanUp.first)
00235 {
00236 if(m_poolAutomaticCleanUp.second) coralConfig.enablePoolAutomaticCleanUp();
00237 else coralConfig.disablePoolAutomaticCleanUp();
00238 }
00239
00240 if(m_connectionRetrialPeriod.first)
00241 {
00242 coralConfig.setConnectionRetrialPeriod( m_connectionRetrialPeriod.second );
00243 }
00244
00245 if( m_connectionRetrialTimeOut.first)
00246 {
00247 coralConfig.setConnectionRetrialTimeOut(m_connectionRetrialTimeOut.second );
00248 }
00249
00250 coralConfig.setMonitoringLevel( m_monitoringLevel );
00251
00252 if( m_SQLMonitoring )
00253 {
00254 std::string pluginName("COND/Services/SQLMonitoringService");
00255 coral::Context::instance().loadComponent( pluginName, m_pluginManager );
00256 coralConfig.setMonitoringLevel(coral::monitor::Trace);
00257 }
00258
00259 }
00260
00261 bool cond::DbConnectionConfiguration::isConnectionSharingEnabled() const
00262 {
00263 return m_connectionSharing.second;
00264 }
00265
00266 int cond::DbConnectionConfiguration::connectionTimeOut() const {
00267 return m_connectionTimeOut.second;
00268 }
00269
00270 bool cond::DbConnectionConfiguration::isReadOnlySessionOnUpdateConnectionEnabled() const {
00271 return m_readOnlySessionOnUpdateConnections.second;
00272 }
00273
00274 int cond::DbConnectionConfiguration::connectionRetrialPeriod() const {
00275 return m_connectionRetrialPeriod.second;
00276 }
00277
00278 int cond::DbConnectionConfiguration::connectionRetrialTimeOut() const {
00279 return m_connectionRetrialTimeOut.second;
00280 }
00281
00282 bool cond::DbConnectionConfiguration::isPoolAutomaticCleanUpEnabled() const {
00283 return m_poolAutomaticCleanUp.second;
00284 }
00285
00286 const std::string& cond::DbConnectionConfiguration::authenticationPath() const
00287 {
00288 return m_authPath;
00289 }
00290
00291 const std::string& cond::DbConnectionConfiguration::transactionId() const {
00292 return m_transactionId;
00293 }
00294
00295
00296 coral::MsgLevel cond::DbConnectionConfiguration::messageLevel() const
00297 {
00298 return m_messageLevel;
00299 }
00300
00301 bool cond::DbConnectionConfiguration::isSQLMonitoringEnabled() const
00302 {
00303 return m_SQLMonitoring;
00304 }
00305