1 kumpf 1.1 //%/////////////////////////////////////////////////////////////////////////////
2 //
|
3 kumpf 1.22 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
|
5 kumpf 1.1 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to
8 // deal in the Software without restriction, including without limitation the
9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
|
12 chip 1.24 //
|
13 kumpf 1.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
14 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
15 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
16 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 //==============================================================================
23 //
24 // Author: Yi Zhou (yi_zhou@hp.com)
25 //
26 // Modified By: Chip Vincent (cvincent@us.ibm.com)
27 // Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
28 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
|
29 kumpf 1.20 // Carol Ann Krug Graves, Hewlett-Packard Company
30 // (carolann_graves@hp.com)
|
31 kumpf 1.1 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
|
34 kumpf 1.5 #include "ProviderRegistrationProvider.h"
35
|
36 kumpf 1.4 #include <Pegasus/Common/PegasusVersion.h>
|
37 kumpf 1.5 #include <Pegasus/Common/XmlWriter.h>
|
38 kumpf 1.6 #include <Pegasus/Common/Constants.h>
39 #include <Pegasus/Common/CIMMessage.h>
|
40 kumpf 1.15 #include <Pegasus/Common/OperationContext.h>
41 #include <Pegasus/Common/System.h>
|
42 kumpf 1.1
43 PEGASUS_NAMESPACE_BEGIN
44
45 /**
46 The name of the operational status property
47 */
48 static const char _PROPERTY_OPERATIONALSTATUS [] = "OperationalStatus";
49
50 /**
51 The name of the name property for PG_Provider class
52 */
53 static const char _PROPERTY_PROVIDER_NAME [] = "Name";
54
55 /**
56 The name of the Name property for PG_ProviderModule class
57 */
58 static const char _PROPERTY_PROVIDERMODULE_NAME [] = "Name";
59
60 /**
|
61 kumpf 1.12 The name of the Vendor property for PG_ProviderModule class
62 */
63 static const char _PROPERTY_VENDOR [] = "Vendor";
64
65 /**
|
66 kumpf 1.1 The name of the Version property for PG_ProviderModule class
67 */
68 static const char _PROPERTY_VERSION [] = "Version";
69
70 /**
71 The name of the interface type property for PG_ProviderModule class
72 */
73 static const char _PROPERTY_INTERFACETYPE [] = "InterfaceType";
74
75 /**
76 The name of the interface version property for PG_ProviderModule class
77 */
78 static const char _PROPERTY_INTERFACEVERSION [] = "InterfaceVersion";
79
80 /**
81 The name of the location property for PG_ProviderModule class
82 */
83 static const char _PROPERTY_LOCATION [] = "Location";
84
85 /**
86 The name of the CapabilityID property for provider capabilities class
87 kumpf 1.1 */
88 static const char _PROPERTY_CAPABILITYID [] = "CapabilityID";
89
90 /**
91 The name of the provider module name property for provider capabilities class
92 */
93 static const char _PROPERTY_PROVIDERMODULENAME [] = "ProviderModuleName";
94
95 /**
96 The name of the provider name property for provider capabilities class
97 */
98 static const char _PROPERTY_PROVIDERNAME [] = "ProviderName";
99
100 /**
101 The name of the classname property for provider capabilities class
102 */
103 static const char _PROPERTY_CLASSNAME [] = "ClassName";
104
105 /**
106 The name of the Namespace property for provider capabilities class
107 */
108 kumpf 1.1 static const char _PROPERTY_NAMESPACES [] = "Namespaces";
109
110 /**
111 The name of the provider type property for provider capabilities class
112 */
113 static const char _PROPERTY_PROVIDERTYPE [] = "ProviderType";
114
115 /**
116 The name of the supported properties property for provider capabilities class
117 */
118 static const char _PROPERTY_SUPPORTEDPROPERTIES [] = "SupportedProperties";
119
120 /**
121 The name of the supported methods property for provider capabilities class
122 */
123 static const char _PROPERTY_SUPPORTEDMETHODS [] = "SupportedMethods";
124
125 /**
126 Registered instance provider type
127 */
128 static const Uint16 _INSTANCE_PROVIDER = 2;
129 kumpf 1.1
130 /**
131 Registered association provider type
132 */
133 static const Uint16 _ASSOCIATION_PROVIDER = 3;
134
135 /**
136 Registered indication provider type
137 */
138 static const Uint16 _INDICATION_PROVIDER = 4;
139
140 /**
141 Registered method provider type
142 */
143 static const Uint16 _METHOD_PROVIDER = 5;
144
145 /**
146 stopping provider method
147 */
148 static const char _STOP_PROVIDER[] = "Stop";
149
150 kumpf 1.1 /**
151 starting provider method
152 */
153 static const char _START_PROVIDER[] = "Start";
154
155 /**
156 Provider status
157 */
|
158 kumpf 1.14 static const Uint16 _MODULE_OK = 2;
|
159 kumpf 1.10
|
160 kumpf 1.14 static const Uint16 _MODULE_STOPPING = 9;
|
161 kumpf 1.1
|
162 kumpf 1.10 static const Uint16 _MODULE_STOPPED = 10;
|
163 kumpf 1.1
164 ProviderRegistrationProvider::ProviderRegistrationProvider(
165 ProviderRegistrationManager * providerRegistrationManager)
|
166 kumpf 1.6 :_id(peg_credential_types::PROVIDER)
|
167 kumpf 1.1 {
168 _providerRegistrationManager = providerRegistrationManager;
|
169 kumpf 1.6
170 _controller = &(ModuleController::get_client_handle(_id, &_client_handle));
171 if(_client_handle == NULL)
|
172 kumpf 1.9 ThrowUninitializedHandle();
|
173 kumpf 1.1 }
174
175 ProviderRegistrationProvider::~ProviderRegistrationProvider(void)
176 {
|
177 kumpf 1.6 if (_providerRegistrationManager)
178 {
179 delete _providerRegistrationManager;
180 }
181
182 if (_client_handle)
183 {
184 delete _client_handle;
185 }
186
|
187 kumpf 1.1 }
188
189 void ProviderRegistrationProvider::initialize(CIMOMHandle & cimom)
190 {
191 // This method should not be called because this is a control provider
192 // and is not dynamically loaded through the provider manager
193 }
194
195 void ProviderRegistrationProvider::terminate(void)
196 {
197 }
198
199 // get registered provider
200 void ProviderRegistrationProvider::getInstance(
201 const OperationContext & context,
|
202 kumpf 1.13 const CIMObjectPath & instanceReference,
|
203 kumpf 1.1 const Uint32 flags,
|
204 kumpf 1.2 const CIMPropertyList & propertyList,
|
205 kumpf 1.1 ResponseHandler<CIMInstance> & handler)
206 {
207
|
208 chip 1.24 if(!String::equalNoCase(instanceReference.getNameSpace(),
|
209 kumpf 1.10 PEGASUS_NAMESPACENAME_INTEROP))
210 {
|
211 kumpf 1.12 throw CIMException (CIM_ERR_NOT_SUPPORTED, instanceReference.getNameSpace());
|
212 kumpf 1.10 }
213
|
214 kumpf 1.1 // ensure the class existing in the specified namespace
215 String className = instanceReference.getClassName();
216
|
217 kumpf 1.10 if(!String::equalNoCase(className, PEGASUS_CLASSNAME_PROVIDER) &&
218 !String::equalNoCase(className, PEGASUS_CLASSNAME_PROVIDERCAPABILITIES) &&
219 !String::equalNoCase(className, PEGASUS_CLASSNAME_PROVIDERMODULE))
|
220 kumpf 1.1 {
|
221 kumpf 1.12 throw CIMException(CIM_ERR_NOT_SUPPORTED, className);
|
222 kumpf 1.1 }
223
224 // begin processing the request
225 handler.processing();
226
227 CIMInstance instance;
228
229 try
230 {
231 instance = _providerRegistrationManager->getInstance(instanceReference);
232 }
233 catch(CIMException& e)
234 {
|
235 kumpf 1.23 throw CIMException(CIM_ERR_FAILED, e.getMessage());
|
236 kumpf 1.1 }
237
238 handler.deliver(instance);
239
240 // complete processing the request
241 handler.complete();
242 }
243
244 // get all registered providers
245 void ProviderRegistrationProvider::enumerateInstances(
246 const OperationContext & context,
|
247 kumpf 1.13 const CIMObjectPath & classReference,
|
248 kumpf 1.1 const Uint32 flags,
|
249 kumpf 1.2 const CIMPropertyList & propertyList,
|
250 kumpf 1.1 ResponseHandler<CIMInstance> & handler)
251 {
|
252 chip 1.24 if(!String::equalNoCase(classReference.getNameSpace(),
|
253 kumpf 1.10 PEGASUS_NAMESPACENAME_INTEROP))
254 {
|
255 kumpf 1.12 throw CIMException (CIM_ERR_NOT_SUPPORTED, classReference.getNameSpace());
|
256 kumpf 1.10 }
257
|
258 kumpf 1.1 // ensure the class existing in the specified namespace
259 String className = classReference.getClassName();
260
|
261 kumpf 1.10 if(!String::equalNoCase(className, PEGASUS_CLASSNAME_PROVIDER) &&
262 !String::equalNoCase(className, PEGASUS_CLASSNAME_PROVIDERCAPABILITIES) &&
263 !String::equalNoCase(className, PEGASUS_CLASSNAME_PROVIDERMODULE))
|
264 kumpf 1.1 {
|
265 kumpf 1.12 throw CIMException(CIM_ERR_NOT_SUPPORTED, className);
|
266 kumpf 1.1 }
267
268 // begin processing the request
269 handler.processing();
270
|
271 kumpf 1.20 Array<CIMInstance> enumInstances;
|
272 kumpf 1.1
273 try
274 {
275 enumInstances = _providerRegistrationManager->enumerateInstances(classReference);
276 }
277 catch(CIMException& e)
278 {
|
279 kumpf 1.23 throw CIMException(CIM_ERR_FAILED, e.getMessage());
|
280 kumpf 1.1 }
281
|
282 kumpf 1.21 handler.deliver(enumInstances);
|
283 kumpf 1.1
284 // complete processing the request
285 handler.complete();
286 }
287
288 // get all registered provider names
289 void ProviderRegistrationProvider::enumerateInstanceNames(
290 const OperationContext & context,
|
291 kumpf 1.13 const CIMObjectPath & classReference,
292 ResponseHandler<CIMObjectPath> & handler)
|
293 kumpf 1.1 {
|
294 chip 1.24 if(!String::equalNoCase(classReference.getNameSpace(),
|
295 kumpf 1.10 PEGASUS_NAMESPACENAME_INTEROP))
296 {
|
297 kumpf 1.12 throw CIMException (CIM_ERR_NOT_SUPPORTED, classReference.getNameSpace());
|
298 kumpf 1.10 }
299
|
300 kumpf 1.1 // ensure the class existing in the specified namespace
301 String className = classReference.getClassName();
302
|
303 kumpf 1.10 if(!String::equalNoCase(className, PEGASUS_CLASSNAME_PROVIDER) &&
304 !String::equalNoCase(className, PEGASUS_CLASSNAME_PROVIDERCAPABILITIES) &&
305 !String::equalNoCase(className, PEGASUS_CLASSNAME_PROVIDERMODULE))
|
306 kumpf 1.1 {
|
307 kumpf 1.12 throw CIMException(CIM_ERR_NOT_SUPPORTED, className);
|
308 kumpf 1.1 }
309
310 // begin processing the request
311 handler.processing();
312
|
313 kumpf 1.13 Array<CIMObjectPath> enumInstanceNames;
|
314 kumpf 1.1
315 // get all instance names from repository
316 try
317 {
318 enumInstanceNames =
319 _providerRegistrationManager->enumerateInstanceNames(classReference);
320 }
321 catch(CIMException& e)
322 {
|
323 kumpf 1.23 throw CIMException(CIM_ERR_FAILED, e.getMessage());
|
324 kumpf 1.1 }
325
326 handler.deliver(enumInstanceNames);
327
328 // complete processing the request
329 handler.complete();
330 }
331
332 // change properties for the registered provider
|
333 chip 1.24 // only support to change property of Namespaces, property of
|
334 kumpf 1.1 // SupportedProperties, and property of SupportedMethods
335 void ProviderRegistrationProvider::modifyInstance(
|
336 kumpf 1.15 const OperationContext & context,
|
337 kumpf 1.13 const CIMObjectPath & instanceReference,
|
338 kumpf 1.1 const CIMInstance & instanceObject,
339 const Uint32 flags,
|
340 kumpf 1.2 const CIMPropertyList & propertyList,
|
341 chip 1.24 ResponseHandler<void> & handler)
|
342 kumpf 1.1 {
|
343 kumpf 1.15 // get userName and only privileged user can execute this operation
|
344 kumpf 1.19 String userName;
345 try
346 {
347 IdentityContainer container = context.get(CONTEXT_IDENTITY);
348 userName = container.getUserName();
349 }
350 catch (...)
351 {
352 userName = String::EMPTY;
353 }
|
354 kumpf 1.15
|
355 chip 1.24 if ((userName != String::EMPTY) && !System::isPrivilegedUser(userName))
|
356 kumpf 1.15 {
357 throw CIMException (CIM_ERR_ACCESS_DENIED,
358 "You must have superuser privilege to modify the registration.");
359 }
360
|
361 chip 1.24 if(!String::equalNoCase(instanceReference.getNameSpace(),
|
362 kumpf 1.10 PEGASUS_NAMESPACENAME_INTEROP))
363 {
|
364 kumpf 1.12 throw CIMException (CIM_ERR_NOT_SUPPORTED, instanceReference.getNameSpace());
|
365 kumpf 1.10 }
366
|
367 kumpf 1.1 //
368 // only support to modify the instance of PG_ProviderCapabilities
369 //
|
370 chip 1.24 if (!String::equalNoCase(instanceReference.getClassName(),
|
371 kumpf 1.10 PEGASUS_CLASSNAME_PROVIDERCAPABILITIES))
|
372 kumpf 1.1 {
|
373 kumpf 1.12 throw CIMException (CIM_ERR_NOT_SUPPORTED, instanceReference.getClassName());
|
374 kumpf 1.1 }
375
376 //
|
377 kumpf 1.2 // only can modify the property of Namespaces, property of
|
378 kumpf 1.1 // SupportedProperties, and property of SupportedMethods
379 //
|
380 kumpf 1.2 if (propertyList.isNull())
|
381 kumpf 1.1 {
|
382 kumpf 1.12 throw CIMException (CIM_ERR_NOT_SUPPORTED,
383 "Only can modify Namespaces, SupportedProperties, and SupportedMethods.");
|
384 kumpf 1.2 }
385
386 Array<String> propertyArray = propertyList.getPropertyNameArray();
387 for (Uint32 i=0; i<propertyArray.size(); i++)
388 {
389 if (!String::equalNoCase(propertyArray[i], _PROPERTY_NAMESPACES) &&
390 !String::equalNoCase(propertyArray[i], _PROPERTY_SUPPORTEDPROPERTIES) &&
391 !String::equalNoCase(propertyArray[i], _PROPERTY_SUPPORTEDMETHODS))
|
392 kumpf 1.1 {
|
393 kumpf 1.12 throw CIMException (CIM_ERR_NOT_SUPPORTED, propertyArray[i]);
|
394 kumpf 1.2 }
|
395 kumpf 1.1 }
396
397 // begin processing the request
398 handler.processing();
399
400 try
401 {
|
402 chip 1.24 _providerRegistrationManager->modifyInstance(instanceReference,
|
403 kumpf 1.2 instanceObject, flags, propertyArray);
|
404 kumpf 1.1 }
405 catch(CIMException& e)
406 {
|
407 kumpf 1.23 throw CIMException(CIM_ERR_FAILED, e.getMessage());
|
408 kumpf 1.1 }
409
410 // complete processing the request
411 handler.complete();
412 }
413
414 // register a provider
415 void ProviderRegistrationProvider::createInstance(
416 const OperationContext & context,
|
417 kumpf 1.13 const CIMObjectPath & instanceReference,
|
418 kumpf 1.1 const CIMInstance & instanceObject,
|
419 kumpf 1.13 ResponseHandler<CIMObjectPath> & handler)
|
420 kumpf 1.1 {
|
421 kumpf 1.15 // get userName and only privileged user can execute this operation
|
422 kumpf 1.19 String userName;
423 try
424 {
425 IdentityContainer container = context.get(CONTEXT_IDENTITY);
426 userName = container.getUserName();
427 }
428 catch (...)
429 {
430 userName = String::EMPTY;
431 }
|
432 kumpf 1.15
|
433 chip 1.24 if ((userName != String::EMPTY) && !System::isPrivilegedUser(userName))
|
434 kumpf 1.15 {
435 throw CIMException (CIM_ERR_ACCESS_DENIED,
436 "You must have superuser privilege to register providers.");
437 }
438
|
439 kumpf 1.1 String className = instanceReference.getClassName();
440 String nameSpace = instanceReference.getNameSpace();
441
|
442 kumpf 1.13 CIMObjectPath returnReference;
|
443 kumpf 1.1
444 CIMInstance instance = instanceObject;
445
|
446 kumpf 1.10 if(!String::equalNoCase(nameSpace, PEGASUS_NAMESPACENAME_INTEROP))
447 {
|
448 kumpf 1.12 throw CIMException (CIM_ERR_NOT_SUPPORTED, nameSpace);
|
449 kumpf 1.10 }
450
|
451 kumpf 1.1 // ensure the class existing in the specified namespace
|
452 kumpf 1.10 if(!String::equalNoCase(className, PEGASUS_CLASSNAME_PROVIDER) &&
453 !String::equalNoCase(className, PEGASUS_CLASSNAME_PROVIDERCAPABILITIES) &&
454 !String::equalNoCase(className, PEGASUS_CLASSNAME_PROVIDERMODULE))
|
455 kumpf 1.1 {
|
456 kumpf 1.12 throw CIMException(CIM_ERR_NOT_SUPPORTED, className);
|
457 kumpf 1.1 }
458
459 //
460 // Check all required properties are set
461 //
|
462 kumpf 1.10 if(String::equalNoCase(className, PEGASUS_CLASSNAME_PROVIDERMODULE))
|
463 kumpf 1.1 {
464 //
465 // Name, Version, InterfaceType, InterfaceVersion, and Location
466 // properties must be set
467 // OperationalStatus property needs to be set. If not, set to default
468 //
469 if (!instanceObject.existsProperty(_PROPERTY_PROVIDERMODULE_NAME))
470 {
|
471 chip 1.24 throw CIMException (CIM_ERR_FAILED,
|
472 kumpf 1.12 "Missing Name which is required property in PG_ProviderModule class.");
473 }
474
475 if (!instanceObject.existsProperty(_PROPERTY_VENDOR))
476 {
|
477 chip 1.24 throw CIMException (CIM_ERR_FAILED,
|
478 kumpf 1.12 "Missing Vendor which is required property in PG_ProviderModule class.");
|
479 kumpf 1.1 }
480
481 if (!instanceObject.existsProperty(_PROPERTY_VERSION))
482 {
|
483 chip 1.24 throw CIMException (CIM_ERR_FAILED,
|
484 kumpf 1.12 "Missing Version which is required property in PG_ProviderModule class.");
|
485 kumpf 1.1 }
486
487 if (!instanceObject.existsProperty(_PROPERTY_INTERFACETYPE))
488 {
|
489 chip 1.24 throw CIMException (CIM_ERR_FAILED,
|
490 kumpf 1.12 "Missing InterfaceType which is required property in PG_ProviderModule class.");
|
491 kumpf 1.1 }
492
493 if (!instanceObject.existsProperty(_PROPERTY_INTERFACEVERSION))
494 {
|
495 chip 1.24 throw CIMException (CIM_ERR_FAILED,
|
496 kumpf 1.12 "Missing InterfaceVersion which is required property in PG_ProviderModule class.");
|
497 kumpf 1.1 }
498
499 if (!instanceObject.existsProperty(_PROPERTY_LOCATION))
500 {
|
501 chip 1.24 throw CIMException (CIM_ERR_FAILED,
|
502 kumpf 1.12 "Missing Location which is required property in PG_ProviderModule class.");
|
503 kumpf 1.1 }
504
505 if (!instanceObject.existsProperty(_PROPERTY_OPERATIONALSTATUS))
506 {
507 Array<Uint16> _operationalStatus;
|
508 kumpf 1.14 _operationalStatus.append(_MODULE_OK);
|
509 kumpf 1.1 instance.addProperty (CIMProperty
510 (_PROPERTY_OPERATIONALSTATUS, _operationalStatus));
511 }
512 }
|
513 kumpf 1.10 else if(String::equalNoCase(className, PEGASUS_CLASSNAME_PROVIDERCAPABILITIES))
|
514 kumpf 1.1 {
515 //
516 // ProviderModuleName, ProviderName, InstanceID, ClassName,
517 // Namespaces, and ProviderType properties must be set
518 //
519
520 if (!instanceObject.existsProperty(_PROPERTY_PROVIDERMODULENAME))
521 {
|
522 chip 1.24 throw CIMException (CIM_ERR_FAILED,
|
523 kumpf 1.12 "Missing ProviderModuleName which is required property in PG_ProviderCapabilities class.");
|
524 kumpf 1.1 }
525
526 if (!instanceObject.existsProperty(_PROPERTY_PROVIDERNAME))
527 {
|
528 chip 1.24 throw CIMException (CIM_ERR_FAILED,
|
529 kumpf 1.12 "Missing ProviderName which is required property in PG_ProviderCapabilities class.");
|
530 kumpf 1.1 }
531
532 if (!instanceObject.existsProperty(_PROPERTY_CAPABILITYID))
533 {
|
534 chip 1.24 throw CIMException (CIM_ERR_FAILED,
|
535 kumpf 1.12 "Missing CapabilityID which is required property in PG_ProviderCapabilities class.");
|
536 kumpf 1.1 }
537
538 if (!instanceObject.existsProperty(_PROPERTY_CLASSNAME))
539 {
|
540 chip 1.24 throw CIMException (CIM_ERR_FAILED,
|
541 kumpf 1.12 "Missing ClassName which is required property in PG_ProviderCapabilities class.");
|
542 kumpf 1.1 }
543
544 if (!instanceObject.existsProperty(_PROPERTY_NAMESPACES))
545 {
|
546 chip 1.24 throw CIMException (CIM_ERR_FAILED,
|
547 kumpf 1.12 "Missing Namespaces which is required property in PG_ProviderCapabilities class.");
|
548 kumpf 1.1 }
549
550 if (!instanceObject.existsProperty(_PROPERTY_PROVIDERTYPE))
551 {
|
552 chip 1.24 throw CIMException (CIM_ERR_FAILED,
|
553 kumpf 1.12 "Missing ProviderType which is required property in PG_ProviderCapabilities class.");
|
554 kumpf 1.1 }
555 }
|
556 kumpf 1.10 else // PEGASUS_CLASSNAME_PROVIDER
|
557 kumpf 1.1 {
558 //
559 // Name and ProviderModuleName properties must be set
560 //
561 if (!instanceObject.existsProperty(_PROPERTY_PROVIDER_NAME))
562 {
|
563 chip 1.24 throw CIMException (CIM_ERR_FAILED,
|
564 kumpf 1.12 "Missing Name which is required property in PG_Provider class.");
|
565 kumpf 1.1 }
566
567 if (!instanceObject.existsProperty(_PROPERTY_PROVIDERMODULENAME))
568 {
|
569 chip 1.24 throw CIMException (CIM_ERR_FAILED,
|
570 kumpf 1.12 "Missing ProviderModuleName which is required property in PG_Provider class.");
|
571 kumpf 1.1 }
572 }
573
574 // begin processing the request
575 handler.processing();
576
577 try
578 {
579 returnReference =
580 _providerRegistrationManager->createInstance(instanceReference, instance);
581 }
582 catch(CIMException& e)
583 {
|
584 kumpf 1.23 throw CIMException(CIM_ERR_FAILED, e.getMessage());
|
585 kumpf 1.1 }
586
587 handler.deliver(returnReference);
588
589 // complete processing request
590 handler.complete();
591 }
592
593 // Unregister a provider
594 void ProviderRegistrationProvider::deleteInstance(
595 const OperationContext & context,
|
596 kumpf 1.13 const CIMObjectPath & instanceReference,
|
597 chip 1.24 ResponseHandler<void> & handler)
|
598 kumpf 1.1 {
|
599 kumpf 1.15 // get userName and only privileged user can execute this operation
|
600 kumpf 1.19 String userName;
601 try
602 {
603 IdentityContainer container = context.get(CONTEXT_IDENTITY);
604 userName = container.getUserName();
605 }
606 catch (...)
607 {
608 userName = String::EMPTY;
609 }
|
610 kumpf 1.15
|
611 chip 1.24 if ((userName != String::EMPTY) && !System::isPrivilegedUser(userName))
|
612 kumpf 1.15 {
613 throw CIMException (CIM_ERR_ACCESS_DENIED,
614 "You must have superuser privilege to unregister providers.");
615 }
616
|
617 chip 1.24 if(!String::equalNoCase(instanceReference.getNameSpace(),
|
618 kumpf 1.10 PEGASUS_NAMESPACENAME_INTEROP))
619 {
|
620 kumpf 1.12 throw CIMException (CIM_ERR_NOT_SUPPORTED, instanceReference.getNameSpace());
|
621 kumpf 1.10 }
622
|
623 kumpf 1.1 String className = instanceReference.getClassName();
624
625 // ensure the class existing in the specified namespace
|
626 kumpf 1.10 if(!String::equalNoCase(className, PEGASUS_CLASSNAME_PROVIDER) &&
627 !String::equalNoCase(className, PEGASUS_CLASSNAME_PROVIDERCAPABILITIES) &&
628 !String::equalNoCase(className, PEGASUS_CLASSNAME_PROVIDERMODULE))
|
629 kumpf 1.1 {
|
630 kumpf 1.12 throw CIMException(CIM_ERR_NOT_SUPPORTED, className);
|
631 kumpf 1.1 }
632
633 // begin processing the request
634 handler.processing();
635
636 try
637 {
638 _providerRegistrationManager->deleteInstance(instanceReference);
639 }
640 catch(CIMException& e)
641 {
|
642 kumpf 1.23 throw CIMException(CIM_ERR_FAILED, e.getMessage());
|
643 kumpf 1.1 }
644
645 // complete processing the request
646 handler.complete();
647 }
648
649 // Block a provider, unblock a provider, and stop a provider
650 void ProviderRegistrationProvider::invokeMethod(
651 const OperationContext & context,
|
652 kumpf 1.13 const CIMObjectPath & objectReference,
|
653 kumpf 1.1 const String & methodName,
654 const Array<CIMParamValue> & inParameters,
655 Array<CIMParamValue> & outParameters,
656 ResponseHandler<CIMValue> & handler)
657 {
|
658 kumpf 1.15 // get userName and only privileged user can execute this operation
|
659 kumpf 1.19 String userName;
660 try
661 {
662 IdentityContainer container = context.get(CONTEXT_IDENTITY);
663 userName = container.getUserName();
664 }
665 catch (...)
666 {
667 userName = String::EMPTY;
668 }
|
669 kumpf 1.15
|
670 chip 1.24 if ((userName != String::EMPTY) && !System::isPrivilegedUser(userName))
|
671 mday 1.17 {
672 throw CIMException (CIM_ERR_ACCESS_DENIED,
673 "You must have superuser privilege to disable or enable providers.");
674 }
|
675 kumpf 1.15
|
676 chip 1.24 if(!String::equalNoCase(objectReference.getNameSpace(),
|
677 kumpf 1.10 PEGASUS_NAMESPACENAME_INTEROP))
678 {
|
679 kumpf 1.12 throw CIMException (CIM_ERR_NOT_SUPPORTED, objectReference.getNameSpace());
|
680 kumpf 1.10 }
681
|
682 kumpf 1.5 String moduleName;
683 Boolean moduleFound = false;
|
684 kumpf 1.3
|
685 kumpf 1.5 // get module name from reference
|
686 kumpf 1.1 Array<KeyBinding> keys = objectReference.getKeyBindings();
687
|
688 kumpf 1.5 for(Uint32 i=0; i<keys.size() ; i++)
|
689 kumpf 1.1 {
|
690 kumpf 1.5 if(String::equalNoCase(keys[i].getName(), _PROPERTY_PROVIDERMODULE_NAME))
|
691 kumpf 1.1 {
|
692 kumpf 1.5 moduleName = keys[i].getValue();
693 moduleFound = true;
|
694 kumpf 1.1 }
695 }
696
|
697 kumpf 1.5 // if _PROPERTY_PROVIDERMODULE_NAME key not found
698 if( !moduleFound)
|
699 kumpf 1.1 {
700 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
701 "key Name was not found");
702 }
703
|
704 kumpf 1.5 //
705 // get module status
706 //
|
707 chip 1.24 Array<Uint16> _OperationalStatus =
|
708 kumpf 1.5 _providerRegistrationManager->getProviderModuleStatus( moduleName);
709
710 handler.processing();
711
712 Sint16 ret_value;
|
713 kumpf 1.1
714 if(String::equalNoCase(methodName, _STOP_PROVIDER))
715 {
|
716 kumpf 1.5 for (Uint32 i = 0; i<_OperationalStatus.size(); i++)
717 {
718 // retValue equals 1 if module is already disabled
|
719 chip 1.24 if (_OperationalStatus[i] == _MODULE_STOPPED ||
|
720 kumpf 1.14 _OperationalStatus[i] == _MODULE_STOPPING)
|
721 kumpf 1.5 {
722 ret_value = 1;
723 CIMValue retValue(ret_value);
724 handler.deliver(retValue);
725 handler.complete();
726 return;
727 }
728 }
|
729 kumpf 1.1
|
730 kumpf 1.8 CIMInstance mInstance;
731 CIMInstance instance;
732 Array<CIMInstance> instances;
733 String _moduleName;
734
735 // get module instance
736 mInstance = _providerRegistrationManager->getInstance(objectReference);
737
738 // get all provider instances which have same module name as moduleName
|
739 kumpf 1.13 CIMObjectPath providerRef(objectReference.getHost(),
|
740 kumpf 1.8 objectReference.getNameSpace(),
741 PEGASUS_CLASSNAME_PROVIDER,
742 objectReference.getKeyBindings());
|
743 kumpf 1.20 Array<CIMInstance> namedInstances;
|
744 kumpf 1.8 namedInstances = _providerRegistrationManager->enumerateInstances(providerRef);
745 for(Uint32 i = 0, n=namedInstances.size(); i < n; i++)
746 {
|
747 kumpf 1.20 instance = namedInstances[i];
|
748 kumpf 1.8 instance.getProperty(instance.findProperty
749 (_PROPERTY_PROVIDERMODULENAME)).getValue().get(_moduleName);
750 if (String::equalNoCase(_moduleName, moduleName))
751 {
752 instances.append(instance);
753 }
|
754 chip 1.24
|
755 kumpf 1.8 }
756
|
757 chip 1.24 //
|
758 kumpf 1.5 // get provider manager service
|
759 kumpf 1.1 //
|
760 kumpf 1.5 MessageQueueService * _service = _getProviderManagerService();
|
761 kumpf 1.1
|
762 kumpf 1.15 if (_service != NULL)
763 {
764 // create CIMDisableModuleRequestMessage
|
765 chip 1.24 CIMDisableModuleRequestMessage * disable_req =
|
766 kumpf 1.15 new CIMDisableModuleRequestMessage(
767 XmlWriter::getNextMessageId (),
768 mInstance,
769 instances,
770 QueueIdStack(_service->getQueueId()));
|
771 kumpf 1.5
|
772 chip 1.24 Array<Uint16> _opStatus =
|
773 kumpf 1.15 _sendDisableMessageToProviderManager(disable_req);
|
774 kumpf 1.5
|
775 kumpf 1.15 for (Uint32 i = 0; i<_opStatus.size(); i++)
|
776 kumpf 1.5 {
|
777 kumpf 1.15 if (_opStatus[i] == _MODULE_STOPPED)
778 {
779 // module was disabled successfully
780 ret_value = 0;
781 CIMValue retValue(ret_value);
782 handler.deliver(retValue);
783 handler.complete();
784
785 // send termination message to subscription service
786 _sendTerminationMessageToSubscription(objectReference, moduleName);
787 return;
788 }
|
789 kumpf 1.5 }
|
790 kumpf 1.15 }
|
791 kumpf 1.5
792 // disable failed
793 ret_value = -1;
794 CIMValue retValue(ret_value);
795 handler.deliver(retValue);
796 handler.complete();
797 return;
|
798 kumpf 1.1 }
799 else if(String::equalNoCase(methodName, _START_PROVIDER))
800 {
|
801 kumpf 1.5 for (Uint32 i = 0; i<_OperationalStatus.size(); i++)
|
802 kumpf 1.1 {
|
803 kumpf 1.5 // retValue equals 1 if module is already enabled
|
804 chip 1.24 if (_OperationalStatus[i] == _MODULE_OK)
|
805 kumpf 1.5 {
806 ret_value = 1;
807 CIMValue retValue(ret_value);
808 handler.deliver(retValue);
809 handler.complete();
810 return;
|
811 kumpf 1.14 }
812
813 // retValue equals 2 if module is stopping
814 // at this stage, module can not be started
815 if (_OperationalStatus[i] == _MODULE_STOPPING)
816 {
817 ret_value = 2;
818 CIMValue retValue(ret_value);
819 handler.deliver(retValue);
820 handler.complete();
821 return;
|
822 kumpf 1.5 }
|
823 kumpf 1.1 }
|
824 kumpf 1.5
|
825 chip 1.24 //
|
826 kumpf 1.5 // get provider manager service
827 //
828 MessageQueueService * _service = _getProviderManagerService();
829
|
830 kumpf 1.15 if (_service != NULL)
831 {
832 // create CIMEnableModuleRequestMessage
|
833 chip 1.24 CIMEnableModuleRequestMessage * enable_req =
|
834 kumpf 1.15 new CIMEnableModuleRequestMessage(
835 XmlWriter::getNextMessageId (),
836 moduleName,
837 QueueIdStack(_service->getQueueId()));
|
838 kumpf 1.5
|
839 kumpf 1.15 Array<Uint16> _opStatus;
840 _opStatus = _sendEnableMessageToProviderManager(enable_req);
|
841 kumpf 1.5
|
842 kumpf 1.15 for (Uint32 i = 0; i<_opStatus.size(); i++)
|
843 kumpf 1.5 {
|
844 kumpf 1.15 if (_opStatus[i] == _MODULE_OK)
845 {
846 // module was enabled successfully
847 ret_value = 0;
848 CIMValue retValue(ret_value);
849 handler.deliver(retValue);
850 handler.complete();
851 return;
852 }
|
853 kumpf 1.5 }
854 }
855
856 // enable failed
857 ret_value = -1;
858 CIMValue retValue(ret_value);
859 handler.deliver(retValue);
860 handler.complete();
861 return;
|
862 kumpf 1.1 }
863 else
864 {
865 throw CIMException(CIM_ERR_METHOD_NOT_AVAILABLE);
866 }
|
867 kumpf 1.5 }
868
869 // get provider manager service
870 MessageQueueService * ProviderRegistrationProvider::_getProviderManagerService()
871 {
872 MessageQueue * queue = MessageQueue::lookup(PEGASUS_QUEUENAME_PROVIDERMANAGER_CPP);
873 MessageQueueService * _service = dynamic_cast<MessageQueueService *>(queue);
874
|
875 chip 1.24 return(_service);
|
876 kumpf 1.5 }
877
878 ProviderRegistrationProvider & ProviderRegistrationProvider::operator=(const ProviderRegistrationProvider & handle)
879 {
880 if(this == &handle)
881 {
882 return(*this);
883 }
884
885 return(*this);
886 }
|
887 kumpf 1.1
|
888 kumpf 1.5 Array<Uint16> ProviderRegistrationProvider::_sendDisableMessageToProviderManager(
889 CIMDisableModuleRequestMessage * disable_req)
890 {
891 MessageQueueService * _service = _getProviderManagerService();
892 Uint32 _queueId = _service->getQueueId();
893
894 callback_data *cb_data = new callback_data(this);
895
896 // create request envelope
897 AsyncLegacyOperationStart * asyncRequest =
898 new AsyncLegacyOperationStart (
899 _service->get_next_xid(),
900 NULL,
901 _queueId,
902 disable_req,
903 _queueId);
904
|
905 kumpf 1.8 AsyncReply * asyncReply = _controller->ClientSendWait(*_client_handle,
906 _queueId,
907 asyncRequest);
|
908 kumpf 1.10 CIMDisableModuleResponseMessage * response =
909 reinterpret_cast<CIMDisableModuleResponseMessage *>(
|
910 kumpf 1.8 (static_cast<AsyncLegacyOperationResult *>(asyncReply))->get_result());
911 if (response->cimException.getCode() != CIM_ERR_SUCCESS)
912 {
913 CIMException e = response->cimException;
914 delete asyncRequest;
915 delete asyncReply;
916 delete response;
917 throw (e);
918 }
|
919 kumpf 1.5
|
920 chip 1.24 Array<Uint16> operationalStatus = response->operationalStatus;
|
921 kumpf 1.8
922 delete asyncRequest;
923 delete asyncReply;
924 delete response;
|
925 mday 1.16
|
926 kumpf 1.5 return(operationalStatus);
927 }
928
929 Array<Uint16> ProviderRegistrationProvider::_sendEnableMessageToProviderManager(
930 CIMEnableModuleRequestMessage * enable_req)
931 {
932 MessageQueueService * _service = _getProviderManagerService();
933 Uint32 _queueId = _service->getQueueId();
934
935 callback_data *cb_data = new callback_data(this);
936
937 // create request envelope
938 AsyncLegacyOperationStart * asyncRequest =
939 new AsyncLegacyOperationStart (
940 _service->get_next_xid(),
941 NULL,
942 _queueId,
943 enable_req,
944 _queueId);
945
|
946 kumpf 1.8 AsyncReply * asyncReply = _controller->ClientSendWait(*_client_handle,
947 _queueId,
948 asyncRequest);
949 CIMEnableModuleResponseMessage * response =
950 reinterpret_cast<CIMEnableModuleResponseMessage *>(
951 (static_cast<AsyncLegacyOperationResult *>(asyncReply))->get_result());
952 if (response->cimException.getCode() != CIM_ERR_SUCCESS)
953 {
954 CIMException e = response->cimException;
955 delete asyncRequest;
956 delete asyncReply;
957 delete response;
958 throw (e);
959 }
960
|
961 chip 1.24 Array<Uint16> operationalStatus = response->operationalStatus;
|
962 kumpf 1.8
963 delete asyncRequest;
964 delete asyncReply;
965 delete response;
|
966 mday 1.16
|
967 kumpf 1.5 return(operationalStatus);
|
968 kumpf 1.6 }
969
970 // send termination message to subscription service
971 void ProviderRegistrationProvider::_sendTerminationMessageToSubscription(
|
972 kumpf 1.13 const CIMObjectPath & ref, const String & moduleName)
|
973 kumpf 1.6 {
974 CIMInstance instance;
975 String _moduleName;
976 Array<CIMInstance> instances;
977
|
978 chip 1.24 CIMObjectPath reference("", PEGASUS_NAMESPACENAME_INTEROP,
|
979 kumpf 1.6 PEGASUS_CLASSNAME_PROVIDER, ref.getKeyBindings());
|
980 chip 1.24
|
981 kumpf 1.6 // get all registered providers
|
982 kumpf 1.20 Array<CIMInstance> enumInstances =
|
983 chip 1.24 _providerRegistrationManager->enumerateInstances(reference);
|
984 kumpf 1.6
985 // find all the instances which have same module name as moduleName
986 for (Uint32 i = 0, n=enumInstances.size(); i < n; i++)
987 {
|
988 kumpf 1.20 instance = enumInstances[i];
|
989 kumpf 1.6
990 //
991 // get provider module name
992 //
993 instance.getProperty(instance.findProperty
994 (_PROPERTY_PROVIDERMODULENAME)).getValue().get(_moduleName);
995
996 if (String::equalNoCase(moduleName, _moduleName))
997 {
998 instances.append(instance);
999 }
1000 }
1001
1002 //
1003 // get indication server queueId
1004 //
1005 MessageQueueService * _service = _getIndicationService();
1006
|
1007 kumpf 1.15 if (_service != NULL)
1008 {
1009 Uint32 _queueId = _service->getQueueId();
|
1010 kumpf 1.6
|
1011 kumpf 1.15 CIMNotifyProviderTerminationRequestMessage * termination_req =
1012 new CIMNotifyProviderTerminationRequestMessage(
1013 XmlWriter::getNextMessageId (),
1014 instances,
1015 QueueIdStack(_service->getQueueId()));
1016
1017 // create request envelope
1018 AsyncLegacyOperationStart * asyncRequest =
1019 new AsyncLegacyOperationStart (
|
1020 kumpf 1.6 _service->get_next_xid(),
1021 NULL,
1022 _queueId,
1023 termination_req,
1024 _queueId);
1025
|
1026 kumpf 1.15 if( false == _controller->ClientSendForget(
|
1027 kumpf 1.6 *_client_handle,
1028 _queueId,
1029 asyncRequest))
|
1030 kumpf 1.15 {
1031 delete asyncRequest;
1032 throw CIMException(CIM_ERR_NOT_FOUND);
1033 }
|
1034 kumpf 1.6 }
1035 }
1036
1037 // get indication service
1038 MessageQueueService * ProviderRegistrationProvider::_getIndicationService()
1039 {
1040 MessageQueue * queue = MessageQueue::lookup(
1041 PEGASUS_QUEUENAME_INDICATIONSERVICE);
1042
1043 MessageQueueService * _service =
1044 dynamic_cast<MessageQueueService *>(queue);
1045 return(_service);
|
1046 kumpf 1.1 }
1047
1048 PEGASUS_NAMESPACE_END
|