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 2021/03/17 14:52:24 UTC

[activemq-artemis] branch master updated: ARTEMIS-3166 support disabling configuration file reload

This is an automated email from the ASF dual-hosted git repository.

jbertram pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/master by this push:
     new fea5e24  ARTEMIS-3166 support disabling configuration file reload
     new d718a9d  This closes #3489
fea5e24 is described below

commit fea5e246e78c65c230dfca610c2e3da39c4a9ffc
Author: Justin Bertram <jb...@apache.org>
AuthorDate: Thu Mar 11 13:32:44 2021 -0600

    ARTEMIS-3166 support disabling configuration file reload
---
 .../apache/activemq/cli/test/FileBrokerTest.java   | 49 +++++++++++++++++
 .../src/test/resources/broker-reload-disabled.xml  | 61 ++++++++++++++++++++++
 .../deployers/impl/FileConfigurationParser.java    |  2 +-
 .../core/server/impl/ActiveMQServerImpl.java       | 23 ++++----
 docs/user-manual/en/config-reload.md               |  4 +-
 5 files changed, 126 insertions(+), 13 deletions(-)

diff --git a/artemis-cli/src/test/java/org/apache/activemq/cli/test/FileBrokerTest.java b/artemis-cli/src/test/java/org/apache/activemq/cli/test/FileBrokerTest.java
index 59d1e89..bb2c6c2 100644
--- a/artemis-cli/src/test/java/org/apache/activemq/cli/test/FileBrokerTest.java
+++ b/artemis-cli/src/test/java/org/apache/activemq/cli/test/FileBrokerTest.java
@@ -153,6 +153,55 @@ public class FileBrokerTest {
       }
    }
 
