aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/RunList.java
blob: b3846dca2c0d700d39ce393871566334ba82f874 (plain) (blame)
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
// Copyright Vespa.ai. 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.vespa.hosted.controller.api.integration.deployment.JobType;

import java.util.Collection;
import java.util.List;

/**
 * List for filtering deployment job {@link Run}s.
 *
 * @author jonmv
 */
public class RunList extends AbstractFilteringList<Run, RunList> {

    private RunList(Collection<? extends Run> items, boolean negate) {
        super(items, negate, RunList::new);
    }

    public static RunList from(Collection<? extends Run> runs) {
        return new RunList(runs, false);
    }

    public static RunList from(JobStatus job) {
        return from(job.runs().descendingMap().values());
    }

    /** Returns the jobs with runs matching the given versions — targets only for system test, everything present otherwise. */
    public RunList on(Versions versions) {
        return matching(run -> matchingVersions(run, versions));
    }

    /** Returns the runs with status among the given. */
    public RunList status(RunStatus... status) {
        return matching(run -> List.of(status).contains(run.status()));
    }

    private static boolean matchingVersions(Run run, Versions versions) {
        return    versions.targetsMatch(run.versions())
               && (versions.sourcesMatchIfPresent(run.versions()) || run.id().type().isSystemTest());
    }

}