ARTEMIS-1198 add listAllSessionsAsJSON mgmnt method
This commit is contained in:
parent
58c058f60e
commit
92cb69513e
|
@ -904,6 +904,29 @@ public interface ActiveMQServerControl {
|
|||
@Operation(desc = "List the sessions for the given connectionID as a JSON string", impact = MBeanOperationInfo.INFO)
|
||||
String listSessionsAsJSON(@Parameter(desc = "a connection ID", name = "connectionID") String connectionID) throws Exception;
|
||||
|
||||
/**
|
||||
* Lists details about all sessions.
|
||||
* The returned String is a JSON string containing details about each and every session, e.g.:
|
||||
* <pre>
|
||||
* [
|
||||
* {
|
||||
* "sessionID":"e71d61d7-2176-11e8-9057-a0afbd82eaba",
|
||||
* "creationTime":1520365520212,
|
||||
* "consumerCount":1,
|
||||
* "principal":"myUser"
|
||||
* },
|
||||
* {
|
||||
* "sessionID":"e718a6e6-2176-11e8-9057-a0afbd82eaba",
|
||||
* "creationTime":1520365520191,
|
||||
* "consumerCount":0,
|
||||
* "principal":"guest"
|
||||
* }
|
||||
* ]
|
||||
* </pre>
|
||||
*/
|
||||
@Operation(desc = "List all sessions as a JSON string", impact = MBeanOperationInfo.INFO)
|
||||
String listAllSessionsAsJSON() throws Exception;
|
||||
|
||||
/**
|
||||
* Lists all the sessions IDs for the specified connection ID.
|
||||
*/
|
||||
|
|
|
@ -1863,6 +1863,30 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
|
|||
return array.build().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String listAllSessionsAsJSON() throws Exception {
|
||||
checkStarted();
|
||||
|
||||
clearIO();
|
||||
|
||||
JsonArrayBuilder array = JsonLoader.createArrayBuilder();
|
||||
try {
|
||||
Set<ServerSession> sessions = server.getSessions();
|
||||
for (ServerSession sess : sessions) {
|
||||
JsonObjectBuilder obj = JsonLoader.createObjectBuilder().add("sessionID", sess.getName()).add("creationTime", sess.getCreationTime()).add("consumerCount", sess.getServerConsumers().size());
|
||||
|
||||
if (sess.getValidatedUser() != null) {
|
||||
obj.add("principal", sess.getValidatedUser());
|
||||
}
|
||||
|
||||
array.add(obj);
|
||||
}
|
||||
} finally {
|
||||
blockOnIO();
|
||||
}
|
||||
return array.build().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String listConsumersAsJSON(String connectionID) throws Exception {
|
||||
checkStarted();
|
||||
|
|
|
@ -1472,6 +1472,52 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
|
|||
Assert.assertEquals(1, second.getJsonNumber("consumerCount").longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListAllSessionsAsJSON() throws Exception {
|
||||
SimpleString queueName = new SimpleString(UUID.randomUUID().toString());
|
||||
server.addAddressInfo(new AddressInfo(queueName, RoutingType.ANYCAST));
|
||||
server.createQueue(queueName, RoutingType.ANYCAST, queueName, null, false, false);
|
||||
ActiveMQServerControl serverControl = createManagementControl();
|
||||
|
||||
ServerLocator locator = createInVMNonHALocator();
|
||||
ClientSessionFactory factory = createSessionFactory(locator);
|
||||
ServerLocator locator2 = createInVMNonHALocator();
|
||||
ClientSessionFactory factory2 = createSessionFactory(locator2);
|
||||
ClientSession session1 = addClientSession(factory.createSession());
|
||||
Thread.sleep(5);
|
||||
ClientSession session2 = addClientSession(factory2.createSession("myUser", "myPass", false, false, false, false, 0));
|
||||
session2.createConsumer(queueName);
|
||||
|
||||
String jsonString = serverControl.listAllSessionsAsJSON();
|
||||
IntegrationTestLogger.LOGGER.info(jsonString);
|
||||
Assert.assertNotNull(jsonString);
|
||||
JsonArray array = JsonUtil.readJsonArray(jsonString);
|
||||
Assert.assertEquals(2 + (usingCore() ? 1 : 0), array.size());
|
||||
JsonObject first;
|
||||
JsonObject second;
|
||||
if (array.getJsonObject(0).getJsonNumber("creationTime").longValue() < array.getJsonObject(1).getJsonNumber("creationTime").longValue()) {
|
||||
first = array.getJsonObject(0);
|
||||
second = array.getJsonObject(1);
|
||||
} else {
|
||||
first = array.getJsonObject(1);
|
||||
second = array.getJsonObject(0);
|
||||
}
|
||||
|
||||
Assert.assertTrue(first.getString("sessionID").length() > 0);
|
||||
Assert.assertEquals(((ClientSessionImpl) session1).getName(), first.getString("sessionID"));
|
||||
Assert.assertTrue(first.getString("principal").length() > 0);
|
||||
Assert.assertEquals("guest", first.getString("principal"));
|
||||
Assert.assertTrue(first.getJsonNumber("creationTime").longValue() > 0);
|
||||
Assert.assertEquals(0, first.getJsonNumber("consumerCount").longValue());
|
||||
|
||||
Assert.assertTrue(second.getString("sessionID").length() > 0);
|
||||
Assert.assertEquals(((ClientSessionImpl) session2).getName(), second.getString("sessionID"));
|
||||
Assert.assertTrue(second.getString("principal").length() > 0);
|
||||
Assert.assertEquals("myUser", second.getString("principal"));
|
||||
Assert.assertTrue(second.getJsonNumber("creationTime").longValue() > 0);
|
||||
Assert.assertEquals(1, second.getJsonNumber("consumerCount").longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListQueues() throws Exception {
|
||||
SimpleString queueName1 = new SimpleString("my_queue_one");
|
||||
|
|
|
@ -1002,6 +1002,11 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes
|
|||
return (String) proxy.invokeOperation("listSessionsAsJSON", connectionID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String listAllSessionsAsJSON() throws Exception {
|
||||
return (String) proxy.invokeOperation("listAllSessionsAsJSON");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String listAddresses(@Parameter(name = "separator", desc = "Separator used on the string listing") String separator) throws Exception {
|
||||
return (String) proxy.invokeOperation("listAddresses", separator);
|
||||
|
|
Loading…
Reference in New Issue