Search in sources :

Example 46 with AttributeDefinition

use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.

the class MessagingXMLWriter method writeJmsBridge.

private void writeJmsBridge(XMLExtendedStreamWriter writer, String bridgeName, ModelNode value) throws XMLStreamException {
    writer.writeStartElement(Element.JMS_BRIDGE.getLocalName());
    if (!DEFAULT.equals(bridgeName)) {
        writer.writeAttribute(Attribute.NAME.getLocalName(), bridgeName);
    }
    JMSBridgeDefinition.MODULE.marshallAsAttribute(value, writer);
    writer.writeStartElement(SOURCE.getLocalName());
    for (AttributeDefinition attr : JMSBridgeDefinition.JMS_SOURCE_ATTRIBUTES) {
        attr.marshallAsElement(value, writer);
    }
    writer.writeEndElement();
    writer.writeStartElement(TARGET.getLocalName());
    for (AttributeDefinition attr : JMSBridgeDefinition.JMS_TARGET_ATTRIBUTES) {
        attr.marshallAsElement(value, writer);
    }
    writer.writeEndElement();
    for (AttributeDefinition attr : JMSBridgeDefinition.JMS_BRIDGE_ATTRIBUTES) {
        if (attr == JMSBridgeDefinition.MODULE) {
            // handled as a XML attribute
            continue;
        }
        attr.marshallAsElement(value, writer);
    }
    writer.writeEndElement();
}
Also used : AttributeDefinition(org.jboss.as.controller.AttributeDefinition)

Example 47 with AttributeDefinition

use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.

the class MessagingXMLWriter method writeConnectionFactories.

private static void writeConnectionFactories(final XMLExtendedStreamWriter writer, final ModelNode node) throws XMLStreamException {
    if (!node.isDefined()) {
        return;
    }
    if (node.asInt() > 0) {
        for (String name : node.keys()) {
            final ModelNode factory = node.get(name);
            if (factory.isDefined()) {
                writer.writeStartElement(Element.CONNECTION_FACTORY.getLocalName());
                writer.writeAttribute(Attribute.NAME.getLocalName(), name);
                for (AttributeDefinition attribute : ConnectionFactoryDefinition.ATTRIBUTES) {
                    attribute.marshallAsElement(factory, writer);
                }
                writer.writeEndElement();
            }
        }
    }
}
Also used : AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelNode(org.jboss.dmr.ModelNode)

Example 48 with AttributeDefinition

use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.

the class ExternalPooledConnectionFactoryDefinition method define.

