summaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/BuildService.java
blob: ff15b8e2aefdbb3b43e14c5ed94716c0475b5672 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.api.integration;

import com.yahoo.config.provision.ApplicationId;

/**
 * @author jonmv
 */
public interface BuildService {

    /**
     * Enqueues a job defined by buildJob in an external build system.
     *
     * Implementations should throw an exception if the triggering fails.
     */
    void trigger(BuildJob buildJob);

    /**
     * Returns the state of the given job in the build service.
     */
    JobState stateOf(BuildJob buildJob);

    /**
     * Returns whether the given build job should be performed by this build service.
     */
    default boolean builds(BuildJob buildJob) { return true; }

    enum JobState {

        /** Job is not running, and may be triggered. */
        idle,

        /** Job is already running, and will be queued if triggered now. */
        running,

        /** Job is running and queued and will automatically be started again after it finishes its current run. */
        queued,

        /** Job is disabled, i.e., it can not be triggered. */
        disabled

    }


    class BuildJob {

        private final ApplicationId applicationId;
        private final long projectId;
        private final String jobName;

        protected BuildJob(ApplicationId applicationId, long projectId, String jobName) {
            this.applicationId = applicationId;
            this.projectId = projectId;
            this.jobName = jobName;
        }

        public static BuildJob of(ApplicationId applicationId, long projectId, String jobName) {
            return new BuildJob(applicationId, projectId, jobName);
        }

        public ApplicationId applicationId() { return applicationId; }
        public long projectId() { return projectId; }
        public String jobName() { return jobName; }

        @Override
        public final boolean equals(Object o) {
            if (this == o) return true;
            if ( ! (o instanceof BuildJob)) return false;

            BuildJob buildJob = (BuildJob) o;

            if (projectId != buildJob.projectId) return false;
            return jobName.equals(buildJob.jobName);
        }

        @Override
        public final int hashCode() {
            int result = (int) (projectId ^ (projectId >>> 32));
            result = 31 * result + jobName.hashCode();
            return result;
        }

        @Override
        public String toString() {
            return jobName + " for " + applicationId + " with project " + projectId;
        }

    }

}