Search in sources :

Example 11 with ActiveMQServer

use of org.apache.activemq.artemis.core.server.ActiveMQServer in project wildfly by wildfly.

the class AbstractQueueControlHandler method executeRuntimeStep.

@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (rollbackOperationIfServerNotActive(context, operation)) {
        return;
    }
    final String operationName = operation.require(ModelDescriptionConstants.OP).asString();
    final String queueName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
    final ServiceName activeMQServiceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    ServiceController<?> activeMQService = context.getServiceRegistry(false).getService(activeMQServiceName);
    ActiveMQServer server = ActiveMQServer.class.cast(activeMQService.getValue());
    final DelegatingQueueControl<T> control = getQueueControl(server, queueName);
    if (control == null) {
        PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
        throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
    }
    boolean reversible = false;
    Object handback = null;
    try {
        if (LIST_MESSAGES.equals(operationName)) {
            String filter = resolveFilter(context, operation);
            String json = control.listMessagesAsJSON(filter);
            context.getResult().set(ModelNode.fromJSONString(json));
        } else if (LIST_MESSAGES_AS_JSON.equals(operationName)) {
            String filter = resolveFilter(context, operation);
            context.getResult().set(control.listMessagesAsJSON(filter));
        } else if (LIST_DELIVERING_MESSAGES.equals(operationName)) {
            String json = control.listDeliveringMessagesAsJSON();
            context.getResult().set(ModelNode.fromJSONString(json));
        } else if (LIST_DELIVERING_MESSAGES_AS_JSON.equals(operationName)) {
            context.getResult().set(control.listDeliveringMessagesAsJSON());
        } else if (LIST_SCHEDULED_MESSAGES.equals(operationName)) {
            String json = control.listScheduledMessagesAsJSON();
            context.getResult().set(ModelNode.fromJSONString(json));
        } else if (LIST_SCHEDULED_MESSAGES_AS_JSON.equals(operationName)) {
            context.getResult().set(control.listScheduledMessagesAsJSON());
        } else if (COUNT_MESSAGES.equals(operationName)) {
            String filter = resolveFilter(context, operation);
            context.getResult().set(control.countMessages(filter));
        } else if (REMOVE_MESSAGE.equals(operationName)) {
            ModelNode id = getMessageIDAttributeDefinition().resolveModelAttribute(context, operation);
            context.getResult().set(control.removeMessage(id));
        } else if (REMOVE_MESSAGES.equals(operationName)) {
            String filter = resolveFilter(context, operation);
            context.getResult().set(control.removeMessages(filter));
        } else if (EXPIRE_MESSAGES.equals(operationName)) {
            String filter = resolveFilter(context, operation);
            context.getResult().set(control.expireMessages(filter));
        } else if (EXPIRE_MESSAGE.equals(operationName)) {
            ModelNode id = getMessageIDAttributeDefinition().resolveModelAttribute(context, operation);
            context.getResult().set(control.expireMessage(id));
        } else if (SEND_MESSAGE_TO_DEAD_LETTER_ADDRESS.equals(operationName)) {
            ModelNode id = getMessageIDAttributeDefinition().resolveModelAttribute(context, operation);
            context.getResult().set(control.sendMessageToDeadLetterAddress(id));
        } else if (SEND_MESSAGES_TO_DEAD_LETTER_ADDRESS.equals(operationName)) {
            String filter = resolveFilter(context, operation);
            context.getResult().set(control.sendMessagesToDeadLetterAddress(filter));
        } else if (CHANGE_MESSAGE_PRIORITY.equals(operationName)) {
            ModelNode id = getMessageIDAttributeDefinition().resolveModelAttribute(context, operation);
            int priority = NEW_PRIORITY.resolveModelAttribute(context, operation).asInt();
            context.getResult().set(control.changeMessagePriority(id, priority));
        } else if (CHANGE_MESSAGES_PRIORITY.equals(operationName)) {
            String filter = resolveFilter(context, operation);
            int priority = NEW_PRIORITY.resolveModelAttribute(context, operation).asInt();
            context.getResult().set(control.changeMessagesPriority(filter, priority));
        } else if (MOVE_MESSAGE.equals(operationName)) {
            ModelNode id = getMessageIDAttributeDefinition().resolveModelAttribute(context, operation);
            String otherQueue = OTHER_QUEUE_NAME.resolveModelAttribute(context, operation).asString();
            ModelNode rejectDuplicates = REJECT_DUPLICATES.resolveModelAttribute(context, operation);
            if (rejectDuplicates.isDefined()) {
                context.getResult().set(control.moveMessage(id, otherQueue, rejectDuplicates.asBoolean()));
            } else {
                context.getResult().set(control.moveMessage(id, otherQueue));
            }
        } else if (MOVE_MESSAGES.equals(operationName)) {
            String filter = resolveFilter(context, operation);
            String otherQueue = OTHER_QUEUE_NAME.resolveModelAttribute(context, operation).asString();
            ModelNode rejectDuplicates = REJECT_DUPLICATES.resolveModelAttribute(context, operation);
            if (rejectDuplicates.isDefined()) {
                context.getResult().set(control.moveMessages(filter, otherQueue, rejectDuplicates.asBoolean()));
            } else {
                context.getResult().set(control.moveMessages(filter, otherQueue));
            }
        } else if (LIST_MESSAGE_COUNTER_AS_JSON.equals(operationName)) {
            context.getResult().set(control.listMessageCounter());
        } else if (LIST_MESSAGE_COUNTER_AS_HTML.equals(operationName)) {
            context.getResult().set(control.listMessageCounterAsHTML());
        } else if (LIST_MESSAGE_COUNTER_HISTORY_AS_JSON.equals(operationName)) {
            context.getResult().set(control.listMessageCounterHistory());
        } else if (LIST_MESSAGE_COUNTER_HISTORY_AS_HTML.equals(operationName)) {
            context.getResult().set(control.listMessageCounterHistoryAsHTML());
        } else if (RESET_MESSAGE_COUNTER.equals(operationName)) {
            control.resetMessageCounter();
            // undefined
            context.getResult();
        } else if (PAUSE.equals(operationName)) {
            control.pause();
            reversible = true;
            // undefined
            context.getResult();
        } else if (RESUME.equals(operationName)) {
            control.resume();
            reversible = true;
            // undefined
            context.getResult();
        } else if (LIST_CONSUMERS_AS_JSON.equals(operationName)) {
            context.getResult().set(control.listConsumersAsJSON());
        } else {
            // TODO dmr-based LIST_MESSAGE_COUNTER, LIST_MESSAGE_COUNTER_HISTORY, LIST_CONSUMERS
            handback = handleAdditionalOperation(operationName, operation, context, control.getDelegate());
            reversible = handback == null;
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        context.getFailureDescription().set(e.getLocalizedMessage());
    }
    OperationContext.RollbackHandler rh;
    if (reversible) {
        final Object rhHandback = handback;
        rh = new OperationContext.RollbackHandler() {

            @Override
            public void handleRollback(OperationContext context, ModelNode operation) {
                try {
                    if (PAUSE.equals(operationName)) {
                        control.resume();
                    } else if (RESUME.equals(operationName)) {
                        control.pause();
                    } else {
                        revertAdditionalOperation(operationName, operation, context, control.getDelegate(), rhHandback);
                    }
                } catch (Exception e) {
                    ROOT_LOGGER.revertOperationFailed(e, getClass().getSimpleName(), operation.require(ModelDescriptionConstants.OP).asString(), PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)));
                }
            }
        };
    } else {
        rh = OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER;
    }
    context.completeStep(rh);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationFailedException(org.jboss.as.controller.OperationFailedException) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) LIST(org.jboss.dmr.ModelType.LIST) INT(org.jboss.dmr.ModelType.INT) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode)

