Esempio n. 1
0
void _printPropertyList(CIMPropertyList& propList)
{
    if (propList.isNull())
    {
        cout << "-----all properties required" << endl;
    }
    else if (propList.size() == 0)
    {
        cout << "-----no properties required" << endl;
    }
    else
    {
        for (Uint32 n = 0; n < propList.size(); n++)
        {
            cout << "-----Required property " << propList[n].getString() << endl;
        }
    }
}
Esempio n. 2
0
void test03()
{
    //
    // Define query:
    //
    
    const char TEXT[] = 
	"SELECT *\n"
	"FROM AnotherClass\n";

    //
    //  Will test WQLParser::parse(const String&, WQLSelectStatement&)
    //  and WQLParser::parse(const char*, WQLSelectStatement&) forms
    //
    String text (TEXT);
    if (verbose)
    {
        cout << text << endl;
    }

    // 
    // Parse the text:
    //

    WQLSelectStatement statement;

    try
    {
	WQLParser::parse(text, statement);
        if (verbose)
        {
	    statement.print();
        }

        //
        //  Test WQLSelectStatement functions
        //
        assert (statement.getClassName().equal ("AnotherClass"));
        assert (statement.getAllProperties());
        CIMPropertyList propList = statement.getSelectPropertyList();
        assert (propList.isNull());
        assert (!statement.hasWhereClause());
        assert (statement.getWherePropertyNameCount() == 0);
        CIMPropertyList wherePropList = statement.getWherePropertyList();
        assert (!wherePropList.isNull());
        assert (wherePropList.size() == 0);
    }
    catch (Exception& e)
    {
	cerr << "Exception: " << e.getMessage() << endl;
	exit(1);
    }
}
void PG_TestPropertyTypes::modifyInstance(
    const OperationContext& context,
    const CIMObjectPath& instanceReference,
    const CIMInstance& instanceObject,
    const Boolean includeQualifiers,
    const CIMPropertyList& propertyList,
    ResponseHandler& handler)
{
    // This provider only allows partial instance modification for the
    // PropertyUint8 property.
    if (!(propertyList.isNull() ||
          ((propertyList.size() == 1) &&
           (propertyList[0].equal("PropertyUint8")))))
    {
        throw CIMException(CIM_ERR_NOT_SUPPORTED);
    }

    // synchronously get references
    Array<CIMObjectPath> references =
        _enumerateInstanceNames(context, instanceReference);

    // 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);
    }

    // ensure the property values are valid
    _testPropertyTypesValue(instanceObject);

    // ensure the request object exists
    Uint32 index = findObjectPath(references, instanceReference);
    if (index == PEG_NOT_FOUND)
    {
        throw CIMException(CIM_ERR_NOT_FOUND);
    }

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

    // We do nothing here since we like to have static result
    // complete processing the request
    handler.complete();
}
Esempio n. 4
0
void test01()
{
    //
    // Create a property source (a place for the evaluate to get the
    // values of properties from):
    //

    WQLSimplePropertySource source;
    assert(source.addValue("x", WQLOperand(10, WQL_INTEGER_VALUE_TAG)));
    assert(source.addValue("y", WQLOperand(20, WQL_INTEGER_VALUE_TAG)));
    assert(source.addValue("z", WQLOperand(1.5, WQL_DOUBLE_VALUE_TAG)));

    //
    // Define query:
    //
    
    const char TEXT[] = 
	"SELECT x,y,z\n"
	"FROM MyClass\n"
	"WHERE x > 5 AND y < 25 AND z > 1.2";

    //
    //  Will test WQLParser::parse(const Array<Sint8>&, WQLSelectStatement&)
    //  and WQLParser::parse(const char*, WQLSelectStatement&) forms
    //
    Array<char> text;
    text.append(TEXT, sizeof(TEXT));
    if (verbose)
    {
        cout << text.getData() << endl;
    }

    // 
    // Parse the text:
    //

    WQLSelectStatement statement;

    try
    {
	WQLParser::parse(text, statement);
        if (verbose)
        {
	    statement.print();
        }

        //
        //  Test WQLSelectStatement functions
        //
        assert (statement.getClassName().equal ("MyClass"));
        assert (!statement.getAllProperties());
        assert (statement.getSelectPropertyNameCount() == 3);
        CIMName propName = statement.getSelectPropertyName (0);
        assert ((propName.equal ("x")) || (propName.equal ("y")) || 
                (propName.equal ("z")));
        CIMPropertyList propList = statement.getSelectPropertyList();
        assert (!propList.isNull());
        assert (propList.size() == 3);
        assert ((propList[0].equal ("x")) || (propList[0].equal ("y")) || 
                (propList[0].equal ("z")));
        assert (statement.hasWhereClause());
        assert (statement.getWherePropertyNameCount() == 3);
        CIMName wherePropName = statement.getWherePropertyName (0);
        assert ((wherePropName.equal ("x")) || (wherePropName.equal ("y")) || 
                (wherePropName.equal ("z")));
        CIMPropertyList wherePropList = statement.getWherePropertyList();
        assert (!wherePropList.isNull());
        assert (wherePropList.size() == 3);
        assert ((wherePropList[0].equal ("x")) || 
                (wherePropList[0].equal ("y")) || 
                (wherePropList[0].equal ("z")));
        assert (statement.evaluateWhereClause(&source));
    }
    catch (Exception& e)
    {
	cerr << "Exception: " << e.getMessage() << endl;
	exit(1);
    }
}
Esempio n. 5
0
void test02()
{
    //
    // Create a property source (a place for the evaluate to get the
    // values of properties from):
    //

    WQLSimplePropertySource source;
    assert(source.addValue("a", WQLOperand(5, WQL_INTEGER_VALUE_TAG)));
    assert(source.addValue("b", WQLOperand(25, WQL_INTEGER_VALUE_TAG)));
    assert(source.addValue("c", WQLOperand(0.9, WQL_DOUBLE_VALUE_TAG)));
    assert(source.addValue("d", WQLOperand("Test", WQL_STRING_VALUE_TAG)));

    //
    // Define query:
    //
    
    const char TEXT[] = 
	"SELECT a,c,d\n"
	"FROM YourClass\n"
	"WHERE a > 5 AND b < 25 AND c > 1.2 AND d = \"Pass\"";

    //
    //  Will test WQLParser::parse(const String&, WQLSelectStatement&)
    //  and WQLParser::parse(const char*, WQLSelectStatement&) forms
    //
    String text (TEXT);
    if (verbose)
    {
        cout << text << endl;
    }

    // 
    // Parse the text:
    //

    WQLSelectStatement statement;

    try
    {
	WQLParser::parse(text, statement);
        if (verbose)
        {
	    statement.print();
        }

        //
        //  Test WQLSelectStatement functions
        //
        assert (statement.getClassName().equal ("YourClass"));
        assert (!statement.getAllProperties());
        assert (statement.getSelectPropertyNameCount() == 3);
        CIMName propName = statement.getSelectPropertyName (2);
        assert ((propName.equal ("a")) || (propName.equal ("c")) || 
                (propName.equal ("d")));
        CIMPropertyList propList = statement.getSelectPropertyList();
        assert (!propList.isNull());
        assert (propList.size() == 3);
        assert ((propList[2].equal ("a")) || (propList[2].equal ("c")) || 
                (propList[2].equal ("d")));
        assert (statement.hasWhereClause());
        assert (statement.getWherePropertyNameCount() == 4);
        CIMName wherePropName = statement.getWherePropertyName (3);
        assert ((wherePropName.equal ("a")) || (wherePropName.equal ("b")) || 
                (wherePropName.equal ("c")) || (wherePropName.equal ("d")));
        CIMPropertyList wherePropList = statement.getWherePropertyList();
        assert (!wherePropList.isNull());
        assert (wherePropList.size() == 4);
        assert ((wherePropList[3].equal ("a")) || 
                (wherePropList[3].equal ("b")) || 
                (wherePropList[3].equal ("c")) || 
                (wherePropList[3].equal ("d")));
        assert (!statement.evaluateWhereClause(&source));
    }
    catch (Exception& e)
    {
	cerr << "Exception: " << e.getMessage() << endl;
	exit(1);
    }
}
void ConfigSettingProvider::_modifyInstance(
    const OperationContext & context,
    const CIMObjectPath & instanceReference,
    const CIMInstance& modifiedIns,
    const CIMPropertyList& propertyList,
    Uint32 timeoutSeconds)
    {
        PEG_METHOD_ENTER(TRC_CONFIG,
            "ConfigSettingProvider::_modifyInstance()");

        //
        // get userName
        //
        String userName;
        try
        {
            IdentityContainer container = context.get(IdentityContainer::NAME);
            userName = container.getUserName();
        }
        catch (...)
        {
            userName = String::EMPTY;
        }

        //
        // verify user authorizations
        // z/OS: authorization check is done in CIMOpReqAuth already
        //
#ifndef PEGASUS_OS_ZOS
        if (userName != String::EMPTY)
        {
            _verifyAuthorization(userName);
        }
#endif
        // NOTE: Qualifiers are not processed by this provider, so the
        // IncludeQualifiers flag is ignored.

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

        //
        // validate key bindings
        //
        Array<CIMKeyBinding> kbArray = instanceReference.getKeyBindings();
        if ( (kbArray.size() != 1) ||
             (!kbArray[0].getName().equal (PROPERTY_NAME)))
        {
            PEG_METHOD_EXIT();
            throw PEGASUS_CIM_EXCEPTION_L(
                CIM_ERR_INVALID_PARAMETER,
                MessageLoaderParms(
                    "ControlProviders.ConfigSettingProvider."
                        "ConfigSettingProvider."
                        "INVALID_INSTANCE_NAME",
                    "Invalid instance name"));

        }

        String configPropertyName = kbArray[0].getValue();

        // Modification of the entire instance is not supported by this provider
        if (propertyList.isNull())
        {
            PEG_METHOD_EXIT();
            //l10n
            //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
            //"Modification of entire instance");
            throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_NOT_SUPPORTED,
                  MessageLoaderParms(
                      "ControlProviders.ConfigSettingProvider."
                          "ConfigSettingProvider."
                          "MODIFICATION_OF_ENTIRE_INSTANCE",
                     "Modification of entire instance"));
        }

        Boolean currentValueModified = false;
        Boolean plannedValueModified = false;

        for (Uint32 i = 0; i < propertyList.size(); ++i)
        {
            CIMName propertyName = propertyList[i];
            if (propertyName.equal (CURRENT_VALUE))
            {
                currentValueModified = true;
            }
            else if (propertyName.equal (PLANNED_VALUE))
            {
                plannedValueModified = true;
            }
            else
            {
                PEG_METHOD_EXIT();

                throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_NOT_SUPPORTED,
                    MessageLoaderParms(
                        "ControlProviders.ConfigSettingProvider."
                            "ConfigSettingProvider."
                            "MODIFICATION_NOT_SUPPORTED",
                        "Modification of property \"$0\"",
                        propertyName.getString()));
            }
        }

        String preValue;
        String currentValue;
        String plannedValue;
        Boolean currentValueIsNull = false;
        Boolean plannedValueIsNull = false;

        //
        // Get the current value from the instance
        //
        Uint32 pos = modifiedIns.findProperty(CURRENT_VALUE);
        if (pos == PEG_NOT_FOUND)
        {
            currentValueIsNull = true;
        }
        else
        {
            CIMConstProperty prop = modifiedIns.getProperty(pos);
            try
            {
                prop.getValue().get(currentValue);
            }
            catch (Exception& e)
            {
                PEG_METHOD_EXIT();
                throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
            }
        }

        //
        // Get the planned value from the instance
        //
        pos = modifiedIns.findProperty(PLANNED_VALUE);
        if (pos == PEG_NOT_FOUND)
        {
            plannedValueIsNull = true;
        }
        else
        {
            CIMConstProperty prop = modifiedIns.getProperty(pos);
            try
            {
                prop.getValue().get(plannedValue);
            }
            catch (Exception& e)
            {
                PEG_METHOD_EXIT();
                throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
            }
        }

        try
        {
            //
            // Update the current value, if requested
            //
            if (currentValueModified)
            {
                preValue = _configManager->getCurrentValue(configPropertyName);

                if ( !_configManager->updateCurrentValue(
                    configPropertyName,
                    currentValue,
                    userName,
                    timeoutSeconds,
                    currentValueIsNull))
                {
                    PEG_METHOD_EXIT();

                    throw PEGASUS_CIM_EXCEPTION_L(
                        CIM_ERR_FAILED,
                        MessageLoaderParms(
                            "ControlProviders.ConfigSettingProvider."
                                "ConfigSettingProvider."
                                "UPDATE_CURRENT_VALUE_FAILED",
                            "Failed to update the current value."));
                }

                // It is unset, get current value which is default
                if (currentValueIsNull)
                {
                    currentValue = _configManager->getCurrentValue(
                        configPropertyName);
                }

               // send notify config change message to Handler Service
               if(String::equal(configPropertyName,
                      "maxIndicationDeliveryRetryAttempts")||
                  String::equal(configPropertyName,
                      "minIndicationDeliveryRetryInterval"))
               {
                   _sendNotifyConfigChangeMessage(
                       configPropertyName,
                       currentValue,
                       userName,
                       PEGASUS_QUEUENAME_INDHANDLERMANAGER,
                       true);
               }

                // send notify config change message to ProviderManager Service
                _sendNotifyConfigChangeMessage(
                    configPropertyName,
                    currentValue,
                    userName,
                    PEGASUS_QUEUENAME_PROVIDERMANAGER_CPP,
                    true);

               PEG_AUDIT_LOG(logSetConfigProperty(userName, configPropertyName,
                   preValue, currentValue, false));
            }

            //
            // Update the planned value, if requested
            //
            if (plannedValueModified)
            {
                preValue = _configManager->getPlannedValue(configPropertyName);

                if ( !_configManager->updatePlannedValue(
                    configPropertyName, plannedValue, plannedValueIsNull) )
                {
                    PEG_METHOD_EXIT();

                    throw PEGASUS_CIM_EXCEPTION_L(
                        CIM_ERR_FAILED,
                        MessageLoaderParms(
                            "ControlProviders.ConfigSettingProvider."
                                "ConfigSettingProvider."
                                "UPDATE_PLANNED_VALUE_FAILED",
                            "Failed to update the planned value."));
                }

                // It is unset, get planned value which is default
                if (plannedValueIsNull)
                {
                    plannedValue = _configManager->getPlannedValue(
                        configPropertyName);

                    if (String::equal(configPropertyName,
                           "maxIndicationDeliveryRetryAttempts") ||
                        String::equal(configPropertyName,
                            "minIndicationDeliveryRetryInterval"))
                    {
                        _sendNotifyConfigChangeMessage(
                            configPropertyName,
                            plannedValue,
                            userName,
                            PEGASUS_QUEUENAME_INDHANDLERMANAGER,
                            false);
                    }
                }

                // send notify config change message to ProviderManager Service
                _sendNotifyConfigChangeMessage(
                    configPropertyName,
                    plannedValue,
                    userName,
                    PEGASUS_QUEUENAME_PROVIDERMANAGER_CPP,
                    false);

               PEG_AUDIT_LOG(logSetConfigProperty(userName, configPropertyName,
                   preValue, plannedValue, true));
            }
        }
        catch (const NonDynamicConfigProperty& ndcp)
        {
            PEG_METHOD_EXIT();
            throw PEGASUS_CIM_EXCEPTION(
                CIM_ERR_NOT_SUPPORTED, ndcp.getMessage());
        }
        catch (const InvalidPropertyValue& ipv)
        {
            PEG_METHOD_EXIT();
            throw PEGASUS_CIM_EXCEPTION(
                CIM_ERR_FAILED, ipv.getMessage());
        }
        catch (const UnrecognizedConfigProperty&)
        {
            PEG_METHOD_EXIT();
            throw PEGASUS_CIM_EXCEPTION_L(
                CIM_ERR_NOT_FOUND,
                MessageLoaderParms(
                    "ControlProviders.ConfigSettingProvider."
                        "ConfigSettingProvider."
                        "CONFIG_PROPERTY_NOT_FOUND",
                    "Configuration property \"$0\"",
                    configPropertyName));
        }

        PEG_METHOD_EXIT();
        return;
    }