diff options
author | Harald Musum <musum@yahooinc.com> | 2023-06-07 08:32:36 +0200 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2023-06-07 08:32:36 +0200 |
commit | 335ade42d91443f700c31bb3448d470a0de43cd2 (patch) | |
tree | f049465b449dcfe57fd3f99bf6aa257b2eb31336 /clustercontroller-core | |
parent | 3fff1ac29d976607382dc21dd9d542ef56671d67 (diff) |
Modernize
Diffstat (limited to 'clustercontroller-core')
3 files changed, 23 insertions, 23 deletions
diff --git a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/restapiv2/MissingIdException.java b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/restapiv2/MissingIdException.java index 21229b4b358..18a3b923908 100644 --- a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/restapiv2/MissingIdException.java +++ b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/restapiv2/MissingIdException.java @@ -4,14 +4,12 @@ package com.yahoo.vespa.clustercontroller.core.restapiv2; import com.yahoo.vdslib.state.Node; import com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.MissingUnitException; +import java.util.List; + public class MissingIdException extends MissingUnitException { - private static String[] createPath(String cluster, Node n) { - String[] path = new String[3]; - path[0] = cluster; - path[1] = n.getType().toString(); - path[2] = String.valueOf(n.getIndex()); - return path; + private static List<String> createPath(String cluster, Node n) { + return List.of(cluster, n.getType().toString(), String.valueOf(n.getIndex())); } public MissingIdException(String cluster, Node n) { diff --git a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/restapiv2/UnitPathResolver.java b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/restapiv2/UnitPathResolver.java index 11fd5f39fad..0db11cad955 100644 --- a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/restapiv2/UnitPathResolver.java +++ b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/restapiv2/UnitPathResolver.java @@ -7,6 +7,7 @@ import com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.MissingUnitEx import com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.OperationNotSupportedForUnitException; import com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.StateRestApiException; import java.util.HashMap; +import java.util.List; import java.util.Map; public class UnitPathResolver<T> { @@ -22,10 +23,10 @@ public class UnitPathResolver<T> { public static abstract class AbstractVisitor<T> implements Visitor<T> { - private final String[] path; + private final List<String> path; private final String failureMessage; - public AbstractVisitor(String[] path, String failureMessage) { + public AbstractVisitor(List<String> path, String failureMessage) { this.path = path; this.failureMessage = failureMessage; } @@ -46,41 +47,41 @@ public class UnitPathResolver<T> { this.fleetControllers = new HashMap<>(fleetControllers); } - public RemoteClusterControllerTaskScheduler resolveFleetController(String[] path) throws StateRestApiException { - if (path.length == 0) return null; - RemoteClusterControllerTaskScheduler fc = fleetControllers.get(path[0]); + public RemoteClusterControllerTaskScheduler resolveFleetController(List<String> path) throws StateRestApiException { + if (path.size() == 0) return null; + RemoteClusterControllerTaskScheduler fc = fleetControllers.get(path.get(0)); if (fc == null) { throw new MissingUnitException(path, 0); } return fc; } - public Request<? extends T> visit(String[] path, Visitor<T> visitor) throws StateRestApiException { - if (path.length == 0) { + public Request<? extends T> visit(List<String> path, Visitor<T> visitor) throws StateRestApiException { + if (path.size() == 0) { return visitor.visitGlobal(); } - RemoteClusterControllerTaskScheduler fc = fleetControllers.get(path[0]); + RemoteClusterControllerTaskScheduler fc = fleetControllers.get(path.get(0)); if (fc == null) throw new MissingUnitException(path, 0); - Id.Cluster cluster = new Id.Cluster(path[0]); - if (path.length == 1) { + Id.Cluster cluster = new Id.Cluster(path.get(0)); + if (path.size() == 1) { return visitor.visitCluster(cluster); } Id.Service service; try{ - service = new Id.Service(cluster, NodeType.get(path[1])); + service = new Id.Service(cluster, NodeType.get(path.get(1))); } catch (IllegalArgumentException e) { throw new MissingUnitException(path, 1); } - if (path.length == 2) { + if (path.size() == 2) { return visitor.visitService(service); } Id.Node node; try{ - node = new Id.Node(service, Integer.valueOf(path[2])); + node = new Id.Node(service, Integer.parseInt(path.get(2))); } catch (NumberFormatException e) { throw new MissingUnitException(path, 2); } - if (path.length == 3) { + if (path.size() == 3) { return visitor.visitNode(node); } throw new MissingUnitException(path, 4); diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/StateRestApiTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/StateRestApiTest.java index 205d5b05b29..bec12ccb195 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/StateRestApiTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/StateRestApiTest.java @@ -22,6 +22,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; @@ -36,18 +37,18 @@ public abstract class StateRestApiTest { Map<Integer, ClusterControllerStateRestAPI.Socket> ccSockets; public static class StateRequest implements UnitStateRequest { - private final String[] path; + private final List<String> path; private final int recursive; StateRequest(String req, int recursive) { - path = req.isEmpty() ? new String[0] : req.split("/"); + path = req.isEmpty() ? List.of() : List.of(req.split("/")); this.recursive = recursive; } @Override public int getRecursiveLevels() { return recursive; } @Override - public String[] getUnitPath() { return path; } + public List<String> getUnitPath() { return path; } } protected void setUp(boolean dontInitializeNode2) { |