diff options
author | Martin Polden <mpolden@mpolden.no> | 2018-08-20 14:43:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-20 14:43:41 +0200 |
commit | 2c1c1ad7a945ad5365e84b118e7a8103a025a88f (patch) | |
tree | 2b9ee9c7fa7aa3751e563bff08ba6325a988397d | |
parent | 5a46e3fa7e8ca830bccf68f03032050ac1b5d11b (diff) | |
parent | f2987e052a0a363ac48abe399153b6274c3b48b2 (diff) |
Merge pull request #6614 from vespa-engine/mpolden/controller-cloud-awareness
Make controller aware of clouds
7 files changed, 102 insertions, 24 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Node.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Node.java index e51814e44f8..d166bb0d3fb 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Node.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Node.java @@ -50,14 +50,6 @@ public class Node { this.wantedRebootGeneration = wantedRebootGeneration; } - // TODO: Remove once internal code supports new constructor - public Node(HostName hostname, State state, NodeType type, Optional<ApplicationId> owner, - Version currentVersion, Version wantedVersion, ServiceState serviceState, - long restartGeneration, long wantedRestartGeneration, long rebootGeneration, long wantedRebootGeneration) { - this(hostname, state, type, owner, currentVersion, wantedVersion, Version.emptyVersion, Version.emptyVersion, - serviceState, restartGeneration, wantedRestartGeneration, rebootGeneration, wantedRebootGeneration); - } - @TestOnly public Node(HostName hostname, State state, NodeType type, Optional<ApplicationId> owner, Version currentVersion, Version wantedVersion) { diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/NodeRepository.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/NodeRepository.java index 92d07edaca8..b0acea188d0 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/NodeRepository.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/NodeRepository.java @@ -31,8 +31,6 @@ public interface NodeRepository { void upgrade(ZoneId zone, NodeType type, Version version); /** Upgrade OS for all nodes of given type to a new version */ - default void upgradeOs(ZoneId zone, NodeType type, Version version) { - // TODO: Remove default implementation once implemented in internal code - } + void upgradeOs(ZoneId zone, NodeType type, Version version); } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/CloudName.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/CloudName.java new file mode 100644 index 00000000000..e7a6b32b36e --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/CloudName.java @@ -0,0 +1,62 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.controller.api.integration.zone; + +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; + +/** + * Represents a cloud provider used in a hosted Vespa system. + * + * @author mpolden + */ +public class CloudName implements Comparable<CloudName> { + + private final static CloudName defaultCloud = from("default"); + + private final String cloud; + + private CloudName(String cloud) { + this.cloud = cloud; + } + + public String value() { + return cloud; + } + + public boolean isDefault() { + return defaultName().equals(this); + } + + public static CloudName defaultName() { + return defaultCloud; + } + + public static CloudName from(String cloud) { + return new CloudName(cloud); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CloudName cloudName = (CloudName) o; + return Objects.equals(cloud, cloudName.cloud); + } + + @Override + public int hashCode() { + return Objects.hash(cloud); + } + + @Override + public String toString() { + return cloud; + } + + @Override + public int compareTo(@NotNull CloudName o) { + return cloud.compareTo(o.cloud); + } + +} diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneFilterMock.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneFilterMock.java index 67d2fd14e6b..10cf862fa30 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneFilterMock.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneFilterMock.java @@ -9,20 +9,21 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.function.Predicate; import java.util.stream.Collectors; /** - * A Zones.List implementation which assumes all zones are controllerManaged. + * A ZoneList implementation which assumes all zones are controllerManaged. * * @author jonmv */ public class ZoneFilterMock implements ZoneList { - private final java.util.List<ZoneId> zones; + private final List<ZoneId> zones; private final boolean negate; - private ZoneFilterMock(java.util.List<ZoneId> zones, boolean negate) { + private ZoneFilterMock(List<ZoneId> zones, boolean negate) { this.negate = negate; this.zones = zones; } @@ -67,7 +68,7 @@ public class ZoneFilterMock implements ZoneList { } @Override - public java.util.List<ZoneId> ids() { + public List<ZoneId> ids() { return Collections.unmodifiableList(zones); } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneId.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneId.java index b53b81398c6..c98f6da3f29 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneId.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneId.java @@ -18,10 +18,16 @@ public class ZoneId { private final Environment environment; private final RegionName region; + private final CloudName cloud; - private ZoneId(Environment environment, RegionName region) { + private ZoneId(Environment environment, RegionName region, CloudName cloud) { this.environment = Objects.requireNonNull(environment); this.region = Objects.requireNonNull(region); + this.cloud = cloud; + } + + private ZoneId(Environment environment, RegionName region) { + this(environment, region, CloudName.defaultName()); } public static ZoneId from(Environment environment, RegionName region) { @@ -31,12 +37,21 @@ public class ZoneId { public static ZoneId from(String environment, String region) { return from(Environment.from(environment), RegionName.from(region)); } + /** Create from a serialised ZoneId. Inverse of {@code ZoneId.value()}. */ public static ZoneId from(String value) { String[] parts = value.split("\\."); return from(parts[0], parts[1]); } + public static ZoneId from(Environment environment, RegionName region, CloudName cloud) { + return new ZoneId(environment, region, cloud); + } + + public static ZoneId from(String environment, String region, String cloud) { + return new ZoneId(Environment.from(environment), RegionName.from(region), CloudName.from(cloud)); + } + public Environment environment() { return environment; } @@ -45,6 +60,10 @@ public class ZoneId { return region; } + public CloudName cloud() { + return cloud; + } + /** Returns the serialised value of this. Inverse of {@code ZoneId.from(String value)}. */ public String value() { return environment + "." + region; @@ -52,21 +71,22 @@ public class ZoneId { @Override public String toString() { - return "zone " + value(); + return "zone " + value() + " in " + cloud; } @Override public boolean equals(Object o) { if (this == o) return true; - if ( ! (o instanceof ZoneId)) return false; - ZoneId id = (ZoneId) o; - return environment == id.environment && - Objects.equals(region, id.region); + if (o == null || getClass() != o.getClass()) return false; + ZoneId zoneId = (ZoneId) o; + return environment == zoneId.environment && + Objects.equals(region, zoneId.region) && + Objects.equals(cloud, zoneId.cloud); } @Override public int hashCode() { - return Objects.hash(environment, region); + return Objects.hash(environment, region, cloud); } } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneRegistry.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneRegistry.java index f721564c80e..4fbad88df8d 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneRegistry.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneRegistry.java @@ -53,9 +53,14 @@ public interface ZoneRegistry { UpgradePolicy upgradePolicy(); /** Returns the OS upgrade policy to use for zones in this registry */ - // TODO: Remove default once internal code implements this + // TODO: Remove default UpgradePolicy osUpgradePolicy() { return upgradePolicy(); } + /** Returns the OS upgrade policy to use for zones belonging to given cloud, in this registry */ + default UpgradePolicy osUpgradePolicy(CloudName cloud) { + return osUpgradePolicy(); // TODO: Remove default implementation + } + } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/JobControllerApiHandlerHelperTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/JobControllerApiHandlerHelperTest.java index f0cb7ca645d..9e8dfad82c1 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/JobControllerApiHandlerHelperTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/JobControllerApiHandlerHelperTest.java @@ -161,7 +161,7 @@ public class JobControllerApiHandlerHelperTest { private void assertFile(HttpResponse response, String resourceName) { try { - Path path = Paths.get(getClass().getClassLoader().getResource(resourceName).getPath()); + Path path = Paths.get("src/test/resources/").resolve(resourceName); String expected = new String(Files.readAllBytes(path)); compare(response, expected); } catch (Exception e) { |