+   @Test
+   public void testConfigFileReloadNegative() throws Exception {
+      ServerDTO serverDTO = new ServerDTO();
+      serverDTO.configuration = "broker-reload-disabled.xml";
+      FileBroker broker = null;
+      String path = null;
+      try {
+         SecurityConfiguration securityConfiguration = new SecurityConfiguration();
+         securityConfiguration.addUser("myUser", "myPass");
+         securityConfiguration.addRole("myUser", "guest");
+         ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), securityConfiguration);
+         broker = new FileBroker(serverDTO, securityManager, null);
+         broker.start();
+         ActiveMQServerImpl activeMQServer = (ActiveMQServerImpl) broker.getComponents().get("core");
+         Assert.assertNotNull(activeMQServer);
+         Assert.assertTrue(activeMQServer.isStarted());
+         Assert.assertTrue(broker.isStarted());
+         File file = new File(activeMQServer.getConfiguration().getConfigurationUrl().toURI());
+         path = file.getPath();
+         Assert.assertNotNull(activeMQServer.getConfiguration().getConfigurationUrl());
+
+         Thread.sleep(1000);
+
+         ServerLocator locator = ActiveMQClient.createServerLocator("tcp://localhost:61616");
+         ClientSessionFactory sf = locator.createSessionFactory();
+         ClientSession session = sf.createSession("myUser", "myPass", false, true, false, false, 0);
+         ClientProducer producer = session.createProducer("DLQ");
+         producer.send(session.createMessage(true));
+
+         replacePatternInFile(path, "guest", "X");
+
+         Thread.sleep(1000);
+
+         try {
+            producer.send(session.createMessage(true));
+         } catch (Exception e) {
+            fail("Should not throw an exception: " + e.getMessage());
+         }
+
+         locator.close();
+      } finally {
+         assert broker != null;
+         broker.stop();
+         if (path != null) {
+            replacePatternInFile(path, "X", "guest");
+         }
+      }
+   }
+
    private void replacePatternInFile(String file, String regex, String replacement) throws IOException {
       Path path = Paths.get(file);
       Charset charset = StandardCharsets.UTF_8;
diff --git a/artemis-cli/src/test/resources/broker-reload-disabled.xml b/artemis-cli/src/test/resources/broker-reload-disabled.xml
new file mode 100644
index 0000000..93b1542
--- /dev/null
+++ b/artemis-cli/src/test/resources/broker-reload-disabled.xml
@@ -0,0 +1,61 @@
+<?xml version='1.0'?>
+<!--
+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">
+   <jms xmlns="urn:activemq:jms">
+      <queue name="DLQ"/>
+      <queue name="ExpiryQueue"/>
+   </jms>
+   <core xmlns="urn:activemq:core">
+      <paging-directory>./target/paging</paging-directory>
+
+      <bindings-directory>./target/bindings</bindings-directory>
+
+      <journal-directory>./target/journal</journal-directory>
+
+      <journal-min-files>2</journal-min-files>
+
+      <large-messages-directory>./target/large-messages</large-messages-directory>
+
+      <configuration-file-refresh-period>-1</configuration-file-refresh-period>
+
+      <acceptors>
+         <acceptor name="activemq">tcp://${activemq.remoting.default.host:localhost}:${activemq.remoting.default.port:61616}</acceptor>
+      </acceptors>
+
+      <security-settings>
+         <security-setting match="#">
+            <permission type="send" roles="guest"/>
+         </security-setting>
+      </security-settings>
+
+      <address-settings>
+         <!--default for catch all-->
+         <address-setting match="#">
+            <dead-letter-address>DLQ</dead-letter-address>
+            <expiry-address>ExpiryQueue</expiry-address>
+            <redelivery-delay>0</redelivery-delay>
+            <max-size-bytes>10Mb</max-size-bytes>
+            <message-counter-history-day-limit>10</message-counter-history-day-limit>
+            <address-full-policy>BLOCK</address-full-policy>
+         </address-setting>
+      </address-settings>
+   </core>
+</configuration>
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 5e8bffb..c5fd448 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
@@ -413,7 +413,7 @@ public final class FileConfigurationParser extends XMLConfigurationUtil {
 
       config.setConnectionTtlCheckInterval(getLong(e, "connection-ttl-check-interval", config.getConnectionTtlCheckInterval(), Validators.GT_ZERO));
 
-      config.setConfigurationFileRefreshPeriod(getLong(e, "configuration-file-refresh-period", config.getConfigurationFileRefreshPeriod(), Validators.GT_ZERO));
+      config.setConfigurationFileRefreshPeriod(getLong(e, "configuration-file-refresh-period", config.getConfigurationFileRefreshPeriod(), Validators.MINUS_ONE_OR_GT_ZERO));
 
       config.setTemporaryQueueNamespace(getString(e, "temporary-queue-namespace", config.getTemporaryQueueNamespace(), Validators.NOT_NULL_OR_EMPTY));
 
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
index 282de99..306b195 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
@@ -3122,18 +3122,21 @@ public class ActiveMQServerImpl implements ActiveMQServer {
 
       deployGroupingHandlerConfiguration(configuration.getGroupingHandlerConfiguration());
 
-      this.reloadManager = new ReloadManagerImpl(getScheduledPool(), executorFactory.getExecutor(), configuration.getConfigurationFileRefreshPeriod());
+      long configurationFileRefreshPeriod = configuration.getConfigurationFileRefreshPeriod();
+      if (configurationFileRefreshPeriod > 0) {
+         this.reloadManager = new ReloadManagerImpl(getScheduledPool(), executorFactory.getExecutor(), configurationFileRefreshPeriod);
 
-      if (configuration.getConfigurationUrl() != null && getScheduledPool() != null) {
-         reloadManager.addCallback(configuration.getConfigurationUrl(), uri -> reloadConfigurationFile(uri));
-      }
+         if (configuration.getConfigurationUrl() != null && getScheduledPool() != null) {
+            reloadManager.addCallback(configuration.getConfigurationUrl(), uri -> reloadConfigurationFile(uri));
+         }
 
-      if (System.getProperty("logging.configuration") != null) {
-         try {
-            reloadManager.addCallback(new URL(System.getProperty("logging.configuration")), new LoggingConfigurationFileReloader());
-         } catch (Exception e) {
-            // a syntax error with the logging system property shouldn't prevent the server from starting
-            ActiveMQServerLogger.LOGGER.problemAddingConfigReloadCallback(System.getProperty("logging.configuration"), e);
+         if (System.getProperty("logging.configuration") != null) {
+            try {
+               reloadManager.addCallback(new URL(System.getProperty("logging.configuration")), new LoggingConfigurationFileReloader());
+            } catch (Exception e) {
+               // a syntax error with the logging system property shouldn't prevent the server from starting
+               ActiveMQServerLogger.LOGGER.problemAddingConfigReloadCallback(System.getProperty("logging.configuration"), e);
+            }
          }
       }
 
diff --git a/docs/user-manual/en/config-reload.md b/docs/user-manual/en/config-reload.md
index b07c203..424c839 100644
--- a/docs/user-manual/en/config-reload.md
+++ b/docs/user-manual/en/config-reload.md
@@ -1,8 +1,8 @@
 # Configuration Reload
 
 The system will perform a periodic check on the configuration files, configured
-by `configuration-file-refresh-period`, with the default at 5000, in
-milliseconds.
+by `configuration-file-refresh-period`, with the default at `5000`, in
+milliseconds. These checks can be disabled by specifying `-1`.
 
 Once the configuration file is changed (broker.xml) the following modules will
 be reloaded automatically: