ARTEMIS-2094 Only deploy reloadable config if reloaded.

This commit is contained in:
Michael André Pearce 2018-10-09 18:17:31 +01:00 committed by Clebert Suconic
parent f5a73dfab1
commit 8c6322deed
2 changed files with 35 additions and 18 deletions

View File

@ -16,6 +16,7 @@
*/ */
package org.apache.activemq.artemis.core.server.impl; package org.apache.activemq.artemis.core.server.impl;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.management.MBeanServer; import javax.management.MBeanServer;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -227,6 +228,8 @@ public class ActiveMQServerImpl implements ActiveMQServer {
private final Configuration configuration; private final Configuration configuration;
private final AtomicBoolean configurationReloadDeployed;
private MBeanServer mbeanServer; private MBeanServer mbeanServer;
private volatile SecurityStore securityStore; private volatile SecurityStore securityStore;
@ -412,6 +415,8 @@ public class ActiveMQServerImpl implements ActiveMQServer {
this.configuration = configuration; this.configuration = configuration;
this.configurationReloadDeployed = new AtomicBoolean(true);
this.mbeanServer = mbeanServer; this.mbeanServer = mbeanServer;
this.securityManager = securityManager; this.securityManager = securityManager;
@ -2602,7 +2607,16 @@ public class ActiveMQServerImpl implements ActiveMQServer {
} }
// Deploy the rest of the stuff // Deploy the rest of the stuff
deployReloadableConfigFromConfiguration(configuration);
// Deploy predefined addresses
deployAddressesFromConfiguration();
// Deploy any predefined queues
deployQueuesFromConfiguration();
// Undeploy any addresses and queues not in config
undeployAddressesAndQueueNotInConfiguration();
//deploy any reloaded config
deployReloadableConfigFromConfiguration();
// We need to call this here, this gives any dependent server a chance to deploy its own addresses // We need to call this here, this gives any dependent server a chance to deploy its own addresses
// this needs to be done before clustering is fully activated // this needs to be done before clustering is fully activated
@ -3482,30 +3496,33 @@ public class ActiveMQServerImpl implements ActiveMQServer {
configuration.setDivertConfigurations(config.getDivertConfigurations()); configuration.setDivertConfigurations(config.getDivertConfigurations());
configuration.setAddressConfigurations(config.getAddressConfigurations()); configuration.setAddressConfigurations(config.getAddressConfigurations());
configuration.setQueueConfigurations(config.getQueueConfigurations()); configuration.setQueueConfigurations(config.getQueueConfigurations());
configurationReloadDeployed.set(false);
if (isActive()) { if (isActive()) {
deployReloadableConfigFromConfiguration(configuration); deployReloadableConfigFromConfiguration();
} }
} }
} }
private void deployReloadableConfigFromConfiguration(Configuration config) throws Exception { private void deployReloadableConfigFromConfiguration() throws Exception {
if (configurationReloadDeployed.compareAndSet(false, true)) {
ActiveMQServerLogger.LOGGER.reloadingConfiguration("security"); ActiveMQServerLogger.LOGGER.reloadingConfiguration("security");
securityRepository.swap(config.getSecurityRoles().entrySet()); securityRepository.swap(configuration.getSecurityRoles().entrySet());
ActiveMQServerLogger.LOGGER.reloadingConfiguration("address settings"); ActiveMQServerLogger.LOGGER.reloadingConfiguration("address settings");
addressSettingsRepository.swap(config.getAddressesSettings().entrySet()); addressSettingsRepository.swap(configuration.getAddressesSettings().entrySet());
ActiveMQServerLogger.LOGGER.reloadingConfiguration("diverts"); ActiveMQServerLogger.LOGGER.reloadingConfiguration("diverts");
for (DivertConfiguration divertConfig : config.getDivertConfigurations()) { for (DivertConfiguration divertConfig : configuration.getDivertConfigurations()) {
if (postOffice.getBinding(new SimpleString(divertConfig.getName())) == null) { if (postOffice.getBinding(new SimpleString(divertConfig.getName())) == null) {
deployDivert(divertConfig); deployDivert(divertConfig);
} }
} }
ActiveMQServerLogger.LOGGER.reloadingConfiguration("addresses"); ActiveMQServerLogger.LOGGER.reloadingConfiguration("addresses");
undeployAddressesAndQueueNotInConfiguration(config); undeployAddressesAndQueueNotInConfiguration(configuration);
deployAddressesFromConfiguration(config); deployAddressesFromConfiguration(configuration);
deployQueuesFromListCoreQueueConfiguration(config.getQueueConfigurations()); deployQueuesFromListCoreQueueConfiguration(configuration.getQueueConfigurations());
}
} }
public Set<ActivateCallback> getActivateCallbacks() { public Set<ActivateCallback> getActivateCallbacks() {

View File

@ -295,8 +295,8 @@ public class RedeployTest extends ActiveMQTestBase {
Assert.assertNotNull("Queue wasn't deployed accordingly", consumer.receive(5000)); Assert.assertNotNull("Queue wasn't deployed accordingly", consumer.receive(5000));
Assert.assertNotNull(consumer.receive(5000)); Assert.assertNotNull(consumer.receive(5000));
} }
assertEquals("Test address settings redeploy - backup", changed, backup.getActiveMQServer().getSecurityRepository().getMatch("myQueue")); assertEquals("Test security settings redeploy - backup", changed, backup.getActiveMQServer().getSecurityRepository().getMatch("myQueue"));
assertEquals("Test security settings redeploy - backup", AddressFullMessagePolicy.PAGE, backup.getActiveMQServer().getAddressSettingsRepository().getMatch("myQueue").getAddressFullMessagePolicy()); assertEquals("Test address settings redeploy - backup", AddressFullMessagePolicy.PAGE, backup.getActiveMQServer().getAddressSettingsRepository().getMatch("myQueue").getAddressFullMessagePolicy());
} finally { } finally {
live.stop(); live.stop();
backup.stop(); backup.stop();