diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..c4f3e5b
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,9 @@
+root = true
+
+[*]
+charset = utf-8
+indent_style = space
+indent_size = 4
+trim_trailing_whitespace = true
+end_of_line = lf
+insert_final_newline = true
diff --git a/executor1/.gitignore b/executor-base/.gitignore
similarity index 100%
rename from executor1/.gitignore
rename to executor-base/.gitignore
diff --git a/executor1/.mvn/wrapper/MavenWrapperDownloader.java b/executor-base/.mvn/wrapper/MavenWrapperDownloader.java
similarity index 100%
rename from executor1/.mvn/wrapper/MavenWrapperDownloader.java
rename to executor-base/.mvn/wrapper/MavenWrapperDownloader.java
diff --git a/executor1/.mvn/wrapper/maven-wrapper.jar b/executor-base/.mvn/wrapper/maven-wrapper.jar
similarity index 100%
rename from executor1/.mvn/wrapper/maven-wrapper.jar
rename to executor-base/.mvn/wrapper/maven-wrapper.jar
diff --git a/executor1/.mvn/wrapper/maven-wrapper.properties b/executor-base/.mvn/wrapper/maven-wrapper.properties
similarity index 100%
rename from executor1/.mvn/wrapper/maven-wrapper.properties
rename to executor-base/.mvn/wrapper/maven-wrapper.properties
diff --git a/executor1/Dockerfile b/executor-base/Dockerfile
similarity index 100%
rename from executor1/Dockerfile
rename to executor-base/Dockerfile
diff --git a/executor1/mvnw b/executor-base/mvnw
similarity index 100%
rename from executor1/mvnw
rename to executor-base/mvnw
diff --git a/executor1/mvnw.cmd b/executor-base/mvnw.cmd
similarity index 100%
rename from executor1/mvnw.cmd
rename to executor-base/mvnw.cmd
diff --git a/executor1/pom.xml b/executor-base/pom.xml
similarity index 77%
rename from executor1/pom.xml
rename to executor-base/pom.xml
index 1534025..6ad675a 100644
--- a/executor1/pom.xml
+++ b/executor-base/pom.xml
@@ -9,9 +9,9 @@
ch.unisg
- executor1
+ executorBase
0.0.1-SNAPSHOT
- executor1
+ executorBase
Demo project for Spring Boot
11
@@ -30,6 +30,10 @@
runtime
true
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
org.projectlombok
lombok
@@ -40,6 +44,18 @@
spring-boot-starter-test
test
+
+
+ javax.validation
+ validation-api
+ 1.1.0.Final
+
+
+
+ javax.transaction
+ javax.transaction-api
+ 1.2
+
diff --git a/executor1/src/main/java/ch/unisg/executor1/Executor1Application.java b/executor-base/src/main/java/ch/unisg/executorBase/Executor1Application.java
similarity index 90%
rename from executor1/src/main/java/ch/unisg/executor1/Executor1Application.java
rename to executor-base/src/main/java/ch/unisg/executorBase/Executor1Application.java
index 4eed560..9bd3fa5 100644
--- a/executor1/src/main/java/ch/unisg/executor1/Executor1Application.java
+++ b/executor-base/src/main/java/ch/unisg/executorBase/Executor1Application.java
@@ -1,4 +1,4 @@
-package ch.unisg.executor1;
+package ch.unisg.executorBase;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
diff --git a/executor-base/src/main/java/ch/unisg/executorBase/common/SelfValidating.java b/executor-base/src/main/java/ch/unisg/executorBase/common/SelfValidating.java
new file mode 100644
index 0000000..1d4a80a
--- /dev/null
+++ b/executor-base/src/main/java/ch/unisg/executorBase/common/SelfValidating.java
@@ -0,0 +1,29 @@
+package ch.unisg.executorBase.common;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.ConstraintViolationException;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+import java.util.Set;
+
+public class SelfValidating {
+
+ private Validator validator;
+
+ public SelfValidating() {
+ ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
+ validator = factory.getValidator();
+ }
+
+ /**
+ * Evaluates all Bean Validations on the attributes of this
+ * instance.
+ */
+ protected void validateSelf() {
+ Set> violations = validator.validate((T) this);
+ if (!violations.isEmpty()) {
+ throw new ConstraintViolationException(violations);
+ }
+ }
+}
diff --git a/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/in/web/TaskAvailableController.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/in/web/TaskAvailableController.java
new file mode 100644
index 0000000..75d3a02
--- /dev/null
+++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/in/web/TaskAvailableController.java
@@ -0,0 +1,36 @@
+package ch.unisg.executorBase.executor.adapter.in.web;
+
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RestController;
+
+import ch.unisg.executorBase.executor.application.port.in.TaskAvailableCommand;
+import ch.unisg.executorBase.executor.application.port.in.TaskAvailableUseCase;
+import ch.unisg.executorBase.executor.domain.ExecutorType;
+
+@RestController
+public class TaskAvailableController {
+ private final TaskAvailableUseCase taskAvailableUseCase;
+
+ public TaskAvailableController(TaskAvailableUseCase taskAvailableUseCase) {
+ this.taskAvailableUseCase = taskAvailableUseCase;
+ }
+
+ @GetMapping(path = "/newtask/{taskType}")
+ public ResponseEntity retrieveTaskFromTaskList(@PathVariable("taskType") String taskType) {
+
+ if (ExecutorType.contains(taskType.toUpperCase())) {
+ TaskAvailableCommand command = new TaskAvailableCommand(
+ ExecutorType.valueOf(taskType.toUpperCase()));
+ taskAvailableUseCase.newTaskAvailable(command);
+ }
+
+ // Add the content type as a response header
+ HttpHeaders responseHeaders = new HttpHeaders();
+
+ return new ResponseEntity<>("OK", responseHeaders, HttpStatus.OK);
+ }
+}
diff --git a/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/ExecutionFinishedEventAdapter.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/ExecutionFinishedEventAdapter.java
new file mode 100644
index 0000000..2f53a2b
--- /dev/null
+++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/ExecutionFinishedEventAdapter.java
@@ -0,0 +1,58 @@
+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.HashMap;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.core.JsonProcessingException;
+
+import ch.unisg.executorBase.executor.application.port.out.ExecutionFinishedEventPort;
+import ch.unisg.executorBase.executor.domain.ExecutionFinishedEvent;
+
+public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort {
+
+ //This is the base URI of the service interested in this event (in my setup, running locally as separate Spring Boot application)
+ String server = "http://127.0.0.1:8082";
+
+ @Override
+ public void publishExecutionFinishedEvent(ExecutionFinishedEvent event) {
+ ///Here we would need to work with DTOs in case the payload of calls becomes more complex
+
+ var values = new HashMap() {{
+ put("result",event.getResult());
+ put("status",event.getStatus());
+ }};
+
+ var objectMapper = new ObjectMapper();
+ String requestBody = null;
+ try {
+ requestBody = objectMapper.writeValueAsString(values);
+ } catch (JsonProcessingException e) {
+ e.printStackTrace();
+ }
+
+ HttpClient client = HttpClient.newHttpClient();
+ HttpRequest request = HttpRequest.newBuilder()
+ .uri(URI.create(server+"/task/"+event.getTaskID()))
+ .PUT(HttpRequest.BodyPublishers.ofString(requestBody))
+ .build();
+
+ /** Needs the other service running
+ try {
+ HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ **/
+
+ System.out.println("Finish execution event sent with result:" + event.getResult());
+
+ }
+
+}
diff --git a/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/GetAssignmentAdapter.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/GetAssignmentAdapter.java
new file mode 100644
index 0000000..b3e7875
--- /dev/null
+++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/GetAssignmentAdapter.java
@@ -0,0 +1,45 @@
+package ch.unisg.executorBase.executor.adapter.out.web;
+
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+
+import org.springframework.context.annotation.Primary;
+import org.springframework.stereotype.Component;
+
+import ch.unisg.executorBase.executor.application.port.out.GetAssignmentPort;
+import ch.unisg.executorBase.executor.domain.ExecutorType;
+import ch.unisg.executorBase.executor.domain.Task;
+
+@Component
+@Primary
+public class GetAssignmentAdapter implements GetAssignmentPort {
+
+ //This is the base URI of the service interested in this event (in my setup, running locally as separate Spring Boot application)
+ String server = "http://127.0.0.1:8082";
+
+ @Override
+ public Task getAssignment(ExecutorType executorType) {
+
+ HttpClient client = HttpClient.newHttpClient();
+ HttpRequest request = HttpRequest.newBuilder()
+ .uri(URI.create(server+"/assignment/" + executorType))
+ .GET()
+ .build();
+
+ /** Needs the other service running
+ try {
+ HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ **/
+
+ // TODO return null or a new Task here depending on the response of the http call
+
+ return new Task("123");
+ }
+
+}
diff --git a/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/NotifyExecutorPoolAdapter.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/NotifyExecutorPoolAdapter.java
new file mode 100644
index 0000000..feeca69
--- /dev/null
+++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/NotifyExecutorPoolAdapter.java
@@ -0,0 +1,62 @@
+package ch.unisg.executorBase.executor.adapter.out.web;
+
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.util.HashMap;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import org.springframework.context.annotation.Primary;
+import org.springframework.stereotype.Component;
+
+import ch.unisg.executorBase.executor.application.port.out.NotifyExecutorPoolPort;
+import ch.unisg.executorBase.executor.domain.ExecutorType;
+
+@Component
+@Primary
+public class NotifyExecutorPoolAdapter implements NotifyExecutorPoolPort {
+
+ //This is the base URI of the service interested in this event (in my setup, running locally as separate Spring Boot application)
+ String server = "http://127.0.0.1:8083";
+
+ @Override
+ public boolean notifyExecutorPool(String ip, int port, ExecutorType executorType) {
+
+ var values = new HashMap() {{
+ put("ip", ip);
+ put("port", Integer.toString(port));
+ put("executorType", executorType.toString());
+ }};
+
+ var objectMapper = new ObjectMapper();
+ String requestBody = null;
+ try {
+ requestBody = objectMapper.writeValueAsString(values);
+ } catch (JsonProcessingException e) {
+ e.printStackTrace();
+ }
+
+ HttpClient client = HttpClient.newHttpClient();
+ HttpRequest request = HttpRequest.newBuilder()
+ .uri(URI.create(server+"/executor/new/"))
+ .POST(HttpRequest.BodyPublishers.ofString(requestBody))
+ .build();
+
+ /** Needs the other service running
+ try {
+ HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ **/
+
+ // TODO return true or false depending on result of http request;
+
+ return true;
+ }
+
+}
diff --git a/executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/in/TaskAvailableCommand.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/in/TaskAvailableCommand.java
new file mode 100644
index 0000000..916c8eb
--- /dev/null
+++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/in/TaskAvailableCommand.java
@@ -0,0 +1,20 @@
+package ch.unisg.executorBase.executor.application.port.in;
+
+import ch.unisg.executorBase.common.SelfValidating;
+import ch.unisg.executorBase.executor.domain.ExecutorType;
+
+import javax.validation.constraints.NotNull;
+
+import lombok.Value;
+
+@Value
+public class TaskAvailableCommand extends SelfValidating {
+
+ @NotNull
+ private final ExecutorType taskType;
+
+ public TaskAvailableCommand(ExecutorType taskType) {
+ this.taskType = taskType;
+ this.validateSelf();
+ }
+}
diff --git a/executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/in/TaskAvailableUseCase.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/in/TaskAvailableUseCase.java
new file mode 100644
index 0000000..cc5215f
--- /dev/null
+++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/in/TaskAvailableUseCase.java
@@ -0,0 +1,5 @@
+package ch.unisg.executorBase.executor.application.port.in;
+
+public interface TaskAvailableUseCase {
+ void newTaskAvailable(TaskAvailableCommand command);
+}
diff --git a/executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/out/ExecutionFinishedEventPort.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/out/ExecutionFinishedEventPort.java
new file mode 100644
index 0000000..1bf668e
--- /dev/null
+++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/out/ExecutionFinishedEventPort.java
@@ -0,0 +1,7 @@
+package ch.unisg.executorBase.executor.application.port.out;
+
+import ch.unisg.executorBase.executor.domain.ExecutionFinishedEvent;
+
+public interface ExecutionFinishedEventPort {
+ void publishExecutionFinishedEvent(ExecutionFinishedEvent event);
+}
diff --git a/executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/out/GetAssignmentPort.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/out/GetAssignmentPort.java
new file mode 100644
index 0000000..1f205b8
--- /dev/null
+++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/out/GetAssignmentPort.java
@@ -0,0 +1,8 @@
+package ch.unisg.executorBase.executor.application.port.out;
+
+import ch.unisg.executorBase.executor.domain.ExecutorType;
+import ch.unisg.executorBase.executor.domain.Task;
+
+public interface GetAssignmentPort {
+ Task getAssignment(ExecutorType executorType);
+}
diff --git a/executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/out/NotifyExecutorPoolPort.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/out/NotifyExecutorPoolPort.java
new file mode 100644
index 0000000..6d41ab4
--- /dev/null
+++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/out/NotifyExecutorPoolPort.java
@@ -0,0 +1,7 @@
+package ch.unisg.executorBase.executor.application.port.out;
+
+import ch.unisg.executorBase.executor.domain.ExecutorType;
+
+public interface NotifyExecutorPoolPort {
+ boolean notifyExecutorPool(String ip, int port, ExecutorType executorType);
+}
diff --git a/executor-base/src/main/java/ch/unisg/executorBase/executor/application/service/NotifyExecutorPoolService.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/service/NotifyExecutorPoolService.java
new file mode 100644
index 0000000..a5ccb64
--- /dev/null
+++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/service/NotifyExecutorPoolService.java
@@ -0,0 +1,15 @@
+package ch.unisg.executorBase.executor.application.service;
+
+import ch.unisg.executorBase.executor.application.port.out.NotifyExecutorPoolPort;
+import ch.unisg.executorBase.executor.domain.ExecutorType;
+import lombok.RequiredArgsConstructor;
+
+@RequiredArgsConstructor
+public class NotifyExecutorPoolService {
+
+ private final NotifyExecutorPoolPort notifyExecutorPoolPort;
+
+ public boolean notifyExecutorPool(String ip, int port, ExecutorType executorType) {
+ return notifyExecutorPoolPort.notifyExecutorPool(ip, port, executorType);
+ }
+}
diff --git a/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutionFinishedEvent.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutionFinishedEvent.java
new file mode 100644
index 0000000..31fd0e6
--- /dev/null
+++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutionFinishedEvent.java
@@ -0,0 +1,21 @@
+package ch.unisg.executorBase.executor.domain;
+
+import lombok.Getter;
+
+public class ExecutionFinishedEvent {
+
+ @Getter
+ private String taskID;
+
+ @Getter
+ private String result;
+
+ @Getter
+ private String status;
+
+ public ExecutionFinishedEvent(String taskID, String result, String status) {
+ this.taskID = taskID;
+ this.result = result;
+ this.status = status;
+ }
+}
diff --git a/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorBase.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorBase.java
new file mode 100644
index 0000000..e639cb3
--- /dev/null
+++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorBase.java
@@ -0,0 +1,85 @@
+package ch.unisg.executorBase.executor.domain;
+
+import ch.unisg.executorBase.executor.application.port.out.ExecutionFinishedEventPort;
+import ch.unisg.executorBase.executor.application.port.out.GetAssignmentPort;
+import ch.unisg.executorBase.executor.application.port.out.NotifyExecutorPoolPort;
+
+import java.util.concurrent.TimeUnit;
+
+import javax.transaction.Transactional;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Configurable;
+
+import ch.unisg.executorBase.executor.adapter.out.web.ExecutionFinishedEventAdapter;
+import ch.unisg.executorBase.executor.adapter.out.web.GetAssignmentAdapter;
+import ch.unisg.executorBase.executor.adapter.out.web.NotifyExecutorPoolAdapter;
+import ch.unisg.executorBase.executor.application.service.NotifyExecutorPoolService;
+import lombok.Getter;
+
+public abstract class ExecutorBase {
+
+ @Getter
+ private String ip;
+
+ @Getter
+ private ExecutorType executorType;
+
+ @Getter
+ private int port;
+
+ @Getter
+ 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 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 NotifyExecutorPoolService notifyExecutorPoolService = new NotifyExecutorPoolService(notifyExecutorPoolPort);
+ private final GetAssignmentPort getAssignmentPort = new GetAssignmentAdapter();
+ private final ExecutionFinishedEventPort executionFinishedEventPort = new ExecutionFinishedEventAdapter();
+
+ public ExecutorBase(ExecutorType executorType) {
+ System.out.println("Starting Executor");
+ // TODO set this automaticly
+ this.ip = "localhost";
+ this.port = 8084;
+ this.executorType = executorType;
+
+ this.status = ExecutorStatus.STARTING_UP;
+ if(!notifyExecutorPoolService.notifyExecutorPool(this.ip, this.port, this.executorType)) {
+ System.exit(0);
+ } else {
+ System.out.println(true);
+ this.status = ExecutorStatus.IDLING;
+ getAssignment();
+ }
+ }
+
+ // public static ExecutorBase getExecutor() {
+ // return executor;
+ // }
+
+ public void getAssignment() {
+ Task newTask = getAssignmentPort.getAssignment(this.getExecutorType());
+ if (newTask != null) {
+ this.executeTask(newTask);
+ } else {
+ this.status = ExecutorStatus.IDLING;
+ }
+ }
+
+ private void executeTask(Task task) {
+ System.out.println("Starting execution");
+ this.status = ExecutorStatus.EXECUTING;
+
+ task.setResult(execution());
+
+ executionFinishedEventPort.publishExecutionFinishedEvent(new ExecutionFinishedEvent(task.getTaskID(), task.getResult(), "SUCCESS"));
+
+ System.out.println("Finish execution");
+ getAssignment();
+ }
+
+ protected abstract String execution();
+
+}
diff --git a/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorStatus.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorStatus.java
new file mode 100644
index 0000000..8bd5bc3
--- /dev/null
+++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorStatus.java
@@ -0,0 +1,7 @@
+package ch.unisg.executorBase.executor.domain;
+
+public enum ExecutorStatus {
+ STARTING_UP,
+ EXECUTING,
+ IDLING,
+}
diff --git a/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorType.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorType.java
new file mode 100644
index 0000000..0b2b305
--- /dev/null
+++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorType.java
@@ -0,0 +1,18 @@
+package ch.unisg.executorBase.executor.domain;
+
+public enum ExecutorType {
+ ADDITION, ROBOT;
+
+ public static boolean contains(String test) {
+
+ for (ExecutorType x : ExecutorType.values()) {
+ if (x.name().equals(test)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
+
+
+
diff --git a/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/Task.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/Task.java
new file mode 100644
index 0000000..6719613
--- /dev/null
+++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/Task.java
@@ -0,0 +1,20 @@
+package ch.unisg.executorBase.executor.domain;
+
+import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
+
+public class Task {
+
+ @Getter
+ private String taskID;
+
+ @Getter
+ @Setter
+ private String result;
+
+ public Task(String taskID) {
+ this.taskID = taskID;
+ }
+
+}
diff --git a/executor1/src/main/resources/application.properties b/executor-base/src/main/resources/application.properties
similarity index 100%
rename from executor1/src/main/resources/application.properties
rename to executor-base/src/main/resources/application.properties
diff --git a/executor1/src/test/java/ch/unisg/executor1/Executor1ApplicationTests.java b/executor-base/src/test/java/ch/unisg/executorBase/Executor1ApplicationTests.java
similarity index 68%
rename from executor1/src/test/java/ch/unisg/executor1/Executor1ApplicationTests.java
rename to executor-base/src/test/java/ch/unisg/executorBase/Executor1ApplicationTests.java
index 889c9cd..6fec034 100644
--- a/executor1/src/test/java/ch/unisg/executor1/Executor1ApplicationTests.java
+++ b/executor-base/src/test/java/ch/unisg/executorBase/Executor1ApplicationTests.java
@@ -1,10 +1,10 @@
-package ch.unisg.executor1;
+package ch.unisg.executorBase;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
-class Executor1ApplicationTests {
+class executorBaseApplicationTests {
@Test
void contextLoads() {
diff --git a/executor1/src/main/java/ch/unisg/executor1/TestController.java b/executor1/src/main/java/ch/unisg/executor1/TestController.java
deleted file mode 100644
index a2f32b4..0000000
--- a/executor1/src/main/java/ch/unisg/executor1/TestController.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package ch.unisg.executor1;
-
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-@RestController
-public class TestController {
- @RequestMapping("/")
- public String index() {
- return "Hello World! Executor1";
- }
-}
diff --git a/executor2/pom.xml b/executor2/pom.xml
index 681cebd..95c67ff 100644
--- a/executor2/pom.xml
+++ b/executor2/pom.xml
@@ -40,6 +40,11 @@
spring-boot-starter-test
test
+
+ ch.unisg
+ executorBase
+ 0.0.1-SNAPSHOT
+
diff --git a/executor2/src/main/java/ch/unisg/executor2/Executor2Application.java b/executor2/src/main/java/ch/unisg/executor2/Executor2Application.java
index d31e277..03edb3d 100644
--- a/executor2/src/main/java/ch/unisg/executor2/Executor2Application.java
+++ b/executor2/src/main/java/ch/unisg/executor2/Executor2Application.java
@@ -3,11 +3,14 @@ package ch.unisg.executor2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import ch.unisg.executor2.executor.domain.Executor;
+
@SpringBootApplication
public class Executor2Application {
public static void main(String[] args) {
SpringApplication.run(Executor2Application.class, args);
+ Executor.getExecutor();
}
}
diff --git a/executor2/src/main/java/ch/unisg/executor2/TestController.java b/executor2/src/main/java/ch/unisg/executor2/TestController.java
deleted file mode 100644
index c98bb02..0000000
--- a/executor2/src/main/java/ch/unisg/executor2/TestController.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package ch.unisg.executor2;
-
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-@RestController
-public class TestController {
- @RequestMapping("/")
- public String index() {
- return "Hello World! Executor2";
- }
-}
diff --git a/executor2/src/main/java/ch/unisg/executor2/executor/application/service/TaskAvailableService.java b/executor2/src/main/java/ch/unisg/executor2/executor/application/service/TaskAvailableService.java
new file mode 100644
index 0000000..4484ebb
--- /dev/null
+++ b/executor2/src/main/java/ch/unisg/executor2/executor/application/service/TaskAvailableService.java
@@ -0,0 +1,28 @@
+package ch.unisg.executor2.executor.application.service;
+
+import org.springframework.stereotype.Component;
+
+import ch.unisg.executor2.executor.domain.Executor;
+import ch.unisg.executorBase.executor.application.port.in.TaskAvailableCommand;
+import ch.unisg.executorBase.executor.application.port.in.TaskAvailableUseCase;
+import ch.unisg.executorBase.executor.domain.ExecutorStatus;
+import lombok.RequiredArgsConstructor;
+
+import javax.transaction.Transactional;
+
+@RequiredArgsConstructor
+@Component
+@Transactional
+public class TaskAvailableService implements TaskAvailableUseCase {
+
+ @Override
+ public void newTaskAvailable(TaskAvailableCommand command) {
+
+ Executor executor = Executor.getExecutor();
+
+ if (executor.getExecutorType() == command.getTaskType() &&
+ executor.getStatus() == ExecutorStatus.IDLING) {
+ executor.getAssignment();
+ }
+ }
+}
diff --git a/executor2/src/main/java/ch/unisg/executor2/executor/domain/Executor.java b/executor2/src/main/java/ch/unisg/executor2/executor/domain/Executor.java
new file mode 100644
index 0000000..bb9308b
--- /dev/null
+++ b/executor2/src/main/java/ch/unisg/executor2/executor/domain/Executor.java
@@ -0,0 +1,36 @@
+package ch.unisg.executor2.executor.domain;
+
+import java.util.concurrent.TimeUnit;
+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.ADDITION);
+
+ public static Executor getExecutor() {
+ return executor;
+ }
+
+ private Executor(ExecutorType executorType) {
+ super(executorType);
+ }
+
+ @Override
+ protected
+ String execution() {
+
+ int a = 20;
+ int b = 20;
+ try {
+ TimeUnit.SECONDS.sleep(10);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ int result = a + b;
+
+ return Integer.toString(result);
+ }
+
+}
diff --git a/tapas-tasks/src/main/java/ch/unisg/tapastasks/TapasTasksApplication.java b/tapas-tasks/src/main/java/ch/unisg/tapastasks/TapasTasksApplication.java
index 40fa5da..90d1716 100644
--- a/tapas-tasks/src/main/java/ch/unisg/tapastasks/TapasTasksApplication.java
+++ b/tapas-tasks/src/main/java/ch/unisg/tapastasks/TapasTasksApplication.java
@@ -10,8 +10,8 @@ public class TapasTasksApplication {
public static void main(String[] args) {
- SpringApplication tapasTasksApp = new SpringApplication(TapasTasksApplication.class);
- tapasTasksApp.run(args);
+ SpringApplication tapasTasksApp = new SpringApplication(TapasTasksApplication.class);
+ tapasTasksApp.run(args);
}
}