(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.61     if (req->getType() == async_messages::CIMSERVICE_STOP)
 61 kumpf   1.33     {
 62                      req->op->processing();
 63                      handle_CimServiceStop(static_cast<CimServiceStop *>(req));
 64                  }
 65 kumpf   1.61     else if (req->getType() == async_messages::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                          Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2,
 86                              "IndicationHandlerService::_handle_async_request got "
 87                                  "unexpected legacy message type '%u'", legacy->getType());
 88                          _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                          // Set the client's requested language into this service thread.
102                          // This will allow functions in this service to return messages
103                          // in the correct language.
104 a.arora         1.38     AutoPtr<CIMMessage>   msg(dynamic_cast<CIMMessage *>(message));
105                          if (msg.get() != NULL)
106 kumpf           1.33     {
107                              if (msg->thread_changed())
108                              {
109 kumpf           1.61             AutoPtr<AcceptLanguageList> langs(new AcceptLanguageList((
110                                      (AcceptLanguageListContainer)msg->operationContext.get(
111                                          AcceptLanguageListContainer::NAME)).getLanguages()));
112 a.arora         1.38             Thread::setLanguages(langs.get());
113                                  langs.release();
114 kumpf           1.33         }
115                          }
116                          else
117                          {
118                              Thread::clearLanguages();
119                          }
120                      
121                          switch (message->getType())
122                          {
123                              case CIM_HANDLE_INDICATION_REQUEST_MESSAGE:
124 chuck           1.28         {
125 kumpf           1.61             AutoPtr<CIMHandleIndicationResponseMessage> response(
126                                      _handleIndication(
127                                          (CIMHandleIndicationRequestMessage*) message));
128 a.arora         1.38             SendForget(response.get());
129                                  response.release();
130 kumpf           1.33             break;
131 chuck           1.28         }
132 chuck           1.23 
133 kumpf           1.33         default:
134 carolann.graves 1.57             PEGASUS_ASSERT(0);
135 kumpf           1.33             break;
136                          }
137                      
138 kumpf           1.1  }
139                      
140 kumpf           1.3  void IndicationHandlerService::handleEnqueue()
141                      {
142 a.arora         1.38    AutoPtr<Message> message(dequeue());
143 kumpf           1.3  
144 a.arora         1.38    PEGASUS_ASSERT(message.get() != 0);
145                         if (message.get())
146 kumpf           1.33    {
147 a.arora         1.38        handleEnqueue(message.get());
148                             message.release();
149 kumpf           1.33    }
150 kumpf           1.3  }
151                      
152 kumpf           1.33 CIMHandleIndicationResponseMessage*
153                      IndicationHandlerService::_handleIndication(
154                          CIMHandleIndicationRequestMessage* request)
155 kumpf           1.1  {
156 kumpf           1.61     PEG_METHOD_ENTER(TRC_IND_HANDLE,
157                              "IndicationHandlerService::_handleIndication");
158 tony            1.27 
159 marek           1.55     Boolean handleIndicationSuccess = true;
160 kumpf           1.33     CIMException cimException =
161                              PEGASUS_CIM_EXCEPTION(CIM_ERR_SUCCESS, String::EMPTY);
162 kumpf           1.1  
163 kumpf           1.33     CIMName className = request->handlerInstance.getClassName();
164                          CIMNamespaceName nameSpace = request->nameSpace;
165 kumpf           1.16 
166 kumpf           1.33     CIMInstance indication = request->indicationInstance;
167                          CIMInstance handler = request->handlerInstance;
168                      
169                          Uint32 pos = PEG_NOT_FOUND;
170                      
171                          if (className.equal (PEGASUS_CLASSNAME_INDHANDLER_CIMXML) ||
172                              className.equal (PEGASUS_CLASSNAME_LSTNRDST_CIMXML))
173                          {
174 yi.zhou         1.42         pos = handler.findProperty(PEGASUS_PROPERTYNAME_LSTNRDST_DESTINATION);
175 kumpf           1.1  
176 yi.zhou         1.42         if (pos == PEG_NOT_FOUND)
177 kumpf           1.33         {
178                                  cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
179 kumpf           1.61                 MessageLoaderParms(
180                                          "HandlerService.IndicationHandlerService."
181                                              "CIMXML_HANDLER_WITHOUT_DESTINATION",
182                                          "CIMXml Handler missing Destination property"));
183 marek           1.55             handleIndicationSuccess = false;
184 yi.zhou         1.42         }
185                              else
186                              {
187                                  CIMProperty prop = handler.getProperty(pos);
188                                  String destination = prop.getValue().toString();
189                      
190                                  if (destination.size() == 0)
191                                  {
192                                      cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
193 kumpf           1.61                     MessageLoaderParms(
194                                              "HandlerService.IndicationHandlerService."
195                                                  "INVALID_DESTINATION",
196                                              "invalid destination"));
197 marek           1.55                 handleIndicationSuccess = false;
198 yi.zhou         1.42             }
199 kumpf           1.33 //compared index 10 is not :
200 yi.zhou         1.42             else if (destination.subString(0, 10) == String("localhost/"))
201                                  {
202                                      Array<Uint32> exportServer;
203 humberto        1.25 
204 yi.zhou         1.42                     find_services(PEGASUS_QUEUENAME_EXPORTREQDISPATCHER, 0, 0,
205 kumpf           1.33                           &exportServer);
206 kumpf           1.1  
207 yi.zhou         1.42                 // Listener is build with Cimom, so send message to ExportServer
208                      
209                                     AutoPtr<CIMExportIndicationRequestMessage> exportmessage( 
210 kumpf           1.61                     new CIMExportIndicationRequestMessage(
211                                              XmlWriter::getNextMessageId(),
212                                              //taking localhost/CIMListener portion out from reg
213                                              destination.subString(21),
214                                              indication,
215                                              QueueIdStack(exportServer[0], getQueueId()),
216                                              String::EMPTY,
217                                              String::EMPTY));
218 kumpf           1.33 
219 mike            1.62.2.1                 exportmessage->sessionKey = request->sessionKey;
220 denise.eckstein 1.50                     exportmessage->operationContext.insert(
221                                              IdentityContainer(String::EMPTY));
222 yi.zhou         1.42                     exportmessage->operationContext.set(
223 kumpf           1.61                         request->operationContext.get(
224                                              ContentLanguageListContainer::NAME)); 
225 yi.zhou         1.42                     AutoPtr<AsyncOpNode> op( this->get_op());
226                          
227                                          AutoPtr<AsyncLegacyOperationStart> asyncRequest(
228 kumpf           1.61                         new AsyncLegacyOperationStart(
229 a.arora         1.38                         op.get(),
230 kumpf           1.33                         exportServer[0],
231 a.arora         1.38                         exportmessage.get(),
232                                              _queueId));
233 yi.zhou         1.42                     exportmessage.release();
234 kumpf           1.33     
235 yi.zhou         1.42                     PEG_TRACE_STRING(TRC_IND_HANDLE, Tracer::LEVEL4,
236 kumpf           1.61                         "Indication handler forwarding message to " +
237                                                  ((MessageQueue::lookup(exportServer[0])) ?
238                                                      String(((MessageQueue::lookup(exportServer[0]))->
239                                                          getQueueName())) :
240                                                      String("BAD queue name")));
241 kumpf           1.33     
242 yi.zhou         1.42                     //SendAsync(op,
243                                          //      exportServer[0],
244                                          //      IndicationHandlerService::_handleIndicationCallBack,
245                                          //      this,
246                                          //      (void *)request->queueIds.top());
247                                          AutoPtr<AsyncReply> asyncReply(SendWait(asyncRequest.get()));
248 kumpf           1.61                     asyncRequest.release();
249 yi.zhou         1.42     
250                                          // Return the ExportIndication results in HandleIndication 
251 kumpf           1.61                     //response
252 yi.zhou         1.42                     AutoPtr<CIMExportIndicationResponseMessage> exportResponse(
253 kumpf           1.61                         reinterpret_cast<CIMExportIndicationResponseMessage *>(
254                                                  (static_cast<AsyncLegacyOperationResult *>(
255                                                      asyncReply.get()))->get_result()));
256 yi.zhou         1.42                     cimException = exportResponse->cimException;
257 kumpf           1.33     
258 yi.zhou         1.42                     op->release();
259                                          this->return_op(op.release());
260                                      }
261 kumpf           1.61                 else
262                                      {
263 marek           1.55                     handleIndicationSuccess = _loadHandler(request, cimException);
264 kumpf           1.61                 }
265 yi.zhou         1.42             }
266                              }
267                              else if (className.equal (PEGASUS_CLASSNAME_INDHANDLER_SNMP))
268                              {
269                                  pos = handler.findProperty(PEGASUS_PROPERTYNAME_LSTNRDST_TARGETHOST);
270 kumpf           1.33     
271 yi.zhou         1.42             if (pos == PEG_NOT_FOUND)
272                                  {
273                                      cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
274 kumpf           1.61                     MessageLoaderParms(
275                                              "HandlerService.IndicationHandlerService."
276                                                  "SNMP_HANDLER_WITHOUT_TARGETHOST",
277                                              "Snmp Handler missing Targethost property"));
278 marek           1.55                 handleIndicationSuccess = false;
279 kumpf           1.33             }
280                                  else
281                                  {
282 yi.zhou         1.42                 CIMProperty prop = handler.getProperty(pos);
283                                      String destination = prop.getValue().toString();
284 tony            1.30     
285 yi.zhou         1.42                 if (destination.size() == 0)
286 kumpf           1.33                 {
287 yi.zhou         1.42                     cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
288 kumpf           1.61                         MessageLoaderParms(
289                                                  "HandlerService.IndicationHandlerService."
290                                                      "INVALID_TARGETHOST",
291                                                  "invalid targethost"));
292 marek           1.55                     handleIndicationSuccess = false;
293 kumpf           1.33                 }
294 kumpf           1.61                 else
295 kumpf           1.33                 {
296 marek           1.55                     handleIndicationSuccess = _loadHandler(request, cimException);
297 kumpf           1.33                 }
298                                  }
299                              }
300 yi.zhou         1.44         else if ((className.equal (PEGASUS_CLASSNAME_LSTNRDST_SYSTEM_LOG)) ||
301 kumpf           1.61                  (className.equal (PEGASUS_CLASSNAME_LSTNRDST_EMAIL)))
302 yi.zhou         1.42         {
303 marek           1.55             handleIndicationSuccess = _loadHandler(request, cimException);
304                              }
305                          
306                              // no success to handle indication
307                              // somewhere an exception message was build
308                              // time to write the error message to the log
309                              if (!handleIndicationSuccess)
310                              {
311 marek           1.62             Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::WARNING,
312                                      "HandlerService.IndicationHandlerService."
313                                          "INDICATION_DELIVERY_FAILED",
314                                      "Failed to deliver an indication: $0",
315 kumpf           1.61                 cimException.getMessage());
316 yi.zhou         1.42         }
317                          
318                              CIMHandleIndicationResponseMessage* response =
319                                  new CIMHandleIndicationResponseMessage(
320 kumpf           1.16                 request->messageId,
321                                      cimException,
322 a.arora         1.39                 request->queueIds.copyAndPop());
323 marek           1.55             
324 karl            1.46         delete request;
325 kumpf           1.33         return response;
326 kumpf           1.1      }
327                          
328 marek           1.55     Boolean IndicationHandlerService::_loadHandler(
329 yi.zhou         1.42         CIMHandleIndicationRequestMessage* request,
330 kumpf           1.61         CIMException& cimException)
331 yi.zhou         1.42     {
332                              CIMName className = request->handlerInstance.getClassName();
333 yi.zhou         1.49     
334 yi.zhou         1.48         try
335                              {
336 kumpf           1.61             CIMHandler* handlerLib = _lookupHandlerForClass(className);
337 yi.zhou         1.42     
338 yi.zhou         1.49             if (handlerLib)
339 yi.zhou         1.48             {
340 kumpf           1.61                 ContentLanguageList langs = 
341 yi.zhou         1.42                     ((ContentLanguageListContainer)request->operationContext.
342                                          get(ContentLanguageListContainer::NAME)).getLanguages();
343                          
344                                      handlerLib->handleIndication(
345                                          request->operationContext,
346                                          request->nameSpace.getString(),
347                                          request->indicationInstance,
348                                          request->handlerInstance,
349                                          request->subscriptionInstance,
350                                          langs);
351 yi.zhou         1.48             }
352                                  else
353                                  {
354                                      cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
355                                          MessageLoaderParms("HandlerService."
356                                          "IndicationHandlerService.FAILED_TO_LOAD",
357                                          "Failed to load Handler"));
358 marek           1.55                 return false;
359 yi.zhou         1.48             }
360                          
361                              }
362                              catch (Exception& e)
363                              {
364                                  cimException =
365                                      PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
366 marek           1.55             return false;
367 yi.zhou         1.42         }
368 yi.zhou         1.48         catch (...)
369 yi.zhou         1.42         {
370 yi.zhou         1.48             cimException =
371                                      PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Exception: Unknown");
372 marek           1.55             return false;
373 yi.zhou         1.42         }
374 marek           1.55         return true;
375 yi.zhou         1.42     }
376                          
377 kumpf           1.1      CIMHandler* IndicationHandlerService::_lookupHandlerForClass(
378 kumpf           1.19        const CIMName& className)
379 kumpf           1.1      {
380 mday            1.6         String handlerId;
381 kumpf           1.1      
382 kumpf           1.61        if (className.equal(PEGASUS_CLASSNAME_INDHANDLER_CIMXML) ||
383                                 className.equal(PEGASUS_CLASSNAME_LSTNRDST_CIMXML))
384                             {
385 humberto        1.45     #ifdef PEGASUS_OS_OS400
386 chuck           1.47            handlerId = LIBRARY_NAME_CIMXML_INDICATION_HNDLR;
387                                 handlerId.append("/CIMxmlIndicationHandler");
388 humberto        1.45     #else
389 kumpf           1.8             handlerId = String("CIMxmlIndicationHandler");
390 humberto        1.45     #endif
391 kumpf           1.61        }
392                             else if (className.equal(PEGASUS_CLASSNAME_INDHANDLER_SNMP))
393                             {
394 humberto        1.45     #ifdef PEGASUS_OS_OS400
395                                 handlerId = LIBRARY_NAME_SNMP_INDICATION_HNDLR;
396 chuck           1.47            handlerId.append("/snmpIndicationHandler");
397 humberto        1.45     #else
398 kumpf           1.8             handlerId = String("snmpIndicationHandler");
399 humberto        1.45     #endif
400 kumpf           1.61        }
401                             else if (className.equal(PEGASUS_CLASSNAME_LSTNRDST_SYSTEM_LOG))
402 yi.zhou         1.42            handlerId = String("SystemLogListenerDestination");
403 kumpf           1.61        else if (className.equal(PEGASUS_CLASSNAME_LSTNRDST_EMAIL))
404 yi.zhou         1.44            handlerId = String("EmailListenerDestination");
405 carolann.graves 1.59     
406                             PEGASUS_ASSERT(handlerId.size() != 0);
407 kumpf           1.1      
408 yi.zhou         1.48        CIMHandler* handler = _handlerTable.getHandler(handlerId, _repository);
409 kumpf           1.1      
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