Search in sources :

Example 76 with OperationFailedException

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

the class JMSConnectionFactoryDefinitionInjectionSource method getResourceValue.

@Override
public void getResourceValue(ResolutionContext context, ServiceBuilder<?> serviceBuilder, DeploymentPhaseContext phaseContext, Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (targetsPooledConnectionFactory(getActiveMQServerName(properties), resourceAdapter, phaseContext.getServiceRegistry())) {
        try {
            startedPooledConnectionFactory(context, jndiName, serviceBuilder, phaseContext.getServiceTarget(), deploymentUnit, injector);
        } catch (OperationFailedException e) {
            throw new DeploymentUnitProcessingException(e);
        }
    } else {
        // delegate to the resource-adapter subsystem to create a generic JCA connection factory.
        ConnectionFactoryDefinitionInjectionSource cfdis = new ConnectionFactoryDefinitionInjectionSource(jndiName, interfaceName, resourceAdapter);
        cfdis.setMaxPoolSize(maxPoolSize);
        cfdis.setMinPoolSize(minPoolSize);
        cfdis.setTransactionSupportLevel(transactional ? TransactionSupport.TransactionSupportLevel.XATransaction : TransactionSupport.TransactionSupportLevel.NoTransaction);
        // transfer all the generic properties + the additional properties specific to the JMSConnectionFactoryDefinition
        for (Map.Entry<String, String> property : properties.entrySet()) {
            cfdis.addProperty(property.getKey(), property.getValue());
        }
        if (!user.isEmpty()) {
            cfdis.addProperty("user", user);
        }
        if (!password.isEmpty()) {
            cfdis.addProperty("password", password);
        }
        if (!clientId.isEmpty()) {
            cfdis.addProperty("clientId", clientId);
        }
        cfdis.getResourceValue(context, serviceBuilder, phaseContext, injector);
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ConnectionFactoryDefinitionInjectionSource(org.jboss.as.connector.deployers.ra.ConnectionFactoryDefinitionInjectionSource) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) Map(java.util.Map) HashMap(java.util.HashMap)

Example 77 with OperationFailedException

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

the class QueueReadAttributeHandler method executeRuntimeStep.

@Override
public void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (ignoreOperationIfServerNotActive(context, operation)) {
        return;
    }
    validator.validate(operation);
    final String attributeName = operation.require(ModelDescriptionConstants.NAME).asString();
    PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
    String queueName = address.getLastElement().getValue();
    if (forwardToRuntimeQueue(context, operation, RUNTIME_INSTANCE)) {
        return;
    }
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(address);
    ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
    ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
    QueueControl control = QueueControl.class.cast(server.getManagementService().getResource(ResourceNames.CORE_QUEUE + queueName));
    if (control == null) {
        throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
    }
    if (MESSAGE_COUNT.getName().equals(attributeName)) {
        context.getResult().set(control.getMessageCount());
    } else if (SCHEDULED_COUNT.getName().equals(attributeName)) {
        context.getResult().set(control.getScheduledCount());
    } else if (CONSUMER_COUNT.getName().equals(attributeName)) {
        context.getResult().set(control.getConsumerCount());
    } else if (DELIVERING_COUNT.getName().equals(attributeName)) {
        context.getResult().set(control.getDeliveringCount());
    } else if (MESSAGES_ADDED.getName().equals(attributeName)) {
        context.getResult().set(control.getMessagesAdded());
    } else if (ID.getName().equals(attributeName)) {
        context.getResult().set(control.getID());
    } else if (PAUSED.getName().equals(attributeName)) {
        try {
            context.getResult().set(control.isPaused());
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else if (TEMPORARY.getName().equals(attributeName)) {
        context.getResult().set(control.isTemporary());
    } else if (EXPIRY_ADDRESS.getName().equals(attributeName)) {
        if (control.getExpiryAddress() != null) {
            context.getResult().set(control.getExpiryAddress());
        }
    } else if (DEAD_LETTER_ADDRESS.getName().equals(attributeName)) {
        if (control.getDeadLetterAddress() != null) {
            context.getResult().set(control.getDeadLetterAddress());
        }
    } else if (readStorageAttributes && getStorageAttributeNames().contains(attributeName)) {
        if (ADDRESS.getName().equals(attributeName)) {
            context.getResult().set(control.getAddress());
        } else if (DURABLE.getName().equals(attributeName)) {
            context.getResult().set(control.isDurable());
        } else if (FILTER.getName().equals(attributeName)) {
            ModelNode result = context.getResult();
            String filter = control.getFilter();
            if (filter != null) {
                result.set(filter);
            }
        }
    } else {
        throw MessagingLogger.ROOT_LOGGER.unsupportedAttribute(attributeName);
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 78 with OperationFailedException

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

the class GroupingHandlerAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    ServiceRegistry registry = context.getServiceRegistry(true);
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    ServiceController<?> service = registry.getService(serviceName);
    if (service != null) {
        final ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
        if (server.getGroupingHandler() != null) {
            throw new OperationFailedException(MessagingLogger.ROOT_LOGGER.childResourceAlreadyExists(CommonAttributes.GROUPING_HANDLER));
        }
        // the groupingHandler is added as a child of the server resource. Requires a reload to restart the server with the grouping-handler
        if (context.isNormalServer()) {
            context.addStep(new OperationStepHandler() {

                public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                    context.reloadRequired();
                    context.completeStep(OperationContext.RollbackHandler.REVERT_RELOAD_REQUIRED_ROLLBACK_HANDLER);
                }
            }, OperationContext.Stage.RUNTIME);
        }
    }
// else the initial subsystem install is not complete and the grouping handler will be added in ServerAdd
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Example 79 with OperationFailedException

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

the class BridgeRemove method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final String name = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
    final ServiceRegistry registry = context.getServiceRegistry(true);
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    final ServiceController<?> service = registry.getService(serviceName);
    if (service != null && service.getState() == ServiceController.State.UP) {
        ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
        try {
            server.getActiveMQServerControl().destroyBridge(name);
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            // TODO should this be an OFE instead?
            throw new RuntimeException(e);
        }
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 80 with OperationFailedException

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

the class PoolOperations method execute.

public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    final String jndiName;
    ModelNode model;
    if (!address.getElement(0).getKey().equals(ModelDescriptionConstants.DEPLOYMENT) && (model = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel()).isDefined()) {
        jndiName = Util.getJndiName(context, model);
    } else {
        jndiName = address.getLastElement().getValue();
    }
    final Object[] parameters = getParameters(context, operation);
    if (context.isNormalServer()) {
        context.addStep(new OperationStepHandler() {

            public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                final ServiceController<?> managementRepoService = context.getServiceRegistry(disallowMonitor).getService(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE);
                if (managementRepoService != null) {
                    ModelNode operationResult = null;
                    try {
                        final ManagementRepository repository = (ManagementRepository) managementRepoService.getValue();
                        final List<Pool> pools = matcher.match(jndiName, repository);
                        if (pools.isEmpty()) {
                            throw ConnectorLogger.ROOT_LOGGER.failedToMatchPool(jndiName);
                        }
                        for (Pool pool : pools) {
                            operationResult = invokeCommandOn(pool, parameters);
                        }
                    } catch (Exception e) {
                        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToInvokeOperation(e.getLocalizedMessage()));
                    }
                    if (operationResult != null) {
                        context.getResult().set(operationResult);
                    }
                }
                context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
            }
        }, OperationContext.Stage.RUNTIME);
    }
    context.stepCompleted();
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) PathAddress(org.jboss.as.controller.PathAddress) ServiceController(org.jboss.msc.service.ServiceController) ArrayList(java.util.ArrayList) List(java.util.List) Pool(org.jboss.jca.core.api.connectionmanager.pool.Pool) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

OperationFailedException (org.jboss.as.controller.OperationFailedException)113 ModelNode (org.jboss.dmr.ModelNode)86 PathAddress (org.jboss.as.controller.PathAddress)51 OperationContext (org.jboss.as.controller.OperationContext)49 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)34 ServiceName (org.jboss.msc.service.ServiceName)33 Resource (org.jboss.as.controller.registry.Resource)26 ServiceController (org.jboss.msc.service.ServiceController)19 ServiceTarget (org.jboss.msc.service.ServiceTarget)15 PathElement (org.jboss.as.controller.PathElement)13 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)12 IOException (java.io.IOException)11 Map (java.util.Map)11 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)11 ArrayList (java.util.ArrayList)9 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)9 ContextNames (org.jboss.as.naming.deployment.ContextNames)7 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)7 List (java.util.List)6 ResourceServiceHandler (org.jboss.as.clustering.controller.ResourceServiceHandler)6