From 1d78bb63abb03a7c4898ed5f98372b9df3153064 Mon Sep 17 00:00:00 2001 From: Marcel Date: Mon, 11 Oct 2021 19:21:22 +0200 Subject: [PATCH 1/4] basic implementation of an executor --- .editorconfig | 12 +++ executor1/pom.xml | 16 ++++ .../unisg/executor1/Executor1Application.java | 3 + .../ch/unisg/executor1/TestController.java | 12 --- .../executor1/common/SelfValidating.java | 29 ++++++ .../in/web/TaskAvailableController.java | 32 +++++++ .../out/web/ExecutionFinishedAdapter.java | 58 ++++++++++++ .../adapter/out/web/GetAssignmentAdapter.java | 44 +++++++++ .../out/web/NotifyExecutorPoolAdapter.java | 61 ++++++++++++ .../port/in/TaskAvailableCommand.java | 19 ++++ .../port/in/TaskAvailableUseCase.java | 5 + .../port/out/ExecutionFinishedEventPort.java | 7 ++ .../port/out/GetAssignmentPort.java | 7 ++ .../port/out/NotifyExecutorPoolPort.java | 5 + .../service/NotifyExecutorPoolService.java | 17 ++++ .../service/TaskAvailableService.java | 27 ++++++ .../domain/ExecutionFinishedEvent.java | 21 +++++ .../executor1/executor/domain/Executor.java | 93 +++++++++++++++++++ .../executor/domain/ExecutorStatus.java | 7 ++ .../unisg/executor1/executor/domain/Task.java | 20 ++++ .../tapastasks/TapasTasksApplication.java | 4 +- 21 files changed, 485 insertions(+), 14 deletions(-) create mode 100644 .editorconfig delete mode 100644 executor1/src/main/java/ch/unisg/executor1/TestController.java create mode 100644 executor1/src/main/java/ch/unisg/executor1/common/SelfValidating.java create mode 100644 executor1/src/main/java/ch/unisg/executor1/executor/adapter/in/web/TaskAvailableController.java create mode 100644 executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/ExecutionFinishedAdapter.java create mode 100644 executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/GetAssignmentAdapter.java create mode 100644 executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/NotifyExecutorPoolAdapter.java create mode 100644 executor1/src/main/java/ch/unisg/executor1/executor/application/port/in/TaskAvailableCommand.java create mode 100644 executor1/src/main/java/ch/unisg/executor1/executor/application/port/in/TaskAvailableUseCase.java create mode 100644 executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/ExecutionFinishedEventPort.java create mode 100644 executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/GetAssignmentPort.java create mode 100644 executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/NotifyExecutorPoolPort.java create mode 100644 executor1/src/main/java/ch/unisg/executor1/executor/application/service/NotifyExecutorPoolService.java create mode 100644 executor1/src/main/java/ch/unisg/executor1/executor/application/service/TaskAvailableService.java create mode 100644 executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutionFinishedEvent.java create mode 100644 executor1/src/main/java/ch/unisg/executor1/executor/domain/Executor.java create mode 100644 executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutorStatus.java create mode 100644 executor1/src/main/java/ch/unisg/executor1/executor/domain/Task.java diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..74c6104 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true + +[*.{java}] +indent_style = space +indent_size = 4 +tab_width = 4 +trim_trailing_whitespace = true +max_line_length = 100 diff --git a/executor1/pom.xml b/executor1/pom.xml index 1534025..8df7a04 100644 --- a/executor1/pom.xml +++ b/executor1/pom.xml @@ -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/executor1/src/main/java/ch/unisg/executor1/Executor1Application.java index 4eed560..dfb8d8c 100644 --- a/executor1/src/main/java/ch/unisg/executor1/Executor1Application.java +++ b/executor1/src/main/java/ch/unisg/executor1/Executor1Application.java @@ -3,11 +3,14 @@ package ch.unisg.executor1; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import ch.unisg.executor1.executor.domain.Executor; + @SpringBootApplication public class Executor1Application { public static void main(String[] args) { SpringApplication.run(Executor1Application.class, args); + Executor.getExecutor(); } } 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/executor1/src/main/java/ch/unisg/executor1/common/SelfValidating.java b/executor1/src/main/java/ch/unisg/executor1/common/SelfValidating.java new file mode 100644 index 0000000..bc9816a --- /dev/null +++ b/executor1/src/main/java/ch/unisg/executor1/common/SelfValidating.java @@ -0,0 +1,29 @@ +package ch.unisg.executor1.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/executor1/src/main/java/ch/unisg/executor1/executor/adapter/in/web/TaskAvailableController.java b/executor1/src/main/java/ch/unisg/executor1/executor/adapter/in/web/TaskAvailableController.java new file mode 100644 index 0000000..14dc3e6 --- /dev/null +++ b/executor1/src/main/java/ch/unisg/executor1/executor/adapter/in/web/TaskAvailableController.java @@ -0,0 +1,32 @@ +package ch.unisg.executor1.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.executor1.executor.application.port.in.TaskAvailableCommand; +import ch.unisg.executor1.executor.application.port.in.TaskAvailableUseCase; + +@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) { + TaskAvailableCommand command = new TaskAvailableCommand(taskType); + + 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/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/ExecutionFinishedAdapter.java b/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/ExecutionFinishedAdapter.java new file mode 100644 index 0000000..e1c3a5d --- /dev/null +++ b/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/ExecutionFinishedAdapter.java @@ -0,0 +1,58 @@ +package ch.unisg.executor1.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.executor1.executor.application.port.out.ExecutionFinishedEventPort; +import ch.unisg.executor1.executor.domain.ExecutionFinishedEvent; + +public class ExecutionFinishedAdapter 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"); + + } + +} diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/GetAssignmentAdapter.java b/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/GetAssignmentAdapter.java new file mode 100644 index 0000000..2c32f84 --- /dev/null +++ b/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/GetAssignmentAdapter.java @@ -0,0 +1,44 @@ +package ch.unisg.executor1.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.executor1.executor.application.port.out.GetAssignmentPort; +import ch.unisg.executor1.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(String 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("1234"); + } + +} diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/NotifyExecutorPoolAdapter.java b/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/NotifyExecutorPoolAdapter.java new file mode 100644 index 0000000..866ab91 --- /dev/null +++ b/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/NotifyExecutorPoolAdapter.java @@ -0,0 +1,61 @@ +package ch.unisg.executor1.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.executor1.executor.application.port.out.NotifyExecutorPoolPort; + +@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, String executorType) { + + var values = new HashMap() {{ + put("ip", ip); + put("port", Integer.toString(port)); + put("executorType", executorType); + }}; + + 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/executor1/src/main/java/ch/unisg/executor1/executor/application/port/in/TaskAvailableCommand.java b/executor1/src/main/java/ch/unisg/executor1/executor/application/port/in/TaskAvailableCommand.java new file mode 100644 index 0000000..a5d530d --- /dev/null +++ b/executor1/src/main/java/ch/unisg/executor1/executor/application/port/in/TaskAvailableCommand.java @@ -0,0 +1,19 @@ +package ch.unisg.executor1.executor.application.port.in; + +import ch.unisg.executor1.common.SelfValidating; + +import javax.validation.constraints.NotNull; + +import lombok.Value; + +@Value +public class TaskAvailableCommand extends SelfValidating { + + @NotNull + private final String taskType; + + public TaskAvailableCommand(String taskType) { + this.taskType = taskType; + this.validateSelf(); + } +} diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/application/port/in/TaskAvailableUseCase.java b/executor1/src/main/java/ch/unisg/executor1/executor/application/port/in/TaskAvailableUseCase.java new file mode 100644 index 0000000..d8184c1 --- /dev/null +++ b/executor1/src/main/java/ch/unisg/executor1/executor/application/port/in/TaskAvailableUseCase.java @@ -0,0 +1,5 @@ +package ch.unisg.executor1.executor.application.port.in; + +public interface TaskAvailableUseCase { + void newTaskAvailable(TaskAvailableCommand command); +} diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/ExecutionFinishedEventPort.java b/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/ExecutionFinishedEventPort.java new file mode 100644 index 0000000..6bfea70 --- /dev/null +++ b/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/ExecutionFinishedEventPort.java @@ -0,0 +1,7 @@ +package ch.unisg.executor1.executor.application.port.out; + +import ch.unisg.executor1.executor.domain.ExecutionFinishedEvent; + +public interface ExecutionFinishedEventPort { + void publishExecutionFinishedEvent(ExecutionFinishedEvent event); +} diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/GetAssignmentPort.java b/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/GetAssignmentPort.java new file mode 100644 index 0000000..bbf9124 --- /dev/null +++ b/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/GetAssignmentPort.java @@ -0,0 +1,7 @@ +package ch.unisg.executor1.executor.application.port.out; + +import ch.unisg.executor1.executor.domain.Task; + +public interface GetAssignmentPort { + Task getAssignment(String executorType); +} diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/NotifyExecutorPoolPort.java b/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/NotifyExecutorPoolPort.java new file mode 100644 index 0000000..856163f --- /dev/null +++ b/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/NotifyExecutorPoolPort.java @@ -0,0 +1,5 @@ +package ch.unisg.executor1.executor.application.port.out; + +public interface NotifyExecutorPoolPort { + boolean notifyExecutorPool(String ip, int port, String executorType); +} diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/application/service/NotifyExecutorPoolService.java b/executor1/src/main/java/ch/unisg/executor1/executor/application/service/NotifyExecutorPoolService.java new file mode 100644 index 0000000..0c05fda --- /dev/null +++ b/executor1/src/main/java/ch/unisg/executor1/executor/application/service/NotifyExecutorPoolService.java @@ -0,0 +1,17 @@ +package ch.unisg.executor1.executor.application.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import ch.unisg.executor1.executor.application.port.out.NotifyExecutorPoolPort; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class NotifyExecutorPoolService { + + private final NotifyExecutorPoolPort notifyExecutorPoolPort; + + public boolean notifyExecutorPool(String ip, int port, String executorType) { + return notifyExecutorPoolPort.notifyExecutorPool(ip, port, executorType); + } +} diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/application/service/TaskAvailableService.java b/executor1/src/main/java/ch/unisg/executor1/executor/application/service/TaskAvailableService.java new file mode 100644 index 0000000..795cd8b --- /dev/null +++ b/executor1/src/main/java/ch/unisg/executor1/executor/application/service/TaskAvailableService.java @@ -0,0 +1,27 @@ +package ch.unisg.executor1.executor.application.service; + +import org.springframework.stereotype.Component; + +import ch.unisg.executor1.executor.application.port.in.TaskAvailableCommand; +import ch.unisg.executor1.executor.application.port.in.TaskAvailableUseCase; +import ch.unisg.executor1.executor.domain.Executor; +import ch.unisg.executor1.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().equalsIgnoreCase(command.getTaskType()) && + executor.getStatus() == ExecutorStatus.IDLING) { + executor.getAssignment(); + } + } +} diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutionFinishedEvent.java b/executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutionFinishedEvent.java new file mode 100644 index 0000000..4455572 --- /dev/null +++ b/executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutionFinishedEvent.java @@ -0,0 +1,21 @@ +package ch.unisg.executor1.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/executor1/src/main/java/ch/unisg/executor1/executor/domain/Executor.java b/executor1/src/main/java/ch/unisg/executor1/executor/domain/Executor.java new file mode 100644 index 0000000..6329f29 --- /dev/null +++ b/executor1/src/main/java/ch/unisg/executor1/executor/domain/Executor.java @@ -0,0 +1,93 @@ +package ch.unisg.executor1.executor.domain; + +import ch.unisg.executor1.executor.application.port.out.ExecutionFinishedEventPort; +import ch.unisg.executor1.executor.application.port.out.GetAssignmentPort; +import ch.unisg.executor1.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.executor1.executor.adapter.out.web.ExecutionFinishedAdapter; +import ch.unisg.executor1.executor.adapter.out.web.GetAssignmentAdapter; +import ch.unisg.executor1.executor.adapter.out.web.NotifyExecutorPoolAdapter; +import ch.unisg.executor1.executor.application.service.NotifyExecutorPoolService; +import lombok.Getter; + +public class Executor { + + @Getter + private String ip; + + @Getter + private String executorType = "addition"; + + @Getter + private int port; + + @Getter + private ExecutorStatus status; + + private static final Executor executor = new Executor(); + + // 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 ExecutionFinishedAdapter(); + + private Executor() { + System.out.println("Starting Executor"); + // TODO set this automaticly + this.ip = "localhost"; + this.port = 8084; + + 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 Executor 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; + int a = 10; + int b = 20; + try { + TimeUnit.SECONDS.sleep(10); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + int result = a + b; + + task.setResult(Integer.toString(result)); + + executionFinishedEventPort.publishExecutionFinishedEvent(new ExecutionFinishedEvent(task.getTaskID(), task.getResult(), "SUCCESS")); + + System.out.println("Finish execution"); + getAssignment(); + } + +} diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutorStatus.java b/executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutorStatus.java new file mode 100644 index 0000000..92af024 --- /dev/null +++ b/executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutorStatus.java @@ -0,0 +1,7 @@ +package ch.unisg.executor1.executor.domain; + +public enum ExecutorStatus { + STARTING_UP, + EXECUTING, + IDLING, +} diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/domain/Task.java b/executor1/src/main/java/ch/unisg/executor1/executor/domain/Task.java new file mode 100644 index 0000000..2287b6c --- /dev/null +++ b/executor1/src/main/java/ch/unisg/executor1/executor/domain/Task.java @@ -0,0 +1,20 @@ +package ch.unisg.executor1.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/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); } } -- 2.45.1 From 3bc39b70aa6e62ee52edc375f97c74c4a73ccaef Mon Sep 17 00:00:00 2001 From: Marcel Date: Mon, 11 Oct 2021 21:20:45 +0200 Subject: [PATCH 2/4] Added abstraction --- .../in/web/TaskAvailableController.java | 10 ++- ...ava => ExecutionFinishedEventAdapter.java} | 4 +- .../adapter/out/web/GetAssignmentAdapter.java | 5 +- .../out/web/NotifyExecutorPoolAdapter.java | 5 +- .../port/in/TaskAvailableCommand.java | 5 +- .../port/out/GetAssignmentPort.java | 3 +- .../port/out/NotifyExecutorPoolPort.java | 4 +- .../service/NotifyExecutorPoolService.java | 3 +- .../service/TaskAvailableService.java | 2 +- .../executor1/executor/domain/Executor.java | 78 ++--------------- .../executor/domain/ExecutorBase.java | 87 +++++++++++++++++++ .../executor/domain/ExecutorType.java | 18 ++++ 12 files changed, 140 insertions(+), 84 deletions(-) rename executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/{ExecutionFinishedAdapter.java => ExecutionFinishedEventAdapter.java} (91%) create mode 100644 executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutorBase.java create mode 100644 executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutorType.java diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/adapter/in/web/TaskAvailableController.java b/executor1/src/main/java/ch/unisg/executor1/executor/adapter/in/web/TaskAvailableController.java index 14dc3e6..eecc4a3 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/adapter/in/web/TaskAvailableController.java +++ b/executor1/src/main/java/ch/unisg/executor1/executor/adapter/in/web/TaskAvailableController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.RestController; import ch.unisg.executor1.executor.application.port.in.TaskAvailableCommand; import ch.unisg.executor1.executor.application.port.in.TaskAvailableUseCase; +import ch.unisg.executor1.executor.domain.ExecutorType; @RestController public class TaskAvailableController { @@ -20,10 +21,13 @@ public class TaskAvailableController { @GetMapping(path = "/newtask/{taskType}") public ResponseEntity retrieveTaskFromTaskList(@PathVariable("taskType") String taskType) { - TaskAvailableCommand command = new TaskAvailableCommand(taskType); - - taskAvailableUseCase.newTaskAvailable(command); + 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(); diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/ExecutionFinishedAdapter.java b/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/ExecutionFinishedEventAdapter.java similarity index 91% rename from executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/ExecutionFinishedAdapter.java rename to executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/ExecutionFinishedEventAdapter.java index e1c3a5d..41e68a6 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/ExecutionFinishedAdapter.java +++ b/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/ExecutionFinishedEventAdapter.java @@ -13,7 +13,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import ch.unisg.executor1.executor.application.port.out.ExecutionFinishedEventPort; import ch.unisg.executor1.executor.domain.ExecutionFinishedEvent; -public class ExecutionFinishedAdapter implements ExecutionFinishedEventPort { +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"; @@ -51,7 +51,7 @@ public class ExecutionFinishedAdapter implements ExecutionFinishedEventPort { } **/ - System.out.println("Finish execution event sent"); + System.out.println("Finish execution event sent with result:" + event.getResult()); } diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/GetAssignmentAdapter.java b/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/GetAssignmentAdapter.java index 2c32f84..c7d8485 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/GetAssignmentAdapter.java +++ b/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/GetAssignmentAdapter.java @@ -8,6 +8,7 @@ import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; import ch.unisg.executor1.executor.application.port.out.GetAssignmentPort; +import ch.unisg.executor1.executor.domain.ExecutorType; import ch.unisg.executor1.executor.domain.Task; @Component @@ -18,7 +19,7 @@ public class GetAssignmentAdapter implements GetAssignmentPort { String server = "http://127.0.0.1:8082"; @Override - public Task getAssignment(String executorType) { + public Task getAssignment(ExecutorType executorType) { HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() @@ -38,7 +39,7 @@ public class GetAssignmentAdapter implements GetAssignmentPort { // TODO return null or a new Task here depending on the response of the http call - return new Task("1234"); + return null; } } diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/NotifyExecutorPoolAdapter.java b/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/NotifyExecutorPoolAdapter.java index 866ab91..d7a9238 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/NotifyExecutorPoolAdapter.java +++ b/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/NotifyExecutorPoolAdapter.java @@ -12,6 +12,7 @@ import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; import ch.unisg.executor1.executor.application.port.out.NotifyExecutorPoolPort; +import ch.unisg.executor1.executor.domain.ExecutorType; @Component @Primary @@ -21,12 +22,12 @@ public class NotifyExecutorPoolAdapter implements NotifyExecutorPoolPort { String server = "http://127.0.0.1:8083"; @Override - public boolean notifyExecutorPool(String ip, int port, String executorType) { + public boolean notifyExecutorPool(String ip, int port, ExecutorType executorType) { var values = new HashMap() {{ put("ip", ip); put("port", Integer.toString(port)); - put("executorType", executorType); + put("executorType", executorType.toString()); }}; var objectMapper = new ObjectMapper(); diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/application/port/in/TaskAvailableCommand.java b/executor1/src/main/java/ch/unisg/executor1/executor/application/port/in/TaskAvailableCommand.java index a5d530d..292d18b 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/application/port/in/TaskAvailableCommand.java +++ b/executor1/src/main/java/ch/unisg/executor1/executor/application/port/in/TaskAvailableCommand.java @@ -1,6 +1,7 @@ package ch.unisg.executor1.executor.application.port.in; import ch.unisg.executor1.common.SelfValidating; +import ch.unisg.executor1.executor.domain.ExecutorType; import javax.validation.constraints.NotNull; @@ -10,9 +11,9 @@ import lombok.Value; public class TaskAvailableCommand extends SelfValidating { @NotNull - private final String taskType; + private final ExecutorType taskType; - public TaskAvailableCommand(String taskType) { + public TaskAvailableCommand(ExecutorType taskType) { this.taskType = taskType; this.validateSelf(); } diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/GetAssignmentPort.java b/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/GetAssignmentPort.java index bbf9124..7b81b13 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/GetAssignmentPort.java +++ b/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/GetAssignmentPort.java @@ -1,7 +1,8 @@ package ch.unisg.executor1.executor.application.port.out; +import ch.unisg.executor1.executor.domain.ExecutorType; import ch.unisg.executor1.executor.domain.Task; public interface GetAssignmentPort { - Task getAssignment(String executorType); + Task getAssignment(ExecutorType executorType); } diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/NotifyExecutorPoolPort.java b/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/NotifyExecutorPoolPort.java index 856163f..4086258 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/NotifyExecutorPoolPort.java +++ b/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/NotifyExecutorPoolPort.java @@ -1,5 +1,7 @@ package ch.unisg.executor1.executor.application.port.out; +import ch.unisg.executor1.executor.domain.ExecutorType; + public interface NotifyExecutorPoolPort { - boolean notifyExecutorPool(String ip, int port, String executorType); + boolean notifyExecutorPool(String ip, int port, ExecutorType executorType); } diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/application/service/NotifyExecutorPoolService.java b/executor1/src/main/java/ch/unisg/executor1/executor/application/service/NotifyExecutorPoolService.java index 0c05fda..acfae94 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/application/service/NotifyExecutorPoolService.java +++ b/executor1/src/main/java/ch/unisg/executor1/executor/application/service/NotifyExecutorPoolService.java @@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import ch.unisg.executor1.executor.application.port.out.NotifyExecutorPoolPort; +import ch.unisg.executor1.executor.domain.ExecutorType; import lombok.RequiredArgsConstructor; @RequiredArgsConstructor @@ -11,7 +12,7 @@ public class NotifyExecutorPoolService { private final NotifyExecutorPoolPort notifyExecutorPoolPort; - public boolean notifyExecutorPool(String ip, int port, String executorType) { + public boolean notifyExecutorPool(String ip, int port, ExecutorType executorType) { return notifyExecutorPoolPort.notifyExecutorPool(ip, port, executorType); } } diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/application/service/TaskAvailableService.java b/executor1/src/main/java/ch/unisg/executor1/executor/application/service/TaskAvailableService.java index 795cd8b..6f15b47 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/application/service/TaskAvailableService.java +++ b/executor1/src/main/java/ch/unisg/executor1/executor/application/service/TaskAvailableService.java @@ -19,7 +19,7 @@ public class TaskAvailableService implements TaskAvailableUseCase { public void newTaskAvailable(TaskAvailableCommand command) { Executor executor = Executor.getExecutor(); - if (executor.getExecutorType().equalsIgnoreCase(command.getTaskType()) && + if (executor.getExecutorType() == command.getTaskType() && executor.getStatus() == ExecutorStatus.IDLING) { executor.getAssignment(); } diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/domain/Executor.java b/executor1/src/main/java/ch/unisg/executor1/executor/domain/Executor.java index 6329f29..d8f9e0b 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/domain/Executor.java +++ b/executor1/src/main/java/ch/unisg/executor1/executor/domain/Executor.java @@ -1,77 +1,22 @@ package ch.unisg.executor1.executor.domain; -import ch.unisg.executor1.executor.application.port.out.ExecutionFinishedEventPort; -import ch.unisg.executor1.executor.application.port.out.GetAssignmentPort; -import ch.unisg.executor1.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.executor1.executor.adapter.out.web.ExecutionFinishedAdapter; -import ch.unisg.executor1.executor.adapter.out.web.GetAssignmentAdapter; -import ch.unisg.executor1.executor.adapter.out.web.NotifyExecutorPoolAdapter; -import ch.unisg.executor1.executor.application.service.NotifyExecutorPoolService; -import lombok.Getter; - -public class Executor { - - @Getter - private String ip; - - @Getter - private String executorType = "addition"; - - @Getter - private int port; - - @Getter - private ExecutorStatus status; - - private static final Executor executor = new Executor(); - - // 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 ExecutionFinishedAdapter(); - - private Executor() { - System.out.println("Starting Executor"); - // TODO set this automaticly - this.ip = "localhost"; - this.port = 8084; +public class Executor extends ExecutorBase { - 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(); - } - } + private static final Executor executor = new Executor(ExecutorType.ADDITION); public static Executor getExecutor() { return executor; } - public void getAssignment() { - Task newTask = getAssignmentPort.getAssignment(this.getExecutorType()); - if (newTask != null) { - this.executeTask(newTask); - } else { - this.status = ExecutorStatus.IDLING; - } + private Executor(ExecutorType executorType) { + super(executorType); } - private void executeTask(Task task) { - System.out.println("Starting execution"); - this.status = ExecutorStatus.EXECUTING; + @Override + String execution() { + int a = 10; int b = 20; try { @@ -82,12 +27,7 @@ public class Executor { int result = a + b; - task.setResult(Integer.toString(result)); - - executionFinishedEventPort.publishExecutionFinishedEvent(new ExecutionFinishedEvent(task.getTaskID(), task.getResult(), "SUCCESS")); - - System.out.println("Finish execution"); - getAssignment(); + return Integer.toString(result); } - + } diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutorBase.java b/executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutorBase.java new file mode 100644 index 0000000..fe65913 --- /dev/null +++ b/executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutorBase.java @@ -0,0 +1,87 @@ +package ch.unisg.executor1.executor.domain; + +import ch.unisg.executor1.executor.application.port.out.ExecutionFinishedEventPort; +import ch.unisg.executor1.executor.application.port.out.GetAssignmentPort; +import ch.unisg.executor1.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.executor1.executor.adapter.out.web.ExecutionFinishedEventAdapter; +import ch.unisg.executor1.executor.adapter.out.web.GetAssignmentAdapter; +import ch.unisg.executor1.executor.adapter.out.web.NotifyExecutorPoolAdapter; +import ch.unisg.executor1.executor.application.service.NotifyExecutorPoolService; +import lombok.Getter; + +abstract class ExecutorBase { + + @Getter + private String ip; + + @Getter + private ExecutorType executorType; + + @Getter + private int port; + + @Getter + private ExecutorStatus status; + + // private static final ExecutorBase executor = new ExecutorBase(); + + // 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(); + } + + abstract String execution(); + +} diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutorType.java b/executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutorType.java new file mode 100644 index 0000000..58c9d91 --- /dev/null +++ b/executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutorType.java @@ -0,0 +1,18 @@ +package ch.unisg.executor1.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; + } +} + + + -- 2.45.1 From 5e8434d679b8c114515e781c4b4576a1acdd35d3 Mon Sep 17 00:00:00 2001 From: Marcel Date: Wed, 13 Oct 2021 12:40:24 +0200 Subject: [PATCH 3/4] refactored executor1 to have base classes in own project --- {executor1 => executor-base}/.gitignore | 0 .../.mvn/wrapper/MavenWrapperDownloader.java | 0 .../.mvn/wrapper/maven-wrapper.jar | Bin .../.mvn/wrapper/maven-wrapper.properties | 0 {executor1 => executor-base}/Dockerfile | 0 {executor1 => executor-base}/mvnw | 0 {executor1 => executor-base}/mvnw.cmd | 0 {executor1 => executor-base}/pom.xml | 4 ++-- .../executorBase}/Executor1Application.java | 5 +--- .../executorBase}/common/SelfValidating.java | 2 +- .../in/web/TaskAvailableController.java | 8 +++---- .../web/ExecutionFinishedEventAdapter.java | 6 ++--- .../adapter/out/web/GetAssignmentAdapter.java | 10 ++++---- .../out/web/NotifyExecutorPoolAdapter.java | 6 ++--- .../port/in/TaskAvailableCommand.java | 6 ++--- .../port/in/TaskAvailableUseCase.java | 2 +- .../port/out/ExecutionFinishedEventPort.java | 7 ++++++ .../port/out/GetAssignmentPort.java | 8 +++++++ .../port/out/NotifyExecutorPoolPort.java | 4 ++-- .../service/NotifyExecutorPoolService.java | 9 +++---- .../domain/ExecutionFinishedEvent.java | 2 +- .../executor/domain/ExecutorBase.java | 22 ++++++++---------- .../executor/domain/ExecutorStatus.java | 2 +- .../executor/domain/ExecutorType.java | 2 +- .../executorBase}/executor/domain/Task.java | 2 +- .../src/main/resources/application.properties | 0 .../Executor1ApplicationTests.java | 4 ++-- .../port/out/ExecutionFinishedEventPort.java | 7 ------ .../port/out/GetAssignmentPort.java | 8 ------- executor2/pom.xml | 5 ++++ .../unisg/executor2/Executor2Application.java | 3 +++ .../ch/unisg/executor2/TestController.java | 12 ---------- .../service/TaskAvailableService.java | 11 +++++---- .../executor2}/executor/domain/Executor.java | 7 ++++-- 34 files changed, 78 insertions(+), 86 deletions(-) rename {executor1 => executor-base}/.gitignore (100%) rename {executor1 => executor-base}/.mvn/wrapper/MavenWrapperDownloader.java (100%) rename {executor1 => executor-base}/.mvn/wrapper/maven-wrapper.jar (100%) rename {executor1 => executor-base}/.mvn/wrapper/maven-wrapper.properties (100%) rename {executor1 => executor-base}/Dockerfile (100%) rename {executor1 => executor-base}/mvnw (100%) rename {executor1 => executor-base}/mvnw.cmd (100%) rename {executor1 => executor-base}/pom.xml (97%) rename {executor1/src/main/java/ch/unisg/executor1 => executor-base/src/main/java/ch/unisg/executorBase}/Executor1Application.java (72%) rename {executor1/src/main/java/ch/unisg/executor1 => executor-base/src/main/java/ch/unisg/executorBase}/common/SelfValidating.java (95%) rename {executor1/src/main/java/ch/unisg/executor1 => executor-base/src/main/java/ch/unisg/executorBase}/executor/adapter/in/web/TaskAvailableController.java (81%) rename {executor1/src/main/java/ch/unisg/executor1 => executor-base/src/main/java/ch/unisg/executorBase}/executor/adapter/out/web/ExecutionFinishedEventAdapter.java (89%) rename {executor1/src/main/java/ch/unisg/executor1 => executor-base/src/main/java/ch/unisg/executorBase}/executor/adapter/out/web/GetAssignmentAdapter.java (81%) rename {executor1/src/main/java/ch/unisg/executor1 => executor-base/src/main/java/ch/unisg/executorBase}/executor/adapter/out/web/NotifyExecutorPoolAdapter.java (90%) rename {executor1/src/main/java/ch/unisg/executor1 => executor-base/src/main/java/ch/unisg/executorBase}/executor/application/port/in/TaskAvailableCommand.java (66%) rename {executor1/src/main/java/ch/unisg/executor1 => executor-base/src/main/java/ch/unisg/executorBase}/executor/application/port/in/TaskAvailableUseCase.java (62%) create mode 100644 executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/out/ExecutionFinishedEventPort.java create mode 100644 executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/out/GetAssignmentPort.java rename {executor1/src/main/java/ch/unisg/executor1 => executor-base/src/main/java/ch/unisg/executorBase}/executor/application/port/out/NotifyExecutorPoolPort.java (51%) rename {executor1/src/main/java/ch/unisg/executor1 => executor-base/src/main/java/ch/unisg/executorBase}/executor/application/service/NotifyExecutorPoolService.java (52%) rename {executor1/src/main/java/ch/unisg/executor1 => executor-base/src/main/java/ch/unisg/executorBase}/executor/domain/ExecutionFinishedEvent.java (88%) rename {executor1/src/main/java/ch/unisg/executor1 => executor-base/src/main/java/ch/unisg/executorBase}/executor/domain/ExecutorBase.java (76%) rename {executor1/src/main/java/ch/unisg/executor1 => executor-base/src/main/java/ch/unisg/executorBase}/executor/domain/ExecutorStatus.java (61%) rename {executor1/src/main/java/ch/unisg/executor1 => executor-base/src/main/java/ch/unisg/executorBase}/executor/domain/ExecutorType.java (85%) rename {executor1/src/main/java/ch/unisg/executor1 => executor-base/src/main/java/ch/unisg/executorBase}/executor/domain/Task.java (84%) rename {executor1 => executor-base}/src/main/resources/application.properties (100%) rename {executor1/src/test/java/ch/unisg/executor1 => executor-base/src/test/java/ch/unisg/executorBase}/Executor1ApplicationTests.java (68%) delete mode 100644 executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/ExecutionFinishedEventPort.java delete mode 100644 executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/GetAssignmentPort.java delete mode 100644 executor2/src/main/java/ch/unisg/executor2/TestController.java rename {executor1/src/main/java/ch/unisg/executor1 => executor2/src/main/java/ch/unisg/executor2}/executor/application/service/TaskAvailableService.java (63%) rename {executor1/src/main/java/ch/unisg/executor1 => executor2/src/main/java/ch/unisg/executor2}/executor/domain/Executor.java (76%) 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 97% rename from executor1/pom.xml rename to executor-base/pom.xml index 8df7a04..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 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 72% rename from executor1/src/main/java/ch/unisg/executor1/Executor1Application.java rename to executor-base/src/main/java/ch/unisg/executorBase/Executor1Application.java index dfb8d8c..9bd3fa5 100644 --- a/executor1/src/main/java/ch/unisg/executor1/Executor1Application.java +++ b/executor-base/src/main/java/ch/unisg/executorBase/Executor1Application.java @@ -1,16 +1,13 @@ -package ch.unisg.executor1; +package ch.unisg.executorBase; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import ch.unisg.executor1.executor.domain.Executor; - @SpringBootApplication public class Executor1Application { public static void main(String[] args) { SpringApplication.run(Executor1Application.class, args); - Executor.getExecutor(); } } diff --git a/executor1/src/main/java/ch/unisg/executor1/common/SelfValidating.java b/executor-base/src/main/java/ch/unisg/executorBase/common/SelfValidating.java similarity index 95% rename from executor1/src/main/java/ch/unisg/executor1/common/SelfValidating.java rename to executor-base/src/main/java/ch/unisg/executorBase/common/SelfValidating.java index bc9816a..1d4a80a 100644 --- a/executor1/src/main/java/ch/unisg/executor1/common/SelfValidating.java +++ b/executor-base/src/main/java/ch/unisg/executorBase/common/SelfValidating.java @@ -1,4 +1,4 @@ -package ch.unisg.executor1.common; +package ch.unisg.executorBase.common; import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolationException; diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/adapter/in/web/TaskAvailableController.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/in/web/TaskAvailableController.java similarity index 81% rename from executor1/src/main/java/ch/unisg/executor1/executor/adapter/in/web/TaskAvailableController.java rename to executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/in/web/TaskAvailableController.java index eecc4a3..75d3a02 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/adapter/in/web/TaskAvailableController.java +++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/in/web/TaskAvailableController.java @@ -1,4 +1,4 @@ -package ch.unisg.executor1.executor.adapter.in.web; +package ch.unisg.executorBase.executor.adapter.in.web; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; @@ -7,9 +7,9 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; -import ch.unisg.executor1.executor.application.port.in.TaskAvailableCommand; -import ch.unisg.executor1.executor.application.port.in.TaskAvailableUseCase; -import ch.unisg.executor1.executor.domain.ExecutorType; +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 { diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/ExecutionFinishedEventAdapter.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/ExecutionFinishedEventAdapter.java similarity index 89% rename from executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/ExecutionFinishedEventAdapter.java rename to executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/ExecutionFinishedEventAdapter.java index 41e68a6..2f53a2b 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/ExecutionFinishedEventAdapter.java +++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/ExecutionFinishedEventAdapter.java @@ -1,4 +1,4 @@ -package ch.unisg.executor1.executor.adapter.out.web; +package ch.unisg.executorBase.executor.adapter.out.web; import java.io.IOException; import java.net.URI; @@ -10,8 +10,8 @@ import java.util.HashMap; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.core.JsonProcessingException; -import ch.unisg.executor1.executor.application.port.out.ExecutionFinishedEventPort; -import ch.unisg.executor1.executor.domain.ExecutionFinishedEvent; +import ch.unisg.executorBase.executor.application.port.out.ExecutionFinishedEventPort; +import ch.unisg.executorBase.executor.domain.ExecutionFinishedEvent; public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort { diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/GetAssignmentAdapter.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/GetAssignmentAdapter.java similarity index 81% rename from executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/GetAssignmentAdapter.java rename to executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/GetAssignmentAdapter.java index c7d8485..b3e7875 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/GetAssignmentAdapter.java +++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/GetAssignmentAdapter.java @@ -1,4 +1,4 @@ -package ch.unisg.executor1.executor.adapter.out.web; +package ch.unisg.executorBase.executor.adapter.out.web; import java.net.URI; import java.net.http.HttpClient; @@ -7,9 +7,9 @@ import java.net.http.HttpRequest; import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; -import ch.unisg.executor1.executor.application.port.out.GetAssignmentPort; -import ch.unisg.executor1.executor.domain.ExecutorType; -import ch.unisg.executor1.executor.domain.Task; +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 @@ -39,7 +39,7 @@ public class GetAssignmentAdapter implements GetAssignmentPort { // TODO return null or a new Task here depending on the response of the http call - return null; + return new Task("123"); } } diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/NotifyExecutorPoolAdapter.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/NotifyExecutorPoolAdapter.java similarity index 90% rename from executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/NotifyExecutorPoolAdapter.java rename to executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/NotifyExecutorPoolAdapter.java index d7a9238..feeca69 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/adapter/out/web/NotifyExecutorPoolAdapter.java +++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/NotifyExecutorPoolAdapter.java @@ -1,4 +1,4 @@ -package ch.unisg.executor1.executor.adapter.out.web; +package ch.unisg.executorBase.executor.adapter.out.web; import java.net.URI; import java.net.http.HttpClient; @@ -11,8 +11,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; -import ch.unisg.executor1.executor.application.port.out.NotifyExecutorPoolPort; -import ch.unisg.executor1.executor.domain.ExecutorType; +import ch.unisg.executorBase.executor.application.port.out.NotifyExecutorPoolPort; +import ch.unisg.executorBase.executor.domain.ExecutorType; @Component @Primary diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/application/port/in/TaskAvailableCommand.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/in/TaskAvailableCommand.java similarity index 66% rename from executor1/src/main/java/ch/unisg/executor1/executor/application/port/in/TaskAvailableCommand.java rename to executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/in/TaskAvailableCommand.java index 292d18b..916c8eb 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/application/port/in/TaskAvailableCommand.java +++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/in/TaskAvailableCommand.java @@ -1,7 +1,7 @@ -package ch.unisg.executor1.executor.application.port.in; +package ch.unisg.executorBase.executor.application.port.in; -import ch.unisg.executor1.common.SelfValidating; -import ch.unisg.executor1.executor.domain.ExecutorType; +import ch.unisg.executorBase.common.SelfValidating; +import ch.unisg.executorBase.executor.domain.ExecutorType; import javax.validation.constraints.NotNull; diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/application/port/in/TaskAvailableUseCase.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/in/TaskAvailableUseCase.java similarity index 62% rename from executor1/src/main/java/ch/unisg/executor1/executor/application/port/in/TaskAvailableUseCase.java rename to executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/in/TaskAvailableUseCase.java index d8184c1..cc5215f 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/application/port/in/TaskAvailableUseCase.java +++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/in/TaskAvailableUseCase.java @@ -1,4 +1,4 @@ -package ch.unisg.executor1.executor.application.port.in; +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/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/NotifyExecutorPoolPort.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/out/NotifyExecutorPoolPort.java similarity index 51% rename from executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/NotifyExecutorPoolPort.java rename to executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/out/NotifyExecutorPoolPort.java index 4086258..6d41ab4 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/NotifyExecutorPoolPort.java +++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/port/out/NotifyExecutorPoolPort.java @@ -1,6 +1,6 @@ -package ch.unisg.executor1.executor.application.port.out; +package ch.unisg.executorBase.executor.application.port.out; -import ch.unisg.executor1.executor.domain.ExecutorType; +import ch.unisg.executorBase.executor.domain.ExecutorType; public interface NotifyExecutorPoolPort { boolean notifyExecutorPool(String ip, int port, ExecutorType executorType); diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/application/service/NotifyExecutorPoolService.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/service/NotifyExecutorPoolService.java similarity index 52% rename from executor1/src/main/java/ch/unisg/executor1/executor/application/service/NotifyExecutorPoolService.java rename to executor-base/src/main/java/ch/unisg/executorBase/executor/application/service/NotifyExecutorPoolService.java index acfae94..a5ccb64 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/application/service/NotifyExecutorPoolService.java +++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/service/NotifyExecutorPoolService.java @@ -1,10 +1,7 @@ -package ch.unisg.executor1.executor.application.service; +package ch.unisg.executorBase.executor.application.service; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import ch.unisg.executor1.executor.application.port.out.NotifyExecutorPoolPort; -import ch.unisg.executor1.executor.domain.ExecutorType; +import ch.unisg.executorBase.executor.application.port.out.NotifyExecutorPoolPort; +import ch.unisg.executorBase.executor.domain.ExecutorType; import lombok.RequiredArgsConstructor; @RequiredArgsConstructor diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutionFinishedEvent.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutionFinishedEvent.java similarity index 88% rename from executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutionFinishedEvent.java rename to executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutionFinishedEvent.java index 4455572..31fd0e6 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutionFinishedEvent.java +++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutionFinishedEvent.java @@ -1,4 +1,4 @@ -package ch.unisg.executor1.executor.domain; +package ch.unisg.executorBase.executor.domain; import lombok.Getter; diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutorBase.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorBase.java similarity index 76% rename from executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutorBase.java rename to executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorBase.java index fe65913..e639cb3 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutorBase.java +++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorBase.java @@ -1,8 +1,8 @@ -package ch.unisg.executor1.executor.domain; +package ch.unisg.executorBase.executor.domain; -import ch.unisg.executor1.executor.application.port.out.ExecutionFinishedEventPort; -import ch.unisg.executor1.executor.application.port.out.GetAssignmentPort; -import ch.unisg.executor1.executor.application.port.out.NotifyExecutorPoolPort; +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; @@ -11,13 +11,13 @@ import javax.transaction.Transactional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Configurable; -import ch.unisg.executor1.executor.adapter.out.web.ExecutionFinishedEventAdapter; -import ch.unisg.executor1.executor.adapter.out.web.GetAssignmentAdapter; -import ch.unisg.executor1.executor.adapter.out.web.NotifyExecutorPoolAdapter; -import ch.unisg.executor1.executor.application.service.NotifyExecutorPoolService; +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; -abstract class ExecutorBase { +public abstract class ExecutorBase { @Getter private String ip; @@ -31,8 +31,6 @@ abstract class ExecutorBase { @Getter private ExecutorStatus status; - // private static final ExecutorBase executor = new ExecutorBase(); - // 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(); @@ -82,6 +80,6 @@ abstract class ExecutorBase { getAssignment(); } - abstract String execution(); + protected abstract String execution(); } diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutorStatus.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorStatus.java similarity index 61% rename from executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutorStatus.java rename to executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorStatus.java index 92af024..8bd5bc3 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutorStatus.java +++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorStatus.java @@ -1,4 +1,4 @@ -package ch.unisg.executor1.executor.domain; +package ch.unisg.executorBase.executor.domain; public enum ExecutorStatus { STARTING_UP, diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutorType.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorType.java similarity index 85% rename from executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutorType.java rename to executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorType.java index 58c9d91..0b2b305 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/domain/ExecutorType.java +++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorType.java @@ -1,4 +1,4 @@ -package ch.unisg.executor1.executor.domain; +package ch.unisg.executorBase.executor.domain; public enum ExecutorType { ADDITION, ROBOT; diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/domain/Task.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/Task.java similarity index 84% rename from executor1/src/main/java/ch/unisg/executor1/executor/domain/Task.java rename to executor-base/src/main/java/ch/unisg/executorBase/executor/domain/Task.java index 2287b6c..6719613 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/domain/Task.java +++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/Task.java @@ -1,4 +1,4 @@ -package ch.unisg.executor1.executor.domain; +package ch.unisg.executorBase.executor.domain; import lombok.Data; import lombok.Getter; 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/executor/application/port/out/ExecutionFinishedEventPort.java b/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/ExecutionFinishedEventPort.java deleted file mode 100644 index 6bfea70..0000000 --- a/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/ExecutionFinishedEventPort.java +++ /dev/null @@ -1,7 +0,0 @@ -package ch.unisg.executor1.executor.application.port.out; - -import ch.unisg.executor1.executor.domain.ExecutionFinishedEvent; - -public interface ExecutionFinishedEventPort { - void publishExecutionFinishedEvent(ExecutionFinishedEvent event); -} diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/GetAssignmentPort.java b/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/GetAssignmentPort.java deleted file mode 100644 index 7b81b13..0000000 --- a/executor1/src/main/java/ch/unisg/executor1/executor/application/port/out/GetAssignmentPort.java +++ /dev/null @@ -1,8 +0,0 @@ -package ch.unisg.executor1.executor.application.port.out; - -import ch.unisg.executor1.executor.domain.ExecutorType; -import ch.unisg.executor1.executor.domain.Task; - -public interface GetAssignmentPort { - Task getAssignment(ExecutorType executorType); -} 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/executor1/src/main/java/ch/unisg/executor1/executor/application/service/TaskAvailableService.java b/executor2/src/main/java/ch/unisg/executor2/executor/application/service/TaskAvailableService.java similarity index 63% rename from executor1/src/main/java/ch/unisg/executor1/executor/application/service/TaskAvailableService.java rename to executor2/src/main/java/ch/unisg/executor2/executor/application/service/TaskAvailableService.java index 6f15b47..4484ebb 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/application/service/TaskAvailableService.java +++ b/executor2/src/main/java/ch/unisg/executor2/executor/application/service/TaskAvailableService.java @@ -1,11 +1,11 @@ -package ch.unisg.executor1.executor.application.service; +package ch.unisg.executor2.executor.application.service; import org.springframework.stereotype.Component; -import ch.unisg.executor1.executor.application.port.in.TaskAvailableCommand; -import ch.unisg.executor1.executor.application.port.in.TaskAvailableUseCase; -import ch.unisg.executor1.executor.domain.Executor; -import ch.unisg.executor1.executor.domain.ExecutorStatus; +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; @@ -17,6 +17,7 @@ public class TaskAvailableService implements TaskAvailableUseCase { @Override public void newTaskAvailable(TaskAvailableCommand command) { + Executor executor = Executor.getExecutor(); if (executor.getExecutorType() == command.getTaskType() && diff --git a/executor1/src/main/java/ch/unisg/executor1/executor/domain/Executor.java b/executor2/src/main/java/ch/unisg/executor2/executor/domain/Executor.java similarity index 76% rename from executor1/src/main/java/ch/unisg/executor1/executor/domain/Executor.java rename to executor2/src/main/java/ch/unisg/executor2/executor/domain/Executor.java index d8f9e0b..bb9308b 100644 --- a/executor1/src/main/java/ch/unisg/executor1/executor/domain/Executor.java +++ b/executor2/src/main/java/ch/unisg/executor2/executor/domain/Executor.java @@ -1,6 +1,8 @@ -package ch.unisg.executor1.executor.domain; +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 { @@ -15,9 +17,10 @@ public class Executor extends ExecutorBase { } @Override + protected String execution() { - int a = 10; + int a = 20; int b = 20; try { TimeUnit.SECONDS.sleep(10); -- 2.45.1 From a7f62a8b23b380afcfbf789b7ee5fb546acdecdd Mon Sep 17 00:00:00 2001 From: Marcel Date: Wed, 13 Oct 2021 16:24:38 +0200 Subject: [PATCH 4/4] edited editorconfig --- .editorconfig | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.editorconfig b/.editorconfig index 74c6104..c4f3e5b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,12 +1,9 @@ root = true [*] -end_of_line = lf -insert_final_newline = true - -[*.{java}] +charset = utf-8 indent_style = space indent_size = 4 -tab_width = 4 trim_trailing_whitespace = true -max_line_length = 100 +end_of_line = lf +insert_final_newline = true -- 2.45.1