ARTEMIS-1947 return metadata in JSON session mgmnt ops
This commit is contained in:
parent
1e5971b70e
commit
2ed8a5764b
|
@ -1849,13 +1849,7 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
|
|||
try {
|
||||
List<ServerSession> sessions = server.getSessions(connectionID);
|
||||
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);
|
||||
buildSessionJSON(array, sess);
|
||||
}
|
||||
} finally {
|
||||
blockOnIO();
|
||||
|
@ -1873,13 +1867,7 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
|
|||
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);
|
||||
buildSessionJSON(array, sess);
|
||||
}
|
||||
} finally {
|
||||
blockOnIO();
|
||||
|
@ -1887,6 +1875,22 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
|
|||
return array.build().toString();
|
||||
}
|
||||
|
||||
public void buildSessionJSON(JsonArrayBuilder array, ServerSession sess) {
|
||||
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());
|
||||
}
|
||||
|
||||
String metadata = sess.getMetaData() == null ? null : sess.getMetaData().toString();
|
||||
if (metadata != null) {
|
||||
// remove leading and trailing curly brackets
|
||||
obj.add("metadata", metadata.substring(1, metadata.length() - 1));
|
||||
}
|
||||
|
||||
array.add(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String listConsumersAsJSON(String connectionID) throws Exception {
|
||||
checkStarted();
|
||||
|
|
|
@ -251,6 +251,8 @@ public interface ServerSession extends SecurityAuth {
|
|||
|
||||
String getMetaData(String key);
|
||||
|
||||
Map<String, String> getMetaData();
|
||||
|
||||
String[] getTargetAddresses();
|
||||
|
||||
/**
|
||||
|
|
|
@ -1547,6 +1547,11 @@ public class ServerSessionImpl implements ServerSession, FailureListener {
|
|||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getMetaData() {
|
||||
return metaData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getTargetAddresses() {
|
||||
Map<SimpleString, Pair<Object, AtomicLong>> copy = cloneTargetAddresses();
|
||||
|
|
|
@ -71,6 +71,8 @@ import org.apache.activemq.artemis.core.server.impl.AddressInfo;
|
|||
import org.apache.activemq.artemis.core.settings.impl.SlowConsumerPolicy;
|
||||
import org.apache.activemq.artemis.core.transaction.impl.XidImpl;
|
||||
import org.apache.activemq.artemis.jlibaio.LibaioContext;
|
||||
import org.apache.activemq.artemis.jms.client.ActiveMQConnection;
|
||||
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.artemis.jms.client.ActiveMQSession;
|
||||
import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager;
|
||||
import org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule;
|
||||
|
@ -1523,6 +1525,8 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
|
|||
ClientSession session1 = addClientSession(factory.createSession());
|
||||
Thread.sleep(5);
|
||||
ClientSession session2 = addClientSession(factory2.createSession("myUser", "myPass", false, false, false, false, 0));
|
||||
session2.addMetaData("foo", "bar");
|
||||
session2.addMetaData("bar", "baz");
|
||||
session2.createConsumer(queueName);
|
||||
|
||||
String jsonString = serverControl.listAllSessionsAsJSON();
|
||||
|
@ -1546,6 +1550,30 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
|
|||
Assert.assertEquals("myUser", second.getString("principal"));
|
||||
Assert.assertTrue(second.getJsonNumber("creationTime").longValue() > 0);
|
||||
Assert.assertEquals(1, second.getJsonNumber("consumerCount").longValue());
|
||||
Assert.assertTrue(second.getJsonString("metadata").getString().contains("foo=bar"));
|
||||
Assert.assertTrue(second.getJsonString("metadata").getString().contains("bar=baz"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListAllSessionsAsJSONWithJMS() 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();
|
||||
|
||||
ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactory("vm://0", "cf");
|
||||
Connection con = cf.createConnection();
|
||||
String clientID = UUID.randomUUID().toString();
|
||||
con.setClientID(clientID);
|
||||
|
||||
String jsonString = serverControl.listAllSessionsAsJSON();
|
||||
IntegrationTestLogger.LOGGER.info(jsonString);
|
||||
Assert.assertNotNull(jsonString);
|
||||
JsonArray array = JsonUtil.readJsonArray(jsonString);
|
||||
Assert.assertEquals(1 + (usingCore() ? 1 : 0), array.size());
|
||||
JsonObject obj = lookupSession(array, ((ActiveMQConnection)con).getInitialSession());
|
||||
Assert.assertTrue(obj.getString("metadata").contains(ClientSession.JMS_SESSION_CLIENT_ID_PROPERTY + "=" + clientID));
|
||||
Assert.assertTrue(obj.getString("metadata").contains(ClientSession.JMS_SESSION_IDENTIFIER_PROPERTY));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue