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