diff --git a/executor-pool/src/main/java/ch/unisg/executorpool/adapter/common/formats/ExecutorJsonRepresentation.java b/executor-pool/src/main/java/ch/unisg/executorpool/adapter/common/formats/ExecutorJsonRepresentation.java deleted file mode 100644 index 3c8f6e4..0000000 --- a/executor-pool/src/main/java/ch/unisg/executorpool/adapter/common/formats/ExecutorJsonRepresentation.java +++ /dev/null @@ -1,51 +0,0 @@ -package ch.unisg.executorpool.adapter.common.formats; - -import ch.unisg.executorpool.domain.ExecutorClass; -import lombok.Getter; -import lombok.Setter; -import org.json.JSONArray; -import org.json.JSONObject; - -import java.util.List; - -public class ExecutorJsonRepresentation { - public static final String EXECUTOR_MEDIA_TYPE = "application/json"; - - @Getter @Setter - private String executorUri; - - @Getter @Setter - private String executorTaskType; - - // TODO Check if this need Setters. Also applies to AuctionJsonRepresentation - public ExecutorJsonRepresentation(String executorUri, String executorTaskType){ - this.executorUri = executorUri; - this.executorTaskType = executorTaskType; - } - - public static String serialize(ExecutorClass executorClass) { - JSONObject payload = new JSONObject(); - - payload.put("executorUri", executorClass.getExecutorUri().getValue()); - payload.put("executorTaskType", executorClass.getExecutorTaskType().getValue()); - - return payload.toString(); - } - - public static String serialize(List listOfExecutors) { - JSONArray jsonArray = new JSONArray(); - - for (ExecutorClass executor: listOfExecutors) { - JSONObject jsonObject = new JSONObject(); - - jsonObject.put("executorUri", executor.getExecutorUri().getValue()); - jsonObject.put("executorTaskType", executor.getExecutorTaskType().getValue()); - - jsonArray.put(jsonObject); - } - - return jsonArray.toString(); - } - - private ExecutorJsonRepresentation() { } -} diff --git a/executor-pool/src/main/java/ch/unisg/executorpool/adapter/in/web/AddNewExecutorToExecutorPoolWebController.java b/executor-pool/src/main/java/ch/unisg/executorpool/adapter/in/web/AddNewExecutorToExecutorPoolWebController.java index 5a2dc09..7967b6b 100644 --- a/executor-pool/src/main/java/ch/unisg/executorpool/adapter/in/web/AddNewExecutorToExecutorPoolWebController.java +++ b/executor-pool/src/main/java/ch/unisg/executorpool/adapter/in/web/AddNewExecutorToExecutorPoolWebController.java @@ -1,6 +1,5 @@ package ch.unisg.executorpool.adapter.in.web; -import ch.unisg.executorpool.adapter.common.formats.ExecutorJsonRepresentation; import ch.unisg.executorpool.application.port.in.AddNewExecutorToExecutorPoolUseCase; import ch.unisg.executorpool.application.port.in.AddNewExecutorToExecutorPoolCommand; import ch.unisg.executorpool.domain.ExecutorClass; @@ -12,7 +11,6 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ResponseStatusException; import javax.validation.ConstraintViolationException; -import java.net.URI; @RestController public class AddNewExecutorToExecutorPoolWebController { @@ -22,20 +20,19 @@ public class AddNewExecutorToExecutorPoolWebController { this.addNewExecutorToExecutorPoolUseCase = addNewExecutorToExecutorPoolUseCase; } - @PostMapping(path = "/executor-pool/AddExecutor", consumes = {ExecutorJsonRepresentation.EXECUTOR_MEDIA_TYPE}) - public ResponseEntity addNewExecutorToExecutorPool(@RequestBody ExecutorJsonRepresentation payload){ + @PostMapping(path = "/executor-pool/AddExecutor", consumes = {ExecutorMediaType.EXECUTOR_MEDIA_TYPE}) + public ResponseEntity addNewExecutorToExecutorPool(@RequestBody ExecutorClass executorClass){ try{ AddNewExecutorToExecutorPoolCommand command = new AddNewExecutorToExecutorPoolCommand( - new ExecutorClass.ExecutorUri(URI.create(payload.getExecutorUri())), - new ExecutorClass.ExecutorTaskType(payload.getExecutorTaskType()) + executorClass.getExecutorIp(), executorClass.getExecutorPort(), executorClass.getExecutorTaskType() ); ExecutorClass newExecutor = addNewExecutorToExecutorPoolUseCase.addNewExecutorToExecutorPool(command); HttpHeaders responseHeaders = new HttpHeaders(); - responseHeaders.add(HttpHeaders.CONTENT_TYPE, ExecutorJsonRepresentation.EXECUTOR_MEDIA_TYPE); + responseHeaders.add(HttpHeaders.CONTENT_TYPE, ExecutorMediaType.EXECUTOR_MEDIA_TYPE); - return new ResponseEntity<>(ExecutorJsonRepresentation.serialize(newExecutor), responseHeaders, HttpStatus.CREATED); + return new ResponseEntity<>(ExecutorMediaType.serialize(newExecutor), responseHeaders, HttpStatus.CREATED); } catch (ConstraintViolationException e){ throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage()); } diff --git a/executor-pool/src/main/java/ch/unisg/executorpool/adapter/in/web/ExecutorMediaType.java b/executor-pool/src/main/java/ch/unisg/executorpool/adapter/in/web/ExecutorMediaType.java new file mode 100644 index 0000000..0ca4e1f --- /dev/null +++ b/executor-pool/src/main/java/ch/unisg/executorpool/adapter/in/web/ExecutorMediaType.java @@ -0,0 +1,38 @@ +package ch.unisg.executorpool.adapter.in.web; + +import ch.unisg.executorpool.domain.ExecutorClass; +import org.json.JSONArray; +import org.json.JSONObject; + +import java.util.List; + +final public class ExecutorMediaType { + public static final String EXECUTOR_MEDIA_TYPE = "application/json"; + + public static String serialize(ExecutorClass executorClass) { + JSONObject payload = new JSONObject(); + + payload.put("executorIp", executorClass.getExecutorIp().getValue()); + payload.put("executorPort", executorClass.getExecutorPort().getValue()); + payload.put("executorTaskType", executorClass.getExecutorTaskType().getValue()); + + return payload.toString(); + } + + public static String serialize(List listOfExecutors) { + String serializedList = "[ \n"; + + for (ExecutorClass executor: listOfExecutors) { + serializedList += serialize(executor) + "\n"; + } + + // return serializedList + "\n ]"; + JSONArray jsonArray = new JSONArray(); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("executorIp", "localhost"); + jsonArray.put(jsonObject); + return jsonArray.toString(); + } + + private ExecutorMediaType() { } +} diff --git a/executor-pool/src/main/java/ch/unisg/executorpool/adapter/in/web/GetAllExecutorInExecutorPoolByTypeWebController.java b/executor-pool/src/main/java/ch/unisg/executorpool/adapter/in/web/GetAllExecutorInExecutorPoolByTypeWebController.java new file mode 100644 index 0000000..2595781 --- /dev/null +++ b/executor-pool/src/main/java/ch/unisg/executorpool/adapter/in/web/GetAllExecutorInExecutorPoolByTypeWebController.java @@ -0,0 +1,35 @@ +package ch.unisg.executorpool.adapter.in.web; + +import ch.unisg.executorpool.application.port.in.GetAllExecutorInExecutorPoolByTypeQuery; +import ch.unisg.executorpool.application.port.in.GetAllExecutorInExecutorPoolByTypeUseCase; +import ch.unisg.executorpool.domain.ExecutorClass; +import ch.unisg.executorpool.domain.ExecutorClass.ExecutorTaskType; +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 java.util.List; + +@RestController +public class GetAllExecutorInExecutorPoolByTypeWebController { + private final GetAllExecutorInExecutorPoolByTypeUseCase getAllExecutorInExecutorPoolByTypeUseCase; + + public GetAllExecutorInExecutorPoolByTypeWebController(GetAllExecutorInExecutorPoolByTypeUseCase getAllExecutorInExecutorPoolByTypeUseCase){ + this.getAllExecutorInExecutorPoolByTypeUseCase = getAllExecutorInExecutorPoolByTypeUseCase; + } + + @GetMapping(path = "/executor-pool/GetAllExecutorInExecutorPoolByType/{taskType}") + public ResponseEntity getAllExecutorInExecutorPoolByType(@PathVariable("taskType") String taskType){ + GetAllExecutorInExecutorPoolByTypeQuery query = new GetAllExecutorInExecutorPoolByTypeQuery(new ExecutorTaskType(taskType)); + List matchedExecutors = getAllExecutorInExecutorPoolByTypeUseCase.getAllExecutorInExecutorPoolByType(query); + + // Add the content type as a response header + HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.add(HttpHeaders.CONTENT_TYPE, ExecutorMediaType.EXECUTOR_MEDIA_TYPE); + + return new ResponseEntity<>(ExecutorMediaType.serialize(matchedExecutors), responseHeaders, HttpStatus.OK); + } +} diff --git a/executor-pool/src/main/java/ch/unisg/executorpool/adapter/in/web/GetAllExecutorsInExecutorPoolByTypeWebController.java b/executor-pool/src/main/java/ch/unisg/executorpool/adapter/in/web/GetAllExecutorsInExecutorPoolByTypeWebController.java deleted file mode 100644 index 8c7ce3d..0000000 --- a/executor-pool/src/main/java/ch/unisg/executorpool/adapter/in/web/GetAllExecutorsInExecutorPoolByTypeWebController.java +++ /dev/null @@ -1,36 +0,0 @@ -package ch.unisg.executorpool.adapter.in.web; - -import ch.unisg.executorpool.adapter.common.formats.ExecutorJsonRepresentation; -import ch.unisg.executorpool.application.port.in.GetAllExecutorsInExecutorPoolByTypeQuery; -import ch.unisg.executorpool.application.port.in.GetAllExecutorsInExecutorPoolByTypeUseCase; -import ch.unisg.executorpool.domain.ExecutorClass; -import ch.unisg.executorpool.domain.ExecutorClass.ExecutorTaskType; -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 java.util.List; - -@RestController -public class GetAllExecutorsInExecutorPoolByTypeWebController { - private final GetAllExecutorsInExecutorPoolByTypeUseCase getAllExecutorsInExecutorPoolByTypeUseCase; - - public GetAllExecutorsInExecutorPoolByTypeWebController(GetAllExecutorsInExecutorPoolByTypeUseCase getAllExecutorInExecutorPoolByTypeUseCase){ - this.getAllExecutorsInExecutorPoolByTypeUseCase = getAllExecutorInExecutorPoolByTypeUseCase; - } - - @GetMapping(path = "/executor-pool/GetAllExecutorsInExecutorPoolByType/{taskType}") - public ResponseEntity getAllExecutorInExecutorPoolByType(@PathVariable("taskType") String taskType){ - GetAllExecutorsInExecutorPoolByTypeQuery query = new GetAllExecutorsInExecutorPoolByTypeQuery(new ExecutorTaskType(taskType)); - List matchedExecutors = getAllExecutorsInExecutorPoolByTypeUseCase.getAllExecutorsInExecutorPoolByType(query); - - // Add the content type as a response header - HttpHeaders responseHeaders = new HttpHeaders(); - responseHeaders.add(HttpHeaders.CONTENT_TYPE, ExecutorJsonRepresentation.EXECUTOR_MEDIA_TYPE); - - return new ResponseEntity<>(ExecutorJsonRepresentation.serialize(matchedExecutors), responseHeaders, HttpStatus.OK); - } -} diff --git a/executor-pool/src/main/java/ch/unisg/executorpool/adapter/in/web/GetAllExecutorsInExecutorPoolWebController.java b/executor-pool/src/main/java/ch/unisg/executorpool/adapter/in/web/GetAllExecutorsInExecutorPoolWebController.java index 13a631a..70a5fd2 100644 --- a/executor-pool/src/main/java/ch/unisg/executorpool/adapter/in/web/GetAllExecutorsInExecutorPoolWebController.java +++ b/executor-pool/src/main/java/ch/unisg/executorpool/adapter/in/web/GetAllExecutorsInExecutorPoolWebController.java @@ -1,6 +1,5 @@ package ch.unisg.executorpool.adapter.in.web; -import ch.unisg.executorpool.adapter.common.formats.ExecutorJsonRepresentation; import ch.unisg.executorpool.application.port.in.GetAllExecutorsInExecutorPoolUseCase; import ch.unisg.executorpool.domain.ExecutorClass; import org.springframework.http.HttpHeaders; @@ -25,8 +24,8 @@ public class GetAllExecutorsInExecutorPoolWebController { // Add the content type as a response header HttpHeaders responseHeaders = new HttpHeaders(); - responseHeaders.add(HttpHeaders.CONTENT_TYPE, ExecutorJsonRepresentation.EXECUTOR_MEDIA_TYPE); + responseHeaders.add(HttpHeaders.CONTENT_TYPE, ExecutorMediaType.EXECUTOR_MEDIA_TYPE); - return new ResponseEntity<>(ExecutorJsonRepresentation.serialize(executorClassList), responseHeaders, HttpStatus.OK); + return new ResponseEntity<>(ExecutorMediaType.serialize(executorClassList), responseHeaders, HttpStatus.OK); } } diff --git a/executor-pool/src/main/java/ch/unisg/executorpool/adapter/in/web/RemoveExecutorFromExecutorPoolWebController.java b/executor-pool/src/main/java/ch/unisg/executorpool/adapter/in/web/RemoveExecutorFromExecutorPoolWebController.java index 28c3511..69bbde3 100644 --- a/executor-pool/src/main/java/ch/unisg/executorpool/adapter/in/web/RemoveExecutorFromExecutorPoolWebController.java +++ b/executor-pool/src/main/java/ch/unisg/executorpool/adapter/in/web/RemoveExecutorFromExecutorPoolWebController.java @@ -1,6 +1,5 @@ package ch.unisg.executorpool.adapter.in.web; -import ch.unisg.executorpool.adapter.common.formats.ExecutorJsonRepresentation; import ch.unisg.executorpool.application.port.in.RemoveExecutorFromExecutorPoolCommand; import ch.unisg.executorpool.application.port.in.RemoveExecutorFromExecutorPoolUseCase; import ch.unisg.executorpool.domain.ExecutorClass; @@ -12,7 +11,6 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ResponseStatusException; -import java.net.URI; import java.util.Optional; @RestController @@ -23,11 +21,9 @@ public class RemoveExecutorFromExecutorPoolWebController { this.removeExecutorFromExecutorPoolUseCase = removeExecutorFromExecutorPoolUseCase; } - @PostMapping(path = "/executor-pool/RemoveExecutor", consumes = {ExecutorJsonRepresentation.EXECUTOR_MEDIA_TYPE}) - public ResponseEntity removeExecutorFromExecutorPool(@RequestBody ExecutorJsonRepresentation executorJsonRepresentation){ - RemoveExecutorFromExecutorPoolCommand command = new RemoveExecutorFromExecutorPoolCommand( - new ExecutorClass.ExecutorUri(URI.create(executorJsonRepresentation.getExecutorUri())) - ); + @PostMapping(path = "/executor-pool/RemoveExecutor", consumes = {ExecutorMediaType.EXECUTOR_MEDIA_TYPE}) + public ResponseEntity removeExecutorFromExecutorPool(@RequestBody ExecutorClass executorClass){ + RemoveExecutorFromExecutorPoolCommand command = new RemoveExecutorFromExecutorPoolCommand(executorClass.getExecutorIp(), executorClass.getExecutorPort()); Optional removedExecutor = removeExecutorFromExecutorPoolUseCase.removeExecutorFromExecutorPool(command); if(removedExecutor.isEmpty()){ @@ -35,9 +31,9 @@ public class RemoveExecutorFromExecutorPoolWebController { } HttpHeaders responseHeaders = new HttpHeaders(); - responseHeaders.add(HttpHeaders.CONTENT_TYPE, ExecutorJsonRepresentation.EXECUTOR_MEDIA_TYPE); + responseHeaders.add(HttpHeaders.CONTENT_TYPE, ExecutorMediaType.EXECUTOR_MEDIA_TYPE); - return new ResponseEntity<>(ExecutorJsonRepresentation.serialize(removedExecutor.get()), responseHeaders, + return new ResponseEntity<>(ExecutorMediaType.serialize(removedExecutor.get()), responseHeaders, HttpStatus.OK); } } diff --git a/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/AddNewExecutorToExecutorPoolCommand.java b/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/AddNewExecutorToExecutorPoolCommand.java index ddd7da9..2682610 100644 --- a/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/AddNewExecutorToExecutorPoolCommand.java +++ b/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/AddNewExecutorToExecutorPoolCommand.java @@ -2,7 +2,8 @@ package ch.unisg.executorpool.application.port.in; import ch.unisg.common.SelfValidating; import ch.unisg.executorpool.domain.ExecutorPool; -import ch.unisg.executorpool.domain.ExecutorClass.ExecutorUri; +import ch.unisg.executorpool.domain.ExecutorClass.ExecutorIp; +import ch.unisg.executorpool.domain.ExecutorClass.ExecutorPort; import ch.unisg.executorpool.domain.ExecutorClass.ExecutorTaskType; import lombok.Value; import javax.validation.constraints.NotNull; @@ -10,13 +11,17 @@ import javax.validation.constraints.NotNull; @Value public class AddNewExecutorToExecutorPoolCommand extends SelfValidating { @NotNull - private final ExecutorUri executorUri; + private final ExecutorIp executorIp; + + @NotNull + private final ExecutorPort executorPort; @NotNull private final ExecutorTaskType executorTaskType; - public AddNewExecutorToExecutorPoolCommand(ExecutorUri executorUri, ExecutorTaskType executorTaskType){ - this.executorUri = executorUri; + public AddNewExecutorToExecutorPoolCommand(ExecutorIp executorIp, ExecutorPort executorPort, ExecutorTaskType executorTaskType){ + this.executorIp = executorIp; + this.executorPort = executorPort; this.executorTaskType = executorTaskType; this.validateSelf(); } diff --git a/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/GetAllExecutorsInExecutorPoolByTypeQuery.java b/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/GetAllExecutorInExecutorPoolByTypeQuery.java similarity index 64% rename from executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/GetAllExecutorsInExecutorPoolByTypeQuery.java rename to executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/GetAllExecutorInExecutorPoolByTypeQuery.java index 079e7e1..c812eab 100644 --- a/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/GetAllExecutorsInExecutorPoolByTypeQuery.java +++ b/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/GetAllExecutorInExecutorPoolByTypeQuery.java @@ -7,11 +7,11 @@ import lombok.Value; import javax.validation.constraints.NotNull; @Value -public class GetAllExecutorsInExecutorPoolByTypeQuery extends SelfValidating { +public class GetAllExecutorInExecutorPoolByTypeQuery extends SelfValidating { @NotNull private final ExecutorTaskType executorTaskType; - public GetAllExecutorsInExecutorPoolByTypeQuery(ExecutorTaskType executorTaskType){ + public GetAllExecutorInExecutorPoolByTypeQuery(ExecutorTaskType executorTaskType){ this.executorTaskType = executorTaskType; this.validateSelf(); } diff --git a/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/GetAllExecutorInExecutorPoolByTypeUseCase.java b/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/GetAllExecutorInExecutorPoolByTypeUseCase.java new file mode 100644 index 0000000..9f612bf --- /dev/null +++ b/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/GetAllExecutorInExecutorPoolByTypeUseCase.java @@ -0,0 +1,9 @@ +package ch.unisg.executorpool.application.port.in; + +import ch.unisg.executorpool.domain.ExecutorClass; + +import java.util.List; + +public interface GetAllExecutorInExecutorPoolByTypeUseCase { + List getAllExecutorInExecutorPoolByType(GetAllExecutorInExecutorPoolByTypeQuery query); +} diff --git a/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/GetAllExecutorsInExecutorPoolByTypeUseCase.java b/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/GetAllExecutorsInExecutorPoolByTypeUseCase.java deleted file mode 100644 index 4821284..0000000 --- a/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/GetAllExecutorsInExecutorPoolByTypeUseCase.java +++ /dev/null @@ -1,9 +0,0 @@ -package ch.unisg.executorpool.application.port.in; - -import ch.unisg.executorpool.domain.ExecutorClass; - -import java.util.List; - -public interface GetAllExecutorsInExecutorPoolByTypeUseCase { - List getAllExecutorsInExecutorPoolByType(GetAllExecutorsInExecutorPoolByTypeQuery query); -} diff --git a/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/RemoveExecutorFromExecutorPoolCommand.java b/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/RemoveExecutorFromExecutorPoolCommand.java index 162426c..11763a9 100644 --- a/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/RemoveExecutorFromExecutorPoolCommand.java +++ b/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/RemoveExecutorFromExecutorPoolCommand.java @@ -1,7 +1,9 @@ package ch.unisg.executorpool.application.port.in; +import ch.unisg.executorpool.domain.ExecutorClass; import ch.unisg.common.SelfValidating; -import ch.unisg.executorpool.domain.ExecutorClass.ExecutorUri; +import ch.unisg.executorpool.domain.ExecutorClass.ExecutorIp; +import ch.unisg.executorpool.domain.ExecutorClass.ExecutorPort; import lombok.Value; import javax.validation.constraints.NotNull; @@ -9,10 +11,14 @@ import javax.validation.constraints.NotNull; @Value public class RemoveExecutorFromExecutorPoolCommand extends SelfValidating { @NotNull - private final ExecutorUri executorUri; + private final ExecutorIp executorIp; - public RemoveExecutorFromExecutorPoolCommand(ExecutorUri executorUri){ - this.executorUri = executorUri; + @NotNull + private final ExecutorPort executorPort; + + public RemoveExecutorFromExecutorPoolCommand(ExecutorIp executorIp, ExecutorPort executorPort){ + this.executorIp = executorIp; + this.executorPort = executorPort; this.validateSelf(); } } diff --git a/executor-pool/src/main/java/ch/unisg/executorpool/application/service/AddNewExecutorToExecutorPoolService.java b/executor-pool/src/main/java/ch/unisg/executorpool/application/service/AddNewExecutorToExecutorPoolService.java index 200739b..e1ef237 100644 --- a/executor-pool/src/main/java/ch/unisg/executorpool/application/service/AddNewExecutorToExecutorPoolService.java +++ b/executor-pool/src/main/java/ch/unisg/executorpool/application/service/AddNewExecutorToExecutorPoolService.java @@ -20,6 +20,6 @@ public class AddNewExecutorToExecutorPoolService implements AddNewExecutorToExec public ExecutorClass addNewExecutorToExecutorPool(AddNewExecutorToExecutorPoolCommand command){ ExecutorPool executorPool = ExecutorPool.getExecutorPool(); - return executorPool.addNewExecutor(command.getExecutorUri(), command.getExecutorTaskType()); + return executorPool.addNewExecutor(command.getExecutorIp(), command.getExecutorPort(), command.getExecutorTaskType()); } } diff --git a/executor-pool/src/main/java/ch/unisg/executorpool/application/service/GetAllExecutorsInExecutorPoolByTypeService.java b/executor-pool/src/main/java/ch/unisg/executorpool/application/service/GetAllExecutorInExecutorPoolByTypeService.java similarity index 56% rename from executor-pool/src/main/java/ch/unisg/executorpool/application/service/GetAllExecutorsInExecutorPoolByTypeService.java rename to executor-pool/src/main/java/ch/unisg/executorpool/application/service/GetAllExecutorInExecutorPoolByTypeService.java index 00d1636..74988b2 100644 --- a/executor-pool/src/main/java/ch/unisg/executorpool/application/service/GetAllExecutorsInExecutorPoolByTypeService.java +++ b/executor-pool/src/main/java/ch/unisg/executorpool/application/service/GetAllExecutorInExecutorPoolByTypeService.java @@ -1,7 +1,7 @@ package ch.unisg.executorpool.application.service; -import ch.unisg.executorpool.application.port.in.GetAllExecutorsInExecutorPoolByTypeQuery; -import ch.unisg.executorpool.application.port.in.GetAllExecutorsInExecutorPoolByTypeUseCase; +import ch.unisg.executorpool.application.port.in.GetAllExecutorInExecutorPoolByTypeQuery; +import ch.unisg.executorpool.application.port.in.GetAllExecutorInExecutorPoolByTypeUseCase; import ch.unisg.executorpool.domain.ExecutorClass; import ch.unisg.executorpool.domain.ExecutorPool; import lombok.RequiredArgsConstructor; @@ -13,10 +13,10 @@ import java.util.List; @RequiredArgsConstructor @Component @Transactional -public class GetAllExecutorsInExecutorPoolByTypeService implements GetAllExecutorsInExecutorPoolByTypeUseCase { +public class GetAllExecutorInExecutorPoolByTypeService implements GetAllExecutorInExecutorPoolByTypeUseCase { @Override - public List getAllExecutorsInExecutorPoolByType(GetAllExecutorsInExecutorPoolByTypeQuery query){ + public List getAllExecutorInExecutorPoolByType(GetAllExecutorInExecutorPoolByTypeQuery query){ ExecutorPool executorPool = ExecutorPool.getExecutorPool(); return executorPool.getAllExecutorsByType(query.getExecutorTaskType()); } diff --git a/executor-pool/src/main/java/ch/unisg/executorpool/application/service/RemoveExecutorFromExecutorPoolService.java b/executor-pool/src/main/java/ch/unisg/executorpool/application/service/RemoveExecutorFromExecutorPoolService.java index a606f57..639ba7f 100644 --- a/executor-pool/src/main/java/ch/unisg/executorpool/application/service/RemoveExecutorFromExecutorPoolService.java +++ b/executor-pool/src/main/java/ch/unisg/executorpool/application/service/RemoveExecutorFromExecutorPoolService.java @@ -17,6 +17,6 @@ public class RemoveExecutorFromExecutorPoolService implements RemoveExecutorFrom @Override public Optional removeExecutorFromExecutorPool(RemoveExecutorFromExecutorPoolCommand command){ ExecutorPool executorPool = ExecutorPool.getExecutorPool(); - return executorPool.removeExecutorByIpAndPort(command.getExecutorUri()); + return executorPool.removeExecutorByIpAndPort(command.getExecutorIp(), command.getExecutorPort()); } } diff --git a/executor-pool/src/main/java/ch/unisg/executorpool/domain/ExecutorClass.java b/executor-pool/src/main/java/ch/unisg/executorpool/domain/ExecutorClass.java index 5da6fe7..d1fca00 100644 --- a/executor-pool/src/main/java/ch/unisg/executorpool/domain/ExecutorClass.java +++ b/executor-pool/src/main/java/ch/unisg/executorpool/domain/ExecutorClass.java @@ -3,29 +3,36 @@ package ch.unisg.executorpool.domain; import lombok.Getter; import lombok.Value; -import java.net.URI; - public class ExecutorClass { @Getter - private final ExecutorUri executorUri; + private final ExecutorIp executorIp; + + @Getter + private final ExecutorPort executorPort; @Getter private final ExecutorTaskType executorTaskType; - public ExecutorClass(ExecutorUri executorUri, ExecutorTaskType executorTaskType){ - this.executorUri = executorUri; + public ExecutorClass(ExecutorIp executorIp, ExecutorPort executorPort, ExecutorTaskType executorTaskType){ + this.executorIp = executorIp; + this.executorPort = executorPort; this.executorTaskType = executorTaskType; } - protected static ExecutorClass createExecutorClass(ExecutorUri executorUri, ExecutorTaskType executorTaskType){ - System.out.println("New Executor: " + executorUri.value.toString() + " " + executorTaskType.getValue()); - return new ExecutorClass(executorUri, executorTaskType); + protected static ExecutorClass createExecutorClass(ExecutorIp executorIp, ExecutorPort executorPort, ExecutorTaskType executorTaskType){ + System.out.println("New Task: " + executorIp.getValue() + " " + executorPort.getValue() + " " + executorTaskType.getValue()); + return new ExecutorClass(executorIp, executorPort, executorTaskType); } @Value - public static class ExecutorUri { - private URI value; + public static class ExecutorIp { + private String value; + } + + @Value + public static class ExecutorPort { + private String value; } @Value diff --git a/executor-pool/src/main/java/ch/unisg/executorpool/domain/ExecutorPool.java b/executor-pool/src/main/java/ch/unisg/executorpool/domain/ExecutorPool.java index 0ca0d5e..dd5375b 100644 --- a/executor-pool/src/main/java/ch/unisg/executorpool/domain/ExecutorPool.java +++ b/executor-pool/src/main/java/ch/unisg/executorpool/domain/ExecutorPool.java @@ -1,8 +1,5 @@ package ch.unisg.executorpool.domain; -import ch.unisg.executorpool.domain.ExecutorClass.ExecutorUri; -import ch.unisg.executorpool.domain.ExecutorClass.ExecutorTaskType; - import lombok.Getter; import lombok.Value; @@ -23,17 +20,19 @@ public class ExecutorPool { public static ExecutorPool getExecutorPool() { return executorPool; } - public ExecutorClass addNewExecutor(ExecutorUri executorUri, ExecutorTaskType executorTaskType){ - ExecutorClass newExecutor = ExecutorClass.createExecutorClass(executorUri, executorTaskType); + public ExecutorClass addNewExecutor(ExecutorClass.ExecutorIp executorIp, ExecutorClass.ExecutorPort executorPort, ExecutorClass.ExecutorTaskType executorTaskType){ + ExecutorClass newExecutor = ExecutorClass.createExecutorClass(executorIp, executorPort, executorTaskType); listOfExecutors.value.add(newExecutor); System.out.println("Number of executors: " + listOfExecutors.value.size()); return newExecutor; } - public Optional getExecutorByUri(ExecutorUri executorUri){ + public Optional getExecutorByIpAndPort(ExecutorClass.ExecutorIp executorIp, ExecutorClass.ExecutorPort executorPort){ for (ExecutorClass executor : listOfExecutors.value ) { - if(executor.getExecutorUri().getValue().equals(executorUri)){ + // TODO can this be simplified by overwriting equals()? + if(executor.getExecutorIp().getValue().equalsIgnoreCase(executorIp.getValue()) && + executor.getExecutorPort().getValue().equalsIgnoreCase(executorPort.getValue())){ return Optional.of(executor); } } @@ -55,10 +54,11 @@ public class ExecutorPool { return matchedExecutors; } - public Optional removeExecutorByIpAndPort(ExecutorUri executorUri){ + public Optional removeExecutorByIpAndPort(ExecutorClass.ExecutorIp executorIp, ExecutorClass.ExecutorPort executorPort){ for (ExecutorClass executor : listOfExecutors.value ) { // TODO can this be simplified by overwriting equals()? - if(executor.getExecutorUri().getValue().equals(executorUri.getValue())){ + if(executor.getExecutorIp().getValue().equalsIgnoreCase(executorIp.getValue()) && + executor.getExecutorPort().getValue().equalsIgnoreCase(executorPort.getValue())){ listOfExecutors.value.remove(executor); return Optional.of(executor); } diff --git a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/adapter/common/formats/AuctionJsonRepresentation.java b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/adapter/common/formats/AuctionJsonRepresentation.java index 4500423..ea4cf2c 100644 --- a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/adapter/common/formats/AuctionJsonRepresentation.java +++ b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/adapter/common/formats/AuctionJsonRepresentation.java @@ -7,6 +7,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.Getter; import lombok.Setter; +import java.sql.Timestamp; + /** * Used to expose a representation of the state of an auction through an interface. This class is * only meant as a starting point when defining a uniform HTTP API for the Auction House: feel free @@ -28,12 +30,12 @@ public class AuctionJsonRepresentation { private String taskType; @Getter @Setter - private Integer deadline; + private Timestamp deadline; public AuctionJsonRepresentation() { } public AuctionJsonRepresentation(String auctionId, String auctionHouseUri, String taskUri, - String taskType, Integer deadline) { + String taskType, Timestamp deadline) { this.auctionId = auctionId; this.auctionHouseUri = auctionHouseUri; this.taskUri = taskUri; diff --git a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/application/service/StartAuctionService.java b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/application/service/StartAuctionService.java index 42c6e37..60c5f24 100644 --- a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/application/service/StartAuctionService.java +++ b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/application/service/StartAuctionService.java @@ -2,6 +2,7 @@ package ch.unisg.tapas.auctionhouse.application.service; import ch.unisg.tapas.auctionhouse.application.port.in.LaunchAuctionCommand; import ch.unisg.tapas.auctionhouse.application.port.in.LaunchAuctionUseCase; +import ch.unisg.tapas.auctionhouse.application.port.in.LaunchAuctionUseCase; import ch.unisg.tapas.auctionhouse.application.port.out.AuctionWonEventPort; import ch.unisg.tapas.auctionhouse.application.port.out.AuctionStartedEventPort; import ch.unisg.tapas.auctionhouse.domain.*; @@ -11,6 +12,7 @@ import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.sql.Timestamp; import java.util.Optional; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -25,7 +27,7 @@ import java.util.concurrent.TimeUnit; public class StartAuctionService implements LaunchAuctionUseCase { private static final Logger LOGGER = LogManager.getLogger(StartAuctionService.class); - private final static int DEFAULT_AUCTION_DEADLINE_MILLIS = 10000; + private final Timestamp DEFAULT_AUCTION_DEADLINE_MILLIS = Timestamp.valueOf("1970-01-01 00:00:01"); // Event port used to publish an auction started event private final AuctionStartedEventPort auctionStartedEventPort; @@ -63,7 +65,7 @@ public class StartAuctionService implements LaunchAuctionUseCase { auctions.addAuction(auction); // Schedule the closing of the auction at the deadline - service.schedule(new CloseAuctionTask(auction.getAuctionId()), deadline.getValue(), + service.schedule(new CloseAuctionTask(auction.getAuctionId()), deadline.getValue().getTime() - System.currentTimeMillis(), TimeUnit.MILLISECONDS); // Publish an auction started event diff --git a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/domain/Auction.java b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/domain/Auction.java index 3e51ef7..c6d9333 100644 --- a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/domain/Auction.java +++ b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/domain/Auction.java @@ -4,6 +4,7 @@ import lombok.Getter; import lombok.Value; import java.net.URI; +import java.sql.Timestamp; import java.util.*; /** @@ -166,6 +167,6 @@ public class Auction { @Value public static class AuctionDeadline { - int value; + Timestamp value; } } diff --git a/tapas-tasks/src/main/java/ch/unisg/tapastasks/tasks/application/service/DeleteTaskService.java b/tapas-tasks/src/main/java/ch/unisg/tapastasks/tasks/application/service/DeleteTaskService.java index 35685a3..f865f4c 100644 --- a/tapas-tasks/src/main/java/ch/unisg/tapastasks/tasks/application/service/DeleteTaskService.java +++ b/tapas-tasks/src/main/java/ch/unisg/tapastasks/tasks/application/service/DeleteTaskService.java @@ -5,7 +5,6 @@ import ch.unisg.tapastasks.tasks.application.port.in.DeleteTaskCommand; import ch.unisg.tapastasks.tasks.application.port.in.DeleteTaskUseCase; import ch.unisg.tapastasks.tasks.domain.Task; import ch.unisg.tapastasks.tasks.domain.TaskList; -import jdk.jshell.spi.ExecutionControl; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -24,10 +23,11 @@ public class DeleteTaskService implements DeleteTaskUseCase { Optional updatedTask = taskList.retrieveTaskById(command.getTaskId()); Task newTask = updatedTask.get(); // TODO: Fill in the right condition into the if-statement and the else-statement - if (true){ + if (/*the task can be deleted*/){ return taskList.deleteTaskById(command.getTaskId()); + } else { + /*send message back to TaskList that the task cannot be deleted*/ } - // TODO Handle with a return message - return Optional.empty(); + } }