1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.deployment;
import com.yahoo.collections.AbstractFilteringList;
import com.yahoo.component.Version;
import java.time.Instant;
import java.util.Collection;
/**
* List for filtering deployment status of applications, for inspection and decision making.
*
* @author jonmv
*/
public class DeploymentStatusList extends AbstractFilteringList<DeploymentStatus, DeploymentStatusList> {
private DeploymentStatusList(Collection<? extends DeploymentStatus> items, boolean negate) {
super(items, negate, DeploymentStatusList::new);
}
public static DeploymentStatusList from(Collection<? extends DeploymentStatus> status) {
return new DeploymentStatusList(status, false);
}
/** Returns the subset of applications which have changes left to deploy; blocked, or deploying */
public DeploymentStatusList withChanges() {
return matching(status -> status.application().instances().values().stream()
.anyMatch(instance -> instance.change().hasTargets() || status.outstandingChange(instance.name()).hasTargets()));
}
/** Returns the subset of applications which have been failing an upgrade to the given version since the given instant */
public DeploymentStatusList failingUpgradeToVersionSince(Version version, Instant threshold) {
return matching(status -> status.instanceJobs().values().stream()
.anyMatch(jobs -> failingUpgradeToVersionSince(jobs, version, threshold)));
}
/** Returns the subset of applications which have been failing an application change since the given instant */
public DeploymentStatusList failingApplicationChangeSince(Instant threshold) {
return matching(status -> status.instanceJobs().values().stream()
.anyMatch(jobs -> failingApplicationChangeSince(jobs, threshold)));
}
private static boolean failingUpgradeToVersionSince(JobList jobs, Version version, Instant threshold) {
return ! jobs.not().failingApplicationChange()
.firstFailing().endedNoLaterThan(threshold)
.lastCompleted().on(version)
.isEmpty();
}
private static boolean failingApplicationChangeSince(JobList jobs, Instant threshold) {
return ! jobs.failingApplicationChange()
.firstFailing().endedNoLaterThan(threshold)
.isEmpty();
}
}
|