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

  1 karl  1.59 //%2006////////////////////////////////////////////////////////////////////////
  2 karl  1.1  //
  3 karl  1.12 // 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.3  // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.12 // 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.18 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.59 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12            // EMC Corporation; Symantec Corporation; The Open Group.
 13 karl  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.59 // 
 21 karl  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 s.manicka 1.66.4.2 //=============================================================================
 31 karl      1.1      
 32                    ///////////////////////////////////////////////////////////////////////////////
 33 karl      1.5      //  Interop Provider - This provider services those classes from the
 34 a.dunfey  1.64     //  DMTF Interop schema in an implementation compliant with the SMI-S v1.1
 35                    //  Server Profile
 36 karl      1.1      //
 37 a.dunfey  1.64     //  Please see PG_ServerProfile20.mof in the directory
 38                    //  $(PEGASUS_ROOT)/Schemas/Pegasus/InterOp/VER20 for retails regarding the
 39                    //  classes supported by this control provider.
 40 david.dillard 1.32     //
 41 a.dunfey      1.64     //  Interop forces all creates to the PEGASUS_NAMESPACENAME_INTEROP 
 42                        //  namespace. There is a test on each operation that returns 
 43                        //  the Invalid Class CIMDError
 44                        //  This is a control provider and as such uses the Tracer functions
 45                        //  for data and function traces.  Since we do not expect high volume
 46                        //  use we added a number of traces to help diagnostics.
 47 karl          1.1      ///////////////////////////////////////////////////////////////////////////////
 48                        
 49                        #include <Pegasus/Common/Config.h>
 50                        #include <Pegasus/Common/PegasusVersion.h>
 51                        
 52                        #include <cctype>
 53                        #include <iostream>
 54                        
 55                        #include "InteropProvider.h"
 56 a.dunfey      1.64     #include "InteropProviderUtils.h"
 57                        #include "InteropConstants.h"
 58                        
 59 karl          1.8      #include <Pegasus/Common/StatisticalData.h>
 60 karl          1.1      
 61                        PEGASUS_USING_STD;
 62 a.dunfey      1.65     PEGASUS_NAMESPACE_BEGIN
 63 karl          1.1      
 64 a.dunfey      1.64     /*****************************************************************************
 65                         *
 66                         * The following are constants representing property names for the classes
 67                         * managed by the Interop Provider. Where multiple classes have properties of
 68                         * the same name, there will be a common CIMName object defined, and a macro
 69                         * defined that points to the common CIMName object, but whose macro name
 70                         * reflects the class in which the property is used.
 71                         *
 72                         *****************************************************************************/
 73 karl          1.1      
 74 tony          1.6      //
 75 a.dunfey      1.64     // Constructor for the InteropProvider control provider
 76 tony          1.6      //
 77 a.dunfey      1.64     InteropProvider::InteropProvider(CIMRepository * rep) : repository(rep),
 78 a.dunfey      1.65         hostName(System::getHostName()), providerInitialized(false),
 79                            profileIds(Array<String>()), conformingElements(Array<CIMNameArray>()),
 80                            elementNamespaces(Array<CIMNamespaceArray>())
 81 a.dunfey      1.64     {
 82                            PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,"InteropProvider::InteropProvider");
 83 tony          1.6      
 84 a.dunfey      1.65     #ifndef PEGASUS_DISABLE_PERFINST
 85                            try
 86                            {
 87                                initProvider();
 88 w.white       1.34         }
 89 a.dunfey      1.65         catch(const Exception & e)
 90 a.dunfey      1.64         {
 91 a.dunfey      1.65             // Provider initialization may fail if the repository is not
 92                                // populated
 93 karl          1.26         }
 94 a.dunfey      1.65     #endif
 95                            
 96 a.dunfey      1.64         PEG_METHOD_EXIT();
 97 karl          1.26     }
 98                        
 99 a.dunfey      1.64     //
