Search in sources :

Example 11 with ModelType

use of org.jboss.dmr.ModelType in project wildfly by wildfly.

the class StatisticsResourceDefinition method getAttributesFromPlugin.

public static List<AttributeDefinition> getAttributesFromPlugin(StatisticsPlugin plugin) {
    LinkedList<AttributeDefinition> result = new LinkedList<>();
    for (String name : plugin.getNames()) {
        ModelType modelType = ModelType.STRING;
        if (plugin.getType(name) == int.class) {
            modelType = ModelType.INT;
        }
        if (plugin.getType(name) == long.class) {
            modelType = ModelType.LONG;
        }
        SimpleAttributeDefinition attribute = new SimpleAttributeDefinitionBuilder(name, modelType).setRequired(false).setStorageRuntime().build();
        result.add(attribute);
    }
    return result;
}
Also used : SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelType(org.jboss.dmr.ModelType) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder) LinkedList(java.util.LinkedList)

Example 12 with ModelType

use of org.jboss.dmr.ModelType in project wildfly by wildfly.

the class ExpressionSupportSmokeTestCase method organizeAttributes.

private void organizeAttributes(PathAddress address, ModelNode description, ModelNode resource, ModelNode resourceNoDefaults, Map<String, ModelNode> expressionAttrs, Map<String, ModelNode> otherAttrs, Map<String, ModelNode> expectedAttrs) {
    ModelNode attributeDescriptions = description.get(ATTRIBUTES);
    for (Property descProp : attributeDescriptions.asPropertyList()) {
        String attrName = descProp.getName();
        ModelNode attrDesc = descProp.getValue();
        if (isAttributeExcluded(address, attrName, attrDesc, resourceNoDefaults)) {
            continue;
        }
        ModelNode noDefaultValue = resourceNoDefaults.get(attrName);
        if (!noDefaultValue.isDefined()) {
            // We need to see if it's legal to set this attribute, or whether it's undefined
            // because an alternative attribute is defined or a required attribute is not defined.
            Set<String> base = new HashSet<String>();
            base.add(attrName);
            if (attrDesc.hasDefined(REQUIRES)) {
                for (ModelNode node : attrDesc.get(REQUIRES).asList()) {
                    base.add(node.asString());
                }
            }
            boolean conflict = false;
            for (String baseAttr : base) {
                if (!resource.hasDefined(baseAttr)) {
                    conflict = true;
                    break;
                }
                ModelNode baseAttrAlts = attributeDescriptions.get(baseAttr, ALTERNATIVES);
                if (baseAttrAlts.isDefined()) {
                    for (ModelNode alt : baseAttrAlts.asList()) {
                        String altName = alt.asString();
                        if (resourceNoDefaults.hasDefined(alt.asString()) || expressionAttrs.containsKey(altName) || otherAttrs.containsKey(altName)) {
                            conflict = true;
                            break;
                        }
                    }
                }
            }
            if (conflict) {
                conflicts++;
                logHandling("Skipping conflicted attribute " + attrName + " at " + address.toModelNode().asString());
                continue;
            }
        }
        ModelNode attrValue = resource.get(attrName);
        ModelType attrType = attrValue.getType();
        if (attrDesc.get(EXPRESSIONS_ALLOWED).asBoolean(false)) {
            // If it's defined and not an expression, use the current value to create an expression
            if (attrType != ModelType.UNDEFINED && attrType != ModelType.EXPRESSION) {
                // Deal with complex types specially
                if (COMPLEX_TYPES.contains(attrType)) {
                    ModelNode valueType = attrDesc.get(VALUE_TYPE);
                    if (valueType.getType() == ModelType.TYPE) {
                        // Simple collection whose elements support expressions
                        handleSimpleCollection(address, attrName, attrValue, valueType.asType(), expressionAttrs, otherAttrs, expectedAttrs);
                    } else if (valueType.isDefined()) {
                        handleComplexCollection(address, attrName, attrValue, attrType, valueType, expressionAttrs, otherAttrs, expectedAttrs);
                    } else {
                        noSimple++;
                        logNoExpressions(address, attrName);
                        otherAttrs.put(attrName, attrValue);
                        expectedAttrs.put(attrName, attrValue);
                    }
                } else {
                    if (attrType == ModelType.STRING) {
                        checkForUnconvertedExpression(address, attrName, attrValue);
                    }
                    String expression = "${exp.test:" + attrValue.asString() + "}";
                    expressionAttrs.put(attrName, new ModelNode(expression));
                    expectedAttrs.put(attrName, new ModelNode().set(new ValueExpression(expression)));
                    simple++;
                    logHandling("Added expression to simple attribute " + attrName + " at " + address.toModelNode().asString());
                }
            } else {
                if (attrType != ModelType.EXPRESSION) {
                    supportedUndefined++;
                    logHandling("Expression supported but value undefined on simple attribute " + attrName + " at " + address.toModelNode().asString());
                } else {
                    simple++;
                    logHandling("Already found an expression on simple attribute " + attrName + " at " + address.toModelNode().asString());
                }
                otherAttrs.put(attrName, attrValue);
                expectedAttrs.put(attrName, attrValue);
            }
        } else if (COMPLEX_TYPES.contains(attrType) && attrDesc.get(VALUE_TYPE).getType() != ModelType.TYPE && attrDesc.get(VALUE_TYPE).isDefined()) {
            handleComplexCollection(address, attrName, attrValue, attrType, attrDesc.get(VALUE_TYPE), expressionAttrs, otherAttrs, expectedAttrs);
        } else /*if (!attrDesc.hasDefined(DEPRECATED))*/
        {
            noSimple++;
            logNoExpressions(address, attrName);
            otherAttrs.put(attrName, attrValue);
            expectedAttrs.put(attrName, attrValue);
        }
    }
}
Also used : ValueExpression(org.jboss.dmr.ValueExpression) ModelType(org.jboss.dmr.ModelType) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property) HashSet(java.util.HashSet)

