Commit d23d61b2 by ashutoshm Committed by Madhan Neethiraj

ATLAS-1960: fixed handling of import/export APIs in HA configuration

parent e0d2cdc2
......@@ -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() {
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment