Skip to content

Commit

Permalink
ARTEMIS-2130 - This is to allow views to have the client id when set …
Browse files Browse the repository at this point in the history
…on core protocol

https://issues.apache.org/jira/browse/ARTEMIS-2130
(cherry picked from commit 8005867)
  • Loading branch information
andytaylor authored and franz1981 committed Dec 14, 2018
1 parent 496e348 commit 31bcfbb
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
Expand Up @@ -22,6 +22,7 @@
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;
Expand Down Expand Up @@ -51,10 +52,14 @@ public JsonObjectBuilder toJson(RemotingConnection connection) {

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()))
Expand All @@ -63,7 +68,7 @@ public JsonObjectBuilder toJson(RemotingConnection connection) {
.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());
}
Expand Down
Expand Up @@ -19,6 +19,7 @@
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;
Expand Down Expand Up @@ -51,9 +52,15 @@ public JsonObjectBuilder toJson(ServerConsumer consumer) {
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()))
Expand Down
Expand Up @@ -18,6 +18,7 @@

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;
Expand Down Expand Up @@ -50,9 +51,15 @@ public JsonObjectBuilder toJson(ServerProducer producer) {
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()))
Expand Down
Expand Up @@ -85,6 +85,8 @@
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 -----------------------------------------------------
Expand Down Expand Up @@ -2448,6 +2450,44 @@ public void testListConnections() throws Exception {
}
}

@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");
Expand Down

0 comments on commit 31bcfbb

Please sign in to comment.