Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions hadoop-ozone/integration-test-s3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,26 @@
<artifactId>aws-java-sdk-s3</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down Expand Up @@ -97,6 +112,31 @@
<artifactId>ratis-common</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-proxy</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 java.util.List;

/**
* Interface for load balancing strategies to select endpoints.
*/
public interface LoadBalanceStrategy {

/**
* Select the next endpoint from the available endpoints list.
*
* @param endpoints list of available endpoints
* @return the selected endpoint URL
*/
String selectEndpoint(List<String> endpoints);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* 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 static org.apache.ozone.test.GenericTestUtils.PortAllocator.localhostWithFreePort;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.ozone.MiniOzoneCluster;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Multi S3 Gateway for {@link MiniOzoneCluster}.
*/
public class MultiS3GatewayService implements MiniOzoneCluster.Service {

private static final Logger LOG = LoggerFactory.getLogger(MultiS3GatewayService.class);

private final List<S3GatewayService> gatewayServices = new ArrayList<>();
private ProxyServer proxyServer;
private OzoneConfiguration configuration;

public MultiS3GatewayService(int numGateways) {
for (int i = 0; i < numGateways; i++) {
gatewayServices.add(new S3GatewayService());
}
}

@Override
public void start(OzoneConfiguration conf) throws Exception {
List<String> urls = new ArrayList<>();
for (S3GatewayService service : gatewayServices) {
service.start(conf);
String redirectUrl = "http://" + service.getConf().get(S3GatewayConfigKeys.OZONE_S3G_HTTP_ADDRESS_KEY);
urls.add(redirectUrl);
}

configuration = new OzoneConfiguration(conf);
configuration.set(S3GatewayConfigKeys.OZONE_S3G_HTTP_ADDRESS_KEY, localhostWithFreePort());
String url = configuration.get(S3GatewayConfigKeys.OZONE_S3G_HTTP_ADDRESS_KEY);
URI proxyUri = new URI("http://" + url);
proxyServer = new ProxyServer(urls, proxyUri.getHost(), proxyUri.getPort());
proxyServer.start();
}

@Override
public void stop() throws Exception {
Exception exception = null;

if (proxyServer != null) {
try {
proxyServer.stop();
} catch (Exception e) {
LOG.warn("Error stopping proxy server", e);
exception = e;
}
}

for (S3GatewayService service : gatewayServices) {
try {
service.stop();
} catch (Exception e) {
LOG.warn("Error stopping S3 gateway service", e);
if (exception == null) {
exception = e;
} else {
exception.addSuppressed(e);
}
}
}

if (exception != null) {
throw exception;
}
}

public OzoneConfiguration getConf() {
return configuration;
}

}
Loading