#include <AlarmHandler.h>
Public Types | |
enum | ALARM_LEVEL { OKAY, WARNING, ERROR, FATAL } |
Public Member Functions | |
AlarmHandler () | |
AlarmHandler (xdaq::Application *) | |
AlarmHandler (xdaq::Application *, boost::shared_ptr< SharedResources >) | |
void | clearAllAlarms () |
Logger & | getLogger () const |
void | localDebug (const std::string &message) const |
virtual void | moveToFailedState (xcept::Exception &) |
virtual void | notifySentinel (const ALARM_LEVEL, xcept::Exception &) |
virtual void | raiseAlarm (const std::string name, const ALARM_LEVEL, xcept::Exception &) |
virtual void | revokeAlarm (const std::string name) |
virtual | ~AlarmHandler () |
Private Member Functions | |
bool | raiseAlarm (const std::string name, const std::string level, xcept::Exception &) |
Private Attributes | |
xdata::InfoSpace * | alarmInfoSpace_ |
xdaq::Application * | app_ |
boost::mutex | mutex_ |
boost::shared_ptr < SharedResources > | sharedResources_ |
Helper class to handle sentinel alarming
Definition at line 30 of file AlarmHandler.h.
stor::AlarmHandler::AlarmHandler | ( | ) | [inline] |
Definition at line 38 of file AlarmHandler.h.
{};
stor::AlarmHandler::AlarmHandler | ( | xdaq::Application * | app | ) | [explicit] |
Definition at line 21 of file AlarmHandler.cc.
References Exception.
: app_(app) { try { alarmInfoSpace_ = xdata::getInfoSpaceFactory()->get("urn:xdaq-sentinel:alarms"); } catch(xdata::exception::Exception) { // sentinel is not available alarmInfoSpace_ = 0; } }
stor::AlarmHandler::AlarmHandler | ( | xdaq::Application * | , |
boost::shared_ptr< SharedResources > | |||
) |
virtual stor::AlarmHandler::~AlarmHandler | ( | ) | [inline, virtual] |
Definition at line 50 of file AlarmHandler.h.
{};
void stor::AlarmHandler::clearAllAlarms | ( | ) |
Revokes all sentinel alarms
Definition at line 191 of file AlarmHandler.cc.
References alarmInfoSpace_, app_, and mutex_.
{ if (!alarmInfoSpace_) return; boost::mutex::scoped_lock sl( mutex_ ); typedef std::map<std::string, xdata::Serializable*, std::less<std::string> > alarmList; alarmList alarms = alarmInfoSpace_->match(".*"); for (alarmList::const_iterator it = alarms.begin(), itEnd = alarms.end(); it != itEnd; ++it) { sentinel::utils::Alarm* alarm = dynamic_cast<sentinel::utils::Alarm*>(it->second); alarmInfoSpace_->fireItemRevoked(it->first, app_); delete alarm; } }
Logger& stor::AlarmHandler::getLogger | ( | ) | const [inline] |
Return the application logger
Definition at line 95 of file AlarmHandler.h.
References app_.
{ return app_->getApplicationLogger(); }
void stor::AlarmHandler::localDebug | ( | const std::string & | message | ) | const |
Write message to a file in /tmp (last resort when everything else fails)
Definition at line 247 of file AlarmHandler.cc.
References f, alignmentValidation::fname, dbtoconf::out, and sharedResources_.
Referenced by moveToFailedState().
{ std::ostringstream fname_oss; fname_oss << "/tmp/storage_manager_debug_" << sharedResources_->configuration_->getDiskWritingParams().smInstanceString_ << "_" << getpid(); const std::string fname = fname_oss.str(); std::ofstream f( fname.c_str(), std::ios_base::ate | std::ios_base::out | std::ios_base::app ); if( f.is_open() ) { try { f << message << std::endl; f.close(); } catch(...) {} } }
void stor::AlarmHandler::moveToFailedState | ( | xcept::Exception & | exception | ) | [virtual] |
Add a Failed state-machine event to the command queue
Definition at line 209 of file AlarmHandler.cc.
References alignCSCRings::e, exception, Exception, Fail, FATAL, localDebug(), notifySentinel(), seconds(), and sharedResources_.
{ std::string errorMsg = "Failed to process FAIL exception: " + xcept::stdformat_exception_history(exception) + " due to "; try { notifySentinel(AlarmHandler::FATAL, exception); sharedResources_->statisticsReporter_->getStateMachineMonitorCollection().setStatusMessage( xcept::stdformat_exception_history(exception) ); EventPtr_t stMachEvent( new Fail() ); // wait maximum 5 seconds until enqueuing succeeds if ( ! sharedResources_->commandQueue_->enqTimedWait( stMachEvent, boost::posix_time::seconds(5) ) ) { XCEPT_DECLARE_NESTED( stor::exception::StateTransition, sentinelException, "Failed to enqueue FAIL event", exception ); notifySentinel(AlarmHandler::FATAL, sentinelException); } } catch(xcept::Exception &e) { errorMsg += xcept::stdformat_exception_history(e); localDebug( errorMsg ); } catch(std::exception &e) { errorMsg += e.what(); localDebug( errorMsg ); } catch( ... ) { errorMsg += "an unknown exception."; localDebug( errorMsg ); } }
void stor::AlarmHandler::notifySentinel | ( | const ALARM_LEVEL | level, |
xcept::Exception & | exception | ||
) | [virtual] |
Notifies the sentinel
Definition at line 98 of file AlarmHandler.cc.
References dqm::qstatus::ERROR, and dqm::qstatus::WARNING.
Referenced by moveToFailedState().
{ switch( level ) { case OKAY: LOG4CPLUS_INFO(app_->getApplicationLogger(), xcept::stdformat_exception_history(exception)); break; case WARNING: LOG4CPLUS_WARN(app_->getApplicationLogger(), xcept::stdformat_exception_history(exception)); app_->notifyQualified("warning", exception); break; case ERROR: LOG4CPLUS_ERROR(app_->getApplicationLogger(), xcept::stdformat_exception_history(exception)); app_->notifyQualified("error", exception); break; case FATAL: LOG4CPLUS_FATAL(app_->getApplicationLogger(), xcept::stdformat_exception_history(exception)); app_->notifyQualified("fatal", exception); break; default: LOG4CPLUS_WARN(app_->getApplicationLogger(), "Unknown alarm level received for exception: " << xcept::stdformat_exception_history(exception)); } }
void stor::AlarmHandler::raiseAlarm | ( | const std::string | name, |
const ALARM_LEVEL | level, | ||
xcept::Exception & | exception | ||
) | [virtual] |
Raises a sentinel alarm
Definition at line 59 of file AlarmHandler.cc.
References dqm::qstatus::ERROR, and dqm::qstatus::WARNING.
{ switch( level ) { case OKAY: revokeAlarm(name); break; case WARNING: if ( raiseAlarm(name, "warning", exception) ) LOG4CPLUS_WARN(app_->getApplicationLogger(), "Raising warning alarm " << name << ": " << exception.message()); break; case ERROR: if ( raiseAlarm(name, "error", exception) ) LOG4CPLUS_ERROR(app_->getApplicationLogger(), "Raising error alarm " << name << ": " << exception.message()); break; case FATAL: if ( raiseAlarm(name, "fatal", exception) ) LOG4CPLUS_FATAL(app_->getApplicationLogger(), "Raising fatal alarm " << name << ": " << exception.message()); break; default: LOG4CPLUS_WARN(app_->getApplicationLogger(), "Unknown alarm level received for " << name << ": " << exception.message()); } }
bool stor::AlarmHandler::raiseAlarm | ( | const std::string | name, |
const std::string | level, | ||
xcept::Exception & | exception | ||
) | [private] |
Definition at line 138 of file AlarmHandler.cc.
References Exception.
{ if (!alarmInfoSpace_) return false; boost::mutex::scoped_lock sl( mutex_ ); sentinel::utils::Alarm *alarm = new sentinel::utils::Alarm(level, exception, app_); try { alarmInfoSpace_->fireItemAvailable(name, alarm); } catch(xdata::exception::Exception) { // Alarm is already set or sentinel not available return false; } return true; }
void stor::AlarmHandler::revokeAlarm | ( | const std::string | name | ) | [virtual] |
Revokes a sentinel alarm
Definition at line 165 of file AlarmHandler.cc.
References Exception, and mergeVDriftHistosByStation::name.
{ if (!alarmInfoSpace_) return; boost::mutex::scoped_lock sl( mutex_ ); sentinel::utils::Alarm *alarm; try { alarm = dynamic_cast<sentinel::utils::Alarm*>( alarmInfoSpace_->find( name ) ); } catch(xdata::exception::Exception) { // Alarm has not been set or sentinel not available return; } LOG4CPLUS_INFO(app_->getApplicationLogger(), "Revoking alarm " << name); alarmInfoSpace_->fireItemRevoked(name, app_); delete alarm; }
xdata::InfoSpace* stor::AlarmHandler::alarmInfoSpace_ [private] |
Definition at line 110 of file AlarmHandler.h.
Referenced by clearAllAlarms().
xdaq::Application* stor::AlarmHandler::app_ [private] |
Definition at line 108 of file AlarmHandler.h.
Referenced by clearAllAlarms(), and getLogger().
boost::mutex stor::AlarmHandler::mutex_ [mutable, private] |
Definition at line 112 of file AlarmHandler.h.
Referenced by clearAllAlarms().
boost::shared_ptr<SharedResources> stor::AlarmHandler::sharedResources_ [private] |
Definition at line 109 of file AlarmHandler.h.
Referenced by localDebug(), and moveToFailedState().