diff options
author | Jon Marius Venstad <jonmv@users.noreply.github.com> | 2022-06-27 14:02:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-27 14:02:53 +0200 |
commit | e0072daba8ebf2466dfd8f3e482dabaee6f49c14 (patch) | |
tree | f2bd2aa5cb2dc33163ca464937748a099a0dc97f /controller-api | |
parent | 1acf5884c705bd78aad0d6177dc81a4a46dd8952 (diff) | |
parent | 0d4d8c719ddc2947b6172eaaa5e2e368dadaa469 (diff) |
Merge pull request #23218 from vespa-engine/jonmv/multiple-test-and-staging-zones
Jonmv/multiple test and staging zones
Diffstat (limited to 'controller-api')
2 files changed, 36 insertions, 20 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/JobType.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/JobType.java index 77879699ab9..3ecf350b0b5 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/JobType.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/JobType.java @@ -1,9 +1,13 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.api.integration.deployment; +import com.yahoo.config.provision.Cloud; +import com.yahoo.config.provision.CloudName; import com.yahoo.config.provision.Environment; import com.yahoo.config.provision.RegionName; +import com.yahoo.config.provision.zone.ZoneApi; import com.yahoo.config.provision.zone.ZoneId; +import com.yahoo.config.provision.zone.ZoneList; import com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneRegistry; import java.util.Comparator; @@ -38,18 +42,24 @@ public final class JobType implements Comparable<JobType> { } /** A system test in a test zone, or throws if no test zones are present.. */ - public static JobType systemTest(ZoneRegistry zones) { - return testIn(test, zones); + public static JobType systemTest(ZoneRegistry zones, CloudName cloud) { + return testIn(test, zones, cloud); } /** A staging test in a staging zone, or throws if no staging zones are present. */ - public static JobType stagingTest(ZoneRegistry zones){ - return testIn(staging, zones); + public static JobType stagingTest(ZoneRegistry zones, CloudName cloud){ + return testIn(staging, zones, cloud); } - private static JobType testIn(Environment environment, ZoneRegistry zones) { - return zones.zones().controllerUpgraded().in(environment).zones().stream().map(zone -> deploymentTo(zone.getId())) - .findFirst().orElseThrow(() -> new IllegalArgumentException("no zones in " + environment + " among " + zones.zones().controllerUpgraded().zones())); + /** Returns a test job in the given environment, preferring the given cloud, is possible; using the system cloud otherwise. */ + private static JobType testIn(Environment environment, ZoneRegistry zones, CloudName cloud) { + ZoneList candidates = zones.zones().controllerUpgraded().in(environment); + if (cloud == null || candidates.in(cloud).zones().isEmpty()) + cloud = zones.systemZone().getCloudName(); + + return candidates.in(cloud).zones().stream().map(zone -> deploymentTo(zone.getId())) + .findFirst().orElseThrow(() -> new IllegalArgumentException("no zones in " + environment + " among " + + zones.zones().controllerUpgraded().zones())); } /** A deployment to the given dev region. */ @@ -118,27 +128,33 @@ public final class JobType implements Comparable<JobType> { throw new IllegalArgumentException("illegal serialized job type '" + raw + "'"); } - /** Creates a new job type from a job name, and a zone registry for looking up zones for the special system and staging test types. */ + /** + * Creates a new job type from a job name, and a zone registry for looking up zones for the special system and staging test types. + * Note: system and staging tests retrieved by job name always use the default cloud for the system! + */ public static JobType fromJobName(String jobName, ZoneRegistry zones) { - String[] parts = jobName.split("-", 2); - if (parts.length != 2) throw new IllegalArgumentException("job names must be 'system-test', 'staging-test', or environment and region parts, separated by '-', but got: " + jobName); - switch (parts[0]) { - case "system": return systemTest(zones); - case "staging": return stagingTest(zones); - case "production": return prod(parts[1]); - case "test": return test(parts[1]); - case "dev": return dev(parts[1]); - case "perf": return perf(parts[1]); - default: throw new IllegalArgumentException("job names must begin with one of: system, staging, production, test, dev, perf; but got: " + jobName); + switch (jobName) { + case "system-test": return systemTest(zones, null); + case "staging-test": return stagingTest(zones, null); } + String[] parts = jobName.split("-", 2); + if (parts.length == 2) + switch (parts[0]) { + case "production": return prod(parts[1]); + case "test": return test(parts[1]); + case "dev": return dev(parts[1]); + case "perf": return perf(parts[1]); + } + throw new IllegalArgumentException("job names must be 'system-test', 'staging-test', or <test|environment>-<region>, but got: " + jobName); } public static List<JobType> allIn(ZoneRegistry zones) { return zones.zones().reachable().zones().stream() .flatMap(zone -> zone.getEnvironment().isProduction() ? Stream.of(deploymentTo(zone.getId()), productionTestOf(zone.getId())) : Stream.of(deploymentTo(zone.getId()))) + .distinct() .sorted(naturalOrder()) - .collect(toUnmodifiableList()); + .toList(); } /** A serialized form of this: {@code <environment>.<region>[.test]}; the inverse of {@link #ofSerialized(String)} */ diff --git a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/JobTypeTest.java b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/JobTypeTest.java index 6ff52bd5f03..bbe0c2bd458 100644 --- a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/JobTypeTest.java +++ b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/JobTypeTest.java @@ -48,4 +48,4 @@ public class JobTypeTest { assertTrue(JobType.test("snohetta").isProduction()); } -} +}
\ No newline at end of file |