Search in sources :

Example 1 with ValueExpression

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

the class InterfaceMarshaller method configureInterface.

private void configureInterface(Interface iface, List<ModelNode> list) {
    if (hasInterface(iface, list)) {
        return;
    }
    ModelNode node = new ModelNode();
    node.get(OP).set(ADD);
    node.get(OP_ADDR).set(INTERFACE_NAME, iface.getName());
    node.get(INET_ADDRESS).set(new ValueExpression(iface.getExpression()));
    list.add(node);
}
Also used : ValueExpression(org.jboss.dmr.ValueExpression) ModelNode(org.jboss.dmr.ModelNode)

Example 2 with ValueExpression

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

the class SocketBindingGroupMarshaller method marshal.

public void marshal(List<ModelNode> list) {
    for (SocketBindingGroup group : this.socketBindingGroups) {
        PathAddress address = PathAddress.pathAddress("socket-binding-group", group.name());
        ModelNode node = new ModelNode();
        node.get(OP).set(ADD);
        node.get(OP_ADDR).set(address.toModelNode());
        node.get(DEFAULT_INTERFACE).set(group.defaultInterface());
        node.get(PORT_OFFSET).set(new ValueExpression(group.portOffsetExpression()));
        LinkedList<ModelNode> subList = new LinkedList<>();
        subList.add(node);
        for (SocketBinding binding : group.socketBindings()) {
            configureSocketBinding(address, binding, subList);
        }
        for (OutboundSocketBinding binding : group.outboundSocketBindings()) {
            configureSocketBinding(address, binding, subList);
        }
        if (!isAlreadyConfigured(subList, list)) {
            list.addAll(subList);
        }
    }
}
Also used : SocketBinding(org.wildfly.swarm.spi.api.SocketBinding) OutboundSocketBinding(org.wildfly.swarm.spi.api.OutboundSocketBinding) SocketBindingGroup(org.wildfly.swarm.spi.api.SocketBindingGroup) OutboundSocketBinding(org.wildfly.swarm.spi.api.OutboundSocketBinding) PathAddress(org.jboss.as.controller.PathAddress) ValueExpression(org.jboss.dmr.ValueExpression) ModelNode(org.jboss.dmr.ModelNode) LinkedList(java.util.LinkedList)

Example 3 with ValueExpression

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

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

the class TransformUtilsTestCase method testExpressions.

@Test
public void testExpressions() {
    ModelNode legacyModel = new ModelNode();
    legacyModel.get("name").set(new ValueExpression("${name}"));
    legacyModel.get("giop-minor-version").set(new ValueExpression("${giop.minor.version:2}"));
    ModelNode newModel = TransformUtils.transformModel(legacyModel);
    Assert.assertTrue(newModel.get("name").equals(new ModelNode(new ValueExpression("${name}"))));
    Assert.assertTrue(newModel.get("giop-version").equals(new ModelNode(new ValueExpression("${giop.minor.version:1.2}"))));
}
Also used : ValueExpression(org.jboss.dmr.ValueExpression) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 5 with ValueExpression

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

the class TransformUtils method transformModel.

static ModelNode transformModel(final ModelNode legacyModel) {
    final ModelNode model = new ModelNode();
    for (Property property : legacyModel.asPropertyList()) {
        String name = property.getName();
        ModelNode legacyValue = property.getValue();
        if (legacyValue.isDefined()) {
            if (name.equals(JacORBSubsystemConstants.IOR_SETTINGS)) {
                transformIorSettings(model, legacyValue);
                continue;
            }
            final boolean expression;
            final String expressionVariable;
            if (legacyValue.getType() == ModelType.EXPRESSION) {
                expression = true;
                final Matcher matcher = Pattern.compile("\\A\\$\\{(.*):(.*)\\}\\Z").matcher(legacyValue.asExpression().getExpressionString());
                if (matcher.find()) {
                    expressionVariable = matcher.group(1);
                    String abc = matcher.group(2);
                    legacyValue = new ModelNode(abc);
                } else {
                    model.get(name).set(legacyValue);
                    continue;
                }
            } else {
                expression = false;
                expressionVariable = null;
            }
            ModelNode value;
            switch(name) {
                case JacORBSubsystemConstants.ORB_GIOP_MINOR_VERSION:
                    name = Constants.ORB_GIOP_VERSION;
                    value = new ModelNode(new StringBuilder().append("1.").append(legacyValue.asString()).toString());
                    break;
                case JacORBSubsystemConstants.ORB_INIT_TRANSACTIONS:
                    if (legacyValue.asString().equals(JacORBSubsystemConstants.ON)) {
                        value = new ModelNode(Constants.FULL);
                    } else if (legacyValue.asString().equals(JacORBSubsystemConstants.OFF)) {
                        value = new ModelNode(Constants.NONE);
                    } else {
                        value = legacyValue;
                    }
                    break;
                case JacORBSubsystemConstants.ORB_INIT_SECURITY:
                    if (legacyValue.asString().equals(JacORBSubsystemConstants.OFF)) {
                        value = new ModelNode(Constants.NONE);
                    } else {
                        value = legacyValue;
                    }
                    break;
                case JacORBSubsystemConstants.SECURITY_SUPPORT_SSL:
                case JacORBSubsystemConstants.SECURITY_ADD_COMP_VIA_INTERCEPTOR:
                case JacORBSubsystemConstants.NAMING_EXPORT_CORBALOC:
                case JacORBSubsystemConstants.INTEROP_IONA:
                    if (legacyValue.asString().equals(JacORBSubsystemConstants.ON)) {
                        value = ModelNode.TRUE;
                    } else {
                        value = ModelNode.FALSE;
                    }
                    break;
                default:
                    value = legacyValue;
            }
            if (!value.asString().equals(JacORBSubsystemConstants.OFF)) {
                if (expression) {
                    String newExpression = "${" + expressionVariable;
                    if (expressionVariable != null) {
                        newExpression += (":" + value.asString());
                    }
                    newExpression += "}";
                    value = new ModelNode(new ValueExpression(newExpression));
                }
                model.get(name).set(value);
            }
        }
    }
    if (!legacyModel.get(JacORBSubsystemConstants.ORB_SOCKET_BINDING).isDefined()) {
        model.get(JacORBSubsystemConstants.ORB_SOCKET_BINDING).set(JacORBSubsystemDefinitions.ORB_SOCKET_BINDING.getDefaultValue());
    }
    return model;
}
Also used : Matcher(java.util.regex.Matcher) ValueExpression(org.jboss.dmr.ValueExpression) 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