mirror of
https://git.yoctoproject.org/poky
synced 2026-03-06 23:39:40 +01:00
The most recent builds area of the all builds and project builds table needs to update as a build progresses. It also needs additional functionality to show other states (e.g. recipe parsing, queued) which again needs to update on the client side. Rather than add to the existing mix of server-side templating with client-side DOM updating, translate all of the server-side templates to client-side ones (jsrender), and add logic which updates the most recent builds area as the state of a build changes. Add a JSON API for mostrecentbuilds, which returns the state of all "recent" builds. Fetch this via Ajax from the build dashboard (rather than fetching the ad hoc API as in the previous version). Then, as new states for builds are fetched via Ajax, determine whether the build state has changed completely, or whether the progress has just updated. If the state completely changed, re-render the template on the client side for that build. If only the progress changed, just update the progress bar. (NB this fixes the task progress bar so it works for the project builds and all builds pages.) In cases where the builds table needs to update as the result of a build finishing, reload the whole page. This work highlighted a variety of other issues, such as build requests not being able to change state as necessary. This was one part of the cause of the "cancelling build..." state being fragile and disappearing entirely when the page refreshed. The cancelling state now persists between page reloads, as the logic for determining whether a build is cancelling is now on the Build object itself. Note that jsrender is redistributed as part of Toaster, so a note was added to LICENSE to that effect. [YOCTO #9631] (Bitbake rev: c868ea036aa34b387a72ec5116a66b2cd863995b) Signed-off-by: Elliot Smith <elliot.smith@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
161 lines
6.0 KiB
Python
161 lines
6.0 KiB
Python
from __future__ import unicode_literals
|
|
from django.db import models
|
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
|
from django.utils.encoding import force_text
|
|
from orm.models import Project, ProjectLayer, ProjectVariable, ProjectTarget, Build, Layer_Version
|
|
|
|
import logging
|
|
logger = logging.getLogger("toaster")
|
|
# a BuildEnvironment is the equivalent of the "build/" directory on the localhost
|
|
class BuildEnvironment(models.Model):
|
|
SERVER_STOPPED = 0
|
|
SERVER_STARTED = 1
|
|
SERVER_STATE = (
|
|
(SERVER_STOPPED, "stopped"),
|
|
(SERVER_STARTED, "started"),
|
|
)
|
|
|
|
TYPE_LOCAL = 0
|
|
TYPE = (
|
|
(TYPE_LOCAL, "local"),
|
|
)
|
|
|
|
LOCK_FREE = 0
|
|
LOCK_LOCK = 1
|
|
LOCK_RUNNING = 2
|
|
LOCK_STATE = (
|
|
(LOCK_FREE, "free"),
|
|
(LOCK_LOCK, "lock"),
|
|
(LOCK_RUNNING, "running"),
|
|
)
|
|
|
|
address = models.CharField(max_length = 254)
|
|
betype = models.IntegerField(choices = TYPE)
|
|
bbaddress = models.CharField(max_length = 254, blank = True)
|
|
bbport = models.IntegerField(default = -1)
|
|
bbtoken = models.CharField(max_length = 126, blank = True)
|
|
bbstate = models.IntegerField(choices = SERVER_STATE, default = SERVER_STOPPED)
|
|
sourcedir = models.CharField(max_length = 512, blank = True)
|
|
builddir = models.CharField(max_length = 512, blank = True)
|
|
lock = models.IntegerField(choices = LOCK_STATE, default = LOCK_FREE)
|
|
created = models.DateTimeField(auto_now_add = True)
|
|
updated = models.DateTimeField(auto_now = True)
|
|
|
|
def get_artifact(self, path):
|
|
if self.betype == BuildEnvironment.TYPE_LOCAL:
|
|
return open(path, "r")
|
|
raise NotImplementedError("FIXME: artifact download not implemented "\
|
|
"for build environment type %s" % \
|
|
self.get_betype_display())
|
|
|
|
def has_artifact(self, path):
|
|
import os
|
|
if self.betype == BuildEnvironment.TYPE_LOCAL:
|
|
return os.path.exists(path)
|
|
raise NotImplementedError("FIXME: has artifact not implemented for "\
|
|
"build environment type %s" % \
|
|
self.get_betype_display())
|
|
|
|
# a BuildRequest is a request that the scheduler will build using a BuildEnvironment
|
|
# the build request queue is the table itself, ordered by state
|
|
|
|
class BuildRequest(models.Model):
|
|
REQ_CREATED = 0
|
|
REQ_QUEUED = 1
|
|
REQ_INPROGRESS = 2
|
|
REQ_FAILED = 3
|
|
REQ_DELETED = 4
|
|
REQ_CANCELLING = 5
|
|
REQ_COMPLETED = 6
|
|
REQ_ARCHIVE = 7
|
|
|
|
REQUEST_STATE = (
|
|
(REQ_CREATED, "created"),
|
|
(REQ_QUEUED, "queued"),
|
|
(REQ_INPROGRESS, "in progress"),
|
|
(REQ_FAILED, "failed"),
|
|
(REQ_DELETED, "deleted"),
|
|
(REQ_CANCELLING, "cancelling"),
|
|
(REQ_COMPLETED, "completed"),
|
|
(REQ_ARCHIVE, "archive"),
|
|
)
|
|
|
|
search_allowed_fields = ("brtarget__target", "build__project__name")
|
|
|
|
project = models.ForeignKey(Project)
|
|
build = models.OneToOneField(Build, null = True) # TODO: toasterui should set this when Build is created
|
|
environment = models.ForeignKey(BuildEnvironment, null = True)
|
|
state = models.IntegerField(choices = REQUEST_STATE, default = REQ_CREATED)
|
|
created = models.DateTimeField(auto_now_add = True)
|
|
updated = models.DateTimeField(auto_now = True)
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super(BuildRequest, self).__init__(*args, **kwargs)
|
|
# Save the old state in case it's about to be modified
|
|
self.old_state = self.state
|
|
|
|
def save(self, *args, **kwargs):
|
|
# Check that the state we're trying to set is not going backwards
|
|
# e.g. from REQ_FAILED to REQ_INPROGRESS
|
|
if self.old_state != self.state and self.old_state > self.state:
|
|
logger.warning("Invalid state change requested: "
|
|
"Cannot go from %s to %s - ignoring request" %
|
|
(BuildRequest.REQUEST_STATE[self.old_state][1],
|
|
BuildRequest.REQUEST_STATE[self.state][1])
|
|
)
|
|
# Set property back to the old value
|
|
self.state = self.old_state
|
|
return
|
|
|
|
super(BuildRequest, self).save(*args, **kwargs)
|
|
|
|
|
|
def get_duration(self):
|
|
return (self.updated - self.created).total_seconds()
|
|
|
|
def get_sorted_target_list(self):
|
|
tgts = self.brtarget_set.order_by( 'target' );
|
|
return( tgts );
|
|
|
|
def get_machine(self):
|
|
return self.brvariable_set.get(name="MACHINE").value
|
|
|
|
def __str__(self):
|
|
return force_text('%s %s' % (self.project, self.get_state_display()))
|
|
|
|
# These tables specify the settings for running an actual build.
|
|
# They MUST be kept in sync with the tables in orm.models.Project*
|
|
|
|
class BRLayer(models.Model):
|
|
req = models.ForeignKey(BuildRequest)
|
|
name = models.CharField(max_length = 100)
|
|
giturl = models.CharField(max_length = 254)
|
|
commit = models.CharField(max_length = 254)
|
|
dirpath = models.CharField(max_length = 254)
|
|
layer_version = models.ForeignKey(Layer_Version, null=True)
|
|
|
|
class BRBitbake(models.Model):
|
|
req = models.OneToOneField(BuildRequest) # only one bitbake for a request
|
|
giturl = models.CharField(max_length =254)
|
|
commit = models.CharField(max_length = 254)
|
|
dirpath = models.CharField(max_length = 254)
|
|
|
|
class BRVariable(models.Model):
|
|
req = models.ForeignKey(BuildRequest)
|
|
name = models.CharField(max_length=100)
|
|
value = models.TextField(blank = True)
|
|
|
|
class BRTarget(models.Model):
|
|
req = models.ForeignKey(BuildRequest)
|
|
target = models.CharField(max_length=100)
|
|
task = models.CharField(max_length=100, null=True)
|
|
|
|
class BRError(models.Model):
|
|
req = models.ForeignKey(BuildRequest)
|
|
errtype = models.CharField(max_length=100)
|
|
errmsg = models.TextField()
|
|
traceback = models.TextField()
|
|
|
|
def __str__(self):
|
|
return "%s (%s)" % (self.errmsg, self.req)
|