Search in sources :

Example 26 with AddressControl

use of org.apache.activemq.artemis.api.core.management.AddressControl in project wildfly by wildfly.

the class AddressControlHandler method handleReadAttribute.

private void handleReadAttribute(OperationContext context, ModelNode operation) {
    if (ignoreOperationIfServerNotActive(context, operation)) {
        return;
    }
    final AddressControl addressControl = getAddressControl(context, operation);
    if (addressControl == null) {
        PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
        throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
    }
    final String name = operation.require(ModelDescriptionConstants.NAME).asString();
    try {
        if (ROLES_ATTR_NAME.equals(name)) {
            String json = addressControl.getRolesAsJSON();
            reportRoles(context, json);
        } else if (QUEUE_NAMES.equals(name)) {
            String[] queues = addressControl.getQueueNames();
            reportListOfStrings(context, queues);
        } else if (NUMBER_OF_BYTES_PER_PAGE.equals(name)) {
            long l = addressControl.getNumberOfBytesPerPage();
            context.getResult().set(l);
        } else if (NUMBER_OF_PAGES.equals(name)) {
            int i = addressControl.getNumberOfPages();
            context.getResult().set(i);
        } else if (BINDING_NAMES.equals(name)) {
            String[] bindings = addressControl.getBindingNames();
            reportListOfStrings(context, bindings);
        } else {
            // Bug
            throw MessagingLogger.ROOT_LOGGER.unsupportedAttribute(name);
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        context.getFailureDescription().set(e.getLocalizedMessage());
    }
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) PathAddress(org.jboss.as.controller.PathAddress) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 27 with AddressControl

use of org.apache.activemq.artemis.api.core.management.AddressControl in project wildfly by wildfly.

the class CoreAddressResource method getSecurityRoles.

private Set<String> getSecurityRoles() {
    AddressControl addressControl = getAddressControl();
    if (addressControl == null) {
        return Collections.emptySet();
    } else {
        Set<String> names = new HashSet<String>();
        try {
            ModelNode res = ModelNode.fromJSONString(addressControl.getRolesAsJSON());
            ModelNode converted = ManagementUtil.convertSecurityRole(res);
            for (ModelNode role : converted.asList()) {
                names.add(role.get(NAME).asString());
            }
            return names;
        } catch (Exception e) {
            return Collections.emptySet();
        }
    }
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) ModelNode(org.jboss.dmr.ModelNode) HashSet(java.util.HashSet)

Example 28 with AddressControl

use of org.apache.activemq.artemis.api.core.management.AddressControl 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 29 with AddressControl

use of org.apache.activemq.artemis.api.core.management.AddressControl 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

AddressControl (org.apache.activemq.artemis.api.core.management.AddressControl)29 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)21 Test (org.junit.Test)18 HashSet (java.util.HashSet)5 Connection (javax.jms.Connection)5 Session (javax.jms.Session)5 JsonString (javax.json.JsonString)5 RandomUtil.randomString (org.apache.activemq.artemis.tests.util.RandomUtil.randomString)5 OperationFailedException (org.jboss.as.controller.OperationFailedException)5 ManagementService (org.apache.activemq.artemis.core.server.management.ManagementService)4 PathAddress (org.jboss.as.controller.PathAddress)4 TextMessage (javax.jms.TextMessage)3 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)3 ModelNode (org.jboss.dmr.ModelNode)3 ServiceName (org.jboss.msc.service.ServiceName)3 BytesMessage (javax.jms.BytesMessage)2 MapMessage (javax.jms.MapMessage)2 Message (javax.jms.Message)2 MessageConsumer (javax.jms.MessageConsumer)2 ObjectMessage (javax.jms.ObjectMessage)2