This closes #1146
This commit is contained in:
commit
facc9dbc94
|
@ -28,6 +28,7 @@ import javax.management.openmbean.CompositeData;
|
|||
import javax.management.openmbean.CompositeDataSupport;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -303,10 +304,16 @@ public final class JsonUtil {
|
|||
}
|
||||
} else if (jsonValue instanceof Object[]) {
|
||||
Object[] array = (Object[]) jsonValue;
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = convertJsonValue(array[i], desiredType);
|
||||
Object[] result;
|
||||
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 {
|
||||
return jsonValue;
|
||||
}
|
||||
|
|
|
@ -18,9 +18,6 @@ package org.apache.activemq.artemis.api.core.management;
|
|||
|
||||
import javax.management.MBeanOperationInfo;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.RoutingType;
|
||||
|
||||
/**
|
||||
* An AddressControl is used to manage an address.
|
||||
|
@ -36,14 +33,14 @@ public interface AddressControl {
|
|||
/*
|
||||
* Whether multicast routing is enabled for this address
|
||||
* */
|
||||
@Attribute(desc = "Get the delivery modes enabled on this address")
|
||||
Set<RoutingType> getDeliveryModes();
|
||||
@Attribute(desc = "Get the routing types enabled on this address")
|
||||
String[] getRoutingTypes();
|
||||
|
||||
/*
|
||||
* Whether multicast routing is enabled for this address
|
||||
* */
|
||||
@Attribute(desc = "Get the delivery modes enabled on this address as JSON")
|
||||
String getDeliveryModesAsJSON() throws Exception;
|
||||
@Attribute(desc = "Get the routing types enabled on this address as JSON")
|
||||
String getRoutingTypesAsJSON() throws Exception;
|
||||
|
||||
/**
|
||||
* Returns the roles (name and permissions) associated with this address.
|
||||
|
|
|
@ -98,19 +98,25 @@ public class AddressControlImpl extends AbstractControl implements AddressContro
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<RoutingType> getDeliveryModes() {
|
||||
return addressInfo.getRoutingTypes();
|
||||
public String[] 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
|
||||
public String getDeliveryModesAsJSON() throws Exception {
|
||||
public String getRoutingTypesAsJSON() throws Exception {
|
||||
clearIO();
|
||||
try {
|
||||
JsonArrayBuilder json = JsonLoader.createArrayBuilder();
|
||||
Set<RoutingType> routingTypes = getDeliveryModes();
|
||||
String[] routingTypes = getRoutingTypes();
|
||||
|
||||
for (RoutingType routingType : routingTypes) {
|
||||
json.add(routingType.toString());
|
||||
for (String routingType : routingTypes) {
|
||||
json.add(routingType);
|
||||
}
|
||||
return json.build().toString();
|
||||
} finally {
|
||||
|
|
|
@ -16,10 +16,15 @@
|
|||
*/
|
||||
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.Set;
|
||||
|
||||
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.client.ClientMessage;
|
||||
import org.apache.activemq.artemis.api.core.client.ClientProducer;
|
||||
|
@ -48,6 +53,10 @@ public class AddressControlTest extends ManagementTestBase {
|
|||
private ServerLocator locator;
|
||||
private ClientSessionFactory sf;
|
||||
|
||||
public boolean usingCore() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAddress() throws Exception {
|
||||
SimpleString address = RandomUtil.randomSimpleString();
|
||||
|
@ -265,6 +274,42 @@ public class AddressControlTest extends ManagementTestBase {
|
|||
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 ---------------------------------------------
|
||||
|
||||
// Protected -----------------------------------------------------
|
||||
|
|
|
@ -16,173 +16,110 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.tests.integration.management;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.Map;
|
||||
|
||||
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.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 ManagementTestBase {
|
||||
public class AddressControlUsingCoreTest extends AddressControlTest {
|
||||
|
||||
// Constants -----------------------------------------------------
|
||||
|
||||
// Attributes ----------------------------------------------------
|
||||
|
||||
private ActiveMQServer server;
|
||||
|
||||
private ServerLocator locator;
|
||||
|
||||
private ClientSessionFactory sf;
|
||||
|
||||
protected ClientSession session;
|
||||
|
||||
// Static --------------------------------------------------------
|
||||
|
||||
// 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
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
protected AddressControl createManagementControl(final SimpleString name) throws Exception {
|
||||
return new AddressControl() {
|
||||
private final CoreMessagingProxy proxy = new CoreMessagingProxy(addServerLocator(createInVMNonHALocator()), ResourceNames.ADDRESS + name);
|
||||
|
||||
Configuration config = createDefaultInVMConfig().setJMXManagementEnabled(true);
|
||||
server = createServer(false, config);
|
||||
server.setMBeanServer(mbeanServer);
|
||||
server.start();
|
||||
@Override
|
||||
public String getAddress() {
|
||||
return (String) proxy.retrieveAttributeValue("address");
|
||||
}
|
||||
|
||||
locator = createInVMNonHALocator().setBlockOnNonDurableSend(true);
|
||||
sf = createSessionFactory(locator);
|
||||
session = sf.createSession(false, true, false);
|
||||
session.start();
|
||||
@Override
|
||||
public String[] getRoutingTypes() {
|
||||
return (String[]) proxy.retrieveAttributeValue("routingTypes", String.class);
|
||||
}
|
||||
|
||||
@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 {
|
||||
CoreMessagingProxy proxy = new CoreMessagingProxy(addServerLocator(createInVMNonHALocator()), ResourceNames.ADDRESS + address);
|
||||
// Public --------------------------------------------------------
|
||||
|
||||
return proxy;
|
||||
}
|
||||
|
||||
protected AddressControl createManagementControl(final SimpleString address) throws Exception {
|
||||
return ManagementControlHelper.createAddressControl(address, mbeanServer);
|
||||
@Override
|
||||
public boolean usingCore() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Private -------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue