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
This commit is contained in:
andytaylor 2018-12-14 11:54:10 +00:00 committed by Clebert Suconic
parent 986051a05d
commit 80058677d9
4 changed files with 63 additions and 4 deletions

View File

@ -22,6 +22,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; 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.management.impl.view.predicate.ConnectionFilterPredicate;
import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.ServerSession; 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()); List<ServerSession> sessions = server.getSessions(connection.getID().toString());
Set<String> users = new HashSet<>(); Set<String> users = new HashSet<>();
String jmsSessionClientID = null;
for (ServerSession session : sessions) { for (ServerSession session : sessions) {
String username = session.getUsername() == null ? "" : session.getUsername(); String username = session.getUsername() == null ? "" : session.getUsername();
users.add(username); 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())) 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("creationTime", new Date(connection.getCreationTime()).toString())
.add("implementation", toString(connection.getClass().getSimpleName())) .add("implementation", toString(connection.getClass().getSimpleName()))
.add("protocol", toString(connection.getProtocolName())) .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("localAddress", toString(connection.getTransportLocalAddress()))
.add("sessionCount", server.getSessions(connection.getID().toString()).size()); .add("sessionCount", server.getSessions(connection.getID().toString()).size());
} }

View File

@ -19,6 +19,7 @@ package org.apache.activemq.artemis.core.management.impl.view;
import javax.json.JsonObjectBuilder; import javax.json.JsonObjectBuilder;
import java.util.Date; 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.management.impl.view.predicate.ConsumerFilterPredicate;
import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.ServerConsumer; import org.apache.activemq.artemis.core.server.ServerConsumer;
@ -51,9 +52,15 @@ public class ConsumerView extends ActiveMQAbstractView<ServerConsumer> {
return null; 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())) JsonObjectBuilder obj = JsonLoader.createObjectBuilder().add("id", toString(consumer.getSequentialID()))
.add("session", toString(consumer.getSessionName())) .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("user", toString(session.getUsername()))
.add("protocol", toString(consumer.getConnectionProtocolName())) .add("protocol", toString(consumer.getConnectionProtocolName()))
.add("queue", toString(consumer.getQueueName())) .add("queue", toString(consumer.getQueueName()))

View File

@ -18,6 +18,7 @@ package org.apache.activemq.artemis.core.management.impl.view;
import javax.json.JsonObjectBuilder; 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.management.impl.view.predicate.ProducerFilterPredicate;
import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.ServerProducer; import org.apache.activemq.artemis.core.server.ServerProducer;
@ -50,9 +51,15 @@ public class ProducerView extends ActiveMQAbstractView<ServerProducer> {
return null; 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())) JsonObjectBuilder obj = JsonLoader.createObjectBuilder().add("id", toString(producer.getID()))
.add("session", toString(session.getName())) .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("user", toString(session.getUsername()))
.add("protocol", toString(session.getRemotingConnection().getProtocolName())) .add("protocol", toString(session.getRemotingConnection().getProtocolName()))
.add("address", toString(producer.getAddress() != null ? producer.getAddress() : session.getDefaultAddress())) .add("address", toString(producer.getAddress() != null ? producer.getAddress() : session.getDefaultAddress()))

View File

@ -86,6 +86,8 @@ import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.apache.activemq.artemis.jms.client.ActiveMQConnection.JMS_SESSION_CLIENT_ID_PROPERTY;
public class ActiveMQServerControlTest extends ManagementTestBase { public class ActiveMQServerControlTest extends ManagementTestBase {
// Constants ----------------------------------------------------- // Constants -----------------------------------------------------
@ -2470,6 +2472,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 @Test
public void testListProducers() throws Exception { public void testListProducers() throws Exception {
SimpleString queueName1 = new SimpleString("my_queue_one"); SimpleString queueName1 = new SimpleString("my_queue_one");