pan3793 commented on code in PR #46611:
URL: https://github.com/apache/spark/pull/46611#discussion_r1606205647


##########
resource-managers/yarn/src/main/java/org/apache/spark/deploy/yarn/AmIpFilter.java:
##########
@@ -0,0 +1,241 @@
+/*
+ * 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.spark.deploy.yarn;
+
+import org.apache.hadoop.classification.InterfaceAudience.Public;
+import org.apache.hadoop.classification.VisibleForTesting;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.util.Time;
+
+import jakarta.servlet.*;
+import jakarta.servlet.http.Cookie;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.net.*;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.spark.internal.SparkLogger;
+import org.apache.spark.internal.SparkLoggerFactory;
+
+// This class is copied from Hadoop 3.4.0
+// org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter
+//
+// Modification:
+// Migrate from javax.servlet to jakarta.servlet
+// Copy constant string definitions to strip external dependency
+//  - RM_HA_URLS
+//  - PROXY_USER_COOKIE_NAME
+@Public
+public class AmIpFilter implements Filter {
+  private static final SparkLogger LOG = 
SparkLoggerFactory.getLogger(AmIpFilter.class);
+
+  @Deprecated
+  public static final String PROXY_HOST = "PROXY_HOST";
+  @Deprecated
+  public static final String PROXY_URI_BASE = "PROXY_URI_BASE";
+  public static final String PROXY_HOSTS = "PROXY_HOSTS";
+  public static final String PROXY_HOSTS_DELIMITER = ",";
+  public static final String PROXY_URI_BASES = "PROXY_URI_BASES";
+  public static final String PROXY_URI_BASES_DELIMITER = ",";
+  private static final String PROXY_PATH = "/proxy";
+  // RM_HA_URLS is defined in AmFilterInitializer in the original Hadoop code
+  private static final String RM_HA_URLS = "RM_HA_URLS";
+  // WebAppProxyServlet is defined in WebAppProxyServlet in the original 
Hadoop code
+  public static final String PROXY_USER_COOKIE_NAME = "proxy-user";
+  //update the proxy IP list about every 5 min
+  private static long updateInterval = TimeUnit.MINUTES.toMillis(5);
+
+  private String[] proxyHosts;
+  private Set<String> proxyAddresses = null;
+  private long lastUpdate;
+  @VisibleForTesting
+  Map<String, String> proxyUriBases;
+  String[] rmUrls = null;
+
+  @Override
+  public void init(FilterConfig conf) throws ServletException {
+    // Maintain for backwards compatibility
+    if (conf.getInitParameter(PROXY_HOST) != null
+        && conf.getInitParameter(PROXY_URI_BASE) != null) {
+      proxyHosts = new String[]{conf.getInitParameter(PROXY_HOST)};
+      proxyUriBases = new HashMap<>(1);
+      proxyUriBases.put("dummy", conf.getInitParameter(PROXY_URI_BASE));
+    } else {
+      proxyHosts = conf.getInitParameter(PROXY_HOSTS)
+          .split(PROXY_HOSTS_DELIMITER);

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to