1 karl 1.5 //%2003////////////////////////////////////////////////////////////////////////
|
2 chip 1.1 //
|
3 karl 1.5 // 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 // IBM Corp.; EMC Corporation, The Open Group.
|
7 chip 1.1 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
|
14 chip 1.6 //
|
15 chip 1.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
16 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
18 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 //==============================================================================
25 //
26 // Author: Chip Vincent (cvincent@us.ibm.com)
27 //
|
28 schuur 1.10 // Modified By: Adrian Schuur (schuur@de-ibm.com)
|
29 chip 1.1 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include "ProviderRegistrar.h"
33
34 #include <Pegasus/Common/Constants.h>
35 #include <Pegasus/Common/Tracer.h>
36 #include <Pegasus/Common/Pair.h>
|
37 schuur 1.10 #include <Pegasus/Common/Tracer.h>
38 #include <Pegasus/Common/Logger.h>
39 #include <Pegasus/Common/MessageLoader.h> //l10n
|
40 chip 1.1
41 #include <Pegasus/Server/ProviderRegistrationManager/ProviderRegistrationManager.h>
|
42 schuur 1.7 #include <Pegasus/ProviderManager2/ProviderType.h>
|
43 chip 1.1
44 PEGASUS_NAMESPACE_BEGIN
45
|
46 chip 1.2 static ProviderRegistrationManager * _prm = 0;
|
47 chip 1.1
|
48 chip 1.2 static CIMValue _getPropertyValue(const CIMInstance & cimInstance, const String & propertyName)
|
49 chip 1.1 {
|
50 chip 1.2 CIMValue value;
51
52 Uint32 pos = 0;
53
54 // get ClassName property
55 if((pos = cimInstance.findProperty(propertyName)) != PEG_NOT_FOUND)
56 {
57 value = cimInstance.getProperty(pos).getValue();
58 }
59
60 return(value);
|
61 chip 1.1 }
62
|
63 chip 1.2 static ProviderName _lookupProvider(const CIMObjectPath & cimObjectPath)
|
64 chip 1.1 {
|
65 chip 1.2 String providerName;
66 String moduleName;
67
68 try
69 {
70 // get the PG_ProviderCapabilities instances for the specified namespace:class_name. use the matching
71 // instance to gather the PG_Provider instance name (logical name).
|
72 chip 1.1
|
73 chip 1.6 Array<CIMObjectPath> cimInstanceNames = _prm->enumerateInstanceNames(CIMObjectPath(String::EMPTY, "root/PG_Interop", "PG_ProviderCapabilities"));
|
74 chip 1.1
|
75 chip 1.6 for(Uint32 i = 0, n = cimInstanceNames.size(); i < n; i++)
|
76 chip 1.2 {
|
77 chip 1.6 CIMInstance cimInstance = _prm->getInstance(cimInstanceNames[i]);
|
78 chip 1.2
79 // check ClassName property value
80 if(String::equalNoCase(cimObjectPath.getClassName().getString(), _getPropertyValue(cimInstance, "ClassName").toString()))
81 {
82 // check Namespaces property value
83 Array<String> nameSpaces;
84
85 _getPropertyValue(cimInstance, "Namespaces").get(nameSpaces);
86
|
87 chip 1.3 // ATTN: need to walk the array
88 if(String::equalNoCase(cimObjectPath.getNameSpace().getString(), nameSpaces[0]))
|
89 chip 1.2 {
|
90 chip 1.3 providerName = _getPropertyValue(cimInstance, "ProviderName").toString();
|
91 chip 1.2
|
92 chip 1.3 break;
|
93 chip 1.2 }
94 }
95 }
96 }
97 catch(...)
98 {
99 }
|
100 chip 1.1
|
101 chip 1.2 // ensure the provider name is valid
102 if(providerName.size() == 0)
103 {
104 throw Exception("Could not determine PG_Provider instance for specified class.");
105 }
|
106 chip 1.1
|
107 chip 1.2 try
108 {
109 // get the PG_Provider instances associated with the specified namespace:class_name. use the matching
110 // instance to gather the PG_ProviderModule instance name.
|
111 chip 1.1
|
112 chip 1.6 Array<CIMObjectPath> cimInstanceNames = _prm->enumerateInstanceNames(CIMObjectPath(String::EMPTY, "root/PG_Interop", "PG_Provider"));
|
113 chip 1.1
|
114 chip 1.6 for(Uint32 i = 0, n = cimInstanceNames.size(); i < n; i++)
|
115 chip 1.2 {
|
116 chip 1.6 CIMInstance cimInstance = _prm->getInstance(cimInstanceNames[i]);
|
117 chip 1.2
118 if(String::equalNoCase(providerName, _getPropertyValue(cimInstance, "Name").toString()))
119 {
120 moduleName = _getPropertyValue(cimInstance, "ProviderModuleName").toString();
121
122 break;
123 }
124 }
125 }
126 catch(...)
|
127 chip 1.1 {
128 }
129
|
130 chip 1.2 // ensure the module name is valid
131 if(moduleName.size() == 0)
132 {
133 throw Exception("Could not determine PG_ProviderModule instance for specified class.");
134 }
|
135 chip 1.1
|
136 chip 1.2 String interfaceType;
137 String moduleLocation;
|
138 chip 1.1
|
139 chip 1.2 try
140 {
141 // get the PG_ProviderModule instances associated with the specified namespace:class_name. use the matching
142 // instance to gather the module status and location (physical name).
|
143 chip 1.1
|
144 chip 1.6 Array<CIMObjectPath> cimInstanceNames = _prm->enumerateInstanceNames(CIMObjectPath(String::EMPTY, "root/PG_Interop", "PG_ProviderModule"));
|
145 chip 1.1
|
146 chip 1.6 for(Uint32 i = 0, n = cimInstanceNames.size(); i < n; i++)
|
147 chip 1.2 {
|
148 chip 1.6 CIMInstance cimInstance = _prm->getInstance(cimInstanceNames[i]);
|
149 chip 1.2
150 if(String::equalNoCase(moduleName, _getPropertyValue(cimInstance, "Name").toString()))
151 {
|
152 chip 1.3 // ATTN: check operational status
153
154 // get interface
155 interfaceType = _getPropertyValue(cimInstance, "InterfaceType").toString();
|
156 chip 1.2
|
157 chip 1.3 // get location
158 moduleLocation = _getPropertyValue(cimInstance, "Location").toString();
|
159 chip 1.2
|
160 chip 1.3 break;
|
161 chip 1.2 }
162 }
|
163 chip 1.3 }
|
164 chip 1.2 catch(...)
|
165 chip 1.1 {
166 }
167
|
168 chip 1.2 // ensure the interface and location are valid
169 if((interfaceType.size() == 0) || (moduleLocation.size() == 0))
170 {
171 throw Exception("Could not determine PG_ProviderModule.InterfaceType or PG_ProviderModule.Location or module is disabled.");
172 }
|
173 chip 1.1
|
174 chip 1.6 // DEBUG
175 CString s1 = interfaceType.getCString();
176 const char * p1 = s1;
177
178 CString s2 = moduleLocation.getCString();
179 const char * p2 = s2;
180
|
181 chip 1.2 ProviderName temp(
182 providerName,
183 moduleLocation,
184 interfaceType,
185 0);
|
186 chip 1.1
|
187 chip 1.2 return(temp);
188 }
189
190 ProviderRegistrar::ProviderRegistrar(void)
191 {
192 }
193
194 ProviderRegistrar::~ProviderRegistrar(void)
195 {
196 }
|
197 chip 1.1
|
198 schuur 1.9 ProviderName ProviderRegistrar::findConsumerProvider(const String & destinationPath)
199 {
200 CIMInstance provider;
201 CIMInstance providerModule;
202 ProviderName temp;
203
204 if (_prm->lookupIndicationConsumer(destinationPath,provider,providerModule))
|
205 schuur 1.12 return ProviderName(
|
206 schuur 1.9 provider.getProperty(providerModule.findProperty
207 ("Name")).getValue ().toString (),
208 providerModule.getProperty(providerModule.findProperty
209 ("Location")).getValue().toString(),
210 providerModule.getProperty(providerModule.findProperty
211 ("InterfaceType")).getValue().toString(),
212 0);
213
214 return temp;
215 }
216
|
217 schuur 1.10 static const Uint16 _MODULE_STOPPING = 9;
218 static const Uint16 _MODULE_STOPPED = 10;
219
220 static void checkBlocked(CIMInstance &pm)
221 {
222 PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "checkBlocked");
223
224 Array<Uint16> operationalStatus;
225
226 Uint32 pos = pm.findProperty(CIMName ("OperationalStatus"));
227 if(pos == PEG_NOT_FOUND) {
228 PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
229 "OperationalStatus not found.");
230 PEG_METHOD_EXIT();
231 //l10n
232 //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "provider lookup failed.");
233 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
234 "ProviderManager.ProviderManagerService.PROVIDER_LOOKUP_FAILED",
235 "provider lookup failed."));
236 }
237
238 schuur 1.10 pm.getProperty(pos).getValue().get(operationalStatus);
239 for(Uint32 i = 0; i < operationalStatus.size(); i++) {
240 if(operationalStatus[i] == _MODULE_STOPPED ||
241 operationalStatus[i] == _MODULE_STOPPING) {
242 PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
243 "Provider blocked.");
244 PEG_METHOD_EXIT();
245 //l10n
246 //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ACCESS_DENIED, "provider blocked.");
247 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED, MessageLoaderParms(
248 "ProviderManager.ProviderManagerService.PROVIDER_BLOCKED",
249 "provider blocked."));
250 }
251 }
252 }
253
|
254 chip 1.2 // need at least the object and the one capability.
255 // for example,
256 // "//localhost/root/cimv2:CIM_ComputerSystem", INSTANCE
257 // "//localhost/root/cimv2:CIM_ComputerSystem", METHOD
258 // "//localhost/root/cimv2:CIM_AssociatedComputerSystem", ASSOCIATION
259 // "//localhost/root/cimv2:CIM_ComputerSystemFailure", INDICATION
260
261 // the method will return the logical and physical provider names associated with the object and capability.
|
262 chip 1.1
|
263 schuur 1.10 ProviderName ProviderRegistrar::findProvider(const ProviderName & providerName, Boolean test)
|
264 chip 1.2 {
|
265 schuur 1.12 // CIMObjectPath objectName = providerName.getObjectName();
|
266 chip 1.2 Uint32 flags = providerName.getCapabilitiesMask();
|
267 chip 1.1
|
268 chip 1.2 // validate arguments
|
269 schuur 1.12 /* if(objectName.getNameSpace().isNull() || objectName.getClassName().isNull())
|
270 chip 1.2 {
271 throw Exception("Invalid argument.");
272 }
|
273 schuur 1.12 */
|
274 schuur 1.7 CIMInstance provider;
275 CIMInstance providerModule;
276 ProviderName temp;
|
277 schuur 1.8 Boolean hasNoQuery;
|
278 schuur 1.7
279 switch (flags) {
|
280 schuur 1.9 case ProviderType_INSTANCE:
|
281 schuur 1.12 if (_prm->lookupInstanceProvider(providerName.getNameSpace(),providerName.getClassName(),
|
282 schuur 1.7 provider,providerModule,0)) {
|
283 schuur 1.11 if (test) checkBlocked(providerModule);
|
284 schuur 1.12 return ProviderName(
|
285 schuur 1.11 provider.getProperty(provider.findProperty
|
286 schuur 1.7 ("Name")).getValue ().toString (),
|
287 schuur 1.11 providerModule.getProperty(providerModule.findProperty
|
288 schuur 1.7 ("Location")).getValue().toString(),
|
289 schuur 1.11 providerModule.getProperty(providerModule.findProperty
|
290 schuur 1.7 ("InterfaceType")).getValue().toString(),
|
291 schuur 1.11 ProviderType::INSTANCE);
|
292 schuur 1.7 }
293 break;
|
294 schuur 1.9 case ProviderType_ASSOCIATION:
|
295 schuur 1.12 if (_prm->lookupInstanceProvider(providerName.getNameSpace(),providerName.getClassName(),
|
296 schuur 1.7 provider,providerModule,1)) {
|
297 schuur 1.11 if (test) checkBlocked(providerModule);
|
298 schuur 1.12 return ProviderName(
|
299 schuur 1.11 provider.getProperty(provider.findProperty
|
300 schuur 1.7 ("Name")).getValue ().toString (),
|
301 schuur 1.11 providerModule.getProperty(providerModule.findProperty
|
302 schuur 1.7 ("Location")).getValue().toString(),
|
303 schuur 1.11 providerModule.getProperty(providerModule.findProperty
|
304 schuur 1.7 ("InterfaceType")).getValue().toString(),
|
305 schuur 1.11 ProviderType::ASSOCIATION);
|
306 schuur 1.8 }
307 break;
|
308 schuur 1.9 case ProviderType_QUERY:
|
309 schuur 1.12 if (_prm->lookupInstanceProvider(providerName.getNameSpace(),providerName.getClassName(),
|
310 schuur 1.8 provider,providerModule,0,&hasNoQuery)) {
|
311 schuur 1.11 if (test) checkBlocked(providerModule);
|
312 schuur 1.12 return ProviderName(
|
313 schuur 1.11 provider.getProperty(provider.findProperty
|
314 schuur 1.8 ("Name")).getValue ().toString (),
|
315 schuur 1.11 providerModule.getProperty(providerModule.findProperty
|
316 schuur 1.8 ("Location")).getValue().toString(),
|
317 schuur 1.11 providerModule.getProperty(providerModule.findProperty
|
318 schuur 1.8 ("InterfaceType")).getValue().toString(),
|
319 schuur 1.11 ProviderType::INSTANCE);
|
320 schuur 1.7 }
321 break;
|
322 schuur 1.11 case ProviderType_METHOD:
|
323 schuur 1.12 if (_prm->lookupMethodProvider(providerName.getNameSpace(),providerName.getClassName(),
|
324 schuur 1.11 providerName.getMethodName(),provider,providerModule)) {
325 if (test) checkBlocked(providerModule);
|
326 schuur 1.12 return ProviderName(
|
327 schuur 1.11 provider.getProperty(provider.findProperty
328 ("Name")).getValue ().toString (),
329 providerModule.getProperty(providerModule.findProperty
330 ("Location")).getValue().toString(),
331 providerModule.getProperty(providerModule.findProperty
332 ("InterfaceType")).getValue().toString(),
333 ProviderType::METHOD);
334 }
335 break;
336 default:
|
337 schuur 1.12 CIMObjectPath objectName(String::EMPTY,
338 providerName.getNameSpace(),providerName.getClassName());
|
339 schuur 1.7 temp = _lookupProvider(objectName);
340 }
341
|
342 chip 1.2 return(temp);
|
343 chip 1.1 }
344
|
345 chip 1.2 Boolean ProviderRegistrar::insertProvider(const ProviderName & providerName)
|
346 chip 1.1 {
|
347 chip 1.2 // assume the providerName is in ProviderName format
348 ProviderName name(providerName);
|
349 chip 1.1
350 return(false);
351 }
352
|
353 chip 1.2 Boolean ProviderRegistrar::removeProvider(const ProviderName & providerName)
|
354 chip 1.1 {
|
355 chip 1.2 // assume the providerName is in ProviderName format
356 ProviderName name(providerName);
|
357 chip 1.1
358 return(false);
359 }
|
360 chip 1.2
361 void SetProviderRegistrationManager(ProviderRegistrationManager * p)
|
362 chip 1.1 {
|
363 chip 1.2 _prm = p;
|
364 chip 1.1 }
365
|
366 chip 1.2 ProviderRegistrationManager * GetProviderRegistrationManager(void)
|
367 chip 1.1 {
|
368 chip 1.2 return(_prm);
|
369 chip 1.1 }
370
371 PEGASUS_NAMESPACE_END
|