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