Search in sources :

Example 6 with ManagementService

use of org.apache.activemq.artemis.core.server.management.ManagementService in project activemq-artemis by apache.

the class BridgeReconnectTest method testReconnectSameNode.

// Fail bridge and reconnect same node, no backup specified
@Test
public void testReconnectSameNode() throws Exception {
    server0 = createActiveMQServer(0, isNetty(), server0Params);
    TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params, "server0tc");
    server0.getConfiguration().setConnectorConfigurations(connectors);
    server1.getConfiguration().setConnectorConfigurations(connectors);
    BridgeConfiguration bridgeConfiguration = createBridgeConfig();
    List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
    bridgeConfigs.add(bridgeConfiguration);
    server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
    CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName);
    List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
    queueConfigs0.add(queueConfig0);
    server0.getConfiguration().setQueueConfigurations(queueConfigs0);
    CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration().setAddress(forwardAddress).setName(queueName);
    List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<>();
    queueConfigs1.add(queueConfig1);
    server1.getConfiguration().setQueueConfigurations(queueConfigs1);
    startServers();
    locator = addServerLocator(ActiveMQClient.createServerLocatorWithHA(server0tc, server1tc));
    ClientSessionFactory csf0 = locator.createSessionFactory(server0tc);
    session0 = csf0.createSession(false, true, true);
    ClientSessionFactory csf1 = locator.createSessionFactory(server1tc);
    session1 = csf1.createSession(false, true, true);
    ClientProducer prod0 = session0.createProducer(testAddress);
    ClientConsumer cons1 = session1.createConsumer(queueName);
    session1.start();
    // Now we will simulate a failure of the bridge connection between server0 and server1
    Bridge bridge = server0.getClusterManager().getBridges().get(bridgeName);
    assertNotNull(bridge);
    RemotingConnection forwardingConnection = getForwardingConnection(bridge);
    InVMConnector.failOnCreateConnection = true;
    InVMConnector.numberOfFailures = reconnectAttempts - 1;
    forwardingConnection.fail(new ActiveMQNotConnectedException());
    forwardingConnection = getForwardingConnection(bridge);
    forwardingConnection.fail(new ActiveMQNotConnectedException());
    final ManagementService managementService = server0.getManagementService();
    QueueControl coreQueueControl = (QueueControl) managementService.getResource(ResourceNames.QUEUE + queueName);
    assertEquals(0, coreQueueControl.getDeliveringCount());
    final int numMessages = NUM_MESSAGES;
    SimpleString propKey = new SimpleString("propkey");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session0.createMessage(false);
        message.putIntProperty(propKey, i);
        prod0.send(message);
    }
    for (int i = 0; i < numMessages; i++) {
        ClientMessage r1 = cons1.receive(1500);
        assertNotNull(r1);
        assertEquals(i, r1.getObjectProperty(propKey));
    }
    closeServers();
    assertNoMoreConnections();
}
Also used : BridgeConfiguration(org.apache.activemq.artemis.core.config.BridgeConfiguration) ArrayList(java.util.ArrayList) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) ManagementService(org.apache.activemq.artemis.core.server.management.ManagementService) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Bridge(org.apache.activemq.artemis.core.server.cluster.Bridge) Test(org.junit.Test)

Example 7 with ManagementService

use of org.apache.activemq.artemis.core.server.management.ManagementService in project activemq-artemis by apache.

the class BridgeTestBase method removeAllMessages.

protected void removeAllMessages(final String queueName, final int index) throws Exception {
    ManagementService managementService = server0.getManagementService();
    if (index == 1) {
        managementService = server1.getManagementService();
    }
    QueueControl queueControl = (QueueControl) managementService.getResource("queue." + queueName);
    queueControl.removeMessages(null);
}
Also used : ManagementService(org.apache.activemq.artemis.core.server.management.ManagementService) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl)

Example 8 with ManagementService

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

the class ActiveMQServerResource method getCoreQueueNames.

