(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                                 providerName, 0, _indicationCallback, _responseChunkCallback,
484                                 _subscriptionInitComplete);
485 chip           1.1  
486 kumpf          1.71         // insert provider in provider table
487 dmitry.mikulin 1.80         _providers.insert(key, pr);
488 marek          1.64 
489 kumpf          1.71         PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
490                                 "Created provider " + pr->getName());
491 chip           1.1      }
492                     
493                         PEG_METHOD_EXIT();
494 kumpf          1.71     return pr;
495 chip           1.1  }
496                     
497 kumpf          1.71 ProviderMessageHandler* DefaultProviderManager::_initProvider(
498                         ProviderMessageHandler* provider,
499                         const String& moduleFileName)
500 chip           1.1  {
501 kumpf          1.71     PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
502                             "DefaultProviderManager::_initProvider");
503 chip           1.1  
504 kumpf          1.71     ProviderModule* module = 0;
505                         CIMProvider* base;
506 chip           1.1  
507 kumpf          1.72     // lookup provider module
508                         module = _lookupModule(moduleFileName);
509 chip           1.1  
510 kumpf          1.72     // lock the provider status mutex
511                         AutoMutex lock(provider->status.getStatusMutex());
512 chip           1.1  
513 kumpf          1.72     if (provider->status.isInitialized())
514 kumpf          1.71     {
515 kumpf          1.72         // Initialization is already complete
516                             return provider;
517                         }
518 chip           1.1  
519 kumpf          1.72     PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
520                             "Loading/Linking Provider Module " + moduleFileName);
521 chip           1.1  
522 kumpf          1.72     // load the provider
523                         try
524                         {
525                             base = module->load(provider->getName());
526                         }
527                         catch (...)
528                         {
529 kumpf          1.71         PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
530 kumpf          1.72             "Exception caught Loading/Linking Provider Module " +
531                                 moduleFileName);
532                             PEG_METHOD_EXIT();
533                             throw;
534                         }
535 chip           1.1  
536 kumpf          1.72     // initialize the provider
537                         PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2,
538                             "Initializing Provider " + provider->getName());
539 chip           1.1  
540 kumpf          1.78     CIMOMHandle* cimomHandle = new CIMOMHandle();
541 kumpf          1.72     provider->status.setCIMOMHandle(cimomHandle);
542                         provider->status.setModule(module);
543                         provider->setProvider(base);
544 chip           1.1  
545 kumpf          1.72     Boolean initializeError = false;
546 chip           1.1  
547 kumpf          1.72     try
548                         {
549                             provider->initialize(*cimomHandle);
550                         }
551                         catch (...)
552                         {
553                             initializeError = true;
554                         }
555 chip           1.1  
556 kumpf          1.72     // The cleanup code executed when an exception occurs was previously
557                         // included in the catch block above. Unloading the provider module
558                         // from inside the catch block resulted in a crash when an exception
559                         // was thrown from a provider's initialize() method. The issue is that
560                         // when an exception is thrown, the program maintains internal
561                         // pointers related to the code that threw the exception. In the case
562                         // of an exception thrown from a provider during the initialize()
563                         // method, those pointers point into the provider library, so when
564                         // the DefaultProviderManager unloads the library, the pointers into
565                         // the library that the program was holding are invalid.
566 chip           1.1  
567 kumpf          1.72     if (initializeError == true)
568                         {
569 kumpf          1.76         // Allow the provider to clean up
570                             provider->terminate();
571                     
572 kumpf          1.72         // delete the cimom handle
573                             delete cimomHandle;
574 marek          1.64 
575 kumpf          1.72         provider->setProvider(0);
576 chip           1.1  
577 kumpf          1.72         // unload provider module
578                             module->unloadModule();
579                         }
580 chip           1.1  
581 kumpf          1.72     provider->status.setInitialized(!initializeError);
582 chip           1.1  
583                         PEG_METHOD_EXIT();
584 kumpf          1.71     return provider;
585 chip           1.1  }
586                     
587 kumpf          1.71 ProviderModule* DefaultProviderManager::_lookupModule(
588                         const String& moduleFileName)
589 chip           1.1  {
590 kumpf          1.71     PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
591                             "DefaultProviderManager::_lookupModule");
592 chip           1.1  
593 kumpf          1.72     // lock the providerTable mutex
594                         AutoMutex lock(_providerTableMutex);
595                     
596 kumpf          1.71     // look up provider module in cache
597                         ProviderModule* module = 0;
598 chip           1.1  
599 kumpf          1.71     if (_modules.lookup(moduleFileName, module))
600                         {
601                             // found provider module in cache
602                             PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
603                                 "Found Provider Module " + moduleFileName +
604                                 " in Provider Manager Cache");
605                         }
606                         else
607 chip           1.1      {
608 kumpf          1.71         // provider module not found in cache, create provider module
609 chip           1.1          PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
610 kumpf          1.71             "Creating Provider Module " + moduleFileName);
611 chip           1.1  
612 kumpf          1.71         module = new ProviderModule(moduleFileName);
613 marek          1.64 
614 kumpf          1.71         // insert provider module in module table
615                             _modules.insert(moduleFileName, module);
616 chip           1.1      }
617                     
618                         PEG_METHOD_EXIT();
619 kumpf          1.71     return module;
620 chip           1.1  }
621                     
622 kumpf          1.71 Boolean DefaultProviderManager::hasActiveProviders()
623 chip           1.1  {
624 kumpf          1.71     PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
625                             "DefaultProviderManager::hasActiveProviders");
626 schuur         1.12 
627                         try
628                         {
629 kumpf          1.71         AutoMutex lock(_providerTableMutex);
630 marek          1.79         PEG_TRACE((TRC_PROVIDERMANAGER, Tracer::LEVEL4,
631                                 "Number of providers in _providers table = %d", _providers.size()));
632 marek          1.64 
633 kumpf          1.71         // Iterate through the _providers table looking for an active provider
634                             for (ProviderTable::Iterator i = _providers.start(); i != 0; i++)
635                             {
636                                 if (i.value()->status.isInitialized())
637                                 {
638                                     PEG_METHOD_EXIT();
639                                     return true;
640                                 }
641                             }
642                         }
643                         catch (...)
644                         {
645                             // Unexpected exception; do not assume that no providers are loaded
646 marek          1.79         PEG_TRACE_CSTRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2,
647 kumpf          1.71             "Unexpected Exception in hasActiveProviders.");
648                             PEG_METHOD_EXIT();
649                             return true;
650 schuur         1.12     }
651 chip           1.1  
652 kumpf          1.71     // No active providers were found in the _providers table
653 chip           1.1      PEG_METHOD_EXIT();
654 kumpf          1.71     return false;
655 chip           1.1  }
656                     
657 kumpf          1.71 void DefaultProviderManager::unloadIdleProviders()
658 chip           1.1  {
659 kumpf          1.71     PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
660 kumpf          1.72         "DefaultProviderManager::unloadIdleProviders");
661 kumpf          1.71 
662 kumpf          1.75     try
663 kumpf          1.71     {
664 kumpf          1.75         struct timeval now;
665                             Time::gettimeofday(&now);
666 chip           1.1  
667 kumpf          1.72         // Make a copy of the table so it is not locked during provider calls
668                             Array<ProviderMessageHandler*> providerList;
669 kumpf          1.71         {
670 kumpf          1.72             AutoMutex lock(_providerTableMutex);
671 chip           1.2  
672 kumpf          1.72             for (ProviderTable::Iterator i = _providers.start(); i != 0; i++)
673 kumpf          1.71             {
674 kumpf          1.72                 providerList.append(i.value());
675 kumpf          1.71             }
676 kumpf          1.72         }
677 se.gupta       1.34 
678 kumpf          1.72         for (Uint32 i = 0; i < providerList.size(); i++)
679                             {
680                                 ProviderMessageHandler* provider = providerList[i];
681 marek          1.64 
682 kumpf          1.72             AutoMutex lock(provider->status.getStatusMutex());
683 kumpf          1.66 
684 kumpf          1.72             if (!provider->status.isInitialized())
685 kumpf          1.71             {
686                                     continue;
687                                 }
688 chip           1.1  
689 kumpf          1.72             struct timeval providerTime = {0, 0};
690                                 provider->status.getLastOperationEndTime(&providerTime);
691 kumpf          1.71 
692                                 PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
693 kumpf          1.72                 "provider->status.isIdle() returns: " +
694                                     CIMValue(provider->status.isIdle()).toString());
695 marek          1.64 
696 kumpf          1.72             if (provider->status.isIdle() &&
697                                     ((now.tv_sec - providerTime.tv_sec) > ((Sint32)IDLE_LIMIT)))
698 kumpf          1.71             {
699 kumpf          1.72                 PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2,
700                                         "Unloading idle provider: " + provider->getName());
701                                     _unloadProvider(provider);
702 kumpf          1.71             }
703                             }
704                         }
705                         catch (...)
706 chip           1.1      {
707 marek          1.79         PEG_TRACE_CSTRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2,
708 kumpf          1.71             "Caught unexpected exception in unloadIdleProviders.");
709 chip           1.1      }
710                     
711                         PEG_METHOD_EXIT();
712                     }
713                     
714 kumpf          1.71 void DefaultProviderManager::_shutdownAllProviders()
715 chip           1.1  {
716 kumpf          1.71     PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
717                             "DefaultProviderManager::_shutdownAllProviders");
718 chip           1.1  
719                         try
720                         {
721 kumpf          1.71         AutoMutex lock(_providerTableMutex);
722 schuur         1.19 
723 marek          1.79         PEG_TRACE((TRC_PROVIDERMANAGER, Tracer::LEVEL4,
724                                 "providers in cache = %d", _providers.size()));
725 chip           1.2  
726 kumpf          1.71         for (ProviderTable::Iterator i = _providers.start(); i != 0; i++)
727                             {
728                                 ProviderMessageHandler* provider = i.value();
729                                 PEGASUS_ASSERT(provider != 0);
730 chip           1.2  
731 kumpf          1.72             AutoMutex lock(provider->status.getStatusMutex());
732                     
733 kumpf          1.71             if (provider->status.isInitialized())
734                                 {
735                                     _unloadProvider(provider);
736                                 }
737                             }
738                         }
739                         catch (...)
740                         {
741 marek          1.79         PEG_TRACE_CSTRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
742 kumpf          1.71             "Unexpected Exception in _shutdownAllProviders().");
743 chip           1.1      }
744                     
745                         PEG_METHOD_EXIT();
746                     }
747                     
748 dmitry.mikulin 1.80 Sint16 DefaultProviderManager::_disableProvider(
749                         const String& moduleName,
750                         const String& providerName)
751 chip           1.1  {
752 kumpf          1.71     PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
753                             "DefaultProviderManager::_disableProvider");
754 chip           1.1  
755 dmitry.mikulin 1.80     ProviderMessageHandler* pr = _lookupProvider(moduleName, providerName);
756 kumpf          1.71     if (!pr->status.isInitialized())
757                         {
758                             PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2,
759                                 "Provider " + providerName + " is not loaded");
760                             PEG_METHOD_EXIT();
761                             return 1;
762                         }
763 chip           1.1  
764 kumpf          1.71     PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
765                             "Disable Provider " + pr->getName());
766                         //
767                         // Check to see if there are pending requests. If there are pending
768                         // requests and the disable timeout has not expired, loop and wait one
769                         // second until either there is no pending requests or until timeout
770                         // expires.
771                         //
772                         Uint32 waitTime = PROVIDER_DISABLE_TIMEOUT;
773 kumpf          1.72     while ((pr->status.numCurrentOperations() > 0) && (waitTime > 0))
774 kumpf          1.71     {
775                             Threads::sleep(1000);
776                             waitTime = waitTime - 1;
777                         }
778 chip           1.1  
779 kumpf          1.71     // There are still pending requests, do not disable
780 kumpf          1.72     if (pr->status.numCurrentOperations() > 0)
781 kumpf          1.71     {
782 marek          1.79         PEG_TRACE_CSTRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
783 kumpf          1.71             "Disable failed since there are pending requests.");
784                             PEG_METHOD_EXIT();
785                             return 0;
786                         }
787 chip           1.1  
788                         try
789                         {
790 kumpf          1.72         AutoMutex lock(pr->status.getStatusMutex());
791 chip           1.1  
792 kumpf          1.71         if (pr->status.isInitialized())
793                             {
794                                 PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
795                                     "Unloading Provider " + pr->getName());
796                                 _unloadProvider(pr);
797                             }
798                         }
799                         catch (...)
800                         {
801 chip           1.2          PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
802 kumpf          1.71             "Unload provider failed " + pr->getName());
803                             PEG_METHOD_EXIT();
804                             return -1;
805 chip           1.1      }
806                     
807                         PEG_METHOD_EXIT();
808 kumpf          1.71     return 1;
809 chip           1.1  }
810                     
811 kumpf          1.71 void DefaultProviderManager::_unloadProvider(ProviderMessageHandler* provider)
812 chip           1.1  {
813 kumpf          1.71     //
814 kumpf          1.72     // NOTE:  It is the caller's responsibility to make sure that the
815                         // provider->status.getStatusMutex() mutex is locked before calling
816                         // this method.
817 kumpf          1.71     //
818 kumpf          1.72 
819 kumpf          1.71     PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
820                             "DefaultProviderManager::_unloadProvider");
821 chip           1.1  
822 kumpf          1.72     if (provider->status.numCurrentOperations() > 0)
823 chip           1.1      {
824                             PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
825 kumpf          1.71             "Provider cannot be unloaded due to pending operations: " +
826                                 provider->getName());
827 chip           1.1      }
828 kumpf          1.71     else
829 chip           1.1      {
830 kumpf          1.71         PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
831                                 "Terminating Provider " + provider->getName());
832 chip           1.1  
833 kumpf          1.72         provider->terminate();
834 chip           1.1  
835 kumpf          1.72         // unload provider module
836                             PEGASUS_ASSERT(provider->status.getModule() != 0);
837                             PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2,
838                                 "Unloading provider module: " + provider->getName());
839                             provider->status.getModule()->unloadModule();
840 chip           1.1  
841 kumpf          1.72         Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::TRACE,
842                                 "DefaultProviderManager:  Unloaded provider $0",
843                                 provider->getName());
844 kumpf          1.71 
845 kumpf          1.72         // NOTE: The "delete provider->status.getCIMOMHandle()" operation
846                             //   was moved to be called after the unloadModule() call above
847 kumpf          1.71         //   as part of a fix for bugzilla 3669. For some providers
848                             //   run out-of-process on Windows platforms (i.e. running
849                             //   the cimserver with the forceProviderProcesses config option
850                             //   set to "true"), deleting the provider's CIMOMHandle before
851                             //   unloading the provider library caused the unload mechanism
852                             //   to deadlock, making that provider unavailable and preventing
853                             //   the cimserver from shutting down. It should NOT be moved back
854                             //   above the unloadModule() call. See bugzilla 3669 for details.
855 kumpf          1.72 
856 kumpf          1.71         // delete the cimom handle
857 chip           1.1          PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
858 kumpf          1.72             "Destroying provider's CIMOMHandle: " + provider->getName());
859                             delete provider->status.getCIMOMHandle();
860 marek          1.64 
861 kumpf          1.71         // set provider status to uninitialized
862 kumpf          1.72         provider->status.setInitialized(false);
863 chip           1.1      }
864                     
865                         PEG_METHOD_EXIT();
866 carolann.graves 1.49 }
867                      
868 mike            1.63 ProviderManager* DefaultProviderManager::createDefaultProviderManagerCallback()
869                      {
870                          return new DefaultProviderManager();
871                      }
872                      
873 kumpf           1.26 PEGASUS_NAMESPACE_END
874 kumpf           1.74 
875                      PEGASUS_USING_PEGASUS;
876                      
877                      // This entry point is not needed because the DefaultProviderManager is created
878                      // using DefaultProviderManager::createDefaultProviderManagerCallback().
879                      #if 0
880                      extern "C" PEGASUS_EXPORT ProviderManager* PegasusCreateProviderManager(
881                          const String& providerManagerName)
882                      {
883                          if (String::equalNoCase(providerManagerName, "Default"))
884                          {
885                              return new DefaultProviderManager();
886                          }
887                      
888                          return 0;
889                      }
890                      #endif

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2