Example 13 with ModelType

use of org.jboss.dmr.ModelType in project wildfly by wildfly.

the class ExpressionSupportSmokeTestCase method handleComplexItem.

private void handleComplexItem(PathAddress address, String attrName, ModelNode item, ModelNode valueTypeDesc, ModelNode updatedItem, ModelNode itemToExpect) {
    // Hack to deal with time unit processing
    Set<String> keys = valueTypeDesc.keys();
    boolean timeAttr = keys.size() == 2 && keys.contains("time") && keys.contains("unit");
    boolean changed = false;
    for (Property fieldProp : valueTypeDesc.asPropertyList()) {
        String fieldName = fieldProp.getName();
        if (!item.has(fieldName)) {
            continue;
        }
        boolean timeunit = timeAttr && "unit".equals(fieldName);
        ModelNode fieldDesc = fieldProp.getValue();
        ModelNode fieldValue = item.get(fieldName);
        ModelType valueType = fieldValue.getType();
        if (valueType == ModelType.UNDEFINED || valueType == ModelType.EXPRESSION || // too complex
        COMPLEX_TYPES.contains(valueType) || !fieldDesc.get(EXPRESSIONS_ALLOWED).asBoolean(false)) {
            updatedItem.get(fieldName).set(fieldValue);
            itemToExpect.get(fieldName).set(fieldValue);
        } else {
            if (valueType == ModelType.STRING) {
                checkForUnconvertedExpression(address, attrName, item);
            }
            String valueString = timeunit ? fieldValue.asString().toLowerCase() : fieldValue.asString();
            String expression = "${exp.test:" + valueString + "}";
            updatedItem.get(fieldName).set(expression);
            itemToExpect.get(fieldName).set(new ModelNode().set(new ValueExpression(expression)));
            changed = true;
        }
    }
    if (!changed) {
        // Use unchanged 'item'
        updatedItem.set(item);
        itemToExpect.set(item);
    }
}
Also used : ValueExpression(org.jboss.dmr.ValueExpression) ModelType(org.jboss.dmr.ModelType) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Example 14 with ModelType

use of org.jboss.dmr.ModelType in project eap-additional-testsuite by jboss-set.

the class ExpressionSupportSmokeTestCase method handleComplexItem.

private void handleComplexItem(PathAddress address, String attrName, ModelNode item, ModelNode valueTypeDesc, ModelNode updatedItem, ModelNode itemToExpect) {
    // Hack to deal with time unit processing
    Set<String> keys = valueTypeDesc.keys();
    boolean timeAttr = keys.size() == 2 && keys.contains("time") && keys.contains("unit");
    boolean changed = false;
    for (Property fieldProp : valueTypeDesc.asPropertyList()) {
        String fieldName = fieldProp.getName();
        if (!item.has(fieldName)) {
            continue;
        }
        boolean timeunit = timeAttr && "unit".equals(fieldName);
        ModelNode fieldDesc = fieldProp.getValue();
        ModelNode fieldValue = item.get(fieldName);
        ModelType valueType = fieldValue.getType();
        if (valueType == ModelType.UNDEFINED || valueType == ModelType.EXPRESSION || // too complex
        COMPLEX_TYPES.contains(valueType) || !fieldDesc.get(EXPRESSIONS_ALLOWED).asBoolean(false)) {
            updatedItem.get(fieldName).set(fieldValue);
            itemToExpect.get(fieldName).set(fieldValue);
        } else {
            if (valueType == ModelType.STRING) {
                checkForUnconvertedExpression(address, attrName, item);
            }
            String valueString = timeunit ? fieldValue.asString().toLowerCase() : fieldValue.asString();
            String expression = "${exp.test:" + valueString + "}";
            updatedItem.get(fieldName).set(expression);
            itemToExpect.get(fieldName).set(new ModelNode().set(new ValueExpression(expression)));
            changed = true;
        }
    }
    if (!changed) {
        // Use unchanged 'item'
        updatedItem.set(item);
        itemToExpect.set(item);
    }
}
Also used : ValueExpression(org.jboss.dmr.ValueExpression) ModelType(org.jboss.dmr.ModelType) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Aggregations

ModelType (org.jboss.dmr.ModelType)14 ModelNode (org.jboss.dmr.ModelNode)12 Property (org.jboss.dmr.Property)9 ValueExpression (org.jboss.dmr.ValueExpression)9 HashSet (java.util.HashSet)3 SimpleAttributeDefinitionBuilder (org.jboss.as.controller.SimpleAttributeDefinitionBuilder)3 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)2 OperationContext (org.jboss.as.controller.OperationContext)2 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)1 SimpleOperationDefinition (org.jboss.as.controller.SimpleOperationDefinition)1