CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SMProxyServer.cc
Go to the documentation of this file.
1 // $Id: SMProxyServer.cc,v 1.47 2011/08/22 14:21:00 mommsen Exp $
3 
8 #include "EventFilter/StorageManager/src/ConsumerUtils.icc"
9 
11 
12 #include "xcept/tools.h"
13 #include "xdaq/NamespaceURI.h"
14 #include "xdata/InfoSpaceFactory.h"
15 #include "xgi/Method.h"
16 #include "xoap/Method.h"
17 
18 #include <cstdlib>
19 
20 using namespace std;
21 using namespace smproxy;
22 
23 
24 SMProxyServer::SMProxyServer(xdaq::ApplicationStub * s) :
25  xdaq::Application(s)
26 {
27  LOG4CPLUS_INFO(this->getApplicationLogger(),"Making SMProxyServer");
28 
29  // bind all callback functions
33 
34  std::string errorMsg = "Exception in SMProxyServer constructor: ";
35  try
36  {
38  }
39  catch(std::exception &e)
40  {
41  errorMsg += e.what();
42  LOG4CPLUS_FATAL( getApplicationLogger(), e.what() );
43  XCEPT_RAISE( exception::Exception, e.what() );
44  }
45  catch(...)
46  {
47  errorMsg += "unknown exception";
48  LOG4CPLUS_FATAL( getApplicationLogger(), errorMsg );
49  XCEPT_RAISE( exception::Exception, errorMsg );
50  }
51 
53 }
54 
55 
57 {
58  xoap::bind( this,
60  "Configure",
61  XDAQ_NS_URI );
62  xoap::bind( this,
64  "Enable",
65  XDAQ_NS_URI );
66  xoap::bind( this,
68  "Stop",
69  XDAQ_NS_URI );
70  xoap::bind( this,
72  "Halt",
73  XDAQ_NS_URI );
74 }
75 
76 
78 {
79  xgi::bind(this,&SMProxyServer::css, "styles.css");
80  xgi::bind(this,&SMProxyServer::defaultWebPage, "Default");
81  xgi::bind(this,&SMProxyServer::dataRetrieverWebPage, "dataRetriever");
82  xgi::bind(this,&SMProxyServer::dqmEventStatisticsWebPage,"dqmEventStatistics");
83  xgi::bind(this,&SMProxyServer::consumerStatisticsWebPage,"consumerStatistics" );
84 }
85 
86 
88 {
89  // event consumers
90  xgi::bind( this, &SMProxyServer::processConsumerRegistrationRequest, "registerConsumer" );
91  xgi::bind( this, &SMProxyServer::processConsumerHeaderRequest, "getregdata" );
92  xgi::bind( this, &SMProxyServer::processConsumerEventRequest, "geteventdata" );
93 
94  // dqm event consumers
95  xgi::bind(this,&SMProxyServer::processDQMConsumerRegistrationRequest, "registerDQMConsumer");
96  xgi::bind(this,&SMProxyServer::processDQMConsumerEventRequest, "getDQMeventdata");
97 }
98 
99 
101 {
102  stateMachine_.reset( new StateMachine(this) );
103 
104  consumerUtils_.reset( new ConsumerUtils_t (
105  stateMachine_->getConfiguration(),
106  stateMachine_->getRegistrationCollection(),
107  stateMachine_->getRegistrationQueue(),
108  stateMachine_->getInitMsgCollection(),
109  stateMachine_->getEventQueueCollection(),
110  stateMachine_->getDQMEventQueueCollection(),
111  stateMachine_->getStatisticsReporter()->alarmHandler()
112  ) );
113 
115  getApplicationDescriptor(), stateMachine_));
116 }
117 
118 
120 {
121  // Start the workloops
122  try
123  {
124  stateMachine_->getStatisticsReporter()->startWorkLoop("theStatisticsReporter");
125  }
126  catch(xcept::Exception &e)
127  {
128  stateMachine_->moveToFailedState(e);
129  }
130  catch(std::exception &e)
131  {
132  XCEPT_DECLARE(exception::Exception,
133  sentinelException, e.what());
134  stateMachine_->moveToFailedState(sentinelException);
135  }
136  catch(...)
137  {
138  std::string errorMsg = "Unknown exception when starting the workloops";
139  XCEPT_DECLARE(exception::Exception,
140  sentinelException, errorMsg);
141  stateMachine_->moveToFailedState(sentinelException);
142  }
143 }
144 
145 
147 // Web interface call back functions //
149 
152 {
153  smpsWebPageHelper_->css(in,out);
154 }
155 
156 
159 {
160  std::string errorMsg = "Failed to create the default webpage";
161 
162  try
163  {
164  smpsWebPageHelper_->defaultWebPage(out);
165  }
166  catch(std::exception &e)
167  {
168  errorMsg += ": ";
169  errorMsg += e.what();
170 
171  LOG4CPLUS_ERROR(getApplicationLogger(), errorMsg);
172  XCEPT_RAISE(xgi::exception::Exception, errorMsg);
173  }
174  catch(...)
175  {
176  errorMsg += ": Unknown exception";
177 
178  LOG4CPLUS_ERROR(getApplicationLogger(), errorMsg);
179  XCEPT_RAISE(xgi::exception::Exception, errorMsg);
180  }
181 }
182 
183 
186 {
187 
188  std::string err_msg =
189  "Failed to create data retriever web page";
190 
191  try
192  {
193  smpsWebPageHelper_->dataRetrieverWebPage(out);
194  }
195  catch( std::exception &e )
196  {
197  err_msg += ": ";
198  err_msg += e.what();
199  LOG4CPLUS_ERROR( getApplicationLogger(), err_msg );
200  XCEPT_RAISE( xgi::exception::Exception, err_msg );
201  }
202  catch(...)
203  {
204  err_msg += ": Unknown exception";
205  LOG4CPLUS_ERROR( getApplicationLogger(), err_msg );
206  XCEPT_RAISE( xgi::exception::Exception, err_msg );
207  }
208 }
209 
210 
213 {
214 
215  std::string err_msg =
216  "Failed to create consumer web page";
217 
218  try
219  {
220  smpsWebPageHelper_->consumerStatisticsWebPage(out);
221  }
222  catch( std::exception &e )
223  {
224  err_msg += ": ";
225  err_msg += e.what();
226  LOG4CPLUS_ERROR( getApplicationLogger(), err_msg );
227  XCEPT_RAISE( xgi::exception::Exception, err_msg );
228  }
229  catch(...)
230  {
231  err_msg += ": Unknown exception";
232  LOG4CPLUS_ERROR( getApplicationLogger(), err_msg );
233  XCEPT_RAISE( xgi::exception::Exception, err_msg );
234  }
235 }
236 
237 
240 {
241  std::string errorMsg = "Failed to create the DQM event statistics webpage";
242 
243  try
244  {
245  smpsWebPageHelper_->dqmEventStatisticsWebPage(out);
246  }
247  catch(std::exception &e)
248  {
249  errorMsg += ": ";
250  errorMsg += e.what();
251 
252  LOG4CPLUS_ERROR(getApplicationLogger(), errorMsg);
253  XCEPT_RAISE(xgi::exception::Exception, errorMsg);
254  }
255  catch(...)
256  {
257  errorMsg += ": Unknown exception";
258 
259  LOG4CPLUS_ERROR(getApplicationLogger(), errorMsg);
260  XCEPT_RAISE(xgi::exception::Exception, errorMsg);
261  }
262 }
263 
264 
266 // State Machine call back functions //
268 
269 xoap::MessageReference SMProxyServer::handleFSMSoapMessage( xoap::MessageReference msg )
271 {
272  std::string errorMsg;
273  xoap::MessageReference returnMsg;
274 
275  try {
276  errorMsg = "Failed to extract FSM event and parameters from SOAP message: ";
278  std::string newState = "unknown";
279 
280  errorMsg = "Failed to process '" + command + "' state machine event: ";
281  if (command == "Configure")
282  {
283  newState = stateMachine_->processEvent( Configure() );
284  }
285  else if (command == "Enable")
286  {
287  newState = stateMachine_->processEvent( Enable() );
288  }
289  else if (command == "Stop")
290  {
291  newState = stateMachine_->processEvent( Stop() );
292  }
293  else if (command == "Halt")
294  {
295  newState = stateMachine_->processEvent( Halt() );
296  }
297  else
298  {
299  XCEPT_RAISE(exception::StateMachine,
300  "Received an unknown state machine event '" + command + "'.");
301  }
302 
303  errorMsg = "Failed to create FSM SOAP reply message: ";
304  returnMsg = stor::soaputils::createFsmSoapResponseMsg(command, newState);
305  }
306  catch (cms::Exception& e) {
307  errorMsg += e.explainSelf();
308  XCEPT_DECLARE(xoap::exception::Exception,
309  sentinelException, errorMsg);
310  stateMachine_->moveToFailedState(sentinelException);
311  }
312  catch (xcept::Exception &e) {
313  XCEPT_DECLARE_NESTED(xoap::exception::Exception,
314  sentinelException, errorMsg, e);
315  stateMachine_->moveToFailedState(sentinelException);
316  }
317  catch (std::exception& e) {
318  errorMsg += e.what();
319  XCEPT_DECLARE(xoap::exception::Exception,
320  sentinelException, errorMsg);
321  stateMachine_->moveToFailedState(sentinelException);
322  }
323  catch (...) {
324  errorMsg += "Unknown exception";
325  XCEPT_DECLARE(xoap::exception::Exception,
326  sentinelException, errorMsg);
327  stateMachine_->moveToFailedState(sentinelException);
328  }
329 
330  return returnMsg;
331 }
332 
333 
337 
338 void
341 {
342  consumerUtils_->processConsumerRegistrationRequest(in,out);
343 }
344 
345 
346 void
349 {
350  consumerUtils_->processConsumerHeaderRequest(in,out);
351 }
352 
353 
354 void
357 {
358  consumerUtils_->processConsumerEventRequest(in,out);
359 }
360 
361 
362 void
365 {
366  consumerUtils_->processDQMConsumerRegistrationRequest(in,out);
367 }
368 
369 
370 void
373 {
374  consumerUtils_->processDQMConsumerEventRequest(in,out);
375 }
376 
377 namespace stor {
379  // Specialization for ConsumerUtils //
381  template<>
382  void
385  {
386  writeHTTPHeaders( out );
387  out->write( (char*)evt.dataLocation(), evt.totalDataSize() );
388  }
389 }
390 
391 
393 // *** Provides factory method for the instantiation of SM applications //
395 // This macro is depreciated:
396 XDAQ_INSTANTIATE(SMProxyServer)
397 
398 // One should use the XDAQ_INSTANTIATOR() in the header file
399 // and this one here. But this breaks the backward compatibility,
400 // as all xml configuration files would have to be changed to use
401 // 'stor::SMProxyServer' instead of 'SMProxyServer'.
402 // XDAQ_INSTANTIATOR_IMPL(stor::SMProxyServer)
403 
404 
405 
void processDQMConsumerEventRequest(xgi::Input *in, xgi::Output *out)
#define Input(cl)
Definition: vmac.h:189
StateMachinePtr stateMachine_
void processConsumerRegistrationRequest(xgi::Input *in, xgi::Output *out)
virtual std::string explainSelf() const
Definition: Exception.cc:146
boost::scoped_ptr< ConsumerUtils_t > consumerUtils_
xoap::MessageReference createFsmSoapResponseMsg(const std::string commandName, const std::string currentState)
Definition: SoapUtils.cc:38
void processConsumerHeaderRequest(xgi::Input *in, xgi::Output *out)
void dataRetrieverWebPage(xgi::Input *in, xgi::Output *out)
void css(xgi::Input *in, xgi::Output *out)
void processConsumerEventRequest(xgi::Input *in, xgi::Output *out)
xoap::MessageReference handleFSMSoapMessage(xoap::MessageReference)
tuple out
Definition: dbtoconf.py:99
unsigned char * dataLocation() const
Definition: EventMsg.cc:66
void consumerStatisticsWebPage(xgi::Input *in, xgi::Output *out)
#define Output(cl)
Definition: vmac.h:193
void defaultWebPage(xgi::Input *in, xgi::Output *out)
void dqmEventStatisticsWebPage(xgi::Input *in, xgi::Output *out)
std::string extractParameters(xoap::MessageReference, xdaq::Application *)
Definition: SoapUtils.cc:25
void processDQMConsumerRegistrationRequest(xgi::Input *in, xgi::Output *out)
unsigned long totalDataSize() const
Definition: EventMsg.cc:60
boost::scoped_ptr< SMPSWebPageHelper > smpsWebPageHelper_