peterxcli commented on code in PR #8733: URL: https://github.com/apache/ozone/pull/8733#discussion_r2187970289
########## hadoop-ozone/integration-test-s3/src/test/java/org/apache/hadoop/ozone/s3/ProxyServer.java: ########## @@ -0,0 +1,257 @@ +/* + * 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.hadoop.ozone.s3; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpServer; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.InetSocketAddress; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * ProxyServer acts as a reverse proxy for S3G endpoints. + * It forwards requests to the selected S3G endpoint based on the load balancing strategy. + */ +public class ProxyServer { + private static final Logger LOG = LoggerFactory.getLogger(ProxyServer.class); + private final List<String> s3gEndpoints; + private final LoadBalanceStrategy loadBalanceStrategy; + private final HttpServer server; + private final String host; + private final int port; + private final ExecutorService executor; + + // Add timeout configurations for better handling of large file operations + private static final int CONNECT_TIMEOUT_MS = 60000; // 60 seconds + private static final int READ_TIMEOUT_MS = 300000; // 5 minutes + + private static final int BUFFER_SIZE = 64 * 1024; // 64KB + private static final ThreadLocal<byte[]> IO_BUFFER = ThreadLocal.withInitial(() -> new byte[BUFFER_SIZE]); + + public ProxyServer(List<String> s3gEndpoints, String host, int proxyPort) throws Exception { + this(s3gEndpoints, host, proxyPort, new RoundRobinStrategy()); + } + + public ProxyServer(List<String> s3gEndpoints, String host, int proxyPort, + LoadBalanceStrategy loadBalanceStrategy) throws Exception { + this.s3gEndpoints = s3gEndpoints; + this.loadBalanceStrategy = loadBalanceStrategy; + this.host = host; + this.port = proxyPort; + server = HttpServer.create(new InetSocketAddress(host, proxyPort), 0); + server.createContext("/", new ProxyHandler()); + + this.executor = Executors.newCachedThreadPool(); + server.setExecutor(executor); + + LOG.info("ProxyServer initialized with endpoints: {}", s3gEndpoints); + LOG.info("Load balance strategy: {}", loadBalanceStrategy.getClass().getSimpleName()); + LOG.info("Timeout settings - Connect: {}ms, Read: {}ms", CONNECT_TIMEOUT_MS, READ_TIMEOUT_MS); + } + + public void start() { + server.start(); + LOG.info("Proxy started on http://{}:{}", host, port); + + } + + public void stop() { + server.stop(0); + executor.shutdownNow(); + LOG.info("Proxy stopped on http://{}:{}", host, port); + } + + private class ProxyHandler implements HttpHandler { Review Comment: Do you have any reference for this logic? I'm not sure if we might be missing something here, even if the tests pass — it could still lead to errors in the future. ########## hadoop-ozone/integration-test-s3/src/test/java/org/apache/hadoop/ozone/s3/ProxyServer.java: ########## @@ -0,0 +1,251 @@ +/* + * 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.hadoop.ozone.s3; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpServer; Review Comment: I found that Jetty has a `ProxyServlet`, it seems to require minimal configuration. ref: https://gist.github.com/jponge/1752767 Please take a look. -- 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: issues-unsubscr...@ozone.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org For additional commands, e-mail: issues-h...@ozone.apache.org