atlas-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject [36/39] atlas git commit: ATLAS-1960: fixed handling of import/export APIs in HA configuration
Date Mon, 24 Jul 2017 15:57:41 GMT
ATLAS-1960: fixed handling of import/export APIs in HA configuration

Signed-off-by: Madhan Neethiraj <madhan@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/d23d61b2
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/d23d61b2
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/d23d61b2

Branch: refs/heads/feature-odf
Commit: d23d61b2a88a472978dcd15428a61dfa48d31215
Parents: e0d2cdc
Author: ashutoshm <amestry@hortonworks.com>
Authored: Fri Jul 21 12:17:42 2017 -0700
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Fri Jul 21 19:24:42 2017 -0700

----------------------------------------------------------------------
 .../atlas/web/filters/ActiveServerFilter.java   | 15 ++++++++-
 .../web/filters/ActiveServerFilterTest.java     | 35 ++++++++++++++++----
 2 files changed, 42 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/d23d61b2/webapp/src/main/java/org/apache/atlas/web/filters/ActiveServerFilter.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/filters/ActiveServerFilter.java b/webapp/src/main/java/org/apache/atlas/web/filters/ActiveServerFilter.java
index 36f2688..29d829f 100644
--- a/webapp/src/main/java/org/apache/atlas/web/filters/ActiveServerFilter.java
+++ b/webapp/src/main/java/org/apache/atlas/web/filters/ActiveServerFilter.java
@@ -100,10 +100,23 @@ public class ActiveServerFilter implements Filter {
         }
     }
 
+    final String adminUriNotFiltered[] = { "/admin/export", "/admin/import", "/admin/importfile"
};
     private boolean isFilteredURI(ServletRequest servletRequest) {
         HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
         String requestURI = httpServletRequest.getRequestURI();
-        return requestURI.contains("/admin/");
+
+        if(requestURI.contains("/admin/")) {
+            for (String s : adminUriNotFiltered) {
+                if (requestURI.contains(s)) {
+                    LOG.error("URL not supported in HA mode: {}", requestURI);
+                    return false;
+                }
+            }
+
+            return true;
+        } else {
+            return false;
+        }
     }
 
     boolean isInstanceActive() {

http://git-wip-us.apache.org/repos/asf/atlas/blob/d23d61b2/webapp/src/test/java/org/apache/atlas/web/filters/ActiveServerFilterTest.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/filters/ActiveServerFilterTest.java
b/webapp/src/test/java/org/apache/atlas/web/filters/ActiveServerFilterTest.java
index a8d1110..3396072 100644
--- a/webapp/src/test/java/org/apache/atlas/web/filters/ActiveServerFilterTest.java
+++ b/webapp/src/test/java/org/apache/atlas/web/filters/ActiveServerFilterTest.java
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -99,7 +99,28 @@ public class ActiveServerFilterTest {
 
         activeServerFilter.doFilter(servletRequest, servletResponse, filterChain);
 
-        verify(servletResponse).sendRedirect(ACTIVE_SERVER_ADDRESS+"types");
+        verify(servletResponse).sendRedirect(ACTIVE_SERVER_ADDRESS + "types");
+    }
+
+
+    @Test
+    public void adminImportRequestsToPassiveServerShouldToActiveServerAddress() throws IOException,
ServletException {
+        String importExportUrls[] = {"api/admin/export", "api/admin/import", "api/admin/importfile"};
+
+        for (String partialUrl : importExportUrls) {
+            when(serviceState.getState()).thenReturn(ServiceState.ServiceStateValue.PASSIVE);
+            when(servletRequest.getRequestURI()).thenReturn(partialUrl);
+
+            ActiveServerFilter activeServerFilter = new ActiveServerFilter(activeInstanceState,
serviceState);
+
+            when(activeInstanceState.getActiveServerAddress()).thenReturn(ACTIVE_SERVER_ADDRESS);
+            when(servletRequest.getRequestURI()).thenReturn(partialUrl);
+            when(servletRequest.getMethod()).thenReturn(HttpMethod.GET);
+
+            activeServerFilter.doFilter(servletRequest, servletResponse, filterChain);
+
+            verify(servletResponse).sendRedirect(ACTIVE_SERVER_ADDRESS + partialUrl);
+        }
     }
 
     @Test
@@ -116,7 +137,7 @@ public class ActiveServerFilterTest {
 
         activeServerFilter.doFilter(servletRequest, servletResponse, filterChain);
 
-        verify(servletResponse).sendRedirect(ACTIVE_SERVER_ADDRESS+"types?query=TRAIT");
+        verify(servletResponse).sendRedirect(ACTIVE_SERVER_ADDRESS + "types?query=TRAIT");
 
     }
 
@@ -133,7 +154,7 @@ public class ActiveServerFilterTest {
 
         activeServerFilter.doFilter(servletRequest, servletResponse, filterChain);
 
-        verify(servletResponse).setHeader("Location", ACTIVE_SERVER_ADDRESS+"types");
+        verify(servletResponse).setHeader("Location", ACTIVE_SERVER_ADDRESS + "types");
         verify(servletResponse).setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
     }
 
@@ -150,7 +171,7 @@ public class ActiveServerFilterTest {
 
         activeServerFilter.doFilter(servletRequest, servletResponse, filterChain);
 
-        verify(servletResponse).setHeader("Location", ACTIVE_SERVER_ADDRESS+"types");
+        verify(servletResponse).setHeader("Location", ACTIVE_SERVER_ADDRESS + "types");
         verify(servletResponse).setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
     }
 


Mime
View raw message