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

  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.7.2.1 // 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.7.2.1 #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                        cimObjectPath.toString(),
183                        providerName,
184                        moduleLocation,
185                        interfaceType,
186                        0);
187 chip   1.1     
188 chip   1.2         return(temp);
189                }
190                
191                ProviderRegistrar::ProviderRegistrar(void)
192                {
193                }
194                
195                ProviderRegistrar::~ProviderRegistrar(void)
196                {
197                }
198 chip   1.1     
199 schuur 1.7.2.1 static const Uint16 _MODULE_STOPPING = 9;
200                static const Uint16 _MODULE_STOPPED  = 10;
201                
202                static void checkBlocked(CIMInstance &pm)
203                {
204                    PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "checkBlocked");
205                    
206                    Array<Uint16> operationalStatus;
207                
208                    Uint32 pos = pm.findProperty(CIMName ("OperationalStatus"));
209                    if(pos == PEG_NOT_FOUND) {
210                        PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
211                            "OperationalStatus not found.");
212                        PEG_METHOD_EXIT();
213                	//l10n
214                        //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "provider lookup failed.");
215                        throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
216                        					"ProviderManager.ProviderManagerService.PROVIDER_LOOKUP_FAILED",
217                        					"provider lookup failed."));
218                    }
219                
220 schuur 1.7.2.1     pm.getProperty(pos).getValue().get(operationalStatus);
221                    for(Uint32 i = 0; i < operationalStatus.size(); i++) {
222                        if(operationalStatus[i] == _MODULE_STOPPED ||
223                	   operationalStatus[i] == _MODULE_STOPPING) {
224                            PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
225                                "Provider blocked.");
226                            PEG_METHOD_EXIT();
227                			//l10n
228                            //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ACCESS_DENIED, "provider blocked.");
229                            throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED, MessageLoaderParms(
230                            			"ProviderManager.ProviderManagerService.PROVIDER_BLOCKED",
231                            			"provider blocked."));
232                        }
233                    }
234                }
235                
236 chip   1.2     // need at least the object and the one capability.
237                // for example,
238                //  "//localhost/root/cimv2:CIM_ComputerSystem", INSTANCE
239                //  "//localhost/root/cimv2:CIM_ComputerSystem", METHOD
240                //  "//localhost/root/cimv2:CIM_AssociatedComputerSystem", ASSOCIATION
241                //  "//localhost/root/cimv2:CIM_ComputerSystemFailure", INDICATION
242                
243                // the method will return the logical and physical provider names associated with the object and capability.
244 chip   1.1     
245 schuur 1.7.2.1 ProviderName ProviderRegistrar::findProvider(const ProviderName & providerName, Boolean test)
246 chip   1.2     {
247                    CIMObjectPath objectName = providerName.getObjectName();
248                    Uint32 flags = providerName.getCapabilitiesMask();
249 chip   1.1     
250 chip   1.2         // validate arguments
251 chip   1.3         if(objectName.getNameSpace().isNull() || objectName.getClassName().isNull())
252 chip   1.2         {
253                        throw Exception("Invalid argument.");
254                    }
255 schuur 1.7         
256                    CIMInstance provider;
257                    CIMInstance providerModule;
258                    ProviderName temp;
259                   
260                   switch (flags) {
261                       case 2: //ProviderType::INSTANCE
262                          if (_prm->lookupInstanceProvider(objectName.getNameSpace(),objectName.getClassName(),
263                                provider,providerModule,0)) {
264 schuur 1.7.2.1               if (test) checkBlocked(providerModule);
265 schuur 1.7     	      return ProviderName(providerName.getObjectName(),
266 schuur 1.7.2.1 	            provider.getProperty(provider.findProperty
267 schuur 1.7                            ("Name")).getValue ().toString (),
268                		    providerModule.getProperty(providerModule.findProperty
269                                       ("Location")).getValue().toString(),
270                	            providerModule.getProperty(providerModule.findProperty
271                                       ("InterfaceType")).getValue().toString(),
272                		    ProviderType::INSTANCE);
273                          }
274                          break;
275                       case 5: //ProviderType::ASSOCIATION
276                          if (_prm->lookupInstanceProvider(objectName.getNameSpace(),objectName.getClassName(),
277                                provider,providerModule,1)) {
278 schuur 1.7.2.1               if (test) checkBlocked(providerModule);
279 schuur 1.7     	      return ProviderName(providerName.getObjectName(),
280 schuur 1.7.2.1 	            provider.getProperty(provider.findProperty
281 schuur 1.7                            ("Name")).getValue ().toString (),
282                		    providerModule.getProperty(providerModule.findProperty
283                                       ("Location")).getValue().toString(),
284                	            providerModule.getProperty(providerModule.findProperty
285                                       ("InterfaceType")).getValue().toString(),
286                		    ProviderType::ASSOCIATION);
287                          }
288                          break;
289                       default:
290                          temp = _lookupProvider(objectName);
291                    }
292                    
293 chip   1.2         return(temp);
294 chip   1.1     }
295                
296 chip   1.2     Boolean ProviderRegistrar::insertProvider(const ProviderName & providerName)
297 chip   1.1     {
298 chip   1.2         // assume the providerName is in ProviderName format
299                    ProviderName name(providerName);
300 chip   1.1     
301                    return(false);
302                }
303                
304 chip   1.2     Boolean ProviderRegistrar::removeProvider(const ProviderName & providerName)
305 chip   1.1     {
306 chip   1.2         // assume the providerName is in ProviderName format
307                    ProviderName name(providerName);
308 chip   1.1     
309                    return(false);
310                }
311 chip   1.2     
312                void SetProviderRegistrationManager(ProviderRegistrationManager * p)
313 chip   1.1     {
314 chip   1.2         _prm = p;
315 chip   1.1     }
316                
317 chip   1.2     ProviderRegistrationManager * GetProviderRegistrationManager(void)
318 chip   1.1     {
319 chip   1.2         return(_prm);
320 chip   1.1     }
321                
322                PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2