From 5606de7c26befb6a25fbd46d4ece686c4a2642f2 Mon Sep 17 00:00:00 2001 From: Marcel Date: Thu, 4 Nov 2021 17:23:49 +0100 Subject: [PATCH] Change type of ExecutorURI value to URI --- .../unisg/common/valueobject/ExecutorURI.java | 18 ++++-------------- .../executor/domain/ExecutorBase.java | 8 +------- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/common/src/main/java/ch/unisg/common/valueobject/ExecutorURI.java b/common/src/main/java/ch/unisg/common/valueobject/ExecutorURI.java index a68a7e0..627104e 100644 --- a/common/src/main/java/ch/unisg/common/valueobject/ExecutorURI.java +++ b/common/src/main/java/ch/unisg/common/valueobject/ExecutorURI.java @@ -1,23 +1,13 @@ package ch.unisg.common.valueobject; -import ch.unisg.common.exception.InvalidExecutorURIException; +import java.net.URI; import lombok.Value; @Value public class ExecutorURI { - private String value; + private URI value; - public ExecutorURI(String uri) throws InvalidExecutorURIException { - String ip = uri.split(":")[0]; - int port = Integer.parseInt(uri.split(":")[1]); - // Check if valid ip4 - if (!ip.equalsIgnoreCase("localhost") && - !uri.matches("^((25[0-5]|(2[0-4]|1\\d|[1-9]|)\\d)(\\.(?!$)|$)){4}$")) { - throw new InvalidExecutorURIException(); - // Check if valid port - } else if (port < 1024 || port > 65535) { - throw new InvalidExecutorURIException(); - } - this.value = uri; + public ExecutorURI(String uri) { + this.value = URI.create(uri); } } diff --git a/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorBase.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorBase.java index f0c5fa9..dddb89d 100644 --- a/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorBase.java +++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorBase.java @@ -2,7 +2,6 @@ package ch.unisg.executorbase.executor.domain; import java.util.logging.Logger; -import ch.unisg.common.exception.InvalidExecutorURIException; import ch.unisg.common.valueobject.ExecutorURI; import ch.unisg.executorbase.executor.adapter.out.web.ExecutionFinishedEventAdapter; import ch.unisg.executorbase.executor.adapter.out.web.GetAssignmentAdapter; @@ -39,12 +38,7 @@ public abstract class ExecutorBase { this.status = ExecutorStatus.STARTING_UP; this.executorType = executorType; // TODO set this automaticly - try { - this.executorURI = new ExecutorURI("localhost:8084"); - } catch (InvalidExecutorURIException e) { - // Shutdown system if the executorURI is not valid - System.exit(1); - } + this.executorURI = new ExecutorURI("localhost:8084"); // 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)) {