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 2018/03/09 15:10:09 UTC

[2/3] activemq-artemis git commit: ARTEMIS-1737 Fixing semantic of ServerControl.forceFailover

ARTEMIS-1737 Fixing semantic of ServerControl.forceFailover

This closes #1940


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

Branch: refs/heads/master
Commit: 91c0452d601729585cd75e4d74c473b92f3bd1af
Parents: dc096f9
Author: Clebert Suconic <cl...@apache.org>
Authored: Thu Mar 8 16:24:38 2018 -0500
Committer: Clebert Suconic <cl...@apache.org>
Committed: Thu Mar 8 23:42:29 2018 -0500

----------------------------------------------------------------------
 .../impl/ActiveMQServerControlImpl.java         |  2 +-
 .../artemis/core/server/ActiveMQServer.java     |  2 +-
 .../core/server/impl/ActiveMQServerImpl.java    |  6 +-
 .../impl/SharedNothingLiveActivation.java       |  2 +-
 .../failover/ReplicatedFailoverTest.java        | 63 ++++++++++++++------
 5 files changed, 50 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/91c0452d/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java
index fe7792b..72e23a7 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java
@@ -2611,7 +2611,7 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
          @Override
          public void run() {
             try {
-               server.fail(true);
+               server.stop(true, true);
             } catch (Throwable e) {
                logger.warn(e.getMessage(), e);
             }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/91c0452d/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java
----------------------------------------------------------------------
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 cc53e99..78ebbb7 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,7 +432,7 @@ public interface ActiveMQServer extends ServiceComponent {
 
    void fail(boolean failoverOnServerShutdown) throws Exception;
 
-   void backToBackup(boolean failoverOnServerShutdown) throws Exception;
+   void stop(boolean failoverOnServerShutdown, boolean isExit) throws Exception;
 
    Queue updateQueue(String name,
                      RoutingType routingType,

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/91c0452d/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
----------------------------------------------------------------------
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 ea485e3..d2ae179 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
@@ -912,14 +912,10 @@ public class ActiveMQServerImpl implements ActiveMQServer {
 
    @Override
    public final void fail(boolean failoverOnServerShutdown) throws Exception {
-      stop(failoverOnServerShutdown, false, false, true);
-   }
-
-   @Override
-   public final void backToBackup(boolean failoverOnServerShutdown) throws Exception {
       stop(failoverOnServerShutdown, false, false, false);
    }
 
+   @Override
    public final void stop(boolean failoverOnServerShutdown, boolean isExit) throws Exception {
       stop(failoverOnServerShutdown, false, false, isExit);
    }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/91c0452d/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingLiveActivation.java
----------------------------------------------------------------------
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 eaba72d..2e289b5 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.backToBackup(true);
+                        activeMQServer.fail(true);
                         ActiveMQServerLogger.LOGGER.restartingReplicatedBackupAfterFailback();
                         //                        activeMQServer.moveServerData(replicatedPolicy.getReplicaPolicy().getMaxSavedReplicatedJournalsSize());
                         activeMQServer.setHAPolicy(replicatedPolicy.getReplicaPolicy());

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/91c0452d/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/ReplicatedFailoverTest.java
----------------------------------------------------------------------
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 6639044..814eb8b 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,9 +16,15 @@
  */
 package org.apache.activemq.artemis.tests.integration.cluster.failover;
 
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
 import java.util.ArrayList;
 import java.util.concurrent.TimeUnit;
 
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+import com.sun.net.httpserver.HttpServer;
 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;
@@ -27,6 +33,7 @@ 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.Assert;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TestRule;
@@ -132,23 +139,45 @@ 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<AppDTO>();
-      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);
+
+      InetSocketAddress address = new InetSocketAddress("127.0.0.1", 8787);
+      HttpServer httpServer = HttpServer.create(address, 100);
+      httpServer.start();
+
+      try {
+         httpServer.createContext("/", new HttpHandler() {
+            @Override
+            public void handle(HttpExchange t) throws IOException {
+               String response = "<html><body><b>This is a unit test</b></body></html>";
+               t.sendResponseHeaders(200, response.length());
+               OutputStream os = t.getResponseBody();
+               os.write(response.getBytes());
+               os.close();
+            }
+         });
+         WebServerDTO wdto = new WebServerDTO();
+         AppDTO appDTO = new AppDTO();
+         appDTO.war = "console.war";
+         appDTO.url = "console";
+         wdto.apps = new ArrayList<AppDTO>();
+         wdto.apps.add(appDTO);
+         wdto.bind = "http://localhost:0";
+         wdto.path = "console";
+         WebServerComponent webServerComponent = new WebServerComponent();
+         webServerComponent.configure(wdto, ".", ".");
+         webServerComponent.start();
+
+         backupServer.getServer().getNetworkHealthCheck().parseURIList("http://localhost:8787");
+         Assert.assertTrue(backupServer.getServer().getNetworkHealthCheck().isStarted());
+         backupServer.getServer().addExternalComponent(webServerComponent);
+         // this is called when backup servers go from live back to backup
+         backupServer.getServer().fail(true);
+         Assert.assertTrue(backupServer.getServer().getNetworkHealthCheck().isStarted());
+         Assert.assertTrue(backupServer.getServer().getExternalComponents().get(0).isStarted());
+         ((ServiceComponent) (backupServer.getServer().getExternalComponents().get(0))).stop(true);
+      } finally {
+         httpServer.stop(0);
+      }
 
    }
    @Override