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