blob: ab411053035e9d1f78f28f88ab6291b72af0be86 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001from django.db import models
2from django.core.validators import MaxValueValidator, MinValueValidator
Patrick Williamsf1e5d692016-03-30 15:21:19 -05003from orm.models import Project, ProjectLayer, ProjectVariable, ProjectTarget, Build, Layer_Version
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004
5# a BuildEnvironment is the equivalent of the "build/" directory on the localhost
6class BuildEnvironment(models.Model):
7 SERVER_STOPPED = 0
8 SERVER_STARTED = 1
9 SERVER_STATE = (
10 (SERVER_STOPPED, "stopped"),
11 (SERVER_STARTED, "started"),
12 )
13
14 TYPE_LOCAL = 0
15 TYPE_SSH = 1
16 TYPE = (
17 (TYPE_LOCAL, "local"),
18 (TYPE_SSH, "ssh"),
19 )
20
21 LOCK_FREE = 0
22 LOCK_LOCK = 1
23 LOCK_RUNNING = 2
24 LOCK_STATE = (
25 (LOCK_FREE, "free"),
26 (LOCK_LOCK, "lock"),
27 (LOCK_RUNNING, "running"),
28 )
29
30 address = models.CharField(max_length = 254)
31 betype = models.IntegerField(choices = TYPE)
32 bbaddress = models.CharField(max_length = 254, blank = True)
33 bbport = models.IntegerField(default = -1)
34 bbtoken = models.CharField(max_length = 126, blank = True)
35 bbstate = models.IntegerField(choices = SERVER_STATE, default = SERVER_STOPPED)
36 sourcedir = models.CharField(max_length = 512, blank = True)
37 builddir = models.CharField(max_length = 512, blank = True)
38 lock = models.IntegerField(choices = LOCK_STATE, default = LOCK_FREE)
39 created = models.DateTimeField(auto_now_add = True)
40 updated = models.DateTimeField(auto_now = True)
41
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042 def get_artifact(self, path):
43 if self.betype == BuildEnvironment.TYPE_LOCAL:
44 return open(path, "r")
45 raise Exception("FIXME: artifact download not implemented for build environment type %s" % self.get_betype_display())
46
47 def has_artifact(self, path):
48 import os
49 if self.betype == BuildEnvironment.TYPE_LOCAL:
50 return os.path.exists(path)
51 raise Exception("FIXME: has artifact not implemented for build environment type %s" % self.get_betype_display())
52
53# a BuildRequest is a request that the scheduler will build using a BuildEnvironment
54# the build request queue is the table itself, ordered by state
55
56class BuildRequest(models.Model):
57 REQ_CREATED = 0
58 REQ_QUEUED = 1
59 REQ_INPROGRESS = 2
60 REQ_COMPLETED = 3
61 REQ_FAILED = 4
62 REQ_DELETED = 5
63 REQ_ARCHIVE = 6
64
65 REQUEST_STATE = (
66 (REQ_CREATED, "created"),
67 (REQ_QUEUED, "queued"),
68 (REQ_INPROGRESS, "in progress"),
69 (REQ_COMPLETED, "completed"),
70 (REQ_FAILED, "failed"),
71 (REQ_DELETED, "deleted"),
72 (REQ_ARCHIVE, "archive"),
73 )
74
75 search_allowed_fields = ("brtarget__target", "build__project__name")
76
77 project = models.ForeignKey(Project)
78 build = models.OneToOneField(Build, null = True) # TODO: toasterui should set this when Build is created
79 environment = models.ForeignKey(BuildEnvironment, null = True)
80 state = models.IntegerField(choices = REQUEST_STATE, default = REQ_CREATED)
81 created = models.DateTimeField(auto_now_add = True)
82 updated = models.DateTimeField(auto_now = True)
83
84 def get_duration(self):
85 return (self.updated - self.created).total_seconds()
86
87 def get_sorted_target_list(self):
88 tgts = self.brtarget_set.order_by( 'target' );
89 return( tgts );
90
91 def get_machine(self):
92 return self.brvariable_set.get(name="MACHINE").value
93
94 def __str__(self):
95 return "%s %s" % (self.project, self.get_state_display())
96
97# These tables specify the settings for running an actual build.
98# They MUST be kept in sync with the tables in orm.models.Project*
99
100class BRLayer(models.Model):
101 req = models.ForeignKey(BuildRequest)
102 name = models.CharField(max_length = 100)
103 giturl = models.CharField(max_length = 254)
104 commit = models.CharField(max_length = 254)
105 dirpath = models.CharField(max_length = 254)
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500106 layer_version = models.ForeignKey(Layer_Version, null=True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500107
108class BRBitbake(models.Model):
109 req = models.ForeignKey(BuildRequest, unique = True) # only one bitbake for a request
110 giturl = models.CharField(max_length =254)
111 commit = models.CharField(max_length = 254)
112 dirpath = models.CharField(max_length = 254)
113
114class BRVariable(models.Model):
115 req = models.ForeignKey(BuildRequest)
116 name = models.CharField(max_length=100)
117 value = models.TextField(blank = True)
118
119class BRTarget(models.Model):
120 req = models.ForeignKey(BuildRequest)
121 target = models.CharField(max_length=100)
122 task = models.CharField(max_length=100, null=True)
123
124class BRError(models.Model):
125 req = models.ForeignKey(BuildRequest)
126 errtype = models.CharField(max_length=100)
127 errmsg = models.TextField()
128 traceback = models.TextField()
129
130 def __str__(self):
131 return "%s (%s)" % (self.errmsg, self.req)