forked from elcallio/kraken-dynamo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7001486
Showing
8 changed files
with
929 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "alternator-load-balancing"] | ||
path = alternator-load-balancing | ||
url = https://github.com/scylladb/alternator-load-balancing.git |
Submodule alternator-load-balancing
added at
4ff1da
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.scylladb.alternator</groupId> | ||
<artifactId>kraken-dynamo</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>pom</packaging> | ||
|
||
<modules> | ||
<module>alternator-load-balancing/java</module> | ||
<module>syncer</module> | ||
</modules> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.scylladb.alternator</groupId> | ||
<artifactId>kraken-dynamo</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>kraken-dynamo-syncer</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.1</version> | ||
<configuration> | ||
<source>${java.version}</source> | ||
<target>${java.version}</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.1</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>bom</artifactId> | ||
<version>2.16.29</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<version>5.4.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>5.4.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.platform</groupId> | ||
<artifactId>junit-platform-commons</artifactId> | ||
<version>1.4.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.platform</groupId> | ||
<artifactId>junit-platform-launcher</artifactId> | ||
<version>1.4.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>dynamodb</artifactId> | ||
<version>2.11.3</version><!--$NO-MVN-MAN-VER$--> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<version>1.3.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.sourceforge.argparse4j</groupId> | ||
<artifactId>argparse4j</artifactId> | ||
<version>0.8.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.scylladb.alternator</groupId> | ||
<artifactId>LoadBalancing</artifactId> | ||
<version>1.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>1.2.3</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>jcl-over-slf4j</artifactId> | ||
<version>1.7.25</version> | ||
</dependency> | ||
|
||
|
||
|
||
</dependencies> | ||
</project> |
85 changes: 85 additions & 0 deletions
85
syncer/src/main/java/com/scylladb/alternator/AlternatorAsyncHttpClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.scylladb.alternator; | ||
|
||
import static com.scylladb.alternator.AlternatorHttpClient.FAKE_HOST; | ||
|
||
import java.net.URI; | ||
import java.util.Arrays; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import software.amazon.awssdk.core.internal.http.loader.DefaultSdkAsyncHttpClientBuilder; | ||
import software.amazon.awssdk.http.SdkHttpRequest; | ||
import software.amazon.awssdk.http.async.AsyncExecuteRequest; | ||
import software.amazon.awssdk.http.async.SdkAsyncHttpClient; | ||
import software.amazon.awssdk.utils.AttributeMap; | ||
|
||
class AlternatorAsyncHttpClient implements SdkAsyncHttpClient { | ||
private final AlternatorLiveNodes liveNodes; | ||
private final SdkAsyncHttpClient base; | ||
private final int port; | ||
private final String protocol; | ||
|
||
public AlternatorAsyncHttpClient(SdkAsyncHttpClient base, String protocol, String host, int port) { | ||
liveNodes = AlternatorLiveNodes.create(protocol, Arrays.asList(host), port); | ||
this.base = base; | ||
this.protocol = protocol; | ||
this.port = port; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
base.close(); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Void> execute(AsyncExecuteRequest request) { | ||
SdkHttpRequest.Builder b = request.request().toBuilder(); | ||
b.protocol(protocol).host(liveNodes.nextNode()).port(port).putHeader("Host", Arrays.asList(FAKE_HOST)); | ||
|
||
AsyncExecuteRequest modified = AsyncExecuteRequest.builder().request(b.build()).fullDuplex(request.fullDuplex()) | ||
.metricCollector(request.metricCollector().orElse(null)) | ||
.requestContentPublisher(request.requestContentPublisher()).responseHandler(request.responseHandler()) | ||
.build(); | ||
|
||
return base.execute(modified); | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static Builder builder(URI endpoint) { | ||
return builder().endpoint(endpoint); | ||
} | ||
|
||
public static final class Builder implements SdkAsyncHttpClient.Builder<Builder> { | ||
private String protocol; | ||
private String host; | ||
private int port; | ||
|
||
Builder protocol(String protocol) { | ||
this.protocol = protocol; | ||
return this; | ||
} | ||
|
||
Builder host(String host) { | ||
this.host = host; | ||
return this; | ||
} | ||
|
||
Builder port(int port) { | ||
this.port = port; | ||
return this; | ||
} | ||
|
||
Builder endpoint(URI endpoint) { | ||
return protocol(endpoint.getScheme()).host(endpoint.getHost()).port(endpoint.getPort()); | ||
} | ||
|
||
@Override | ||
public SdkAsyncHttpClient buildWithDefaults(AttributeMap serviceDefaults) { | ||
return new AlternatorAsyncHttpClient( | ||
new DefaultSdkAsyncHttpClientBuilder().buildWithDefaults(serviceDefaults), protocol, host, port); | ||
} | ||
}; | ||
|
||
} |
Oops, something went wrong.