integration + fixes
This commit is contained in:
parent
8b0eea1270
commit
f461c5f3cb
|
@ -1,57 +1,108 @@
|
|||
version: "3.0"
|
||||
|
||||
services:
|
||||
reverse-proxy:
|
||||
image: traefik:v2.1.3
|
||||
command:
|
||||
- --entrypoints.web.address=:80
|
||||
- --entrypoints.websecure.address=:443
|
||||
- --providers.docker=true
|
||||
- --certificatesResolvers.le.acme.httpChallenge.entryPoint=web
|
||||
- --certificatesresolvers.le.acme.email=martin.eigenmann@unisg.ch
|
||||
- --certificatesresolvers.le.acme.storage=/acme.json
|
||||
- --providers.docker.exposedByDefault=false
|
||||
- --serversTransport.insecureSkipVerify=true
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- ./acme.json:/acme.json
|
||||
restart: unless-stopped
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.http-catchall.rule=hostregexp(`{host:.+}`)"
|
||||
- "traefik.http.routers.http-catchall.entrypoints=web"
|
||||
- "traefik.http.routers.http-catchall.middlewares=redirect-to-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"
|
||||
reverse-proxy:
|
||||
image: traefik:v2.1.3
|
||||
command:
|
||||
- --entrypoints.web.address=:80
|
||||
- --entrypoints.websecure.address=:443
|
||||
- --providers.docker=true
|
||||
- --certificatesResolvers.le.acme.httpChallenge.entryPoint=web
|
||||
- --certificatesresolvers.le.acme.email=martin.eigenmann@unisg.ch
|
||||
- --certificatesresolvers.le.acme.storage=/acme.json
|
||||
- --providers.docker.exposedByDefault=false
|
||||
- --serversTransport.insecureSkipVerify=true
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- ./acme.json:/acme.json
|
||||
restart: unless-stopped
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.http-catchall.rule=hostregexp(`{host:.+}`)"
|
||||
- "traefik.http.routers.http-catchall.entrypoints=web"
|
||||
- "traefik.http.routers.http-catchall.middlewares=redirect-to-https"
|
||||
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
|
||||
|
||||
app:
|
||||
image: openjdk
|
||||
command: "java -jar /data/app-0.1.0.jar"
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- ./:/data/
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.app.rule=Host(`app.${PUB_IP}.nip.io`)"
|
||||
- "traefik.http.routers.app.service=app"
|
||||
- "traefik.http.services.app.loadbalancer.server.port=8080"
|
||||
- "traefik.http.routers.app.tls=true"
|
||||
- "traefik.http.routers.app.entryPoints=web,websecure"
|
||||
- "traefik.http.routers.app.tls.certresolver=le"
|
||||
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"
|
||||
|
||||
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"
|
||||
|
|
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: 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
|
||||
run: mvn -f executor1/pom.xml --batch-mode --update-snapshots verify
|
||||
- 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"})
|
||||
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());
|
||||
|
||||
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
|
||||
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());
|
||||
|
||||
|
@ -32,6 +33,21 @@ public class PublishNewTaskEventAdapter implements NewTaskEventPort {
|
|||
.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 {
|
||||
client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
} catch (IOException | InterruptedException e) {
|
||||
|
|
|
@ -19,7 +19,7 @@ import ch.unisg.assignment.assignment.domain.event.TaskAssignedEvent;
|
|||
@Primary
|
||||
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());
|
||||
|
||||
|
@ -32,7 +32,7 @@ public class PublishTaskAssignedEventAdapter implements TaskAssignedEventPort {
|
|||
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(server + "/tasks/completeTask"))
|
||||
.uri(URI.create(server + "/tasks/assignTask"))
|
||||
.header("Content-Type", "application/json")
|
||||
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||
.build();
|
||||
|
|
|
@ -2,7 +2,6 @@ package ch.unisg.assignment.assignment.application.port.in;
|
|||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import ch.unisg.assignment.assignment.domain.valueobject.ExecutorType;
|
||||
import ch.unisg.assignment.common.SelfValidating;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Value;
|
||||
|
@ -14,18 +13,14 @@ public class TaskCompletedCommand extends SelfValidating<TaskCompletedCommand>{
|
|||
@NotNull
|
||||
private final String taskID;
|
||||
|
||||
@NotNull
|
||||
private final ExecutorType taskType;
|
||||
|
||||
@NotNull
|
||||
private final String taskStatus;
|
||||
|
||||
@NotNull
|
||||
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.taskType = taskType;
|
||||
this.taskStatus = taskStatus;
|
||||
this.taskResult = taskResult;
|
||||
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.NewTaskUseCase;
|
||||
import ch.unisg.assignment.assignment.application.port.out.GetAllExecutorInExecutorPoolByTypePort;
|
||||
import ch.unisg.assignment.assignment.application.port.out.NewTaskEventPort;
|
||||
import ch.unisg.assignment.assignment.domain.Roster;
|
||||
import ch.unisg.assignment.assignment.domain.Task;
|
||||
|
@ -21,14 +22,13 @@ import lombok.RequiredArgsConstructor;
|
|||
public class NewTaskService implements NewTaskUseCase {
|
||||
|
||||
private final NewTaskEventPort newTaskEventPort;
|
||||
private final GetAllExecutorInExecutorPoolByTypePort getAllExecutorInExecutorPoolByTypePort;
|
||||
|
||||
@Override
|
||||
public boolean addNewTaskToQueue(NewTaskCommand command) {
|
||||
|
||||
// TODO Get availableTaskTypes from executor pool
|
||||
List<String> availableTaskTypes = Arrays.asList("ADDITION", "ROBOT");
|
||||
|
||||
if (!availableTaskTypes.contains(command.getTaskType().getValue())) {
|
||||
if (!getAllExecutorInExecutorPoolByTypePort.doesExecutorTypeExist(command.getTaskType())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,9 +30,9 @@ public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort
|
|||
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(server+"/task/"+event.getTaskID()))
|
||||
.uri(URI.create(server+"/task/completed"))
|
||||
.header("Content-Type", "application/json")
|
||||
.PUT(HttpRequest.BodyPublishers.ofString(body))
|
||||
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||
.build();
|
||||
|
||||
try {
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
package ch.unisg.executorBase.executor.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.JSONObject;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
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";
|
||||
|
||||
Logger logger = Logger.getLogger(NotifyExecutorPoolAdapter.class.getName());
|
||||
|
||||
@Override
|
||||
public boolean notifyExecutorPool(String ip, int port, ExecutorType executorType) {
|
||||
|
||||
String body = new JSONObject()
|
||||
.put("executorType", executorType)
|
||||
.put("ip", ip)
|
||||
.put("port", port)
|
||||
.put("executorTaskType", executorType)
|
||||
.put("executorIp", ip)
|
||||
.put("executorPort", Integer.toString(port))
|
||||
.toString();
|
||||
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
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))
|
||||
.build();
|
||||
|
||||
/** Needs the other service running
|
||||
try {
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
if (response.statusCode() == HttpStatus.CREATED.value()) {
|
||||
return true;
|
||||
}
|
||||
} 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 true;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,10 +23,15 @@ final public class ExecutorMediaType {
|
|||
String serializedList = "[ \n";
|
||||
|
||||
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() { }
|
||||
|
|
|
@ -2,7 +2,6 @@ package ch.unisg.executorpool.adapter.in.web;
|
|||
|
||||
import ch.unisg.executorpool.application.port.in.GetAllExecutorsInExecutorPoolUseCase;
|
||||
import ch.unisg.executorpool.domain.ExecutorClass;
|
||||
import ch.unisg.tapastasks.tasks.adapter.in.web.TaskMediaType;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
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;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -25,7 +27,7 @@ public class TaskAvailableController {
|
|||
if (ExecutorType.contains(taskType.toUpperCase())) {
|
||||
TaskAvailableCommand command = new TaskAvailableCommand(
|
||||
ExecutorType.valueOf(taskType.toUpperCase()));
|
||||
taskAvailableUseCase.newTaskAvailable(command);
|
||||
CompletableFuture.runAsync(() -> taskAvailableUseCase.newTaskAvailable(command));
|
||||
}
|
||||
|
||||
// Add the content type as a response header
|
||||
|
|
|
@ -14,7 +14,7 @@ import ch.unisg.executorBase.executor.domain.ExecutorBase;
|
|||
import ch.unisg.executorBase.executor.domain.ExecutorType;
|
||||
|
||||
public class Executor extends ExecutorBase {
|
||||
|
||||
|
||||
private static final Executor executor = new Executor(ExecutorType.ROBOT);
|
||||
private final UserToRobotPort userToRobotPort = new UserToRobotAdapter();
|
||||
private final InstructionToRobotPort instructionToRobotPort = new InstructionToRobotAdapter();
|
||||
|
@ -31,12 +31,24 @@ public class Executor extends ExecutorBase {
|
|||
@Override
|
||||
protected
|
||||
String execution() {
|
||||
|
||||
|
||||
String key = userToRobotPort.userToRobot();
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(1500);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
boolean result1 = instructionToRobotPort.instructionToRobot(key);
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(10000);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
deleteUserFromRobotPort.deleteUserFromRobot(key);
|
||||
|
||||
return Boolean.toString(result1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public class Executor extends ExecutorBase {
|
|||
int a = 20;
|
||||
int b = 20;
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(10);
|
||||
TimeUnit.SECONDS.sleep(20);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ public class CompleteTaskWebController {
|
|||
|
||||
@PostMapping(path = "/tasks/completeTask", consumes = {TaskMediaType.TASK_MEDIA_TYPE})
|
||||
public ResponseEntity<String> completeTask (@RequestBody Task task){
|
||||
|
||||
try {
|
||||
CompleteTaskCommand command = new CompleteTaskCommand(
|
||||
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
|
||||
|
||||
var values = new HashMap<String, String>() {{
|
||||
put("taskname",event.taskName);
|
||||
put("tasklist",event.taskListName);
|
||||
put("taskId", event.taskId);
|
||||
put("taskID", event.taskId);
|
||||
put("taskType", event.taskType);
|
||||
}};
|
||||
|
||||
|
@ -43,11 +41,11 @@ public class PublishNewTaskAddedEventWebAdapter implements NewTaskAddedEventPort
|
|||
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
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))
|
||||
.build();
|
||||
|
||||
/** Needs the other service running
|
||||
try {
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
} catch (IOException e) {
|
||||
|
@ -55,6 +53,5 @@ public class PublishNewTaskAddedEventWebAdapter implements NewTaskAddedEventPort
|
|||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
**/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ public class AddNewTaskToTaskListService implements AddNewTaskToTaskListUseCase
|
|||
//the core and then the integration event in the application layer.
|
||||
if (newTask != null) {
|
||||
NewTaskAddedEvent newTaskAdded = new NewTaskAddedEvent(newTask.getTaskName().getValue(),
|
||||
taskList.getTaskListName().getValue(), newTask.getTaskId().getValue(), newTask.getTaskType().getValue());
|
||||
newTaskAddedEventPort.publishNewTaskAddedEvent(newTaskAdded);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@ public class DeleteTaskService implements DeleteTaskUseCase {
|
|||
|
||||
@Override
|
||||
public Optional<Task> deleteTask(DeleteTaskCommand command){
|
||||
|
||||
// TODO check with assignment service if we can delte
|
||||
|
||||
TaskList taskList = TaskList.getTapasTaskList();
|
||||
return taskList.deleteTaskById(command.getTaskId());
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user