00001
00002 #include "CondCore/DBCommon/interface/DbConnectionConfiguration.h"
00003 #include "CondCore/DBCommon/interface/CoralServiceManager.h"
00004 #include "CondCore/DBCommon/interface/Auth.h"
00005
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007
00008 #include "RelationalAccess/IConnectionServiceConfiguration.h"
00009 #include "CoralKernel/Context.h"
00010 #include "CoralKernel/IProperty.h"
00011 #include "CoralKernel/IPropertyManager.h"
00012
00013 #include <boost/filesystem/operations.hpp>
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 std::string authServiceName("CORAL/Services/EnvironmentAuthenticationService");
00202 std::string authPath = m_authPath;
00203
00204 if( authPath.empty() ){
00205
00206 const char* authEnv = ::getenv( Auth::COND_AUTH_PATH );
00207 if(authEnv){
00208 authPath += authEnv;
00209 }
00210 }
00211 const char* authSys = ::getenv( Auth::COND_AUTH_SYS );
00212 std::string servName("");
00213 if( authSys ){
00214 if( authPath.empty() ){
00215 const char* authEnv = ::getenv("HOME");
00216 if(authEnv){
00217 authPath += authEnv;
00218 }
00219 }
00220 servName = "COND/Services/RelationalAuthenticationService";
00221 } else {
00222 servName = "COND/Services/XMLAuthenticationService";
00223 }
00224 if( !authPath.empty() ){
00225 authServiceName = servName;
00226 coral::Context::instance().PropertyManager().property(Auth::COND_AUTH_PATH_PROPERTY)->set(authPath);
00227 coral::Context::instance().loadComponent( authServiceName, m_pluginManager );
00228 }
00229 coralConfig.setAuthenticationService( authServiceName );
00230
00231 if(m_connectionSharing.first)
00232 {
00233 if(m_connectionSharing.second) coralConfig.enableConnectionSharing();
00234 else coralConfig.disableConnectionSharing();
00235 }
00236
00237 if(m_connectionTimeOut.first)
00238 {
00239 coralConfig.setConnectionTimeOut(m_connectionTimeOut.second);
00240 }
00241
00242 if(m_readOnlySessionOnUpdateConnections.first)
00243 {
00244 if(m_readOnlySessionOnUpdateConnections.second) coralConfig.enableReadOnlySessionOnUpdateConnections();
00245 else coralConfig.disableReadOnlySessionOnUpdateConnections();
00246 }
00247
00248 if(m_poolAutomaticCleanUp.first)
00249 {
00250 if(m_poolAutomaticCleanUp.second) coralConfig.enablePoolAutomaticCleanUp();
00251 else coralConfig.disablePoolAutomaticCleanUp();
00252 }
00253
00254 if(m_connectionRetrialPeriod.first)
00255 {
00256 coralConfig.setConnectionRetrialPeriod( m_connectionRetrialPeriod.second );
00257 }
00258
00259 if( m_connectionRetrialTimeOut.first)
00260 {
00261 coralConfig.setConnectionRetrialTimeOut(m_connectionRetrialTimeOut.second );
00262 }
00263
00264 coralConfig.setMonitoringLevel( m_monitoringLevel );
00265
00266 if( m_SQLMonitoring )
00267 {
00268 std::string pluginName("COND/Services/SQLMonitoringService");
00269 coral::Context::instance().loadComponent( pluginName, m_pluginManager );
00270 coralConfig.setMonitoringLevel(coral::monitor::Trace);
00271 }
00272
00273 }
00274
00275 bool cond::DbConnectionConfiguration::isConnectionSharingEnabled() const
00276 {
00277 return m_connectionSharing.second;
00278 }
00279
00280 int cond::DbConnectionConfiguration::connectionTimeOut() const {
00281 return m_connectionTimeOut.second;
00282 }
00283
00284 bool cond::DbConnectionConfiguration::isReadOnlySessionOnUpdateConnectionEnabled() const {
00285 return m_readOnlySessionOnUpdateConnections.second;
00286 }
00287
00288 int cond::DbConnectionConfiguration::connectionRetrialPeriod() const {
00289 return m_connectionRetrialPeriod.second;
00290 }
00291
00292 int cond::DbConnectionConfiguration::connectionRetrialTimeOut() const {
00293 return m_connectionRetrialTimeOut.second;
00294 }
00295
00296 bool cond::DbConnectionConfiguration::isPoolAutomaticCleanUpEnabled() const {
00297 return m_poolAutomaticCleanUp.second;
00298 }
00299
00300 const std::string& cond::DbConnectionConfiguration::authenticationPath() const
00301 {
00302 return m_authPath;
00303 }
00304
00305 const std::string& cond::DbConnectionConfiguration::transactionId() const {
00306 return m_transactionId;
00307 }
00308
00309
00310 coral::MsgLevel cond::DbConnectionConfiguration::messageLevel() const
00311 {
00312 return m_messageLevel;
00313 }
00314
00315 bool cond::DbConnectionConfiguration::isSQLMonitoringEnabled() const
00316 {
00317 return m_SQLMonitoring;
00318 }
00319