private Set<String> getCoreQueueNames() {
    final ManagementService managementService = getManagementService();
    if (managementService == null) {
        return Collections.emptySet();
    } else {
        Set<String> result = new HashSet<String>();
        for (Object obj : managementService.getResources(QueueControl.class)) {
            QueueControl qc = QueueControl.class.cast(obj);
            result.add(qc.getName());
        }
        return result;
    }
}
Also used : ManagementService(org.apache.activemq.artemis.core.server.management.ManagementService) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 9 with ManagementService

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

the class JMSTopicControlHandler method executeRuntimeStep.

@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (rollbackOperationIfServerNotActive(context, operation)) {
        return;
    }
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    final String operationName = operation.require(ModelDescriptionConstants.OP).asString();
    final String topicName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
    boolean readOnly = context.getResourceRegistration().getOperationFlags(PathAddress.EMPTY_ADDRESS, operationName).contains(OperationEntry.Flag.READ_ONLY);
    ServiceController<?> service = context.getServiceRegistry(!readOnly).getService(serviceName);
    ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
    ManagementService managementService = server.getManagementService();
    AddressControl control = AddressControl.class.cast(managementService.getResource(ResourceNames.ADDRESS + JMS_TOPIC_PREFIX + topicName));
    if (control == null) {
        PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
        throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
    }
    try {
        if (LIST_ALL_SUBSCRIPTIONS.equals(operationName)) {
            String json = listAllSubscriptionsAsJSON(control, managementService);
            ModelNode jsonAsNode = ModelNode.fromJSONString(json);
            context.getResult().set(jsonAsNode);
        } else if (LIST_ALL_SUBSCRIPTIONS_AS_JSON.equals(operationName)) {
            context.getResult().set(listAllSubscriptionsAsJSON(control, managementService));
        } else if (LIST_DURABLE_SUBSCRIPTIONS.equals(operationName)) {
            String json = listDurableSubscriptionsAsJSON(control, managementService);
            ModelNode jsonAsNode = ModelNode.fromJSONString(json);
            context.getResult().set(jsonAsNode);
        } else if (LIST_DURABLE_SUBSCRIPTIONS_AS_JSON.equals(operationName)) {
            context.getResult().set(listDurableSubscriptionsAsJSON(control, managementService));
        } else if (LIST_NON_DURABLE_SUBSCRIPTIONS.equals(operationName)) {
            String json = listNonDurableSubscriptionsAsJSON(control, managementService);
            ModelNode jsonAsNode = ModelNode.fromJSONString(json);
            context.getResult().set(jsonAsNode);
        } else if (LIST_NON_DURABLE_SUBSCRIPTIONS_AS_JSON.equals(operationName)) {
            context.getResult().set(listNonDurableSubscriptionsAsJSON(control, managementService));
        } else if (LIST_MESSAGES_FOR_SUBSCRIPTION.equals(operationName)) {
            final String queueName = QUEUE_NAME.resolveModelAttribute(context, operation).asString();
            String json = listMessagesForSubscriptionAsJSON(queueName, managementService);
            context.getResult().set(ModelNode.fromJSONString(json));
        } else if (LIST_MESSAGES_FOR_SUBSCRIPTION_AS_JSON.equals(operationName)) {
            final String queueName = QUEUE_NAME.resolveModelAttribute(context, operation).asString();
            context.getResult().set(listMessagesForSubscriptionAsJSON(queueName, managementService));
        } else if (COUNT_MESSAGES_FOR_SUBSCRIPTION.equals(operationName)) {
            String clientId = CLIENT_ID.resolveModelAttribute(context, operation).asString();
            String subscriptionName = SUBSCRIPTION_NAME.resolveModelAttribute(context, operation).asString();
            String filter = resolveFilter(context, operation);
            context.getResult().set(countMessagesForSubscription(clientId, subscriptionName, filter, managementService));
        } else if (DROP_DURABLE_SUBSCRIPTION.equals(operationName)) {
            String clientId = CLIENT_ID.resolveModelAttribute(context, operation).asString();
            String subscriptionName = SUBSCRIPTION_NAME.resolveModelAttribute(context, operation).asString();
            dropDurableSubscription(clientId, subscriptionName, managementService);
            context.getResult();
        } else if (DROP_ALL_SUBSCRIPTIONS.equals(operationName)) {
            dropAllSubscriptions(control, managementService);
            context.getResult();
        } else if (REMOVE_MESSAGES.equals(operationName)) {
            String filter = resolveFilter(context, operation);
            context.getResult().set(removeMessages(filter, control, managementService));
        } else if (PAUSE.equals(operationName)) {
            pause(control, PERSIST.resolveModelAttribute(context, operation).asBoolean());
            context.getResult();
        } else if (RESUME.equals(operationName)) {
            resume(control);
            context.getResult();
        } else {
            // Bug
            throw MessagingLogger.ROOT_LOGGER.unsupportedOperation(operationName);
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        context.getFailureDescription().set(e.toString());
    }
    context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ManagementService(org.apache.activemq.artemis.core.server.management.ManagementService) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ModelNode(org.jboss.dmr.ModelNode) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 10 with ManagementService

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

the class JMSTopicReadAttributeHandler 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();
    String topicName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
    ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
    ManagementService managementService = server.getManagementService();
    AddressControl control = AddressControl.class.cast(managementService.getResource(ResourceNames.ADDRESS + JMS_TOPIC_PREFIX + topicName));
    if (control == null) {
        PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
        throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
    }
    if (CommonAttributes.MESSAGE_COUNT.getName().equals(attributeName)) {
        try {
            context.getResult().set(control.getMessageCount());
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else if (CommonAttributes.DELIVERING_COUNT.getName().equals(attributeName)) {
        context.getResult().set(getDeliveringCount(control, managementService));
    } else if (CommonAttributes.MESSAGES_ADDED.getName().equals(attributeName)) {
        context.getResult().set(getMessagesAdded(control, managementService));
    } else if (DURABLE_MESSAGE_COUNT.getName().equals(attributeName)) {
        context.getResult().set(getDurableMessageCount(control, managementService));
    } else if (NON_DURABLE_MESSAGE_COUNT.getName().equals(attributeName)) {
        context.getResult().set(getNonDurableMessageCount(control, managementService));
    } else if (SUBSCRIPTION_COUNT.getName().equals(attributeName)) {
        context.getResult().set(getSubscriptionCount(control, managementService));
    } else if (DURABLE_SUBSCRIPTION_COUNT.getName().equals(attributeName)) {
        context.getResult().set(getDurableSubscriptionCount(control, managementService));
    } else if (NON_DURABLE_SUBSCRIPTION_COUNT.getName().equals(attributeName)) {
        context.getResult().set(getNonDurableSubscriptionCount(control, managementService));
    } else if (TOPIC_ADDRESS.getName().equals(attributeName)) {
        context.getResult().set(control.getAddress());
    } else if (CommonAttributes.TEMPORARY.getName().equals(attributeName)) {
        // This attribute does not make sense. Jakarta Messaging topics created by the management API are always
        // managed and not temporary. Only topics created by the Clients can be temporary.
        context.getResult().set(false);
    } else if (PAUSED.getName().equals(attributeName)) {
        context.getResult().set(control.isPaused());
    } else {
        throw MessagingLogger.ROOT_LOGGER.unsupportedAttribute(attributeName);
    }
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ManagementService(org.apache.activemq.artemis.core.server.management.ManagementService) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Aggregations

ManagementService (org.apache.activemq.artemis.core.server.management.ManagementService)10 AddressControl (org.apache.activemq.artemis.api.core.management.AddressControl)4 QueueControl (org.apache.activemq.artemis.api.core.management.QueueControl)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)2 OperationFailedException (org.jboss.as.controller.OperationFailedException)2 PathAddress (org.jboss.as.controller.PathAddress)2 ServiceName (org.jboss.msc.service.ServiceName)2 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)1 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)1 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)1 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)1 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)1 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)1 ActiveMQServerControl (org.apache.activemq.artemis.api.core.management.ActiveMQServerControl)1 BridgeConfiguration (org.apache.activemq.artemis.core.config.BridgeConfiguration)1