activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject activemq-artemis git commit: ARTEMIS-1947 return metadata in JSON session mgmnt ops
Date Wed, 20 Jun 2018 21:18:43 GMT
Repository: activemq-artemis
Updated Branches:
  refs/heads/2.6.x 358bf7d4e -> 26b7cf45d


ARTEMIS-1947 return metadata in JSON session mgmnt ops

(cherry picked from commit 2ed8a5764b1d1c2ae8069e36ca25fb1418358d8f)


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/26b7cf45
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/26b7cf45
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/26b7cf45

Branch: refs/heads/2.6.x
Commit: 26b7cf45d2be02827568432e34e7f3045400671d
Parents: 358bf7d
Author: Justin Bertram <jbertram@apache.org>
Authored: Wed Jun 20 11:02:30 2018 -0500
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Wed Jun 20 17:18:37 2018 -0400

----------------------------------------------------------------------
 .../impl/ActiveMQServerControlImpl.java         | 32 +++++++++++---------
 .../artemis/core/server/ServerSession.java      |  2 ++
 .../core/server/impl/ServerSessionImpl.java     |  5 +++
 .../management/ActiveMQServerControlTest.java   | 28 +++++++++++++++++
 4 files changed, 53 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/26b7cf45/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java
index 58f2613..cabdc10 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java
@@ -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();

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/26b7cf45/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ServerSession.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ServerSession.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ServerSession.java
index f5cca75..8c2f748 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ServerSession.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ServerSession.java
@@ -251,6 +251,8 @@ public interface ServerSession extends SecurityAuth {
 
    String getMetaData(String key);
 
+   Map<String, String> getMetaData();
+
    String[] getTargetAddresses();
 
    /**

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/26b7cf45/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
index 3057041..bd36659 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
@@ -1545,6 +1545,11 @@ public class ServerSessionImpl implements ServerSession, FailureListener
{
    }
 
    @Override
+   public Map<String, String> getMetaData() {
+      return metaData;
+   }
+
+   @Override
    public String[] getTargetAddresses() {
       Map<SimpleString, Pair<Object, AtomicLong>> copy = cloneTargetAddresses();
       Iterator<SimpleString> iter = copy.keySet().iterator();

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/26b7cf45/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java
index b79fced..048d506 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java
@@ -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


Mime
View raw message