Search in sources :

Example 56 with OperationFailedException

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

the class RemotingProfileRemove method recoverServices.

@Override
protected void recoverServices(final OperationContext context, final ModelNode operation, final ModelNode profileNode) throws OperationFailedException {
    try {
        final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
        RemotingProfileAdd.INSTANCE.installServices(context, address, profileNode);
    } catch (OperationFailedException e) {
        throw ControllerLogger.ROOT_LOGGER.failedToRecoverServices(e);
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 57 with OperationFailedException

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

the class AbstractEJBComponentRuntimeHandler method getComponent.

private T getComponent(final ServiceName serviceName, final PathAddress operationAddress, final OperationContext context, final boolean forWrite) throws OperationFailedException {
    ServiceRegistry registry = context.getServiceRegistry(forWrite);
    ServiceController<?> controller = registry.getService(serviceName);
    if (controller == null) {
        String exceptionMessage = EjbLogger.ROOT_LOGGER.noComponentAvailableForAddress(operationAddress);
        throw new OperationFailedException(exceptionMessage);
    }
    ServiceController.State controllerState = controller.getState();
    if (controllerState != ServiceController.State.UP) {
        String exceptionMessage = EjbLogger.ROOT_LOGGER.invalidComponentState(operationAddress, controllerState, ServiceController.State.UP);
        throw new OperationFailedException(exceptionMessage);
    }
    return componentClass.cast(controller.getValue());
}
Also used : OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry)

Example 58 with OperationFailedException

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

the class AbstractEJBComponentRuntimeHandler method getComponentConfiguration.

private ServiceName getComponentConfiguration(final OperationContext context, final PathAddress operationAddress) throws OperationFailedException {
    final List<PathElement> relativeAddress = new ArrayList<PathElement>();
    final String typeKey = this.componentType.getResourceType();
    boolean skip = true;
    for (int i = operationAddress.size() - 1; i >= 0; i--) {
        PathElement pe = operationAddress.getElement(i);
        if (skip && !pe.getKey().equals(typeKey)) {
            continue;
        } else {
            skip = false;
        }
        if (ModelDescriptionConstants.DEPLOYMENT.equals(pe.getKey())) {
            final String runtimName = resolveRuntimeName(context, pe);
            PathElement realPe = PathElement.pathElement(pe.getKey(), runtimName);
            relativeAddress.add(0, realPe);
            break;
        } else {
            relativeAddress.add(0, pe);
        }
    }
    final PathAddress pa = PathAddress.pathAddress(relativeAddress);
    final ServiceName config = componentConfigs.get(pa);
    if (config == null) {
        String exceptionMessage = EjbLogger.ROOT_LOGGER.noComponentRegisteredForAddress(operationAddress);
        throw new OperationFailedException(exceptionMessage);
    }
    return config;
}
Also used : PathElement(org.jboss.as.controller.PathElement) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ArrayList(java.util.ArrayList) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 59 with OperationFailedException

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

the class AbstractUpdateJndiHandler method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    JNDI_BINDING.validateOperation(operation);
    final String jndiName = JNDI_BINDING.resolveModelAttribute(context, operation).asString();
    final ModelNode entries = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel().get(CommonAttributes.DESTINATION_ENTRIES.getName());
    if (addOperation) {
        for (ModelNode entry : entries.asList()) {
            if (jndiName.equals(entry.asString())) {
                throw new OperationFailedException(ROOT_LOGGER.jndiNameAlreadyRegistered(jndiName));
            }
        }
        entries.add(jndiName);
    } else {
        ModelNode updatedEntries = new ModelNode();
        boolean updated = false;
        for (ModelNode entry : entries.asList()) {
            if (jndiName.equals(entry.asString())) {
                if (entries.asList().size() == 1) {
                    throw new OperationFailedException(ROOT_LOGGER.canNotRemoveLastJNDIName(jndiName));
                }
                updated = true;
            } else {
                updatedEntries.add(entry);
            }
        }
        if (!updated) {
            throw MessagingLogger.ROOT_LOGGER.canNotRemoveUnknownEntry(jndiName);
        }
        context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel().get(CommonAttributes.DESTINATION_ENTRIES.getName()).set(updatedEntries);
    }
    if (context.isNormalServer()) {
        if (rollbackOperationIfServerNotActive(context, operation)) {
            return;
        }
        context.addStep(new OperationStepHandler() {

            @Override
            public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                final String resourceName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
                final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
                final ServiceName jmsManagerServiceName = JMSServices.getJmsManagerBaseServiceName(serviceName);
                final ServiceController<?> jmsServerService = context.getServiceRegistry(false).getService(jmsManagerServiceName);
                if (jmsServerService != null) {
                    JMSServerManager jmsServerManager = JMSServerManager.class.cast(jmsServerService.getValue());
                    if (jmsServerManager == null) {
                        PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
                        throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
                    }
                    try {
                        if (addOperation) {
                            addJndiName(jmsServerManager, resourceName, jndiName);
                        } else {
                            removeJndiName(jmsServerManager, resourceName, jndiName);
                        }
                    } catch (Exception e) {
                        context.getFailureDescription().set(e.getLocalizedMessage());
                    }
                }
                if (!context.hasFailureDescription()) {
                    context.getResult();
                }
                context.completeStep(new OperationContext.RollbackHandler() {

                    @Override
                    public void handleRollback(OperationContext context, ModelNode operation) {
                        if (jmsServerService != null) {
                            JMSServerManager jmsServerManager = JMSServerManager.class.cast(jmsServerService.getValue());
                            try {
                                if (addOperation) {
                                    removeJndiName(jmsServerManager, resourceName, jndiName);
                                } else {
                                    addJndiName(jmsServerManager, resourceName, jndiName);
                                }
                            } catch (Exception e) {
                                context.getFailureDescription().set(e.getLocalizedMessage());
                            }
                        }
                    }
                });
            }
        }, OperationContext.Stage.RUNTIME);
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) JMSServerManager(org.apache.activemq.artemis.jms.server.JMSServerManager) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ServiceController(org.jboss.msc.service.ServiceController) ModelNode(org.jboss.dmr.ModelNode)

Example 60 with OperationFailedException

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

the class JMSServerControlHandler method executeRuntimeStep.

@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (rollbackOperationIfServerNotActive(context, operation)) {
        return;
    }
    final String operationName = operation.require(OP).asString();
    final JMSServerControl serverControl = getServerControl(context, operation);
    if (serverControl == null) {
        PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
        throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
    }
    try {
        if (LIST_CONNECTIONS_AS_JSON.equals(operationName)) {
            String json = serverControl.listConnectionsAsJSON();
            context.getResult().set(json);
        } else if (LIST_CONSUMERS_AS_JSON.equals(operationName)) {
            String connectionID = CONNECTION_ID.resolveModelAttribute(context, operation).asString();
            String json = serverControl.listConsumersAsJSON(connectionID);
            context.getResult().set(json);
        } else if (LIST_ALL_CONSUMERS_AS_JSON.equals(operationName)) {
            String json = serverControl.listAllConsumersAsJSON();
            context.getResult().set(json);
        } else if (LIST_TARGET_DESTINATIONS.equals(operationName)) {
            String sessionID = SESSION_ID.resolveModelAttribute(context, operation).asString();
            String[] list = serverControl.listTargetDestinations(sessionID);
            reportListOfStrings(context, list);
        } else if (GET_LAST_SENT_MESSAGE_ID.equals(operationName)) {
            String sessionID = SESSION_ID.resolveModelAttribute(context, operation).asString();
            String addressName = ADDRESS_NAME.resolveModelAttribute(context, operation).asString();
            String msgId = serverControl.getLastSentMessageID(sessionID, addressName);
            context.getResult().set(msgId);
        } else if (GET_SESSION_CREATION_TIME.equals(operationName)) {
            String sessionID = SESSION_ID.resolveModelAttribute(context, operation).asString();
            String time = serverControl.getSessionCreationTime(sessionID);
            context.getResult().set(time);
        } else if (LIST_SESSIONS_AS_JSON.equals(operationName)) {
            String connectionID = CONNECTION_ID.resolveModelAttribute(context, operation).asString();
            String json = serverControl.listSessionsAsJSON(connectionID);
            context.getResult().set(json);
        } else if (LIST_PREPARED_TRANSACTION_JMS_DETAILS_AS_JSON.equals(operationName)) {
            String json = serverControl.listPreparedTransactionDetailsAsJSON();
            context.getResult().set(json);
        } else if (LIST_PREPARED_TRANSACTION_JMS_DETAILS_AS_HTML.equals(operationName)) {
            String html = serverControl.listPreparedTransactionDetailsAsHTML();
            context.getResult().set(html);
        } else {
            // Bug
            throw MessagingLogger.ROOT_LOGGER.unsupportedOperation(operationName);
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        context.getFailureDescription().set(e.getLocalizedMessage());
    }
}
Also used : JMSServerControl(org.apache.activemq.artemis.api.jms.management.JMSServerControl) PathAddress(org.jboss.as.controller.PathAddress) OperationFailedException(org.jboss.as.controller.OperationFailedException)

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