Executor1 #18

Merged
Maece97 merged 4 commits from executor1 into dev 2021-10-13 14:30:04 +00:00
34 changed files with 78 additions and 86 deletions
Showing only changes of commit 5e8434d679 - Show all commits

View File

@ -9,9 +9,9 @@
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>ch.unisg</groupId>
<artifactId>executor1</artifactId>
<artifactId>executorBase</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>executor1</name>
<name>executorBase</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>

View File

@ -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();
}
}

View File

@ -1,4 +1,4 @@
package ch.unisg.executor1.common;
package ch.unisg.executorBase.common;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;

View File

@ -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 {

View File

@ -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 {

View File

@ -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");
}
}

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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

View File

@ -1,4 +1,4 @@
package ch.unisg.executor1.executor.domain;
package ch.unisg.executorBase.executor.domain;
import lombok.Getter;

View File

@ -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();
}

View File

@ -1,4 +1,4 @@
package ch.unisg.executor1.executor.domain;
package ch.unisg.executorBase.executor.domain;
public enum ExecutorStatus {
STARTING_UP,

View File

@ -1,4 +1,4 @@
package ch.unisg.executor1.executor.domain;
package ch.unisg.executorBase.executor.domain;
public enum ExecutorType {
ADDITION, ROBOT;

View File

@ -1,4 +1,4 @@
package ch.unisg.executor1.executor.domain;
package ch.unisg.executorBase.executor.domain;
import lombok.Data;
import lombok.Getter;

View File

@ -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() {

View File

@ -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);
}

View File

@ -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);
}

View File

@ -40,6 +40,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.unisg</groupId>
<artifactId>executorBase</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>

View File

@ -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();
}
}

View File

@ -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";
}
}

View File

@ -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() &&

View File

@ -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);