(file) Return to IndicationHandlerService.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / HandlerService

  1 karl  1.52 //%2006////////////////////////////////////////////////////////////////////////
  2 kumpf 1.1  //
  3 karl  1.37 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4            // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 karl  1.31 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.37 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl  1.40 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.52 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12            // EMC Corporation; Symantec Corporation; The Open Group.
 13 kumpf 1.1  //
 14            // Permission is hereby granted, free of charge, to any person obtaining a copy
 15            // of this software and associated documentation files (the "Software"), to
 16            // deal in the Software without restriction, including without limitation the
 17            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 18            // sell copies of the Software, and to permit persons to whom the Software is
 19            // furnished to do so, subject to the following conditions:
 20 kumpf 1.17 // 
 21 kumpf 1.1  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 23            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 24            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 25            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 26            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 27            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 28            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 29            //
 30            //==============================================================================
 31            //
 32            //%/////////////////////////////////////////////////////////////////////////////
 33            
 34 kumpf 1.11 #include <Pegasus/Common/Constants.h>
 35 kumpf 1.19 #include <Pegasus/Common/CIMName.h>
 36 mday  1.14 #include <Pegasus/Common/Tracer.h>
 37 kumpf 1.1  #include <Pegasus/Common/CIMMessage.h>
 38            #include <Pegasus/Common/XmlWriter.h>
 39 kumpf 1.13 #include <Pegasus/Common/PegasusVersion.h>
 40 yi.zhou 1.42 #include <Pegasus/Common/Constants.h>
 41 kumpf   1.61 #include <Pegasus/Common/MessageLoader.h>
 42              #include <Pegasus/Common/AutoPtr.h>
 43 kumpf   1.1  
 44              #include "IndicationHandlerService.h"
 45              
 46              PEGASUS_USING_STD;
 47 kumpf   1.61 
 48 kumpf   1.1  PEGASUS_USING_PEGASUS;
 49              
 50              PEGASUS_NAMESPACE_BEGIN
 51              
 52 kumpf   1.2  IndicationHandlerService::IndicationHandlerService(CIMRepository* repository)
 53 kumpf   1.61     : Base("IndicationHandlerService", MessageQueue::getNextQueueId()),
 54                    _repository(repository)
 55 kumpf   1.1  {
 56              }
 57              
 58 kumpf   1.61 void IndicationHandlerService::_handle_async_request(AsyncRequest* req)
 59 kumpf   1.1  {
 60 kumpf   1.67     if (req->getType() == ASYNC_CIMSERVICE_STOP)
 61 kumpf   1.33     {
 62                      req->op->processing();
 63                      handle_CimServiceStop(static_cast<CimServiceStop *>(req));
 64                  }
 65 kumpf   1.67     else if (req->getType() == ASYNC_ASYNC_LEGACY_OP_START)
 66 kumpf   1.33     {
 67                      req->op->processing();
 68 kumpf   1.61         AutoPtr<Message> legacy(
 69                          static_cast<AsyncLegacyOperationStart *>(req)->get_action());
 70 kumpf   1.33         if (legacy->getType() == CIM_HANDLE_INDICATION_REQUEST_MESSAGE)
 71                      {
 72 a.arora 1.38             AutoPtr<Message> legacy_response(_handleIndication(
 73 kumpf   1.61                 (CIMHandleIndicationRequestMessage*) legacy.get()));
 74 a.arora 1.38             legacy.release();
 75 kumpf   1.61             AutoPtr<AsyncLegacyOperationResult> async_result(
 76                              new AsyncLegacyOperationResult(
 77 kumpf   1.33                     req->op,
 78 kumpf   1.61                     legacy_response.get()));
 79 a.arora 1.38             legacy_response.release();
 80                          async_result.release();
 81 kumpf   1.33             _complete_op_node(req->op, ASYNC_OPSTATE_COMPLETE, 0, 0);
 82                      }
 83                      else
 84                      {
 85 marek   1.64             PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL2,
 86 kumpf   1.33                 "IndicationHandlerService::_handle_async_request got "
 87 marek   1.64                     "unexpected legacy message type '%u'", legacy->getType()));
 88 kumpf   1.33             _make_response(req, async_results::CIM_NAK);
 89                      }
 90                  }
 91                  else
 92                  {
 93                      Base::_handle_async_request(req);
 94                  }
 95 kumpf   1.1  }
 96              
 97 mday    1.4  void IndicationHandlerService::handleEnqueue(Message* message)
 98 kumpf   1.1  {
 99 carolann.graves 1.58     PEGASUS_ASSERT(message != 0);
100 kumpf           1.33 
101 kumpf           1.68     AutoPtr<CIMMessage> cimMessage(dynamic_cast<CIMMessage *>(message));
102                          PEGASUS_ASSERT(cimMessage.get() != 0);
103                      
104 kumpf           1.33     // Set the client's requested language into this service thread.
105                          // This will allow functions in this service to return messages
106                          // in the correct language.
107 kumpf           1.68     cimMessage->updateThreadLanguages();
108 kumpf           1.33 
109                          switch (message->getType())
110                          {
111                              case CIM_HANDLE_INDICATION_REQUEST_MESSAGE:
112 chuck           1.28         {
113 kumpf           1.61             AutoPtr<CIMHandleIndicationResponseMessage> response(
114                                      _handleIndication(
115                                          (CIMHandleIndicationRequestMessage*) message));
116 a.arora         1.38             SendForget(response.get());
117                                  response.release();
118 kumpf           1.33             break;
119 chuck           1.28         }
120 chuck           1.23 
121 kumpf           1.33         default:
122 carolann.graves 1.57             PEGASUS_ASSERT(0);
123 kumpf           1.33             break;
124                          }
125 kumpf           1.1  }
126                      
127 kumpf           1.3  void IndicationHandlerService::handleEnqueue()
128                      {
129 a.arora         1.38    AutoPtr<Message> message(dequeue());
130 kumpf           1.3  
131 a.arora         1.38    PEGASUS_ASSERT(message.get() != 0);
132                         if (message.get())
133 kumpf           1.33    {
134 a.arora         1.38        handleEnqueue(message.get());
135                             message.release();
136 kumpf           1.33    }
137 kumpf           1.3  }
138                      
139 kumpf           1.33 CIMHandleIndicationResponseMessage*
140                      IndicationHandlerService::_handleIndication(
141                          CIMHandleIndicationRequestMessage* request)
142 kumpf           1.1  {
143 kumpf           1.61     PEG_METHOD_ENTER(TRC_IND_HANDLE,
144 thilo.boehm     1.63         "IndicationHandlerService::_handleIndication()");
145 tony            1.27 
146 marek           1.55     Boolean handleIndicationSuccess = true;
147 kumpf           1.33     CIMException cimException =
148                              PEGASUS_CIM_EXCEPTION(CIM_ERR_SUCCESS, String::EMPTY);
149 kumpf           1.1  
150 kumpf           1.33     CIMName className = request->handlerInstance.getClassName();
151                          CIMNamespaceName nameSpace = request->nameSpace;
152 kumpf           1.16 
153 kumpf           1.33     CIMInstance indication = request->indicationInstance;
154                          CIMInstance handler = request->handlerInstance;
155                      
156 mike            1.69.4.1     PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4,
157 w.otsuka        1.65             "Handler service received %s Indication %s for %s:%s.%s Handler",
158                                  (const char*)(indication.getClassName().getString().getCString()),
159                                  (const char*)(request->messageId.getCString()),
160                                  (const char*)(request->nameSpace.getString().getCString()),
161                                  (const char*)(handler.getClassName().getString().getCString()),
162                                  (const char*)(handler.getProperty(handler.findProperty(
163                                  PEGASUS_PROPERTYNAME_NAME)).getValue().toString().getCString())));
164 kumpf           1.33         Uint32 pos = PEG_NOT_FOUND;
165                          
166                              if (className.equal (PEGASUS_CLASSNAME_INDHANDLER_CIMXML) ||
167                                  className.equal (PEGASUS_CLASSNAME_LSTNRDST_CIMXML))
168                              {
169 yi.zhou         1.42             pos = handler.findProperty(PEGASUS_PROPERTYNAME_LSTNRDST_DESTINATION);
170 kumpf           1.1      
171 yi.zhou         1.42             if (pos == PEG_NOT_FOUND)
172 kumpf           1.33             {
173                                      cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
174 kumpf           1.61                     MessageLoaderParms(
175                                              "HandlerService.IndicationHandlerService."
176                                                  "CIMXML_HANDLER_WITHOUT_DESTINATION",
177                                              "CIMXml Handler missing Destination property"));
178 marek           1.55                 handleIndicationSuccess = false;
179 yi.zhou         1.42             }
180                                  else
181                                  {
182                                      CIMProperty prop = handler.getProperty(pos);
183                                      String destination = prop.getValue().toString();
184                          
185                                      if (destination.size() == 0)
186                                      {
187                                          cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
188 kumpf           1.61                         MessageLoaderParms(
189                                                  "HandlerService.IndicationHandlerService."
190                                                      "INVALID_DESTINATION",
191                                                  "invalid destination"));
192 marek           1.55                     handleIndicationSuccess = false;
193 yi.zhou         1.42                 }
194 kumpf           1.33     //compared index 10 is not :
195 yi.zhou         1.42                 else if (destination.subString(0, 10) == String("localhost/"))
196                                      {
197                                          Array<Uint32> exportServer;
198 humberto        1.25     
199 yi.zhou         1.42                         find_services(PEGASUS_QUEUENAME_EXPORTREQDISPATCHER, 0, 0,
200 kumpf           1.33                               &exportServer);
201 kumpf           1.1      
202 yi.zhou         1.42                     // Listener is build with Cimom, so send message to ExportServer
203                                         AutoPtr<CIMExportIndicationRequestMessage> exportmessage( 
204 kumpf           1.61                         new CIMExportIndicationRequestMessage(
205                                                  XmlWriter::getNextMessageId(),
206                                                  //taking localhost/CIMListener portion out from reg
207                                                  destination.subString(21),
208                                                  indication,
209                                                  QueueIdStack(exportServer[0], getQueueId()),
210                                                  String::EMPTY,
211                                                  String::EMPTY));
212 kumpf           1.33     
213 denise.eckstein 1.50                     exportmessage->operationContext.insert(
214                                              IdentityContainer(String::EMPTY));
215 yi.zhou         1.42                     exportmessage->operationContext.set(
216 kumpf           1.61                         request->operationContext.get(
217                                              ContentLanguageListContainer::NAME)); 
218 yi.zhou         1.42                     AutoPtr<AsyncOpNode> op( this->get_op());
219                          
220                                          AutoPtr<AsyncLegacyOperationStart> asyncRequest(
221 kumpf           1.61                         new AsyncLegacyOperationStart(
222 a.arora         1.38                         op.get(),
223 kumpf           1.33                         exportServer[0],
224 a.arora         1.38                         exportmessage.get(),
225                                              _queueId));
226 yi.zhou         1.42                     exportmessage.release();
227 kumpf           1.33     
228 yi.zhou         1.42                     PEG_TRACE_STRING(TRC_IND_HANDLE, Tracer::LEVEL4,
229 kumpf           1.61                         "Indication handler forwarding message to " +
230                                                  ((MessageQueue::lookup(exportServer[0])) ?
231                                                      String(((MessageQueue::lookup(exportServer[0]))->
232                                                          getQueueName())) :
233                                                      String("BAD queue name")));
234 mike            1.69.4.1                 PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4,
235 w.otsuka        1.65                         "Sending %s Indication %s to destination %s",
236                                              (const char*) (indication.getClassName().getString().
237                                              getCString()),
238                                              (const char*)(request->messageId.getCString()),
239                                              (const char*) destination.getCString()));
240 kumpf           1.33     
241 yi.zhou         1.42                     //SendAsync(op,
242                                          //      exportServer[0],
243                                          //      IndicationHandlerService::_handleIndicationCallBack,
244                                          //      this,
245                                          //      (void *)request->queueIds.top());
246                                          AutoPtr<AsyncReply> asyncReply(SendWait(asyncRequest.get()));
247 kumpf           1.61                     asyncRequest.release();
248 yi.zhou         1.42     
249                                          // Return the ExportIndication results in HandleIndication 
250 kumpf           1.61                     //response
251 yi.zhou         1.42                     AutoPtr<CIMExportIndicationResponseMessage> exportResponse(
252 kumpf           1.61                         reinterpret_cast<CIMExportIndicationResponseMessage *>(
253                                                  (static_cast<AsyncLegacyOperationResult *>(
254                                                      asyncReply.get()))->get_result()));
255 yi.zhou         1.42                     cimException = exportResponse->cimException;
256 kumpf           1.33     
257 yi.zhou         1.42                     op->release();
258                                          this->return_op(op.release());
259                                      }
260 kumpf           1.61                 else
261                                      {
262 marek           1.55                     handleIndicationSuccess = _loadHandler(request, cimException);
263 kumpf           1.61                 }
264 yi.zhou         1.42             }
265                              }
266                              else if (className.equal (PEGASUS_CLASSNAME_INDHANDLER_SNMP))
267                              {
268                                  pos = handler.findProperty(PEGASUS_PROPERTYNAME_LSTNRDST_TARGETHOST);
269 kumpf           1.33     
270 yi.zhou         1.42             if (pos == PEG_NOT_FOUND)
271                                  {
272                                      cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
273 kumpf           1.61                     MessageLoaderParms(
274                                              "HandlerService.IndicationHandlerService."
275                                                  "SNMP_HANDLER_WITHOUT_TARGETHOST",
276                                              "Snmp Handler missing Targethost property"));
277 marek           1.55                 handleIndicationSuccess = false;
278 kumpf           1.33             }
279                                  else
280                                  {
281 yi.zhou         1.42                 CIMProperty prop = handler.getProperty(pos);
282                                      String destination = prop.getValue().toString();
283 tony            1.30     
284 yi.zhou         1.42                 if (destination.size() == 0)
285 kumpf           1.33                 {
286 yi.zhou         1.42                     cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
287 kumpf           1.61                         MessageLoaderParms(
288                                                  "HandlerService.IndicationHandlerService."
289                                                      "INVALID_TARGETHOST",
290                                                  "invalid targethost"));
291 marek           1.55                     handleIndicationSuccess = false;
292 kumpf           1.33                 }
293 kumpf           1.61                 else
294 kumpf           1.33                 {
295 marek           1.55                     handleIndicationSuccess = _loadHandler(request, cimException);
296 kumpf           1.33                 }
297                                  }
298                              }
299 yi.zhou         1.44         else if ((className.equal (PEGASUS_CLASSNAME_LSTNRDST_SYSTEM_LOG)) ||
300 kumpf           1.61                  (className.equal (PEGASUS_CLASSNAME_LSTNRDST_EMAIL)))
301 yi.zhou         1.42         {
302 marek           1.55             handleIndicationSuccess = _loadHandler(request, cimException);
303                              }
304                          
305                              // no success to handle indication
306                              // somewhere an exception message was build
307                              // time to write the error message to the log
308                              if (!handleIndicationSuccess)
309                              {
310 marek           1.62             Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::WARNING,
311                                      "HandlerService.IndicationHandlerService."
312                                          "INDICATION_DELIVERY_FAILED",
313                                      "Failed to deliver an indication: $0",
314 kumpf           1.61                 cimException.getMessage());
315 yi.zhou         1.42         }
316                          
317                              CIMHandleIndicationResponseMessage* response =
318 kumpf           1.69             dynamic_cast<CIMHandleIndicationResponseMessage*>(
319                                      request->buildResponse());
320                              response->cimException = cimException;
321                          
322 karl            1.46         delete request;
323 thilo.boehm     1.63         PEG_METHOD_EXIT();
324 kumpf           1.33         return response;
325 kumpf           1.1      }
326                          
327 marek           1.55     Boolean IndicationHandlerService::_loadHandler(
328 yi.zhou         1.42         CIMHandleIndicationRequestMessage* request,
329 kumpf           1.61         CIMException& cimException)
330 yi.zhou         1.42     {
331 thilo.boehm     1.63         PEG_METHOD_ENTER(TRC_IND_HANDLE,
332                                  "IndicationHandlerService::__loadHandler()");
333                          
334 yi.zhou         1.42         CIMName className = request->handlerInstance.getClassName();
335 yi.zhou         1.49     
336 yi.zhou         1.48         try
337                              {
338 kumpf           1.61             CIMHandler* handlerLib = _lookupHandlerForClass(className);
339 yi.zhou         1.42     
340 yi.zhou         1.49             if (handlerLib)
341 yi.zhou         1.48             {
342 kumpf           1.61                 ContentLanguageList langs = 
343 yi.zhou         1.42                     ((ContentLanguageListContainer)request->operationContext.
344                                          get(ContentLanguageListContainer::NAME)).getLanguages();
345                          
346                                      handlerLib->handleIndication(
347                                          request->operationContext,
348                                          request->nameSpace.getString(),
349                                          request->indicationInstance,
350                                          request->handlerInstance,
351                                          request->subscriptionInstance,
352                                          langs);
353 yi.zhou         1.48             }
354                                  else
355                                  {
356                                      cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
357                                          MessageLoaderParms("HandlerService."
358                                          "IndicationHandlerService.FAILED_TO_LOAD",
359                                          "Failed to load Handler"));
360 thilo.boehm     1.63                 PEG_METHOD_EXIT();
361 marek           1.55                 return false;
362 yi.zhou         1.48             }
363                          
364                              }
365                              catch (Exception& e)
366                              {
367                                  cimException =
368                                      PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
369 thilo.boehm     1.63             PEG_METHOD_EXIT();
370 marek           1.55             return false;
371 yi.zhou         1.42         }
372 yi.zhou         1.48         catch (...)
373 yi.zhou         1.42         {
374 yi.zhou         1.48             cimException =
375                                      PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Exception: Unknown");
376 thilo.boehm     1.63             PEG_METHOD_EXIT();
377 marek           1.55             return false;
378 yi.zhou         1.42         }
379 thilo.boehm     1.63         PEG_METHOD_EXIT();
380 marek           1.55         return true;
381 yi.zhou         1.42     }
382                          
383 kumpf           1.1      CIMHandler* IndicationHandlerService::_lookupHandlerForClass(
384 kumpf           1.19        const CIMName& className)
385 kumpf           1.1      {
386 thilo.boehm     1.63        PEG_METHOD_ENTER(TRC_IND_HANDLE,
387                                  "IndicationHandlerService::_lookupHandlerForClass()");
388                          
389 mday            1.6         String handlerId;
390 kumpf           1.1      
391 kumpf           1.61        if (className.equal(PEGASUS_CLASSNAME_INDHANDLER_CIMXML) ||
392                                 className.equal(PEGASUS_CLASSNAME_LSTNRDST_CIMXML))
393                             {
394 kumpf           1.8             handlerId = String("CIMxmlIndicationHandler");
395 kumpf           1.61        }
396                             else if (className.equal(PEGASUS_CLASSNAME_INDHANDLER_SNMP))
397                             {
398 kumpf           1.8             handlerId = String("snmpIndicationHandler");
399 kumpf           1.61        }
400                             else if (className.equal(PEGASUS_CLASSNAME_LSTNRDST_SYSTEM_LOG))
401 yi.zhou         1.42            handlerId = String("SystemLogListenerDestination");
402 kumpf           1.61        else if (className.equal(PEGASUS_CLASSNAME_LSTNRDST_EMAIL))
403 yi.zhou         1.44            handlerId = String("EmailListenerDestination");
404 carolann.graves 1.59     
405                             PEGASUS_ASSERT(handlerId.size() != 0);
406 kumpf           1.1      
407 yi.zhou         1.48        CIMHandler* handler = _handlerTable.getHandler(handlerId, _repository);
408 kumpf           1.1      
409 thilo.boehm     1.63        PEG_METHOD_EXIT();
410 mday            1.6         return handler;
411 kumpf           1.1      }
412                          
413                          PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2