integration + fixes

This commit is contained in:
Marcel 2021-10-17 15:38:04 +02:00
parent 8b0eea1270
commit f461c5f3cb
25 changed files with 252 additions and 186 deletions

View File

@ -1,57 +1,108 @@
version: "3.0" version: "3.0"
services: services:
reverse-proxy: reverse-proxy:
image: traefik:v2.1.3 image: traefik:v2.1.3
command: command:
- --entrypoints.web.address=:80 - --entrypoints.web.address=:80
- --entrypoints.websecure.address=:443 - --entrypoints.websecure.address=:443
- --providers.docker=true - --providers.docker=true
- --certificatesResolvers.le.acme.httpChallenge.entryPoint=web - --certificatesResolvers.le.acme.httpChallenge.entryPoint=web
- --certificatesresolvers.le.acme.email=martin.eigenmann@unisg.ch - --certificatesresolvers.le.acme.email=martin.eigenmann@unisg.ch
- --certificatesresolvers.le.acme.storage=/acme.json - --certificatesresolvers.le.acme.storage=/acme.json
- --providers.docker.exposedByDefault=false - --providers.docker.exposedByDefault=false
- --serversTransport.insecureSkipVerify=true - --serversTransport.insecureSkipVerify=true
ports: ports:
- "80:80" - "80:80"
- "443:443" - "443:443"
volumes: volumes:
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock
- ./acme.json:/acme.json - ./acme.json:/acme.json
restart: unless-stopped restart: unless-stopped
labels: labels:
- "traefik.enable=true" - "traefik.enable=true"
- "traefik.http.routers.http-catchall.rule=hostregexp(`{host:.+}`)" - "traefik.http.routers.http-catchall.rule=hostregexp(`{host:.+}`)"
- "traefik.http.routers.http-catchall.entrypoints=web" - "traefik.http.routers.http-catchall.entrypoints=web"
- "traefik.http.routers.http-catchall.middlewares=redirect-to-https" - "traefik.http.routers.http-catchall.middlewares=redirect-to-https"
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https" - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
tapas-tasks:
image: openjdk
command: "java -jar /data/tapas-tasks-0.0.1-SNAPSHOT.jar"
restart: unless-stopped
volumes:
- ./:/data/
labels:
- "traefik.enable=true"
- "traefik.http.routers.tapas-tasks.rule=Host(`tapas-tasks.${PUB_IP}.nip.io`)"
- "traefik.http.routers.tapas-tasks.service=tapas-tasks"
- "traefik.http.services.tapas-tasks.loadbalancer.server.port=8081"
- "traefik.http.routers.tapas-tasks.tls=true"
- "traefik.http.routers.tapas-tasks.entryPoints=web,websecure"
- "traefik.http.routers.tapas-tasks.tls.certresolver=le"
app: tapas-tasks:
image: openjdk image: openjdk
command: "java -jar /data/app-0.1.0.jar" command: "java -jar /data/tapas-tasks-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.app.rule=Host(`app.${PUB_IP}.nip.io`)" - "traefik.http.routers.tapas-tasks.rule=Host(`tapas-tasks.${PUB_IP}.nip.io`)"
- "traefik.http.routers.app.service=app" - "traefik.http.routers.tapas-tasks.service=tapas-tasks"
- "traefik.http.services.app.loadbalancer.server.port=8080" - "traefik.http.services.tapas-tasks.loadbalancer.server.port=8081"
- "traefik.http.routers.app.tls=true" - "traefik.http.routers.tapas-tasks.tls=true"
- "traefik.http.routers.app.entryPoints=web,websecure" - "traefik.http.routers.tapas-tasks.entryPoints=web,websecure"
- "traefik.http.routers.app.tls.certresolver=le" - "traefik.http.routers.tapas-tasks.tls.certresolver=le"
assignment:
image: openjdk
command: "java -jar /data/assignment-0.0.1.jar"
restart: unless-stopped
volumes:
- ./:/data/
labels:
- "traefik.enable=true"
- "traefik.http.routers.assignment.rule=Host(`assignment.${PUB_IP}.nip.io`)"
- "traefik.http.routers.assignment.service=assignment"
- "traefik.http.services.assignment.loadbalancer.server.port=8082"
- "traefik.http.routers.assignment.tls=true"
- "traefik.http.routers.assignment.entryPoints=web,websecure"
- "traefik.http.routers.assignment.tls.certresolver=le"
executor-pool:
image: openjdk
command: "java -jar /data/executor-pool-0.0.1.jar"
restart: unless-stopped
volumes:
- ./:/data/
labels:
- "traefik.enable=true"
- "traefik.http.routers.executor-pool.rule=Host(`executor-pool.${PUB_IP}.nip.io`)"
- "traefik.http.routers.executor-pool.service=executor-pool"
- "traefik.http.services.executor-pool.loadbalancer.server.port=8083"
- "traefik.http.routers.executor-pool.tls=true"
- "traefik.http.routers.executor-pool.entryPoints=web,websecure"
- "traefik.http.routers.executor-pool.tls.certresolver=le"
executor1:
image: openjdk
command: "java -jar /data/executor1-0.0.1.jar"
restart: unless-stopped
depends_on:
- executor-pool
- assignment
volumes:
- ./:/data/
labels:
- "traefik.enable=true"
- "traefik.http.routers.executor1.rule=Host(`executor1.${PUB_IP}.nip.io`)"
- "traefik.http.routers.executor1.service=executor1"
- "traefik.http.services.executor1.loadbalancer.server.port=8084"
- "traefik.http.routers.executor1.tls=true"
- "traefik.http.routers.executor1.entryPoints=web,websecure"
- "traefik.http.routers.executor1.tls.certresolver=le"
executor2:
image: openjdk
command: "java -jar /data/executor2-0.0.1.jar"
restart: unless-stopped
depends_on:
- executor-pool
- assignment
volumes:
- ./:/data/
labels:
- "traefik.enable=true"
- "traefik.http.routers.executor2.rule=Host(`executor2.${PUB_IP}.nip.io`)"
- "traefik.http.routers.executor2.service=executor2"
- "traefik.http.services.executor2.loadbalancer.server.port=8085"
- "traefik.http.routers.executor2.tls=true"
- "traefik.http.routers.executor2.entryPoints=web,websecure"
- "traefik.http.routers.executor2.tls.certresolver=le"

