(file) Return to DefaultProviderManager.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / ProviderManager2 / Default

  1 karl  1.59 //%2006////////////////////////////////////////////////////////////////////////
  2 chip  1.1  //
  3 karl  1.43 // 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.7  // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.43 // 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.47 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.59 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12            // EMC Corporation; Symantec Corporation; The Open Group.
 13 chip  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 karl  1.43 // 
 21 chip  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            #include "DefaultProviderManager.h"
 35            
 36            #include <Pegasus/Common/CIMMessage.h>
 37            #include <Pegasus/Common/OperationContext.h>
 38 kumpf 1.71 #include <Pegasus/Common/Time.h>
 39 chip  1.1  #include <Pegasus/Common/Tracer.h>
 40            #include <Pegasus/Common/StatisticalData.h>
 41            #include <Pegasus/Common/Logger.h>
 42 kumpf 1.71 #include <Pegasus/Common/MessageLoader.h>
 43 kumpf 1.77 #include <Pegasus/Common/FileSystem.h>
 44 kumpf 1.71 #include <Pegasus/Common/PegasusVersion.h>
 45 kumpf 1.38 #include <Pegasus/Common/Constants.h>
 46 chip  1.1  
 47 chuck 1.44 #include <Pegasus/Query/QueryExpression/QueryExpression.h>
 48 schuur 1.12 #include <Pegasus/ProviderManager2/QueryExpressionFactory.h>
 49             
 50 schuur 1.21 #include <Pegasus/ProviderManager2/OperationResponseHandler.h>
 51 chip   1.1  
 52 kumpf  1.71 PEGASUS_NAMESPACE_BEGIN
 53             
 54             //
 55             // Default Provider Manager
 56             //
 57             DefaultProviderManager::DefaultProviderManager()
 58             {
 59                 _subscriptionInitComplete = false;
 60 kumpf  1.66 }
 61 a.dunfey 1.58 
 62 kumpf    1.71 DefaultProviderManager::~DefaultProviderManager()
 63               {
 64                   PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
 65                       "DefaultProviderManager::~DefaultProviderManager");
 66 a.dunfey 1.58 
 67 kumpf    1.71     _shutdownAllProviders();
 68 chip     1.1  
 69 kumpf    1.71     for (ProviderTable::Iterator i = _providers.start(); i != 0; i++)
 70 chip     1.1      {
 71 kumpf    1.71         ProviderMessageHandler* provider = i.value();
 72                       delete provider;
 73 chip     1.1      }
 74               
 75 kumpf    1.71     for (ModuleTable::Iterator j = _modules.start(); j != 0; j++)
 76 chip     1.1      {
 77 kumpf    1.71         ProviderModule* module = j.value();
 78                       delete module;
 79 chip     1.1      }
 80               
 81 kumpf    1.71     PEG_METHOD_EXIT();
 82 chip     1.1  }
 83               
 84 kumpf    1.73 Message* DefaultProviderManager::processMessage(Message* message)
 85 chip     1.1  {
 86                   PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
 87                       "DefaultProviderManager::processMessage()");
 88               
 89 kumpf    1.73     CIMRequestMessage* request = dynamic_cast<CIMRequestMessage*>(message);
 90                   PEGASUS_ASSERT(request != 0);
 91               
 92                   CIMResponseMessage* response = 0;
 93 chip     1.1  
 94 kumpf    1.73     try
 95 chip     1.1      {
 96 kumpf    1.73         // pass the request message to a handler method based on message type
 97                       switch(request->getType())
 98                       {
 99                       case CIM_GET_INSTANCE_REQUEST_MESSAGE:
100                       case CIM_ENUMERATE_INSTANCES_REQUEST_MESSAGE:
101                       case CIM_ENUMERATE_INSTANCE_NAMES_REQUEST_MESSAGE:
102                       case CIM_CREATE_INSTANCE_REQUEST_MESSAGE:
103                       case CIM_MODIFY_INSTANCE_REQUEST_MESSAGE:
104                       case CIM_DELETE_INSTANCE_REQUEST_MESSAGE:
105                       case CIM_EXEC_QUERY_REQUEST_MESSAGE:
106                       case CIM_ASSOCIATORS_REQUEST_MESSAGE:
107                       case CIM_ASSOCIATOR_NAMES_REQUEST_MESSAGE:
108                       case CIM_REFERENCES_REQUEST_MESSAGE:
109                       case CIM_REFERENCE_NAMES_REQUEST_MESSAGE:
110                       case CIM_GET_PROPERTY_REQUEST_MESSAGE:
111                       case CIM_SET_PROPERTY_REQUEST_MESSAGE:
112                       case CIM_INVOKE_METHOD_REQUEST_MESSAGE:
113                       case CIM_CREATE_SUBSCRIPTION_REQUEST_MESSAGE:
114                       case CIM_MODIFY_SUBSCRIPTION_REQUEST_MESSAGE:
115                       case CIM_DELETE_SUBSCRIPTION_REQUEST_MESSAGE:
116                       case CIM_EXPORT_INDICATION_REQUEST_MESSAGE:
117 kumpf    1.71         {
118 dmitry.mikulin 1.80             ProviderIdContainer providerId = 
119                                     request->operationContext.get(ProviderIdContainer::NAME);
120                     
121 kumpf          1.71             // resolve provider name
122 dmitry.mikulin 1.80             ProviderName name = _resolveProviderName(providerId);
123 kumpf          1.71 
124                                 // get cached or load new provider module
125                                 ProviderOperationCounter poc(
126 dmitry.mikulin 1.80                 _getProvider(
127                                         name.getPhysicalName(), 
128                                         name.getModuleName(), 
129                                         name.getLogicalName()));
130 chip           1.1  
131 kumpf          1.73             response = poc.GetProvider().processMessage(request);
132 kumpf          1.71             break;
133                             }
134 schuur         1.14 
135 kumpf          1.73         case CIM_DISABLE_MODULE_REQUEST_MESSAGE:
136                                 response = _handleDisableModuleRequest(request);
137                                 break;
138                     
139                             case CIM_ENABLE_MODULE_REQUEST_MESSAGE:
140                                 response = _handleEnableModuleRequest(request);
141                                 break;
142 chip           1.1  
143 kumpf          1.73         case CIM_STOP_ALL_PROVIDERS_REQUEST_MESSAGE:
144                                 // tell the provider manager to shutdown all the providers
145                                 _shutdownAllProviders();
146                                 response = request->buildResponse();
147                                 break;
148 chip           1.1  
149 kumpf          1.73         case CIM_SUBSCRIPTION_INIT_COMPLETE_REQUEST_MESSAGE:
150                                 response = _handleSubscriptionInitCompleteRequest(request);
151                                 break;
152 chip           1.1  
153 kumpf          1.73 // Note: The PG_Provider AutoStart property is not yet supported
154                     #if 0
155                             case CIM_INITIALIZE_PROVIDER_REQUEST_MESSAGE:
156                             {
157 dmitry.mikulin 1.80             ProviderIdContainer providerId = 
158                                     request->operationContext.get(ProviderIdContainer::NAME);
159                     
160 kumpf          1.73             // resolve provider name
161 dmitry.mikulin 1.80             ProviderName name = _resolveProviderName(providerId);
162 kumpf          1.30 
163 kumpf          1.73             // get cached or load new provider module
164                                 ProviderOperationCounter poc(
165 dmitry.mikulin 1.80                 _getProvider(
166                                         name.getPhysicalName(), 
167                                         name.getModuleName(), 
168                                         name.getLogicalName()));
169 kumpf          1.30 
170 kumpf          1.73             break;
171                             }
172                     #endif
173 kumpf          1.30 
174 kumpf          1.73         default:
175                                 PEGASUS_ASSERT(0);
176                                 break;
177                             }
178 kumpf          1.30     }
179 kumpf          1.71     catch (CIMException& e)
180 kumpf          1.30     {
181 kumpf          1.73         PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2,
182 kumpf          1.30             "CIMException: " + e.getMessage());
183 kumpf          1.73         response = request->buildResponse();
184 kumpf          1.71         response->cimException = PEGASUS_CIM_EXCEPTION_LANG(
185                                 e.getContentLanguages(), e.getCode(), e.getMessage());
186 kumpf          1.30     }
187 kumpf          1.71     catch (Exception& e)
188 kumpf          1.30     {
189 kumpf          1.73         PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2,
190 kumpf          1.30             "Exception: " + e.getMessage());
191 kumpf          1.73         response = request->buildResponse();
192 kumpf          1.71         response->cimException = PEGASUS_CIM_EXCEPTION_LANG(
193                                 e.getContentLanguages(), CIM_ERR_FAILED, e.getMessage());
194 kumpf          1.30     }
195 kumpf          1.71     catch (...)
196 kumpf          1.30     {
197 marek          1.79         PEG_TRACE_CSTRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2,
198 kumpf          1.30             "Exception: Unknown");
199 kumpf          1.73         response = request->buildResponse();
200 kumpf          1.71         response->cimException = PEGASUS_CIM_EXCEPTION(
201                                 CIM_ERR_FAILED, "Unknown error.");
202 kumpf          1.30     }
203                     
204                         PEG_METHOD_EXIT();
205 kumpf          1.71     return response;
206 kumpf          1.30 }
207                     
208 kumpf          1.73 CIMResponseMessage* DefaultProviderManager::_handleDisableModuleRequest(
209                         CIMRequestMessage* message)
210 chip           1.1  {
211 kumpf          1.71     PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
212                             "DefaultProviderManager::_handleDisableModuleRequest");
213 chip           1.1  
214 kumpf          1.71     CIMDisableModuleRequestMessage* request =
215                             dynamic_cast<CIMDisableModuleRequestMessage*>(message);
216 chip           1.1      PEGASUS_ASSERT(request != 0);
217                     
218 kumpf          1.71     Array<Uint16> operationalStatus;
219                         CIMException cimException;
220 chip           1.1  
221                         try
222                         {
223 kumpf          1.71         // get provider module name
224                             String moduleName;
225                             CIMInstance mInstance = request->providerModule;
226                             Uint32 pos = mInstance.findProperty(CIMName("Name"));
227                             PEGASUS_ASSERT(pos != PEG_NOT_FOUND);
228                             mInstance.getProperty(pos).getValue().get(moduleName);
229 chip           1.1  
230 kumpf          1.71         //
231                             // Unload providers
232                             //
233                             Array<CIMInstance> providerInstances = request->providers;
234 chip           1.1  
235 kumpf          1.71         for (Uint32 i = 0, n = providerInstances.size(); i < n; i++)
236                             {
237                                 String pName;
238                                 providerInstances[i].getProperty(
239                                     providerInstances[i].findProperty("Name")).
240                                         getValue().get(pName);
241 chip           1.1  
242 dmitry.mikulin 1.80             Sint16 ret_value = _disableProvider(moduleName, pName);
243 chip           1.1  
244 kumpf          1.71             if (ret_value == 0)
245                                 {
246                                     // disable failed since there are pending requests,
247                                     // stop trying to disable other providers in this module.
248                                     operationalStatus.append(CIM_MSE_OPSTATUS_VALUE_OK);
249                                     break;
250                                 }
251                                 else if (ret_value != 1)  // Not success
252                                 {
253                                     // disable failed for other reason, throw exception
254                                     throw PEGASUS_CIM_EXCEPTION_L(
255                                         CIM_ERR_FAILED,
256                                         MessageLoaderParms(
257                                             "ProviderManager.ProviderManagerService."
258                                                 "DISABLE_PROVIDER_FAILED",
259                                             "Failed to disable the provider."));
260                                 }
261                             }
262                         }
263 kumpf          1.78     catch (CIMException& e)
264 kumpf          1.71     {
265                             PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
266                                              "Exception: " + e.getMessage());
267                             cimException = e;
268                         }
269 kumpf          1.78     catch (Exception& e)
270 kumpf          1.71     {
271                             PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
272                                 "Exception: " + e.getMessage());
273                             cimException = CIMException(CIM_ERR_FAILED, e.getMessage());
274                         }
275                         catch (...)
276                         {
277 marek          1.79         PEG_TRACE_CSTRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
278 kumpf          1.71             "Exception: Unknown");
279                             cimException = PEGASUS_CIM_EXCEPTION_L(
280                                 CIM_ERR_FAILED,
281                                 MessageLoaderParms(
282                                     "ProviderManager.ProviderManagerService.UNKNOWN_ERROR",
283                                     "Unknown Error"));
284                         }
285 chip           1.1  
286 kumpf          1.71     if (cimException.getCode() == CIM_ERR_SUCCESS)
287                         {
288                             // Status is set to OK if a provider was busy
289                             if (operationalStatus.size() == 0)
290                             {
291                                 operationalStatus.append(CIM_MSE_OPSTATUS_VALUE_STOPPED);
292                             }
293                         }
294                         else
295                         {
296                             // If exception occurs, module is not stopped
297                             operationalStatus.append(CIM_MSE_OPSTATUS_VALUE_OK);
298                         }
299 marek          1.64 
300 kumpf          1.71     CIMDisableModuleResponseMessage* response =
301                             dynamic_cast<CIMDisableModuleResponseMessage*>(
302                                 request->buildResponse());
303                         PEGASUS_ASSERT(response != 0);
304 chip           1.1  
305 kumpf          1.71     response->operationalStatus = operationalStatus;
306 chip           1.1  
307 kumpf          1.71     PEG_METHOD_EXIT();
308 chip           1.1  
309 kumpf          1.71     return response;
310 chip           1.1  }
311                     
312 kumpf          1.73 CIMResponseMessage* DefaultProviderManager::_handleEnableModuleRequest(
313                         CIMRequestMessage* message)
314 chip           1.1  {
315 kumpf          1.71     PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
316                             "DefaultProviderManager::_handleEnableModuleRequest");
317 chip           1.1  
318 kumpf          1.71     CIMEnableModuleRequestMessage* request =
319                             dynamic_cast<CIMEnableModuleRequestMessage*>(message);
320                         PEGASUS_ASSERT(request != 0);
321 chip           1.1  
322 kumpf          1.71     Array<Uint16> operationalStatus;
323                         operationalStatus.append(CIM_MSE_OPSTATUS_VALUE_OK);
324 chip           1.1  
325 kumpf          1.71     CIMEnableModuleResponseMessage* response =
326                             dynamic_cast<CIMEnableModuleResponseMessage*>(
327 kumpf          1.54             request->buildResponse());
328 chip           1.1      PEGASUS_ASSERT(response != 0);
329                     
330 kumpf          1.71     response->operationalStatus = operationalStatus;
331 chip           1.1  
332 kumpf          1.71     PEG_METHOD_EXIT();
333                         return response;
334                     }
335 chip           1.1  
336 kumpf          1.73 CIMResponseMessage*
337                     DefaultProviderManager::_handleSubscriptionInitCompleteRequest(
338                         CIMRequestMessage* message)
339 kumpf          1.71 {
340                         PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
341                             "DefaultProviderManager::_handleSubscriptionInitCompleteRequest");
342 chip           1.1  
343 kumpf          1.71     CIMSubscriptionInitCompleteRequestMessage* request =
344                             dynamic_cast<CIMSubscriptionInitCompleteRequestMessage*>(message);
345 chip           1.1      PEGASUS_ASSERT(request != 0);
346                     
347 kumpf          1.71     CIMSubscriptionInitCompleteResponseMessage* response =
348                             dynamic_cast<CIMSubscriptionInitCompleteResponseMessage*>(
349 kumpf          1.54             request->buildResponse());
350 chip           1.1      PEGASUS_ASSERT(response != 0);
351                     
352 kumpf          1.71     _subscriptionInitComplete = true;
353 chip           1.1  
354 kumpf          1.71     // Make a copy of the table so it is not locked during the provider calls
355                         Array<ProviderMessageHandler*> providerList;
356 chip           1.1      {
357 kumpf          1.71         AutoMutex lock(_providerTableMutex);
358 chip           1.1  
359 kumpf          1.71         for (ProviderTable::Iterator i = _providers.start(); i != 0; i++)
360                             {
361                                 providerList.append(i.value());
362                             }
363                         }
364 chip           1.1  
365 kumpf          1.71     //
366                         // Notify all providers that subscription initialization is complete
367                         //
368                         for (Uint32 j = 0; j < providerList.size(); j++)
369                         {
370 kumpf          1.72         AutoMutex lock(providerList[j]->status.getStatusMutex());
371                     
372                             if (providerList[j]->status.isInitialized())
373                             {
374                                 providerList[j]->subscriptionInitComplete();
375                             }
376 kumpf          1.71     }
377 chip           1.1  
378 kumpf          1.71     PEG_METHOD_EXIT();
379                         return response;
380                     }
381 chip           1.1  
382 kumpf          1.71 ProviderName DefaultProviderManager::_resolveProviderName(
383 kumpf          1.78     const ProviderIdContainer& providerId)
384 kumpf          1.71 {
385                         String providerName;
386                         String fileName;
387 dmitry.mikulin 1.80     String moduleName;
388 kumpf          1.71     CIMValue genericValue;
389 se.gupta       1.34 
390 dmitry.mikulin 1.80     genericValue = providerId.getModule().getProperty(
391                             providerId.getModule().findProperty("Name")).getValue();
392                         genericValue.get(moduleName);
393                     
394 kumpf          1.71     genericValue = providerId.getProvider().getProperty(
395                             providerId.getProvider().findProperty("Name")).getValue();
396                         genericValue.get(providerName);
397 chip           1.1  
398 kumpf          1.71     genericValue = providerId.getModule().getProperty(
399                             providerId.getModule().findProperty("Location")).getValue();
400                         genericValue.get(fileName);
401 marek          1.64 
402 kumpf          1.77     String resolvedFileName = _resolvePhysicalName(fileName);
403                     
404                         if (resolvedFileName == String::EMPTY)
405                         {
406                             // Provider library not found
407                             String moduleName;
408                             genericValue = providerId.getModule().getProperty(
409                                 providerId.getModule().findProperty("Name")).getValue();
410                             genericValue.get(moduleName);
411                     
412                             throw Exception(MessageLoaderParms(
413                                 "ProviderManager.ProviderManagerService.PROVIDER_FILE_NOT_FOUND",
414                                 "File \"$0\" was not found for provider module \"$1\".",
415                                 FileSystem::buildLibraryFileName(fileName), moduleName));
416                         }
417                     
418 dmitry.mikulin 1.80     return ProviderName(moduleName, providerName, resolvedFileName);
419 chip           1.1  }
420                     
421 kumpf          1.71 ProviderOperationCounter DefaultProviderManager::_getProvider(
422                         const String& moduleFileName,
423 dmitry.mikulin 1.80     const String& moduleName,
424 kumpf          1.71     const String& providerName)
425 chip           1.1  {
426 kumpf          1.71     PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
427                             "DefaultProviderManager::_getProvider");
428 chip           1.1  
429 dmitry.mikulin 1.80     ProviderMessageHandler* pr = _lookupProvider(moduleName, providerName);
430 chip           1.1  
431 kumpf          1.71     if (!pr->status.isInitialized())
432                         {
433                             _initProvider(pr, moduleFileName);
434 kumpf          1.72     }
435                     
436                         AutoMutex lock(pr->status.getStatusMutex());
437 chip           1.1  
438 kumpf          1.72     if (!pr->status.isInitialized())
439                         {
440                             PEG_METHOD_EXIT();
441                             throw PEGASUS_CIM_EXCEPTION(
442                                 CIM_ERR_FAILED, "provider initialization failed");
443 kumpf          1.71     }
444 chip           1.1  
445 kumpf          1.71     ProviderOperationCounter poc(pr);
446 chip           1.1  
447 kumpf          1.71     PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
448                             "Returning Provider " + providerName);
449 chip           1.1  
450 kumpf          1.71     PEG_METHOD_EXIT();
451                         return poc;
452                     }
453 chip           1.1  
454 kumpf          1.71 ProviderMessageHandler* DefaultProviderManager::_lookupProvider(
455 dmitry.mikulin 1.80     const String& moduleName,
456 kumpf          1.71     const String& providerName)
457                     {
458                         PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
459                             "DefaultProviderManager::_lookupProvider");
460 chip           1.1  
461 kumpf          1.71     // lock the providerTable mutex
462                         AutoMutex lock(_providerTableMutex);
463 chip           1.1  
464 dmitry.mikulin 1.80     // Construct the lookup key. We need a compound key to differentiate
465                         // providers with the same name from different modules. The size field is
466                         // added to handle the unlikely case when moduleName+providerName
467                         // produce identical strings but define different providers.
468                         char buffer[12];
469                         sprintf(buffer, "%u:", providerName.size());
470                         const String key = buffer + moduleName + ":" + providerName;
471                     
472 kumpf          1.71     // look up provider in cache
473                         ProviderMessageHandler* pr = 0;
474 dmitry.mikulin 1.80     if (_providers.lookup(key, pr))
475 kumpf          1.71     {
476 chip           1.1          PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
477 kumpf          1.71             "Found Provider " + providerName + " in Provider Manager Cache");
478                         }
479                         else
480                         {
481                             // create provider
482                             pr = new ProviderMessageHandler(
483 dmitry.mikulin 1.81             moduleName, providerName, 
484                                 0, _indicationCallback, _responseChunkCallback,
485 kumpf          1.71             _subscriptionInitComplete);
486 chip           1.1  
487 kumpf          1.71         // insert provider in provider table
488 dmitry.mikulin 1.80         _providers.insert(key, pr);
489 marek          1.64 
490 kumpf          1.71         PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
491                                 "Created provider " + pr->getName());
492 chip           1.1      }
493                     
494                         PEG_METHOD_EXIT();
495 kumpf          1.71     return pr;
496 chip           1.1  }
497                     
498 kumpf          1.71 ProviderMessageHandler* DefaultProviderManager::_initProvider(
499                         ProviderMessageHandler* provider,
500                         const String& moduleFileName)
501 chip           1.1  {
502 kumpf          1.71     PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
503                             "DefaultProviderManager::_initProvider");
504 chip           1.1  
505 kumpf          1.71     ProviderModule* module = 0;
506                         CIMProvider* base;
507 chip           1.1  
508 kumpf          1.72     // lookup provider module
509                         module = _lookupModule(moduleFileName);
510 chip           1.1  
511 kumpf          1.72     // lock the provider status mutex
512                         AutoMutex lock(provider->status.getStatusMutex());
513 chip           1.1  
514 kumpf          1.72     if (provider->status.isInitialized())
515 kumpf          1.71     {
516 kumpf          1.72         // Initialization is already complete
517                             return provider;
518                         }
519 chip           1.1  
520 kumpf          1.72     PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
521                             "Loading/Linking Provider Module " + moduleFileName);
522 chip           1.1  
523 kumpf          1.72     // load the provider
524                         try
525                         {
526                             base = module->load(provider->getName());
527                         }
528                         catch (...)
529                         {
530 kumpf          1.71         PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
531 kumpf          1.72             "Exception caught Loading/Linking Provider Module " +
532                                 moduleFileName);
533                             PEG_METHOD_EXIT();
534                             throw;
535                         }
536 chip           1.1  
537 kumpf          1.72     // initialize the provider
538                         PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2,
539                             "Initializing Provider " + provider->getName());
540 chip           1.1  
541 kumpf          1.78     CIMOMHandle* cimomHandle = new CIMOMHandle();
542 kumpf          1.72     provider->status.setCIMOMHandle(cimomHandle);
543                         provider->status.setModule(module);
544                         provider->setProvider(base);
545 chip           1.1  
546 kumpf          1.72     Boolean initializeError = false;
547 chip           1.1  
548 kumpf          1.72     try
549                         {
550                             provider->initialize(*cimomHandle);
551                         }
552                         catch (...)
553                         {
554                             initializeError = true;
555                         }
556 chip           1.1  
557 kumpf          1.72     // The cleanup code executed when an exception occurs was previously
558                         // included in the catch block above. Unloading the provider module
559                         // from inside the catch block resulted in a crash when an exception
560                         // was thrown from a provider's initialize() method. The issue is that
561                         // when an exception is thrown, the program maintains internal
562                         // pointers related to the code that threw the exception. In the case
563                         // of an exception thrown from a provider during the initialize()
564                         // method, those pointers point into the provider library, so when
565                         // the DefaultProviderManager unloads the library, the pointers into
566                         // the library that the program was holding are invalid.
567 chip           1.1  
568 kumpf          1.72     if (initializeError == true)
569                         {
570 kumpf          1.76         // Allow the provider to clean up
571                             provider->terminate();
572                     
573 kumpf          1.72         // delete the cimom handle
574                             delete cimomHandle;
575 marek          1.64 
576 kumpf          1.72         provider->setProvider(0);
577 chip           1.1  
578 kumpf          1.72         // unload provider module
579                             module->unloadModule();
580                         }
581 chip           1.1  
582 kumpf          1.72     provider->status.setInitialized(!initializeError);
583 chip           1.1  
584                         PEG_METHOD_EXIT();
585 kumpf          1.71     return provider;
586 chip           1.1  }
587                     
588 kumpf          1.71 ProviderModule* DefaultProviderManager::_lookupModule(
589                         const String& moduleFileName)
590 chip           1.1  {
591 kumpf          1.71     PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
592                             "DefaultProviderManager::_lookupModule");
593 chip           1.1  
594 kumpf          1.72     // lock the providerTable mutex
595                         AutoMutex lock(_providerTableMutex);
596                     
597 kumpf          1.71     // look up provider module in cache
598                         ProviderModule* module = 0;
599 chip           1.1  
600 kumpf          1.71     if (_modules.lookup(moduleFileName, module))
601                         {
602                             // found provider module in cache
603                             PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
604                                 "Found Provider Module " + moduleFileName +
605                                 " in Provider Manager Cache");
606                         }
607                         else
608 chip           1.1      {
609 kumpf          1.71         // provider module not found in cache, create provider module
610 chip           1.1          PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
611 kumpf          1.71             "Creating Provider Module " + moduleFileName);
612 chip           1.1  
613 kumpf          1.71         module = new ProviderModule(moduleFileName);
614 marek          1.64 
615 kumpf          1.71         // insert provider module in module table
616                             _modules.insert(moduleFileName, module);
617 chip           1.1      }
618                     
619                         PEG_METHOD_EXIT();
620 kumpf          1.71     return module;
621 chip           1.1  }
622                     
623 kumpf          1.71 Boolean DefaultProviderManager::hasActiveProviders()
624 chip           1.1  {
625 kumpf          1.71     PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
626                             "DefaultProviderManager::hasActiveProviders");
627 schuur         1.12 
628                         try
629                         {
630 kumpf          1.71         AutoMutex lock(_providerTableMutex);
631 marek          1.79         PEG_TRACE((TRC_PROVIDERMANAGER, Tracer::LEVEL4,
632                                 "Number of providers in _providers table = %d", _providers.size()));
633 marek          1.64 
634 kumpf          1.71         // Iterate through the _providers table looking for an active provider
635                             for (ProviderTable::Iterator i = _providers.start(); i != 0; i++)
636                             {
637                                 if (i.value()->status.isInitialized())
638                                 {
639                                     PEG_METHOD_EXIT();
640                                     return true;
641                                 }
642                             }
643                         }
644                         catch (...)
645                         {
646                             // Unexpected exception; do not assume that no providers are loaded
647 marek          1.79         PEG_TRACE_CSTRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2,
648 kumpf          1.71             "Unexpected Exception in hasActiveProviders.");
649                             PEG_METHOD_EXIT();
650                             return true;
651 schuur         1.12     }
652 chip           1.1  
653 kumpf          1.71     // No active providers were found in the _providers table
654 chip           1.1      PEG_METHOD_EXIT();
655 kumpf          1.71     return false;
656 chip           1.1  }
657                     
658 kumpf          1.71 void DefaultProviderManager::unloadIdleProviders()
659 chip           1.1  {
660 kumpf          1.71     PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
661 kumpf          1.72         "DefaultProviderManager::unloadIdleProviders");
662 kumpf          1.71 
663 kumpf          1.75     try
664 kumpf          1.71     {
665 kumpf          1.75         struct timeval now;
666                             Time::gettimeofday(&now);
667 chip           1.1  
668 kumpf          1.72         // Make a copy of the table so it is not locked during provider calls
669                             Array<ProviderMessageHandler*> providerList;
670 kumpf          1.71         {
671 kumpf          1.72             AutoMutex lock(_providerTableMutex);
672 chip           1.2  
673 kumpf          1.72             for (ProviderTable::Iterator i = _providers.start(); i != 0; i++)
674 kumpf          1.71             {
675 kumpf          1.72                 providerList.append(i.value());
676 kumpf          1.71             }
677 kumpf          1.72         }
678 se.gupta       1.34 
679 kumpf          1.72         for (Uint32 i = 0; i < providerList.size(); i++)
680                             {
681                                 ProviderMessageHandler* provider = providerList[i];
682 marek          1.64 
683 kumpf          1.72             AutoMutex lock(provider->status.getStatusMutex());
684 kumpf          1.66 
685 kumpf          1.72             if (!provider->status.isInitialized())
686 kumpf          1.71             {
687                                     continue;
688                                 }
689 chip           1.1  
690 kumpf          1.72             struct timeval providerTime = {0, 0};
691                                 provider->status.getLastOperationEndTime(&providerTime);
692 kumpf          1.71 
693                                 PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
694 kumpf          1.72                 "provider->status.isIdle() returns: " +
695                                     CIMValue(provider->status.isIdle()).toString());
696 marek          1.64 
697 kumpf          1.72             if (provider->status.isIdle() &&
698                                     ((now.tv_sec - providerTime.tv_sec) > ((Sint32)IDLE_LIMIT)))
699 kumpf          1.71             {
700 kumpf          1.72                 PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2,
701                                         "Unloading idle provider: " + provider->getName());
702                                     _unloadProvider(provider);
703 kumpf          1.71             }
704                             }
705                         }
706                         catch (...)
707 chip           1.1      {
708 marek          1.79         PEG_TRACE_CSTRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2,
709 kumpf          1.71             "Caught unexpected exception in unloadIdleProviders.");
710 chip           1.1      }
711                     
712                         PEG_METHOD_EXIT();
713                     }
714                     
715 kumpf          1.71 void DefaultProviderManager::_shutdownAllProviders()
716 chip           1.1  {
717 kumpf          1.71     PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
718                             "DefaultProviderManager::_shutdownAllProviders");
719 chip           1.1  
720                         try
721                         {
722 kumpf          1.71         AutoMutex lock(_providerTableMutex);
723 schuur         1.19 
724 marek          1.79         PEG_TRACE((TRC_PROVIDERMANAGER, Tracer::LEVEL4,
725                                 "providers in cache = %d", _providers.size()));
726 chip           1.2  
727 kumpf          1.71         for (ProviderTable::Iterator i = _providers.start(); i != 0; i++)
728                             {
729                                 ProviderMessageHandler* provider = i.value();
730                                 PEGASUS_ASSERT(provider != 0);
731 chip           1.2  
732 kumpf          1.72             AutoMutex lock(provider->status.getStatusMutex());
733                     
734 kumpf          1.71             if (provider->status.isInitialized())
735                                 {
736                                     _unloadProvider(provider);
737                                 }
738                             }
739                         }
740                         catch (...)
741                         {
742 marek          1.79         PEG_TRACE_CSTRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
743 kumpf          1.71             "Unexpected Exception in _shutdownAllProviders().");
744 chip           1.1      }
745                     
746                         PEG_METHOD_EXIT();
747                     }
748                     
749 dmitry.mikulin 1.80 Sint16 DefaultProviderManager::_disableProvider(
750                         const String& moduleName,
751                         const String& providerName)
752 chip           1.1  {
753 kumpf          1.71     PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
754                             "DefaultProviderManager::_disableProvider");
755 chip           1.1  
756 dmitry.mikulin 1.80     ProviderMessageHandler* pr = _lookupProvider(moduleName, providerName);
757 kumpf          1.71     if (!pr->status.isInitialized())
758                         {
759                             PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2,
760                                 "Provider " + providerName + " is not loaded");
761                             PEG_METHOD_EXIT();
762                             return 1;
763                         }
764 chip           1.1  
765 kumpf          1.71     PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
766                             "Disable Provider " + pr->getName());
767                         //
768                         // Check to see if there are pending requests. If there are pending
769                         // requests and the disable timeout has not expired, loop and wait one
770                         // second until either there is no pending requests or until timeout
771                         // expires.
772                         //
773                         Uint32 waitTime = PROVIDER_DISABLE_TIMEOUT;
774 kumpf          1.72     while ((pr->status.numCurrentOperations() > 0) && (waitTime > 0))
775 kumpf          1.71     {
776                             Threads::sleep(1000);
777                             waitTime = waitTime - 1;
778                         }
779 chip           1.1  
780 kumpf          1.71     // There are still pending requests, do not disable
781 kumpf          1.72     if (pr->status.numCurrentOperations() > 0)
782 kumpf          1.71     {
783 marek          1.79         PEG_TRACE_CSTRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
784 kumpf          1.71             "Disable failed since there are pending requests.");
785                             PEG_METHOD_EXIT();
786                             return 0;
787                         }
788 chip           1.1  
789                         try
790                         {
791 kumpf          1.72         AutoMutex lock(pr->status.getStatusMutex());
792 chip           1.1  
793 kumpf          1.71         if (pr->status.isInitialized())
794                             {
795                                 PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
796                                     "Unloading Provider " + pr->getName());
797                                 _unloadProvider(pr);
798                             }
799                         }
800                         catch (...)
801                         {
802 chip           1.2          PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
803 kumpf          1.71             "Unload provider failed " + pr->getName());
804                             PEG_METHOD_EXIT();
805                             return -1;
806 chip           1.1      }
807                     
808                         PEG_METHOD_EXIT();
809 kumpf          1.71     return 1;
810 chip           1.1  }
811                     
812 kumpf          1.71 void DefaultProviderManager::_unloadProvider(ProviderMessageHandler* provider)
813 chip           1.1  {
814 kumpf          1.71     //
815 kumpf          1.72     // NOTE:  It is the caller's responsibility to make sure that the
816                         // provider->status.getStatusMutex() mutex is locked before calling
817                         // this method.
818 kumpf          1.71     //
819 kumpf          1.72 
820 kumpf          1.71     PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
821                             "DefaultProviderManager::_unloadProvider");
822 chip           1.1  
823 kumpf          1.72     if (provider->status.numCurrentOperations() > 0)
824 chip           1.1      {
825                             PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
826 kumpf          1.71             "Provider cannot be unloaded due to pending operations: " +
827                                 provider->getName());
828 chip           1.1      }
829 kumpf          1.71     else
830 chip           1.1      {
831 kumpf          1.71         PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
832                                 "Terminating Provider " + provider->getName());
833 chip           1.1  
834 kumpf          1.72         provider->terminate();
835 chip           1.1  
836 kumpf          1.72         // unload provider module
837                             PEGASUS_ASSERT(provider->status.getModule() != 0);
838                             PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2,
839                                 "Unloading provider module: " + provider->getName());
840                             provider->status.getModule()->unloadModule();
841 chip           1.1  
842 kumpf          1.72         Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::TRACE,
843                                 "DefaultProviderManager:  Unloaded provider $0",
844                                 provider->getName());
845 kumpf          1.71 
846 kumpf          1.72         // NOTE: The "delete provider->status.getCIMOMHandle()" operation
847                             //   was moved to be called after the unloadModule() call above
848 kumpf          1.71         //   as part of a fix for bugzilla 3669. For some providers
849                             //   run out-of-process on Windows platforms (i.e. running
850                             //   the cimserver with the forceProviderProcesses config option
851                             //   set to "true"), deleting the provider's CIMOMHandle before
852                             //   unloading the provider library caused the unload mechanism
853                             //   to deadlock, making that provider unavailable and preventing
854                             //   the cimserver from shutting down. It should NOT be moved back
855                             //   above the unloadModule() call. See bugzilla 3669 for details.
856 kumpf          1.72 
857 kumpf          1.71         // delete the cimom handle
858 chip           1.1          PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
859 kumpf          1.72             "Destroying provider's CIMOMHandle: " + provider->getName());
860                             delete provider->status.getCIMOMHandle();
861 marek          1.64 
862 kumpf          1.71         // set provider status to uninitialized
863 kumpf          1.72         provider->status.setInitialized(false);
864 chip           1.1      }
865                     
866                         PEG_METHOD_EXIT();
867 carolann.graves 1.49 }
868                      
869 mike            1.63 ProviderManager* DefaultProviderManager::createDefaultProviderManagerCallback()
870                      {
871                          return new DefaultProviderManager();
872                      }
873                      
874 kumpf           1.26 PEGASUS_NAMESPACE_END
875 kumpf           1.74 
876                      PEGASUS_USING_PEGASUS;
877                      
878                      // This entry point is not needed because the DefaultProviderManager is created
879                      // using DefaultProviderManager::createDefaultProviderManagerCallback().
880                      #if 0
881                      extern "C" PEGASUS_EXPORT ProviderManager* PegasusCreateProviderManager(
882                          const String& providerManagerName)
883                      {
884                          if (String::equalNoCase(providerManagerName, "Default"))
885                          {
886                              return new DefaultProviderManager();
887                          }
888                      
889                          return 0;
890                      }
891                      #endif

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2