// the generation of the Pooled CF attributes is a bit ugly but it is with purpose:
// * factorize the attributes which are common between the regular CF and the pooled CF
// * keep in a single place the subtle differences (e.g. different default values for reconnect-attempts between
// the regular and pooled CF
private static ConnectionFactoryAttribute[] define(ConnectionFactoryAttribute[] specific, ConnectionFactoryAttribute... common) {
    int size = common.length + specific.length + 1;
    ConnectionFactoryAttribute[] result = new ConnectionFactoryAttribute[size];
    for (int i = 0; i < specific.length; i++) {
        ConnectionFactoryAttribute attr = specific[i];
        AttributeDefinition definition = attr.getDefinition();
        if (definition == ConnectionFactoryAttributes.Pooled.INITIAL_CONNECT_ATTEMPTS) {
            result[i] = ConnectionFactoryAttribute.create(SimpleAttributeDefinitionBuilder.create(ConnectionFactoryAttributes.Pooled.INITIAL_CONNECT_ATTEMPTS).setDefaultValue(new ModelNode(-1)).build(), attr.getPropertyName(), true);
        } else {
            result[i] = attr;
        }
    }
    for (int i = 0; i < common.length; i++) {
        ConnectionFactoryAttribute attr = common[i];
        AttributeDefinition definition = attr.getDefinition();
        ConnectionFactoryAttribute newAttr;
        // replace the reconnect-attempts attribute to use a different default value for pooled CF
        if (definition == Common.RECONNECT_ATTEMPTS) {
            AttributeDefinition copy = copy(Pooled.RECONNECT_ATTEMPTS, AttributeAccess.Flag.RESTART_ALL_SERVICES);
            newAttr = ConnectionFactoryAttribute.create(copy, Pooled.RECONNECT_ATTEMPTS_PROP_NAME, true);
        } else if (definition == CommonAttributes.HA) {
            newAttr = ConnectionFactoryAttribute.create(SimpleAttributeDefinitionBuilder.create(CommonAttributes.HA).setDefaultValue(ModelNode.TRUE).setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES).build(), attr.getPropertyName(), true);
        } else if (definition == Common.CONNECTORS) {
            StringListAttributeDefinition copy = new StringListAttributeDefinition.Builder(Common.CONNECTORS).setAlternatives(CommonAttributes.DISCOVERY_GROUP).setRequired(true).setAttributeParser(AttributeParser.STRING_LIST).setAttributeMarshaller(AttributeMarshaller.STRING_LIST).setCapabilityReference(new AbstractTransportDefinition.TransportCapabilityReferenceRecorder(CAPABILITY_NAME, CONNECTOR_CAPABILITY_NAME, true)).setRestartAllServices().build();
            newAttr = ConnectionFactoryAttribute.create(copy, attr.getPropertyName(), attr.isResourceAdapterProperty(), attr.getConfigType());
        } else {
            AttributeDefinition copy = copy(definition, AttributeAccess.Flag.RESTART_ALL_SERVICES);
            newAttr = ConnectionFactoryAttribute.create(copy, attr.getPropertyName(), attr.isResourceAdapterProperty(), attr.getConfigType());
        }
        result[specific.length + i] = newAttr;
    }
    result[size - 1] = ConnectionFactoryAttribute.create(External.ENABLE_AMQ1_PREFIX, "enable1xPrefixes", true);
    return result;
}
Also used : StringListAttributeDefinition(org.jboss.as.controller.StringListAttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SimpleMapAttributeDefinition(org.jboss.as.controller.SimpleMapAttributeDefinition) StringListAttributeDefinition(org.jboss.as.controller.StringListAttributeDefinition) PrimitiveListAttributeDefinition(org.jboss.as.controller.PrimitiveListAttributeDefinition) SimpleListAttributeDefinition(org.jboss.as.controller.SimpleListAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelNode(org.jboss.dmr.ModelNode) AbstractTransportDefinition(org.wildfly.extension.messaging.activemq.AbstractTransportDefinition)

Example 49 with AttributeDefinition

use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.

the class PooledConnectionFactoryAdd method getAdapterParams.

static List<PooledConnectionFactoryConfigProperties> getAdapterParams(ModelNode model, OperationContext context, ConnectionFactoryAttribute[] attributes) throws OperationFailedException {
    List<PooledConnectionFactoryConfigProperties> configs = new ArrayList<PooledConnectionFactoryConfigProperties>();
    for (ConnectionFactoryAttribute nodeAttribute : attributes) {
        if (!nodeAttribute.isResourceAdapterProperty())
            continue;
        AttributeDefinition definition = nodeAttribute.getDefinition();
        ModelNode node = definition.resolveModelAttribute(context, model);
        if (node.isDefined()) {
            String attributeName = definition.getName();
            final String value;
            if (attributeName.equals(Common.DESERIALIZATION_BLACKLIST.getName())) {
                value = String.join(",", Common.DESERIALIZATION_BLACKLIST.unwrap(context, model));
            } else if (attributeName.equals(Common.DESERIALIZATION_WHITELIST.getName())) {
                value = String.join(",", Common.DESERIALIZATION_WHITELIST.unwrap(context, model));
            } else {
                value = node.asString();
            }
            configs.add(new PooledConnectionFactoryConfigProperties(nodeAttribute.getPropertyName(), value, nodeAttribute.getClassType(), nodeAttribute.getConfigType()));
        }
    }
    return configs;
}
Also used : ArrayList(java.util.ArrayList) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelNode(org.jboss.dmr.ModelNode)

Example 50 with AttributeDefinition

use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.

the class PooledConnectionFactoryAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
    ModelNode model = resource.getModel();
    PathAddress address = context.getCurrentAddress();
    final String name = context.getCurrentAddressValue();
    final ModelNode resolvedModel = model.clone();
    for (final AttributeDefinition attribute : attributes) {
        resolvedModel.get(attribute.getName()).set(attribute.resolveModelAttribute(context, resolvedModel));
    }
    // We validated that jndiName part of the model in populateModel
    final List<String> jndiNames = new ArrayList<>();
    for (ModelNode node : resolvedModel.get(Common.ENTRIES.getName()).asList()) {
        jndiNames.add(node.asString());
    }
    final BindInfo bindInfo = ContextNames.bindInfoFor(jndiNames.get(0));
    List<String> jndiAliases;
    if (jndiNames.size() > 1) {
        jndiAliases = new ArrayList<>(jndiNames.subList(1, jndiNames.size()));
    } else {
        jndiAliases = Collections.emptyList();
    }
    String managedConnectionPoolClassName = resolvedModel.get(ConnectionFactoryAttributes.Pooled.MANAGED_CONNECTION_POOL.getName()).asStringOrNull();
    final int minPoolSize = resolvedModel.get(ConnectionFactoryAttributes.Pooled.MIN_POOL_SIZE.getName()).asInt();
    final int maxPoolSize = resolvedModel.get(ConnectionFactoryAttributes.Pooled.MAX_POOL_SIZE.getName()).asInt();
    Boolean enlistmentTrace = resolvedModel.get(ConnectionFactoryAttributes.Pooled.ENLISTMENT_TRACE.getName()).asBooleanOrNull();
    String txSupport = getTxSupport(resolvedModel);
    List<String> connectors = Common.CONNECTORS.unwrap(context, model);
    String discoveryGroupName = getDiscoveryGroup(resolvedModel);
    String jgroupClusterName = null;
    final PathAddress serverAddress = MessagingServices.getActiveMQServerPathAddress(address);
    if (discoveryGroupName != null) {
        Resource dgResource;
        try {
            dgResource = context.readResourceFromRoot(serverAddress.append(CommonAttributes.SOCKET_DISCOVERY_GROUP, discoveryGroupName), false);
        } catch (Resource.NoSuchResourceException ex) {
            dgResource = context.readResourceFromRoot(serverAddress.append(CommonAttributes.JGROUPS_DISCOVERY_GROUP, discoveryGroupName), false);
        }
        ModelNode dgModel = dgResource.getModel();
        ModelNode jgroupCluster = JGROUPS_CLUSTER.resolveModelAttribute(context, dgModel);
        if (jgroupCluster.isDefined()) {
            jgroupClusterName = jgroupCluster.asString();
        }
    }
    List<PooledConnectionFactoryConfigProperties> adapterParams = getAdapterParams(resolvedModel, context, PooledConnectionFactoryDefinition.ATTRIBUTES);
    String serverName = serverAddress.getLastElement().getValue();
    PooledConnectionFactoryService.installService(context, name, serverName, connectors, discoveryGroupName, jgroupClusterName, adapterParams, bindInfo, jndiAliases, txSupport, minPoolSize, maxPoolSize, managedConnectionPoolClassName, enlistmentTrace, model);
    boolean statsEnabled = ConnectionFactoryAttributes.Pooled.STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean();
    if (statsEnabled) {
        // Add the stats resource. This is kind of a hack as we are modifying the resource
        // in runtime, but oh well. We don't use readResourceForUpdate for this reason.
        // This only runs in this add op anyway, and because it's an add we know readResource
        // is going to be returning the current write snapshot of the model, i.e. the one we want
        PooledConnectionFactoryStatisticsService.registerStatisticsResources(resource);
        installStatistics(context, name);
    }
}
Also used : ArrayList(java.util.ArrayList) Resource(org.jboss.as.controller.registry.Resource) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) BindInfo(org.jboss.as.naming.deployment.ContextNames.BindInfo)

