Skip to content

Commit

Permalink
fatjar
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio Esposito committed Aug 18, 2017
1 parent 89d471a commit 68f11af
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 14 deletions.
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
# Survey Gorilla
Survey monkey clone using vertx

## Todo

- Statistics
- Event sourcing
- Docker

## Components

survey-api
API for all frontends

survey-common
Shared VOs used by all services

survey-write
Handle all write-side requests (POST/PUT/DELETE)

survey-read
Answer all read-side requests (GET)

survey-write
survey-event
Log all events happening on the system


## How to run

`docker-compose up`
`gradle clean build`

`java -jar survey-api/build/libs/survey-api-1.0-SNAPSHOT.jar`

`java -jar survey-read/build/libs/survey-read-1.0-SNAPSHOT.jar`

`java -jar survey-write/build/libs/survey-write-1.0-SNAPSHOT.jar`

`java -jar survey-events/build/libs/survey-events-1.0-SNAPSHOT.jar`


## How to use

`curl -X GET \
http://localhost:8080/api/polls`
Expand Down
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
group 'gorilla'
version '1.0-SNAPSHOT'

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
}
}

subprojects {

apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'

sourceCompatibility = 1.8

Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ include 'survey-write'
include 'survey-api'
include 'survey-common'
include 'survey-api'
include 'survey-events'

16 changes: 16 additions & 0 deletions survey-api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
apply plugin: 'application'

dependencies {
compile project(":survey-common")
}

shadowJar {
classifier = 'fat'
mainClassName = 'com.surveygorilla.api.MainApi'

/*manifest {
attributes 'Main-Verticle': 'com.surveygorilla.api.SurveyApiVerticle'
}*/
mergeServiceFiles {
include 'META-INF/survey-api/io.vertx.core.spi.VerticleFactory'
}
}

build.dependsOn(shadowJar)
11 changes: 9 additions & 2 deletions survey-common/src/main/java/com/surveygorilla/common/Poll.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ public class Poll {

private Map<Integer, Integer> answers;

public Poll(Integer pollID, String question, Map<Integer, String> options, Map<Integer, Integer> answers) throws PollCreationException {
private Map<Integer, Double> stats;

if (pollID == null || question == null || options == null || answers == null) {
public Poll(Integer pollID, String question, Map<Integer, String> options, Map<Integer, Integer> answers, Map<Integer, Double> stats) throws PollCreationException {

if (pollID == null || question == null || options == null || answers == null || stats == null) {
throw new PollCreationException("Unable to create a new poll");
}

this.pollID = pollID;
this.question = question;
this.options = options;
this.answers = answers;
this.stats = stats;
}

public Integer getPollID() {
Expand All @@ -44,4 +47,8 @@ public Map<Integer, String> getOptions() {
public Map<Integer, Integer> getAnswers() {
return answers;
}

public Map<Integer, Double> getStats() {
return stats;
}
}
18 changes: 18 additions & 0 deletions survey-events/src/main/java/com/surveygorilla/event/MainEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.surveygorilla.event;

import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;

/**
* Created by fabio.pires on 18.08.17.
*/
public class MainEvent {
public static void main(String[] args) {
Vertx.clusteredVertx(new VertxOptions().setClustered(true), cluster -> {
if (cluster.succeeded()) {
final Vertx vertx = cluster.result();
vertx.deployVerticle(SurveyEventVerticle.class.getName());
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.surveygorilla.event;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;

/**
* Created by fabio.pires on 18.08.17.
*/
public class SurveyEventVerticle extends AbstractVerticle {

private final Logger logger = LoggerFactory.getLogger(this.getClass().getName());

@Override
public void start(Future<Void> start) throws Exception {
logger.info("SurveyEventVerticle started");
vertx.eventBus().addInterceptor(message -> {
logger.info("NEW EVENT:", message.message().body());
});

start.complete();
}
}
17 changes: 17 additions & 0 deletions survey-read/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
apply plugin: 'application'

dependencies {
compile project(":survey-common")
}

shadowJar {
classifier = 'fat'
mainClassName = 'com.surveygorilla.read.MainRead'
/*
manifest {
Attributes 'Main-Verticle': 'com.surveygorilla.read.SurveyReadVerticle'
}
*/
mergeServiceFiles {
include 'META-INF/survey-api/io.vertx.core.spi.VerticleFactory'
}
}

build.dependsOn(shadowJar)
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ private Handler<Message<String>> pollCreatedEventListener() {
PollCreatedEvent.class);

try {
polls.put(pollCreatedEvent.getPollID(), new Poll(pollCreatedEvent.getPollID(), pollCreatedEvent.getQuestion(), pollCreatedEvent.getOptions(), new HashMap<>()));
polls.put(
pollCreatedEvent.getPollID(),
new Poll(
pollCreatedEvent.getPollID(),
pollCreatedEvent.getQuestion(),
pollCreatedEvent.getOptions(),
new HashMap<>(),
new HashMap<>()
));
} catch (PollCreationException e) {
e.printStackTrace();
}
Expand Down
16 changes: 16 additions & 0 deletions survey-write/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
apply plugin: 'application'

dependencies {
compile project(":survey-common")
}

shadowJar {
classifier = 'fat'
mainClassName = 'com.surveygorilla.write.MainWrite'

/*manifest {
Attributes 'Main-Verticle': 'com.surveygorilla.write.SurveyWriteVerticle'
}*/
mergeServiceFiles {
include 'META-INF/survey-api/io.vertx.core.spi.VerticleFactory'
}
}

build.dependsOn(shadowJar)
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;


/**
Expand Down Expand Up @@ -52,10 +53,14 @@ private Handler<Message<Object>> addPoll() {
count.addAndGet(1),
createPollCommand.getQuestion(),
createPollCommand.getOptions(),
new HashMap<>(),
new HashMap<>()
);

createPollCommand.getOptions().keySet().forEach(o -> p.getAnswers().merge(o, 0, Integer::sum));
createPollCommand.getOptions().keySet().forEach(o -> {
p.getAnswers().merge(o, 0, Integer::sum);
p.getStats().merge(o, 0.0, Double::sum);
});

polls.put(count.get(), p);

Expand All @@ -82,8 +87,13 @@ private Handler<Message<Object>> submitAnswer() {

Poll p = polls.get(submitAnswerCommand.getPollID());
if (p != null){
submitAnswerCommand.getAnswers().forEach(a -> p.getAnswers().merge(a, 1, Integer::sum));
polls.put(p.getPollID(), p);
submitAnswerCommand.getAnswers().forEach(a -> {
p.getAnswers().merge(a, 1, Integer::sum);
});

// TODO stats

polls.put(p.getPollID(), p);

final AnswerSubmitted answerSubmitted = new AnswerSubmitted(p.getPollID(), p.getAnswers());
vertx.eventBus().send("answerSubmittedEvent", Json.encode(answerSubmitted));
Expand Down

0 comments on commit 68f11af

Please sign in to comment.