diff options
4 files changed, 33 insertions, 51 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/application/v4/model/EndpointStatus.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/application/v4/model/EndpointStatus.java index 2f1b93158ab..4b326bc7430 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/application/v4/model/EndpointStatus.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/application/v4/model/EndpointStatus.java @@ -1,59 +1,45 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.api.application.v4.model; +import java.time.Instant; +import java.util.Objects; + /** - * Represent the operational status of a service endpoint (where the endpoint itself - * is identified by the container cluster id). - * - * The status of an endpoint may be assigned from the controller. + * Represent the routing status for all endpoints of a deployment. * * @author smorgrav */ public class EndpointStatus { + private final String agent; - private final String reason; private final Status status; - private final long epoch; + private final Instant changedAt; - public enum Status { - in, - out, - unknown; + public EndpointStatus(Status status, String agent, Instant changedAt) { + this.status = Objects.requireNonNull(status); + this.agent = Objects.requireNonNull(agent); + this.changedAt = Objects.requireNonNull(changedAt); } - public EndpointStatus(Status status, String reason, String agent, long epoch) { - this.status = status; - this.reason = reason; - this.agent = agent; - this.epoch = epoch; - } - - /** - * @return The agent responsible setting this status - */ - public String getAgent() { + /** Returns the agent responsible setting this status */ + public String agent() { return agent; } - /** - * @return The reason for this status (e.g. 'incident INCXXX') - */ - public String getReason() { - return reason; + /** Returns the current status */ + public Status status() { + return status; } - /** - * @return The current status - */ - public Status getStatus() { - return status; + /** Returns when this was last changed */ + public Instant changedAt() { + return changedAt; } - /** - * @return The epoch for when this status became active, in seconds - */ - public long getEpoch() { - return epoch; + public enum Status { + in, + out, + unknown; } } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/context/DeploymentRoutingContext.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/context/DeploymentRoutingContext.java index b61548c7e84..e784666f22a 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/context/DeploymentRoutingContext.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/context/DeploymentRoutingContext.java @@ -16,7 +16,6 @@ import com.yahoo.vespa.hosted.controller.routing.RoutingPolicyId; import com.yahoo.vespa.hosted.controller.routing.RoutingStatus; import java.time.Clock; -import java.time.Instant; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -90,9 +89,8 @@ public abstract class DeploymentRoutingContext implements RoutingContext { EndpointStatus newStatus = new EndpointStatus(value == RoutingStatus.Value.in ? EndpointStatus.Status.in : EndpointStatus.Status.out, - "", agent.name(), - clock.instant().getEpochSecond()); + clock.instant()); try { configServer.setGlobalRotationStatus(deployment, upstreamNames(), newStatus); } catch (Exception e) { @@ -112,15 +110,15 @@ public abstract class DeploymentRoutingContext implements RoutingContext { EndpointStatus status = configServer.getGlobalRotationStatus(deployment, upstreamName); RoutingStatus.Agent agent; try { - agent = RoutingStatus.Agent.valueOf(status.getAgent().toLowerCase()); + agent = RoutingStatus.Agent.valueOf(status.agent().toLowerCase()); } catch (IllegalArgumentException e) { agent = RoutingStatus.Agent.unknown; } - return new RoutingStatus(status.getStatus() == EndpointStatus.Status.in + return new RoutingStatus(status.status() == EndpointStatus.Status.in ? RoutingStatus.Value.in : RoutingStatus.Value.out, agent, - Instant.ofEpochSecond(status.getEpoch())); + status.changedAt()); } private List<String> upstreamNames() { @@ -138,9 +136,8 @@ public abstract class DeploymentRoutingContext implements RoutingContext { EndpointStatus newStatus = new EndpointStatus(value == RoutingStatus.Value.in ? EndpointStatus.Status.in : EndpointStatus.Status.out, - "", agent.name(), - clock.instant().getEpochSecond()); + clock.instant()); primaryEndpoint().ifPresent(endpoint -> { try { configServer.setGlobalRotationStatus(deployment, List.of(endpoint.upstreamName(deployment)), newStatus); @@ -158,15 +155,15 @@ public abstract class DeploymentRoutingContext implements RoutingContext { if (status.isEmpty()) return RoutingStatus.DEFAULT; RoutingStatus.Agent agent; try { - agent = RoutingStatus.Agent.valueOf(status.get().getAgent().toLowerCase()); + agent = RoutingStatus.Agent.valueOf(status.get().agent().toLowerCase()); } catch (IllegalArgumentException e) { agent = RoutingStatus.Agent.unknown; } - return new RoutingStatus(status.get().getStatus() == EndpointStatus.Status.in + return new RoutingStatus(status.get().status() == EndpointStatus.Status.in ? RoutingStatus.Value.in : RoutingStatus.Value.out, agent, - Instant.ofEpochSecond(status.get().getEpoch())); + status.get().changedAt()); } private Optional<Endpoint> primaryEndpoint() { diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ConfigServerMock.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ConfigServerMock.java index 8163618fc1e..aa53d09be04 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ConfigServerMock.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ConfigServerMock.java @@ -551,8 +551,8 @@ public class ConfigServerMock extends AbstractComponent implements ConfigServer @Override public EndpointStatus getGlobalRotationStatus(DeploymentId deployment, String upstreamName) { - EndpointStatus result = new EndpointStatus(EndpointStatus.Status.in, "", "", 1497618757L); - return endpoints.getOrDefault(deployment, result); + EndpointStatus status = new EndpointStatus(EndpointStatus.Status.in, "", Instant.ofEpochSecond(1497618757L)); + return endpoints.getOrDefault(deployment, status); } @Override diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java index 6e8445102c3..6cf3e89bdfe 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java @@ -52,7 +52,6 @@ import com.yahoo.vespa.hosted.controller.api.integration.resource.MeteringData; import com.yahoo.vespa.hosted.controller.api.integration.resource.ResourceAllocation; import com.yahoo.vespa.hosted.controller.api.integration.resource.ResourceSnapshot; import com.yahoo.vespa.hosted.controller.api.integration.stubs.MockMeteringClient; -import com.yahoo.vespa.hosted.controller.application.Change; import com.yahoo.vespa.hosted.controller.application.Deployment; import com.yahoo.vespa.hosted.controller.application.DeploymentMetrics; import com.yahoo.vespa.hosted.controller.application.TenantAndApplicationId; @@ -1877,7 +1876,7 @@ public class ApplicationApiTest extends ControllerContainerTest { RoutingStatus status = context.routingStatus(); assertEquals(value, status.value()); assertEquals(agent, status.agent()); - assertEquals(changedAt.truncatedTo(ChronoUnit.SECONDS), status.changedAt()); + assertEquals(changedAt, status.changedAt()); } private static class RequestBuilder implements Supplier<Request> { |