From de80724b756e8f3e617755e838189948b8d835cc Mon Sep 17 00:00:00 2001 From: Jon Marius Venstad Date: Mon, 26 Apr 2021 16:41:58 +0200 Subject: Revert "Merge pull request #17603 from vespa-engine/jonmv/revert-apache-config-server-client" This reverts commit 9458ad2d810ff988ccc19cd8554bdbc78dabe588, reversing changes made to 6e94e192a07a540bff9b3e13ad05c8d0af093928. --- .../configserver/ConfigServerException.java | 53 ++++++++++++---------- .../api/integration/configserver/LoadBalancer.java | 6 +-- 2 files changed, 32 insertions(+), 27 deletions(-) (limited to 'controller-api') diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServerException.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServerException.java index 4240b0d9fa6..5e4d3345b7a 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServerException.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServerException.java @@ -1,38 +1,32 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.api.integration.configserver; -import java.net.URI; -import java.util.Objects; +import com.yahoo.slime.Inspector; +import com.yahoo.slime.SlimeUtils; +import org.apache.hc.core5.http.ClassicHttpRequest; + +import java.util.stream.Stream; /** - * @author Tony Vaagenes + * An exception due to server error, a bad request, or similar. + * + * @author jonmv */ public class ConfigServerException extends RuntimeException { - private final URI serverUri; - private final ErrorCode errorCode; - private final String serverMessage; + private final ErrorCode code; + private final String message; - public ConfigServerException(URI serverUri, String context, String serverMessage, ErrorCode errorCode, Throwable cause) { - super(context + ": " + serverMessage, cause); - this.serverUri = Objects.requireNonNull(serverUri); - this.errorCode = Objects.requireNonNull(errorCode); - this.serverMessage = Objects.requireNonNull(serverMessage); + public ConfigServerException(ErrorCode code, String message, String context) { + super(context + ": " + message); + this.code = code; + this.message = message; } - public ErrorCode getErrorCode() { - return errorCode; - } + public ErrorCode code() { return code; } - public URI getServerUri() { - return serverUri; - } + public String message() { return message; } - public String getServerMessage() { - return serverMessage; - } - - // TODO: Copied from Vespa. Expose these in Vespa and use them here public enum ErrorCode { APPLICATION_LOCK_FAILURE, BAD_REQUEST, @@ -46,7 +40,18 @@ public class ConfigServerException extends RuntimeException { UNKNOWN_VESPA_VERSION, PARENT_HOST_NOT_READY, CERTIFICATE_NOT_READY, - LOAD_BALANCER_NOT_READY + LOAD_BALANCER_NOT_READY, + INCOMPLETE_RESPONSE + } + + public static ConfigServerException readException(int statusCode, byte[] body, ClassicHttpRequest request) { + Inspector root = SlimeUtils.jsonToSlime(body).get(); + String codeName = root.field("error-code").asString(); + ErrorCode code = Stream.of(ErrorCode.values()) + .filter(value -> value.name().equals(codeName)) + .findAny().orElse(ErrorCode.INCOMPLETE_RESPONSE); + String message = root.field("message").valid() ? root.field("message").asString() : "(no message)"; + return new ConfigServerException(code, message, request + " failed with status " + statusCode); } } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/LoadBalancer.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/LoadBalancer.java index 05bdf3c3412..d2f19f4df9f 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/LoadBalancer.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/LoadBalancer.java @@ -18,11 +18,11 @@ public class LoadBalancer { private final String id; private final ApplicationId application; private final ClusterSpec.Id cluster; - private final HostName hostname; + private final Optional hostname; private final State state; private final Optional dnsZone; - public LoadBalancer(String id, ApplicationId application, ClusterSpec.Id cluster, HostName hostname, State state, + public LoadBalancer(String id, ApplicationId application, ClusterSpec.Id cluster, Optional hostname, State state, Optional dnsZone) { this.id = Objects.requireNonNull(id, "id must be non-null"); this.application = Objects.requireNonNull(application, "application must be non-null"); @@ -44,7 +44,7 @@ public class LoadBalancer { return cluster; } - public HostName hostname() { + public Optional hostname() { return hostname; } -- cgit v1.2.3 From 29234349cc188aa8f7fc948b3208d83a87f461e3 Mon Sep 17 00:00:00 2001 From: Jon Marius Venstad Date: Mon, 26 Apr 2021 16:54:12 +0200 Subject: Avoid leaking apache classes --- .../api/integration/configserver/ConfigServerException.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'controller-api') diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServerException.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServerException.java index 5e4d3345b7a..d651eda7139 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServerException.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServerException.java @@ -44,14 +44,14 @@ public class ConfigServerException extends RuntimeException { INCOMPLETE_RESPONSE } - public static ConfigServerException readException(int statusCode, byte[] body, ClassicHttpRequest request) { + public static ConfigServerException readException(byte[] body, String context) { Inspector root = SlimeUtils.jsonToSlime(body).get(); String codeName = root.field("error-code").asString(); ErrorCode code = Stream.of(ErrorCode.values()) .filter(value -> value.name().equals(codeName)) .findAny().orElse(ErrorCode.INCOMPLETE_RESPONSE); String message = root.field("message").valid() ? root.field("message").asString() : "(no message)"; - return new ConfigServerException(code, message, request + " failed with status " + statusCode); + return new ConfigServerException(code, message, context); } } -- cgit v1.2.3