This commit is contained in:
Justin Bertram 2022-08-25 08:41:50 -05:00
commit 38ee7bad33
No known key found for this signature in database
GPG Key ID: F41830B875BB8633
5 changed files with 91 additions and 1 deletions

View File

@ -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);
}

View File

@ -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();

View File

@ -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()) {

View File

@ -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");

View File

@ -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");