From fea5e246e78c65c230dfca610c2e3da39c4a9ffc Mon Sep 17 00:00:00 2001 From: Justin Bertram Date: Thu, 11 Mar 2021 13:32:44 -0600 Subject: [PATCH] ARTEMIS-3166 support disabling configuration file reload --- .../activemq/cli/test/FileBrokerTest.java | 49 +++++++++++++++ .../test/resources/broker-reload-disabled.xml | 61 +++++++++++++++++++ .../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(-) create mode 100644 artemis-cli/src/test/resources/broker-reload-disabled.xml 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 59d1e89b00..bb2c6c27cf 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 0000000000..93b1542dbf --- /dev/null +++ b/artemis-cli/src/test/resources/broker-reload-disabled.xml @@ -0,0 +1,61 @@ + + + + + + + + + + ./target/paging + + ./target/bindings + + ./target/journal + + 2 + + ./target/large-messages + + -1 + + + tcp://${activemq.remoting.default.host:localhost}:${activemq.remoting.default.port:61616} + + + + + + + + + + + + DLQ + ExpiryQueue + 0 + 10Mb + 10 + BLOCK + + + + 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 5e8bffbc9a..c5fd448935 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 282de99545..306b1955d1 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 b07c203816..424c83949d 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: