brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [08/19] incubator-brooklyn git commit: Deny resource requests during rebind
Date Thu, 19 Mar 2015 14:07:26 GMT
Deny resource requests during rebind


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

Branch: refs/heads/master
Commit: 3b99a96fd3f7fce9ba8b4f396c7bc696ecac6e9d
Parents: 35e6c3a
Author: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Authored: Wed Mar 4 17:05:56 2015 +0200
Committer: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Committed: Thu Mar 19 16:01:29 2015 +0200

----------------------------------------------------------------------
 .../rest/filter/HaStateCheckResourceFilter.java   | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3b99a96f/usage/rest-server/src/main/java/brooklyn/rest/filter/HaStateCheckResourceFilter.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/brooklyn/rest/filter/HaStateCheckResourceFilter.java
b/usage/rest-server/src/main/java/brooklyn/rest/filter/HaStateCheckResourceFilter.java
index 44f1d1a..9da0766 100644
--- a/usage/rest-server/src/main/java/brooklyn/rest/filter/HaStateCheckResourceFilter.java
+++ b/usage/rest-server/src/main/java/brooklyn/rest/filter/HaStateCheckResourceFilter.java
@@ -29,6 +29,7 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
 import brooklyn.config.BrooklynServiceAttributes;
+import brooklyn.entity.rebind.RebindManagerImpl.RebindTracker;
 import brooklyn.management.ManagementContext;
 import brooklyn.management.ha.ManagementNodeState;
 
@@ -68,11 +69,7 @@ public class HaStateCheckResourceFilter implements ResourceFilterFactory
{
 
         @Override
         public ContainerRequest filter(ContainerRequest request) {
-            boolean isHot = isHaHotStatus();
-            boolean isOverriden = "true".equalsIgnoreCase(request.getHeaderValue(HaMasterCheckFilter.SKIP_CHECK_HEADER));
-            if (!isHot && !isOverriden &&
-                    (am.getAnnotation(HaHotStateRequired.class) != null ||
-                    am.getResource().getAnnotation(HaHotStateRequired.class) != null)) {
+            if (!isStateLoaded() && isUnsafe(request)) {
                 Response response = Response.status(Response.Status.FORBIDDEN)
                         .type(MediaType.APPLICATION_JSON)
                         .entity("{\"error\":403,\"message\":\"Requests should be made to
the master Brooklyn server\"}")
@@ -82,6 +79,17 @@ public class HaStateCheckResourceFilter implements ResourceFilterFactory
{
             return request;
         }
 
+        private boolean isStateLoaded() {
+            return isHaHotStatus() && !RebindTracker.isRebinding();
+        }
+
+        private boolean isUnsafe(ContainerRequest request) {
+            boolean isOverriden = "true".equalsIgnoreCase(request.getHeaderValue(HaMasterCheckFilter.SKIP_CHECK_HEADER));
+            return !isOverriden &&
+                    (am.getAnnotation(HaHotStateRequired.class) != null ||
+                    am.getResource().getAnnotation(HaHotStateRequired.class) != null);
+        }
+
         private boolean isHaHotStatus() {
             ManagementNodeState state = mgmt.getHighAvailabilityManager().getNodeState();
             return HOT_STATES.contains(state);


Mime
View raw message