From dc096f950d24e47f48883fdd49b27f51914d5783 Mon Sep 17 00:00:00 2001 From: Stanislav Knot Date: Thu, 8 Mar 2018 11:03:37 +0100 Subject: [PATCH] ARTEMIS-1737 fix for inaccessible slave console after failover --- .../artemis/core/server/ActiveMQServer.java | 4 +++ .../core/server/impl/ActiveMQServerImpl.java | 10 +++++++ .../impl/SharedNothingLiveActivation.java | 2 +- tests/integration-tests/pom.xml | 6 +++++ .../failover/ReplicatedFailoverTest.java | 26 +++++++++++++++++++ 5 files changed, 47 insertions(+), 1 deletion(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java index 88c25a853b..cc53e9932b 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java @@ -432,6 +432,8 @@ public interface ActiveMQServer extends ServiceComponent { void fail(boolean failoverOnServerShutdown) throws Exception; + void backToBackup(boolean failoverOnServerShutdown) throws Exception; + Queue updateQueue(String name, RoutingType routingType, Integer maxConsumers, @@ -472,6 +474,8 @@ public interface ActiveMQServer extends ServiceComponent { void addExternalComponent(ActiveMQComponent externalComponent); + List getExternalComponents(); + boolean addClientConnection(String clientId, boolean unique); void removeClientConnection(String clientId); 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 1f0dbd6a14..ea485e3ab1 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 @@ -915,6 +915,11 @@ public class ActiveMQServerImpl implements ActiveMQServer { stop(failoverOnServerShutdown, false, false, true); } + @Override + public final void backToBackup(boolean failoverOnServerShutdown) throws Exception { + stop(failoverOnServerShutdown, false, false, false); + } + public final void stop(boolean failoverOnServerShutdown, boolean isExit) throws Exception { stop(failoverOnServerShutdown, false, false, isExit); } @@ -3124,4 +3129,9 @@ public class ActiveMQServerImpl implements ActiveMQServer { public Set getActivateCallbacks() { return activateCallbacks; } + + @Override + public List getExternalComponents() { + return externalComponents; + } } \ No newline at end of file diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingLiveActivation.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingLiveActivation.java index 2e289b5acf..eaba72df3f 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingLiveActivation.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingLiveActivation.java @@ -187,7 +187,7 @@ public class SharedNothingLiveActivation extends LiveActivation { clusterConnection.addClusterTopologyListener(listener1); if (listener1.waitForBackup()) { //if we have to many backups kept or are not configured to restart just stop, otherwise restart as a backup - activeMQServer.fail(true); + activeMQServer.backToBackup(true); ActiveMQServerLogger.LOGGER.restartingReplicatedBackupAfterFailback(); // activeMQServer.moveServerData(replicatedPolicy.getReplicaPolicy().getMaxSavedReplicatedJournalsSize()); activeMQServer.setHAPolicy(replicatedPolicy.getReplicaPolicy()); diff --git a/tests/integration-tests/pom.xml b/tests/integration-tests/pom.xml index bf3f575278..5362b1e5dd 100644 --- a/tests/integration-tests/pom.xml +++ b/tests/integration-tests/pom.xml @@ -275,6 +275,12 @@ slf4j-api 1.7.5 + + org.apache.activemq + artemis-web + ${project.version} + test + diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/ReplicatedFailoverTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/ReplicatedFailoverTest.java index 88ac5e0d5c..663904406d 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/ReplicatedFailoverTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/ReplicatedFailoverTest.java @@ -16,12 +16,17 @@ */ package org.apache.activemq.artemis.tests.integration.cluster.failover; +import java.util.ArrayList; import java.util.concurrent.TimeUnit; import org.apache.activemq.artemis.api.core.client.ClientSession; +import org.apache.activemq.artemis.component.WebServerComponent; import org.apache.activemq.artemis.core.config.ha.ReplicaPolicyConfiguration; import org.apache.activemq.artemis.core.config.ha.ReplicatedPolicyConfiguration; +import org.apache.activemq.artemis.core.server.ServiceComponent; import org.apache.activemq.artemis.core.server.cluster.ha.ReplicatedPolicy; +import org.apache.activemq.artemis.dto.AppDTO; +import org.apache.activemq.artemis.dto.WebServerDTO; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestRule; @@ -125,6 +130,27 @@ public class ReplicatedFailoverTest extends FailoverTest { } } + @Test + public void testReplicatedFailbackBackupFromLiveBackToBackup() throws Exception { + WebServerDTO wdto = new WebServerDTO(); + AppDTO appDTO = new AppDTO(); + appDTO.war = "console.war"; + appDTO.url = "console"; + wdto.apps = new ArrayList(); + wdto.apps.add(appDTO); + wdto.bind = "http://localhost:0"; + wdto.path = "console"; + WebServerComponent webServerComponent = new WebServerComponent(); + webServerComponent.configure(wdto, ".", "."); + webServerComponent.start(); + + backupServer.getServer().addExternalComponent(webServerComponent); + // this is called when backup servers go from live back to backup + backupServer.getServer().backToBackup(true); + assertTrue(backupServer.getServer().getExternalComponents().get(0).isStarted()); + ((ServiceComponent)(backupServer.getServer().getExternalComponents().get(0))).stop(true); + + } @Override protected void createConfigs() throws Exception { createReplicatedConfigs();