CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
stor::AlarmHandler Class Reference

#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_
 

Detailed Description

Helper class to handle sentinel alarming

Author:
mommsen
Revision:
1.10
Date:
2011/11/08 10:48:39

Definition at line 30 of file AlarmHandler.h.

Member Enumeration Documentation

Enumerator
OKAY 
WARNING 
ERROR 
FATAL 

Definition at line 35 of file AlarmHandler.h.

Constructor & Destructor Documentation

stor::AlarmHandler::AlarmHandler ( )
inline

Definition at line 38 of file AlarmHandler.h.

38 {};
stor::AlarmHandler::AlarmHandler ( xdaq::Application *  app)
explicit

Definition at line 21 of file AlarmHandler.cc.

References edm::hlt::Exception.

23  :
24  app_(app)
25  {
26  try
27  {
28  alarmInfoSpace_ = xdata::getInfoSpaceFactory()->get("urn:xdaq-sentinel:alarms");
29  }
31  {
32  // sentinel is not available
33  alarmInfoSpace_ = 0;
34  }
35  }
xdaq::Application * app_
Definition: AlarmHandler.h:108
xdata::InfoSpace * alarmInfoSpace_
Definition: AlarmHandler.h:110
stor::AlarmHandler::AlarmHandler ( xdaq::Application *  ,
boost::shared_ptr< SharedResources  
)
virtual stor::AlarmHandler::~AlarmHandler ( )
inlinevirtual

Definition at line 50 of file AlarmHandler.h.

50 {};

Member Function Documentation

void stor::AlarmHandler::clearAllAlarms ( )

Revokes all sentinel alarms

Definition at line 191 of file AlarmHandler.cc.

References alarmInfoSpace_, app_, and mutex_.

192  {
193  if (!alarmInfoSpace_) return;
194 
195  boost::mutex::scoped_lock sl( mutex_ );
196 
197  typedef std::map<std::string, xdata::Serializable*, std::less<std::string> > alarmList;
198  alarmList alarms = alarmInfoSpace_->match(".*");
199  for (alarmList::const_iterator it = alarms.begin(), itEnd = alarms.end();
200  it != itEnd; ++it)
201  {
202  sentinel::utils::Alarm* alarm = dynamic_cast<sentinel::utils::Alarm*>(it->second);
203  alarmInfoSpace_->fireItemRevoked(it->first, app_);
204  delete alarm;
205  }
206  }
xdaq::Application * app_
Definition: AlarmHandler.h:108
xdata::InfoSpace * alarmInfoSpace_
Definition: AlarmHandler.h:110
boost::mutex mutex_
Definition: AlarmHandler.h:112
Logger& stor::AlarmHandler::getLogger ( ) const
inline

Return the application logger

Definition at line 95 of file AlarmHandler.h.

References app_.

96  { return app_->getApplicationLogger(); }
xdaq::Application * app_
Definition: AlarmHandler.h:108
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().

248  {
249  std::ostringstream fname_oss;
250  fname_oss << "/tmp/storage_manager_debug_" <<
251  sharedResources_->configuration_->getDiskWritingParams().smInstanceString_ <<
252  "_" << getpid();
253  const std::string fname = fname_oss.str();
254  std::ofstream f( fname.c_str(), std::ios_base::ate | std::ios_base::out | std::ios_base::app );
255  if( f.is_open() )
256  {
257  try
258  {
259  f << message << std::endl;
260  f.close();
261  }
262  catch(...)
263  {}
264  }
265  }
double f[11][100]
boost::shared_ptr< SharedResources > sharedResources_
Definition: AlarmHandler.h:109
tuple out
Definition: dbtoconf.py:99
string fname
main script
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, cppFunctionSkipper::exception, edm::hlt::Exception, edm::hlt::Fail, FATAL, localDebug(), notifySentinel(), seconds(), and sharedResources_.

210  {
211  std::string errorMsg = "Failed to process FAIL exception: "
212  + xcept::stdformat_exception_history(exception) + " due to ";
213 
214  try
215  {
217  sharedResources_->statisticsReporter_->getStateMachineMonitorCollection().setStatusMessage(
218  xcept::stdformat_exception_history(exception)
219  );
220  EventPtr_t stMachEvent( new Fail() );
221  // wait maximum 5 seconds until enqueuing succeeds
222  if ( ! sharedResources_->commandQueue_->enqTimedWait( stMachEvent, boost::posix_time::seconds(5) ) )
223  {
224  XCEPT_DECLARE_NESTED( stor::exception::StateTransition,
225  sentinelException, "Failed to enqueue FAIL event", exception );
226  notifySentinel(AlarmHandler::FATAL, sentinelException);
227  }
228  }
229  catch(xcept::Exception &e)
230  {
231  errorMsg += xcept::stdformat_exception_history(e);
232  localDebug( errorMsg );
233  }
234  catch(std::exception &e)
235  {
236  errorMsg += e.what();
237  localDebug( errorMsg );
238  }
239  catch( ... )
240  {
241  errorMsg += "an unknown exception.";
242  localDebug( errorMsg );
243  }
244  }
virtual void notifySentinel(const ALARM_LEVEL, xcept::Exception &)
Definition: AlarmHandler.cc:98
double seconds()
reject
Definition: HLTenums.h:23
void localDebug(const std::string &message) const
boost::shared_ptr< boost::statechart::event_base > EventPtr_t
Definition: CommandQueue.h:21
boost::shared_ptr< SharedResources > sharedResources_
Definition: AlarmHandler.h:109
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().

102  {
103 
104  switch( level )
105  {
106  case OKAY:
107  LOG4CPLUS_INFO(app_->getApplicationLogger(),
108  xcept::stdformat_exception_history(exception));
109  break;
110 
111  case WARNING:
112  LOG4CPLUS_WARN(app_->getApplicationLogger(),
113  xcept::stdformat_exception_history(exception));
114  app_->notifyQualified("warning", exception);
115  break;
116 
117  case ERROR:
118  LOG4CPLUS_ERROR(app_->getApplicationLogger(),
119  xcept::stdformat_exception_history(exception));
120  app_->notifyQualified("error", exception);
121  break;
122 
123  case FATAL:
124  LOG4CPLUS_FATAL(app_->getApplicationLogger(),
125  xcept::stdformat_exception_history(exception));
126  app_->notifyQualified("fatal", exception);
127  break;
128 
129  default:
130  LOG4CPLUS_WARN(app_->getApplicationLogger(),
131  "Unknown alarm level received for exception: " <<
132  xcept::stdformat_exception_history(exception));
133  }
134  }
xdaq::Application * app_
Definition: AlarmHandler.h:108
tuple level
Definition: testEve_cfg.py:34
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.

64  {
65 
66  switch( level )
67  {
68  case OKAY:
70  break;
71 
72  case WARNING:
73  if ( raiseAlarm(name, "warning", exception) )
74  LOG4CPLUS_WARN(app_->getApplicationLogger(),
75  "Raising warning alarm " << name << ": " << exception.message());
76  break;
77 
78  case ERROR:
79  if ( raiseAlarm(name, "error", exception) )
80  LOG4CPLUS_ERROR(app_->getApplicationLogger(),
81  "Raising error alarm " << name << ": " << exception.message());
82  break;
83 
84  case FATAL:
85  if ( raiseAlarm(name, "fatal", exception) )
86  LOG4CPLUS_FATAL(app_->getApplicationLogger(),
87  "Raising fatal alarm " << name << ": " << exception.message());
88  break;
89 
90  default:
91  LOG4CPLUS_WARN(app_->getApplicationLogger(),
92  "Unknown alarm level received for " << name << ": " << exception.message());
93  }
94  }
xdaq::Application * app_
Definition: AlarmHandler.h:108
virtual void raiseAlarm(const std::string name, const ALARM_LEVEL, xcept::Exception &)
Definition: AlarmHandler.cc:59
virtual void revokeAlarm(const std::string name)
tuple level
Definition: testEve_cfg.py:34
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 edm::hlt::Exception.

143  {
144 
145  if (!alarmInfoSpace_) return false;
146 
147  boost::mutex::scoped_lock sl( mutex_ );
148 
149  sentinel::utils::Alarm *alarm =
150  new sentinel::utils::Alarm(level, exception, app_);
151  try
152  {
153  alarmInfoSpace_->fireItemAvailable(name, alarm);
154  }
156  {
157  // Alarm is already set or sentinel not available
158  return false;
159  }
160  return true;
161  }
xdaq::Application * app_
Definition: AlarmHandler.h:108
xdata::InfoSpace * alarmInfoSpace_
Definition: AlarmHandler.h:110
boost::mutex mutex_
Definition: AlarmHandler.h:112
tuple level
Definition: testEve_cfg.py:34
void stor::AlarmHandler::revokeAlarm ( const std::string  name)
virtual

Revokes a sentinel alarm

Definition at line 165 of file AlarmHandler.cc.

References edm::hlt::Exception, and mergeVDriftHistosByStation::name.

168  {
169  if (!alarmInfoSpace_) return;
170 
171  boost::mutex::scoped_lock sl( mutex_ );
172 
173  sentinel::utils::Alarm *alarm;
174  try
175  {
176  alarm = dynamic_cast<sentinel::utils::Alarm*>( alarmInfoSpace_->find( name ) );
177  }
179  {
180  // Alarm has not been set or sentinel not available
181  return;
182  }
183 
184  LOG4CPLUS_INFO(app_->getApplicationLogger(), "Revoking alarm " << name);
185 
186  alarmInfoSpace_->fireItemRevoked(name, app_);
187  delete alarm;
188  }
xdaq::Application * app_
Definition: AlarmHandler.h:108
xdata::InfoSpace * alarmInfoSpace_
Definition: AlarmHandler.h:110
boost::mutex mutex_
Definition: AlarmHandler.h:112

Member Data Documentation

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_
mutableprivate

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().