You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jb...@apache.org on 2017/10/16 21:52:13 UTC

[2/2] activemq-artemis git commit: ARTEMIS-1366 Hide Advisory Address from Management Console

ARTEMIS-1366 Hide Advisory Address from Management Console

Openwire consumer is listed twice below "consumers" tab.
First it shows correctly the requested queue consume.
Second it shows consumer from multicast queue ActiveMQ.Advisory.
The second one is internal and should be hidden.


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

Branch: refs/heads/master
Commit: 105d8c33889b4dd7d123de36cc63e5ec9b6e0177
Parents: 090ac5b
Author: Howard Gao <ho...@gmail.com>
Authored: Mon Oct 16 17:26:51 2017 +0800
Committer: Justin Bertram <jb...@apache.org>
Committed: Mon Oct 16 16:51:54 2017 -0500

----------------------------------------------------------------------
 .../core/postoffice/impl/PostOfficeImpl.java    |  4 +-
 .../artemis/core/server/impl/AddressInfo.java   |  9 +-
 .../management/ManagementControlHelper.java     |  2 +-
 .../integration/openwire/OpenWireTestBase.java  |  5 +-
 .../management/OpenWireManagementTest.java      | 98 ++++++++++++++++++++
 5 files changed, 112 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/105d8c33/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java
index f25426c..e2153e1 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java
@@ -442,7 +442,9 @@ public class PostOfficeImpl implements PostOffice, NotificationListener, Binding
          // only register address if it is new
          if (result) {
             try {
-               managementService.registerAddress(addressInfo);
+               if (!addressInfo.isInternal()) {
+                  managementService.registerAddress(addressInfo);
+               }
             } catch (Exception e) {
                e.printStackTrace();
             }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/105d8c33/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java
index bd92bf2..3fb808f 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java
@@ -24,6 +24,9 @@ import org.apache.activemq.artemis.api.core.RoutingType;
 
 public class AddressInfo {
 
+   //from openwire
+   public static final SimpleString ADVISORY_TOPIC = new SimpleString("ActiveMQ.Advisory.");
+
    private long id;
 
    private final SimpleString name;
@@ -33,8 +36,7 @@ public class AddressInfo {
    private Set<RoutingType> routingTypes;
 
    public AddressInfo(SimpleString name) {
-      this.name = name;
-      routingTypes = new HashSet<>();
+      this(name, new HashSet<>());
    }
 
    /**
@@ -127,4 +129,7 @@ public class AddressInfo {
       return buff.toString();
    }
 
+   public boolean isInternal() {
+      return this.name.startsWith(ADVISORY_TOPIC);
+   }
 }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/105d8c33/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ManagementControlHelper.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ManagementControlHelper.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ManagementControlHelper.java
index f6021d6..7211261 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ManagementControlHelper.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ManagementControlHelper.java
@@ -96,7 +96,7 @@ public class ManagementControlHelper {
 
    // Private -------------------------------------------------------
 
-   private static Object createProxy(final ObjectName objectName,
+   public static Object createProxy(final ObjectName objectName,
                                      final Class mbeanInterface,
                                      final MBeanServer mbeanServer) {
       return MBeanServerInvocationHandler.newProxyInstance(mbeanServer, objectName, mbeanInterface, false);

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/105d8c33/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/OpenWireTestBase.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/OpenWireTestBase.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/OpenWireTestBase.java
index e61a0f4..2a07aa9 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/OpenWireTestBase.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/OpenWireTestBase.java
@@ -104,6 +104,9 @@ public class OpenWireTestBase extends ActiveMQTestBase {
 
          server.getConfiguration().putSecurityRoles("#", roles);
       }
+
+      mbeanServer = MBeanServerFactory.createMBeanServer();
+      server.setMBeanServer(mbeanServer);
       addServer(server);
       jmsServer = new JMSServerManagerImpl(server);
       namingContext = new InVMNamingContext();
@@ -111,8 +114,6 @@ public class OpenWireTestBase extends ActiveMQTestBase {
       jmsServer.start();
 
       registerConnectionFactory();
-
-      mbeanServer = MBeanServerFactory.createMBeanServer();
       System.out.println("debug: server started");
    }
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/105d8c33/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/management/OpenWireManagementTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/management/OpenWireManagementTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/management/OpenWireManagementTest.java
new file mode 100644
index 0000000..3ff3b6b
--- /dev/null
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/management/OpenWireManagementTest.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.tests.integration.openwire.management;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.advisory.ConsumerEventSource;
+import org.apache.activemq.advisory.ProducerEventSource;
+import org.apache.activemq.artemis.api.core.RoutingType;
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.api.core.management.ActiveMQServerControl;
+import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder;
+import org.apache.activemq.artemis.core.config.Configuration;
+import org.apache.activemq.artemis.core.server.impl.AddressInfo;
+import org.apache.activemq.artemis.tests.integration.management.ManagementControlHelper;
+import org.apache.activemq.artemis.tests.integration.openwire.OpenWireTestBase;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.Session;
+
+public class OpenWireManagementTest extends OpenWireTestBase {
+
+   private ActiveMQServerControl serverControl;
+   private SimpleString queueName1 = new SimpleString("queue1");
+   private SimpleString queueName2 = new SimpleString("queue2");;
+   private SimpleString queueName3 = new SimpleString("queue3");;
+
+   private ConnectionFactory factory;
+
+   @Before
+   @Override
+   public void setUp() throws Exception {
+      super.setUp();
+      serverControl = (ActiveMQServerControl) ManagementControlHelper.createProxy(ObjectNameBuilder.DEFAULT.getActiveMQServerObjectName(), ActiveMQServerControl.class, mbeanServer);
+      factory = new ActiveMQConnectionFactory(urlString);
+   }
+
+   @Override
+   protected void extraServerConfig(Configuration serverConfig) {
+      serverConfig.setJMXManagementEnabled(true);
+   }
+
+   @Test
+   public void testHiddenInternalAddress() throws Exception {
+      server.createQueue(queueName1, RoutingType.ANYCAST, queueName1, null, true, false, -1, false, true);
+      server.createQueue(queueName2, RoutingType.ANYCAST, queueName2, null, true, false, -1, false, true);
+      server.createQueue(queueName3, RoutingType.ANYCAST, queueName3, null, true, false, -1, false, true);
+
+
+      String[] addresses = serverControl.getAddressNames();
+      assertEquals(3, addresses.length);
+      for (String addr : addresses) {
+         assertFalse(addr.startsWith(AddressInfo.ADVISORY_TOPIC.toString()));
+      }
+
+      try (Connection connection = factory.createConnection()) {
+         connection.start();
+         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         Destination destination = session.createQueue(queueName1.toString());
+
+         ConsumerEventSource consumerEventSource = new ConsumerEventSource(connection, destination);
+         consumerEventSource.setConsumerListener(consumerEvent -> {
+         });
+         consumerEventSource.start();
+
+         ProducerEventSource producerEventSource = new ProducerEventSource(connection, destination);
+         producerEventSource.setProducerListener(producerEvent -> {
+         });
+         producerEventSource.start();
+
+         //after that point several advisory addresses are created.
+         //make sure they are not accessible via management api.
+         addresses = serverControl.getAddressNames();
+         for (String addr : addresses) {
+            assertFalse(addr.startsWith(AddressInfo.ADVISORY_TOPIC.toString()));
+         }
+         consumerEventSource.stop();
+         producerEventSource.stop();
+      }
+   }
+}