1 kumpf 1.1 //%////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
5 //
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 //
13 // 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 kumpf 1.1 //=============================================================================
23 //
24 // Author: Nag Boranna, Hewlett-Packard Company (nagaraja_boranna@hp.com)
25 //
26 // Modified By: Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
27 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
28 // Sushma Fernandes, Hewlett-Packard Company
29 // (sushma_fernandes@hp.com)
30 //
31 //%////////////////////////////////////////////////////////////////////////////
32
33
34 ///////////////////////////////////////////////////////////////////////////////
35 // ConfigSetting Provider
36 ///////////////////////////////////////////////////////////////////////////////
37
38 #include <Pegasus/Common/Config.h>
|
39 kumpf 1.4 #include <Pegasus/Common/PegasusVersion.h>
|
40 kumpf 1.1
41 #include <cctype>
42 #include <iostream>
43
44 #include "ConfigSettingProvider.h"
45 #include <Pegasus/Common/String.h>
46 #include <Pegasus/Common/System.h>
47 #include <Pegasus/Common/Array.h>
48 #include <Pegasus/Common/CIMType.h>
49 #include <Pegasus/Common/CIMInstance.h>
50 #include <Pegasus/Common/CIMReference.h>
51 #include <Pegasus/Common/Exception.h>
52 #include <Pegasus/Common/CIMStatusCode.h>
53 #include <Pegasus/Common/Tracer.h>
54 #include <Pegasus/Config/ConfigManager.h>
55
56 #include <Pegasus/Repository/CIMRepository.h>
57 #include <Pegasus/Provider/CIMInstanceProvider.h>
58 #include <Pegasus/Provider/SimpleResponseHandler.h>
59 #include <Pegasus/Provider/OperationFlag.h>
60
61 kumpf 1.1 PEGASUS_USING_STD;
62
63 PEGASUS_NAMESPACE_BEGIN
64
65 /**
66 The constants representing the string literals.
67 */
68 static const char PROPERTY_NAME [] = "PropertyName";
69
70 static const char DEFAULT_VALUE [] = "DefaultValue";
71
72 static const char CURRENT_VALUE [] = "CurrentValue";
73
74 static const char PLANNED_VALUE [] = "PlannedValue";
75
76 static const char DYNAMIC_PROPERTY [] = "DynamicProperty";
77
78 /**
79 The constant represeting the config setting class name
80 */
81 static const char PG_CONFIG_SETTING [] = "PG_ConfigSetting";
82 kumpf 1.1
83
84 void ConfigSettingProvider::getInstance(
85 const OperationContext & context,
86 const CIMReference& instanceName,
87 const Uint32 flags,
|
88 kumpf 1.2 const CIMPropertyList& propertyList,
|
89 kumpf 1.1 ResponseHandler<CIMInstance> & handler)
90 {
91 PEG_METHOD_ENTER(TRC_CONFIG, "ConfigSettingProvider::getInstance()");
92
93 Array<String> propertyInfo;
94 KeyBinding kb;
95 String keyName;
96 String keyValue;
97
|
98 kumpf 1.5 //
99 // check if the class name requested is PG_ConfigSetting
100 //
101 if (!String::equalNoCase(PG_CONFIG_SETTING, instanceName.getClassName()))
102 {
103 PEG_METHOD_EXIT();
104 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
105 instanceName.getClassName());
106 }
|
107 kumpf 1.1
|
108 kumpf 1.5 //
109 // validate key bindings
110 //
|
111 kumpf 1.1 Array<KeyBinding> kbArray = instanceName.getKeyBindings();
|
112 kumpf 1.5 if ( (kbArray.size() != 1) ||
113 (!String::equalNoCase(kbArray[0].getName(), PROPERTY_NAME)) )
|
114 kumpf 1.1 {
115 PEG_METHOD_EXIT();
116 throw PEGASUS_CIM_EXCEPTION(
|
117 kumpf 1.5 CIM_ERR_INVALID_PARAMETER,
118 "Invalid instance name");
|
119 kumpf 1.1 }
120
|
121 kumpf 1.5 keyValue.assign(kbArray[0].getValue());
122
|
123 kumpf 1.1 // begin processing the request
124 handler.processing();
125
|
126 kumpf 1.5 //
127 // Get values for the property
128 //
129 try
130 {
131 _configManager->getPropertyInfo(keyValue, propertyInfo);
132 }
133 catch (UnrecognizedConfigProperty& ucp)
134 {
135 PEG_METHOD_EXIT();
136 throw PEGASUS_CIM_EXCEPTION(
137 CIM_ERR_NOT_FOUND,
138 String("Configuration property \"") + keyValue + "\"");
139 }
|
140 kumpf 1.1
|
141 kumpf 1.5 if (propertyInfo.size() >= 5)
|
142 kumpf 1.1 {
|
143 kumpf 1.5 CIMInstance instance(PG_CONFIG_SETTING);
144
|
145 kumpf 1.1 //
|
146 kumpf 1.5 // construct the instance
|
147 kumpf 1.1 //
|
148 kumpf 1.5 instance.addProperty(CIMProperty(PROPERTY_NAME, propertyInfo[0]));
149 instance.addProperty(CIMProperty(DEFAULT_VALUE, propertyInfo[1]));
150 instance.addProperty(CIMProperty(CURRENT_VALUE, propertyInfo[2]));
151 instance.addProperty(CIMProperty(PLANNED_VALUE, propertyInfo[3]));
152 instance.addProperty(CIMProperty(DYNAMIC_PROPERTY,
153 Boolean(propertyInfo[4]=="true"?true:false)));
|
154 kumpf 1.1
|
155 kumpf 1.5 handler.deliver(instance);
|
156 kumpf 1.1
|
157 kumpf 1.5 // complete processing the request
158 handler.complete();
|
159 kumpf 1.1
|
160 kumpf 1.5 PEG_METHOD_EXIT();
161 return ;
|
162 kumpf 1.1 }
163 }
164
165 void ConfigSettingProvider::modifyInstance(
166 const OperationContext & context,
167 const CIMReference & instanceReference,
168 const CIMInstance& modifiedIns,
169 const Uint32 flags,
|
170 kumpf 1.2 const CIMPropertyList& propertyList,
|
171 kumpf 1.1 ResponseHandler<CIMInstance> & handler)
172 {
173 PEG_METHOD_ENTER(TRC_CONFIG, "ConfigSettingProvider::modifyInstance()");
174
|
175 kumpf 1.5 // NOTE: Qualifiers are not processed by this provider, so the
176 // IncludeQualifiers flag is ignored.
177
178 //
179 // check if the class name requested is PG_ConfigSetting
180 //
181 if (!String::equalNoCase(PG_CONFIG_SETTING,
182 instanceReference.getClassName()))
|
183 kumpf 1.1 {
184 PEG_METHOD_EXIT();
|
185 kumpf 1.5 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
186 instanceReference.getClassName());
|
187 kumpf 1.1 }
188
|
189 kumpf 1.5 //
190 // validate key bindings
191 //
192 Array<KeyBinding> kbArray = instanceReference.getKeyBindings();
193 if ( (kbArray.size() != 1) ||
194 (!String::equalNoCase(kbArray[0].getName(), PROPERTY_NAME)) )
195 {
196 PEG_METHOD_EXIT();
197 throw PEGASUS_CIM_EXCEPTION(
198 CIM_ERR_INVALID_PARAMETER,
199 "Invalid instance name");
200 }
201
202 String configPropertyName = kbArray[0].getValue();
203
204 // Modification of the entire instance is not supported by this provider
205 if (propertyList.isNull())
206 {
207 PEG_METHOD_EXIT();
208 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
209 "Modification of entire instance");
210 kumpf 1.5 }
|
211 kumpf 1.1
212 Boolean currentValueModified = false;
213 Boolean plannedValueModified = false;
214
|
215 kumpf 1.5 for (Uint32 i=0; i<propertyList.getNumProperties(); i++)
216 {
217 String propertyName = propertyList.getPropertyName(i);
218 if (String::equalNoCase(propertyName, CURRENT_VALUE))
219 {
220 currentValueModified = true;
221 }
222 else if (String::equalNoCase(propertyName, PLANNED_VALUE))
223 {
224 plannedValueModified = true;
225 }
226 else
227 {
228 PEG_METHOD_EXIT();
229 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
230 String("Modification of property \"") + propertyName + "\"");
231 }
232 }
233
234 String currentValue = String::EMPTY;
235 String plannedValue = String::EMPTY;
236 kumpf 1.5 Boolean currentValueIsNull = false;
237 Boolean plannedValueIsNull = false;
|
238 kumpf 1.1
239 // begin processing the request
240 handler.processing();
241
|
242 kumpf 1.5 //
243 // Get the current value from the instance
244 //
245 Uint32 pos = modifiedIns.findProperty(CURRENT_VALUE);
246 if (pos == PEG_NOT_FOUND)
247 {
248 currentValueIsNull = true;
249 }
250 else
|
251 kumpf 1.1 {
|
252 kumpf 1.5 CIMConstProperty prop = modifiedIns.getProperty(pos);
253 try
|
254 kumpf 1.1 {
|
255 kumpf 1.5 prop.getValue().get(currentValue);
|
256 kumpf 1.1 }
|
257 kumpf 1.5 catch (Exception& e)
|
258 kumpf 1.1 {
|
259 kumpf 1.5 PEG_METHOD_EXIT();
260 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
261 }
262 }
|
263 kumpf 1.1
|
264 kumpf 1.5 //
265 // Get the planned value from the instance
266 //
267 pos = modifiedIns.findProperty(PLANNED_VALUE);
268 if (pos == PEG_NOT_FOUND)
269 {
270 plannedValueIsNull = true;
|
271 kumpf 1.1 }
|
272 kumpf 1.5 else
|
273 kumpf 1.1 {
|
274 kumpf 1.5 CIMConstProperty prop = modifiedIns.getProperty(pos);
275 try
276 {
277 prop.getValue().get(plannedValue);
278 }
279 catch (Exception& e)
280 {
281 PEG_METHOD_EXIT();
282 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
283 }
|
284 kumpf 1.1 }
285
286 try
287 {
|
288 kumpf 1.5 //
289 // Update the current value, if requested
290 //
|
291 kumpf 1.1 if (currentValueModified)
292 {
|
293 kumpf 1.5 if ( !_configManager->updateCurrentValue(
294 configPropertyName, currentValue, currentValueIsNull) )
|
295 kumpf 1.1 {
|
296 kumpf 1.5 handler.complete();
|
297 kumpf 1.1 PEG_METHOD_EXIT();
298 throw PEGASUS_CIM_EXCEPTION(
299 CIM_ERR_FAILED,
300 "Failed to update the current value.");
301 }
302 }
303
|
304 kumpf 1.5 //
305 // Update the planned value, if requested
306 //
|
307 kumpf 1.1 if (plannedValueModified)
308 {
|
309 kumpf 1.5 if ( !_configManager->updatePlannedValue(
310 configPropertyName, plannedValue, plannedValueIsNull) )
|
311 kumpf 1.1 {
|
312 kumpf 1.5 handler.complete();
|
313 kumpf 1.1 PEG_METHOD_EXIT();
314 throw PEGASUS_CIM_EXCEPTION(
315 CIM_ERR_FAILED,
316 "Failed to update the planned value.");
317 }
318 }
319 }
320 catch (NonDynamicConfigProperty& ndcp)
321 {
322 PEG_METHOD_EXIT();
323 throw PEGASUS_CIM_EXCEPTION(
324 CIM_ERR_NOT_SUPPORTED, ndcp.getMessage());
325 }
326 catch (InvalidPropertyValue& ipv)
327 {
328 PEG_METHOD_EXIT();
329 throw PEGASUS_CIM_EXCEPTION(
|
330 kumpf 1.5 CIM_ERR_FAILED, ipv.getMessage());
|
331 kumpf 1.1 }
332 catch (UnrecognizedConfigProperty& ucp)
333 {
334 PEG_METHOD_EXIT();
335 throw PEGASUS_CIM_EXCEPTION(
|
336 kumpf 1.3 CIM_ERR_NOT_FOUND,
|
337 kumpf 1.5 String("Configuration property \"") +
338 configPropertyName + "\"");
|
339 kumpf 1.1 }
340
|
341 kumpf 1.5 handler.complete();
|
342 kumpf 1.1 PEG_METHOD_EXIT();
|
343 kumpf 1.5 return;
|
344 kumpf 1.1 }
345
346 void ConfigSettingProvider::enumerateInstances(
347 const OperationContext & context,
348 const CIMReference & ref,
349 const Uint32 flags,
|
350 kumpf 1.2 const CIMPropertyList& propertyList,
|
351 kumpf 1.1 ResponseHandler<CIMInstance> & handler)
352 {
353 PEG_METHOD_ENTER(TRC_CONFIG, "ConfigSettingProvider::enumerateInstances()");
354
355 Array<CIMInstance> instanceArray;
356 Array<String> propertyNames;
357
358 //
359 // check if the class name requested is PG_ConfigSetting
360 //
|
361 kumpf 1.5 if (!String::equalNoCase(PG_CONFIG_SETTING, ref.getClassName()))
|
362 kumpf 1.1 {
363 PEG_METHOD_EXIT();
|
364 kumpf 1.5 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
365 ref.getClassName());
|
366 kumpf 1.1 }
367
368 // begin processing the request
369 handler.processing();
370
371 try
372 {
373 _configManager->getAllPropertyNames(propertyNames);
374
375 for (Uint32 i = 0; i < propertyNames.size(); i++)
376 {
377 Array<String> propertyInfo;
378
379 CIMInstance instance(PG_CONFIG_SETTING);
380
381 propertyInfo.clear();
382
383 _configManager->getPropertyInfo(propertyNames[i], propertyInfo);
384
385 Array<KeyBinding> keyBindings;
386 keyBindings.append(KeyBinding(PROPERTY_NAME, propertyInfo[0],
387 kumpf 1.1 KeyBinding::STRING));
388 CIMReference instanceName(ref.getHost(), ref.getNameSpace(),
389 PG_CONFIG_SETTING, keyBindings);
390
391 // construct the instance
392 instance.addProperty(CIMProperty(PROPERTY_NAME, propertyInfo[0]));
393 instance.addProperty(CIMProperty(DEFAULT_VALUE, propertyInfo[1]));
394 instance.addProperty(CIMProperty(CURRENT_VALUE, propertyInfo[2]));
395 instance.addProperty(CIMProperty(PLANNED_VALUE, propertyInfo[3]));
396 instance.addProperty(CIMProperty(DYNAMIC_PROPERTY,
397 Boolean(propertyInfo[4]=="true"?true:false)));
398
399 //namedInstanceArray.append(
400 // CIMNamedInstance(instanceName, instance));
401 instanceArray.append(instance);
402 }
403 }
404 catch(Exception& e)
405 {
406 PEG_METHOD_EXIT();
407 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
408 kumpf 1.1 }
409
410 handler.deliver(instanceArray);
411
412 // complete processing the request
413 handler.complete();
414
415 PEG_METHOD_EXIT();
416 }
417
418 void ConfigSettingProvider::enumerateInstanceNames(
419 const OperationContext & context,
420 const CIMReference & classReference,
421 ResponseHandler<CIMReference> & handler)
422 {
423 PEG_METHOD_ENTER(TRC_CONFIG,
424 "ConfigSettingProvider::enumerateInstanceNames()");
425
426 Array<CIMReference> instanceRefs;
427 Array<String> propertyNames;
428 Array<KeyBinding> keyBindings;
429 kumpf 1.1 KeyBinding kb;
430 String hostName;
431
432 hostName.assign(System::getHostName());
433
434 const String& className = classReference.getClassName();
435 const String& nameSpace = classReference.getNameSpace();
436
|
437 kumpf 1.5 if (!String::equalNoCase(PG_CONFIG_SETTING, className))
|
438 kumpf 1.1 {
439 PEG_METHOD_EXIT();
|
440 kumpf 1.5 throw PEGASUS_CIM_EXCEPTION( CIM_ERR_NOT_SUPPORTED, className );
|
441 kumpf 1.1 }
442
443 // begin processing the request
444 handler.processing();
445
446 try
447 {
448 _configManager->getAllPropertyNames(propertyNames);
449
450 Uint32 size = propertyNames.size();
451
452 for (Uint32 i = 0; i < size; i++)
453 {
454 keyBindings.append(KeyBinding(PROPERTY_NAME, propertyNames[i],
455 KeyBinding::STRING));
456
457 //
458 // Convert instance names to References
459 //
460 CIMReference ref(hostName, nameSpace, className, keyBindings);
461
462 kumpf 1.1 instanceRefs.append(ref);
463 keyBindings.clear();
464 }
465 }
466 catch(Exception& e)
467 {
468 PEG_METHOD_EXIT();
469 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
470 }
471
472 handler.deliver(instanceRefs);
473
474 // complete processing the request
475 handler.complete();
476
477 PEG_METHOD_EXIT();
478 }
479
480 PEGASUS_NAMESPACE_END
481
|