ARTEMIS-1064 AddressControl routingType fix
This commit is contained in:
parent
e3a23cda73
commit
b7e11f92b6
|
@ -28,6 +28,7 @@ import javax.management.openmbean.CompositeData;
|
||||||
import javax.management.openmbean.CompositeDataSupport;
|
import javax.management.openmbean.CompositeDataSupport;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
import java.lang.reflect.Array;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -303,10 +304,16 @@ public final class JsonUtil {
|
||||||
}
|
}
|
||||||
} else if (jsonValue instanceof Object[]) {
|
} else if (jsonValue instanceof Object[]) {
|
||||||
Object[] array = (Object[]) jsonValue;
|
Object[] array = (Object[]) jsonValue;
|
||||||
for (int i = 0; i < array.length; i++) {
|
Object[] result;
|
||||||
array[i] = convertJsonValue(array[i], desiredType);
|
if (desiredType != null) {
|
||||||
|
result = (Object[]) Array.newInstance(desiredType, array.length);
|
||||||
|
} else {
|
||||||
|
result = array;
|
||||||
}
|
}
|
||||||
return array;
|
for (int i = 0; i < array.length; i++) {
|
||||||
|
result[i] = convertJsonValue(array[i], desiredType);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
} else {
|
} else {
|
||||||
return jsonValue;
|
return jsonValue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,6 @@ package org.apache.activemq.artemis.api.core.management;
|
||||||
|
|
||||||
import javax.management.MBeanOperationInfo;
|
import javax.management.MBeanOperationInfo;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.apache.activemq.artemis.api.core.RoutingType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An AddressControl is used to manage an address.
|
* An AddressControl is used to manage an address.
|
||||||
|
@ -36,14 +33,14 @@ public interface AddressControl {
|
||||||
/*
|
/*
|
||||||
* Whether multicast routing is enabled for this address
|
* Whether multicast routing is enabled for this address
|
||||||
* */
|
* */
|
||||||
@Attribute(desc = "Get the delivery modes enabled on this address")
|
@Attribute(desc = "Get the routing types enabled on this address")
|
||||||
Set<RoutingType> getDeliveryModes();
|
String[] getRoutingTypes();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Whether multicast routing is enabled for this address
|
* Whether multicast routing is enabled for this address
|
||||||
* */
|
* */
|
||||||
@Attribute(desc = "Get the delivery modes enabled on this address as JSON")
|
@Attribute(desc = "Get the routing types enabled on this address as JSON")
|
||||||
String getDeliveryModesAsJSON() throws Exception;
|
String getRoutingTypesAsJSON() throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the roles (name and permissions) associated with this address.
|
* Returns the roles (name and permissions) associated with this address.
|
||||||
|
|
|
@ -98,19 +98,25 @@ public class AddressControlImpl extends AbstractControl implements AddressContro
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<RoutingType> getDeliveryModes() {
|
public String[] getRoutingTypes() {
|
||||||
return addressInfo.getRoutingTypes();
|
Set<RoutingType> routingTypes = addressInfo.getRoutingTypes();
|
||||||
|
String[] result = new String[routingTypes.size()];
|
||||||
|
int i = 0;
|
||||||
|
for (RoutingType routingType : routingTypes) {
|
||||||
|
result[i++] = routingType.toString();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDeliveryModesAsJSON() throws Exception {
|
public String getRoutingTypesAsJSON() throws Exception {
|
||||||
clearIO();
|
clearIO();
|
||||||
try {
|
try {
|
||||||
JsonArrayBuilder json = JsonLoader.createArrayBuilder();
|
JsonArrayBuilder json = JsonLoader.createArrayBuilder();
|
||||||
Set<RoutingType> routingTypes = getDeliveryModes();
|
String[] routingTypes = getRoutingTypes();
|
||||||
|
|
||||||
for (RoutingType routingType : routingTypes) {
|
for (String routingType : routingTypes) {
|
||||||
json.add(routingType.toString());
|
json.add(routingType);
|
||||||
}
|
}
|
||||||
return json.build().toString();
|
return json.build().toString();
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -16,10 +16,15 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.artemis.tests.integration.management;
|
package org.apache.activemq.artemis.tests.integration.management;
|
||||||
|
|
||||||
|
import javax.json.JsonArray;
|
||||||
|
import javax.json.JsonString;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
|
import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
|
||||||
|
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||||
|
import org.apache.activemq.artemis.api.core.RoutingType;
|
||||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||||
import org.apache.activemq.artemis.api.core.client.ClientMessage;
|
import org.apache.activemq.artemis.api.core.client.ClientMessage;
|
||||||
import org.apache.activemq.artemis.api.core.client.ClientProducer;
|
import org.apache.activemq.artemis.api.core.client.ClientProducer;
|
||||||
|
@ -48,6 +53,10 @@ public class AddressControlTest extends ManagementTestBase {
|
||||||
private ServerLocator locator;
|
private ServerLocator locator;
|
||||||
private ClientSessionFactory sf;
|
private ClientSessionFactory sf;
|
||||||
|
|
||||||
|
public boolean usingCore() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAddress() throws Exception {
|
public void testGetAddress() throws Exception {
|
||||||
SimpleString address = RandomUtil.randomSimpleString();
|
SimpleString address = RandomUtil.randomSimpleString();
|
||||||
|
@ -265,6 +274,42 @@ public class AddressControlTest extends ManagementTestBase {
|
||||||
Assert.assertEquals(1024, addressControl.getNumberOfBytesPerPage());
|
Assert.assertEquals(1024, addressControl.getNumberOfBytesPerPage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetRoutingTypes() throws Exception {
|
||||||
|
SimpleString address = RandomUtil.randomSimpleString();
|
||||||
|
session.createAddress(address, RoutingType.ANYCAST, false);
|
||||||
|
|
||||||
|
AddressControl addressControl = createManagementControl(address);
|
||||||
|
String[] routingTypes = addressControl.getRoutingTypes();
|
||||||
|
Assert.assertEquals(1, routingTypes.length);
|
||||||
|
Assert.assertEquals(RoutingType.ANYCAST.toString(), routingTypes[0]);
|
||||||
|
|
||||||
|
address = RandomUtil.randomSimpleString();
|
||||||
|
Set<RoutingType> types = new HashSet<>();
|
||||||
|
types.add(RoutingType.ANYCAST);
|
||||||
|
types.add(RoutingType.MULTICAST);
|
||||||
|
session.createAddress(address, types, false);
|
||||||
|
|
||||||
|
addressControl = createManagementControl(address);
|
||||||
|
routingTypes = addressControl.getRoutingTypes();
|
||||||
|
Set<String> strings = new HashSet<>(Arrays.asList(routingTypes));
|
||||||
|
Assert.assertEquals(2, strings.size());
|
||||||
|
Assert.assertTrue(strings.contains(RoutingType.ANYCAST.toString()));
|
||||||
|
Assert.assertTrue(strings.contains(RoutingType.MULTICAST.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetRoutingTypesAsJSON() throws Exception {
|
||||||
|
SimpleString address = RandomUtil.randomSimpleString();
|
||||||
|
session.createAddress(address, RoutingType.ANYCAST, false);
|
||||||
|
|
||||||
|
AddressControl addressControl = createManagementControl(address);
|
||||||
|
JsonArray jsonArray = JsonUtil.readJsonArray(addressControl.getRoutingTypesAsJSON());
|
||||||
|
|
||||||
|
assertEquals(1, jsonArray.size());
|
||||||
|
assertEquals(RoutingType.ANYCAST.toString(), ((JsonString) jsonArray.get(0)).getString());
|
||||||
|
}
|
||||||
|
|
||||||
// Package protected ---------------------------------------------
|
// Package protected ---------------------------------------------
|
||||||
|
|
||||||
// Protected -----------------------------------------------------
|
// Protected -----------------------------------------------------
|
||||||
|
|
|
@ -16,173 +16,110 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.artemis.tests.integration.management;
|
package org.apache.activemq.artemis.tests.integration.management;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||||
import org.apache.activemq.artemis.api.core.client.ClientSession;
|
|
||||||
import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
|
|
||||||
import org.apache.activemq.artemis.api.core.client.ServerLocator;
|
|
||||||
import org.apache.activemq.artemis.api.core.management.AddressControl;
|
import org.apache.activemq.artemis.api.core.management.AddressControl;
|
||||||
import org.apache.activemq.artemis.api.core.management.ResourceNames;
|
import org.apache.activemq.artemis.api.core.management.ResourceNames;
|
||||||
import org.apache.activemq.artemis.core.config.Configuration;
|
|
||||||
import org.apache.activemq.artemis.core.security.CheckType;
|
|
||||||
import org.apache.activemq.artemis.core.security.Role;
|
|
||||||
import org.apache.activemq.artemis.core.server.ActiveMQServer;
|
|
||||||
import org.apache.activemq.artemis.utils.RandomUtil;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.apache.activemq.artemis.tests.util.RandomUtil.randomString;
|
public class AddressControlUsingCoreTest extends AddressControlTest {
|
||||||
|
|
||||||
public class AddressControlUsingCoreTest extends ManagementTestBase {
|
|
||||||
|
|
||||||
// Constants -----------------------------------------------------
|
// Constants -----------------------------------------------------
|
||||||
|
|
||||||
// Attributes ----------------------------------------------------
|
// Attributes ----------------------------------------------------
|
||||||
|
|
||||||
private ActiveMQServer server;
|
|
||||||
|
|
||||||
private ServerLocator locator;
|
|
||||||
|
|
||||||
private ClientSessionFactory sf;
|
|
||||||
|
|
||||||
protected ClientSession session;
|
|
||||||
|
|
||||||
// Static --------------------------------------------------------
|
// Static --------------------------------------------------------
|
||||||
|
|
||||||
// Constructors --------------------------------------------------
|
// Constructors --------------------------------------------------
|
||||||
|
|
||||||
// Public --------------------------------------------------------
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetAddress() throws Exception {
|
|
||||||
SimpleString address = RandomUtil.randomSimpleString();
|
|
||||||
SimpleString queue = RandomUtil.randomSimpleString();
|
|
||||||
|
|
||||||
session.createQueue(address, queue, false);
|
|
||||||
|
|
||||||
CoreMessagingProxy proxy = createProxy(address);
|
|
||||||
|
|
||||||
Assert.assertEquals(address.toString(), proxy.retrieveAttributeValue("address"));
|
|
||||||
|
|
||||||
session.deleteQueue(queue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetQueueNames() throws Exception {
|
|
||||||
SimpleString address = RandomUtil.randomSimpleString();
|
|
||||||
SimpleString queue = RandomUtil.randomSimpleString();
|
|
||||||
SimpleString anotherQueue = RandomUtil.randomSimpleString();
|
|
||||||
|
|
||||||
session.createQueue(address, queue, true);
|
|
||||||
|
|
||||||
CoreMessagingProxy proxy = createProxy(address);
|
|
||||||
Object[] queueNames = (Object[]) proxy.retrieveAttributeValue("queueNames");
|
|
||||||
Assert.assertEquals(1, queueNames.length);
|
|
||||||
Assert.assertEquals(queue.toString(), queueNames[0]);
|
|
||||||
|
|
||||||
session.createQueue(address, anotherQueue, false);
|
|
||||||
queueNames = (Object[]) proxy.retrieveAttributeValue("queueNames");
|
|
||||||
Assert.assertEquals(2, queueNames.length);
|
|
||||||
|
|
||||||
session.deleteQueue(queue);
|
|
||||||
|
|
||||||
queueNames = (Object[]) proxy.retrieveAttributeValue("queueNames");
|
|
||||||
Assert.assertEquals(1, queueNames.length);
|
|
||||||
Assert.assertEquals(anotherQueue.toString(), queueNames[0]);
|
|
||||||
|
|
||||||
session.deleteQueue(anotherQueue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetBindingNames() throws Exception {
|
|
||||||
SimpleString address = RandomUtil.randomSimpleString();
|
|
||||||
SimpleString queue = RandomUtil.randomSimpleString();
|
|
||||||
String divertName = RandomUtil.randomString();
|
|
||||||
|
|
||||||
session.createQueue(address, queue, false);
|
|
||||||
|
|
||||||
CoreMessagingProxy proxy = createProxy(address);
|
|
||||||
Object[] bindingNames = (Object[]) proxy.retrieveAttributeValue("bindingNames");
|
|
||||||
assertEquals(1, bindingNames.length);
|
|
||||||
assertEquals(queue.toString(), bindingNames[0]);
|
|
||||||
|
|
||||||
server.getActiveMQServerControl().createDivert(divertName, randomString(), address.toString(), RandomUtil.randomString(), false, null, null);
|
|
||||||
|
|
||||||
bindingNames = (Object[]) proxy.retrieveAttributeValue("bindingNames");
|
|
||||||
assertEquals(2, bindingNames.length);
|
|
||||||
|
|
||||||
session.deleteQueue(queue);
|
|
||||||
|
|
||||||
bindingNames = (Object[]) proxy.retrieveAttributeValue("bindingNames");
|
|
||||||
assertEquals(1, bindingNames.length);
|
|
||||||
assertEquals(divertName.toString(), bindingNames[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetRoles() throws Exception {
|
|
||||||
SimpleString address = RandomUtil.randomSimpleString();
|
|
||||||
SimpleString queue = RandomUtil.randomSimpleString();
|
|
||||||
Role role = new Role(RandomUtil.randomString(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean());
|
|
||||||
|
|
||||||
session.createQueue(address, queue, true);
|
|
||||||
|
|
||||||
CoreMessagingProxy proxy = createProxy(address);
|
|
||||||
Object[] roles = (Object[]) proxy.retrieveAttributeValue("roles");
|
|
||||||
for (Object role2 : roles) {
|
|
||||||
System.out.println(((Object[]) role2)[0]);
|
|
||||||
}
|
|
||||||
Assert.assertEquals(0, roles.length);
|
|
||||||
|
|
||||||
Set<Role> newRoles = new HashSet<>();
|
|
||||||
newRoles.add(role);
|
|
||||||
server.getSecurityRepository().addMatch(address.toString(), newRoles);
|
|
||||||
|
|
||||||
roles = (Object[]) proxy.retrieveAttributeValue("roles", String.class);
|
|
||||||
Assert.assertEquals(1, roles.length);
|
|
||||||
Object[] r = (Object[]) roles[0];
|
|
||||||
Assert.assertEquals(role.getName(), r[0]);
|
|
||||||
Assert.assertEquals(CheckType.SEND.hasRole(role), r[1]);
|
|
||||||
Assert.assertEquals(CheckType.CONSUME.hasRole(role), r[2]);
|
|
||||||
Assert.assertEquals(CheckType.CREATE_DURABLE_QUEUE.hasRole(role), r[3]);
|
|
||||||
Assert.assertEquals(CheckType.DELETE_DURABLE_QUEUE.hasRole(role), r[4]);
|
|
||||||
Assert.assertEquals(CheckType.CREATE_NON_DURABLE_QUEUE.hasRole(role), r[5]);
|
|
||||||
Assert.assertEquals(CheckType.DELETE_NON_DURABLE_QUEUE.hasRole(role), r[6]);
|
|
||||||
Assert.assertEquals(CheckType.MANAGE.hasRole(role), r[7]);
|
|
||||||
|
|
||||||
session.deleteQueue(queue);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Package protected ---------------------------------------------
|
|
||||||
|
|
||||||
// Protected -----------------------------------------------------
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Before
|
protected AddressControl createManagementControl(final SimpleString name) throws Exception {
|
||||||
public void setUp() throws Exception {
|
return new AddressControl() {
|
||||||
super.setUp();
|
private final CoreMessagingProxy proxy = new CoreMessagingProxy(addServerLocator(createInVMNonHALocator()), ResourceNames.ADDRESS + name);
|
||||||
|
|
||||||
Configuration config = createDefaultInVMConfig().setJMXManagementEnabled(true);
|
@Override
|
||||||
server = createServer(false, config);
|
public String getAddress() {
|
||||||
server.setMBeanServer(mbeanServer);
|
return (String) proxy.retrieveAttributeValue("address");
|
||||||
server.start();
|
}
|
||||||
|
|
||||||
locator = createInVMNonHALocator().setBlockOnNonDurableSend(true);
|
@Override
|
||||||
sf = createSessionFactory(locator);
|
public String[] getRoutingTypes() {
|
||||||
session = sf.createSession(false, true, false);
|
return (String[]) proxy.retrieveAttributeValue("routingTypes", String.class);
|
||||||
session.start();
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRoutingTypesAsJSON() throws Exception {
|
||||||
|
return (String) proxy.retrieveAttributeValue("routingTypesAsJSON");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object[] getRoles() throws Exception {
|
||||||
|
return (Object[]) proxy.retrieveAttributeValue("roles");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRolesAsJSON() throws Exception {
|
||||||
|
return (String) proxy.retrieveAttributeValue("rolesAsJSON");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getAddressSize() throws Exception {
|
||||||
|
return (long) proxy.retrieveAttributeValue("addressSize");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getNumberOfMessages() throws Exception {
|
||||||
|
return (long) proxy.retrieveAttributeValue("numberOfMessages");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getQueueNames() throws Exception {
|
||||||
|
return (String[]) proxy.retrieveAttributeValue("queueNames", String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getNumberOfPages() throws Exception {
|
||||||
|
return (int) proxy.retrieveAttributeValue("numberOfPages", Integer.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPaging() throws Exception {
|
||||||
|
return (boolean) proxy.retrieveAttributeValue("paging");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getNumberOfBytesPerPage() throws Exception {
|
||||||
|
return (long) proxy.retrieveAttributeValue("numberOfBytesPerPage");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getBindingNames() throws Exception {
|
||||||
|
return (String[]) proxy.retrieveAttributeValue("bindingNames", String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getMessageCount() {
|
||||||
|
return (long) proxy.retrieveAttributeValue("messageCount");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String sendMessage(Map<String, String> headers,
|
||||||
|
int type,
|
||||||
|
String body,
|
||||||
|
boolean durable,
|
||||||
|
String user,
|
||||||
|
String password) throws Exception {
|
||||||
|
return (String) proxy.invokeOperation("sendMessage", headers, type, body, durable, user, password);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CoreMessagingProxy createProxy(final SimpleString address) throws Exception {
|
// Public --------------------------------------------------------
|
||||||
CoreMessagingProxy proxy = new CoreMessagingProxy(addServerLocator(createInVMNonHALocator()), ResourceNames.ADDRESS + address);
|
|
||||||
|
|
||||||
return proxy;
|
@Override
|
||||||
}
|
public boolean usingCore() {
|
||||||
|
return true;
|
||||||
protected AddressControl createManagementControl(final SimpleString address) throws Exception {
|
|
||||||
return ManagementControlHelper.createAddressControl(address, mbeanServer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private -------------------------------------------------------
|
// Private -------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue