summaryrefslogtreecommitdiffstats
path: root/clustercontroller-utils
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2023-06-07 08:32:36 +0200
committerHarald Musum <musum@yahooinc.com>2023-06-07 08:32:36 +0200
commit335ade42d91443f700c31bb3448d470a0de43cd2 (patch)
treef049465b449dcfe57fd3f99bf6aa257b2eb31336 /clustercontroller-utils
parent3fff1ac29d976607382dc21dd9d542ef56671d67 (diff)
Modernize
Diffstat (limited to 'clustercontroller-utils')
-rw-r--r--clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/errors/MissingUnitException.java8
-rw-r--r--clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/errors/OperationNotSupportedForUnitException.java7
-rw-r--r--clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/requests/UnitRequest.java4
-rw-r--r--clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/response/SetResponse.java2
-rw-r--r--clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/server/RestApiHandler.java15
-rw-r--r--clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/util/ComponentMetricReporter.java6
-rw-r--r--clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/DummyStateApi.java25
-rw-r--r--clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/StateRestAPITest.java5
8 files changed, 37 insertions, 35 deletions
diff --git a/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/errors/MissingUnitException.java b/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/errors/MissingUnitException.java
index 838e13fc4ee..58a862f4878 100644
--- a/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/errors/MissingUnitException.java
+++ b/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/errors/MissingUnitException.java
@@ -1,19 +1,21 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.utils.staterestapi.errors;
+import java.util.List;
+
public class MissingUnitException extends StateRestApiException {
- private static String createMessage(String[] path, int level) {
+ private static String createMessage(List<String> path, int level) {
StringBuilder sb = new StringBuilder();
sb.append("No such resource '");
for (int i=0; i<=level; ++i) {
if (i != 0) sb.append('/');
- sb.append(path[i]);
+ sb.append(path.get(i));
}
return sb.append("'.").toString();
}
- public MissingUnitException(String[] path, int level) {
+ public MissingUnitException(List<String> path, int level) {
super(createMessage(path, level));
setHtmlCode(404);
setHtmlStatus(getMessage());
diff --git a/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/errors/OperationNotSupportedForUnitException.java b/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/errors/OperationNotSupportedForUnitException.java
index 342f568eacc..abc55d68bc6 100644
--- a/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/errors/OperationNotSupportedForUnitException.java
+++ b/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/errors/OperationNotSupportedForUnitException.java
@@ -2,16 +2,17 @@
package com.yahoo.vespa.clustercontroller.utils.staterestapi.errors;
import java.util.Arrays;
+import java.util.List;
public class OperationNotSupportedForUnitException extends StateRestApiException {
- private static String createMessage(String[] path, String description) {
+ private static String createMessage(List<String> path, String description) {
return new StringBuilder()
- .append(Arrays.toString(path)).append(": ").append(description)
+ .append(Arrays.toString(path.toArray())).append(": ").append(description)
.toString();
}
- public OperationNotSupportedForUnitException(String path[], String description) {
+ public OperationNotSupportedForUnitException(List<String> path, String description) {
super(createMessage(path, description));
setHtmlCode(405);
setHtmlStatus("Operation not supported for resource");
diff --git a/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/requests/UnitRequest.java b/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/requests/UnitRequest.java
index 53abfff8aba..52bef3b09c0 100644
--- a/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/requests/UnitRequest.java
+++ b/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/requests/UnitRequest.java
@@ -1,8 +1,10 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.utils.staterestapi.requests;
+import java.util.List;
+
public interface UnitRequest {
- String[] getUnitPath();
+ List<String> getUnitPath();
}
diff --git a/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/response/SetResponse.java b/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/response/SetResponse.java
index 1c704ea3b63..2287abb5ca7 100644
--- a/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/response/SetResponse.java
+++ b/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/response/SetResponse.java
@@ -24,7 +24,7 @@ public class SetResponse {
public boolean getWasModified() { return wasModified; }
/**
- * Human readable reason.
+ * Human-readable reason.
*
* @return reason as string
*/
diff --git a/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/server/RestApiHandler.java b/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/server/RestApiHandler.java
index 654481aee33..ceec4f67e1b 100644
--- a/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/server/RestApiHandler.java
+++ b/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/server/RestApiHandler.java
@@ -25,7 +25,6 @@ import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -64,7 +63,7 @@ public class RestApiHandler implements HttpRequestHandler {
Instant start = clock.instant();
try{
- final String[] unitPath = createUnitPath(request);
+ List<String> unitPath = createUnitPath(request);
if (request.getHttpOperation().equals(HttpRequest.HttpOp.GET)) {
final int recursiveLevel = getRecursiveLevel(request);
UnitResponse data = restApi.getState(new UnitStateRequest() {
@@ -73,9 +72,7 @@ public class RestApiHandler implements HttpRequestHandler {
return recursiveLevel;
}
@Override
- public String[] getUnitPath() {
- return unitPath;
- }
+ public List<String> getUnitPath() { return unitPath; }
});
return new JsonHttpResult().setJson(jsonWriter.createJson(data));
} else {
@@ -87,7 +84,7 @@ public class RestApiHandler implements HttpRequestHandler {
return setRequestData.stateMap;
}
@Override
- public String[] getUnitPath() {
+ public List<String> getUnitPath() {
return unitPath;
}
@Override
@@ -137,9 +134,9 @@ public class RestApiHandler implements HttpRequestHandler {
}
}
- private String[] createUnitPath(HttpRequest request) {
- List<String> path = Arrays.asList(request.getPath().split("/"));
- return path.subList(3, path.size()).toArray(new String[0]);
+ private List<String> createUnitPath(HttpRequest request) {
+ List<String> path = List.of(request.getPath().split("/"));
+ return path.subList(3, path.size());
}
private int getRecursiveLevel(HttpRequest request) throws StateRestApiException {
diff --git a/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/util/ComponentMetricReporter.java b/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/util/ComponentMetricReporter.java
index bed2ddcecd0..cde44b76fcb 100644
--- a/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/util/ComponentMetricReporter.java
+++ b/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/util/ComponentMetricReporter.java
@@ -1,12 +1,12 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-/**
- * Metric reporter wrapper to add component name prefix and common dimensions.
- */
package com.yahoo.vespa.clustercontroller.utils.util;
import java.util.Map;
import java.util.TreeMap;
+/**
+ * Metric reporter wrapper to add component name prefix and common dimensions.
+ */
public class ComponentMetricReporter implements MetricReporter {
private final MetricReporter impl;
diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/DummyStateApi.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/DummyStateApi.java
index d611b0c0ea8..2fcbf22aa59 100644
--- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/DummyStateApi.java
+++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/DummyStateApi.java
@@ -10,6 +10,7 @@ import com.yahoo.vespa.clustercontroller.utils.staterestapi.requests.UnitStateRe
import com.yahoo.vespa.clustercontroller.utils.staterestapi.response.*;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
public class DummyStateApi implements StateRestAPI {
@@ -28,8 +29,8 @@ public class DummyStateApi implements StateRestAPI {
}
public class SubUnitListImpl implements SubUnitList {
- private Map<String, String> links = new LinkedHashMap<>();
- private Map<String, UnitResponse> values = new LinkedHashMap<>();
+ private final Map<String, String> links = new LinkedHashMap<>();
+ private final Map<String, UnitResponse> values = new LinkedHashMap<>();
@Override
public Map<String, String> getSubUnitLinks() { return links; }
@@ -156,18 +157,18 @@ public class DummyStateApi implements StateRestAPI {
@Override
public UnitResponse getState(UnitStateRequest request) throws StateRestApiException {
checkForInducedException();
- String[] path = request.getUnitPath();
- if (path.length == 0) {
+ List<String> path = request.getUnitPath();
+ if (path.size() == 0) {
return getClusterList(request.getRecursiveLevels());
}
- final DummyBackend.Cluster c = backend.getClusters().get(path[0]);
+ DummyBackend.Cluster c = backend.getClusters().get(path.get(0));
if (c == null) throw new MissingUnitException(path, 0);
- if (path.length == 1) {
+ if (path.size() == 1) {
return getClusterState(c, request.getRecursiveLevels());
}
- final DummyBackend.Node n = c.nodes.get(path[1]);
+ DummyBackend.Node n = c.nodes.get(path.get(1));
if (n == null) throw new MissingUnitException(path, 1);
- if (path.length == 2) {
+ if (path.size() == 2) {
return getNodeState(n);
}
throw new MissingUnitException(path, 3);
@@ -176,15 +177,15 @@ public class DummyStateApi implements StateRestAPI {
@Override
public SetResponse setUnitState(SetUnitStateRequest request) throws StateRestApiException {
checkForInducedException();
- String[] path = request.getUnitPath();
- if (path.length != 2) {
+ List<String> path = request.getUnitPath();
+ if (path.size() != 2) {
throw new OperationNotSupportedForUnitException(
path, "You can only set states on nodes");
}
DummyBackend.Node n = null;
- DummyBackend.Cluster c = backend.getClusters().get(path[0]);
+ DummyBackend.Cluster c = backend.getClusters().get(path.get(0));
if (c != null) {
- n = c.nodes.get(path[1]);
+ n = c.nodes.get(path.get(1));
}
if (n == null) throw new MissingUnitException(path, 2);
Map<String, UnitState> newState = request.getNewState();
diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/StateRestAPITest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/StateRestAPITest.java
index 47b12f883ff..29e33b7906a 100644
--- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/StateRestAPITest.java
+++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/StateRestAPITest.java
@@ -19,6 +19,7 @@ import com.yahoo.vespa.clustercontroller.utils.staterestapi.server.RestApiHandle
import com.yahoo.vespa.clustercontroller.utils.test.TestTransport;
import org.junit.jupiter.api.Test;
+import java.util.List;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -486,9 +487,7 @@ public class StateRestAPITest {
assertEquals(expected, result.getContent().toString());
}
{
- String path[] = new String[1];
- path[0] = "foo";
- stateApi.induceException(new OperationNotSupportedForUnitException(path, "Foo"));
+ stateApi.induceException(new OperationNotSupportedForUnitException(List.of("foo"), "Foo"));
HttpResult result = execute(new HttpRequest().setPath("/cluster/v2"));
assertEquals(405, result.getHttpReturnCode(), result.toString(true));
assertEquals("Operation not supported for resource", result.getHttpReturnCodeDescription(), result.toString(true));