Skip to content

Commit

Permalink
Merge pull request #89 from IanMeyers/master
Browse files Browse the repository at this point in the history
Version .9.7.0
  • Loading branch information
IanMeyers authored Jun 25, 2020
2 parents 264ec43 + bb07114 commit 0194f56
Show file tree
Hide file tree
Showing 17 changed files with 369 additions and 350 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,24 @@ The Kinesis Autoscaling WAR can be deployed as an Elastic Beanstalk application,

![AutoscalingGraph](https://s3-eu-west-1.amazonaws.com/meyersi-ire-aws/KinesisScalingUtility/img/KinesisAutoscalingGraph.png)

To get started, create a new Elastic Beanstalk application which is a Web Server with a Tomcat predefined configuration. Deploy the WAR by uploading from your local GitHub copy of [dist/KinesisAutoscaling-.9.6.0.war](dist/KinesisAutoscaling-.9.6.0.war), or using the following S3 URLs:
To get started, create a new Elastic Beanstalk application which is a Web Server with a Tomcat predefined configuration. Deploy the WAR by uploading from your local GitHub copy of [dist/KinesisAutoscaling-.9.7.0.war](dist/KinesisAutoscaling-.9.7.0.war), or using the following S3 URLs:

| region| S3 Path |
| ----- | ------- |
| ap-northeast-1 | https://s3.ap-northeast-1.amazonaws.com/awslabs-code-ap-northeast-1/KinesisAutoscaling/KinesisAutoscaling-.9.6.0.war |
| ap-northeast-2 | https://s3.ap-northeast-2.amazonaws.com/awslabs-code-ap-northeast-2/KinesisAutoscaling/KinesisAutoscaling-.9.6.0.war |
| ap-south-1 | https://s3.ap-south-1.amazonaws.com/awslabs-code-ap-south-1/KinesisAutoscaling/KinesisAutoscaling-.9.6.0.war |
| ap-southeast-1 | https://s3.ap-southeast-1.amazonaws.com/awslabs-code-ap-southeast-1/KinesisAutoscaling/KinesisAutoscaling-.9.6.0.war |
| ap-southeast-2 | https://s3.ap-southeast-2.amazonaws.com/awslabs-code-ap-southeast-2/KinesisAutoscaling/KinesisAutoscaling-.9.6.0.war |
| ca-central-1 | https://s3.ca-central-1.amazonaws.com/awslabs-code-ca-central-1/KinesisAutoscaling/KinesisAutoscaling-.9.6.0.war |
| eu-central-1 | https://s3.eu-central-1.amazonaws.com/awslabs-code-eu-central-1/KinesisAutoscaling/KinesisAutoscaling-.9.6.0.war |
| eu-west-1 | https://s3.eu-west-1.amazonaws.com/awslabs-code-eu-west-1/KinesisAutoscaling/KinesisAutoscaling-.9.6.0.war |
| eu-west-2 | https://s3.eu-west-2.amazonaws.com/awslabs-code-eu-west-2/KinesisAutoscaling/KinesisAutoscaling-.9.6.0.war |
| sa-east-1 | https://s3.sa-east-1.amazonaws.com/awslabs-code-sa-east-1/KinesisAutoscaling/KinesisAutoscaling-.9.6.0.war |
| us-east-1 | https://s3.us-east-1.amazonaws.com/awslabs-code-us-east-1/KinesisAutoscaling/KinesisAutoscaling-.9.6.0.war |
| us-east-2 | https://s3.us-east-2.amazonaws.com/awslabs-code-us-east-2/KinesisAutoscaling/KinesisAutoscaling-.9.6.0.war |
| us-west-1 | https://s3.us-west-1.amazonaws.com/awslabs-code-us-west-1/KinesisAutoscaling/KinesisAutoscaling-.9.6.0.war |
| us-west-2 | https://s3.us-west-2.amazonaws.com/awslabs-code-us-west-2/KinesisAutoscaling/KinesisAutoscaling-.9.6.0.war |
| ap-northeast-1 | https://s3.ap-northeast-1.amazonaws.com/awslabs-code-ap-northeast-1/KinesisAutoscaling/KinesisAutoscaling-.9.7.0.war |
| ap-northeast-2 | https://s3.ap-northeast-2.amazonaws.com/awslabs-code-ap-northeast-2/KinesisAutoscaling/KinesisAutoscaling-.9.7.0.war |
| ap-south-1 | https://s3.ap-south-1.amazonaws.com/awslabs-code-ap-south-1/KinesisAutoscaling/KinesisAutoscaling-.9.7.0.war |
| ap-southeast-1 | https://s3.ap-southeast-1.amazonaws.com/awslabs-code-ap-southeast-1/KinesisAutoscaling/KinesisAutoscaling-.9.7.0.war |
| ap-southeast-2 | https://s3.ap-southeast-2.amazonaws.com/awslabs-code-ap-southeast-2/KinesisAutoscaling/KinesisAutoscaling-.9.7.0.war |
| ca-central-1 | https://s3.ca-central-1.amazonaws.com/awslabs-code-ca-central-1/KinesisAutoscaling/KinesisAutoscaling-.9.7.0.war |
| eu-central-1 | https://s3.eu-central-1.amazonaws.com/awslabs-code-eu-central-1/KinesisAutoscaling/KinesisAutoscaling-.9.7.0.war |
| eu-west-1 | https://s3.eu-west-1.amazonaws.com/awslabs-code-eu-west-1/KinesisAutoscaling/KinesisAutoscaling-.9.7.0.war |
| eu-west-2 | https://s3.eu-west-2.amazonaws.com/awslabs-code-eu-west-2/KinesisAutoscaling/KinesisAutoscaling-.9.7.0.war |
| sa-east-1 | https://s3.sa-east-1.amazonaws.com/awslabs-code-sa-east-1/KinesisAutoscaling/KinesisAutoscaling-.9.7.0.war |
| us-east-1 | https://s3.us-east-1.amazonaws.com/awslabs-code-us-east-1/KinesisAutoscaling/KinesisAutoscaling-.9.7.0.war |
| us-east-2 | https://s3.us-east-2.amazonaws.com/awslabs-code-us-east-2/KinesisAutoscaling/KinesisAutoscaling-.9.7.0.war |
| us-west-1 | https://s3.us-west-1.amazonaws.com/awslabs-code-us-west-1/KinesisAutoscaling/KinesisAutoscaling-.9.7.0.war |
| us-west-2 | https://s3.us-west-2.amazonaws.com/awslabs-code-us-west-2/KinesisAutoscaling/KinesisAutoscaling-.9.7.0.war |

Once deployed, you must configure the Autoscaling engine by providing a JSON configuration file on an HTTP or S3 URL. The structure of this configuration file is as follows:

Expand Down
2 changes: 1 addition & 1 deletion bin/distribute.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
# set -x

ver=.9.6.0
ver=.9.7.0

# publish war to regional buckets
for r in `aws ec2 describe-regions --query Regions[*].RegionName --output text`; do aws s3 cp ../dist/KinesisAutoscaling-$ver.war s3://awslabs-code-$r/KinesisAutoscaling/ --acl public-read --region $r; done
72 changes: 55 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.amazonaws</groupId>
<artifactId>kinesis-scaling-utils</artifactId>
<version>.9.6.0</version>
<version>.9.7.0</version>
<properties>
<sdk-version>1.11.452</sdk-version>
<sdk-version>2.13.39</sdk-version>
</properties>
<licenses>
<license>
Expand All @@ -22,6 +23,7 @@
<includes>
<include>README</include>
<include>*.properties</include>
<include>*.xml</include>
</includes>
</resource>
</resources>
Expand Down Expand Up @@ -95,28 +97,34 @@
</build>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sdk-core</artifactId>
<version>${sdk-version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-kinesis</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>kinesis</artifactId>
<version>${sdk-version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>${sdk-version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sns</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sns</artifactId>
<version>${sdk-version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-cloudwatch</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>cloudwatch</artifactId>
<version>${sdk-version}</version>
</dependency>
<dependency>
Expand All @@ -133,7 +141,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>LATEST</version>
<version>2.7</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
Expand All @@ -152,9 +160,39 @@
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>http-client-spi</artifactId>
<version>2.13.39</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
</dependencies>
<url>https://github.com/awslabs/amazon-kinesis-scaling-utils</url>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/ScalingClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.kinesis.scaling.ScaleDirection;
import com.amazonaws.services.kinesis.scaling.ScalingCompletionStatus;
import com.amazonaws.services.kinesis.scaling.ScalingOperationReport;
import com.amazonaws.services.kinesis.scaling.StreamScaler;
import com.amazonaws.services.kinesis.scaling.StreamScaler.ScalingAction;

import software.amazon.awssdk.regions.Region;

/**
* Class which provides a host environment interface to working with the Kinesis
* Scaling Utility<br>
Expand Down Expand Up @@ -76,7 +76,7 @@ public class ScalingClient {

private String shardId;

private Region region = Region.getRegion(Regions.US_EAST_1);
private Region region = Region.US_EAST_1;

private ScalingAction scalingAction;

Expand Down Expand Up @@ -112,7 +112,7 @@ private void loadParams() throws Exception {
}

if (System.getProperty(REGION_PARAM) != null) {
this.region = Region.getRegion(Regions.fromName(System.getProperty(REGION_PARAM)));
this.region = Region.of(System.getProperty(REGION_PARAM));
}

if (System.getProperty(WAIT_FOR_COMPLETION) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import java.math.BigInteger;
import java.util.Map;

import com.amazonaws.services.kinesis.AmazonKinesisClient;
import com.amazonaws.services.kinesis.model.LimitExceededException;
import com.amazonaws.services.kinesis.model.ResourceInUseException;
import software.amazon.awssdk.services.kinesis.KinesisClient;

/**
* AdjacentShards are a transfer object for maintaining references between an
Expand All @@ -27,8 +25,8 @@ public class AdjacentShards {

public AdjacentShards(String streamName, ShardHashInfo lower, ShardHashInfo higher) throws Exception {
// ensure that the shards are adjacent
if (!new BigInteger(higher.getShard().getHashKeyRange().getStartingHashKey())
.subtract(new BigInteger(lower.getShard().getHashKeyRange().getEndingHashKey()))
if (!new BigInteger(higher.getShard().hashKeyRange().startingHashKey())
.subtract(new BigInteger(lower.getShard().hashKeyRange().endingHashKey()))
.equals(new BigInteger("1"))) {
throw new Exception("Shards are not Adjacent");
}
Expand All @@ -52,15 +50,15 @@ protected ShardHashInfo getHigherShard() {
* @return
* @throws Exception
*/
protected ShardHashInfo doMerge(AmazonKinesisClient kinesisClient, String currentHighestShardId) throws Exception {
protected ShardHashInfo doMerge(KinesisClient kinesisClient, String currentHighestShardId) throws Exception {
StreamScalingUtils.mergeShards(kinesisClient, streamName, this.lowerShard, this.higherShard, true);

Map<String, ShardHashInfo> openShards = StreamScalingUtils.getOpenShards(kinesisClient, streamName,
currentHighestShardId);

for (ShardHashInfo info : openShards.values()) {
if (lowerShard.getShardId().equals(info.getShard().getParentShardId())
&& higherShard.getShardId().equals(info.getShard().getAdjacentParentShardId())) {
if (lowerShard.getShardId().equals(info.getShard().parentShardId())
&& higherShard.getShardId().equals(info.getShard().adjacentParentShardId())) {
return new ShardHashInfo(streamName, info.getShard());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
import java.text.NumberFormat;
import java.util.Map;

import com.amazonaws.services.kinesis.AmazonKinesisClient;
import com.amazonaws.services.kinesis.model.Shard;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import software.amazon.awssdk.services.kinesis.KinesisClient;
import software.amazon.awssdk.services.kinesis.model.Shard;

/**
* Immutable transfer object containing enhanced metadata about Shards in a
* Stream, as well as utility methods for working with a Stream of Shards
Expand Down Expand Up @@ -53,8 +54,8 @@ public ShardHashInfo(String streamName, Shard shard) {
}
this.shard = shard;
this.streamName = streamName;
this.endHash = new BigInteger(shard.getHashKeyRange().getEndingHashKey());
this.startHash = new BigInteger(shard.getHashKeyRange().getStartingHashKey());
this.endHash = new BigInteger(shard.hashKeyRange().endingHashKey());
this.startHash = new BigInteger(shard.hashKeyRange().startingHashKey());
this.hashWidth = getWidth(this.startHash, this.endHash);
this.pctOfKeyspace = getPctOfKeyspace(this.hashWidth);
}
Expand All @@ -74,7 +75,7 @@ public static Double getPctOfKeyspace(BigInteger hashWidth) {

@JsonProperty("shardID")
protected String getShardId() {
return this.shard.getShardId();
return this.shard.shardId();
}

protected Shard getShard() {
Expand Down Expand Up @@ -125,7 +126,7 @@ public String getStreamName() {
* @return
* @throws Exception
*/
public AdjacentShards doSplit(AmazonKinesisClient kinesisClient, double targetPct, String currentHighestShardId)
public AdjacentShards doSplit(KinesisClient kinesisClient, double targetPct, String currentHighestShardId)
throws Exception {
BigInteger targetHash = getHashAtPctOffset(targetPct);

Expand All @@ -140,8 +141,8 @@ public AdjacentShards doSplit(AmazonKinesisClient kinesisClient, double targetPc
currentHighestShardId);

for (ShardHashInfo info : openShards.values()) {
if (!info.getShard().getShardId().equals(this.shard.getShardId())) {
if (info.getShard().getHashKeyRange().getStartingHashKey().equals(targetHash.toString())) {
if (!info.getShard().shardId().equals(this.shard.shardId())) {
if (info.getShard().hashKeyRange().startingHashKey().equals(targetHash.toString())) {
higherShard = new ShardHashInfo(this.streamName, info.getShard());
break;
} else {
Expand Down
Loading

0 comments on commit 0194f56

Please sign in to comment.