refactored executor1 to have base classes in own project
This commit is contained in:
parent
3bc39b70aa
commit
5e8434d679
0
executor1/mvnw → executor-base/mvnw
vendored
0
executor1/mvnw → executor-base/mvnw
vendored
|
@ -9,9 +9,9 @@
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>ch.unisg</groupId>
|
<groupId>ch.unisg</groupId>
|
||||||
<artifactId>executor1</artifactId>
|
<artifactId>executorBase</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<name>executor1</name>
|
<name>executorBase</name>
|
||||||
<description>Demo project for Spring Boot</description>
|
<description>Demo project for Spring Boot</description>
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>11</java.version>
|
<java.version>11</java.version>
|
|
@ -1,16 +1,13 @@
|
||||||
package ch.unisg.executor1;
|
package ch.unisg.executorBase;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
import ch.unisg.executor1.executor.domain.Executor;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class Executor1Application {
|
public class Executor1Application {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(Executor1Application.class, args);
|
SpringApplication.run(Executor1Application.class, args);
|
||||||
Executor.getExecutor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package ch.unisg.executor1.common;
|
package ch.unisg.executorBase.common;
|
||||||
|
|
||||||
import javax.validation.ConstraintViolation;
|
import javax.validation.ConstraintViolation;
|
||||||
import javax.validation.ConstraintViolationException;
|
import javax.validation.ConstraintViolationException;
|
|
@ -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.HttpHeaders;
|
||||||
import org.springframework.http.HttpStatus;
|
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.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import ch.unisg.executor1.executor.application.port.in.TaskAvailableCommand;
|
import ch.unisg.executorBase.executor.application.port.in.TaskAvailableCommand;
|
||||||
import ch.unisg.executor1.executor.application.port.in.TaskAvailableUseCase;
|
import ch.unisg.executorBase.executor.application.port.in.TaskAvailableUseCase;
|
||||||
import ch.unisg.executor1.executor.domain.ExecutorType;
|
import ch.unisg.executorBase.executor.domain.ExecutorType;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class TaskAvailableController {
|
public class TaskAvailableController {
|
|
@ -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.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -10,8 +10,8 @@ import java.util.HashMap;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
|
||||||
import ch.unisg.executor1.executor.application.port.out.ExecutionFinishedEventPort;
|
import ch.unisg.executorBase.executor.application.port.out.ExecutionFinishedEventPort;
|
||||||
import ch.unisg.executor1.executor.domain.ExecutionFinishedEvent;
|
import ch.unisg.executorBase.executor.domain.ExecutionFinishedEvent;
|
||||||
|
|
||||||
public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort {
|
public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort {
|
||||||
|
|
|
@ -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.URI;
|
||||||
import java.net.http.HttpClient;
|
import java.net.http.HttpClient;
|
||||||
|
@ -7,9 +7,9 @@ import java.net.http.HttpRequest;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import ch.unisg.executor1.executor.application.port.out.GetAssignmentPort;
|
import ch.unisg.executorBase.executor.application.port.out.GetAssignmentPort;
|
||||||
import ch.unisg.executor1.executor.domain.ExecutorType;
|
import ch.unisg.executorBase.executor.domain.ExecutorType;
|
||||||
import ch.unisg.executor1.executor.domain.Task;
|
import ch.unisg.executorBase.executor.domain.Task;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Primary
|
@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
|
// TODO return null or a new Task here depending on the response of the http call
|
||||||
|
|
||||||
return null;
|
return new Task("123");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -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.URI;
|
||||||
import java.net.http.HttpClient;
|
import java.net.http.HttpClient;
|
||||||
|
@ -11,8 +11,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import ch.unisg.executor1.executor.application.port.out.NotifyExecutorPoolPort;
|
import ch.unisg.executorBase.executor.application.port.out.NotifyExecutorPoolPort;
|
||||||
import ch.unisg.executor1.executor.domain.ExecutorType;
|
import ch.unisg.executorBase.executor.domain.ExecutorType;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Primary
|
@Primary
|
|
@ -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.executorBase.common.SelfValidating;
|
||||||
import ch.unisg.executor1.executor.domain.ExecutorType;
|
import ch.unisg.executorBase.executor.domain.ExecutorType;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package ch.unisg.executor1.executor.application.port.in;
|
package ch.unisg.executorBase.executor.application.port.in;
|
||||||
|
|
||||||
public interface TaskAvailableUseCase {
|
public interface TaskAvailableUseCase {
|
||||||
void newTaskAvailable(TaskAvailableCommand command);
|
void newTaskAvailable(TaskAvailableCommand command);
|
|
@ -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);
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -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 {
|
public interface NotifyExecutorPoolPort {
|
||||||
boolean notifyExecutorPool(String ip, int port, ExecutorType executorType);
|
boolean notifyExecutorPool(String ip, int port, ExecutorType executorType);
|
|
@ -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 ch.unisg.executorBase.executor.application.port.out.NotifyExecutorPoolPort;
|
||||||
import org.springframework.stereotype.Component;
|
import ch.unisg.executorBase.executor.domain.ExecutorType;
|
||||||
|
|
||||||
import ch.unisg.executor1.executor.application.port.out.NotifyExecutorPoolPort;
|
|
||||||
import ch.unisg.executor1.executor.domain.ExecutorType;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
|
@ -1,4 +1,4 @@
|
||||||
package ch.unisg.executor1.executor.domain;
|
package ch.unisg.executorBase.executor.domain;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
|
@ -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.executorBase.executor.application.port.out.ExecutionFinishedEventPort;
|
||||||
import ch.unisg.executor1.executor.application.port.out.GetAssignmentPort;
|
import ch.unisg.executorBase.executor.application.port.out.GetAssignmentPort;
|
||||||
import ch.unisg.executor1.executor.application.port.out.NotifyExecutorPoolPort;
|
import ch.unisg.executorBase.executor.application.port.out.NotifyExecutorPoolPort;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
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.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Configurable;
|
import org.springframework.beans.factory.annotation.Configurable;
|
||||||
|
|
||||||
import ch.unisg.executor1.executor.adapter.out.web.ExecutionFinishedEventAdapter;
|
import ch.unisg.executorBase.executor.adapter.out.web.ExecutionFinishedEventAdapter;
|
||||||
import ch.unisg.executor1.executor.adapter.out.web.GetAssignmentAdapter;
|
import ch.unisg.executorBase.executor.adapter.out.web.GetAssignmentAdapter;
|
||||||
import ch.unisg.executor1.executor.adapter.out.web.NotifyExecutorPoolAdapter;
|
import ch.unisg.executorBase.executor.adapter.out.web.NotifyExecutorPoolAdapter;
|
||||||
import ch.unisg.executor1.executor.application.service.NotifyExecutorPoolService;
|
import ch.unisg.executorBase.executor.application.service.NotifyExecutorPoolService;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
abstract class ExecutorBase {
|
public abstract class ExecutorBase {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private String ip;
|
private String ip;
|
||||||
|
@ -31,8 +31,6 @@ abstract class ExecutorBase {
|
||||||
@Getter
|
@Getter
|
||||||
private ExecutorStatus status;
|
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 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
|
// 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 NotifyExecutorPoolPort notifyExecutorPoolPort = new NotifyExecutorPoolAdapter();
|
||||||
|
@ -82,6 +80,6 @@ abstract class ExecutorBase {
|
||||||
getAssignment();
|
getAssignment();
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract String execution();
|
protected abstract String execution();
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package ch.unisg.executor1.executor.domain;
|
package ch.unisg.executorBase.executor.domain;
|
||||||
|
|
||||||
public enum ExecutorStatus {
|
public enum ExecutorStatus {
|
||||||
STARTING_UP,
|
STARTING_UP,
|
|
@ -1,4 +1,4 @@
|
||||||
package ch.unisg.executor1.executor.domain;
|
package ch.unisg.executorBase.executor.domain;
|
||||||
|
|
||||||
public enum ExecutorType {
|
public enum ExecutorType {
|
||||||
ADDITION, ROBOT;
|
ADDITION, ROBOT;
|
|
@ -1,4 +1,4 @@
|
||||||
package ch.unisg.executor1.executor.domain;
|
package ch.unisg.executorBase.executor.domain;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
|
@ -1,10 +1,10 @@
|
||||||
package ch.unisg.executor1;
|
package ch.unisg.executorBase;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class Executor1ApplicationTests {
|
class executorBaseApplicationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void contextLoads() {
|
void contextLoads() {
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -40,6 +40,11 @@
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.unisg</groupId>
|
||||||
|
<artifactId>executorBase</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -3,11 +3,14 @@ package ch.unisg.executor2;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
import ch.unisg.executor2.executor.domain.Executor;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class Executor2Application {
|
public class Executor2Application {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(Executor2Application.class, args);
|
SpringApplication.run(Executor2Application.class, args);
|
||||||
|
Executor.getExecutor();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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";
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +1,11 @@
|
||||||
package ch.unisg.executor1.executor.application.service;
|
package ch.unisg.executor2.executor.application.service;
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import ch.unisg.executor1.executor.application.port.in.TaskAvailableCommand;
|
import ch.unisg.executor2.executor.domain.Executor;
|
||||||
import ch.unisg.executor1.executor.application.port.in.TaskAvailableUseCase;
|
import ch.unisg.executorBase.executor.application.port.in.TaskAvailableCommand;
|
||||||
import ch.unisg.executor1.executor.domain.Executor;
|
import ch.unisg.executorBase.executor.application.port.in.TaskAvailableUseCase;
|
||||||
import ch.unisg.executor1.executor.domain.ExecutorStatus;
|
import ch.unisg.executorBase.executor.domain.ExecutorStatus;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
@ -17,6 +17,7 @@ public class TaskAvailableService implements TaskAvailableUseCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void newTaskAvailable(TaskAvailableCommand command) {
|
public void newTaskAvailable(TaskAvailableCommand command) {
|
||||||
|
|
||||||
Executor executor = Executor.getExecutor();
|
Executor executor = Executor.getExecutor();
|
||||||
|
|
||||||
if (executor.getExecutorType() == command.getTaskType() &&
|
if (executor.getExecutorType() == command.getTaskType() &&
|
|
@ -1,6 +1,8 @@
|
||||||
package ch.unisg.executor1.executor.domain;
|
package ch.unisg.executor2.executor.domain;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import ch.unisg.executorBase.executor.domain.ExecutorBase;
|
||||||
|
import ch.unisg.executorBase.executor.domain.ExecutorType;
|
||||||
|
|
||||||
public class Executor extends ExecutorBase {
|
public class Executor extends ExecutorBase {
|
||||||
|
|
||||||
|
@ -15,9 +17,10 @@ public class Executor extends ExecutorBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
protected
|
||||||
String execution() {
|
String execution() {
|
||||||
|
|
||||||
int a = 10;
|
int a = 20;
|
||||||
int b = 20;
|
int b = 20;
|
||||||
try {
|
try {
|
||||||
TimeUnit.SECONDS.sleep(10);
|
TimeUnit.SECONDS.sleep(10);
|
Loading…
Reference in New Issue
Block a user