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());
}
}
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();
}
}
}
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);
}
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);
}
}
Aggregations