bugfixes
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package ch.unisg.executorBase.executor.adapter.in.web;
|
||||
package ch.unisg.executorbase.executor.adapter.in.web;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -30,7 +30,7 @@ public class TaskAvailableController {
|
||||
@GetMapping(path = "/newtask/{taskType}", consumes = { "application/json" })
|
||||
public ResponseEntity<String> retrieveTaskFromTaskList(@PathVariable("taskType") String taskType) {
|
||||
|
||||
logger.info("New " + taskType + " available");
|
||||
logger.info("ExecutorBase | New " + taskType + " task available");
|
||||
|
||||
if (ExecutorType.contains(taskType.toUpperCase())) {
|
||||
TaskAvailableCommand command = new TaskAvailableCommand(
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package ch.unisg.executorBase.executor.adapter.out.web;
|
||||
package ch.unisg.executorbase.executor.adapter.out.web;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@@ -28,6 +28,8 @@ public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort
|
||||
@Override
|
||||
public void publishExecutionFinishedEvent(ExecutionFinishedEvent event) {
|
||||
|
||||
logger.log(Level.INFO, "ExecutorBase | Sending finish execution event....");
|
||||
|
||||
String body = new JSONObject()
|
||||
.put("taskID", event.getTaskID())
|
||||
.put("outputData", event.getOutputData())
|
||||
@@ -51,8 +53,7 @@ public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort
|
||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
}
|
||||
|
||||
logger.log(Level.INFO, "Finish execution event sent with result: {0}", event.getOutputData());
|
||||
|
||||
logger.log(Level.INFO, "ExecutorBase | Finish execution event sent with result: {0}", event.getOutputData());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -8,7 +8,6 @@ import java.net.http.HttpResponse;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -52,15 +51,17 @@ public class GetAssignmentAdapter implements GetAssignmentPort {
|
||||
try {
|
||||
logger.info("ExecutorBase | Sending getAssignment request");
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
if (response.statusCode() != HttpStatus.CREATED.value()) {
|
||||
if (response.statusCode() != HttpStatus.OK.value()) {
|
||||
logger.info("ExecutorBase | No task assigned");
|
||||
return null;
|
||||
}
|
||||
logger.info("ExecutorBase | Task assigned");
|
||||
JSONObject responseBody = new JSONObject(response.body());
|
||||
|
||||
String inputData = responseBody.getString("inputData");
|
||||
return new Task(responseBody.getString("taskID"), inputData);
|
||||
if (!responseBody.get("inputData").equals(null)) {
|
||||
return new Task(responseBody.getString("taskID"), responseBody.getString("inputData"));
|
||||
}
|
||||
return new Task(responseBody.getString("taskID"));
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
|
@@ -9,7 +9,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@@ -4,9 +4,11 @@ import javax.validation.constraints.NotNull;
|
||||
|
||||
import ch.unisg.common.validation.SelfValidating;
|
||||
import ch.unisg.executorbase.executor.domain.ExecutorType;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
public class TaskAvailableCommand extends SelfValidating<TaskAvailableCommand> {
|
||||
|
||||
@NotNull
|
||||
|
@@ -15,6 +15,6 @@ public class TaskAvailableService implements TaskAvailableUseCase {
|
||||
|
||||
@Override
|
||||
public void newTaskAvailable(TaskAvailableCommand command) {
|
||||
// Placeholder so spring can create a bean, implementation of this function is inside the executors
|
||||
// Placeholder so spring can create a bean, implementation of this service is inside the individual executors
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,10 @@
|
||||
package ch.unisg.executorbase.executor.domain;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.unisg.common.valueobject.ExecutorURI;
|
||||
import ch.unisg.executorBase.executor.adapter.out.web.ExecutionFinishedEventAdapter;
|
||||
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.port.out.ExecutionFinishedEventPort;
|
||||
@@ -35,18 +34,19 @@ public abstract class ExecutorBase {
|
||||
Logger logger = Logger.getLogger(ExecutorBase.class.getName());
|
||||
|
||||
protected ExecutorBase(ExecutorType executorType) {
|
||||
logger.info("Starting Executor");
|
||||
logger.info("ExecutorBase | Starting Executor");
|
||||
this.status = ExecutorStatus.STARTING_UP;
|
||||
this.executorType = executorType;
|
||||
// TODO set this automaticly
|
||||
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.
|
||||
logger.info("ExecutorBase | Notifying executor-pool about existens");
|
||||
if(!notifyExecutorPoolService.notifyExecutorPool(this.executorURI, this.executorType)) {
|
||||
logger.log(Level.WARNING, "Executor could not connect to executor pool! Shuting down!");
|
||||
logger.log(Level.WARNING, "ExecutorBase | Executor could not connect to executor pool! Shuting down!");
|
||||
System.exit(0);
|
||||
} else {
|
||||
logger.info("Executor conntected to executor pool");
|
||||
logger.info("ExecutorBase | Executor conntected to executor pool");
|
||||
this.status = ExecutorStatus.IDLING;
|
||||
getAssignment();
|
||||
}
|
||||
@@ -59,10 +59,10 @@ public abstract class ExecutorBase {
|
||||
public void getAssignment() {
|
||||
Task newTask = getAssignmentPort.getAssignment(this.getExecutorType(), this.getExecutorURI());
|
||||
if (newTask != null) {
|
||||
logger.info("Executor got a new task");
|
||||
logger.info("ExecutorBase | Executor got a new task");
|
||||
this.executeTask(newTask);
|
||||
} else {
|
||||
logger.info("Executor got no new task");
|
||||
logger.info("ExecutorBase | Executor got no new task");
|
||||
this.status = ExecutorStatus.IDLING;
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public abstract class ExecutorBase {
|
||||
* @return void
|
||||
**/
|
||||
private void executeTask(Task task) {
|
||||
logger.info("Starting execution");
|
||||
logger.info("ExecutorBase | Starting execution");
|
||||
this.status = ExecutorStatus.EXECUTING;
|
||||
|
||||
task.setOutputData(execution(task.getInputData()));
|
||||
@@ -81,7 +81,7 @@ public abstract class ExecutorBase {
|
||||
executionFinishedEventPort.publishExecutionFinishedEvent(
|
||||
new ExecutionFinishedEvent(task.getTaskID(), task.getOutputData(), "SUCCESS"));
|
||||
|
||||
logger.info("Finish execution");
|
||||
logger.info("ExecutorBase | Finish execution");
|
||||
getAssignment();
|
||||
}
|
||||
|
||||
|
@@ -19,7 +19,12 @@ public class Task {
|
||||
|
||||
public Task(String taskID, String inputData) {
|
||||
this.taskID = taskID;
|
||||
this.inputData= inputData;
|
||||
this.inputData = inputData;
|
||||
}
|
||||
|
||||
public Task(String taskID) {
|
||||
this.taskID = taskID;
|
||||
this.inputData = "";
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user