integration + fixes
This commit is contained in:
parent
8b0eea1270
commit
f461c5f3cb
|
@ -41,17 +41,68 @@ services:
|
||||||
- "traefik.http.routers.tapas-tasks.entryPoints=web,websecure"
|
- "traefik.http.routers.tapas-tasks.entryPoints=web,websecure"
|
||||||
- "traefik.http.routers.tapas-tasks.tls.certresolver=le"
|
- "traefik.http.routers.tapas-tasks.tls.certresolver=le"
|
||||||
|
|
||||||
app:
|
assignment:
|
||||||
image: openjdk
|
image: openjdk
|
||||||
command: "java -jar /data/app-0.1.0.jar"
|
command: "java -jar /data/assignment-0.0.1.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.assignment.rule=Host(`assignment.${PUB_IP}.nip.io`)"
|
||||||
- "traefik.http.routers.app.service=app"
|
- "traefik.http.routers.assignment.service=assignment"
|
||||||
- "traefik.http.services.app.loadbalancer.server.port=8080"
|
- "traefik.http.services.assignment.loadbalancer.server.port=8082"
|
||||||
- "traefik.http.routers.app.tls=true"
|
- "traefik.http.routers.assignment.tls=true"
|
||||||
- "traefik.http.routers.app.entryPoints=web,websecure"
|
- "traefik.http.routers.assignment.entryPoints=web,websecure"
|
||||||
- "traefik.http.routers.app.tls.certresolver=le"
|
- "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"
|
||||||
|
|
3
.github/workflows/build-and-deploy.yml
vendored
3
.github/workflows/build-and-deploy.yml
vendored
|
@ -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
|
||||||
|
|
44
app/pom.xml
44
app/pom.xml
|
@ -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>
|
|
|
@ -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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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);
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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) {
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
**/
|
|
||||||
|
|
||||||
// TODO return true or false depending on result of http request;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} catch (IOException | InterruptedException e) {
|
||||||
|
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||||
|
// Restore interrupted state...
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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() { }
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
server.port=8081
|
server.port=8083
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -33,7 +33,19 @@ public class Executor extends ExecutorBase {
|
||||||
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);
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
**/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user