Skip to content

Commit 71e28e0

Browse files
author
Michael Wunderlich
committed
Scorekeep web API
1 parent 629ce7e commit 71e28e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1720
-2
lines changed

.ebextensions/dev.config

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
option_settings:
2+
aws:autoscaling:updatepolicy:rollingupdate:
3+
RollingUpdateEnabled: "false"
4+
aws:elasticbeanstalk:command:
5+
DeploymentPolicy: AllAtOnce
6+
IgnoreHealthCheck: "true"
7+
aws:elasticbeanstalk:monitoring:
8+
Automatically Terminate Unhealthy Instances: "false"
9+
commands:
10+
01-clear-logs:
11+
command: cd /var/log/ && rm nginx/* && mv *.gz rotated
12+
ignoreErrors: true
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
Resources:
2+
UserTable:
3+
Type: AWS::DynamoDB::Table
4+
Properties:
5+
TableName: scorekeep-user
6+
KeySchema:
7+
HashKeyElement: {AttributeName: id, AttributeType: S}
8+
ProvisionedThroughput: {ReadCapacityUnits: 5, WriteCapacityUnits: 5}
9+
SessionTable:
10+
Type: AWS::DynamoDB::Table
11+
Properties:
12+
TableName: scorekeep-session
13+
KeySchema:
14+
HashKeyElement: {AttributeName: id, AttributeType: S}
15+
ProvisionedThroughput: {ReadCapacityUnits: 5, WriteCapacityUnits: 5}
16+
GameTable:
17+
Type: AWS::DynamoDB::Table
18+
Properties:
19+
TableName: scorekeep-game
20+
AttributeDefinitions:
21+
- AttributeName: "id"
22+
AttributeType: "S"
23+
- AttributeName: "session"
24+
AttributeType: "S"
25+
KeySchema:
26+
- AttributeName: "id"
27+
KeyType: "HASH"
28+
GlobalSecondaryIndexes:
29+
- IndexName: "session-index"
30+
KeySchema:
31+
- AttributeName: "session"
32+
KeyType: "HASH"
33+
ProvisionedThroughput: {ReadCapacityUnits: 5, WriteCapacityUnits: 5}
34+
Projection: { ProjectionType: ALL }
35+
ProvisionedThroughput: {ReadCapacityUnits: 5, WriteCapacityUnits: 5}
36+
MoveTable:
37+
Type: AWS::DynamoDB::Table
38+
Properties:
39+
TableName: scorekeep-move
40+
AttributeDefinitions:
41+
- AttributeName: "id"
42+
AttributeType: "S"
43+
- AttributeName: "game"
44+
AttributeType: "S"
45+
KeySchema:
46+
- AttributeName: "id"
47+
KeyType: "HASH"
48+
GlobalSecondaryIndexes:
49+
- IndexName: "game-index"
50+
KeySchema:
51+
- AttributeName: "game"
52+
KeyType: "HASH"
53+
ProvisionedThroughput: {ReadCapacityUnits: 5, WriteCapacityUnits: 5}
54+
Projection: { ProjectionType: ALL }
55+
ProvisionedThroughput: {ReadCapacityUnits: 5, WriteCapacityUnits: 5}
56+
StateTable:
57+
Type: AWS::DynamoDB::Table
58+
Properties:
59+
TableName: scorekeep-state
60+
AttributeDefinitions:
61+
- AttributeName: "id"
62+
AttributeType: "S"
63+
- AttributeName: "game"
64+
AttributeType: "S"
65+
KeySchema:
66+
- AttributeName: "id"
67+
KeyType: "HASH"
68+
GlobalSecondaryIndexes:
69+
- IndexName: "game-index"
70+
KeySchema:
71+
- AttributeName: "game"
72+
KeyType: "HASH"
73+
ProvisionedThroughput: {ReadCapacityUnits: 5, WriteCapacityUnits: 5}
74+
Projection: { ProjectionType: ALL }
75+
ProvisionedThroughput: {ReadCapacityUnits: 5, WriteCapacityUnits: 5}
76+

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.gradle/*
2+
build/*
3+
*.DS_Store
4+
# Elastic Beanstalk Files
5+
.elasticbeanstalk/*
6+
!.elasticbeanstalk/*.cfg.yml
7+
!.elasticbeanstalk/*.global.yml

Buildfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build: gradle build

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: java -Dserver.port=5000 -jar build/libs/scorekeep-api-0.1.0.jar

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
# eb-java-scorekeep
2-
Sample Java JSON web API in Spring that provides an HTTP interface for create and managing game sessions and users.
1+
Create a Java 8 SE environment in Elastic Beanstalk
2+
Add DynamoDB permissions to your instance profile (aws-elasticbeanstalk-ec2-role): [IAM console](https://console.aws.amazon.com/iam/home#roles)
3+
Deploy the application to your environment.

bin/test-api.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
API=.us-east-1.elasticbeanstalk.com
3+
4+
# for (( c=1; c<=5; c++ ))
5+
for (( ; ; ))
6+
do
7+
echo "Creating users, "
8+
USER1ID=$(curl --silent -X POST $API/user | jq -r .id)
9+
USER2ID=$(curl --silent -X POST $API/user | jq -r .id)
10+
echo "session, "
11+
SESSIONID=$(curl --silent -X POST $API/session | jq -r .id)
12+
echo "game, "
13+
GAMEID=$(curl --silent -X POST $API/game/$SESSIONID | jq -r .id)
14+
echo "configuring game, "
15+
curl --silent -X POST $API/game/$SESSIONID/$GAMEID/users -H "Content-Type: application/json" --data "[\"$USER1ID\",\"$USER2ID\"]"
16+
curl --silent -X PUT $API/game/$SESSIONID/$GAMEID/rules/102
17+
curl --silent -X PUT $API/game/$SESSIONID/$GAMEID/name/tic-tac-toe-test
18+
EPOCH=$(date +%s)
19+
curl --silent -X PUT $API/game/$SESSIONID/$GAMEID/starttime/$EPOCH
20+
echo "playing game, "
21+
curl --silent -X POST $API/move/$SESSIONID/$GAMEID/$USER1ID -H "Content-Type: text/plain" --data "X1" >/dev/null
22+
curl --silent -X POST $API/move/$SESSIONID/$GAMEID/$USER2ID -H "Content-Type: text/plain" --data "O2" >/dev/null
23+
curl --silent -X POST $API/move/$SESSIONID/$GAMEID/$USER1ID -H "Content-Type: text/plain" --data "X3" >/dev/null
24+
curl --silent -X POST $API/move/$SESSIONID/$GAMEID/$USER2ID -H "Content-Type: text/plain" --data "O4" >/dev/null
25+
curl --silent -X POST $API/move/$SESSIONID/$GAMEID/$USER1ID -H "Content-Type: text/plain" --data "X5" >/dev/null
26+
curl --silent -X POST $API/move/$SESSIONID/$GAMEID/$USER2ID -H "Content-Type: text/plain" --data "O6" >/dev/null
27+
curl --silent -X POST $API/move/$SESSIONID/$GAMEID/$USER1ID -H "Content-Type: text/plain" --data "X7" >/dev/null
28+
curl --silent -X POST $API/move/$SESSIONID/$GAMEID/$USER2ID -H "Content-Type: text/plain" --data "O8" >/dev/null
29+
curl --silent -X POST $API/move/$SESSIONID/$GAMEID/$USER1ID -H "Content-Type: text/plain" --data "X9" >/dev/null
30+
echo "ending game, "
31+
EPOCH=$(date +%s)
32+
curl --silent -X PUT $API/game/$SESSIONID/$GAMEID/endtime/$EPOCH
33+
echo "game complete."
34+
curl $API/game/$SESSIONID/$GAMEID
35+
# Cleanup
36+
echo "cleaning up"
37+
curl -X DELETE $API/game/$SESSIONID/$GAMEID
38+
curl -X DELETE $API/session/$SESSIONID
39+
curl -X DELETE $API/user/$USER1ID
40+
curl -X DELETE $API/user/$USER2ID
41+
echo ""
42+
done
43+
echo ""

build.gradle

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
buildscript {
2+
repositories {
3+
mavenCentral()
4+
}
5+
dependencies {
6+
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE")
7+
classpath("io.spring.gradle:dependency-management-plugin:0.5.4.RELEASE")
8+
}
9+
}
10+
11+
apply plugin: 'java'
12+
apply plugin: 'eclipse'
13+
apply plugin: 'idea'
14+
apply plugin: 'spring-boot'
15+
apply plugin: 'io.spring.dependency-management'
16+
17+
jar {
18+
baseName = 'scorekeep-api'
19+
version = '0.1.0'
20+
}
21+
22+
repositories {
23+
mavenCentral()
24+
}
25+
26+
sourceCompatibility = 1.8
27+
targetCompatibility = 1.8
28+
29+
dependencies {
30+
compile("org.springframework.boot:spring-boot-starter-web")
31+
testCompile('org.springframework.boot:spring-boot-starter-test')
32+
compile('com.amazonaws:aws-java-sdk-dynamodb')
33+
testCompile group: 'junit', name: 'junit', version: '4.11'
34+
}
35+
36+
dependencyManagement {
37+
imports {
38+
mavenBom('com.amazonaws:aws-java-sdk-bom:1.11.25')
39+
}
40+
}
41+
task wrapper(type: Wrapper) {
42+
gradleVersion = '2.3'
43+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package scorekeep;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Application {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(Application.class, args);
11+
}
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package scorekeep;
2+
import com.amazonaws.regions.Regions;
3+
4+
public class Constants {
5+
public static final String SESSION_TABLE = "scorekeep-session";
6+
public static final String GAME_TABLE = "scorekeep-game";
7+
public static final String USER_TABLE = "scorekeep-user";
8+
public static final String MOVE_TABLE = "scorekeep-move";
9+
public static final String STATE_TABLE = "scorekeep-state";
10+
public static final Regions REGION = Regions.US_EAST_1;
11+
}

0 commit comments

Comments
 (0)