SLIDER-724 Implement OfflineFilter to return 503 "unavailable", for AM bootstrap âremoving filter
Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/b09bd848 Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/b09bd848 Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/b09bd848 Branch: refs/heads/feature/SLIDER-151_REST_API Commit: b09bd848069f1fff450e4d4690cafcf11678f544 Parents: fe3ffc9 Author: Steve Loughran <[email protected]> Authored: Mon Dec 15 14:27:32 2014 +0000 Committer: Steve Loughran <[email protected]> Committed: Tue Dec 16 20:25:39 2014 +0000 ---------------------------------------------------------------------- .../appmaster/web/utils/OfflineFilter.java | 104 ------------------- 1 file changed, 104 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/b09bd848/slider-core/src/main/java/org/apache/slider/server/appmaster/web/utils/OfflineFilter.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/utils/OfflineFilter.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/utils/OfflineFilter.java deleted file mode 100644 index ad16f4e..0000000 --- a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/utils/OfflineFilter.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * 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 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.slider.server.appmaster.web.utils; - -import com.google.common.base.Preconditions; -import org.apache.hadoop.http.FilterContainer; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Offline filter. - * All filter instances share the static offline flag. - * <p> - * Callers must use the method {@link #bindFilter(FilterContainer)} - * to bind to the web container. - */ -public class OfflineFilter implements Filter { - - private static final AtomicBoolean offline = new AtomicBoolean(true); - - private static String offlineMessage = "offline"; - private static final AtomicInteger retry = new AtomicInteger(10); - - public OfflineFilter() { - } - - public static synchronized void goOffline(String message) { - Preconditions.checkArgument(message != null, "null message"); - offline.set(true); - offlineMessage = message; - } - - public static synchronized String getOfflineMessage() { - return offlineMessage; - } - - public static int getRetry() { - return retry.intValue(); - } - - public static void setRetry(int retryCount) { - retry.set(retryCount); - } - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - - } - - @Override - public void doFilter(ServletRequest request, - ServletResponse response, - FilterChain chain) throws IOException, ServletException { - - if (!offline.get()) { - chain.doFilter(request, response); - } else { - // service is offline - HttpServletResponse httpResponse = (HttpServletResponse) response; - httpResponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, - getOfflineMessage()); - } - } - - @Override - public void destroy() { - - } - - /** - * Add the filter to a container - * @param container container - */ - public static void bindFilter(FilterContainer container) { - container.addFilter("OfflineFilter", - "org.apache.slider.server.appmaster.web.utils.OfflineFilter", - null); - } -}
