diff options
author | Jon Bratseth <bratseth@oath.com> | 2020-12-22 00:06:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-22 00:06:45 +0100 |
commit | 3c9108ed10ba6cb0b02eeceb52f3e3176f8b121a (patch) | |
tree | 6228f8e24675aaa3b036442429460b756a426c37 | |
parent | e6de8561267addf211e7c3ad900e40eb6feb2365 (diff) | |
parent | 55b88522928cc77a341daed62f47e6f4ea56c227 (diff) |
Merge pull request #15862 from vespa-engine/jonmv/find-oldest-version-from-job-history-when-possible
Find oldest platform from job history when possible
-rw-r--r-- | controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java index b92b6bc12f5..832668bf9f7 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java @@ -62,7 +62,9 @@ import com.yahoo.vespa.hosted.controller.athenz.impl.AthenzFacade; import com.yahoo.vespa.hosted.controller.certificate.EndpointCertificateManager; import com.yahoo.vespa.hosted.controller.concurrent.Once; import com.yahoo.vespa.hosted.controller.deployment.DeploymentTrigger; +import com.yahoo.vespa.hosted.controller.deployment.JobStatus; import com.yahoo.vespa.hosted.controller.deployment.Run; +import com.yahoo.vespa.hosted.controller.deployment.RunStatus; import com.yahoo.vespa.hosted.controller.deployment.Versions; import com.yahoo.vespa.hosted.controller.persistence.CuratorDb; import com.yahoo.vespa.hosted.controller.security.AccessControl; @@ -76,11 +78,13 @@ import java.security.Principal; import java.time.Clock; import java.time.Duration; import java.time.Instant; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.EnumSet; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Objects; @@ -88,15 +92,20 @@ import java.util.Optional; import java.util.Set; import java.util.TreeMap; import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; import static com.yahoo.vespa.hosted.controller.api.integration.configserver.Node.State.active; import static com.yahoo.vespa.hosted.controller.api.integration.configserver.Node.State.reserved; import static java.util.Comparator.naturalOrder; +import static java.util.function.Function.identity; +import static java.util.function.Predicate.not; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toMap; +import static java.util.stream.Collectors.toUnmodifiableMap; /** * A singleton owned by the Controller which contains the methods and state for controlling applications. @@ -259,18 +268,40 @@ public class ApplicationController { return Collections.unmodifiableMap(clusters); } + /** Reads the oldest installed platform for the given application and zone from job history, or a node repo. */ + private Optional<Version> oldestInstalledPlatform(JobStatus job) { + Version oldest = null; + for (Run run : job.runs().descendingMap().values()) { + Version version = run.versions().targetPlatform(); + if (oldest == null || version.isBefore(oldest)) + oldest = version; + + if (run.status() == RunStatus.success) + return Optional.of(oldest); + } + // If no successful run was found, ask the node repository in the relevant zone. + return oldestInstalledPlatform(job.id()); + } + + /** Reads the oldest installed platform for the given application and zone from the node repo of that zone. */ + private Optional<Version> oldestInstalledPlatform(JobId job) { + return configServer.nodeRepository().list(job.type().zone(controller.system()), + job.application(), + EnumSet.of(active, reserved)) + .stream() + .map(Node::currentVersion) + .filter(version -> ! version.isEmpty()) + .min(naturalOrder()); + } + /** Returns the oldest Vespa version installed on any active or reserved production node for the given application. */ public Version oldestInstalledPlatform(TenantAndApplicationId id) { - return requireApplication(id).instances().values().stream() - .flatMap(instance -> instance.productionDeployments().keySet().stream() - .flatMap(zone -> configServer.nodeRepository().list(zone, - id.instance(instance.name()), - EnumSet.of(active, reserved)) - .stream()) - .map(Node::currentVersion) - .filter(version -> ! version.isEmpty())) - .min(naturalOrder()) - .orElseGet(controller::readSystemVersion); + return controller.jobController().deploymentStatus(requireApplication(id)).jobs() + .production().asList().stream() + .map(this::oldestInstalledPlatform) + .flatMap(Optional::stream) + .min(naturalOrder()) + .orElse(controller.readSystemVersion()); } /** |