activemq-artemis git commit: ARTEMIS-2130 - This is to allow views to have the client id when set on core protocol

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

activemq-artemis git commit: ARTEMIS-2130 - This is to allow views to have the client id when set on core protocol

nigrofranz
Repository: activemq-artemis
Updated Branches:
  refs/heads/2.6.x 496e34859 -> 31bcfbbea


ARTEMIS-2130 - This is to allow views to have the client id when set on core protocol

https://issues.apache.org/jira/browse/ARTEMIS-2130
(cherry picked from commit 80058677d920fbddd057968a6a944ac95b2646fc)


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

Branch: refs/heads/2.6.x
Commit: 31bcfbbea122b781f16fe59bfec5fda56c609baf
Parents: 496e348
Author: andytaylor <[hidden email]>
Authored: Fri Dec 14 11:54:10 2018 +0000
Committer: Francesco Nigro <[hidden email]>
Committed: Fri Dec 14 16:51:58 2018 +0100

----------------------------------------------------------------------
 .../management/impl/view/ConnectionView.java    |  9 ++++-
 .../core/management/impl/view/ConsumerView.java |  9 ++++-
 .../core/management/impl/view/ProducerView.java |  9 ++++-
 .../management/ActiveMQServerControlTest.java   | 40 ++++++++++++++++++++
 4 files changed, 63 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/31bcfbbe/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConnectionView.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConnectionView.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConnectionView.java
index b8ed6e3..9f2d0bf 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConnectionView.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConnectionView.java
@@ -22,6 +22,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.activemq.artemis.api.core.client.ClientSession;
 import org.apache.activemq.artemis.core.management.impl.view.predicate.ConnectionFilterPredicate;
 import org.apache.activemq.artemis.core.server.ActiveMQServer;
 import org.apache.activemq.artemis.core.server.ServerSession;