Aggregations

AttributeDefinition (org.jboss.as.controller.AttributeDefinition)102 ModelNode (org.jboss.dmr.ModelNode)48 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)40 PathAddress (org.jboss.as.controller.PathAddress)17 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)16 ReloadRequiredWriteAttributeHandler (org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)14 OperationContext (org.jboss.as.controller.OperationContext)13 Resource (org.jboss.as.controller.registry.Resource)12 Property (org.jboss.dmr.Property)12 ObjectTypeAttributeDefinition (org.jboss.as.controller.ObjectTypeAttributeDefinition)9 PropertiesAttributeDefinition (org.jboss.as.controller.PropertiesAttributeDefinition)9 StringListAttributeDefinition (org.jboss.as.controller.StringListAttributeDefinition)9 OperationFailedException (org.jboss.as.controller.OperationFailedException)8 ArrayList (java.util.ArrayList)7 PrimitiveListAttributeDefinition (org.jboss.as.controller.PrimitiveListAttributeDefinition)6 Map (java.util.Map)5 AbstractAddStepHandler (org.jboss.as.controller.AbstractAddStepHandler)5 SimpleListAttributeDefinition (org.jboss.as.controller.SimpleListAttributeDefinition)5 SimpleOperationDefinitionBuilder (org.jboss.as.controller.SimpleOperationDefinitionBuilder)5 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)5