You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2017/05/08 16:00:08 UTC

[1/2] activemq-artemis git commit: This closes #1257

Repository: activemq-artemis
Updated Branches:
  refs/heads/master 6984d39a9 -> 117d92bc9


This closes #1257


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

Branch: refs/heads/master
Commit: 117d92bc94cdf7b700e3db967ddcf23345a761f5
Parents: 6984d39 9fdba82
Author: Clebert Suconic <cl...@apache.org>
Authored: Mon May 8 11:59:41 2017 -0400
Committer: Clebert Suconic <cl...@apache.org>
Committed: Mon May 8 11:59:41 2017 -0400

----------------------------------------------------------------------
 .../deployers/impl/FileConfigurationParser.java | 32 +++++++++++++
 .../resources/schema/artemis-configuration.xsd  | 28 +++++++++++
 .../core/config/impl/FileConfigurationTest.java | 24 +++++++++-
 .../src/test/resources/brokerPlugin.xml         | 27 +++++++++++
 .../plugin/MethodCalledVerifier.java            |  5 ++
 .../integration/plugin/XmlConfigPluginTest.java | 49 ++++++++++++++++++++
 .../test/resources/broker-plugins-config.xml    | 48 +++++++++++++++++++
 7 files changed, 212 insertions(+), 1 deletion(-)
----------------------------------------------------------------------



[2/2] activemq-artemis git commit: ARTEMIS-898 - Adding support for XML configuration of Broker Plugins

Posted by cl...@apache.org.
ARTEMIS-898 - Adding support for XML configuration of Broker Plugins

Broker plugins can now be added to the broker through XML config.


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

Branch: refs/heads/master
Commit: 9fdba8292f7553a1cca6ac7b71477ad4a037807a
Parents: 6984d39
Author: Christopher L. Shannon (cshannon) <ch...@gmail.com>
Authored: Mon May 8 09:04:16 2017 -0400
Committer: Clebert Suconic <cl...@apache.org>
Committed: Mon May 8 11:59:41 2017 -0400

----------------------------------------------------------------------
 .../deployers/impl/FileConfigurationParser.java | 32 +++++++++++++
 .../resources/schema/artemis-configuration.xsd  | 28 +++++++++++
 .../core/config/impl/FileConfigurationTest.java | 24 +++++++++-
 .../src/test/resources/brokerPlugin.xml         | 27 +++++++++++
 .../plugin/MethodCalledVerifier.java            |  5 ++
 .../integration/plugin/XmlConfigPluginTest.java | 49 ++++++++++++++++++++
 .../test/resources/broker-plugins-config.xml    | 48 +++++++++++++++++++
 7 files changed, 212 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9fdba829/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java
index 17c9a32..5243325 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java
@@ -69,6 +69,7 @@ import org.apache.activemq.artemis.core.server.JournalType;
 import org.apache.activemq.artemis.core.server.SecuritySettingPlugin;
 import org.apache.activemq.artemis.core.server.cluster.impl.MessageLoadBalancingType;
 import org.apache.activemq.artemis.core.server.group.impl.GroupingHandlerConfiguration;
+import org.apache.activemq.artemis.core.server.plugin.ActiveMQServerPlugin;
 import org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy;
 import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
 import org.apache.activemq.artemis.core.settings.impl.ResourceLimitSettings;
@@ -97,6 +98,10 @@ public final class FileConfigurationParser extends XMLConfigurationUtil {
 
    public static final String SECURITY_ROLE_MAPPING_NAME = "role-mapping";
 
+   public static final String BROKER_PLUGINS_ELEMENT_NAME = "broker-plugins";
+
+   public static final String BROKER_PLUGIN_ELEMENT_NAME = "broker-plugin";
+
    private static final String PERMISSION_ELEMENT_NAME = "permission";
 
    private static final String SETTING_ELEMENT_NAME = "setting";
@@ -600,6 +605,8 @@ public final class FileConfigurationParser extends XMLConfigurationUtil {
 
       parseSecurity(e, config);
 
+      parseBrokerPlugins(e, config);
+
       NodeList connectorServiceConfigs = e.getElementsByTagName("connector-service");
 
       ArrayList<ConnectorServiceConfiguration> configs = new ArrayList<>();
@@ -647,6 +654,31 @@ public final class FileConfigurationParser extends XMLConfigurationUtil {
       }
    }
 
+   private void parseBrokerPlugins(final Element e, final Configuration config) {
+      NodeList brokerPlugins = e.getElementsByTagName(BROKER_PLUGINS_ELEMENT_NAME);
+      if (brokerPlugins.getLength() != 0) {
+         Element node = (Element) brokerPlugins.item(0);
+         NodeList list = node.getElementsByTagName(BROKER_PLUGIN_ELEMENT_NAME);
+         for (int i = 0; i < list.getLength(); i++) {
+            ActiveMQServerPlugin plugin = parseActiveMQServerPlugin(list.item(i));
+            config.registerBrokerPlugin(plugin);
+         }
+      }
+   }
+
+   private ActiveMQServerPlugin parseActiveMQServerPlugin(Node item) {
+      final String clazz = item.getAttributes().getNamedItem("class-name").getNodeValue();
+
+      ActiveMQServerPlugin serverPlugin = AccessController.doPrivileged(new PrivilegedAction<ActiveMQServerPlugin>() {
+         @Override
+         public ActiveMQServerPlugin run() {
+            return (ActiveMQServerPlugin) ClassloadingUtil.newInstanceFromClassLoader(clazz);
+         }
+      });
+
+      return serverPlugin;
+   }
+
    /**
     * @param e
     * @param config

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9fdba829/artemis-server/src/main/resources/schema/artemis-configuration.xsd
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/resources/schema/artemis-configuration.xsd b/artemis-server/src/main/resources/schema/artemis-configuration.xsd
index 2caef9b..b0e8502 100644
--- a/artemis-server/src/main/resources/schema/artemis-configuration.xsd
+++ b/artemis-server/src/main/resources/schema/artemis-configuration.xsd
@@ -852,6 +852,34 @@
                </xsd:sequence>
             </xsd:complexType>
          </xsd:element>
+         
+         <xsd:element name="broker-plugins" maxOccurs="1" minOccurs="0">
+            <xsd:annotation>
+               <xsd:documentation>
+                  a list of broker-plugins
+               </xsd:documentation>
+            </xsd:annotation>
+            <xsd:complexType>
+               <xsd:sequence>
+                  <xsd:element name="broker-plugin" maxOccurs="unbounded" minOccurs="0">
+                     <xsd:complexType>
+                        <xsd:annotation>
+                           <xsd:documentation>
+                              a broker plugin
+                           </xsd:documentation>
+                        </xsd:annotation>
+                        <xsd:attribute name="class-name" type="xsd:string" use="required">
+                           <xsd:annotation>
+                              <xsd:documentation>
+                                 the name of the broker plugin class to instantiate
+                              </xsd:documentation>
+                           </xsd:annotation>
+                        </xsd:attribute>
+                     </xsd:complexType>
+                  </xsd:element>               
+               </xsd:sequence>
+            </xsd:complexType>
+         </xsd:element>
 
          <xsd:element name="address-settings" maxOccurs="1" minOccurs="0">
             <xsd:annotation>

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9fdba829/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationTest.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationTest.java
index c87ce34..2f18365 100644
--- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationTest.java
+++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationTest.java
@@ -31,6 +31,7 @@ import java.util.Set;
 import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
 import org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration;
 import org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration;
+import org.apache.activemq.artemis.api.core.RoutingType;
 import org.apache.activemq.artemis.api.core.SimpleString;
 import org.apache.activemq.artemis.api.core.TransportConfiguration;
 import org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory;
@@ -45,12 +46,12 @@ import org.apache.activemq.artemis.core.config.HAPolicyConfiguration;
 import org.apache.activemq.artemis.core.config.ha.LiveOnlyPolicyConfiguration;
 import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
 import org.apache.activemq.artemis.core.security.Role;
-import org.apache.activemq.artemis.api.core.RoutingType;
 import org.apache.activemq.artemis.core.server.JournalType;
 import org.apache.activemq.artemis.core.server.Queue;
 import org.apache.activemq.artemis.core.server.SecuritySettingPlugin;
 import org.apache.activemq.artemis.core.server.cluster.impl.MessageLoadBalancingType;
 import org.apache.activemq.artemis.core.server.impl.LegacyLDAPSecuritySettingPlugin;
+import org.apache.activemq.artemis.core.server.plugin.ActiveMQServerPlugin;
 import org.apache.activemq.artemis.core.settings.impl.SlowConsumerPolicy;
 import org.junit.Assert;
 import org.junit.Test;
@@ -618,6 +619,19 @@ public class FileConfigurationTest extends ConfigurationImplTest {
       }
    }
 
+   @Test
+   public void testBrokerPlugin() throws Exception {
+      FileConfiguration fc = new FileConfiguration();
+      FileDeploymentManager deploymentManager = new FileDeploymentManager("brokerPlugin.xml");
+      deploymentManager.addDeployable(fc);
+      deploymentManager.readConfiguration();
+
+      List<ActiveMQServerPlugin> brokerPlugins = fc.getBrokerPlugins();
+      assertEquals(2, brokerPlugins.size());
+      assertTrue(brokerPlugins.get(0) instanceof EmptyPlugin1);
+      assertTrue(brokerPlugins.get(1) instanceof EmptyPlugin2);
+   }
+
    @Override
    protected Configuration createConfiguration() throws Exception {
       FileConfiguration fc = new FileConfiguration();
@@ -626,4 +640,12 @@ public class FileConfigurationTest extends ConfigurationImplTest {
       deploymentManager.readConfiguration();
       return fc;
    }
+
+   public static class EmptyPlugin1 implements ActiveMQServerPlugin {
+
+   }
+
+   public static class EmptyPlugin2 implements ActiveMQServerPlugin {
+
+   }
 }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9fdba829/artemis-server/src/test/resources/brokerPlugin.xml
----------------------------------------------------------------------
diff --git a/artemis-server/src/test/resources/brokerPlugin.xml b/artemis-server/src/test/resources/brokerPlugin.xml
new file mode 100644
index 0000000..6b1da34
--- /dev/null
+++ b/artemis-server/src/test/resources/brokerPlugin.xml
@@ -0,0 +1,27 @@
+<!--
+  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.
+-->
+<configuration
+        xmlns="urn:activemq"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:schemaLocation="urn:activemq ../../../../activemq-server/src/main/resources/schema/artemis-server.xsd">
+   <core xmlns="urn:activemq:core">
+      <broker-plugins>
+         <broker-plugin class-name="org.apache.activemq.artemis.core.config.impl.FileConfigurationTest$EmptyPlugin1" />
+         <broker-plugin class-name="org.apache.activemq.artemis.core.config.impl.FileConfigurationTest$EmptyPlugin2" />
+      </broker-plugins>
+   </core>
+</configuration>

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9fdba829/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/MethodCalledVerifier.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/MethodCalledVerifier.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/MethodCalledVerifier.java
index a055f06..d7627b5 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/MethodCalledVerifier.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/MethodCalledVerifier.java
@@ -7,6 +7,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -88,6 +89,10 @@ public class MethodCalledVerifier implements ActiveMQServerPlugin {
       this.methodCalls = methodCalls;
    }
 
+   public MethodCalledVerifier() {
+      this(new HashMap<String, AtomicInteger>());
+   }
+
    @Override
    public void afterCreateConnection(RemotingConnection connection) {
       Preconditions.checkNotNull(connection);

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9fdba829/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/XmlConfigPluginTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/XmlConfigPluginTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/XmlConfigPluginTest.java
new file mode 100644
index 0000000..fc81098
--- /dev/null
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/XmlConfigPluginTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.plugin;
+
+import org.apache.activemq.artemis.core.config.FileDeploymentManager;
+import org.apache.activemq.artemis.core.config.impl.FileConfiguration;
+import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl;
+import org.apache.activemq.artemis.jms.server.config.impl.FileJMSConfiguration;
+import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
+import org.junit.Test;
+
+public class XmlConfigPluginTest extends ActiveMQTestBase {
+
+   @Test
+   public void testStopStart1() throws Exception {
+      FileConfiguration fc = new FileConfiguration();
+      FileJMSConfiguration fileConfiguration = new FileJMSConfiguration();
+      FileDeploymentManager deploymentManager = new FileDeploymentManager("broker-plugins-config.xml");
+      deploymentManager.addDeployable(fc);
+      deploymentManager.addDeployable(fileConfiguration);
+      deploymentManager.readConfiguration();
+
+      ActiveMQServer server = addServer(new ActiveMQServerImpl(fc));
+      try {
+         server.start();
+         assertEquals(1, server.getBrokerPlugins().size());
+         assertTrue(server.getBrokerPlugins().get(0) instanceof MethodCalledVerifier);
+      } finally {
+         if (server != null) {
+            server.stop();
+         }
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9fdba829/tests/integration-tests/src/test/resources/broker-plugins-config.xml
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/resources/broker-plugins-config.xml b/tests/integration-tests/src/test/resources/broker-plugins-config.xml
new file mode 100644
index 0000000..a8ac3fb
--- /dev/null
+++ b/tests/integration-tests/src/test/resources/broker-plugins-config.xml
@@ -0,0 +1,48 @@
+<!--
+  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.
+-->
+<configuration xmlns="urn:activemq"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd">
+   <jms xmlns="urn:activemq:jms">
+      <queue name="myJMSQueue"/>
+   </jms>
+   <core xmlns="urn:activemq:core">
+
+      <connectors>
+         <connector name="netty-connector">tcp://localhost:61616</connector>
+      </connectors>
+
+      <journal-directory>./target/tmp/activemq-unit-test/broker-plugin-test/</journal-directory>
+
+      <acceptors>
+         <acceptor name="netty-acceptor">tcp://localhost:61616</acceptor>
+      </acceptors>
+
+      <security-enabled>false</security-enabled>
+
+      <queues>
+         <queue name="myQueue">
+            <address>myAddress</address>
+         </queue>
+      </queues>
+            
+      <broker-plugins>
+         <broker-plugin class-name="org.apache.activemq.artemis.tests.integration.plugin.MethodCalledVerifier" />
+      </broker-plugins>
+   </core>
+
+</configuration>