summaryrefslogtreecommitdiffstats
path: root/controller-api
diff options
context:
space:
mode:
authorJon Marius Venstad <jvenstad@yahoo-inc.com>2018-01-03 11:06:26 +0100
committerJon Marius Venstad <jvenstad@yahoo-inc.com>2018-01-03 11:06:26 +0100
commit0eab0f1de57dc41cd6eecce1365666cd05a94ec0 (patch)
tree4a0a483c19f48287eef54f401e227f7d86d058fe /controller-api
parent96373e3f8379d3e4783d87733b32458fd4e18007 (diff)
Revert "Revert "Revert "Revert "Jvenstad/zone cleanup 4""""
This reverts commit 7b99d259bf378c0e5c43c9a199efffdf056678f4.
Diffstat (limited to 'controller-api')
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/identifiers/DeploymentId.java2
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/MetricsService.java2
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneFilter.java22
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneFilterMock.java72
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneId.java73
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneList.java34
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneRegistry.java6
-rw-r--r--controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/identifiers/IdentifierTest.java4
8 files changed, 206 insertions, 9 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/identifiers/DeploymentId.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/identifiers/DeploymentId.java
index f1c584c7a3c..04dd91670c1 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/identifiers/DeploymentId.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/identifiers/DeploymentId.java
@@ -1,7 +1,7 @@
// Copyright 2017 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.identifiers;
-import com.yahoo.config.provision.ZoneId;
+import com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId;
import java.util.Objects;
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/MetricsService.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/MetricsService.java
index d3e1b881bbd..20e9710f092 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/MetricsService.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/MetricsService.java
@@ -2,7 +2,7 @@
package com.yahoo.vespa.hosted.controller.api.integration;
import com.yahoo.config.provision.ApplicationId;
-import com.yahoo.config.provision.ZoneId;
+import com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId;
import java.util.Map;
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneFilter.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneFilter.java
new file mode 100644
index 00000000000..f718b86ca40
--- /dev/null
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneFilter.java
@@ -0,0 +1,22 @@
+package com.yahoo.vespa.hosted.controller.api.integration.zone;
+
+/**
+ * A ZoneId list which can be filtered in various ways; elements can be accessed after at least one filter.
+ *
+ * The methods here return instances of {@link ZoneList}, which extends ZoneFilter, but with accessors and additional filters.
+ * This forces the developer to consider which of the filters in this class to apply, prior to processing any zones.
+ *
+ * @author jvenstad
+ */
+public interface ZoneFilter {
+
+ /** Negates the next filter. */
+ ZoneFilter not();
+
+ /** All zones from the initial pool. */
+ ZoneList all();
+
+ /** Zones where which are managed by the controller. */
+ ZoneList controllerManaged();
+
+}
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
new file mode 100644
index 00000000000..e68bf0ccc24
--- /dev/null
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneFilterMock.java
@@ -0,0 +1,72 @@
+package com.yahoo.vespa.hosted.controller.api.integration.zone;
+
+import com.yahoo.config.provision.Environment;
+import com.yahoo.config.provision.RegionName;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+/**
+ * A Zones.List implementation which assumes all zones are controllerManaged.
+ *
+ * @author jvenstad
+ */
+public class ZoneFilterMock implements ZoneList {
+
+ private final java.util.List<ZoneId> zones;
+ private final boolean negate;
+
+ private ZoneFilterMock(java.util.List<ZoneId> zones, boolean negate) {
+ this.negate = negate;
+ this.zones = zones;
+ }
+
+ public static ZoneFilter from(Collection<ZoneId> zones) {
+ return new ZoneFilterMock(new ArrayList<>(zones), false);
+ }
+
+ @Override
+ public ZoneList not() {
+ return new ZoneFilterMock(zones, ! negate);
+ }
+
+ @Override
+ public ZoneList all() {
+ return filter(zoneId -> true);
+ }
+
+ @Override
+ public ZoneList controllerManaged() {
+ return all();
+ }
+
+ @Override
+ public ZoneList in(Environment environment) {
+ return filter(zoneId -> zoneId.environment() == environment);
+ }
+
+ @Override
+ public ZoneList in(RegionName region) {
+ return filter(zoneId -> zoneId.region().equals(region));
+ }
+
+ @Override
+ public ZoneList zones(ZoneId... zones) {
+ return filter(zoneId -> new HashSet<>(Arrays.asList(zones)).contains(zoneId));
+ }
+
+ @Override
+ public java.util.List<ZoneId> ids() {
+ return Collections.unmodifiableList(zones);
+ }
+
+ private ZoneFilterMock filter(Predicate<ZoneId> condition) {
+ return new ZoneFilterMock(zones.stream().filter(negate ? condition.negate() : condition).collect(Collectors.toList()), false);
+ }
+
+}
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
new file mode 100644
index 00000000000..21ac7a654b8
--- /dev/null
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneId.java
@@ -0,0 +1,73 @@
+// Copyright 2017 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 com.yahoo.config.provision.Environment;
+import com.yahoo.config.provision.RegionName;
+
+import java.util.Objects;
+
+/**
+ * Unique identifier for a Zone; use when referencing them.
+ *
+ * Serialised form is 'environment.region'.
+ *
+ * @author jvenstad
+ */
+public class ZoneId {
+ // TODO: Replace usages of environment + region with usages of this.
+
+ private final Environment environment;
+ private final RegionName region;
+
+ private ZoneId(Environment environment, RegionName region) {
+ this.environment = Objects.requireNonNull(environment);
+ this.region = Objects.requireNonNull(region);
+ }
+
+ public static ZoneId from(Environment environment, RegionName region) {
+ return new ZoneId(environment, region);
+ }
+
+ 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 Environment environment() {
+ return environment;
+ }
+
+ public RegionName region() {
+ return region;
+ }
+
+ /** Returns the serialised value of this. Inverse of {@code ZoneId.from(String value)}. */
+ public String value() {
+ return environment + "." + region;
+ }
+
+ @Override
+ public String toString() {
+ return "zone " + value();
+ }
+
+ @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);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(environment, region);
+ }
+
+}
+
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneList.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneList.java
new file mode 100644
index 00000000000..cd263769864
--- /dev/null
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneList.java
@@ -0,0 +1,34 @@
+package com.yahoo.vespa.hosted.controller.api.integration.zone;
+
+import com.yahoo.config.provision.Environment;
+import com.yahoo.config.provision.RegionName;
+
+import java.util.List;
+
+/**
+ * Provides filters for and access to a list of ZoneIds.
+ *
+ * This is typically offered after an initial filter from {@link ZoneFilter} has been applied.
+ * This forces the developer to consider which zones to process.
+ *
+ * @author jvenstad
+ */
+public interface ZoneList extends ZoneFilter {
+
+ /** Negates the next filter. */
+ @Override
+ ZoneList not();
+
+ /** Zones in the given environment. */
+ ZoneList in(Environment environment);
+
+ /** Zones in the given region. */
+ ZoneList in(RegionName region);
+
+ /** Only the given zones — combine with not() for best effect! */
+ ZoneList zones(ZoneId... zones);
+
+ /** Returns the id of all zones in this list as — you guessed it — a list. */
+ List<ZoneId> ids();
+
+}
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 af7c464b8d7..03207d86983 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
@@ -1,11 +1,9 @@
// Copyright 2017 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 com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.Environment;
import com.yahoo.config.provision.RegionName;
import com.yahoo.config.provision.SystemName;
-import com.yahoo.config.provision.ZoneId;
import com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId;
import java.net.URI;
@@ -24,7 +22,7 @@ public interface ZoneRegistry {
boolean hasZone(ZoneId zoneId);
/** Returns a list containing the id of all zones in this registry. */
- List<ZoneId> zones();
+ ZoneFilter zones();
/** Returns the default region for the given environment, if one is configured. */
Optional<RegionName> getDefaultRegion(Environment environment);
@@ -39,7 +37,7 @@ public interface ZoneRegistry {
/** Returns a list with all known config servers in the given zone, with a secure connection URL. */
List<URI> getConfigServerSecureUris(ZoneId zoneId);
- /** Returns a URL with the logs for the given deployment, if loggin is configured for its zone. */
+ /** Returns a URL with the logs for the given deployment, if logging is configured for its zone. */
Optional<URI> getLogServerUri(DeploymentId deploymentId);
/** Returns the time to live for deployments in the given zone, or empty if this is infinite. */
diff --git a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/identifiers/IdentifierTest.java b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/identifiers/IdentifierTest.java
index aa3d1be879e..0ba607a235b 100644
--- a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/identifiers/IdentifierTest.java
+++ b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/identifiers/IdentifierTest.java
@@ -1,9 +1,7 @@
// Copyright 2017 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.identifiers;
-import com.yahoo.config.provision.Environment;
-import com.yahoo.config.provision.RegionName;
-import com.yahoo.config.provision.ZoneId;
+import com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId;
import org.junit.Test;
import static org.junit.Assert.assertEquals;