(file) Return to ProviderRegistrar.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / ProviderManager2

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2