@@ -51,10 +52,14 @@ public class ConnectionView extends ActiveMQAbstractView<RemotingConnection> {
 
       List<ServerSession> sessions = server.getSessions(connection.getID().toString());
       Set<String> users = new HashSet<>();
-
+      String jmsSessionClientID = null;
       for (ServerSession session : sessions) {
          String username = session.getUsername() == null ? "" : session.getUsername();
          users.add(username);
+         //for the special case for JMS
+         if (session.getMetaData(ClientSession.JMS_SESSION_IDENTIFIER_PROPERTY) != null) {
+            jmsSessionClientID = session.getMetaData("jms-client-id");
+         }
       }
 
       return JsonLoader.createObjectBuilder().add("connectionID", toString(connection.getID()))
@@ -63,7 +68,7 @@ public class ConnectionView extends ActiveMQAbstractView<RemotingConnection> {
          .add("creationTime", new Date(connection.getCreationTime()).toString())
          .add("implementation", toString(connection.getClass().getSimpleName()))
          .add("protocol", toString(connection.getProtocolName()))
-         .add("clientID", toString(connection.getClientID()))
+         .add("clientID", toString(connection.getClientID() != null ? connection.getClientID() : jmsSessionClientID))
          .add("localAddress", toString(connection.getTransportLocalAddress()))
          .add("sessionCount", server.getSessions(connection.getID().toString()).size());
    }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/31bcfbbe/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConsumerView.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConsumerView.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConsumerView.java
index 52604a8..4bdd9c6 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConsumerView.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConsumerView.java
@@ -19,6 +19,7 @@ package org.apache.activemq.artemis.core.management.impl.view;
 import javax.json.JsonObjectBuilder;
 import java.util.Date;
 
+import org.apache.activemq.artemis.api.core.client.ClientSession;
 import org.apache.activemq.artemis.core.management.impl.view.predicate.ConsumerFilterPredicate;
 import org.apache.activemq.artemis.core.server.ActiveMQServer;
 import org.apache.activemq.artemis.core.server.ServerConsumer;
@@ -51,9 +52,15 @@ public class ConsumerView extends ActiveMQAbstractView<ServerConsumer> {
          return null;
       }
 
+      String jmsSessionClientID = null;
+      //for the special case for JMS
+      if (session.getMetaData(ClientSession.JMS_SESSION_IDENTIFIER_PROPERTY) != null) {
+         jmsSessionClientID = session.getMetaData("jms-client-id");
+      }
+
       JsonObjectBuilder obj = JsonLoader.createObjectBuilder().add("id", toString(consumer.getSequentialID()))
          .add("session", toString(consumer.getSessionName()))
-         .add("clientID", toString(consumer.getConnectionClientID()))
+         .add("clientID", toString(consumer.getConnectionClientID() != null ? consumer.getConnectionClientID() : jmsSessionClientID))
          .add("user", toString(session.getUsername()))
          .add("protocol", toString(consumer.getConnectionProtocolName()))
          .add("queue", toString(consumer.getQueueName()))

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/31bcfbbe/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ProducerView.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ProducerView.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ProducerView.java
index 977aec8..27aed84 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ProducerView.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ProducerView.java
@@ -18,6 +18,7 @@ package org.apache.activemq.artemis.core.management.impl.view;
 
 import javax.json.JsonObjectBuilder;
 
+import org.apache.activemq.artemis.api.core.client.ClientSession;
 import org.apache.activemq.artemis.core.management.impl.view.predicate.ProducerFilterPredicate;
 import org.apache.activemq.artemis.core.server.ActiveMQServer;
 import org.apache.activemq.artemis.core.server.ServerProducer;
@@ -50,9 +51,15 @@ public class ProducerView extends ActiveMQAbstractView<ServerProducer> {
          return null;
       }
 
+      String jmsSessionClientID = null;
+      //for the special case for JMS
+      if (session.getMetaData(ClientSession.JMS_SESSION_IDENTIFIER_PROPERTY) != null) {
+         jmsSessionClientID = session.getMetaData("jms-client-id");
+      }
+
       JsonObjectBuilder obj = JsonLoader.createObjectBuilder().add("id", toString(producer.getID()))
          .add("session", toString(session.getName()))
-         .add("clientID", toString(session.getRemotingConnection().getClientID()))
+         .add("clientID", toString(session.getRemotingConnection().getClientID() != null ? session.getRemotingConnection().getClientID() : jmsSessionClientID))
          .add("user", toString(session.getUsername()))
          .add("protocol", toString(session.getRemotingConnection().getProtocolName()))
          .add("address", toString(producer.getAddress() != null ? producer.getAddress() : session.getDefaultAddress()))

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/31bcfbbe/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 2b76de6..3a70992 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
@@ -85,6 +85,8 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
+import static org.apache.activemq.artemis.jms.client.ActiveMQConnection.JMS_SESSION_CLIENT_ID_PROPERTY;
+
 public class ActiveMQServerControlTest extends ManagementTestBase {
 
    // Constants -----------------------------------------------------
@@ -2449,6 +2451,44 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
    }
 
    @Test
+   public void testListConnectionsClientID() throws Exception {
+      SimpleString queueName1 = new SimpleString("my_queue_one");
+      SimpleString addressName1 = new SimpleString("my_address_one");
+
+      ActiveMQServerControl serverControl = createManagementControl();
+
+      server.addAddressInfo(new AddressInfo(addressName1, RoutingType.ANYCAST));
+      server.createQueue(addressName1, RoutingType.ANYCAST, queueName1, null, false, false);
+
+      ClientSessionFactoryImpl csf = null;
+
+      // create some consumers
+      try (ServerLocator locator = createInVMNonHALocator()) {
+         //sleep as test compares creationTime
+         csf = (ClientSessionFactoryImpl) createSessionFactory(locator);
+         ClientSession session1_c1 = csf.createSession();
+         ClientSession session2_c1 = csf.createSession();
+         session1_c1.addMetaData(ClientSession.JMS_SESSION_IDENTIFIER_PROPERTY, "");
+         session1_c1.addMetaData(JMS_SESSION_CLIENT_ID_PROPERTY, "MYClientID");
+
+         String filterString = createJsonFilter("SESSION_COUNT", "GREATER_THAN", "1");
+         String connectionsAsJsonString = serverControl.listConnections(filterString, 1, 50);
+         JsonObject connectionsAsJsonObject = JsonUtil.readJsonObject(connectionsAsJsonString);
+         JsonArray array = (JsonArray) connectionsAsJsonObject.get("data");
+
+         Assert.assertEquals("number of connections returned from query", 1, array.size());
+         JsonObject jsonConnection = array.getJsonObject(0);
+
+         //check all fields
+         Assert.assertEquals("clientID", "MYClientID", jsonConnection.getString("clientID"));
+      } finally {
+         if (csf != null) {
+            csf.close();
+         }
+      }
+   }
+
+   @Test
    public void testListProducers() throws Exception {
       SimpleString queueName1 = new SimpleString("my_queue_one");
       SimpleString addressName1 = new SimpleString("my_address_one");