diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/AuditLogger.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/AuditLogger.java index 5633997375..481a5945be 100644 --- a/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/AuditLogger.java +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/AuditLogger.java @@ -2960,4 +2960,20 @@ public interface AuditLogger extends BasicLogger { @LogMessage(level = Logger.Level.INFO) @Message(id = 601761, value = "User {0} rolled back transaction {1} involving {2}", format = Message.Format.MESSAGE_FORMAT) void rolledBackTransaction(String user, String tx, String resource); + + static void addConnector(Object source, Object... args) { + BASE_LOGGER.addConnector(getCaller(), source, arrayToString(args)); + } + + @LogMessage(level = Logger.Level.INFO) + @Message(id = 601762, value = "User {0} is adding a connector on target resource: {1} {2}", format = Message.Format.MESSAGE_FORMAT) + void addConnector(String user, Object source, Object... args); + + static void removeConnector(Object source, Object... args) { + BASE_LOGGER.addConnector(getCaller(), source, arrayToString(args)); + } + + @LogMessage(level = Logger.Level.INFO) + @Message(id = 601763, value = "User {0} is remove a connector on target resource: {1} {2}", format = Message.Format.MESSAGE_FORMAT) + void removeConnector(String user, Object source, Object... args); } diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java index c7c335f892..ad88409819 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java @@ -1823,6 +1823,13 @@ public interface ActiveMQServerControl { @Operation(desc = "Destroy a bridge", impact = MBeanOperationInfo.ACTION) void destroyBridge(@Parameter(name = "name", desc = "Name of the bridge") String name) throws Exception; + @Operation(desc = "Add a connector", impact = MBeanOperationInfo.ACTION) + void addConnector(@Parameter(name = "name", desc = "the unique name of the connector to add; may be referenced from other components (e.g. bridges)") String name, + @Parameter(name = "url", desc = "the URL of the connector") String url) throws Exception; + + @Operation(desc = "Remove a connector", impact = MBeanOperationInfo.ACTION) + void removeConnector(@Parameter(name = "name", desc = "the name of the connector to remove") String name) throws Exception; + @Operation(desc = "List the existing broker connections", impact = MBeanOperationInfo.INFO) String listBrokerConnections(); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java index 5695cb1f65..658df90f2a 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java @@ -3911,6 +3911,38 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active } } + @Override + public void addConnector(String name, String url) throws Exception { + if (AuditLogger.isBaseLoggingEnabled()) { + AuditLogger.addConnector(this.server, name, url); + } + checkStarted(); + + clearIO(); + + try { + server.getConfiguration().addConnectorConfiguration(name, url); + } finally { + blockOnIO(); + } + } + + @Override + public void removeConnector(String name) throws Exception { + if (AuditLogger.isBaseLoggingEnabled()) { + AuditLogger.removeConnector(this.server, name); + } + checkStarted(); + + clearIO(); + + try { + server.getConfiguration().getConnectorConfigurations().remove(name); + } finally { + blockOnIO(); + } + } + @Override public String listBrokerConnections() { if (AuditLogger.isBaseLoggingEnabled()) { diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java index 30f76a3186..210c8b5a42 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java @@ -1984,6 +1984,15 @@ public class ActiveMQServerControlTest extends ManagementTestBase { @Test public void testCreateAndDestroyBridgeFromJson() throws Exception { + internalTestCreateAndDestroyBridgeFromJson(false); + } + + @Test + public void testCreateAndDestroyBridgeFromJsonDynamicConnector() throws Exception { + internalTestCreateAndDestroyBridgeFromJson(true); + } + + private void internalTestCreateAndDestroyBridgeFromJson(boolean dynamicConnector) throws Exception { String name = RandomUtil.randomString(); String sourceAddress = RandomUtil.randomString(); String sourceQueue = RandomUtil.randomString(); @@ -2007,13 +2016,19 @@ public class ActiveMQServerControlTest extends ManagementTestBase { session.createQueue(new QueueConfiguration(targetQueue).setAddress(targetAddress).setRoutingType(RoutingType.ANYCAST).setDurable(false)); } + String connectorName = connectorConfig.getName(); + if (dynamicConnector) { + connectorName = RandomUtil.randomString(); + serverControl.addConnector(connectorName, "vm://0"); + } + BridgeConfiguration bridgeConfiguration = new BridgeConfiguration(name) .setQueueName(sourceQueue) .setForwardingAddress(targetAddress) .setUseDuplicateDetection(false) .setConfirmationWindowSize(1) .setProducerWindowSize(-1) - .setStaticConnectors(Collections.singletonList(connectorConfig.getName())) + .setStaticConnectors(Collections.singletonList(connectorName)) .setHA(false) .setUser(null) .setPassword(null); @@ -2072,6 +2087,16 @@ public class ActiveMQServerControlTest extends ManagementTestBase { locator.close(); } + @Test + public void testAddAndRemoveConnector() throws Exception { + ActiveMQServerControl serverControl = createManagementControl(); + String connectorName = RandomUtil.randomString(); + serverControl.addConnector(connectorName, "vm://0"); + assertEquals(connectorName, server.getConfiguration().getConnectorConfigurations().get(connectorName).getName()); + serverControl.removeConnector(connectorName); + assertNull(server.getConfiguration().getConnectorConfigurations().get(connectorName)); + } + @Test public void testListPreparedTransactionDetails() throws Exception { SimpleString atestq = new SimpleString("BasicXaTestq"); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java index b7c412874f..a28ee4e633 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java @@ -1587,6 +1587,16 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes proxy.invokeOperation("createBridge", bridgeConfiguration); } + @Override + public void addConnector(String name, String url) throws Exception { + proxy.invokeOperation("addConnector", name, url); + } + + @Override + public void removeConnector(String name) throws Exception { + proxy.invokeOperation("removeConnector", name); + } + @Override public String listProducersInfoAsJSON() throws Exception { return (String) proxy.invokeOperation("listProducersInfoAsJSON");