summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2020-01-16 11:15:03 +0100
committerMartin Polden <mpolden@mpolden.no>2020-01-20 13:19:08 +0100
commit94af145a942bd38b4e8029b8f508822b5cf8bd84 (patch)
treef700a65c131bff340283d48ca4fa5fb241464bef
parentff5cb1626ae172aba997b9af67f5765d195b805c (diff)
Extract Status
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/RoutingPolicySerializer.java6
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java4
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicies.java2
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicy.java14
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/Status.java40
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java5
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/RoutingPolicySerializerTest.java7
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java5
8 files changed, 63 insertions, 20 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/RoutingPolicySerializer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/RoutingPolicySerializer.java
index 0e9b91b6ba5..c5f249cd7b9 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/RoutingPolicySerializer.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/RoutingPolicySerializer.java
@@ -10,12 +10,12 @@ import com.yahoo.slime.Slime;
import com.yahoo.vespa.hosted.controller.application.EndpointId;
import com.yahoo.vespa.hosted.controller.routing.RoutingPolicy;
import com.yahoo.vespa.hosted.controller.routing.RoutingPolicyId;
+import com.yahoo.vespa.hosted.controller.routing.Status;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
-import java.util.Set;
/**
* Serializer and deserializer for a {@link RoutingPolicy}.
@@ -54,7 +54,7 @@ public class RoutingPolicySerializer {
policy.endpoints().forEach(endpointId -> {
rotationArray.addString(endpointId.id());
});
- policyObject.setBool(loadBalancerActiveField, policy.loadBalancerActive());
+ policyObject.setBool(loadBalancerActiveField, policy.status().loadBalancerActive());
});
return slime;
}
@@ -73,7 +73,7 @@ public class RoutingPolicySerializer {
HostName.from(inspect.field(canonicalNameField).asString()),
Serializers.optionalString(inspect.field(dnsZoneField)),
endpointIds,
- inspect.field(loadBalancerActiveField).asBool()));
+ new Status(inspect.field(loadBalancerActiveField).asBool())));
});
return Collections.unmodifiableMap(policies);
}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java
index f2cc9844820..5ee7295b98b 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java
@@ -924,7 +924,7 @@ public class ApplicationApiHandler extends LoggingRequestHandler {
// Per-cluster rotations
var routingPolicies = controller.applications().routingPolicies().get(instance.id()).values();
for (var policy : routingPolicies) {
- if (!policy.loadBalancerActive()) continue;
+ if (!policy.status().loadBalancerActive()) continue;
policy.globalEndpointsIn(controller.system()).asList().stream()
.map(Endpoint::url)
.map(URI::toString)
@@ -1037,7 +1037,7 @@ public class ApplicationApiHandler extends LoggingRequestHandler {
// Add endpoint(s) defined by routing policies
var endpointArray = response.setArray("endpoints");
for (var policy : controller.applications().routingPolicies().get(deploymentId).values()) {
- if (!policy.loadBalancerActive()) continue;
+ if (!policy.status().loadBalancerActive()) continue;
Cursor endpointObject = endpointArray.addObject();
Endpoint endpoint = policy.endpointIn(controller.system());
endpointObject.setString("cluster", policy.id().cluster().value());
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicies.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicies.java
index 2b32321bc66..1ab657773f6 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicies.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicies.java
@@ -118,7 +118,7 @@ public class RoutingPolicies {
Set<EndpointId> endpointIds) {
var routingPolicy = new RoutingPolicy(new RoutingPolicyId(application, loadBalancer.cluster(), zone),
loadBalancer.hostname(),
- loadBalancer.dnsZone(), endpointIds, isActive(loadBalancer));
+ loadBalancer.dnsZone(), endpointIds, new Status(isActive(loadBalancer)));
var name = RecordName.from(routingPolicy.endpointIn(controller.system()).dnsName());
var data = RecordData.fqdn(loadBalancer.hostname().value());
controller.nameServiceForwarder().createCname(name, data, Priority.normal);
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicy.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicy.java
index 49be82e15d8..8c9f7336668 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicy.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicy.java
@@ -26,16 +26,16 @@ public class RoutingPolicy {
private final HostName canonicalName;
private final Optional<String> dnsZone;
private final Set<EndpointId> endpoints;
- private final boolean loadBalancerActive;
+ private final Status status;
/** DO NOT USE. Public for serialization purposes */
- public RoutingPolicy(RoutingPolicyId id, HostName canonicalName,
- Optional<String> dnsZone, Set<EndpointId> endpoints, boolean loadBalancerActive) {
+ public RoutingPolicy(RoutingPolicyId id, HostName canonicalName, Optional<String> dnsZone, Set<EndpointId> endpoints,
+ Status status) {
this.id = Objects.requireNonNull(id, "id must be non-null");
this.canonicalName = Objects.requireNonNull(canonicalName, "canonicalName must be non-null");
this.dnsZone = Objects.requireNonNull(dnsZone, "dnsZone must be non-null");
this.endpoints = ImmutableSortedSet.copyOf(Objects.requireNonNull(endpoints, "endpoints must be non-null"));
- this.loadBalancerActive = loadBalancerActive;
+ this.status = Objects.requireNonNull(status, "status must be non-null");
}
/** The ID of this */
@@ -58,9 +58,9 @@ public class RoutingPolicy {
return endpoints;
}
- /** Returns whether the load balancer for this is active in node repository */
- public boolean loadBalancerActive() {
- return loadBalancerActive;
+ /** Returns the status of this */
+ public Status status() {
+ return status;
}
/** Returns the endpoint of this */
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/Status.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/Status.java
new file mode 100644
index 00000000000..79c971f56f5
--- /dev/null
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/Status.java
@@ -0,0 +1,40 @@
+// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.hosted.controller.routing;
+
+import java.util.Objects;
+
+/**
+ * Represents the status of a routing policy.
+ *
+ * This is immutable.
+ *
+ * @author mpolden
+ */
+public class Status {
+
+ private final boolean loadBalancerActive;
+
+ /** DO NOT USE. Public for serialization purposes */
+ public Status(boolean loadBalancerActive) {
+ this.loadBalancerActive = loadBalancerActive;
+ }
+
+ /** Returns whether the load balancer is active in node repository */
+ public boolean loadBalancerActive() {
+ return loadBalancerActive;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ Status status = (Status) o;
+ return loadBalancerActive == status.loadBalancerActive;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(loadBalancerActive);
+ }
+
+}
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java
index f9094935444..97c75d93285 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java
@@ -27,6 +27,7 @@ import com.yahoo.vespa.hosted.controller.application.ApplicationPackage;
import com.yahoo.vespa.hosted.controller.integration.ZoneApiMock;
import com.yahoo.vespa.hosted.controller.routing.RoutingPolicy;
import com.yahoo.vespa.hosted.controller.routing.RoutingPolicyId;
+import com.yahoo.vespa.hosted.controller.routing.Status;
import org.junit.Before;
import org.junit.Test;
@@ -216,14 +217,14 @@ public class InternalStepRunnerTest {
tester.controller().curator().writeRoutingPolicies(app.instanceId(), Map.of(id1, new RoutingPolicy(id1,
HostName.from("host"),
Optional.empty(),
- emptySet(), true)));
+ emptySet(), new Status(true))));
var id2 = new RoutingPolicyId(app.testerId().id(),
ClusterSpec.Id.from("default"),
JobType.systemTest.zone(system()));
tester.controller().curator().writeRoutingPolicies(app.testerId().id(), Map.of(id2, new RoutingPolicy(id2,
HostName.from("host"),
Optional.empty(),
- emptySet(), true)));
+ emptySet(), new Status(true))));
tester.runner().run();;
assertEquals(succeeded, tester.jobs().last(app.instanceId(), JobType.systemTest).get().stepStatuses().get(Step.installReal));
assertEquals(succeeded, tester.jobs().last(app.instanceId(), JobType.systemTest).get().stepStatuses().get(Step.installTester));
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/RoutingPolicySerializerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/RoutingPolicySerializerTest.java
index b14a81ec758..65486f5dcc5 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/RoutingPolicySerializerTest.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/RoutingPolicySerializerTest.java
@@ -9,6 +9,7 @@ import com.yahoo.config.provision.zone.ZoneId;
import com.yahoo.vespa.hosted.controller.application.EndpointId;
import com.yahoo.vespa.hosted.controller.routing.RoutingPolicy;
import com.yahoo.vespa.hosted.controller.routing.RoutingPolicyId;
+import com.yahoo.vespa.hosted.controller.routing.Status;
import org.junit.Test;
import java.util.Iterator;
@@ -37,11 +38,11 @@ public class RoutingPolicySerializerTest {
var policies = ImmutableMap.of(id1, new RoutingPolicy(id1,
HostName.from("long-and-ugly-name"),
Optional.of("zone1"),
- endpoints, true),
+ endpoints, new Status(true)),
id2, new RoutingPolicy(id2,
HostName.from("long-and-ugly-name-2"),
Optional.empty(),
- endpoints, false));
+ endpoints, new Status(false)));
var serialized = serializer.fromSlime(owner, serializer.toSlime(policies));
assertEquals(policies.size(), serialized.size());
for (Iterator<RoutingPolicy> it1 = policies.values().iterator(), it2 = serialized.values().iterator(); it1.hasNext();) {
@@ -51,7 +52,7 @@ public class RoutingPolicySerializerTest {
assertEquals(expected.canonicalName(), actual.canonicalName());
assertEquals(expected.dnsZone(), actual.dnsZone());
assertEquals(expected.endpoints(), actual.endpoints());
- assertEquals(expected.loadBalancerActive(), actual.loadBalancerActive());
+ assertEquals(expected.status(), actual.status());
}
}
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 c88250bd816..fc1e45dd1a6 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
@@ -67,6 +67,7 @@ import com.yahoo.vespa.hosted.controller.restapi.ContainerTester;
import com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest;
import com.yahoo.vespa.hosted.controller.routing.RoutingPolicy;
import com.yahoo.vespa.hosted.controller.routing.RoutingPolicyId;
+import com.yahoo.vespa.hosted.controller.routing.Status;
import com.yahoo.vespa.hosted.controller.security.AthenzCredentials;
import com.yahoo.vespa.hosted.controller.security.AthenzTenantSpec;
import com.yahoo.vespa.hosted.controller.tenant.AthenzTenant;
@@ -1438,11 +1439,11 @@ public class ApplicationApiTest extends ControllerContainerTest {
ZoneId.from(Environment.prod, RegionName.from("us-west-1")));
var policies = Map.of(id1, new RoutingPolicy(id1,
HostName.from("lb-0-canonical-name"),
- Optional.of("dns-zone-1"), Set.of(EndpointId.of("c0")), true),
+ Optional.of("dns-zone-1"), Set.of(EndpointId.of("c0")), new Status(true)),
// Inactive policy is not included
id2, new RoutingPolicy(id2,
HostName.from("lb-1-canonical-name"),
- Optional.of("dns-zone-1"), Set.of(), false));
+ Optional.of("dns-zone-1"), Set.of(), new Status(false)));
tester.controller().curator().writeRoutingPolicies(app.instanceId(), policies);
// GET application