Developing lightweight computation at the DSG edge

Unverified Commit 0777f318 authored by Peter Zeller's avatar Peter Zeller Committed by GitHub
Browse files

Merge pull request #5 from dvasilas/dockerize_gradle_build

Remove Java and Gradle prerequisites
parents f1e444fe 4963d507
Pipeline #15 canceled with stages
......@@ -5,11 +5,12 @@ This is a sample application to demonstrate how to build applications that use [
This tutorial is made for [Antidote Bookstore Tutorial](https://github.com/AntidoteDB/antidote-java-tutorial)
## What you need
* [Java 1.7 or Higher](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
* An IDE for java development
* [Gradle](https://gradle.org/) build tool
* [Docker](https://docs.docker.com/engine/installation/)
* [docker-compose](https://docs.docker.com/compose/install/)
* An IDE for java development
## Clone source code
git clone https://github.com/AntidoteDB/antidote-java-tutorial
## Getting started
This repository is divided into two source directories:
......@@ -19,76 +20,81 @@ This repository is divided into two source directories:
| Note: make sure you have the software requirements listed above before following next steps. |
| --- |
## Interactive Tutorial / Game
### Step 1 : Starting antidote nodes
The following script starts two antidote docker containers and set up the inter-dc replication.
```bash
# in setup/
./start_antidote.sh
```
### Step 2 : Interactive Tutorial / Game
The interactive tutorial is an executable that presents a series of tasks/challenges. Each task has an outcome, SUCCESS or FAIL.
Solving a task allows you to try out the next task.
To try the interactive tutorial:
* Follow steps 1 and 2 bellow, and then:
Open a new shell:
```bash
# in setup/
./tutorial.sh
./tutorial_setup.sh
# build the tutorial
root@tutorial$ ./gradlew build
# run the tutorial executable
root@tutorial$ ./tutorial.sh
```
Notes:
* Solving the interactive tutorial is equivalent to following steps 3, 4 and 5 bellow.
* To reset you progress:
In case you want to reset your progress:
```bash
# in setup/
./stop_antidote.sh
./start_antidote.sh
```
### Step 1: Build Bookstore application
First we need to build the source code of our Bookstore application, we will use Gradle as follows:
```bash
cd bookstore
./gradlew build
```
Note that you will need to rebuild the sources each time you make a change.
More information about Gradle [Here](https://docs.gradle.org/current/userguide/userguide.html)
| Note: Solving the interactive tutorial is equivalent to following steps 3, 4 and 5 bellow. Alternatively, you can skip this step and go directly to step 3.
| --- |
### Step 2 : Starting antidote nodes
The following script starts two antidote docker containers and set up the inter-dc replication.
```bash
# in setup/
./start_antidote.sh
```
### Step 3 : Starting the application
Open two shells:
* In the first one, start the first app:
```bash
# in setup/
./app1.sh
./app1_setup.sh
# build the app code
root@app1$ ./gradlew build
# and start the app
root@app1$ ./app1.sh
# then connect the app to Antidote instance 1:
bookstore@antidote1> connect antidote1 8087
bookstore@antidote1 > connect antidote1 8087
```
* We will do the same for the second app:
```bash
# in setup/
./app2.sh
./app2_setup.sh
# build the app code
root@app2$ ./gradlew build
# and start the app
root@app2$ ./app2.sh
# then connect the app to Antidote instance 2:
bookstore@antidote2> connect antidote2 8087
bookstore@antidote2 > connect antidote2 8087
```
Now we built this configuration:
We have now deployed this configuration:
![Tutorial Figure](./doc/tutorial-figure.png "Tutorial figure")
### Step 4 : Try the following app commands
Some commands are already implemented in the app, lets try them:
~~~~
inc testbucket mycounter
getcounter testbucket mycounter
additem testbucket myset newitem
getset testbucket myset
bookstore@antidote> inc testbucket mycounter
bookstore@antidote> getcounter testbucket mycounter
bookstore@antidote> additem testbucket myset newitem
bookstore@antidote> getset testbucket myset
~~~~
To stop the app:
~~~~
quit
bookstore@antidote> quit
~~~~
You can also try to disconnect Antidote servers to simulate network partitions, commit some concurrent updates, then reconnect to merge CRDTs:
......@@ -101,7 +107,7 @@ You can also try to disconnect Antidote servers to simulate network partitions,
./connect.sh #connect Antidote nodes back
~~~~
To stop Antidote Nodes:
To stop the two Antidote Nodes:
```bash
# in setup/
./stop_antidote.sh
......@@ -113,6 +119,17 @@ We now want to build our Bookstore app. The provided sources are divided into 3
* `DemoCommandsExecutor.java`: this file contains the implementation of the demo commands we have seen in the previous Step. You can use them as examples to implement your own commands.
* `BookCommands.java`: Here is the file where you need to implement Bookstore commands, fill in the methods to add necessary.
The main method is located at bookstore/src/main/java/BookStore.java.
To re-build the app after modifying the source code:
```bash
some_docker_container$ ./gradlew build
```
where `some_docker_container` may be:
* `root@app1` or
* `root@app2` or
* `root@tutorial`
### Resources:
Some useful references:
* [Antidote API Javadoc](https://www.javadoc.io/doc/eu.antidotedb/antidote-java-client/0.3.1)
......
FROM openjdk:12
RUN echo 'PS1="\u@\\h$ "' >> /root/.bashrc
RUN mkdir /code
VOLUME /code
WORKDIR /code
#!/bin/bash
java -jar ./build/libs/bookstore.jar 1
#!/bin/bash
java -jar ./build/libs/bookstore.jar 2
......@@ -289,6 +289,8 @@ public class Tester {
"In this task you will learn to open a connection to an AntidoteDB note.\n" +
"Implement the connect() method. The method should receive as arguments a hostname and a port number,\n" +
"initiates a connection to the corresponding AntidoteDB node, and return the connection object\n" +
"To re-build the application after modifying the source code:\n" +
"root@tutorial$ ./gradlew build\n" +
"================================\n\n" +
"Here is a useful reference for the rest of the tasks:\n" +
"https://www.javadoc.io/doc/eu.antidotedb/antidote-java-client/0.3.0\n";
......
#!/bin/bash
java -jar ./build/libs/bookstore.jar -t
#!/bin/bash
docker-compose run server1
#!/bin/bash
docker build -t client ../bookstore
docker run -ti --rm --name app1 --hostname="app1" -v $(pwd)/../bookstore:/code --network="setup_local1" client /bin/bash
#!/bin/bash
docker-compose run server2
#!/bin/bash
docker build -t client ../bookstore
docker run -ti --rm --name app2 --hostname="app2" -v $(pwd)/../bookstore:/code --network="setup_local2" client /bin/bash
......@@ -26,42 +26,6 @@ services:
- interdc
- local2
server1:
image: openjdk:12
volumes:
- ../bookstore/build/libs:/code
command: "java -jar bookstore.jar 1"
working_dir: /code
cap_add:
- NET_ADMIN
networks:
- local1
server2:
image: openjdk:12
volumes:
- ../bookstore/build/libs:/code
command: "java -jar bookstore.jar 2"
working_dir: /code
cap_add:
- NET_ADMIN
networks:
- local2
server_tutorial:
image: java:8
volumes:
- ../bookstore/build/libs:/code
command: "java -jar bookstore.jar -t"
working_dir: /code
environment:
- ANTIDOTE_TUTORIAL_SAVE=0
cap_add:
- NET_ADMIN
networks:
- local1
- local2
link:
image: erlang:19
volumes:
......
#!/bin/bash
docker-compose run server_tutorial
#!/bin/bash
docker build -t client ../bookstore
docker create -t --rm --name tutorial --hostname="tutorial" -e "ANTIDOTE_TUTORIAL_SAVE=0" -v $(pwd)/../bookstore:/code client
docker network connect setup_local1 tutorial
docker network connect setup_local2 tutorial
docker start tutorial
docker exec -ti tutorial /bin/bash
docker stop tutorial
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment