Search in sources :

Example 41 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class WebMigrateOperation method addExtension.

/**
     * It's possible that the extension is already present. In that case, this method does nothing.
     */
private void addExtension(OperationContext context, Map<PathAddress, ModelNode> migrationOperations, boolean describe, String extension) {
    Resource root = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, false);
    if (root.getChildrenNames(EXTENSION).contains(extension)) {
        // extension is already added, do nothing
        return;
    }
    PathAddress extensionAddress = pathAddress(EXTENSION, extension);
    OperationEntry addEntry = context.getRootResourceRegistration().getOperationEntry(extensionAddress, ADD);
    ModelNode addOperation = createAddOperation(extensionAddress);
    addOperation.get(MODULE).set(extension);
    if (describe) {
        migrationOperations.put(extensionAddress, addOperation);
    } else {
        context.addStep(context.getResult().get(extensionAddress.toString()), addOperation, addEntry.getOperationHandler(), MODEL);
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) OperationEntry(org.jboss.as.controller.registry.OperationEntry) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode)

Example 42 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class MigrateOperation method connectionFactoryIsUsingInVMConnectors.

private boolean connectionFactoryIsUsingInVMConnectors(OperationContext context, ModelNode connectionFactoryAddOp) {
    ModelNode connector = connectionFactoryAddOp.get(CONNECTOR);
    if (connector.isDefined()) {
        PathAddress connectionFactoryAddress = pathAddress(connectionFactoryAddOp.get(OP_ADDR));
        PathElement relativeLegacyServerAddress = connectionFactoryAddress.getParent().getLastElement();
        // read the server resource related to the context current address (which is the messaging subsystem address).
        Resource serverResource = context.readResource(pathAddress(relativeLegacyServerAddress), false);
        Set<String> definedInVMConnectors = serverResource.getChildrenNames("in-vm-connector");
        // legacy connector is a property list where the name is the connector and the value is undefined
        List<Property> connectorProps = connector.asPropertyList();
        for (Property connectorProp : connectorProps) {
            String connectorName = connectorProp.getName();
            if (definedInVMConnectors.contains(connectorName)) {
                return true;
            }
        }
    }
    return false;
}
Also used : PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Example 43 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class MigrateOperation method addMessagingActiveMQExtension.

/**
     * It's possible that the extension is already present. In that case, this method does nothing.
     */
private void addMessagingActiveMQExtension(OperationContext context, Map<PathAddress, ModelNode> migrationOperations, boolean describe) {
    Resource root = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, false);
    if (root.getChildrenNames(EXTENSION).contains(MESSAGING_ACTIVEMQ_EXTENSION)) {
        // extension is already added, do nothing
        return;
    }
    PathAddress extensionAddress = pathAddress(EXTENSION, MESSAGING_ACTIVEMQ_EXTENSION);
    OperationEntry addEntry = context.getRootResourceRegistration().getOperationEntry(extensionAddress, ADD);
    ModelNode addOperation = createAddOperation(extensionAddress);
    addOperation.get(MODULE).set(MESSAGING_ACTIVEMQ_MODULE);
    if (describe) {
        migrationOperations.put(extensionAddress, addOperation);
    } else {
        context.addStep(context.getResult().get(extensionAddress.toString()), addOperation, addEntry.getOperationHandler(), MODEL);
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) OperationEntry(org.jboss.as.controller.registry.OperationEntry) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode)

Example 44 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class BroadcastGroupDefinition method getAvailableConnectors.

private static Set<String> getAvailableConnectors(final OperationContext context, final ModelNode operation) throws OperationFailedException {
    PathAddress hornetqServer = context.getCurrentAddress().getParent();
    Resource hornetQServerResource = context.readResourceFromRoot(hornetqServer);
    Set<String> availableConnectors = new HashSet<String>();
    availableConnectors.addAll(hornetQServerResource.getChildrenNames(CommonAttributes.HTTP_CONNECTOR));
    availableConnectors.addAll(hornetQServerResource.getChildrenNames(CommonAttributes.IN_VM_CONNECTOR));
    availableConnectors.addAll(hornetQServerResource.getChildrenNames(CommonAttributes.REMOTE_CONNECTOR));
    availableConnectors.addAll(hornetQServerResource.getChildrenNames(CommonAttributes.CONNECTOR));
    return availableConnectors;
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) HashSet(java.util.HashSet)

Example 45 with Resource

use of org.jboss.as.controller.registry.Resource 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 : getDefinitions(PooledConnectionFactoryDefinition.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<String>();
    for (ModelNode node : resolvedModel.get(Common.ENTRIES.getName()).asList()) {
        jndiNames.add(node.asString());
    }
    String managedConnectionPoolClassName = null;
    if (resolvedModel.hasDefined(ConnectionFactoryAttributes.Pooled.MANAGED_CONNECTION_POOL.getName())) {
        managedConnectionPoolClassName = resolvedModel.get(ConnectionFactoryAttributes.Pooled.MANAGED_CONNECTION_POOL.getName()).asString();
    }
    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 = null;
    if (resolvedModel.hasDefined(ConnectionFactoryAttributes.Pooled.ENLISTMENT_TRACE.getName())) {
        enlistmentTrace = resolvedModel.get(ConnectionFactoryAttributes.Pooled.ENLISTMENT_TRACE.getName()).asBoolean();
    }
    final String txSupport;
    if (resolvedModel.hasDefined(ConnectionFactoryAttributes.Pooled.TRANSACTION.getName())) {
        String txType = resolvedModel.get(ConnectionFactoryAttributes.Pooled.TRANSACTION.getName()).asString();
        if (LOCAL.equals(txType)) {
            txSupport = LOCAL_TX;
        } else if (NONE.equals(txType)) {
            txSupport = NO_TX;
        } else {
            txSupport = XA_TX;
        }
    } else {
        txSupport = XA_TX;
    }
    ServiceTarget serviceTarget = context.getServiceTarget();
    List<String> connectors = Common.CONNECTORS.unwrap(context, model);
    String discoveryGroupName = getDiscoveryGroup(resolvedModel);
    String jgroupsChannelName = null;
    if (discoveryGroupName != null) {
        Resource dgResource = context.readResourceFromRoot(MessagingServices.getActiveMQServerPathAddress(address).append(CommonAttributes.DISCOVERY_GROUP, discoveryGroupName));
        ModelNode dgModel = dgResource.getModel();
        jgroupsChannelName = JGROUPS_CHANNEL.resolveModelAttribute(context, dgModel).asString();
    }
    List<PooledConnectionFactoryConfigProperties> adapterParams = getAdapterParams(resolvedModel, context);
    final PathAddress serverAddress = MessagingServices.getActiveMQServerPathAddress(address);
    PooledConnectionFactoryService.installService(serviceTarget, name, serverAddress.getLastElement().getValue(), connectors, discoveryGroupName, jgroupsChannelName, adapterParams, jndiNames, txSupport, minPoolSize, maxPoolSize, managedConnectionPoolClassName, enlistmentTrace);
    boolean statsEnabled = ConnectionFactoryAttributes.Pooled.STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean();
    if (statsEnabled) {
        installStatistics(context, name);
    }
}
Also used : ServiceTarget(org.jboss.msc.service.ServiceTarget) 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)

Aggregations

Resource (org.jboss.as.controller.registry.Resource)93 PathAddress (org.jboss.as.controller.PathAddress)52 ModelNode (org.jboss.dmr.ModelNode)52 PathElement (org.jboss.as.controller.PathElement)25 OperationFailedException (org.jboss.as.controller.OperationFailedException)24 OperationContext (org.jboss.as.controller.OperationContext)15 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)12 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)11 Map (java.util.Map)10 ServiceName (org.jboss.msc.service.ServiceName)10 ServiceTarget (org.jboss.msc.service.ServiceTarget)10 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)9 ResourceTransformationContext (org.jboss.as.controller.transform.ResourceTransformationContext)6 ResourceTransformer (org.jboss.as.controller.transform.ResourceTransformer)6 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)6 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)6 ObjectName (javax.management.ObjectName)5 Activation (org.jboss.jca.common.api.metadata.resourceadapter.Activation)5 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)5 ArrayList (java.util.ArrayList)4