View File

@ -41,6 +41,9 @@ jobs:
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.jar ./target - run: cp ./executor-pool/target/executor-pool-0.0.1.jar ./target
- name: Build with Maven
run: mvn -f executorBase/pom.xml --batch-mode --update-snapshots install
- name: Build with Maven - name: Build with Maven
run: mvn -f executor1/pom.xml --batch-mode --update-snapshots verify run: mvn -f executor1/pom.xml --batch-mode --update-snapshots verify
- run: cp ./executor1/target/executor1-0.0.1.jar ./target - run: cp ./executor1/target/executor1-0.0.1.jar ./target

View File

@ -1,44 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.dockerforjavadevelopers</groupId>
<artifactId>app</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<start-class>com.dockerforjavadevelopers.hello.Application</start-class>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,19 +0,0 @@
package com.app.hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
}
}

View File

@ -1,14 +0,0 @@
package com.app.hello;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
@RestController
public class HelloController {
@RequestMapping("/")
public String index() {
return "Hello World! Nice to see you :-)\n";
}
}

View File

@ -1,13 +0,0 @@
package com.app.hello;
import static org.junit.Assert.*;
import org.junit.Test;
public class DummyTest {
@Test
public void aTest() {
assertEquals(true, true);
}
}

View File

@ -22,7 +22,7 @@ public class TaskCompletedController {
@PostMapping(path = "/task/completed", consumes = {"application/json"}) @PostMapping(path = "/task/completed", consumes = {"application/json"})
public ResponseEntity<Void> addNewTaskTaskToTaskList(@RequestBody Task task) { public ResponseEntity<Void> addNewTaskTaskToTaskList(@RequestBody Task task) {
TaskCompletedCommand command = new TaskCompletedCommand(task.getTaskID(), task.getTaskType(), TaskCompletedCommand command = new TaskCompletedCommand(task.getTaskID(),
task.getStatus(), task.getResult()); task.getStatus(), task.getResult());
taskCompletedUseCase.taskCompleted(command); taskCompletedUseCase.taskCompleted(command);

View File

@ -0,0 +1,55 @@
package ch.unisg.assignment.assignment.adapter.out.web;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.context.annotation.Primary;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import ch.unisg.assignment.assignment.application.port.out.GetAllExecutorInExecutorPoolByTypePort;
import ch.unisg.assignment.assignment.domain.valueobject.ExecutorType;
@Component
@Primary
public class GetAllExecutorInExecutorPoolByTypeAdapter implements GetAllExecutorInExecutorPoolByTypePort {
@Override
public boolean doesExecutorTypeExist(ExecutorType type) {
String server = "http://127.0.0.1:8083";
Logger logger = Logger.getLogger(PublishNewTaskEventAdapter.class.getName());
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(server + "/executor-pool/GetAllExecutorInExecutorPoolByType/" + type.getValue()))
.header("Content-Type", "application/json")
.GET()
.build();
try {
HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == HttpStatus.OK.value()) {
JSONArray jsonArray = new JSONArray(response.body().toString());
if (jsonArray.length() > 0) {
return true;
}
}
} catch (IOException | InterruptedException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
// Restore interrupted state...
Thread.currentThread().interrupt();
}
return false;
}
}

View File

@ -18,7 +18,8 @@ import ch.unisg.assignment.assignment.domain.event.NewTaskEvent;
@Primary @Primary
public class PublishNewTaskEventAdapter implements NewTaskEventPort { public class PublishNewTaskEventAdapter implements NewTaskEventPort {
String server = "http://127.0.0.1:8085"; String server = "http://127.0.0.1:8084";
String server2 = "http://127.0.0.1:8085";
Logger logger = Logger.getLogger(PublishNewTaskEventAdapter.class.getName()); Logger logger = Logger.getLogger(PublishNewTaskEventAdapter.class.getName());
@ -32,6 +33,21 @@ public class PublishNewTaskEventAdapter implements NewTaskEventPort {
.build(); .build();
try {
client.send(request, HttpResponse.BodyHandlers.ofString());
} catch (IOException | InterruptedException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
// Restore interrupted state...
Thread.currentThread().interrupt();
}
HttpClient client2 = HttpClient.newHttpClient();
HttpRequest request2 = HttpRequest.newBuilder()
.uri(URI.create(server2 + "/newtask/" + event.taskType.getValue()))
.GET()
.build();
try { try {
client.send(request, HttpResponse.BodyHandlers.ofString()); client.send(request, HttpResponse.BodyHandlers.ofString());
} catch (IOException | InterruptedException e) { } catch (IOException | InterruptedException e) {

View File

@ -19,7 +19,7 @@ import ch.unisg.assignment.assignment.domain.event.TaskAssignedEvent;
@Primary @Primary
public class PublishTaskAssignedEventAdapter implements TaskAssignedEventPort { public class PublishTaskAssignedEventAdapter implements TaskAssignedEventPort {
String server = "http://127.0.0.1:8085"; String server = "http://127.0.0.1:8081";
Logger logger = Logger.getLogger(PublishTaskAssignedEventAdapter.class.getName()); Logger logger = Logger.getLogger(PublishTaskAssignedEventAdapter.class.getName());
@ -32,7 +32,7 @@ public class PublishTaskAssignedEventAdapter implements TaskAssignedEventPort {
HttpClient client = HttpClient.newHttpClient(); HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder() HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(server + "/tasks/completeTask")) .uri(URI.create(server + "/tasks/assignTask"))
.header("Content-Type", "application/json") .header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body)) .POST(HttpRequest.BodyPublishers.ofString(body))
.build(); .build();

View File

@ -2,7 +2,6 @@ package ch.unisg.assignment.assignment.application.port.in;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import ch.unisg.assignment.assignment.domain.valueobject.ExecutorType;
import ch.unisg.assignment.common.SelfValidating; import ch.unisg.assignment.common.SelfValidating;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Value; import lombok.Value;
@ -14,18 +13,14 @@ public class TaskCompletedCommand extends SelfValidating<TaskCompletedCommand>{
@NotNull @NotNull
private final String taskID; private final String taskID;
@NotNull
private final ExecutorType taskType;
@NotNull @NotNull
private final String taskStatus; private final String taskStatus;
@NotNull @NotNull
private final String taskResult; private final String taskResult;
public TaskCompletedCommand(String taskID, ExecutorType taskType, String taskStatus, String taskResult) { public TaskCompletedCommand(String taskID, String taskStatus, String taskResult) {
this.taskID = taskID; this.taskID = taskID;
this.taskType = taskType;
this.taskStatus = taskStatus; this.taskStatus = taskStatus;
this.taskResult = taskResult; this.taskResult = taskResult;
this.validateSelf(); this.validateSelf();

View File

@ -0,0 +1,9 @@
package ch.unisg.assignment.assignment.application.port.out;
import ch.unisg.assignment.assignment.domain.valueobject.ExecutorType;
public interface GetAllExecutorInExecutorPoolByTypePort {
boolean doesExecutorTypeExist(ExecutorType type);
}

View File

@ -9,6 +9,7 @@ import org.springframework.stereotype.Component;
import ch.unisg.assignment.assignment.application.port.in.NewTaskCommand; import ch.unisg.assignment.assignment.application.port.in.NewTaskCommand;
import ch.unisg.assignment.assignment.application.port.in.NewTaskUseCase; import ch.unisg.assignment.assignment.application.port.in.NewTaskUseCase;
import ch.unisg.assignment.assignment.application.port.out.GetAllExecutorInExecutorPoolByTypePort;
import ch.unisg.assignment.assignment.application.port.out.NewTaskEventPort; import ch.unisg.assignment.assignment.application.port.out.NewTaskEventPort;
import ch.unisg.assignment.assignment.domain.Roster; import ch.unisg.assignment.assignment.domain.Roster;
import ch.unisg.assignment.assignment.domain.Task; import ch.unisg.assignment.assignment.domain.Task;
@ -21,14 +22,13 @@ import lombok.RequiredArgsConstructor;
public class NewTaskService implements NewTaskUseCase { public class NewTaskService implements NewTaskUseCase {
private final NewTaskEventPort newTaskEventPort; private final NewTaskEventPort newTaskEventPort;
private final GetAllExecutorInExecutorPoolByTypePort getAllExecutorInExecutorPoolByTypePort;
@Override @Override
public boolean addNewTaskToQueue(NewTaskCommand command) { public boolean addNewTaskToQueue(NewTaskCommand command) {
// TODO Get availableTaskTypes from executor pool // TODO Get availableTaskTypes from executor pool
List<String> availableTaskTypes = Arrays.asList("ADDITION", "ROBOT"); if (!getAllExecutorInExecutorPoolByTypePort.doesExecutorTypeExist(command.getTaskType())) {
if (!availableTaskTypes.contains(command.getTaskType().getValue())) {
return false; return false;
} }

View File

@ -30,9 +30,9 @@ public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort
HttpClient client = HttpClient.newHttpClient(); HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder() HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(server+"/task/"+event.getTaskID())) .uri(URI.create(server+"/task/completed"))
.header("Content-Type", "application/json") .header("Content-Type", "application/json")
.PUT(HttpRequest.BodyPublishers.ofString(body)) .POST(HttpRequest.BodyPublishers.ofString(body))
.build(); .build();
try { try {

View File

@ -1,11 +1,16 @@
package ch.unisg.executorBase.executor.adapter.out.web; package ch.unisg.executorBase.executor.adapter.out.web;
import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.http.HttpClient; import java.net.http.HttpClient;
import java.net.http.HttpRequest; import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONObject; import org.json.JSONObject;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import ch.unisg.executorBase.executor.application.port.out.NotifyExecutorPoolPort; import ch.unisg.executorBase.executor.application.port.out.NotifyExecutorPoolPort;
@ -17,34 +22,36 @@ public class NotifyExecutorPoolAdapter implements NotifyExecutorPoolPort {
String server = "http://127.0.0.1:8083"; String server = "http://127.0.0.1:8083";
Logger logger = Logger.getLogger(NotifyExecutorPoolAdapter.class.getName());
@Override @Override
public boolean notifyExecutorPool(String ip, int port, ExecutorType executorType) { public boolean notifyExecutorPool(String ip, int port, ExecutorType executorType) {
String body = new JSONObject() String body = new JSONObject()
.put("executorType", executorType) .put("executorTaskType", executorType)
.put("ip", ip) .put("executorIp", ip)
.put("port", port) .put("executorPort", Integer.toString(port))
.toString(); .toString();
HttpClient client = HttpClient.newHttpClient(); HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder() HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(server+"/executor/new/")) .uri(URI.create(server+"/executor-pool/AddExecutor"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body)) .POST(HttpRequest.BodyPublishers.ofString(body))
.build(); .build();
/** Needs the other service running
try { try {
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
} catch (IOException e) { if (response.statusCode() == HttpStatus.CREATED.value()) {
e.printStackTrace(); return true;
} catch (InterruptedException e) { }
e.printStackTrace(); } catch (IOException | InterruptedException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
// Restore interrupted state...
Thread.currentThread().interrupt();
} }
**/
// TODO return true or false depending on result of http request; return false;
return true;
} }
} }

View File

@ -23,10 +23,15 @@ final public class ExecutorMediaType {
String serializedList = "[ \n"; String serializedList = "[ \n";
for (ExecutorClass executor: listOfExecutors) { for (ExecutorClass executor: listOfExecutors) {
serializedList += serialize(executor) + ",\n"; serializedList += serialize(executor) + "\n";
} }
return serializedList + "\n ]"; // return serializedList + "\n ]";
JSONArray jsonArray = new JSONArray();
JSONObject jsonObject = new JSONObject();
jsonObject.put("executorIp", "localhost");
jsonArray.put(jsonObject);
return jsonArray.toString();
} }
private ExecutorMediaType() { } private ExecutorMediaType() { }

View File

@ -2,7 +2,6 @@ package ch.unisg.executorpool.adapter.in.web;
import ch.unisg.executorpool.application.port.in.GetAllExecutorsInExecutorPoolUseCase; import ch.unisg.executorpool.application.port.in.GetAllExecutorsInExecutorPoolUseCase;
import ch.unisg.executorpool.domain.ExecutorClass; import ch.unisg.executorpool.domain.ExecutorClass;
import ch.unisg.tapastasks.tasks.adapter.in.web.TaskMediaType;
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;

View File

@ -1 +1 @@
server.port=8081 server.port=8083

View File

@ -1,5 +1,7 @@
package ch.unisg.executor1.executor.adapter.in.web; package ch.unisg.executor1.executor.adapter.in.web;
import java.util.concurrent.CompletableFuture;
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;
@ -25,7 +27,7 @@ public class TaskAvailableController {
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()));
taskAvailableUseCase.newTaskAvailable(command); CompletableFuture.runAsync(() -> taskAvailableUseCase.newTaskAvailable(command));
} }
// Add the content type as a response header // Add the content type as a response header

View File

@ -14,7 +14,7 @@ import ch.unisg.executorBase.executor.domain.ExecutorBase;
import ch.unisg.executorBase.executor.domain.ExecutorType; import ch.unisg.executorBase.executor.domain.ExecutorType;
public class Executor extends ExecutorBase { public class Executor extends ExecutorBase {
private static final Executor executor = new Executor(ExecutorType.ROBOT); private static final Executor executor = new Executor(ExecutorType.ROBOT);
private final UserToRobotPort userToRobotPort = new UserToRobotAdapter(); private final UserToRobotPort userToRobotPort = new UserToRobotAdapter();
private final InstructionToRobotPort instructionToRobotPort = new InstructionToRobotAdapter(); private final InstructionToRobotPort instructionToRobotPort = new InstructionToRobotAdapter();
@ -31,12 +31,24 @@ public class Executor extends ExecutorBase {
@Override @Override
protected protected
String execution() { String execution() {
String key = userToRobotPort.userToRobot(); String key = userToRobotPort.userToRobot();
try {
TimeUnit.MILLISECONDS.sleep(1500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
boolean result1 = instructionToRobotPort.instructionToRobot(key); boolean result1 = instructionToRobotPort.instructionToRobot(key);
try {
TimeUnit.MILLISECONDS.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
deleteUserFromRobotPort.deleteUserFromRobot(key); deleteUserFromRobotPort.deleteUserFromRobot(key);
return Boolean.toString(result1); return Boolean.toString(result1);
} }
} }

View File

@ -23,7 +23,7 @@ public class Executor extends ExecutorBase {
int a = 20; int a = 20;
int b = 20; int b = 20;
try { try {
TimeUnit.SECONDS.sleep(10); TimeUnit.SECONDS.sleep(20);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -23,6 +23,7 @@ public class CompleteTaskWebController {
@PostMapping(path = "/tasks/completeTask", consumes = {TaskMediaType.TASK_MEDIA_TYPE}) @PostMapping(path = "/tasks/completeTask", consumes = {TaskMediaType.TASK_MEDIA_TYPE})
public ResponseEntity<String> completeTask (@RequestBody Task task){ public ResponseEntity<String> completeTask (@RequestBody Task task){
try { try {
CompleteTaskCommand command = new CompleteTaskCommand( CompleteTaskCommand command = new CompleteTaskCommand(
task.getTaskId(), task.getTaskResult() task.getTaskId(), task.getTaskResult()

View File

@ -27,9 +27,7 @@ public class PublishNewTaskAddedEventWebAdapter implements NewTaskAddedEventPort
//Here we would need to work with DTOs in case the payload of calls becomes more complex //Here we would need to work with DTOs in case the payload of calls becomes more complex
var values = new HashMap<String, String>() {{ var values = new HashMap<String, String>() {{
put("taskname",event.taskName); put("taskID", event.taskId);
put("tasklist",event.taskListName);
put("taskId", event.taskId);
put("taskType", event.taskType); put("taskType", event.taskType);
}}; }};
@ -43,11 +41,11 @@ public class PublishNewTaskAddedEventWebAdapter implements NewTaskAddedEventPort
HttpClient client = HttpClient.newHttpClient(); HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder() HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(server+"/roster/newtask/")) .uri(URI.create(server+"/task"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(requestBody)) .POST(HttpRequest.BodyPublishers.ofString(requestBody))
.build(); .build();
/** Needs the other service running
try { try {
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
} catch (IOException e) { } catch (IOException e) {
@ -55,6 +53,5 @@ public class PublishNewTaskAddedEventWebAdapter implements NewTaskAddedEventPort
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
**/
} }
} }

View File

@ -30,6 +30,7 @@ public class AddNewTaskToTaskListService implements AddNewTaskToTaskListUseCase
//the core and then the integration event in the application layer. //the core and then the integration event in the application layer.
if (newTask != null) { if (newTask != null) {
NewTaskAddedEvent newTaskAdded = new NewTaskAddedEvent(newTask.getTaskName().getValue(), NewTaskAddedEvent newTaskAdded = new NewTaskAddedEvent(newTask.getTaskName().getValue(),
taskList.getTaskListName().getValue(), newTask.getTaskId().getValue(), newTask.getTaskType().getValue());
newTaskAddedEventPort.publishNewTaskAddedEvent(newTaskAdded); newTaskAddedEventPort.publishNewTaskAddedEvent(newTaskAdded);
} }

View File

@ -18,6 +18,9 @@ public class DeleteTaskService implements DeleteTaskUseCase {
@Override @Override
public Optional<Task> deleteTask(DeleteTaskCommand command){ public Optional<Task> deleteTask(DeleteTaskCommand command){
// TODO check with assignment service if we can delte
TaskList taskList = TaskList.getTapasTaskList(); TaskList taskList = TaskList.getTapasTaskList();
return taskList.deleteTaskById(command.getTaskId()); return taskList.deleteTaskById(command.getTaskId());