100                        // Local version of getInstance to be used by other functions in the the
101                        // provider. Returns a single instance. Note that it always returns an
102                        // instance. If none was found, it is uninialitized.
103                        //
104                        CIMInstance InteropProvider::localGetInstance(
105                            const OperationContext & context,
106                            const CIMObjectPath & instanceName,
107                            const CIMPropertyList & propertyList)
108 karl          1.52     {
109 a.dunfey      1.64         PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::localGetInstance");
110 karl          1.40     
111 marek         1.66.4.1     PEG_TRACE((TRC_CONTROLPROVIDER, Tracer::LEVEL4,
112 a.dunfey      1.64             "%s getInstance. instanceName= %s , PropertyList= %s",
113                                thisProvider,
114                                (const char *)instanceName.toString().getCString(),
115 marek         1.66.4.1         (const char *)propertyListToString(propertyList).getCString()));
116 karl          1.40     
117 a.dunfey      1.64         // Test if we're looking for something outside of our namespace. This will
118                            // happen during associators calls from PG_RegisteredProfile instances
119                            // through the PG_ElementConformsToProfile association
120                            CIMNamespaceName opNamespace = instanceName.getNameSpace();
121                            CIMName opClass = instanceName.getClassName();
122                            if(opNamespace != PEGASUS_NAMESPACENAME_INTEROP &&
123                                opClass != PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE)
124                            {
125                                AutoMutex mut(interopMut);
126                                return cimomHandle.getInstance(context, opNamespace,
127                                    instanceName, false, false, false, propertyList);
128                            }
129 karl          1.40     
130 a.dunfey      1.64         // Create reference from host, namespace, class components of
131                            // instance name
132                            CIMObjectPath ref;
133                            ref.setHost(instanceName.getHost());
134                            ref.setClassName(opClass);
135                            ref.setNameSpace(opNamespace);
136 karl          1.26     
137 a.dunfey      1.64         // Enumerate instances for this class. Returns all instances
138                            // Note that this returns paths setup and instances already
139                            // filtered per the input criteria.
140                            Array<CIMInstance> instances =  localEnumerateInstances(
141                                context,
142                                ref,
143                                propertyList);
144 karl          1.26     
145 a.dunfey      1.64         // deliver a single instance if found.
146                            CIMInstance retInstance;
147 karl          1.26     
148 a.dunfey      1.64         bool found = false;
149                            for(Uint32 i = 0, n = instances.size(); i < n; i++)
150 tony          1.6          {
151 a.dunfey      1.64             CIMObjectPath currentInstRef = instances[i].getPath();
152                                currentInstRef.setHost(instanceName.getHost());
153                                currentInstRef.setNameSpace(instanceName.getNameSpace());
154                                if(instanceName == currentInstRef)
155 tony          1.6              {
156 a.dunfey      1.64                 retInstance = instances[i];
157                                    found = true;
158                                    break;
159 tony          1.6              }
160                            }
161 karl          1.8      
162 a.dunfey      1.64         if(!found)
163 karl          1.8          {
164 a.dunfey      1.64           cout << "Coule not find instance: " << instanceName.toString() << endl;
165 karl          1.8          }
166 a.dunfey      1.64         PEG_METHOD_EXIT();
167                            return retInstance;
168 tony          1.6      }
169 karl          1.11     
170 a.dunfey      1.64     
171                        //
172                        // Local version of enumerateInstances to be used by other functions in the
173                        // provider. Note that this delivers instances as a group rather than one
174                        // at a time. This design point may need to be revisited if this provider
175                        // is used in environments such that returning segmented responses would have
176                        // significant performance advantages. For now, that doesn't seem to be the
177                        // case.
178                        //
179                        Array<CIMInstance> InteropProvider::localEnumerateInstances(
180                            const OperationContext & context,
181                            const CIMObjectPath & ref,
182                            const CIMPropertyList& propertyList)
183 david.dillard 1.32     {
184 a.dunfey      1.64         PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
185                                "InteropProvider::localEnumerateInstances()");
186                            const CIMName & className = ref.getClassName();
187 marek         1.66.4.1     PEG_TRACE((TRC_CONTROLPROVIDER, Tracer::LEVEL4,
188 a.dunfey      1.64             "%s enumerateInstances. referenc= %s , PropertyList= %s",
189                                thisProvider,
190                                (const char *)className.getString().getCString(),
191 marek         1.66.4.1         (const char *)propertyListToString(propertyList).getCString()));
192 david.dillard 1.32     
193 a.dunfey      1.64         // Verify that ClassName is correct and get its enum value
194                            TARGET_CLASS classEnum  = translateClassInput(className);
195 tony          1.6      
196 a.dunfey      1.64         Array<CIMInstance> instances;
197                            switch(classEnum)
198                            {
199                                case PG_OBJECTMANAGER:
200                                {
201                                    instances.append(getObjectManagerInstance());
202                                    break;
203                                }
204                                case PG_CIMXMLCOMMUNICATIONMECHANISM:
205                                {
206                                    instances = enumCIMXMLCommunicationMechanismInstances();
207                                    break;
208                                }
209                                case PG_NAMESPACEINMANAGER:
210                                {
211                                    instances = enumNamespaceInManagerInstances();
212                                    break;
213                                }
214                                case PG_COMMMECHANISMFORMANAGER:
215                                {
216                                    instances = enumCommMechanismForManagerInstances();
217 a.dunfey      1.64                 break;
218                                }
219                                case PG_NAMESPACE:
220                                {
221                                    instances = enumNamespaceInstances();
222                                    break;
223                                }
224                                case PG_REGISTEREDPROFILE:
225                                {
226                                    instances = enumRegisteredProfileInstances();
227                                    break;
228                                }
229                                case PG_REGISTEREDSUBPROFILE:
230                                {
231                                    instances = enumRegisteredSubProfileInstances();
232                                    break;
233                                }
234                                case PG_REFERENCEDPROFILE:
235                                {
236                                    instances = enumReferencedProfileInstances();
237                                    break;
238 a.dunfey      1.64             }
239                                case PG_ELEMENTCONFORMSTOPROFILE:
240                                {
241                                    instances = enumElementConformsToProfileInstances(context,
242                                        ref.getNameSpace());
243                                    break;
244                                }
245 s.manicka     1.66.4.2         case PG_ELEMENTCONFORMSTOPROFILE_RP_RP:
246                                {
247                                    instances = enumElementConformsToProfileRPRPInstances(
248                                        context,
249                                        ref.getNameSpace());
250                                    break;
251                                }
252 a.dunfey      1.64             case PG_SUBPROFILEREQUIRESPROFILE:
253                                {
254                                    instances = enumSubProfileRequiresProfileInstances();
255                                    break;
256                                }
257                                case PG_SOFTWAREIDENTITY:
258                                {
259                                    instances = enumSoftwareIdentityInstances();
260                                    break;
261                                }
262                                case PG_ELEMENTSOFTWAREIDENTITY:
263                                {
264                                    instances = enumElementSoftwareIdentityInstances();
265                                    break;
266                                }
267                                case PG_INSTALLEDSOFTWAREIDENTITY:
268                                {
269                                    instances = enumInstalledSoftwareIdentityInstances();
270                                    break;
271                                }
272                                case PG_COMPUTERSYSTEM:
273 a.dunfey      1.64             {
274                                    instances.append(getComputerSystemInstance());
275                                    break;
276                                }
277                                case PG_HOSTEDOBJECTMANAGER:
278                                {
279                                    instances.append(getHostedObjectManagerInstance());
280                                    break;
281                                }
282                                case PG_HOSTEDACCESSPOINT:
283                                {
284                                    instances = enumHostedAccessPointInstances();
285                                    break;
286                                }
287                                default:
288                                    PEG_METHOD_EXIT();
289                                    throw CIMNotSupportedException(className.getString() +
290                                      " not supported by Interop Provider enumerate");
291                            }
292 karl          1.41     
293 a.dunfey      1.64         // Filter and deliver the resulting instances
294                            for (Uint32 i = 0 ; i < instances.size() ; i++)
295                            {
296                                normalizeInstance(instances[i], ref, false,
297                                    false, propertyList);
298                            }
299 tony          1.6      
300 a.dunfey      1.64         PEG_METHOD_EXIT();
301                            return instances;
302 tony          1.6      }
303 karl          1.55     
304 a.dunfey      1.64     //
305                        // Class that determines whether or not the origin class in an association
306                        // operation is valid for the given association class, and also determines
307                        // the origin and target "roles". These values generally correspond to the
308                        // role and resultRole parameter of an associators/associatorNames operation.
309                        //
310                        bool InteropProvider::validAssocClassForObject(
311 s.manicka     1.66.4.2     const OperationContext & context,
312                            const CIMName & assocClass, 
313                            const CIMObjectPath & objectName,
314 a.dunfey      1.64         const CIMNamespaceName & opNamespace,
315 s.manicka     1.66.4.2     String & originProperty, 
316                            String & targetProperty)
317 a.dunfey      1.64     {
318                            PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
319                                "InteropProvider::validAssocClassForObject()");
320                            TARGET_CLASS assocClassEnum = translateClassInput(assocClass);
321                            TARGET_CLASS originClassEnum;
322 s.manicka     1.66.4.2     CIMName originClass = objectName.getClassName();
323 a.dunfey      1.64         // If the association class is PG_ElementConformsToProfile, we'll have to
324                            // do some special processing in case the origin instance for the operation
325                            // is managed by another provider.
326                            if(assocClassEnum == PG_ELEMENTCONFORMSTOPROFILE)
327                            {
328                                // Test if the origin is an element managed by another provider
329                                // that has implemented a registered profile.
330                                if(opNamespace != PEGASUS_NAMESPACENAME_INTEROP ||
331                                    (originClass != PEGASUS_CLASSNAME_PG_REGISTEREDPROFILE &&
332 s.manicka     1.66.4.2              originClass != PEGASUS_CLASSNAME_PG_OBJECTMANAGER ))
333 a.dunfey      1.64             {
334                                    //
335                                    // Search the cached conformingElements list for the originClass,
336                                    // returning false if it is not found
337                                    //
338                                    bool found = false;
339 karl          1.1      
340 a.dunfey      1.64                 PEGASUS_ASSERT(conformingElements.size() ==
341                                        elementNamespaces.size());
342                                    for(Uint32 i = 0, n = conformingElements.size(); i < n; ++i)
343                                    {
344                                        CIMNameArray & elementList = conformingElements[i];
345                                        CIMNamespaceArray & namespaceList = elementNamespaces[i];
346                                        PEGASUS_ASSERT(elementList.size() == namespaceList.size());
347                                        for(Uint32 j = 0, m = elementList.size(); j < m; ++j)
348                                        {
349                                            CIMName & curElement = elementList[j];
350                                            if((curElement == originClass ||
351                                              curElement.getString().find(PEGASUS_DYNAMIC) == 0) &&
352                                              opNamespace == namespaceList[j])
353                                            {
354                                                found = true;
355                                                break;
356                                            }
357                                        }
358                                        if(found)
359                                            break;
360                                    }
361 karl          1.28     
362 a.dunfey      1.64                 if(!found)
363                                        return false;
364                                }
365                            }
366                            else
367                            {
368                                // Otherwise, just get the enum value representing the origin class
369                                // for this operation
370                                originClassEnum = translateClassInput(originClass);
371                            }
372 karl          1.1      
373 a.dunfey      1.64         CIMName expectedTargetRole;
374                            CIMName expectedOriginRole;
375 tony          1.6      
376 s.manicka     1.66.4.2     Array<CIMName> propNames;
377                            String profileName;
378                            CIMPropertyList propertyList;
379                            CIMInstance tmpInstance;
380                            Uint32 index;
381                            propNames.clear();
382                            
383 a.dunfey      1.64         //
384                            // Set the target and origin role values. Note that if these values are
385                            // not set following the switch block, that implies that the origin class
386                            // is not valid for the supplied association class.
387                            //
388                            switch(assocClassEnum)
389 tony          1.6          {
390 a.dunfey      1.64           case PG_NAMESPACEINMANAGER:
391                                  if(originClassEnum == PG_OBJECTMANAGER)
392                                  {
393                                      expectedTargetRole = PROPERTY_DEPENDENT;
394                                      expectedOriginRole = PROPERTY_ANTECEDENT;
395                                  }
396                                  else if(originClassEnum == PG_NAMESPACE)
397                                  {
398                                      expectedTargetRole = PROPERTY_ANTECEDENT;
399                                      expectedOriginRole = PROPERTY_DEPENDENT;
400                                  }
401                                  break;
402                              case PG_COMMMECHANISMFORMANAGER:
403                                  if(originClassEnum == PG_OBJECTMANAGER)
404                                  {
405                                      expectedTargetRole = PROPERTY_DEPENDENT;
406                                      expectedOriginRole = PROPERTY_ANTECEDENT;
407                                  }
408                                  else if(originClassEnum == PG_CIMXMLCOMMUNICATIONMECHANISM)
409                                  {
410                                      expectedTargetRole = PROPERTY_ANTECEDENT;
411 a.dunfey      1.64                   expectedOriginRole = PROPERTY_DEPENDENT;
412                                  }
413                                  break;
414                              case PG_ELEMENTCONFORMSTOPROFILE:
415                                  if(originClass.equal(PEGASUS_CLASSNAME_PG_REGISTEREDPROFILE))
416                                  {
417                                      expectedTargetRole =
418                                          ELEMENTCONFORMSTOPROFILE_PROPERTY_MANAGEDELEMENT;
419                                      expectedOriginRole =
420                                          ELEMENTCONFORMSTOPROFILE_PROPERTY_CONFORMANTSTANDARD;
421                                  }
422                                  else
423                                  {
424                                      expectedTargetRole =
425                                          ELEMENTCONFORMSTOPROFILE_PROPERTY_CONFORMANTSTANDARD;
426                                      expectedOriginRole =
427                                          ELEMENTCONFORMSTOPROFILE_PROPERTY_MANAGEDELEMENT;
428                                  }
429                                  break;
430 s.manicka     1.66.4.2       case PG_ELEMENTCONFORMSTOPROFILE_RP_RP:
431                                  propNames.append(CIMName("RegisteredName"));
432                                  propertyList = CIMPropertyList(propNames);
433                                  tmpInstance = localGetInstance(
434                                      context, 
435                                      objectName,
436                                      propertyList);
437                                  index = tmpInstance.findProperty("RegisteredName");
438                                  if (index != PEG_NOT_FOUND)
439                                  {
440                                      const CIMValue &tmpVal = 
441                                          tmpInstance.getProperty(index).getValue();
442                                      if (!tmpVal.isNull())
443                                      {
444                                          tmpVal.get(profileName);
445                                      }
446                                  }
447                                  if (String::compareNoCase(profileName, String("SMI-S")) == 0)
448                                  {
449                                      expectedTargetRole =
450                                          ELEMENTCONFORMSTOPROFILE_PROPERTY_MANAGEDELEMENT;
451 s.manicka     1.66.4.2               expectedOriginRole =
452                                          ELEMENTCONFORMSTOPROFILE_PROPERTY_CONFORMANTSTANDARD;
453                                  }
454                                  else
455                                  {
456                                      expectedTargetRole =
457                                          ELEMENTCONFORMSTOPROFILE_PROPERTY_CONFORMANTSTANDARD;
458                                      expectedOriginRole =
459                                          ELEMENTCONFORMSTOPROFILE_PROPERTY_MANAGEDELEMENT;
460                                  }
461                                  break;
462 a.dunfey      1.64           case PG_SUBPROFILEREQUIRESPROFILE:
463                                  if(originClassEnum == PG_REGISTEREDPROFILE)
464                                  {
465                                      expectedTargetRole = PROPERTY_DEPENDENT;
466                                      expectedOriginRole = PROPERTY_ANTECEDENT;
467                                  }
468                                  else if(originClassEnum == PG_REGISTEREDSUBPROFILE)
469                                  {
470                                      expectedTargetRole = PROPERTY_ANTECEDENT;
471                                      expectedOriginRole = PROPERTY_DEPENDENT;
472                                  }
473                                  break;
474 s.manicka     1.66.4.2       case PG_REFERENCEDPROFILE:
475                                  if (originClassEnum == PG_REGISTEREDSUBPROFILE)
476                                  {
477                                      expectedTargetRole = PROPERTY_ANTECEDENT;
478                                      expectedOriginRole = PROPERTY_DEPENDENT;
479                                  }
480                                  else if (originClassEnum == PG_REGISTEREDPROFILE)
481                                  {
482                                      if ((targetProperty.size() != 0) &&
483                                          (originProperty.size() != 0) &&
484                                          String::equalNoCase(targetProperty, originProperty))
485                                      {
486                                          return false;
487                                      }
488                                      if (targetProperty.size() != 0)
489                                      {
490                                          if (!(String::equalNoCase(targetProperty, "Antecedent") ||
491                                              String::equalNoCase(targetProperty, "Dependent") ))
492                                          {
493                                              return false;
494                                          }
495 s.manicka     1.66.4.2               }
496                                      if (originProperty.size() != 0)
497                                      {
498                                          if (!(String::equalNoCase(originProperty, "Antecedent") ||
499                                              String::equalNoCase(originProperty, "Dependent") ))
500                                          {
501                                              return false;
502                                          }
503                                      }
504                                      if (String::equalNoCase(originProperty, "Antecedent") &&
505                                          targetProperty.size() == 0)
506                                      {
507                                          targetProperty = String("Dependent");
508                                      }
509                                      if (String::equalNoCase(originProperty, "Dependent") &&
510                                          targetProperty.size() == 0)
511                                      {
512                                          targetProperty = String("Antecedent");
513                                      }
514                                      if (String::equalNoCase(targetProperty, "Antecedent") &&
515                                          originProperty.size() == 0)
516 s.manicka     1.66.4.2               {
517                                          originProperty = String("Dependent");
518                                      }
519                                      if (String::equalNoCase(targetProperty, "Dependent") &&
520                                          originProperty.size() == 0)
521                                      {
522                                          originProperty = String("Antecedent");
523                                      }
524                                      return true;
525                                  }
526                                  break;
527 a.dunfey      1.64           case PG_ELEMENTSOFTWAREIDENTITY:
528                                  if(originClassEnum == PG_SOFTWAREIDENTITY)
529                                  {
530                                      expectedTargetRole = PROPERTY_DEPENDENT;
531                                      expectedOriginRole = PROPERTY_ANTECEDENT;
532                                  }
533                                  else if(originClassEnum == PG_REGISTEREDPROFILE ||
534                                      originClassEnum == PG_REGISTEREDSUBPROFILE)
535                                  {
536                                      expectedTargetRole = PROPERTY_ANTECEDENT;
537                                      expectedOriginRole = PROPERTY_DEPENDENT;
538                                  }
539                                  break;
540                              case PG_INSTALLEDSOFTWAREIDENTITY:
541                                  if(originClassEnum == PG_SOFTWAREIDENTITY)
542                                  {
543                                      expectedTargetRole = INSTALLEDSOFTWAREIDENTITY_PROPERTY_SYSTEM;
544                                      expectedOriginRole =
545                                          INSTALLEDSOFTWAREIDENTITY_PROPERTY_INSTALLEDSOFTWARE;
546                                  }
547                                  else if(originClassEnum == PG_COMPUTERSYSTEM)
548 a.dunfey      1.64               {
549                                      expectedTargetRole =
550                                          INSTALLEDSOFTWAREIDENTITY_PROPERTY_INSTALLEDSOFTWARE;
551                                      expectedOriginRole = INSTALLEDSOFTWAREIDENTITY_PROPERTY_SYSTEM;
552                                  }
553                                  break;
554                              case PG_HOSTEDACCESSPOINT:
555                                  if(originClassEnum == PG_COMPUTERSYSTEM)
556                                  {
557                                      expectedTargetRole = PROPERTY_DEPENDENT;
558                                      expectedOriginRole = PROPERTY_ANTECEDENT;
559                                  }
560                                  else if(originClassEnum == PG_CIMXMLCOMMUNICATIONMECHANISM)
561                                  {
562                                      expectedTargetRole = PROPERTY_ANTECEDENT;
563                                      expectedOriginRole = PROPERTY_DEPENDENT;
564                                  }
565                              case PG_HOSTEDOBJECTMANAGER:
566                                  if(originClassEnum == PG_COMPUTERSYSTEM)
567                                  {
568                                      expectedTargetRole = PROPERTY_DEPENDENT;
569 a.dunfey      1.64                   expectedOriginRole = PROPERTY_ANTECEDENT;
570                                  }
571                                  else if(originClassEnum == PG_OBJECTMANAGER)
572                                  {
573                                      expectedTargetRole = PROPERTY_ANTECEDENT;
574                                      expectedOriginRole = PROPERTY_DEPENDENT;
575                                  }
576                                  break;
577                              default:
578                                  break;
579 tony          1.6          }
580 a.dunfey      1.64     
581 karl          1.5          //
582 a.dunfey      1.64         // The rest of this method checks to see if target role and origin roles
583                            // were found for the association and origin class combination and, if
584                            // found, checks against the input target and origin roles if provided.
585                            // Failure for any of these tests points to an invalid association
586                            // traversal request.
587 karl          1.5          //
588 a.dunfey      1.64         if(expectedTargetRole.isNull() ||
589                                expectedOriginRole.isNull())
590 tony          1.6          {
591                                PEG_METHOD_EXIT();
592 a.dunfey      1.64             return false;
593 tony          1.6          }
594                        
595 a.dunfey      1.64         if(targetProperty.size() == 0)
596 karl          1.5          {
597 a.dunfey      1.64             targetProperty = expectedTargetRole.getString();
598 karl          1.5          }
599 a.dunfey      1.64         else if(!expectedTargetRole.equal(targetProperty))
600 karl          1.48         {
601 a.dunfey      1.64             PEG_METHOD_EXIT();
602                                return false;
603 karl          1.48         }
604 david.dillard 1.32     
605 a.dunfey      1.64         if(originProperty.size() == 0)
606 tony          1.6          {
607 a.dunfey      1.64             originProperty = expectedOriginRole.getString();
608 tony          1.6          }
609 a.dunfey      1.64         else if(!expectedOriginRole.equal(originProperty))
610 tony          1.6          {
611                                PEG_METHOD_EXIT();
612 a.dunfey      1.64             return false;
613 tony          1.6          }
614 a.dunfey      1.64         
615 tony          1.6          PEG_METHOD_EXIT();
616 a.dunfey      1.64         return true;
617 karl          1.5      }
618 karl          1.28     
619 a.dunfey      1.64     //
620                        // Local version of the references operation. It validates the input
621                        // parameters, setting the origin and target property values if not set
622                        // already, and then performs an enumeration on the association class. It then
623                        // filters the results of that enumeration to see if one of the reference
624                        // properties matches the objectName parameter passed into the method. If so,
625                        // then it is added to the array of association instances to be returned.
626                        //
627                        Array<CIMInstance> InteropProvider::localReferences(
628                            const OperationContext & context,
629                            const CIMObjectPath & objectName,
630                            const CIMName & assocClass,
631                            String & originProperty,
632                            String & targetProperty,
633                            const CIMPropertyList & propertyList,
634                            const CIMName & targetClass)
635 karl          1.5      {
636 tony          1.6          PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
637 a.dunfey      1.64             "InteropProvider::localReferences()");
638 karl          1.5      
639 a.dunfey      1.64         Array<CIMInstance> instances;
640                            CIMName originClass = objectName.getClassName();
641                        
642                            Array<CIMName> targetSubclasses;
643                            CIMNamespaceName lastTargetNamespace;
644                            CIMNamespaceName originNamespace(objectName.getNameSpace());
645                        
646                            // Check that the association traversal request is valid
647 s.manicka     1.66.4.2     if (validAssocClassForObject(
648                                context, 
649                                assocClass, 
650                                objectName,
651                                originNamespace, 
652                                originProperty, 
653                                targetProperty))
654 a.dunfey      1.64         {
655                                // retrieve all of the association class instances
656                                Array<CIMInstance> localInstances = localEnumerateInstances(context,
657                                    CIMObjectPath(hostName, originNamespace,
658                                        assocClass));
659                                // Filter the association class instances based on the origin instance
660                                // and other input parameters.
661                                for(Uint32 i = 0, n = localInstances.size(); i < n; ++i)
662                                {
663                                    CIMInstance & currentInstance = localInstances[i];
664                                    CIMObjectPath originPath = getRequiredValue<CIMObjectPath>(
665                                        currentInstance, originProperty);
666                                    originPath.setNameSpace(objectName.getNameSpace());
667                                    originPath.setHost(objectName.getHost());
668                                    // Only include instances where the origin instance is present in
669                                    // the association.
670                                    if(originPath.identical(objectName))
671 karl          1.5                  {
672 a.dunfey      1.64                     if(!targetClass.isNull())
673 karl          1.5                      {
674 a.dunfey      1.64                         // Have to check if the target reference is of the
675                                            // targetClass type. We first must determine all the
676                                            // possible subclasses of the targetClass in the target
677                                            // namespace.
678                                            CIMObjectPath targetPath = getRequiredValue<CIMObjectPath>(
679                                                currentInstance, targetProperty);
680                        
681                                            CIMNamespaceName targetNamespace(
682                                                targetPath.getNameSpace());
683                                            if(targetNamespace.isNull())
684                                            {
685                                                targetNamespace = originNamespace;
686                                                targetPath.setNameSpace(targetNamespace);
687                                            }
688                                            if(targetNamespace != lastTargetNamespace)
689                                            {
690                                                try
691                                                {
692                                                    targetSubclasses = repository->enumerateClassNames(
693                                                        targetNamespace, targetClass, true);
694                                                }
695 a.dunfey      1.64                             catch(...)
696                                                {
697                                                    // If an exception was thrown during enumeration,
698                                                    // then the base class didn't exist in the
699                                                    // namespace, so the target instance retrieved
700                                                    // must not match the targetClass parameter.
701                                                    continue;
702                                                }
703                                                targetSubclasses.append(targetClass);
704                                                lastTargetNamespace = targetNamespace;
705                                            }
706 david.dillard 1.32     
707 a.dunfey      1.64                         // Try to find the targetPath's class in the search space
708                                            CIMName targetPathClass = targetPath.getClassName();
709                                            for(Uint32 j = 0, m = targetSubclasses.size(); j < m; ++j)
710                                            {
711                                                if(targetPathClass == targetSubclasses[j])
712                                                {
713                                                    instances.append(currentInstance);
714                                                    break;
715                                                }
716                                            }
717                                        }
718                                        else
719 karl          1.46                     {
720 a.dunfey      1.64                         instances.append(currentInstance);
721 karl          1.46                     }
722 tony          1.6                  }
723 karl          1.1              }
724 karl          1.46         }
725                        
726                            PEG_METHOD_EXIT();
727 a.dunfey      1.64         return instances;
728 karl          1.1      }
729                        
730 a.dunfey      1.64     
731                        //
732                        // Builds an instance of the class named className. Gets Class defintion and
733                        // fills in the correct properties from the class.  This requires a repository
734                        // getClass request for each instance built. The skeleton is built by
735                        // creating the instance and copying qualifiers and properties from
736                        // the class. Finally the instance is cloned to separate it from the
737                        // original objects.
738                        // NOTE: This is very inefficient for anything larger than a few instances.
739                        // We should separate the get from the createSkeleton.
740                        // @param className CIMName of the class for which the instance is to be built
741                        // @return CIMInstance of this class with properties complete.
742                        // @exception passes on any exceptions received from the repository request.
743                        //
744                        CIMInstance InteropProvider::buildInstanceSkeleton(
745                              const CIMNamespaceName & nameSpace,
746                              const CIMName& className,
747                              CIMClass& returnedClass)
748 karl          1.1      {
749 tony          1.6          PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
750 a.dunfey      1.64             "InteropProvider::_buildInstanceSkeleton()");
751                            // get class with lo = false, qualifier = true classorig = true
752                            returnedClass = repository->getClass(nameSpace,
753                                className, false, true, true);
754                            CIMInstance skeleton = returnedClass.buildInstance(true,true,
755                                CIMPropertyList());
756 karl          1.46     
757                            PEG_METHOD_EXIT();
758 a.dunfey      1.64         return skeleton;
759 karl          1.1      }
760                        
761 karl          1.46     
762 a.dunfey      1.64     CIMInstance InteropProvider::buildDependencyInstance(
763                            const String & antecedentId,
764                            const CIMName & antecedentClass,
765                            const String & dependentId,
766                            const CIMName & dependentClass,
767                            const CIMClass & dependencyClass)
768 karl          1.1      {
769 a.dunfey      1.64         Array<CIMKeyBinding> dependentKeys;
770 karl          1.52     
771 a.dunfey      1.64         dependentKeys.append(CIMKeyBinding(
772                                COMMON_PROPERTY_INSTANCEID,
773                                dependentId,CIMKeyBinding::STRING));
774 karl          1.46     
775 a.dunfey      1.64         return buildDependencyInstanceFromPaths(
776                                buildDependencyReference(hostName, antecedentId, antecedentClass),
777                                buildDependencyReference(hostName, dependentId, dependentClass),
778                                dependencyClass);
779 tony          1.6      }
780 karl          1.46     
781 a.dunfey      1.65     void InteropProvider::initProvider()
782                        {
783                            if(providerInitialized)
784                                return;
785                            // Placed METHOD_ENTER trace statement after checking whether the
786                            // provider is initialized because this method will be called for every
787                            // operation through the InteropProvider, and this method is only
788                            // interesting the first time it is successfully run.
789                            PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
790                                "InteropProvider::initProvider()");
791                        
792                            AutoMutex lock(interopMut);
793                            if(!providerInitialized)
794                            {
795                                //
796                                // Initialize the object manager instance for the CIM Server, and
797                                // retrieve the object manager's name property. This is retrieved once
798                                // and stored for use in constructing other instances requiring its
799                                // value.
800                                //
801                                CIMInstance objectManager = getObjectManagerInstance();
802 a.dunfey      1.65             objectManager.getProperty(objectManager.findProperty(
803                                    OM_PROPERTY_NAME)).getValue().get(objectManagerName);
804                        
805                                //
806 karl          1.66             // Determine whether the CIMOM should be gathering statistical data
807 a.dunfey      1.65             // based on the GatherStatisticalData property in the object manager.
808                                //
809                                Uint32 gatherDataIndex = objectManager.findProperty(
810                                    OM_PROPERTY_GATHERSTATISTICALDATA);
811                                if(gatherDataIndex != PEG_NOT_FOUND)
812                                {
813                                    CIMConstProperty gatherDataProp =
814                                        objectManager.getProperty(gatherDataIndex);
815                                    if (gatherDataProp.getType() == CIMTYPE_BOOLEAN)
816                                    {
817                                        CIMValue gatherDataVal  = gatherDataProp.getValue();
818                                        if (!gatherDataVal.isNull())
819                                        {
820                                            Boolean gatherData;
821                                            gatherDataVal.get(gatherData);
822                                            if (gatherData == true) 
823                                            {
824                                                StatisticalData* sd = StatisticalData::current();
825                                                sd->setCopyGSD(true);
826                                            }
827                                        }
828 a.dunfey      1.65                 }
829                                }
830                        
831                                // Cache this class definition for use later.
832                                profileCapabilitiesClass = repository->getClass(
833                                    PEGASUS_NAMESPACENAME_INTEROP,
834 karl          1.66                 PEGASUS_CLASSNAME_PG_PROVIDERPROFILECAPABILITIES,
835                                    false, true, false);
836                        
837 a.dunfey      1.65             providerClassifications.append(Uint16(5)); // "Instrumentation"
838                        
839                                //
840                                // Initialize the namespaces so that all namespaces with the
841                                // CIM_ElementConformsToProfile class also have the
842 karl          1.66             // PG_ElementConformsToProfile class. Needed in order to implement
843 a.dunfey      1.65             // the cross-namespace ElementConformsToProfile association in both
844                                // directions.
845                                //
846                                Array<CIMNamespaceName> namespaceNames = 
847                                    repository->enumerateNameSpaces();
848                                CIMClass conformsClass = repository->getClass(
849                                    PEGASUS_NAMESPACENAME_INTEROP,
850                                    PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE);
851                                CIMClass profileClass = repository->getClass(
852                                    PEGASUS_NAMESPACENAME_INTEROP,
853                                    PEGASUS_CLASSNAME_PG_REGISTEREDPROFILE);
854                                for(Uint32 i = 0, n = namespaceNames.size(); i < n; ++i)
855                                {
856                                    // Check if the PG_ElementConformsToProfile class is present
857                                    CIMNamespaceName & currentNamespace = namespaceNames[i];
858                        
859                                    CIMClass tmpCimClass;
860                                    CIMClass tmpPgClass;
861                                    CIMClass tmpPgProfileClass;
862                                    try
863                                    {
864 a.dunfey      1.65                     // Look for these classes in the same try-block since the
865                                        // second depends on the first
866                                        tmpCimClass = repository->getClass(currentNamespace,
867                                            PEGASUS_CLASSNAME_CIM_ELEMENTCONFORMSTOPROFILE);
868                                        tmpPgClass = repository->getClass(currentNamespace,
869                                            PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE);
870                                    }
871                                    catch(const Exception &)
872                                    {
873                                    }
874                                    try
875                                    {
876                                        tmpPgProfileClass = repository->getClass(currentNamespace,
877                                            PEGASUS_CLASSNAME_PG_REGISTEREDPROFILE);
878                                    }
879                                    catch(const Exception &)
880                                    {
881                                        // Note: if any of the above three classes aren't found,
882                                        // an exception will be thrown, which we can ignore since it's
883                                        // an expected case
884                                        // TBD: Log trace message?
885 a.dunfey      1.65                 }
886                        
887                                    // If the CIM_ElementConformsToProfile class is present, but
888                                    // the PG_ElementConformsToProfile or PG_RegisteredProfile
889                                    // class is not, then add it to that namespace.
890                                    //
891                                    // Note that we don't have to check for the
892                                    // CIM_RegisteredProfile class because if the
893                                    // CIM_ElementConformsToProfile class is present, the
894                                    // CIM_RegisteredProfile class must also be present.
895                                    if(!tmpCimClass.isUninitialized())
896                                    {
897                                        if(tmpPgClass.isUninitialized())
898                                        {
899                                            CIMObjectPath newPath = conformsClass.getPath();
900                                            newPath.setNameSpace(currentNamespace);
901                                            conformsClass.setPath(newPath);
902                                            repository->createClass(currentNamespace,
903                                                conformsClass);
904                                        }
905                                        if(tmpPgProfileClass.isUninitialized())
906 a.dunfey      1.65                     {
907                                            CIMObjectPath newPath = conformsClass.getPath();
908                                            newPath.setNameSpace(currentNamespace);
909                                            conformsClass.setPath(newPath);
910                                            repository->createClass(currentNamespace,
911                                                profileClass);
912                                        }
913                                    }
914                                }
915                        
916                                // Now cache the Registration info used for ElementConformsToProfile
917                                cacheProfileRegistrationInfo();
918                        
919                                providerInitialized = true;
920                            }
921                        
922                            PEG_METHOD_EXIT();
923                        }
924                        
925                        PEGASUS_NAMESPACE_END
926 karl          1.1      
927 a.dunfey      1.64     // END OF FILE

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2