brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [05/19] incubator-brooklyn git commit: Don't deny requests if HA is stopped
Date Thu, 19 Mar 2015 14:07:23 GMT
Don't deny requests if HA is stopped


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/95e48b9f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/95e48b9f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/95e48b9f

Branch: refs/heads/master
Commit: 95e48b9fcea72789db7b2441bfaca058de2bbbf8
Parents: 5a75775
Author: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Authored: Fri Mar 6 15:37:24 2015 +0200
Committer: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Committed: Thu Mar 19 16:01:29 2015 +0200

----------------------------------------------------------------------
 .../rest/filter/HaHotCheckResourceFilter.java   |  5 +-
 .../test/java/brooklyn/rest/HaHotCheckTest.java |  8 +++
 .../brooklyn/rest/HaMasterCheckFilterTest.java  | 61 ++++++++++----------
 .../mocks/HighAvailabilityManagerMock.java      | 10 ++--
 4 files changed, 45 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/95e48b9f/usage/rest-server/src/main/java/brooklyn/rest/filter/HaHotCheckResourceFilter.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/brooklyn/rest/filter/HaHotCheckResourceFilter.java
b/usage/rest-server/src/main/java/brooklyn/rest/filter/HaHotCheckResourceFilter.java
index 55f5467..8b1d67f 100644
--- a/usage/rest-server/src/main/java/brooklyn/rest/filter/HaHotCheckResourceFilter.java
+++ b/usage/rest-server/src/main/java/brooklyn/rest/filter/HaHotCheckResourceFilter.java
@@ -81,7 +81,7 @@ public class HaHotCheckResourceFilter implements ResourceFilterFactory {
         }
 
         private boolean isStateLoaded() {
-            return isHaHotStatus() && !RebindTracker.isRebinding() && !recentlySwitchedState();
+            return isHaHotStatusOrDisabled() && !RebindTracker.isRebinding() &&
!recentlySwitchedState();
         }
 
         // Ideally there will be a separate state to indicate that we switched state
@@ -99,7 +99,8 @@ public class HaHotCheckResourceFilter implements ResourceFilterFactory {
                     am.getResource().getAnnotation(HaHotStateRequired.class) != null);
         }
 
