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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2