Search in sources :

Example 11 with ValueExpression

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

the class AbstractExpressionSupportTestCase 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 12 with ValueExpression

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

the class WebMigrateOperation method createWelcomeContentHandler.

/**
 * create a handler for serving welcome content
 */
private void createWelcomeContentHandler(Map<PathAddress, ModelNode> migrationOperations) {
    PathAddress address = pathAddress(pathElement(SUBSYSTEM, UndertowExtension.SUBSYSTEM_NAME), pathElement(Constants.CONFIGURATION, Constants.HANDLER));
    migrationOperations.put(address, createAddOperation(address));
    address = pathAddress(pathElement(SUBSYSTEM, UndertowExtension.SUBSYSTEM_NAME), pathElement(Constants.CONFIGURATION, Constants.HANDLER), pathElement(Constants.FILE, "welcome-content"));
    final ModelNode add = createAddOperation(address);
    add.get(Constants.PATH).set(new ModelNode(new ValueExpression("${jboss.home.dir}/welcome-content")));
    migrationOperations.put(address, add);
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) ValueExpression(org.jboss.dmr.ValueExpression) ModelNode(org.jboss.dmr.ModelNode)

Example 13 with ValueExpression

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

the class JaegerTracerConfigurationTest method testModelResolution.

@Test
public void testModelResolution() throws OperationFailedException {
    ModelNode operation = Operations.createAddOperation(PathAddress.pathAddress("subsystem", "microprofile-opentracing-smallrye").append("jaeger-tracer", "jaeger").toModelNode());
    operation.get("propagation").add("B3").add(new ValueExpression("${jaeger.propagation:JAEGER}"));
    operation.get("sampler-type").set(new ValueExpression("${jaeger.sampler.type:const}"));
    operation.get("sampler-param").set(new ValueExpression("${jaeger.sampler-param:0.8}"));
    operation.get("sampler-manager-host-port").set(new ValueExpression("${jaeger.sampler-manager-host-port:localhost:4321}"));
    operation.get("sender-endpoint").set(new ValueExpression("${jaeger.sender.endpoint:http://localhost:14268/api/traces}"));
    operation.get("sender-auth-token").set(new ValueExpression("${jaeger.sender.auth-token:myAuthToken}"));
    operation.get("sender-auth-user").set(new ValueExpression("${jaeger.sender.user:sender}"));
    operation.get("sender-auth-password").set(new ValueExpression("${jaeger.sender.password:senderPassword}"));
    operation.get("reporter-log-spans").set(new ValueExpression("${jaeger.reporter.log-spans:false}"));
    operation.get("reporter-flush-interval").set(new ValueExpression("${jaeger.reporter.flush-interval:5}"));
    operation.get("reporter-max-queue-size").set(new ValueExpression("${jaeger.reporter.max-queue-size:10}"));
    operation.get("tracer_id_128bit").set(new ValueExpression("${jaeger.tracer_id_128bit:true}"));
    operation.get("tags").add("test", "${jaeger.reporter.max-queue-sizesimple}");
    JaegerTracerConfiguration tracerConfiguration = new JaegerTracerConfiguration(ExpressionResolver.TEST_RESOLVER, "jaeger", operation, () -> null);
    Configuration config = tracerConfiguration.createConfiguration("myApplication.war");
    Assert.assertEquals(2, config.getCodec().getCodecs().size());
    Assert.assertEquals(1, config.getCodec().getBinaryCodecs().size());
    Assert.assertEquals(2, config.getCodec().getCodecs().get(Format.Builtin.HTTP_HEADERS).size());
    Assert.assertEquals(2, config.getCodec().getCodecs().get(Format.Builtin.TEXT_MAP).size());
    Assert.assertEquals(1, config.getCodec().getBinaryCodecs().get(Format.Builtin.BINARY).size());
    Assert.assertEquals("const", config.getSampler().getType());
    Assert.assertEquals(0.8d, config.getSampler().getParam().doubleValue(), 0.01);
    Assert.assertEquals("localhost:4321", config.getSampler().getManagerHostPort());
    Assert.assertEquals("http://localhost:14268/api/traces", config.getReporter().getSenderConfiguration().getEndpoint());
    Assert.assertEquals("myAuthToken", config.getReporter().getSenderConfiguration().getAuthToken());
    Assert.assertEquals("sender", config.getReporter().getSenderConfiguration().getAuthUsername());
    Assert.assertEquals("senderPassword", config.getReporter().getSenderConfiguration().getAuthPassword());
    Assert.assertEquals(false, config.getReporter().getLogSpans());
    Assert.assertEquals(5, config.getReporter().getFlushIntervalMs().intValue());
    Assert.assertEquals(10, config.getReporter().getMaxQueueSize().intValue());
}
Also used : Configuration(io.jaegertracing.Configuration) ValueExpression(org.jboss.dmr.ValueExpression) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 14 with ValueExpression

use of org.jboss.dmr.ValueExpression 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 15 with ValueExpression

use of org.jboss.dmr.ValueExpression 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)

Aggregations

ModelNode (org.jboss.dmr.ModelNode)18 ValueExpression (org.jboss.dmr.ValueExpression)18 Property (org.jboss.dmr.Property)10 ModelType (org.jboss.dmr.ModelType)9 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 PathAddress (org.jboss.as.controller.PathAddress)2 Configuration (io.jaegertracing.Configuration)1 LinkedList (java.util.LinkedList)1 Matcher (java.util.regex.Matcher)1 OutboundSocketBinding (org.wildfly.swarm.spi.api.OutboundSocketBinding)1 SocketBinding (org.wildfly.swarm.spi.api.SocketBinding)1 SocketBindingGroup (org.wildfly.swarm.spi.api.SocketBindingGroup)1