~launchpad-pqm/launchpad/devel

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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# Copyright 2009 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

# pylint: disable-msg=E0211,E0213

"""Build interfaces."""

__metaclass__ = type

__all__ = [
    'IBuildQueue',
    'IBuildQueueSet',
    ]

from lazr.restful.fields import Reference
from zope.interface import (
    Attribute,
    Interface,
    )
from zope.schema import (
    Bool,
    Choice,
    Datetime,
    Field,
    Int,
    Text,
    Timedelta,
    )

from lp import _
from lp.buildmaster.enums import BuildFarmJobType
from lp.buildmaster.interfaces.builder import IBuilder
from lp.buildmaster.interfaces.buildfarmjob import IBuildFarmJob
from lp.services.job.interfaces.job import IJob
from lp.soyuz.interfaces.processor import IProcessor


class IBuildQueue(Interface):
    """A Launchpad Auto Build queue entry.

    This table contains work-in-progress in Buildd environment, as well as
    incoming jobs.

    It relates a pending Builds with an heuristic index (last_score) which
    is used to order build jobs in a proper way.

    When building (job dispatched) it also includes the responsible Builder
    (builder), the time it has started (buildstarted) and up to 2 Kbytes
    of the current processing log (logtail).
    """

    id = Attribute("Job identifier")
    builder = Reference(
        IBuilder, title=_("Builder"), required=True, readonly=True,
        description=_("The IBuilder instance processing this job"))
    logtail = Text(
        description=_("The current tail of the log of the job"))
    lastscore = Int(description=_("This job's score."))
    manual = Bool(
        description=_("Whether or not the job was manually scored."))
    processor = Reference(
        IProcessor, title=_("Processor"), required=False, readonly=True,
        description=_("The processor required by this build farm job."))
    virtualized = Bool(
        required=False,
        description=_(
            "The virtualization setting required by this build farm job."))

    job = Reference(
        IJob, title=_("Job"), required=True, readonly=True,
        description=_("Data common to all job types."))

    job_type = Choice(
        title=_('Job type'), required=True, vocabulary=BuildFarmJobType,
        description=_("The type of this job."))

    required_build_behavior = Field(
        title=_('The builder behavior required to run this job.'),
        required=False, readonly=True)

    estimated_duration = Timedelta(
        title=_("Estimated Job Duration"), required=True,
        description=_("Estimated job duration interval."))

    current_build_duration = Timedelta(
        title=_("Current build duration"), required=False,
        description=_("Time spent building so far."))

    def manualScore(value):
        """Manually set a score value to a queue item and lock it."""

    def score():
        """The job score calculated for the job type in question."""

    def destroySelf():
        """Delete this entry from the database."""

    def getLogFileName():
        """Get the preferred filename for the buildlog of this build."""

    def markAsBuilding(builder):
        """Set this queue item to a 'building' state."""

    def reset():
        """Reset this job, so it can be re-dispatched."""

    def cancel():
        """Cancel this job, it will not be re-dispatched."""

    specific_job = Reference(
        IBuildFarmJob, title=_("Job"),
        description=_("Data and operations common to all build farm jobs."))

    def setDateStarted(timestamp):
        """Sets the date started property to the given value."""

    date_started = Datetime(
        title=_('Start time'),
        description=_('Time when the job started.'))

    def getEstimatedJobStartTime():
        """Get the estimated start time for a pending build farm job.

        :return: a timestamp upon success or None on failure. None
            indicates that an estimated start time is not available.
        :raise: AssertionError when the build job is not in the
            `JobStatus.WAITING` state.
        """


class IBuildQueueSet(Interface):
    """Launchpad Auto Build queue set handler and auxiliary methods."""

    title = Attribute('Title')

    def __iter__():
        """Iterate over current build jobs."""

    def __getitem__(buildqueue_id):
        """Retrieve a build job by id."""

    def count():
        """Return the number of build jobs in the queue."""

    def get(buildqueue_id):
        """Return the `IBuildQueue` with the given id."""

    def getByJob(job):
        """Find the `IBuildQueue` to which `job` belongs.

        :param job: A `Job`.
        :return: The matching `IBuildQueue`, or None.
        """

    def getByBuilder(builder):
        """Return an IBuildQueue instance for a builder.

        Retrieve the only one possible entry being processed for a given
        builder. If not found, return None.
        """

    def getActiveBuildJobs():
        """Return All active Build Jobs."""