fixed multiple bugs & updated cicd workflows
This commit is contained in:
parent
5400798e9c
commit
1c4da28480
|
@ -56,20 +56,20 @@ services:
|
||||||
- "traefik.http.routers.tapas-auction-house.entryPoints=web,websecure"
|
- "traefik.http.routers.tapas-auction-house.entryPoints=web,websecure"
|
||||||
- "traefik.http.routers.tapas-auction-house.tls.certresolver=le"
|
- "traefik.http.routers.tapas-auction-house.tls.certresolver=le"
|
||||||
|
|
||||||
assignment:
|
roster:
|
||||||
image: openjdk
|
image: openjdk
|
||||||
command: "java -jar /data/assignment-0.0.1-SNAPSHOT.jar"
|
command: "java -jar /data/roster-0.0.1-SNAPSHOT.jar"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
volumes:
|
volumes:
|
||||||
- ./:/data/
|
- ./:/data/
|
||||||
labels:
|
labels:
|
||||||
- "traefik.enable=true"
|
- "traefik.enable=true"
|
||||||
- "traefik.http.routers.assignment.rule=Host(`assignment.${PUB_IP}.nip.io`)"
|
- "traefik.http.routers.roster.rule=Host(`roster.${PUB_IP}.nip.io`)"
|
||||||
- "traefik.http.routers.assignment.service=assignment"
|
- "traefik.http.routers.roster.service=roster"
|
||||||
- "traefik.http.services.assignment.loadbalancer.server.port=8082"
|
- "traefik.http.services.roster.loadbalancer.server.port=8082"
|
||||||
- "traefik.http.routers.assignment.tls=true"
|
- "traefik.http.routers.roster.tls=true"
|
||||||
- "traefik.http.routers.assignment.entryPoints=web,websecure"
|
- "traefik.http.routers.roster.entryPoints=web,websecure"
|
||||||
- "traefik.http.routers.assignment.tls.certresolver=le"
|
- "traefik.http.routers.roster.tls.certresolver=le"
|
||||||
|
|
||||||
executor-pool:
|
executor-pool:
|
||||||
image: openjdk
|
image: openjdk
|
||||||
|
@ -86,38 +86,38 @@ services:
|
||||||
- "traefik.http.routers.executor-pool.entryPoints=web,websecure"
|
- "traefik.http.routers.executor-pool.entryPoints=web,websecure"
|
||||||
- "traefik.http.routers.executor-pool.tls.certresolver=le"
|
- "traefik.http.routers.executor-pool.tls.certresolver=le"
|
||||||
|
|
||||||
executor1:
|
executor-computation:
|
||||||
image: openjdk
|
image: openjdk
|
||||||
command: "java -jar /data/executor1-0.0.1-SNAPSHOT.jar"
|
command: "java -jar /data/executor-computation-0.0.1-SNAPSHOT.jar"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
depends_on:
|
depends_on:
|
||||||
- executor-pool
|
- executor-pool
|
||||||
- assignment
|
- roster
|
||||||
volumes:
|
volumes:
|
||||||
- ./:/data/
|
- ./:/data/
|
||||||
labels:
|
labels:
|
||||||
- "traefik.enable=true"
|
- "traefik.enable=true"
|
||||||
- "traefik.http.routers.executor1.rule=Host(`executor1.${PUB_IP}.nip.io`)"
|
- "traefik.http.routers.executor-computation.rule=Host(`executor-computation.${PUB_IP}.nip.io`)"
|
||||||
- "traefik.http.routers.executor1.service=executor1"
|
- "traefik.http.routers.executor-computation.service=executor-computation"
|
||||||
- "traefik.http.services.executor1.loadbalancer.server.port=8084"
|
- "traefik.http.services.executor-computation.loadbalancer.server.port=8084"
|
||||||
- "traefik.http.routers.executor1.tls=true"
|
- "traefik.http.routers.executor-computation.tls=true"
|
||||||
- "traefik.http.routers.executor1.entryPoints=web,websecure"
|
- "traefik.http.routers.executor-computation.entryPoints=web,websecure"
|
||||||
- "traefik.http.routers.executor1.tls.certresolver=le"
|
- "traefik.http.routers.executor-computation.tls.certresolver=le"
|
||||||
|
|
||||||
executor2:
|
executor-robot:
|
||||||
image: openjdk
|
image: openjdk
|
||||||
command: "java -jar /data/executor2-0.0.1-SNAPSHOT.jar"
|
command: "java -jar /data/executor-robot-0.0.1-SNAPSHOT.jar"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
depends_on:
|
depends_on:
|
||||||
- executor-pool
|
- executor-pool
|
||||||
- assignment
|
- roster
|
||||||
volumes:
|
volumes:
|
||||||
- ./:/data/
|
- ./:/data/
|
||||||
labels:
|
labels:
|
||||||
- "traefik.enable=true"
|
- "traefik.enable=true"
|
||||||
- "traefik.http.routers.executor2.rule=Host(`executor2.${PUB_IP}.nip.io`)"
|
- "traefik.http.routers.executor-robot.rule=Host(`executor-robot.${PUB_IP}.nip.io`)"
|
||||||
- "traefik.http.routers.executor2.service=executor2"
|
- "traefik.http.routers.executor-robot.service=executor-robot"
|
||||||
- "traefik.http.services.executor2.loadbalancer.server.port=8085"
|
- "traefik.http.services.executor-robot.loadbalancer.server.port=8085"
|
||||||
- "traefik.http.routers.executor2.tls=true"
|
- "traefik.http.routers.executor-robot.tls=true"
|
||||||
- "traefik.http.routers.executor2.entryPoints=web,websecure"
|
- "traefik.http.routers.executor-robot.entryPoints=web,websecure"
|
||||||
- "traefik.http.routers.executor2.tls.certresolver=le"
|
- "traefik.http.routers.executor-robot.tls.certresolver=le"
|
||||||
|
|
29
.github/workflows/build-and-deploy.yml
vendored
29
.github/workflows/build-and-deploy.yml
vendored
|
@ -33,30 +33,33 @@ jobs:
|
||||||
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
||||||
restore-keys: ${{ runner.os }}-m2
|
restore-keys: ${{ runner.os }}-m2
|
||||||
|
|
||||||
- name: Build with Maven
|
- name: Build common library
|
||||||
run: mvn -f assignment/pom.xml --batch-mode --update-snapshots verify
|
run: mvn -f common/pom.xml --batch-mode --update-snapshots install
|
||||||
- run: cp ./assignment/target/assignment-0.0.1-SNAPSHOT.jar ./target
|
|
||||||
|
|
||||||
- name: Build with Maven
|
- name: Build roster service
|
||||||
|
run: mvn -f roster/pom.xml --batch-mode --update-snapshots verify
|
||||||
|
- run: cp ./roster/target/roster-0.0.1-SNAPSHOT.jar ./target
|
||||||
|
|
||||||
|
- name: Build executor-pool service
|
||||||
run: mvn -f executor-pool/pom.xml --batch-mode --update-snapshots verify
|
run: mvn -f executor-pool/pom.xml --batch-mode --update-snapshots verify
|
||||||
- run: cp ./executor-pool/target/executor-pool-0.0.1-SNAPSHOT.jar ./target
|
- run: cp ./executor-pool/target/executor-pool-0.0.1-SNAPSHOT.jar ./target
|
||||||
|
|
||||||
- name: Build with Maven
|
- name: Build executor-base library
|
||||||
run: mvn -f executor-base/pom.xml --batch-mode --update-snapshots install
|
run: mvn -f executor-base/pom.xml --batch-mode --update-snapshots install
|
||||||
|
|
||||||
- name: Build with Maven
|
- name: Build executor-computation service
|
||||||
run: mvn -f executor1/pom.xml --batch-mode --update-snapshots verify
|
run: mvn -f executor-computation/pom.xml --batch-mode --update-snapshots verify
|
||||||
- run: cp ./executor1/target/executor1-0.0.1-SNAPSHOT.jar ./target
|
- run: cp ./executor-computation/target/executor-computation-0.0.1-SNAPSHOT.jar ./target
|
||||||
|
|
||||||
- name: Build with Maven
|
- name: Build executor-robot service
|
||||||
run: mvn -f executor2/pom.xml --batch-mode --update-snapshots verify
|
run: mvn -f executor-robot/pom.xml --batch-mode --update-snapshots verify
|
||||||
- run: cp ./executor2/target/executor2-0.0.1-SNAPSHOT.jar ./target
|
- run: cp ./executor-robot/target/executor-robot-0.0.1-SNAPSHOT.jar ./target
|
||||||
|
|
||||||
- name: Build with Maven
|
- name: Build tapas-task service
|
||||||
run: mvn -f tapas-tasks/pom.xml --batch-mode --update-snapshots verify
|
run: mvn -f tapas-tasks/pom.xml --batch-mode --update-snapshots verify
|
||||||
- run: cp ./tapas-tasks/target/tapas-tasks-0.0.1-SNAPSHOT.jar ./target
|
- run: cp ./tapas-tasks/target/tapas-tasks-0.0.1-SNAPSHOT.jar ./target
|
||||||
|
|
||||||
- name: Build with Maven
|
- name: Build tapas-auction-house service
|
||||||
run: mvn -f tapas-auction-house/pom.xml --batch-mode --update-snapshots verify
|
run: mvn -f tapas-auction-house/pom.xml --batch-mode --update-snapshots verify
|
||||||
- run: cp ./tapas-auction-house/target/tapas-auction-house-0.0.1-SNAPSHOT.jar ./target
|
- run: cp ./tapas-auction-house/target/tapas-auction-house-0.0.1-SNAPSHOT.jar ./target
|
||||||
|
|
||||||
|
|
41
.github/workflows/ci.assignment.yml
vendored
41
.github/workflows/ci.assignment.yml
vendored
|
@ -1,41 +0,0 @@
|
||||||
name: CI Assignment
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main, dev]
|
|
||||||
paths:
|
|
||||||
- "assignment/**"
|
|
||||||
pull_request:
|
|
||||||
branches: [main, dev]
|
|
||||||
paths:
|
|
||||||
- "assignment/**"
|
|
||||||
|
|
||||||
workflow_dispatch:
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
name: Build
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- name: Set up JDK 11
|
|
||||||
uses: actions/setup-java@v1
|
|
||||||
with:
|
|
||||||
java-version: 11
|
|
||||||
- name: Cache SonarCloud packages
|
|
||||||
uses: actions/cache@v1
|
|
||||||
with:
|
|
||||||
path: ~/.sonar/cache
|
|
||||||
key: ${{ runner.os }}-sonar
|
|
||||||
restore-keys: ${{ runner.os }}-sonar
|
|
||||||
- name: Cache Maven packages
|
|
||||||
uses: actions/cache@v1
|
|
||||||
with:
|
|
||||||
path: ~/.m2
|
|
||||||
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
|
||||||
restore-keys: ${{ runner.os }}-m2
|
|
||||||
- name: Build and analyze
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
|
||||||
run: mvn -f assignment/pom.xml -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=scs-asse-fs21-group1_tapas-assignment
|
|
|
@ -1,15 +1,17 @@
|
||||||
name: CI Executor 2
|
name: CI executor-computation
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main, dev]
|
branches: [main, dev]
|
||||||
paths:
|
paths:
|
||||||
- "executor-base/**"
|
- "executor-base/**"
|
||||||
- "executor2/**"
|
- "executor-computation/**"
|
||||||
|
- "common/**"
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [main, dev]
|
branches: [main, dev]
|
||||||
paths:
|
paths:
|
||||||
- "executor-base/**"
|
- "executor-base/**"
|
||||||
- "executor2/**"
|
- "executor-computation/**"
|
||||||
|
- "common/**"
|
||||||
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
jobs:
|
jobs:
|
||||||
|
@ -36,10 +38,12 @@ jobs:
|
||||||
path: ~/.m2
|
path: ~/.m2
|
||||||
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
||||||
restore-keys: ${{ runner.os }}-m2
|
restore-keys: ${{ runner.os }}-m2
|
||||||
|
- name: Build common
|
||||||
|
run: mvn -f common/pom.xml -B install
|
||||||
- name: Build executorBase
|
- name: Build executorBase
|
||||||
run: mvn -f executor-base/pom.xml -B install
|
run: mvn -f executor-base/pom.xml -B install
|
||||||
- name: Build and analyze
|
- name: Build and analyze
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||||
run: mvn -f executor2/pom.xml -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=scs-asse-fs21-group1_tapas-executor2
|
run: mvn -f executor-computation/pom.xml -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=scs-asse-fs21-group1_tapas-executor2
|
|
@ -4,12 +4,14 @@ on:
|
||||||
branches: [main, dev]
|
branches: [main, dev]
|
||||||
paths:
|
paths:
|
||||||
- "executor-base/**"
|
- "executor-base/**"
|
||||||
- "executor1/**"
|
- "executor-robot/**"
|
||||||
|
- "common/**"
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [main, dev]
|
branches: [main, dev]
|
||||||
paths:
|
paths:
|
||||||
- "executor-base/**"
|
- "executor-base/**"
|
||||||
- "executor1/**"
|
- "executor-robot/**"
|
||||||
|
- "common/**"
|
||||||
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
jobs:
|
jobs:
|
||||||
|
@ -36,10 +38,12 @@ jobs:
|
||||||
path: ~/.m2
|
path: ~/.m2
|
||||||
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
||||||
restore-keys: ${{ runner.os }}-m2
|
restore-keys: ${{ runner.os }}-m2
|
||||||
|
- name: Build executorBase
|
||||||
|
run: mvn -f common/pom.xml -B install
|
||||||
- name: Build executorBase
|
- name: Build executorBase
|
||||||
run: mvn -f executor-base/pom.xml -B install
|
run: mvn -f executor-base/pom.xml -B install
|
||||||
- name: Build and analyze
|
- name: Build and analyze
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||||
run: mvn -f executor1/pom.xml -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=scs-asse-fs21-group1_tapas-executor1
|
run: mvn -f executor-robot/pom.xml -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=scs-asse-fs21-group1_tapas-executor1
|
45
.github/workflows/ci.roster.yml
vendored
Normal file
45
.github/workflows/ci.roster.yml
vendored
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
name: CI Roster
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main, dev]
|
||||||
|
paths:
|
||||||
|
- "roster/**"
|
||||||
|
- "common/**"
|
||||||
|
pull_request:
|
||||||
|
branches: [main, dev]
|
||||||
|
paths:
|
||||||
|
- "roster/**"
|
||||||
|
- "common/**"
|
||||||
|
|
||||||
|
workflow_dispatch:
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Set up JDK 11
|
||||||
|
uses: actions/setup-java@v1
|
||||||
|
with:
|
||||||
|
java-version: 11
|
||||||
|
- name: Cache SonarCloud packages
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.sonar/cache
|
||||||
|
key: ${{ runner.os }}-sonar
|
||||||
|
restore-keys: ${{ runner.os }}-sonar
|
||||||
|
- name: Cache Maven packages
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.m2
|
||||||
|
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
||||||
|
restore-keys: ${{ runner.os }}-m2
|
||||||
|
- name: Build common package
|
||||||
|
run: mvn -f common/pom.xml -B install
|
||||||
|
- name: Build and analyze
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||||
|
run: mvn -f roster/pom.xml -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=scs-asse-fs21-group1_tapas-assignment
|
|
@ -1,5 +1,7 @@
|
||||||
package ch.unisg.executorbase.executor.adapter.in.web;
|
package ch.unisg.executorbase.executor.adapter.in.web;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
@ -19,6 +21,8 @@ public class TaskAvailableController {
|
||||||
this.taskAvailableUseCase = taskAvailableUseCase;
|
this.taskAvailableUseCase = taskAvailableUseCase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger logger = Logger.getLogger(TaskAvailableController.class.getName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller for notification about new events.
|
* Controller for notification about new events.
|
||||||
* @return 200 OK
|
* @return 200 OK
|
||||||
|
@ -26,6 +30,8 @@ public class TaskAvailableController {
|
||||||
@GetMapping(path = "/newtask/{taskType}", consumes = { "application/json" })
|
@GetMapping(path = "/newtask/{taskType}", consumes = { "application/json" })
|
||||||
public ResponseEntity<String> retrieveTaskFromTaskList(@PathVariable("taskType") String taskType) {
|
public ResponseEntity<String> retrieveTaskFromTaskList(@PathVariable("taskType") String taskType) {
|
||||||
|
|
||||||
|
logger.info("New " + taskType + " available");
|
||||||
|
|
||||||
if (ExecutorType.contains(taskType.toUpperCase())) {
|
if (ExecutorType.contains(taskType.toUpperCase())) {
|
||||||
TaskAvailableCommand command = new TaskAvailableCommand(
|
TaskAvailableCommand command = new TaskAvailableCommand(
|
||||||
ExecutorType.valueOf(taskType.toUpperCase()));
|
ExecutorType.valueOf(taskType.toUpperCase()));
|
||||||
|
|
|
@ -16,8 +16,9 @@ import ch.unisg.executorbase.executor.domain.ExecutionFinishedEvent;
|
||||||
|
|
||||||
public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort {
|
public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort {
|
||||||
|
|
||||||
|
// TODO url doesn't get mapped bc no autowiring
|
||||||
@Value("${roster.url}")
|
@Value("${roster.url}")
|
||||||
String server;
|
String server = "http://localhost:8082";
|
||||||
|
|
||||||
Logger logger = Logger.getLogger(ExecutionFinishedEventAdapter.class.getName());
|
Logger logger = Logger.getLogger(ExecutionFinishedEventAdapter.class.getName());
|
||||||
|
|
||||||
|
@ -28,6 +29,9 @@ public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort
|
||||||
@Override
|
@Override
|
||||||
public void publishExecutionFinishedEvent(ExecutionFinishedEvent event) {
|
public void publishExecutionFinishedEvent(ExecutionFinishedEvent event) {
|
||||||
|
|
||||||
|
System.out.println("HI");
|
||||||
|
System.out.println(server);
|
||||||
|
|
||||||
String body = new JSONObject()
|
String body = new JSONObject()
|
||||||
.put("taskID", event.getTaskID())
|
.put("taskID", event.getTaskID())
|
||||||
.put("result", event.getResult())
|
.put("result", event.getResult())
|
||||||
|
@ -41,6 +45,9 @@ public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort
|
||||||
.POST(HttpRequest.BodyPublishers.ofString(body))
|
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(server);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client.send(request, HttpResponse.BodyHandlers.ofString());
|
client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
@ -50,7 +57,7 @@ public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort
|
||||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.log(Level.INFO, "Finish execution event sent with result: {}", event.getResult());
|
logger.log(Level.INFO, "Finish execution event sent with result: {0}", event.getResult());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,9 @@ import org.json.JSONObject;
|
||||||
@Primary
|
@Primary
|
||||||
public class GetAssignmentAdapter implements GetAssignmentPort {
|
public class GetAssignmentAdapter implements GetAssignmentPort {
|
||||||
|
|
||||||
|
// TODO Not working for now bc it doesn't get autowired
|
||||||
@Value("${roster.url}")
|
@Value("${roster.url}")
|
||||||
String server;
|
String server = "http://127.0.0.1:8082";
|
||||||
|
|
||||||
Logger logger = Logger.getLogger(GetAssignmentAdapter.class.getName());
|
Logger logger = Logger.getLogger(GetAssignmentAdapter.class.getName());
|
||||||
|
|
||||||
|
@ -51,12 +52,15 @@ public class GetAssignmentAdapter implements GetAssignmentPort {
|
||||||
try {
|
try {
|
||||||
logger.info("Sending getAssignment Request");
|
logger.info("Sending getAssignment Request");
|
||||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||||
logger.log(Level.INFO, "getAssignment request result:\n {}", response.body());
|
logger.log(Level.INFO, "getAssignment request result:\n {0}", response.body());
|
||||||
if (response.body().equals("")) {
|
if (response.body().equals("")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
JSONObject responseBody = new JSONObject(response.body());
|
JSONObject responseBody = new JSONObject(response.body());
|
||||||
return new Task(responseBody.getString("taskID"), responseBody.getString("input"));
|
|
||||||
|
String[] input = { "1", "+", "2" };
|
||||||
|
// TODO Add input in roster + tasklist
|
||||||
|
return new Task(responseBody.getString("taskID"), input);
|
||||||
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||||
|
|
|
@ -22,8 +22,9 @@ import ch.unisg.executorbase.executor.domain.ExecutorType;
|
||||||
@Primary
|
@Primary
|
||||||
public class NotifyExecutorPoolAdapter implements NotifyExecutorPoolPort {
|
public class NotifyExecutorPoolAdapter implements NotifyExecutorPoolPort {
|
||||||
|
|
||||||
@Value("${executor-pool.url}")
|
// TODO Not working for now bc it doesn't get autowired
|
||||||
String server;
|
@Value("${executor.pool.url}")
|
||||||
|
String server = "http://127.0.0.1:8083";
|
||||||
|
|
||||||
Logger logger = Logger.getLogger(NotifyExecutorPoolAdapter.class.getName());
|
Logger logger = Logger.getLogger(NotifyExecutorPoolAdapter.class.getName());
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ public class NotifyExecutorPoolAdapter implements NotifyExecutorPoolPort {
|
||||||
|
|
||||||
String body = new JSONObject()
|
String body = new JSONObject()
|
||||||
.put("executorTaskType", executorType)
|
.put("executorTaskType", executorType)
|
||||||
.put("executorURI", executorURI.getValue())
|
.put("executorUri", executorURI.getValue())
|
||||||
.toString();
|
.toString();
|
||||||
|
|
||||||
HttpClient client = HttpClient.newHttpClient();
|
HttpClient client = HttpClient.newHttpClient();
|
||||||
|
|
|
@ -23,9 +23,8 @@ public abstract class ExecutorBase {
|
||||||
@Getter
|
@Getter
|
||||||
private ExecutorStatus status;
|
private ExecutorStatus status;
|
||||||
|
|
||||||
// TODO Violation of the Dependency Inversion Principle?, but we havn't really got a better solutions to send a http request / access a service from a domain model
|
// TODO Violation of the Dependency Inversion Principle?,
|
||||||
// TODO I guess we can implement the execution as a service but there still is the problem with the startup request.
|
// TODO do this with only services
|
||||||
// TODO I guess we can somehow autowire this but I don't know why it's not working :D
|
|
||||||
private final NotifyExecutorPoolPort notifyExecutorPoolPort = new NotifyExecutorPoolAdapter();
|
private final NotifyExecutorPoolPort notifyExecutorPoolPort = new NotifyExecutorPoolAdapter();
|
||||||
private final NotifyExecutorPoolService notifyExecutorPoolService = new NotifyExecutorPoolService(notifyExecutorPoolPort);
|
private final NotifyExecutorPoolService notifyExecutorPoolService = new NotifyExecutorPoolService(notifyExecutorPoolPort);
|
||||||
private final GetAssignmentPort getAssignmentPort = new GetAssignmentAdapter();
|
private final GetAssignmentPort getAssignmentPort = new GetAssignmentAdapter();
|
||||||
|
@ -38,8 +37,8 @@ public abstract class ExecutorBase {
|
||||||
this.status = ExecutorStatus.STARTING_UP;
|
this.status = ExecutorStatus.STARTING_UP;
|
||||||
this.executorType = executorType;
|
this.executorType = executorType;
|
||||||
// TODO set this automaticly
|
// TODO set this automaticly
|
||||||
this.executorURI = new ExecutorURI("localhost:8084");
|
this.executorURI = new ExecutorURI("http://localhost:8084");
|
||||||
|
// TODO do this in main
|
||||||
// Notify executor-pool about existence. If executor-pools response is successfull start with getting an assignment, else shut down executor.
|
// Notify executor-pool about existence. If executor-pools response is successfull start with getting an assignment, else shut down executor.
|
||||||
if(!notifyExecutorPoolService.notifyExecutorPool(this.executorURI, this.executorType)) {
|
if(!notifyExecutorPoolService.notifyExecutorPool(this.executorURI, this.executorType)) {
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
|
@ -55,6 +54,8 @@ public abstract class ExecutorBase {
|
||||||
**/
|
**/
|
||||||
public void getAssignment() {
|
public void getAssignment() {
|
||||||
Task newTask = getAssignmentPort.getAssignment(this.getExecutorType(), this.getExecutorURI());
|
Task newTask = getAssignmentPort.getAssignment(this.getExecutorType(), this.getExecutorURI());
|
||||||
|
System.out.println("New assignment");
|
||||||
|
System.out.println(newTask);
|
||||||
if (newTask != null) {
|
if (newTask != null) {
|
||||||
this.executeTask(newTask);
|
this.executeTask(newTask);
|
||||||
} else {
|
} else {
|
||||||
|
@ -72,6 +73,8 @@ public abstract class ExecutorBase {
|
||||||
|
|
||||||
task.setResult(execution(task.getInput()));
|
task.setResult(execution(task.getInput()));
|
||||||
|
|
||||||
|
System.out.println(task.getResult());
|
||||||
|
|
||||||
// TODO implement logic if execution was not successful
|
// TODO implement logic if execution was not successful
|
||||||
executionFinishedEventPort.publishExecutionFinishedEvent(
|
executionFinishedEventPort.publishExecutionFinishedEvent(
|
||||||
new ExecutionFinishedEvent(task.getTaskID(), task.getResult(), "SUCCESS"));
|
new ExecutionFinishedEvent(task.getTaskID(), task.getResult(), "SUCCESS"));
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
server.port=8081
|
server.port=8081
|
||||||
roster.url=http://127.0.0.1:8082
|
roster.url=http://127.0.0.1:8082
|
||||||
executor-pool.url=http://127.0.0.1:8083
|
executor.pool.url=http://127.0.0.1:8083
|
||||||
executor1.url=http://127.0.0.1:8084
|
executor1.url=http://127.0.0.1:8084
|
||||||
executor2.url=http://127.0.0.1:8085
|
executor2.url=http://127.0.0.1:8085
|
||||||
task-list.url=http://127.0.0.1:8081
|
task-list.url=http://127.0.0.1:8081
|
||||||
|
|
|
@ -21,16 +21,18 @@ public class Executor extends ExecutorBase {
|
||||||
protected
|
protected
|
||||||
String execution(String... input) {
|
String execution(String... input) {
|
||||||
|
|
||||||
|
System.out.println(input);
|
||||||
|
|
||||||
double result = Double.NaN;
|
double result = Double.NaN;
|
||||||
int a = Integer.parseInt(input[0]);
|
int a = Integer.parseInt(input[0]);
|
||||||
int b = Integer.parseInt(input[2]);
|
int b = Integer.parseInt(input[2]);
|
||||||
String operation = input[1];
|
String operation = input[1];
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
TimeUnit.SECONDS.sleep(20);
|
// TimeUnit.SECONDS.sleep(20);
|
||||||
} catch (InterruptedException e) {
|
// } catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (operation == "+") {
|
if (operation == "+") {
|
||||||
result = a + b;
|
result = a + b;
|
||||||
|
@ -40,7 +42,9 @@ public class Executor extends ExecutorBase {
|
||||||
result = a - b;
|
result = a - b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println("finish");
|
||||||
|
|
||||||
return Double.toString(result);
|
return Double.toString(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,41 @@
|
||||||
package ch.unisg.roster;
|
package ch.unisg.roster;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
import ch.unisg.roster.roster.adapter.common.clients.TapasMqttClient;
|
||||||
|
import ch.unisg.roster.roster.adapter.in.messaging.mqtt.ExecutorEventMqttListener;
|
||||||
|
import ch.unisg.roster.roster.adapter.in.messaging.mqtt.ExecutorEventsMqttDispatcher;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class RosterApplication {
|
public class RosterApplication {
|
||||||
|
|
||||||
|
static Logger logger = Logger.getLogger(RosterApplication.class.getName());
|
||||||
|
|
||||||
|
public static String MQTT_BROKER = "tcp://localhost:1883";
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(RosterApplication.class, args);
|
SpringApplication.run(RosterApplication.class, args);
|
||||||
|
|
||||||
|
bootstrapMarketplaceWithMqtt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connects to an MQTT broker, presumably the one used by all TAPAS groups to communicate with
|
||||||
|
* one another
|
||||||
|
*/
|
||||||
|
private static void bootstrapMarketplaceWithMqtt() {
|
||||||
|
try {
|
||||||
|
ExecutorEventsMqttDispatcher dispatcher = new ExecutorEventsMqttDispatcher();
|
||||||
|
TapasMqttClient client = TapasMqttClient.getInstance(MQTT_BROKER, dispatcher);
|
||||||
|
client.startReceivingMessages();
|
||||||
|
} catch (MqttException e) {
|
||||||
|
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,9 @@ public class ExecutorAddedEventListenerMqttAdapter extends ExecutorEventMqttList
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handleEvent(MqttMessage message) {
|
public boolean handleEvent(MqttMessage message) {
|
||||||
|
|
||||||
|
System.out.println("New Executor added!");
|
||||||
|
|
||||||
String payload = new String(message.getPayload());
|
String payload = new String(message.getPayload());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -25,7 +28,7 @@ public class ExecutorAddedEventListenerMqttAdapter extends ExecutorEventMqttList
|
||||||
JsonNode data = new ObjectMapper().readTree(payload);
|
JsonNode data = new ObjectMapper().readTree(payload);
|
||||||
|
|
||||||
String taskType = data.get("executorTaskType").asText();
|
String taskType = data.get("executorTaskType").asText();
|
||||||
String executorId = data.get("executorURI").asText();
|
String executorId = data.get("executorUri").asText();
|
||||||
|
|
||||||
ExecutorAddedEvent executorAddedEvent = new ExecutorAddedEvent(
|
ExecutorAddedEvent executorAddedEvent = new ExecutorAddedEvent(
|
||||||
new ExecutorURI(executorId),
|
new ExecutorURI(executorId),
|
||||||
|
|
|
@ -16,8 +16,8 @@ public class ExecutorEventsMqttDispatcher {
|
||||||
|
|
||||||
// TODO: Register here your topics and event listener adapters
|
// TODO: Register here your topics and event listener adapters
|
||||||
private void initRouter() {
|
private void initRouter() {
|
||||||
router.put("ch/unisg/tapas-group-tutors/executors/added", new ExecutorAddedEventListenerMqttAdapter());
|
router.put("ch/unisg/tapas/executors/added", new ExecutorAddedEventListenerMqttAdapter());
|
||||||
router.put("ch/unisg/tapas-group-tutors/executors/removed", new ExecutorRemovedEventListenerMqttAdapter());
|
router.put("ch/unisg/tapas/executors/removed", new ExecutorRemovedEventListenerMqttAdapter());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package ch.unisg.roster.roster.adapter.in.web;
|
package ch.unisg.roster.roster.adapter.in.web;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
@ -18,6 +20,8 @@ public class NewTaskController {
|
||||||
this.newTaskUseCase = newTaskUseCase;
|
this.newTaskUseCase = newTaskUseCase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger logger = Logger.getLogger(NewTaskController.class.getName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller which handles the new task event from the tasklist
|
* Controller which handles the new task event from the tasklist
|
||||||
* @return 201 Create or 409 Conflict
|
* @return 201 Create or 409 Conflict
|
||||||
|
@ -25,10 +29,14 @@ public class NewTaskController {
|
||||||
@PostMapping(path = "/task", consumes = {"application/task+json"})
|
@PostMapping(path = "/task", consumes = {"application/task+json"})
|
||||||
public ResponseEntity<Void> newTaskController(@RequestBody Task task) {
|
public ResponseEntity<Void> newTaskController(@RequestBody Task task) {
|
||||||
|
|
||||||
|
logger.info("New task with id:" + task.getTaskID());
|
||||||
|
|
||||||
NewTaskCommand command = new NewTaskCommand(task.getTaskID(), task.getTaskType());
|
NewTaskCommand command = new NewTaskCommand(task.getTaskID(), task.getTaskType());
|
||||||
|
|
||||||
boolean success = newTaskUseCase.addNewTaskToQueue(command);
|
boolean success = newTaskUseCase.addNewTaskToQueue(command);
|
||||||
|
|
||||||
|
logger.info("Could create task: " + success);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,21 +34,23 @@ public class PublishNewTaskEventAdapter implements NewTaskEventPort {
|
||||||
@Override
|
@Override
|
||||||
public void publishNewTaskEvent(NewTaskEvent event) {
|
public void publishNewTaskEvent(NewTaskEvent event) {
|
||||||
|
|
||||||
HttpClient client = HttpClient.newHttpClient();
|
System.out.println(server2);
|
||||||
HttpRequest request = HttpRequest.newBuilder()
|
|
||||||
.uri(URI.create(server + "/newtask/" + event.taskType.getValue()))
|
// HttpClient client = HttpClient.newHttpClient();
|
||||||
.GET()
|
// HttpRequest request = HttpRequest.newBuilder()
|
||||||
.build();
|
// .uri(URI.create(server + "/newtask/" + event.taskType.getValue()))
|
||||||
|
// .GET()
|
||||||
|
// .build();
|
||||||
|
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
client.send(request, HttpResponse.BodyHandlers.ofString());
|
// client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||||
} catch (InterruptedException e) {
|
// } catch (InterruptedException e) {
|
||||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
// logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||||
Thread.currentThread().interrupt();
|
// Thread.currentThread().interrupt();
|
||||||
} catch (IOException e) {
|
// } catch (IOException e) {
|
||||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
// logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||||
}
|
// }
|
||||||
|
|
||||||
HttpClient client2 = HttpClient.newHttpClient();
|
HttpClient client2 = HttpClient.newHttpClient();
|
||||||
HttpRequest request2 = HttpRequest.newBuilder()
|
HttpRequest request2 = HttpRequest.newBuilder()
|
||||||
|
|
|
@ -29,6 +29,7 @@ public class NewTaskService implements NewTaskUseCase {
|
||||||
public boolean addNewTaskToQueue(NewTaskCommand command) {
|
public boolean addNewTaskToQueue(NewTaskCommand command) {
|
||||||
|
|
||||||
ExecutorRegistry executorRegistry = ExecutorRegistry.getInstance();
|
ExecutorRegistry executorRegistry = ExecutorRegistry.getInstance();
|
||||||
|
|
||||||
if (!executorRegistry.containsTaskType(command.getTaskType())) {
|
if (!executorRegistry.containsTaskType(command.getTaskType())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user