Ejemplo n.º 1
0
Array<CIMObjectPath> PG_TestPropertyTypes::_enumerateInstanceNames(
    const OperationContext& context,
    const CIMObjectPath& classReference)
{
    Array<CIMObjectPath> instanceNames;

    // get class definition from repository
    CIMClass cimclass = _cimom.getClass(
        context,
        classReference.getNameSpace(),
        classReference.getClassName(),
        false,
        true,
        true,
        CIMPropertyList());

    // convert instances to references;
    for (Uint32 i = 0; i < _instances.size(); i++)
    {
        CIMObjectPath tempRef = _instances[i].buildPath(cimclass);

        // ensure references are fully qualified
        tempRef.setHost(classReference.getHost());
        tempRef.setNameSpace(classReference.getNameSpace());

        instanceNames.append(tempRef);
    }

    return instanceNames;
}
Ejemplo n.º 2
0
static void _inject_object_path(
    CIMInstance& instance,
    const CIMObjectPath& objectPath,
    const char* tag)
{
    Array<CIMKeyBinding> bindings;

    bindings.append(CIMKeyBinding("Tag", tag, CIMKeyBinding::STRING));

    bindings.append(CIMKeyBinding(
        "CreationClassName", "Benchmark2", CIMKeyBinding::STRING));

    instance.setPath(CIMObjectPath(
        objectPath.getHost(),
        objectPath.getNameSpace(),
        "Benchmark2",
        bindings));
}
Ejemplo n.º 3
0
void testAssociationsHostName(
    CIMClient & client)
{
    Array<CIMObjectPath> objPaths = client.enumerateInstanceNames(
        CIMNamespaceName("test/TestProvider"),
        CIMName("TST_Person"));

    PEGASUS_TEST_ASSERT(objPaths.size() > 0);

    Array<CIMObject> objects = client.associators(
        CIMNamespaceName("test/TestProvider"),
        objPaths[0]);

    PEGASUS_TEST_ASSERT(objects.size() > 0);

    CIMObjectPath path = objects[0].getPath();    
    String pathHN = path.getHost();

    PEGASUS_TEST_ASSERT(String::equal(pathHN,"hugo"));
}
Ejemplo n.º 4
0
void CIMClientRep::compareObjectPathtoCurrentConnection(const CIMObjectPath& obj)
{

    String ObjHost = obj.getHost();
    // test if a host is given at all, if not everything is fine and we leave it at that
    if (ObjHost==String::EMPTY)
    {
        return;
    }

    MessageLoaderParms typeMismatchMessage;
    // splitting the port from hostname as we have to compare both separate
    int i = ObjHost.find(":");
    String ObjPort = String::EMPTY;
    // only if there is a ":" we should split a port address from hostname string
    if (i > 0)
    {
        ObjPort = ObjHost.subString(i+1);
        ObjHost.remove(i);

        // lets see who we are really connected to
        // should stand in UInt32 _connectPortNumber and String _connectHost;

        // comparing the stuff
        // first the easy part, comparing the ports
        Uint32 objectport = strtoul((const char*) ObjPort.getCString(), NULL, 0);

        // if port in object path does not equal port of connection throw a TypeMismatch Exception
        if (objectport != _connectPortNumber)
        {
            typeMismatchMessage = MessageLoaderParms("Client.CIMClientRep.TYPEMISMATCH_PORTMISMATCH",
                                  "Failed validation of CIM object path: port of CIMClient connection($0) and port of object path($1) not equal",
                                  _connectPortNumber, objectport);
            throw TypeMismatchException(typeMismatchMessage);
        }
    }
}
Ejemplo n.º 5
0
CIMObjectPath ObjectNormalizer::processInstanceObjectPath(
    const CIMObjectPath& cimObjectPath) const
{
    // pre-check
    if (!_enableNormalization || _cimClass.isUninitialized())
    {
        // do nothing
        return cimObjectPath;
    }

    /*
    // ATTN: moving similar logic to the response handlers because this
    // type of error should be checked regardless with or without
    // normalization enabled.
    if (cimObjectPath.getClassName().isNull())
    {
        throw CIMException(CIM_ERR_FAILED, "uninitialized object path");
    }
    */

    /*
    // ATTN: The following code is currently redundant because the CIMName
    // object validates legal names when it is constructed. It is included
    // here for completeness.
    // check class name
    if (!CIMName(cimObjectPath.getClassName()).legal())
    {
        MessageLoaderParms message(
            "Common.ObjectNormalizer.INVALID_CLASS_NAME",
            "Invalid class name: $0",
            cimObjectPath.getClassName().getString());

        throw CIMException(CIM_ERR_FAILED, message);
    }
    */

    // check class type
    if (!_cimClass.getClassName().equal(cimObjectPath.getClassName()))
    {
        MessageLoaderParms message(
            "Common.ObjectNormalizer.INVALID_CLASS_TYPE",
            "Invalid class type: $0",
            cimObjectPath.getClassName().getString());

        throw CIMException(CIM_ERR_FAILED, message);
    }

    CIMObjectPath normalizedObjectPath(
        cimObjectPath.getHost(),
        cimObjectPath.getNameSpace(),
        cimObjectPath.getClassName());

    Array<CIMKeyBinding> normalizedKeys;

    Array<CIMKeyBinding> referenceKeys = _cimClass.getPath().getKeyBindings();
    Array<CIMKeyBinding> cimKeys = cimObjectPath.getKeyBindings();

    for (Uint32 i = 0, n = referenceKeys.size(); i < n; i++)
    {
        CIMKeyBinding key;

        // override the value from the specified object
        for (Uint32 j = 0, m = cimKeys.size(); j < m; j++)
        {
            if (referenceKeys[i].getName().equal(cimKeys[j].getName()))
            {
                // check type
                if (referenceKeys[i].getType() != cimKeys[j].getType())
                {
                    MessageLoaderParms message(
                        "Common.ObjectNormalizer.INVALID_KEY_TYPE",
                        "Invalid key type: $0",
                        referenceKeys[i].getName().getString());

                    throw CIMException(CIM_ERR_FAILED, message);
                }

                key = CIMKeyBinding(referenceKeys[i].getName(),
                    cimKeys[j].getValue(), referenceKeys[i].getType());

                break;
            }
        }

        // key not found
        if (key.getName().isNull())
        {
            MessageLoaderParms message(
                "Common.ObjectNormalizer.MISSING_KEY",
                "Missing key: $0",
                referenceKeys[i].getName().getString());

            throw CIMException(CIM_ERR_FAILED, message);
        }

        normalizedKeys.append(key);
    }

    normalizedObjectPath.setKeyBindings(normalizedKeys);

    return normalizedObjectPath;
}
Ejemplo n.º 6
0
//
// Local version of the references operation. It validates the input
// parameters, setting the origin and target property values if not set
// already, and then performs an enumeration on the association class. It then
// filters the results of that enumeration to see if one of the reference
// properties matches the objectName parameter passed into the method. If so,
// then it is added to the array of association instances to be returned.
//
Array<CIMInstance> InteropProvider::localReferences(
    const OperationContext & context,
    const CIMObjectPath & objectName,
    const CIMName & assocClass,
    String & originProperty,
    String & targetProperty,
    const CIMPropertyList & propertyList,
    const CIMName & targetClass)
{
    PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
        "InteropProvider::localReferences()");

    Array<CIMInstance> instances;
    CIMName originClass = objectName.getClassName();

    Array<CIMName> targetSubclasses;
    CIMNamespaceName lastTargetNamespace;
    CIMNamespaceName originNamespace(objectName.getNameSpace());

    // Check that the association traversal request is valid
    if (validAssocClassForObject(
        context, 
        assocClass, 
        objectName,
        originNamespace, 
        originProperty, 
        targetProperty))
    {
        // retrieve all of the association class instances
        Array<CIMInstance> localInstances = localEnumerateInstances(context,
            CIMObjectPath(hostName, originNamespace,
                assocClass));
        // Filter the association class instances based on the origin instance
        // and other input parameters.
        for(Uint32 i = 0, n = localInstances.size(); i < n; ++i)
        {
            CIMInstance & currentInstance = localInstances[i];
            CIMObjectPath originPath = getRequiredValue<CIMObjectPath>(
                currentInstance, originProperty);
            originPath.setNameSpace(objectName.getNameSpace());
            originPath.setHost(objectName.getHost());
            // Only include instances where the origin instance is present in
            // the association.
            if(originPath.identical(objectName))
            {
                if(!targetClass.isNull())
                {
                    // Have to check if the target reference is of the
                    // targetClass type. We first must determine all the
                    // possible subclasses of the targetClass in the target
                    // namespace.
                    CIMObjectPath targetPath = getRequiredValue<CIMObjectPath>(
                        currentInstance, targetProperty);

                    CIMNamespaceName targetNamespace(
                        targetPath.getNameSpace());
                    if(targetNamespace.isNull())
                    {
                        targetNamespace = originNamespace;
                        targetPath.setNameSpace(targetNamespace);
                    }
                    if(targetNamespace != lastTargetNamespace)
                    {
                        try
                        {
                            targetSubclasses = repository->enumerateClassNames(
                                targetNamespace, targetClass, true);
                        }
                        catch(...)
                        {
                            // If an exception was thrown during enumeration,
                            // then the base class didn't exist in the
                            // namespace, so the target instance retrieved
                            // must not match the targetClass parameter.
                            continue;
                        }
                        targetSubclasses.append(targetClass);
                        lastTargetNamespace = targetNamespace;
                    }

                    // Try to find the targetPath's class in the search space
                    CIMName targetPathClass = targetPath.getClassName();
                    for(Uint32 j = 0, m = targetSubclasses.size(); j < m; ++j)
                    {
                        if(targetPathClass == targetSubclasses[j])
                        {
                            instances.append(currentInstance);
                            break;
                        }
                    }
                }
                else
                {
                    instances.append(currentInstance);
                }
            }
        }
    }

    PEG_METHOD_EXIT();
    return instances;
}
Ejemplo n.º 7
0
//
// Local version of getInstance to be used by other functions in the the
// provider. Returns a single instance. Note that it always returns an
// instance. If none was found, it is uninialitized.
//
CIMInstance InteropProvider::localGetInstance(
    const OperationContext & context,
    const CIMObjectPath & instanceName,
    const CIMPropertyList & propertyList)
{
    PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::localGetInstance");

    PEG_TRACE((TRC_CONTROLPROVIDER, Tracer::LEVEL4,
        "%s getInstance. instanceName= %s , PropertyList= %s",
        thisProvider,
        (const char *)instanceName.toString().getCString(),
        (const char *)propertyListToString(propertyList).getCString()));

    // Test if we're looking for something outside of our namespace. This will
    // happen during associators calls from PG_RegisteredProfile instances
    // through the PG_ElementConformsToProfile association
    CIMNamespaceName opNamespace = instanceName.getNameSpace();
    CIMName opClass = instanceName.getClassName();
    if(opNamespace != PEGASUS_NAMESPACENAME_INTEROP &&
        opClass != PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE
        // Get CIM_IndicationService instance from IndicationService.
#ifdef PEGASUS_ENABLE_DMTF_INDICATION_PROFILE_SUPPORT
        || opClass == PEGASUS_CLASSNAME_CIM_INDICATIONSERVICE
#endif
        )
    {
        AutoMutex mut(interopMut);
        CIMInstance gotInstance = cimomHandle.getInstance(
                                         context,
                                         opNamespace,
                                         instanceName, 
                                         false, 
                                         false, 
                                         false, 
                                         propertyList);
        PEG_METHOD_EXIT();
        return gotInstance;
    }

    // Create reference from host, namespace, class components of
    // instance name
    CIMObjectPath ref;
    ref.setHost(instanceName.getHost());
    ref.setClassName(opClass);
    ref.setNameSpace(opNamespace);

    // Enumerate instances for this class. Returns all instances
    // Note that this returns paths setup and instances already
    // filtered per the input criteria.
    Array<CIMInstance> instances =  localEnumerateInstances(
        context,
        ref,
        propertyList);

    // deliver a single instance if found.
    CIMInstance retInstance;

    bool found = false;
    for(Uint32 i = 0, n = instances.size(); i < n; i++)
    {
        CIMObjectPath currentInstRef = instances[i].getPath();
        currentInstRef.setHost(instanceName.getHost());
        currentInstRef.setNameSpace(instanceName.getNameSpace());
        if(instanceName == currentInstRef)
        {
            retInstance = instances[i];
            found = true;
            break;
        }
    }

    if(!found)
    {
      cout << "Coule not find instance: " << instanceName.toString() << endl;
    }
    PEG_METHOD_EXIT();
    return retInstance;
}
Ejemplo n.º 8
0
void testInstanceClass(CIMClient & client, const CIMName & className)
{
    cout << "Testing Instance Class "
        << (const char *)className.getString().getCString()
        << "...";
    Array<CIMInstance> instances = testAnyClass(client, className);

    for(unsigned int i = 0, n = instances.size(); i < n; ++i)
    {
        CIMInstance currentInstance = instances[i];
        CIMObjectPath currentPath = currentInstance.getPath();
        if(currentPath.getNameSpace().isNull())
          currentPath.setNameSpace(interopNamespace);

        //
        // Now test association traversal
        // Note that the "TestAssociationClass" method does a very good job
        // of testing association traversal between references contained in
        // instances of the supplied association class. Therefore, all we
        // really have to do here is make sure that the results of the
        // associators, associatorNames, references, and referenceNames
        // operations are consistent.
        //
        Boolean failure = false;
        try
        {
            Array<CIMObject> associatorsResults = client.associators(
                currentPath.getNameSpace(), currentPath);
            Array<CIMObjectPath> associatorNamesResults =
                client.associatorNames(
                    currentPath.getNameSpace(), currentPath);
            Array<CIMObject> referencesResults = client.references(
                currentPath.getNameSpace(), currentPath);
            Array<CIMObjectPath> referenceNamesResults = client.referenceNames(
                currentPath.getNameSpace(), currentPath);

            Uint32 numResults = associatorsResults.size();
            if(numResults != associatorNamesResults.size() ||
                numResults != referencesResults.size() ||
                numResults != referenceNamesResults.size())
            {
                failure = true;
            }
            else
            {
                // Check that the results for the references and referenceNames
                // operations are consistent.
                unsigned int j = 0;
                for(j = 0; j < numResults; ++j)
                {
                    CIMObjectPath currentReferenceName =
                        referenceNamesResults[j];
                    Boolean found = false;
                    for(unsigned int k = 0; k < numResults; ++k)
                    {
                        if(currentReferenceName ==
                            referencesResults[k].getPath())
                        {
                            found = true;
                            break;
                        }
                    }

                    if(!found)
                    {
                        failure = true;
                        break;
                    }
                }

                // Check that that results for the associatorNames call is
                // consistent with the associators call and the references
                // call.
                for(j = 0; j < numResults; ++j)
                {
                    CIMObjectPath currentAssociatorName =
                        associatorNamesResults[j];
                    Boolean found = false;
                    unsigned int k = 0;
                    for(k = 0; k < numResults; ++k)
                    {
                        if(currentAssociatorName ==
                            associatorsResults[k].getPath())
                        {
                            found = true;
                            break;
                        }
                    }

                    if(!found)
                    {
                        failure = true;
                        break;
                    }

                    found = false;

                    for(k = 0; k < numResults; ++k)
                    {
                        CIMObject referenceInstance = referencesResults[k];
                        for(unsigned int x = 0,
                            m = referenceInstance.getPropertyCount();
                            x < m; ++x)
                        {
                            CIMProperty currentProp =
                                referenceInstance.getProperty(x);
                            if(currentProp.getType() == CIMTYPE_REFERENCE)
                            {
                                CIMObjectPath currentRef;
                                currentProp.getValue().get(currentRef);
                                currentRef.setHost(
                                    currentAssociatorName.getHost());
                                if(currentRef == currentAssociatorName)
                                {
                                    found = true;
                                    break;
                                }
                            }
                        }

                        if(found)
                            break;
                    }

                    if(!found)
                    {
                        failure = true;
                        break;
                    }
                }
            }

            if(failure)
            {
                exitFailure(
                    String("Association Operations returned inconsistent ") +
                    String("results for instance ") +
                    currentPath.toString());
            }
        }
        catch(CIMException & e)
        {
          exitFailure(String("Caught exception while performing ") +
            String("association operations on instance ") +
            currentPath.toString() + String(": ") + e.getMessage());
        }
    }

    cout << "Test Complete" << endl;
}
Ejemplo n.º 9
0
void PG_TestPropertyTypes::getInstance(
    const OperationContext& context,
    const CIMObjectPath& instanceReference,
    const Boolean includeQualifiers,
    const Boolean includeClassOrigin,
    const CIMPropertyList& propertyList,
    InstanceResponseHandler& handler)
{
    // synchronously get references
    //Get extra instance created for testing negative realValues.
    Array<CIMObjectPath> references =
        _enumerateInstanceNames(context, instanceReference);

    // ensure the InstanceId key is valid
    Array<CIMKeyBinding> keys = instanceReference.getKeyBindings();
    Uint32 i;
    for (i=0; i<keys.size() && !keys[i].getName().equal("InstanceId"); i++);

    if (i==keys.size())
    {
        throw CIMException(CIM_ERR_INVALID_PARAMETER);
    }

    // ensure the Namespace is valid
    if (!instanceReference.getNameSpace().equal ("test/static"))
    {
        throw CIMException(CIM_ERR_INVALID_NAMESPACE);
    }

    // ensure the class existing in the specified namespace
    if (!instanceReference.getClassName().equal ("PG_TestPropertyTypes"))
    {
        throw CIMException(CIM_ERR_INVALID_CLASS);
    }
        Boolean testRealValue = false;
    // ensure the request object exists
    Uint32 index = findObjectPath(references, instanceReference);
    if (index == PEG_NOT_FOUND)
    {
        CIMClass cimclass = _cimom.getClass(
            context,
            instanceReference.getNameSpace(),
            instanceReference.getClassName(),
            false,
            true,
            true,
            CIMPropertyList());
        CIMObjectPath tempRef = realValueTestInstance.buildPath(cimclass);
        tempRef.setHost(instanceReference.getHost());
        tempRef.setNameSpace(instanceReference.getNameSpace());
        if (instanceReference != tempRef)
        {
            throw CIMException(CIM_ERR_NOT_FOUND);
        }
        testRealValue = true;
    }

    // begin processing the request
    handler.processing();
    if (testRealValue)
    {
        handler.deliver(realValueTestInstance);
    }
    else
    {
        // instance index corresponds to reference index
        handler.deliver(_instances[index]);
    }
    // complete processing the request
    handler.complete();
}
Ejemplo n.º 10
0
void testAssociationClass(CIMClient & client, const CIMName & className)
{
    cout << "Testing Association Class "
        << (const char *)className.getString().getCString()
        << "...";
    Array<CIMInstance> instances = testAnyClass(client, className);

    for(unsigned int i = 0, n = instances.size(); i < n; ++i)
    {
        //
        // Now make sure that the references are valid and that association
        // traversal between them is working properly.
        //
        CIMObjectPath referenceA;
        CIMObjectPath referenceB;
        CIMInstance currentInstance = instances[i];
        CIMObjectPath currentInstanceName = currentInstance.getPath();
        if(currentInstanceName.getNameSpace().isNull())
            currentInstanceName.setNameSpace(interopNamespace);

        for(unsigned int j = 0, m = currentInstance.getPropertyCount();
            j < m; ++j)
        {
            CIMProperty currentProp = currentInstance.getProperty(j);
            if(currentProp.getValue().getType() == CIMTYPE_REFERENCE)
            {
                if(referenceA.getKeyBindings().size() == 0)
                {
                    currentProp.getValue().get(referenceA);
                }
                else
                {
                    currentProp.getValue().get(referenceB);
                    break;
                }
            }
        }

        if(referenceA.getKeyBindings().size() == 0 ||
            referenceB.getKeyBindings().size() == 0)
        {
            exitFailure(
                String("Could not find reference properties for ") +
                String("association: ") +
                currentInstanceName.toString());
        }

        try
        {
            client.getInstance(referenceA.getNameSpace(), referenceA);
            client.getInstance(referenceB.getNameSpace(), referenceB);
        }
        catch(CIMException &)
        {
            exitFailure(String("Could not get instances for association : ") +
                currentInstanceName.toString());
        }

        Boolean associationFailure = false;
        try
        {
            Array<CIMObjectPath> results = client.associatorNames(
                referenceA.getNameSpace(), referenceA, className);
            Boolean found = false;
            for(unsigned int j = 0, m = results.size(); j < m; ++j)
            {
                CIMObjectPath result = results[j];
                result.setHost(referenceB.getHost());
                result.setNameSpace(referenceB.getNameSpace());
                if(result == referenceB)
                {
                    found = true;
                    break;
                }
            }

            if(found)
            {
                results = client.associatorNames(referenceB.getNameSpace(),
                    referenceB, className);
                for(unsigned int j = 0, m = results.size(); j < m; ++j)
                {
                    CIMObjectPath result = results[j];
                    result.setHost(referenceA.getHost());
                    result.setNameSpace(referenceA.getNameSpace());
                    if(result == referenceA)
                    {
                        found = true;
                        break;
                    }
                }
            }

            if(!found)
            {
                associationFailure = true;
            }
        }
        catch(CIMException & e)
        {
            cout << "Exception: " << e.getMessage() << endl;
            associationFailure = true;
        }

        if(associationFailure)
        {
            exitFailure(String("Association traversal failed between ") +
                String("instances of association: ") +
                currentInstanceName.toString());
        }

        Boolean referencesFailure = false;
        try
        {
            Array<CIMObjectPath> results = client.referenceNames(
                referenceA.getNameSpace(), referenceA, className);
            Boolean found = false;
            for(unsigned int j = 0, m = results.size(); j < m; ++j)
            {
                CIMObjectPath currentPath = results[j];
                if(currentPath.getNameSpace().isNull())
                    currentPath.setNameSpace(interopNamespace);
                if(currentPath.getHost().size() != 0)
                    currentPath.setHost(String::EMPTY);
                if(currentPath == currentInstanceName)
                {
                    found = true;
                    break;
                }
            }

            if(found)
            {
                results = client.referenceNames(referenceB.getNameSpace(),
                    referenceB, className);
                for(unsigned int j = 0, m = results.size(); j < m; ++j)
                {
                    CIMObjectPath currentPath = results[j];
                    if(currentPath.getNameSpace().isNull())
                        currentPath.setNameSpace(interopNamespace);
                    if(currentPath.getHost().size() != 0)
                        currentPath.setHost(String::EMPTY);
                    if(currentPath == currentInstanceName)
                    {
                        found = true;
                        break;
                    }
                }
            }

            if(!found)
            {
                referencesFailure = true;
            }
        }
        catch(CIMException &)
        {
            referencesFailure = true;
        }

        if(referencesFailure)
        {
            exitFailure(String("References operation failed for ") +
                String("instances of association: ") +
                currentInstanceName.toString());
        }
    }

    cout << "Test Complete" << endl;
}
Ejemplo n.º 11
0
Array<CIMInstance> InteropProvider::getReferencedInstances(
    const Array<CIMInstance> &refs,
    const String &targetRole,
    const OperationContext & context,
    const CIMPropertyList & propertyList)
{
    PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
                     "InteropProvider::getReferencedObjects");

    Array<CIMInstance> referencedInstances;
    Array<CIMInstance> classInstances;
    CIMName prevClassName;

    ConstArrayIterator<CIMInstance> refsIter(refs);
    for(Uint32 i = 0; i < refsIter.size(); i++)
    {
        CIMInstance thisRef = refsIter[i];
        CIMObjectPath thisTarget = getRequiredValue<CIMObjectPath>(
                                       thisRef,
                                       targetRole);

        // Test if we're looking for something outside of our namespace. This
        // will happen during associators calls from PG_RegisteredProfile
        // instances through the PG_ElementConformsToProfile association
        CIMNamespaceName opNamespace = thisTarget.getNameSpace();
        CIMName opClass = thisTarget.getClassName();

        if((opNamespace != PEGASUS_NAMESPACENAME_INTEROP &&
                opClass != PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE)
                // Get CIM_IndicationService instance from IndicationService.
#ifdef PEGASUS_ENABLE_DMTF_INDICATION_PROFILE_SUPPORT
                || opClass == PEGASUS_CLASSNAME_CIM_INDICATIONSERVICE
#endif
          )
        {
            AutoMutex mut(interopMut);
            CIMInstance gotInstance = cimomHandle.getInstance(
                                          context,
                                          opNamespace,
                                          thisTarget,
                                          false,
                                          false,
                                          false,
                                          propertyList);
            referencedInstances.append(gotInstance);
            continue;
        }

        TARGET_CLASS classEnum  = translateClassInput(opClass);
        CIMInstance retInstance;
        switch(classEnum)
        {
        case PG_SOFTWAREIDENTITY:
        {
            CIMInstance retInstance =
                getSoftwareIdentityInstance(thisTarget);
            normalizeInstance(
                retInstance, thisTarget, false, false, propertyList);
            retInstance.setPath(thisTarget);
            referencedInstances.append(retInstance);
        }
        break;
        case PG_NAMESPACE:
        {
            CIMInstance retInstance = getNameSpaceInstance(thisTarget);
            normalizeInstance(
                retInstance, thisTarget, false, false, propertyList);
            retInstance.setPath(thisTarget);
            referencedInstances.append(retInstance);
        }
        break;
        default:
        {
            if( opClass != prevClassName )
            {
                CIMObjectPath ref;
                ref.setHost(thisTarget.getHost());
                ref.setClassName(thisTarget.getClassName());
                ref.setNameSpace(thisTarget.getNameSpace());
                classInstances = localEnumerateInstances(
                                     context,
                                     ref,
                                     propertyList);
                ArrayIterator<CIMInstance> instsIter(classInstances);
                for(Uint32 n = 0; n < instsIter.size(); n++)
                {
                    CIMObjectPath tmpInst = instsIter[n].getPath();
                    tmpInst.setHost(thisTarget.getHost());
                    tmpInst.setNameSpace(thisTarget.getNameSpace());
                    instsIter[n].setPath(tmpInst);
                }
                prevClassName = opClass;
            }
            ConstArrayIterator<CIMInstance> instsConstIter(classInstances);
            for(Uint32 j = 0; j < instsConstIter.size(); j++)
            {
                if(thisTarget == instsConstIter[j].getPath())
                {
                    referencedInstances.append(instsConstIter[j]);
                    break;
                }
            }
        }
        break;
        }
    }
    PEG_METHOD_EXIT();
    return referencedInstances;
}
Ejemplo n.º 12
0
//
// Local version of getInstance to be used by other functions in the the
// provider. Returns a single instance. Note that it always returns an
// instance. If none was found, it is uninialitized.
//
CIMInstance InteropProvider::localGetInstance(
    const OperationContext & context,
    const CIMObjectPath & instanceName,
    const CIMPropertyList & propertyList)
{
    PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::localGetInstance");

    PEG_TRACE((TRC_CONTROLPROVIDER, Tracer::LEVEL4,
               "%s getInstance. instanceName= %s , PropertyList= %s",
               thisProvider,
               (const char *)instanceName.toString().getCString(),
               (const char *)propertyList.toString().getCString()));

    // Test if we're looking for something outside of our namespace. This will
    // happen during associators calls from PG_RegisteredProfile instances
    // through the PG_ElementConformsToProfile association
    CIMNamespaceName opNamespace = instanceName.getNameSpace();
    CIMName opClass = instanceName.getClassName();
    if((opNamespace != PEGASUS_NAMESPACENAME_INTEROP &&
            opClass != PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE)
            // Get CIM_IndicationService instance from IndicationService.
#ifdef PEGASUS_ENABLE_DMTF_INDICATION_PROFILE_SUPPORT
            || opClass == PEGASUS_CLASSNAME_CIM_INDICATIONSERVICE
#endif
      )
    {
        AutoMutex mut(interopMut);
        CIMInstance gotInstance = cimomHandle.getInstance(
                                      context,
                                      opNamespace,
                                      instanceName,
                                      false,
                                      false,
                                      false,
                                      propertyList);
        PEG_METHOD_EXIT();
        return gotInstance;
    }

    TARGET_CLASS classEnum  = translateClassInput(opClass);
    CIMInstance retInstance;
    switch(classEnum)
    {
    case PG_SOFTWAREIDENTITY:
    {
        retInstance = getSoftwareIdentityInstance(instanceName);
        normalizeInstance(
            retInstance, instanceName, false, false, propertyList);
    }
    break;
    case PG_NAMESPACE:
    {
        retInstance = getNameSpaceInstance(instanceName);
        normalizeInstance(
            retInstance, instanceName, false, false, propertyList);
    }
    break;
    // ATTN: Implement getIntstance for all other classes. Currently
    // this method calls localEnumerateInstances() to select instance
    // which is too expensive.
    default:
    {
        // Create reference from host, namespace, class components of
        // instance name
        CIMObjectPath ref;
        ref.setHost(instanceName.getHost());
        ref.setClassName(opClass);
        ref.setNameSpace(opNamespace);

        // Enumerate instances for this class. Returns all instances
        // Note that this returns paths setup and instances already
        // filtered per the input criteria.
        Array<CIMInstance> instances =  localEnumerateInstances(
                                            context,
                                            ref,
                                            propertyList);
        ConstArrayIterator<CIMInstance> instancesIter(instances);

        // deliver a single instance if found.
        bool found = false;
        for(Uint32 i = 0; i < instancesIter.size(); i++)
        {
            CIMObjectPath currentInstRef = instancesIter[i].getPath();
            currentInstRef.setHost(instanceName.getHost());
            currentInstRef.setNameSpace(instanceName.getNameSpace());
            if(instanceName == currentInstRef)
            {
                retInstance = instancesIter[i];
                found = true;
                break;
            }
        }

        if (!found)
        {
            PEG_METHOD_EXIT();
            throw CIMObjectNotFoundException(instanceName.toString());
        }
    }
    }

    PEG_METHOD_EXIT();
    return retInstance;
}
Ejemplo n.º 13
0
void MCCA_TestAssocProvider::associators(
    const OperationContext & context,
    const CIMObjectPath & objectName,
    const CIMName & associationClass,
    const CIMName & resultClass,
    const String & role,
    const String & resultRole,
    const Boolean includeQualifiers,
    const Boolean includeClassOrigin,
    const CIMPropertyList & propertyList,
    ObjectResponseHandler & handler)
{
    CDEBUG("MCCA_TestAssocProvider::associators() called.");
    // create a new CIMInstance based on class with name className
    CIMInstance constructedInstance = CIMInstance(testClassName);
    CIMObjectPath   targetObjectPath = CIMObjectPath();
    Array<CIMKeyBinding> keyBindings = Array<CIMKeyBinding>();
    Uint32 sourceKey = 0;

    CDEBUG("Initialisation ended.");
    handler.processing();
    CDEBUG("handler.processing started.");
    // we do ignore role, resultRole, includeQualifiers, includeClassOrigin,
    // propertyList

    CDEBUG("Next building object path.");
    /////////////////////////////////////////////////////////////////////
    //      BUILD OBJECTPATH
    /////////////////////////////////////////////////////////////////////

    // preparing object path first
    targetObjectPath.setHost("localhost:5988");
    targetObjectPath.setClassName(testClassName);
    CDEBUG("Host and classname set, host=" << objectName.getHost());
    // determine if source namespace is namespace A or B
    // and build respective target namespace ...
    if (objectName.getNameSpace().equal(nameSpaceA))
    {
        targetObjectPath.setNameSpace(nameSpaceB);
    }
    if (objectName.getNameSpace().equal(nameSpaceB))
    {
        targetObjectPath.setNameSpace(nameSpaceA);
    }
    CDEBUG("NameSpace set.");
    // determine key of source object so we can create target object
    Array<CIMKeyBinding> sourceKeyBindings = objectName.getKeyBindings();

    CDEBUG("Determining sourceKey.");
    // only one keyvalue, so we take that first one
    String      keyValueString = String(sourceKeyBindings[0].getValue());
    CDEBUG("keyValueString=" << keyValueString);
    sourceKey = strtoul((const char*) keyValueString.getCString(), NULL, 0);
    CDEBUG("sourceKey=" << sourceKey);


    CIMKeyBinding  testClassKey = CIMKeyBinding(CIMName("theKey"),
                                                    CIMValue(sourceKey) );
    CDEBUG("Created new KeyBinding testClassKey.");
    // testClassKey.setValue(keyValueString);

    CDEBUG("sourceKey = string(set keybinding),int(sourceKey)"
            << testClassKey.getValue()
            << "," << sourceKey);
    keyBindings.append(testClassKey);
    CDEBUG("Appended(testClassKey).");

    targetObjectPath.setKeyBindings(keyBindings);
    /////////////////////////////////////////////////////////////////////
    //      ADD PROPERTIES
    /////////////////////////////////////////////////////////////////////

    // add properties to the CIMInstance object
    constructedInstance.addProperty( CIMProperty( CIMName("theKey"),
                sourceKey));
    constructedInstance.addProperty( CIMProperty( CIMName("theData"),
                20+sourceKey));
    char  buffer[100];
    sprintf(buffer,"ABC-%u",20*sourceKey+sourceKey);
    constructedInstance.addProperty(CIMProperty(CIMName ("theString"),
                String(buffer)));

    CDEBUG("Added properties to the CIMInstance object");

    CIMObject cimObject(constructedInstance);
    cimObject.setPath (targetObjectPath);

    // lets deliver all instances of CIMObjectpaths I do think are okay
    handler.deliver(cimObject);
    // complete processing the request
    handler.complete();
    CDEBUG("Association call conmplete.");
}
Ejemplo n.º 14
0
void ConfigSettingProvider::enumerateInstances(
    const OperationContext & context,
    const CIMObjectPath & ref,
    const Boolean includeQualifiers,
    const Boolean includeClassOrigin,
    const CIMPropertyList& propertyList,
    InstanceResponseHandler & handler)
    {
        PEG_METHOD_ENTER(TRC_CONFIG,
                         "ConfigSettingProvider::enumerateInstances()");

        Array<CIMInstance> instanceArray;
        Array<String> propertyNames;

        //
        // check if the class name requested is PG_ConfigSetting
        //
        if (!ref.getClassName().equal (PG_CONFIG_SETTING))
        {
            PEG_METHOD_EXIT();
            throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
                                        ref.getClassName().getString());
        }

        // begin processing the request
        handler.processing();

        try
        {
            _configManager->getAllPropertyNames(propertyNames, false);


            for (Uint32 i = 0; i < propertyNames.size(); i++)
            {
                Array<String> propertyInfo;

                CIMInstance        instance(PG_CONFIG_SETTING);

                propertyInfo.clear();

                _configManager->getPropertyInfo(
                propertyNames[i], propertyInfo);

                Array<CIMKeyBinding> keyBindings;
                keyBindings.append(CIMKeyBinding(PROPERTY_NAME,
                    propertyInfo[0], CIMKeyBinding::STRING));
                CIMObjectPath instanceName(ref.getHost(),
                    ref.getNameSpace(),
                PG_CONFIG_SETTING, keyBindings);

                // construct the instance
                instance.addProperty(CIMProperty(PROPERTY_NAME,
                                     propertyInfo[0]));
                instance.addProperty(CIMProperty(DEFAULT_VALUE,
                                     propertyInfo[1]));
                instance.addProperty(CIMProperty(CURRENT_VALUE,
                                     propertyInfo[2]));
                instance.addProperty(CIMProperty(PLANNED_VALUE,
                                     propertyInfo[3]));
                instance.addProperty(CIMProperty(DYNAMIC_PROPERTY,
                   Boolean(propertyInfo[4]=="true"?true:false)));
                if (propertyInfo.size() > 6)
                {
                    instance.addProperty(
                        CIMProperty(DESCRIPTION, propertyInfo[6]));
                }

                instance.setPath(instanceName);
                instanceArray.append(instance);
            }
        }
        catch(Exception& e)
        {
            PEG_METHOD_EXIT();
            throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
        }

        handler.deliver(instanceArray);

        // complete processing the request
        handler.complete();

        PEG_METHOD_EXIT();
    }