summaryrefslogtreecommitdiffstats
path: root/controller-api
diff options
context:
space:
mode:
authorJon Marius Venstad <jvenstad@yahoo-inc.com>2017-12-15 09:17:47 +0100
committerJon Marius Venstad <jvenstad@yahoo-inc.com>2017-12-15 09:17:47 +0100
commit8d82aa33667c4b401e693624bd40bf2061b64238 (patch)
tree075707a6a6dca23aabb2d333c5192b777459df4c /controller-api
parenta3fc6158428e18169ee379f405ee35181e71c443 (diff)
Changes to Zones, a MockZones and some usages
Diffstat (limited to 'controller-api')
-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.java27
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZonesMock.java65
3 files changed, 80 insertions, 14 deletions
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 18212001992..b7eb3adadcf 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. */
- List<ZoneId> zones();
+ Zones 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
index 74e2d43a308..966cb376154 100644
--- 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
@@ -6,6 +6,11 @@ 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 {
@@ -19,23 +24,19 @@ public interface Zones {
/** Zones where which are managed by the controller. */
Zones.List controllerManaged();
- // TODO: Move to implementation in hosted?
- /** Zones where auto provisioning of nodes is possible. */
- Zones.List autoProvisioned();
- // TODO: Move to implementation in hosted?
- /** Zones where the nodes should be kept track of in an inventory. */
- Zones.List inventoried();
-
- /** Zones in the given environment. */
- Zones.List in(Environment environment);
+ /** Wraps access to the zones; this forces the user to consider which zones to access. */
+ interface List extends Zones {
- /** Zones in the given region. */
- Zones.List in(RegionName region);
+ /** Negates the next filter. */
+ @Override
+ Zones.List not();
+ /** Zones in the given environment. */
+ Zones.List in(Environment environment);
- /** Wraps access to the zones; this forces the user to consider which zones to access. */
- interface List extends Zones {
+ /** 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();
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/ZonesMock.java
new file mode 100644
index 00000000000..a63dadf6a46
--- /dev/null
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZonesMock.java
@@ -0,0 +1,65 @@
+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.Collection;
+import java.util.Collections;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+/**
+ * A Zones.List implementation which assumes all zones are controllerManaged.
+ *
+ * @author jvenstad
+ */
+public class ZonesMock implements Zones.List {
+
+ private final java.util.List<ZoneId> zones;
+ private final boolean negate;
+
+ private ZonesMock(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);
+ }
+
+ @Override
+ public Zones.List not() {
+ return new ZonesMock(zones, ! negate);
+ }
+
+ @Override
+ public Zones.List all() {
+ return filter(zoneId -> true);
+ }
+
+ @Override
+ public Zones.List controllerManaged() {
+ return all();
+ }
+
+ @Override
+ public Zones.List in(Environment environment) {
+ return filter(zoneId -> zoneId.environment() == environment);
+ }
+
+ @Override
+ public Zones.List in(RegionName region) {
+ return filter(zoneId -> zoneId.region().equals(region));
+ }
+
+ @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);
+ }
+
+}