-        private boolean isHaHotStatus() {
+        private boolean isHaHotStatusOrDisabled() {
+            if (!mgmt.getHighAvailabilityManager().isRunning()) return true;
             ManagementNodeState state = mgmt.getHighAvailabilityManager().getNodeState();
             return HOT_STATES.contains(state);
         }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/95e48b9f/usage/rest-server/src/test/java/brooklyn/rest/HaHotCheckTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/brooklyn/rest/HaHotCheckTest.java b/usage/rest-server/src/test/java/brooklyn/rest/HaHotCheckTest.java
index 224cda6..345e51b 100644
--- a/usage/rest-server/src/test/java/brooklyn/rest/HaHotCheckTest.java
+++ b/usage/rest-server/src/test/java/brooklyn/rest/HaHotCheckTest.java
@@ -70,6 +70,14 @@ public class HaHotCheckTest extends BrooklynRestResourceTest {
         testResourceFetch("/ha/method/ok", 200);
         testResourceFetch("/ha/method/fail", 403);
         testResourceFetch("/ha/class/fail", 403);
+
+        //forces isRunning = false
+        mgmtMock.setState(ManagementNodeState.TERMINATED);
+        assertEquals(ha.getNodeState(), ManagementNodeState.TERMINATED);
+
+        testResourceFetch("/ha/method/ok", 200);
+        testResourceFetch("/ha/method/fail", 200);
+        testResourceFetch("/ha/class/fail", 200);
     }
 
     private void testResourceFetch(String resource, int code) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/95e48b9f/usage/rest-server/src/test/java/brooklyn/rest/HaMasterCheckFilterTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/brooklyn/rest/HaMasterCheckFilterTest.java b/usage/rest-server/src/test/java/brooklyn/rest/HaMasterCheckFilterTest.java
index 55452c8..671a6b2 100644
--- a/usage/rest-server/src/test/java/brooklyn/rest/HaMasterCheckFilterTest.java
+++ b/usage/rest-server/src/test/java/brooklyn/rest/HaMasterCheckFilterTest.java
@@ -19,7 +19,6 @@
 package brooklyn.rest;
 
 import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
 import io.brooklyn.camp.brooklyn.BrooklynCampPlatformLauncherNoServer;
 
 import java.io.File;
@@ -27,10 +26,9 @@ import java.net.URI;
 import java.util.concurrent.Callable;
 import java.util.concurrent.TimeoutException;
 
+import org.apache.http.HttpStatus;
 import org.apache.http.client.HttpClient;
 import org.eclipse.jetty.server.Server;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.Test;
 
@@ -55,7 +53,6 @@ import com.google.common.base.Supplier;
 import com.google.common.collect.ImmutableMap;
 
 public class HaMasterCheckFilterTest extends BrooklynRestApiLauncherTestFixture {
-    private static final Logger LOG = LoggerFactory.getLogger(HaMasterCheckFilterTest.class);
     private static final Duration TIMEOUT = Duration.THIRTY_SECONDS;
 
     private File mementoDir;
@@ -74,6 +71,13 @@ public class HaMasterCheckFilterTest extends BrooklynRestApiLauncherTestFixture
     }
 
     @Test(groups = "Integration")
+    public void testEntitiesExistOnDisabledHA() throws Exception {
+        initHaCluster(HighAvailabilityMode.DISABLED, HighAvailabilityMode.DISABLED);
+        assertReadIsMaster();
+        assertEntityExists(new ReturnCodeCheck());
+    }
+
+    @Test(groups = "Integration")
     public void testEntitiesExistOnMasterPromotion() throws Exception {
         initHaCluster(HighAvailabilityMode.AUTO, HighAvailabilityMode.AUTO);
         stopWriteNode();
@@ -129,7 +133,11 @@ public class HaMasterCheckFilterTest extends BrooklynRestApiLauncherTestFixture
                 .emptyCatalog(true)
                 .buildUnstarted();
 
-        mgmt.getHighAvailabilityManager().start(mode);
+        if (mode == HighAvailabilityMode.DISABLED) {
+            mgmt.getHighAvailabilityManager().disabled();
+        } else {
+            mgmt.getHighAvailabilityManager().start(mode);
+        }
 
         new BrooklynCampPlatformLauncherNoServer()
             .useManagementContext(mgmt)
@@ -145,7 +153,12 @@ public class HaMasterCheckFilterTest extends BrooklynRestApiLauncherTestFixture
         appId = createApp(writeMgmt);
         writeMgmt.getRebindManager().getPersister().waitForWritesCompleted(TIMEOUT);
 
-        readMgmt = createManagementContext(mementoDir, readMode);
+        if (readMode == HighAvailabilityMode.DISABLED) {
+            //no HA, one node only
+            readMgmt = writeMgmt;
+        } else {
+            readMgmt = createManagementContext(mementoDir, readMode);
+        }
 
         server = useServerForTest(BrooklynRestApiLauncher.launcher()
                 .managementContext(readMgmt)
@@ -157,12 +170,11 @@ public class HaMasterCheckFilterTest extends BrooklynRestApiLauncherTestFixture
         client = getClient(server);
     }
 
-    private void assertEntityExists(Callable<Boolean> c) {
-        assertTrue(Asserts.succeedsEventually(c), "Unexpected code returned");
+    private void assertEntityExists(Callable<Integer> c) {
+        assertEquals((int)Asserts.succeedsEventually(c), 200);
     }
 
     private void assertReadIsMaster() {
-//        Asserts.eventually(new NodeStateSupplier(readMgmt), Predicates.equalTo(ManagementNodeState.MASTER));
         assertEquals(readMgmt.getHighAvailabilityManager().getNodeState(), ManagementNodeState.MASTER);
     }
 
@@ -170,26 +182,23 @@ public class HaMasterCheckFilterTest extends BrooklynRestApiLauncherTestFixture
         writeMgmt.getHighAvailabilityManager().stop();
     }
 
-    private class ReturnCodeCheck implements Callable<Boolean> {
+    private class ReturnCodeCheck implements Callable<Integer> {
         @Override
-        public Boolean call() {
+        public Integer call() {
             int retCode = getAppResponseCode();
-            if (retCode == 200) {
-                return true;
-            } else if (retCode == 403) {
-                throw new RuntimeException("Not ready, response " + retCode);
+            if (retCode == 403) {
+                throw new RuntimeException("Not ready, retry. Response - " + retCode);
             } else {
-                LOG.error("Unexpected return code " + retCode);
-                return false;
+                return retCode;
             }
         }
     }
 
     private class ReturnCodeAndNodeState extends ReturnCodeCheck {
         @Override
-        public Boolean call() {
-            Boolean ret = super.call();
-            if (ret) {
+        public Integer call() {
+            Integer ret = super.call();
+            if (ret == HttpStatus.SC_OK) {
                 ManagementNodeState state = readMgmt.getHighAvailabilityManager().getNodeState();
                 if (state != ManagementNodeState.MASTER) {
                     throw new RuntimeException("Not master yet " + state);
@@ -206,16 +215,4 @@ public class HaMasterCheckFilterTest extends BrooklynRestApiLauncherTestFixture
         }
     }
 
-    private static class NodeStateSupplier implements Supplier<ManagementNodeState>
{
-        private ManagementContext node;
-        public NodeStateSupplier(ManagementContext node) {
-            this.node = node;
-        }
-
-        @Override
-        public ManagementNodeState get() {
-            return node.getHighAvailabilityManager().getNodeState();
-        }
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/95e48b9f/usage/rest-server/src/test/java/brooklyn/rest/testing/mocks/HighAvailabilityManagerMock.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/brooklyn/rest/testing/mocks/HighAvailabilityManagerMock.java
b/usage/rest-server/src/test/java/brooklyn/rest/testing/mocks/HighAvailabilityManagerMock.java
index abc8e00..5c99183 100644
--- a/usage/rest-server/src/test/java/brooklyn/rest/testing/mocks/HighAvailabilityManagerMock.java
+++ b/usage/rest-server/src/test/java/brooklyn/rest/testing/mocks/HighAvailabilityManagerMock.java
@@ -39,6 +39,11 @@ public class HighAvailabilityManagerMock implements HighAvailabilityManager
{
     }
 
     @Override
+    public boolean isRunning() {
+        return state != ManagementNodeState.TERMINATED;
+    }
+
+    @Override
     public ManagementNodeState getNodeState() {
         return state;
     }
@@ -59,11 +64,6 @@ public class HighAvailabilityManagerMock implements HighAvailabilityManager
{
     }
 
     @Override
-    public boolean isRunning() {
-        throw fail();
-    }
-
-    @Override
     public void start(HighAvailabilityMode startMode) {
         throw fail();
     }


Mime
View raw message