Search in sources :

Example 31 with Property

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

the class ExpressionSupportSmokeTestCase method handleSimpleCollection.

private void handleSimpleCollection(PathAddress address, String attrName, ModelNode attrValue, ModelType valueType, Map<String, ModelNode> expressionAttrs, Map<String, ModelNode> otherAttrs, Map<String, ModelNode> expectedAttrs) {
    if (COMPLEX_TYPES.contains(valueType)) {
        // Too complicated
        noSimpleCollection++;
        logNoExpressions(address, attrName);
        otherAttrs.put(attrName, attrValue);
    } else {
        boolean hasExpression = false;
        ModelNode updated = new ModelNode();
        ModelNode expected = new ModelNode();
        for (ModelNode item : attrValue.asList()) {
            ModelType itemType = item.getType();
            if (itemType == ModelType.PROPERTY) {
                Property prop = item.asProperty();
                ModelNode propVal = prop.getValue();
                ModelType propValType = propVal.getType();
                if (propVal.isDefined() && propValType != ModelType.EXPRESSION) {
                    // Convert property value to expression
                    if (propValType == ModelType.STRING) {
                        checkForUnconvertedExpression(address, attrName, propVal);
                    }
                    String expression = "${exp.test:" + propVal.asString() + "}";
                    updated.get(prop.getName()).set(expression);
                    expected.get(prop.getName()).set(new ModelNode().set(new ValueExpression(expression)));
                    hasExpression = true;
                } else {
                    updated.get(prop.getName()).set(propVal);
                    expected.get(prop.getName()).set(propVal);
                }
            } else if (item.isDefined() && itemType != ModelType.EXPRESSION) {
                // Convert item to expression
                if (itemType == ModelType.STRING) {
                    checkForUnconvertedExpression(address, attrName, item);
                }
                String expression = "${exp.test:" + item.asString() + "}";
                updated.add(expression);
                expected.add(new ModelNode().set(new ValueExpression(expression)));
                hasExpression = true;
            } else {
                updated.add(item);
                expected.add(item);
            }
        }
        if (hasExpression) {
            simpleCollection++;
            logHandling("Added expression to SIMPLE " + attrValue.getType() + " attribute " + attrName + " at " + address.toModelNode().asString());
            expressionAttrs.put(attrName, updated);
            expectedAttrs.put(attrName, expected);
        } else {
            // We didn't change anything
            noSimpleCollection++;
            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)

Example 32 with Property

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

the class ExpressionSupportSmokeTestCase method setExpressions.

private void setExpressions(PathAddress address, String hostName, Map<PathAddress, Map<String, ModelNode>> expectedValues) throws IOException, MgmtOperationException {
    ModelNode description = readResourceDescription(address);
    ModelNode resource = readResource(address, true, false);
    ModelNode resourceNoDefaults = readResource(address, false, false);
    Map<String, ModelNode> expressionAttrs = new HashMap<String, ModelNode>();
    Map<String, ModelNode> otherAttrs = new HashMap<String, ModelNode>();
    Map<String, ModelNode> expectedAttrs = new HashMap<String, ModelNode>();
    organizeAttributes(address, description, resource, resourceNoDefaults, expressionAttrs, otherAttrs, expectedAttrs);
    for (Map.Entry<String, ModelNode> entry : expressionAttrs.entrySet()) {
        writeAttribute(address, entry.getKey(), entry.getValue());
    }
    // Set the other attrs as well just to exercise the write-attribute handlers
    for (Map.Entry<String, ModelNode> entry : otherAttrs.entrySet()) {
        writeAttribute(address, entry.getKey(), entry.getValue());
    }
    if (expectedAttrs.size() > 0 && immediateValidation) {
        // Validate that our write-attribute calls resulted in the expected values in the model
        ModelNode modifiedResource = readResource(address, true, true);
        for (Map.Entry<String, ModelNode> entry : expectedAttrs.entrySet()) {
            ModelNode expectedValue = entry.getValue();
            ModelNode modVal = modifiedResource.get(entry.getKey());
            validateAttributeValue(address, entry.getKey(), expectedValue, modVal);
        }
    }
    // Store the modified values for confirmation after HC reload
    expectedValues.put(address, expectedAttrs);
    // Recurse into children, being careful about what processes we are touching
    boolean isHost = address.size() == 1 && HOST.equals(address.getLastElement().getKey());
    for (Property descProp : description.get(CHILDREN).asPropertyList()) {
        String childType = descProp.getName();
        if (isHost && SERVER.equals(childType)) {
            continue;
        }
        boolean hostChild = address.size() == 0 && HOST.equals(childType);
        List<String> children = readChildrenNames(address, childType);
        for (String child : children) {
            if (!hostChild || hostName.equals(child)) {
                setExpressions(address.append(PathElement.pathElement(childType, child)), hostName, expectedValues);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map) HashMap(java.util.HashMap) Property(org.jboss.dmr.Property)

Example 33 with Property

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

the class JSSEExpressionsUnitTestCase method validateModel.

@Override
protected void validateModel(ModelNode model) {
    super.validateModel(model);
    ModelNode jsse = model.get("subsystem", "security", "security-domain", "other", "jsse", "classic");
    Assert.assertEquals(ModelType.OBJECT, jsse.getType());
    Assert.assertEquals(ModelType.EXPRESSION, jsse.get(Constants.CLIENT_ALIAS).getType());
    Assert.assertEquals(ModelType.EXPRESSION, jsse.get(Constants.SERVER_ALIAS).getType());
    Assert.assertEquals(ModelType.EXPRESSION, jsse.get(Constants.SERVICE_AUTH_TOKEN).getType());
    Assert.assertEquals(ModelType.EXPRESSION, jsse.get(Constants.CLIENT_AUTH).getType());
    Assert.assertEquals(ModelType.EXPRESSION, jsse.get(Constants.PROTOCOLS).getType());
    Assert.assertEquals(ModelType.EXPRESSION, jsse.get(Constants.CLIENT_ALIAS).getType());
    ModelNode keystore = jsse.get(Constants.KEYSTORE);
    Assert.assertEquals(ModelType.OBJECT, keystore.getType());
    Assert.assertEquals(ModelType.EXPRESSION, keystore.get(Constants.PASSWORD).getType());
    Assert.assertEquals(ModelType.EXPRESSION, keystore.get(Constants.TYPE).getType());
    Assert.assertEquals(ModelType.EXPRESSION, keystore.get(Constants.URL).getType());
    Assert.assertEquals(ModelType.EXPRESSION, keystore.get(Constants.PROVIDER).getType());
    Assert.assertEquals(ModelType.EXPRESSION, keystore.get(Constants.PROVIDER_ARGUMENT).getType());
    ModelNode truststore = jsse.get(Constants.TRUSTSTORE);
    Assert.assertEquals(ModelType.OBJECT, truststore.getType());
    Assert.assertEquals(ModelType.EXPRESSION, truststore.get(Constants.PASSWORD).getType());
    Assert.assertEquals(ModelType.EXPRESSION, truststore.get(Constants.TYPE).getType());
    Assert.assertEquals(ModelType.EXPRESSION, truststore.get(Constants.URL).getType());
    Assert.assertEquals(ModelType.EXPRESSION, truststore.get(Constants.PROVIDER).getType());
    Assert.assertEquals(ModelType.EXPRESSION, truststore.get(Constants.PROVIDER_ARGUMENT).getType());
    ModelNode keyManager = jsse.get(Constants.KEY_MANAGER);
    Assert.assertEquals(ModelType.OBJECT, keyManager.getType());
    Assert.assertEquals(ModelType.EXPRESSION, keyManager.get(Constants.ALGORITHM).getType());
    Assert.assertEquals(ModelType.EXPRESSION, keyManager.get(Constants.PROVIDER).getType());
    ModelNode trustManager = jsse.get(Constants.TRUST_MANAGER);
    Assert.assertEquals(ModelType.OBJECT, trustManager.getType());
    Assert.assertEquals(ModelType.EXPRESSION, trustManager.get(Constants.ALGORITHM).getType());
    Assert.assertEquals(ModelType.EXPRESSION, trustManager.get(Constants.PROVIDER).getType());
    // check if the module-option values have been created as expression nodes.
    ModelNode auth = model.get("subsystem", "security", "security-domain", "other", "authentication", "classic");
    Assert.assertEquals(ModelType.OBJECT, auth.getType());
    List<Property> loginModules = auth.get(Constants.LOGIN_MODULE).asPropertyList();
    // Assert.assertEquals(ModelType.LIST, loginModules.getType());
    ModelNode loginModule = loginModules.get(0).getValue();
    Assert.assertEquals(ModelType.OBJECT, auth.getType());
    for (Property prop : loginModule.get(Constants.MODULE_OPTIONS).asPropertyList()) {
        Assert.assertEquals(ModelType.EXPRESSION, prop.getValue().getType());
    }
    ModelNode domain = model.get("subsystem", "security", "security-domain", "jboss-empty-jsse", "jsse", "classic");
    Assert.assertEquals(ModelType.OBJECT, domain.getType());
}
Also used : ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Example 34 with Property

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

the class JMSThreadPoolMetricsUtil method getResources.

public static Map<String, ModelNode> getResources(ManagementClient client) throws IOException {
    Map<String, ModelNode> resources = new HashMap<>();
    List<Property> propertyList = client.getControllerClient().execute(READ_MESSAGING_SUBSYSTEM_OPERATION).require("result").asPropertyList();
    for (Property property : propertyList) {
        resources.put(property.getName(), property.getValue());
    }
    return resources;
}
Also used : HashMap(java.util.HashMap) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Example 35 with Property

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

the class DeployedXmlJMSManagementTestCase method getDeployedResourceAddress.

private ModelNode getDeployedResourceAddress(String type, String name) {
    ModelNode address = new ModelNode();
    String deployment = jmsOperations.getProviderName().equals("hornetq") ? TEST_HORNETQ_JMS_XML : TEST_ACTIVEMQ_JMS_XML;
    address.add("deployment", deployment);
    for (Property property : jmsOperations.getServerAddress().asPropertyList()) {
        address.add(property.getName(), property.getValue());
    }
    address.add(type, name);
    return address;
}
Also used : ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Aggregations

Property (org.jboss.dmr.Property)203 ModelNode (org.jboss.dmr.ModelNode)163 HashMap (java.util.HashMap)22 Test (org.junit.Test)19 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)16 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)16 PathAddress (org.jboss.as.controller.PathAddress)12 ArrayList (java.util.ArrayList)11 Map (java.util.Map)11 ValueExpression (org.jboss.dmr.ValueExpression)10 ModelType (org.jboss.dmr.ModelType)9 OperationFailedException (org.jboss.as.controller.OperationFailedException)8 HashSet (java.util.HashSet)7 ArrayDeque (java.util.ArrayDeque)6 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)6 Properties (java.util.Properties)5 LinkedHashMap (java.util.LinkedHashMap)4 LoginModuleControlFlag (javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)4 HttpResponse (org.apache.http.HttpResponse)3