]> git.ipfire.org Git - people/jschlag/pbs.git/blob - src/web/jobs.py
defdefbaf5f2ec22a3766485b2509d5e0e1d7047
[people/jschlag/pbs.git] / src / web / jobs.py
1 #!/usr/bin/python
2
3 import tornado.web
4
5 from . import base
6
7 class ShowQueueHandler(base.BaseHandler):
8 def get(self, arch=None):
9 if arch:
10 if not self.backend.arches.exists(arch):
11 raise tornado.web.HTTPError(400, "Architecture does not exist")
12
13 queue = self.backend.jobqueue.for_arches([arch, "noarch"])
14 else:
15 queue = self.backend.jobqueue
16
17 self.render("queue.html", arch=arch, queue=queue)
18
19
20 class JobDetailHandler(base.BaseHandler):
21 def get(self, uuid):
22 job = self.backend.jobs.get_by_uuid(uuid)
23 if not job:
24 raise tornado.web.HTTPError(404, "No such job: %s" % job)
25
26 # Cache the log.
27 log = job.get_log()
28
29 self.render("jobs-detail.html", job=job, build=job.build, log=log)
30
31
32 class JobBuildrootHandler(base.BaseHandler):
33 def get(self, uuid):
34 job = self.backend.jobs.get_by_uuid(uuid)
35 if not job:
36 raise tornado.web.HTTPError(404, "Job not found: %s" % uuid)
37
38 # Calculate the download size and buildroot size.
39 download_size = 0
40 buildroot_size = 0
41
42 for name, uuid, pkg in job.buildroot:
43 if not pkg:
44 continue
45
46 download_size += pkg.filesize
47 buildroot_size += pkg.size
48
49 self.render("jobs-buildroot.html", job=job, build=job.build,
50 buildroot=job.buildroot, download_size=download_size,
51 buildroot_size=buildroot_size)
52
53
54 class JobScheduleHandler(base.BaseHandler):
55 allowed_types = ("test", "rebuild",)
56
57 @tornado.web.authenticated
58 def get(self, uuid):
59 type = self.get_argument("type")
60 assert type in self.allowed_types
61
62 job = self.backend.jobs.get_by_uuid(uuid)
63 if not job:
64 raise tornado.web.HTTPError(404, "Job not found: %s" % uuid)
65
66 self.render("job-schedule-%s.html" % type, type=type, job=job, build=job.build)
67
68 @tornado.web.authenticated
69 def post(self, uuid):
70 type = self.get_argument("type")
71 assert type in self.allowed_types
72
73 job = self.backend.jobs.get_by_uuid(uuid)
74 if not job:
75 raise tornado.web.HTTPError(404, "Job not found: %s" % uuid)
76
77 # Get the start offset.
78 offset = self.get_argument("offset", 0)
79 try:
80 offset = int(offset)
81 except TypeError:
82 offset = 0
83
84 # Submit the build.
85 if type == "test":
86 job = job.schedule_test(offset)
87
88 elif type == "rebuild":
89 job.schedule_rebuild(offset)
90
91 self.redirect("/job/%s" % job.uuid)
92
93
94 class JobAbortHandler(base.BaseHandler):
95 def get_job(self, uuid):
96 job = self.backend.jobs.get_by_uuid(uuid)
97 if not job:
98 raise tornado.web.HTTPError(404, "Job not found: %s" % uuid)
99
100 return job
101
102 @tornado.web.authenticated
103 def get(self, uuid):
104 job = self.get_job(uuid)
105
106 # XXX Check if user has the right to manage the job.
107
108 self.render("jobs-abort.html", job=job)
109
110 @tornado.web.authenticated
111 def post(self, uuid):
112 job = self.get_job(uuid)
113
114 # XXX Check if user has the right to manage the job.
115
116 # Only running builds can be set to aborted state.
117 if not job.state == "running":
118 # XXX send the user a nicer error message.
119 self.redirect("/job/%s" % job.uuid)
120 return
121
122 # Set the job into aborted state.
123 job.state = "aborted"
124
125 # 0 means the job was aborted by the user.
126 job.aborted_state = 0
127
128 self.redirect("/job/%s" % job.uuid)