summaryrefslogtreecommitdiffstats
path: root/controller-api
diff options
context:
space:
mode:
authorJon Marius Venstad <jvenstad@yahoo-inc.com>2017-12-16 08:16:38 +0100
committerJon Marius Venstad <jvenstad@yahoo-inc.com>2017-12-16 08:16:38 +0100
commit9b7f64abf7601305856d0480cb5b3199c85a831f (patch)
treeba4ac7f3b5a4b7c5221e9cd9ba6ef95edb84cd80 /controller-api
parentf9c450c9dc49883f924f273670bd96e685bdf247 (diff)
Split Zones and renamed it
Diffstat (limited to 'controller-api')
-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.java (renamed from controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZonesMock.java)31
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneId.java2
-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.java2
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/Zones.java46
6 files changed, 77 insertions, 60 deletions
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/ZonesMock.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneFilterMock.java
index a63dadf6a46..e68bf0ccc24 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZonesMock.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneFilterMock.java
@@ -4,8 +4,10 @@ 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;
@@ -14,52 +16,57 @@ import java.util.stream.Collectors;
*
* @author jvenstad
*/
-public class ZonesMock implements Zones.List {
+public class ZoneFilterMock implements ZoneList {
private final java.util.List<ZoneId> zones;
private final boolean negate;
- private ZonesMock(java.util.List<ZoneId> zones, boolean negate) {
+ private ZoneFilterMock(java.util.List<ZoneId> zones, boolean negate) {
this.negate = negate;
this.zones = zones;
}
- public static Zones from(Collection<ZoneId> zones) {
- return new ZonesMock(new ArrayList<>(zones), false);
+ public static ZoneFilter from(Collection<ZoneId> zones) {
+ return new ZoneFilterMock(new ArrayList<>(zones), false);
}
@Override
- public Zones.List not() {
- return new ZonesMock(zones, ! negate);
+ public ZoneList not() {
+ return new ZoneFilterMock(zones, ! negate);
}
@Override
- public Zones.List all() {
+ public ZoneList all() {
return filter(zoneId -> true);
}
@Override
- public Zones.List controllerManaged() {
+ public ZoneList controllerManaged() {
return all();
}
@Override
- public Zones.List in(Environment environment) {
+ public ZoneList in(Environment environment) {
return filter(zoneId -> zoneId.environment() == environment);
}
@Override
- public Zones.List in(RegionName region) {
+ 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 ZonesMock filter(Predicate<ZoneId> condition) {
- return new ZonesMock(zones.stream().filter(negate ? condition.negate() : condition).collect(Collectors.toList()), false);
+ 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
index 818f57ec44d..21ac7a654b8 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
@@ -14,7 +14,7 @@ import java.util.Objects;
* @author jvenstad
*/
public class ZoneId {
- // TODO: Replace usages of zone + region with usages of this.
+ // TODO: Replace usages of environment + region with usages of this.
private final Environment environment;
private final RegionName 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 b7eb3adadcf..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
@@ -22,7 +22,7 @@ public interface ZoneRegistry {
boolean hasZone(ZoneId zoneId);
/** Returns a list containing the id of all zones in this registry. */
- Zones zones();
+ ZoneFilter zones();
/** Returns the default region for the given environment, if one is configured. */
Optional<RegionName> getDefaultRegion(Environment environment);
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/Zones.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/Zones.java
deleted file mode 100644
index 966cb376154..00000000000
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/Zones.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package com.yahoo.vespa.hosted.controller.api.integration.zone;
-
-import com.yahoo.config.provision.Environment;
-import com.yahoo.config.provision.RegionName;
-
-/**
- * A ZoneId list which can be filtered in various ways; elements can be accessed after at least one filter.
- *
- * The class is split in an outer and an inner class to force the user to make an initial choice between
- * the filters available in the outer class; these should be pertinent to what code should use the zone,
- * while the filters in the inner class are optional and / or for convenience.
- *
- *
- * @author jvenstad
- */
-public interface Zones {
-
- /** Negates the next filter. */
- Zones not();
-
- /** All zones from the initial pool. */
- Zones.List all();
-
- /** Zones where which are managed by the controller. */
- Zones.List controllerManaged();
-
-
- /** Wraps access to the zones; this forces the user to consider which zones to access. */
- interface List extends Zones {
-
- /** Negates the next filter. */
- @Override
- Zones.List not();
-
- /** Zones in the given environment. */
- Zones.List in(Environment environment);
-
- /** Zones in the given region. */
- Zones.List in(RegionName region);
-
- /** Returns the id of all zones in this list as — you guessed it — a list. */
- java.util.List<ZoneId> ids();
-
- }
-
-}