fixed multiple bugs & updated cicd workflows
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package ch.unisg.executorbase.executor.adapter.in.web;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -19,6 +21,8 @@ public class TaskAvailableController {
|
||||
this.taskAvailableUseCase = taskAvailableUseCase;
|
||||
}
|
||||
|
||||
Logger logger = Logger.getLogger(TaskAvailableController.class.getName());
|
||||
|
||||
/**
|
||||
* Controller for notification about new events.
|
||||
* @return 200 OK
|
||||
@@ -26,6 +30,8 @@ public class TaskAvailableController {
|
||||
@GetMapping(path = "/newtask/{taskType}", consumes = { "application/json" })
|
||||
public ResponseEntity<String> retrieveTaskFromTaskList(@PathVariable("taskType") String taskType) {
|
||||
|
||||
logger.info("New " + taskType + " available");
|
||||
|
||||
if (ExecutorType.contains(taskType.toUpperCase())) {
|
||||
TaskAvailableCommand command = new TaskAvailableCommand(
|
||||
ExecutorType.valueOf(taskType.toUpperCase()));
|
||||
|
@@ -16,8 +16,9 @@ import ch.unisg.executorbase.executor.domain.ExecutionFinishedEvent;
|
||||
|
||||
public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort {
|
||||
|
||||
// TODO url doesn't get mapped bc no autowiring
|
||||
@Value("${roster.url}")
|
||||
String server;
|
||||
String server = "http://localhost:8082";
|
||||
|
||||
Logger logger = Logger.getLogger(ExecutionFinishedEventAdapter.class.getName());
|
||||
|
||||
@@ -28,6 +29,9 @@ public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort
|
||||
@Override
|
||||
public void publishExecutionFinishedEvent(ExecutionFinishedEvent event) {
|
||||
|
||||
System.out.println("HI");
|
||||
System.out.println(server);
|
||||
|
||||
String body = new JSONObject()
|
||||
.put("taskID", event.getTaskID())
|
||||
.put("result", event.getResult())
|
||||
@@ -41,6 +45,9 @@ public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort
|
||||
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||
.build();
|
||||
|
||||
|
||||
System.out.println(server);
|
||||
|
||||
try {
|
||||
client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
} catch (InterruptedException e) {
|
||||
@@ -50,7 +57,7 @@ public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort
|
||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
}
|
||||
|
||||
logger.log(Level.INFO, "Finish execution event sent with result: {}", event.getResult());
|
||||
logger.log(Level.INFO, "Finish execution event sent with result: {0}", event.getResult());
|
||||
|
||||
}
|
||||
|
||||
|
@@ -23,8 +23,9 @@ import org.json.JSONObject;
|
||||
@Primary
|
||||
public class GetAssignmentAdapter implements GetAssignmentPort {
|
||||
|
||||
// TODO Not working for now bc it doesn't get autowired
|
||||
@Value("${roster.url}")
|
||||
String server;
|
||||
String server = "http://127.0.0.1:8082";
|
||||
|
||||
Logger logger = Logger.getLogger(GetAssignmentAdapter.class.getName());
|
||||
|
||||
@@ -51,12 +52,15 @@ public class GetAssignmentAdapter implements GetAssignmentPort {
|
||||
try {
|
||||
logger.info("Sending getAssignment Request");
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
logger.log(Level.INFO, "getAssignment request result:\n {}", response.body());
|
||||
logger.log(Level.INFO, "getAssignment request result:\n {0}", response.body());
|
||||
if (response.body().equals("")) {
|
||||
return null;
|
||||
}
|
||||
JSONObject responseBody = new JSONObject(response.body());
|
||||
return new Task(responseBody.getString("taskID"), responseBody.getString("input"));
|
||||
|
||||
String[] input = { "1", "+", "2" };
|
||||
// TODO Add input in roster + tasklist
|
||||
return new Task(responseBody.getString("taskID"), input);
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
|
@@ -22,8 +22,9 @@ import ch.unisg.executorbase.executor.domain.ExecutorType;
|
||||
@Primary
|
||||
public class NotifyExecutorPoolAdapter implements NotifyExecutorPoolPort {
|
||||
|
||||
@Value("${executor-pool.url}")
|
||||
String server;
|
||||
// TODO Not working for now bc it doesn't get autowired
|
||||
@Value("${executor.pool.url}")
|
||||
String server = "http://127.0.0.1:8083";
|
||||
|
||||
Logger logger = Logger.getLogger(NotifyExecutorPoolAdapter.class.getName());
|
||||
|
||||
@@ -36,7 +37,7 @@ public class NotifyExecutorPoolAdapter implements NotifyExecutorPoolPort {
|
||||
|
||||
String body = new JSONObject()
|
||||
.put("executorTaskType", executorType)
|
||||
.put("executorURI", executorURI.getValue())
|
||||
.put("executorUri", executorURI.getValue())
|
||||
.toString();
|
||||
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
|
@@ -23,9 +23,8 @@ public abstract class ExecutorBase {
|
||||
@Getter
|
||||
private ExecutorStatus status;
|
||||
|
||||
// TODO Violation of the Dependency Inversion Principle?, but we havn't really got a better solutions to send a http request / access a service from a domain model
|
||||
// TODO I guess we can implement the execution as a service but there still is the problem with the startup request.
|
||||
// TODO I guess we can somehow autowire this but I don't know why it's not working :D
|
||||
// TODO Violation of the Dependency Inversion Principle?,
|
||||
// TODO do this with only services
|
||||
private final NotifyExecutorPoolPort notifyExecutorPoolPort = new NotifyExecutorPoolAdapter();
|
||||
private final NotifyExecutorPoolService notifyExecutorPoolService = new NotifyExecutorPoolService(notifyExecutorPoolPort);
|
||||
private final GetAssignmentPort getAssignmentPort = new GetAssignmentAdapter();
|
||||
@@ -38,8 +37,8 @@ public abstract class ExecutorBase {
|
||||
this.status = ExecutorStatus.STARTING_UP;
|
||||
this.executorType = executorType;
|
||||
// TODO set this automaticly
|
||||
this.executorURI = new ExecutorURI("localhost:8084");
|
||||
|
||||
this.executorURI = new ExecutorURI("http://localhost:8084");
|
||||
// TODO do this in main
|
||||
// Notify executor-pool about existence. If executor-pools response is successfull start with getting an assignment, else shut down executor.
|
||||
if(!notifyExecutorPoolService.notifyExecutorPool(this.executorURI, this.executorType)) {
|
||||
System.exit(0);
|
||||
@@ -55,6 +54,8 @@ public abstract class ExecutorBase {
|
||||
**/
|
||||
public void getAssignment() {
|
||||
Task newTask = getAssignmentPort.getAssignment(this.getExecutorType(), this.getExecutorURI());
|
||||
System.out.println("New assignment");
|
||||
System.out.println(newTask);
|
||||
if (newTask != null) {
|
||||
this.executeTask(newTask);
|
||||
} else {
|
||||
@@ -72,6 +73,8 @@ public abstract class ExecutorBase {
|
||||
|
||||
task.setResult(execution(task.getInput()));
|
||||
|
||||
System.out.println(task.getResult());
|
||||
|
||||
// TODO implement logic if execution was not successful
|
||||
executionFinishedEventPort.publishExecutionFinishedEvent(
|
||||
new ExecutionFinishedEvent(task.getTaskID(), task.getResult(), "SUCCESS"));
|
||||
|
@@ -1,6 +1,6 @@
|
||||
server.port=8081
|
||||
roster.url=http://127.0.0.1:8082
|
||||
executor-pool.url=http://127.0.0.1:8083
|
||||
executor.pool.url=http://127.0.0.1:8083
|
||||
executor1.url=http://127.0.0.1:8084
|
||||
executor2.url=http://127.0.0.1:8085
|
||||
task-list.url=http://127.0.0.1:8081
|
||||
|
Reference in New Issue
Block a user