Example 12 with ActiveMQServer

use of org.apache.activemq.artemis.core.server.ActiveMQServer in project wildfly by wildfly.

the class ActiveMQServerControlHandler method executeRuntimeStep.

@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    final String operationName = operation.require(OP).asString();
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    if (READ_ATTRIBUTE_OPERATION.equals(operationName)) {
        ActiveMQServer server = null;
        if (context.getRunningMode() == RunningMode.NORMAL) {
            ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
            if (service == null || service.getState() != ServiceController.State.UP) {
                throw MessagingLogger.ROOT_LOGGER.activeMQServerNotInstalled(serviceName.getSimpleName());
            }
            server = ActiveMQServer.class.cast(service.getValue());
        }
        handleReadAttribute(context, operation, server);
        return;
    }
    if (rollbackOperationIfServerNotActive(context, operation)) {
        return;
    }
    final ActiveMQServerControl serverControl = getServerControl(context, operation);
    try {
        if (GET_CONNECTORS_AS_JSON.equals(operationName)) {
            String json = serverControl.getConnectorsAsJSON();
            context.getResult().set(json);
        } else if (RESET_ALL_MESSAGE_COUNTERS.equals(operationName)) {
            serverControl.resetAllMessageCounters();
            context.getResult();
        } else if (RESET_ALL_MESSAGE_COUNTER_HISTORIES.equals(operationName)) {
            serverControl.resetAllMessageCounterHistories();
            context.getResult();
        } else if (LIST_PREPARED_TRANSACTIONS.equals(operationName)) {
            String[] list = serverControl.listPreparedTransactions();
            reportListOfStrings(context, list);
        } else if (LIST_PREPARED_TRANSACTION_DETAILS_AS_JSON.equals(operationName)) {
            String json = serverControl.listPreparedTransactionDetailsAsJSON();
            context.getResult().set(json);
        } else if (LIST_PREPARED_TRANSACTION_DETAILS_AS_HTML.equals(operationName)) {
            String html = serverControl.listPreparedTransactionDetailsAsHTML();
            context.getResult().set(html);
        } else if (LIST_HEURISTIC_COMMITTED_TRANSACTIONS.equals(operationName)) {
            String[] list = serverControl.listHeuristicCommittedTransactions();
            reportListOfStrings(context, list);
        } else if (LIST_HEURISTIC_ROLLED_BACK_TRANSACTIONS.equals(operationName)) {
            String[] list = serverControl.listHeuristicRolledBackTransactions();
            reportListOfStrings(context, list);
        } else if (COMMIT_PREPARED_TRANSACTION.equals(operationName)) {
            String txId = TRANSACTION_AS_BASE_64.resolveModelAttribute(context, operation).asString();
            boolean committed = serverControl.commitPreparedTransaction(txId);
            context.getResult().set(committed);
        } else if (ROLLBACK_PREPARED_TRANSACTION.equals(operationName)) {
            String txId = TRANSACTION_AS_BASE_64.resolveModelAttribute(context, operation).asString();
            boolean committed = serverControl.rollbackPreparedTransaction(txId);
            context.getResult().set(committed);
        } else if (LIST_REMOTE_ADDRESSES.equals(operationName)) {
            ModelNode address = OPTIONAL_IP_ADDRESS.resolveModelAttribute(context, operation);
            String[] list = address.isDefined() ? serverControl.listRemoteAddresses(address.asString()) : serverControl.listRemoteAddresses();
            reportListOfStrings(context, list);
        } else if (CLOSE_CONNECTIONS_FOR_ADDRESS.equals(operationName)) {
            String address = REQUIRED_IP_ADDRESS.resolveModelAttribute(context, operation).asString();
            boolean closed = serverControl.closeConnectionsForAddress(address);
            context.getResult().set(closed);
        } else if (CLOSE_CONNECTIONS_FOR_USER.equals(operationName)) {
            String user = USER.resolveModelAttribute(context, operation).asString();
            boolean closed = serverControl.closeConnectionsForUser(user);
            context.getResult().set(closed);
        } else if (CLOSE_CONSUMER_CONNECTIONS_FOR_ADDRESS.equals(operationName)) {
            String address = ADDRESS_MATCH.resolveModelAttribute(context, operation).asString();
            boolean closed = serverControl.closeConsumerConnectionsForAddress(address);
            context.getResult().set(closed);
        } else if (LIST_CONNECTION_IDS.equals(operationName)) {
            String[] list = serverControl.listConnectionIDs();
            reportListOfStrings(context, list);
        } else if (LIST_PRODUCERS_INFO_AS_JSON.equals(operationName)) {
            String json = serverControl.listProducersInfoAsJSON();
            context.getResult().set(json);
        } else if (LIST_SESSIONS.equals(operationName)) {
            String connectionID = CONNECTION_ID.resolveModelAttribute(context, operation).asString();
            String[] list = serverControl.listSessions(connectionID);
            reportListOfStrings(context, list);
        } else if (GET_ROLES.equals(operationName)) {
            String addressMatch = ADDRESS_MATCH.resolveModelAttribute(context, operation).asString();
            String json = serverControl.getRolesAsJSON(addressMatch);
            reportRoles(context, json);
        } else if (GET_ROLES_AS_JSON.equals(operationName)) {
            String addressMatch = ADDRESS_MATCH.resolveModelAttribute(context, operation).asString();
            String json = serverControl.getRolesAsJSON(addressMatch);
            reportRolesAsJSON(context, json);
        } else if (GET_ADDRESS_SETTINGS_AS_JSON.equals(operationName)) {
            String addressMatch = ADDRESS_MATCH.resolveModelAttribute(context, operation).asString();
            String json = serverControl.getAddressSettingsAsJSON(addressMatch);
            context.getResult().set(json);
        } else if (FORCE_FAILOVER.equals(operationName)) {
            serverControl.forceFailover();
            context.getResult();
        } else {
            // Bug
            throw MessagingLogger.ROOT_LOGGER.unsupportedOperation(operationName);
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        context.getFailureDescription().set(e.getLocalizedMessage());
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) ServiceName(org.jboss.msc.service.ServiceName) ModelNode(org.jboss.dmr.ModelNode) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 13 with ActiveMQServer

use of org.apache.activemq.artemis.core.server.ActiveMQServer in project wildfly by wildfly.

the class ActiveMQServerControlHandler method getServerControl.

private ActiveMQServerControl getServerControl(final OperationContext context, ModelNode operation) throws OperationFailedException {
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
    if (service == null || service.getState() != ServiceController.State.UP) {
        throw MessagingLogger.ROOT_LOGGER.activeMQServerNotInstalled(serviceName.getSimpleName());
    }
    ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
    return server.getActiveMQServerControl();
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName)

Example 14 with ActiveMQServer

use of org.apache.activemq.artemis.core.server.ActiveMQServer in project wildfly by wildfly.

the class BridgeRemove method recoverServices.

@Override
protected void recoverServices(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    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) {
        final String name = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
        final BridgeConfiguration bridgeConfiguration = BridgeAdd.createBridgeConfiguration(context, name, model);
        ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
        BridgeAdd.createBridge(name, bridgeConfiguration, server.getActiveMQServerControl());
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) BridgeConfiguration(org.apache.activemq.artemis.core.config.BridgeConfiguration) ServiceRegistry(org.jboss.msc.service.ServiceRegistry)

Example 15 with ActiveMQServer

use of org.apache.activemq.artemis.core.server.ActiveMQServer in project wildfly by wildfly.

the class AddressSettingRemove method performRuntime.

@Override
protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException {
    final ActiveMQServer server = getServer(context, operation);
    if (server != null) {
        final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
        server.getAddressSettingsRepository().removeMatch(address.getLastElement().getValue());
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) PathAddress(org.jboss.as.controller.PathAddress)

Aggregations

ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)37 ServiceName (org.jboss.msc.service.ServiceName)20 PathAddress (org.jboss.as.controller.PathAddress)19 OperationFailedException (org.jboss.as.controller.OperationFailedException)12 ModelNode (org.jboss.dmr.ModelNode)9 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)5 ActiveMQActivationService.getActiveMQServer (org.wildfly.extension.messaging.activemq.ActiveMQActivationService.getActiveMQServer)4 Role (org.apache.activemq.artemis.core.security.Role)3 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)3 HttpServerExchange (io.undertow.server.HttpServerExchange)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 ConnectionFactoryControl (org.apache.activemq.artemis.api.jms.management.ConnectionFactoryControl)2 JMSServerControl (org.apache.activemq.artemis.api.jms.management.JMSServerControl)2 TopicControl (org.apache.activemq.artemis.api.jms.management.TopicControl)2 RemotingService (org.apache.activemq.artemis.core.remoting.server.RemotingService)2 OperationContext (org.jboss.as.controller.OperationContext)2 Resource (org.jboss.as.controller.registry.Resource)2 ContextNames (org.jboss.as.naming.deployment.ContextNames)2 StartException (org.jboss.msc.service.StartException)2 SocketChannel (io.netty.channel.socket.SocketChannel)1