Go to the documentation of this file.00001
00003
00004
00005 #include "sentinel/utils/version.h"
00006 #include "sentinel/utils/Alarm.h"
00007
00008 #include "xcept/tools.h"
00009 #include "xdata/InfoSpaceFactory.h"
00010
00011 #include "EventFilter/StorageManager/interface/AlarmHandler.h"
00012
00013
00014 namespace stor {
00015
00016 AlarmHandler::AlarmHandler(xdaq::Application* app) :
00017 app_(app)
00018 {
00019 try
00020 {
00021 alarmInfoSpace_ = xdata::getInfoSpaceFactory()->get("urn:xdaq-sentinel:alarms");
00022 }
00023 catch(xdata::exception::Exception)
00024 {
00025
00026 alarmInfoSpace_ = 0;
00027 }
00028 }
00029
00030
00031 void AlarmHandler::raiseAlarm
00032 (
00033 const std::string name,
00034 const ALARM_LEVEL level,
00035 xcept::Exception& exception
00036 )
00037 {
00038
00039 switch( level )
00040 {
00041 case OKAY:
00042 revokeAlarm(name);
00043 break;
00044
00045 case WARNING:
00046 if ( raiseAlarm(name, "warning", exception) )
00047 LOG4CPLUS_WARN(app_->getApplicationLogger(),
00048 "Raising warning alarm " << name << ": " << exception.message());
00049 break;
00050
00051 case ERROR:
00052 if ( raiseAlarm(name, "error", exception) )
00053 LOG4CPLUS_ERROR(app_->getApplicationLogger(),
00054 "Raising error alarm " << name << ": " << exception.message());
00055 break;
00056
00057 case FATAL:
00058 if ( raiseAlarm(name, "fatal", exception) )
00059 LOG4CPLUS_FATAL(app_->getApplicationLogger(),
00060 "Raising fatal alarm " << name << ": " << exception.message());
00061 break;
00062
00063 default:
00064 LOG4CPLUS_WARN(app_->getApplicationLogger(),
00065 "Unknown alarm level received for " << name << ": " << exception.message());
00066 }
00067 }
00068
00069
00070 void AlarmHandler::notifySentinel
00071 (
00072 const ALARM_LEVEL level,
00073 xcept::Exception& exception
00074 )
00075 {
00076
00077 switch( level )
00078 {
00079 case OKAY:
00080 LOG4CPLUS_INFO(app_->getApplicationLogger(),
00081 xcept::stdformat_exception_history(exception));
00082 break;
00083
00084 case WARNING:
00085 LOG4CPLUS_WARN(app_->getApplicationLogger(),
00086 xcept::stdformat_exception_history(exception));
00087 app_->notifyQualified("warning", exception);
00088 break;
00089
00090 case ERROR:
00091 LOG4CPLUS_ERROR(app_->getApplicationLogger(),
00092 xcept::stdformat_exception_history(exception));
00093 app_->notifyQualified("error", exception);
00094 break;
00095
00096 case FATAL:
00097 LOG4CPLUS_FATAL(app_->getApplicationLogger(),
00098 xcept::stdformat_exception_history(exception));
00099 app_->notifyQualified("fatal", exception);
00100 break;
00101
00102 default:
00103 LOG4CPLUS_WARN(app_->getApplicationLogger(),
00104 "Unknown alarm level received for exception: " <<
00105 xcept::stdformat_exception_history(exception));
00106 }
00107 }
00108
00109
00110 bool AlarmHandler::raiseAlarm
00111 (
00112 const std::string name,
00113 const std::string level,
00114 xcept::Exception& exception
00115 )
00116 {
00117
00118 if (!alarmInfoSpace_) return false;
00119
00120 boost::mutex::scoped_lock sl( mutex_ );
00121
00122 sentinel::utils::Alarm *alarm =
00123 new sentinel::utils::Alarm(level, exception, app_);
00124 try
00125 {
00126 alarmInfoSpace_->fireItemAvailable(name, alarm);
00127 }
00128 catch(xdata::exception::Exception)
00129 {
00130
00131 return false;
00132 }
00133 return true;
00134 }
00135
00136
00137 void AlarmHandler::revokeAlarm
00138 (
00139 const std::string name
00140 )
00141 {
00142 if (!alarmInfoSpace_) return;
00143
00144 boost::mutex::scoped_lock sl( mutex_ );
00145
00146 sentinel::utils::Alarm *alarm;
00147 try
00148 {
00149 alarm = dynamic_cast<sentinel::utils::Alarm*>( alarmInfoSpace_->find( name ) );
00150 }
00151 catch(xdata::exception::Exception)
00152 {
00153
00154 return;
00155 }
00156
00157 LOG4CPLUS_INFO(app_->getApplicationLogger(), "Revoking alarm " << name);
00158
00159 alarmInfoSpace_->fireItemRevoked(name, app_);
00160 delete alarm;
00161 }
00162
00163
00164 void AlarmHandler::clearAllAlarms()
00165 {
00166 if (!alarmInfoSpace_) return;
00167
00168 boost::mutex::scoped_lock sl( mutex_ );
00169
00170 typedef std::map<std::string, xdata::Serializable*, std::less<std::string> > alarmList;
00171 alarmList alarms = alarmInfoSpace_->match(".*");
00172 for (alarmList::const_iterator it = alarms.begin(), itEnd = alarms.end();
00173 it != itEnd; ++it)
00174 {
00175 sentinel::utils::Alarm* alarm = dynamic_cast<sentinel::utils::Alarm*>(it->second);
00176 alarmInfoSpace_->fireItemRevoked(it->first, app_);
00177 delete alarm;
00178 }
00179 }
00180
00181 }
00182
00183