summaryrefslogtreecommitdiffstats
path: root/bitbake/lib
diff options
context:
space:
mode:
authorMichael Wood <michael.g.wood@intel.com>2016-04-06 17:46:31 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-04-06 23:10:29 +0100
commitafab95c649c6e478f462a32e3d9831cb9007b0e4 (patch)
treec61f13e42d9f28d70cf583d7110f8698b57af41b /bitbake/lib
parenteead032aca1592de9a764b530f9c436ff57cee21 (diff)
downloadpoky-afab95c649c6e478f462a32e3d9831cb9007b0e4.tar.gz
bitbake: toaster: xhr Update the implementation of the build cancellation request
Update the implementation of the backend api for cancelling builds with the new cancelling BuildRequest state and cancelled Build state. Also added some docstring about general usage. Co-Author: Sujith H <sujith.h@gmail.com> (Bitbake rev: 0d76084f5d896e4199e1446e2d6d43190a4fcc3a) Signed-off-by: Michael Wood <michael.g.wood@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r--bitbake/lib/toaster/toastergui/api.py54
1 files changed, 45 insertions, 9 deletions
diff --git a/bitbake/lib/toaster/toastergui/api.py b/bitbake/lib/toaster/toastergui/api.py
index 1b1f59813f..42901f750a 100644
--- a/bitbake/lib/toaster/toastergui/api.py
+++ b/bitbake/lib/toaster/toastergui/api.py
@@ -19,7 +19,7 @@
19 19
20# Temporary home for the UI's misc API 20# Temporary home for the UI's misc API
21 21
22from orm.models import Project, ProjectTarget 22from orm.models import Project, ProjectTarget, Build
23from bldcontrol.models import BuildRequest 23from bldcontrol.models import BuildRequest
24from bldcontrol import bbcontroller 24from bldcontrol import bbcontroller
25from django.http import HttpResponse, JsonResponse 25from django.http import HttpResponse, JsonResponse
@@ -32,18 +32,54 @@ class XhrBuildRequest(View):
32 return HttpResponse() 32 return HttpResponse()
33 33
34 def post(self, request, *args, **kwargs): 34 def post(self, request, *args, **kwargs):
35 """ Process HTTP POSTs which make build requests """ 35 """
36 Build control
37
38 Entry point: /xhr_buildrequest/<project_id>
39 Method: POST
40
41 Args:
42 id: id of build to change
43 buildCancel = build_request_id ...
44 buildDelete = id ...
45 targets = recipe_name ...
46
47 Returns:
48 {"error": "ok"}
49 or
50 {"error": <error message>}
51 """
36 52
37 project = Project.objects.get(pk=kwargs['pid']) 53 project = Project.objects.get(pk=kwargs['pid'])
38 54
39 if 'buildCancel' in request.POST: 55 if 'buildCancel' in request.POST:
40 for i in request.POST['buildCancel'].strip().split(" "): 56 for i in request.POST['buildCancel'].strip().split(" "):
41 try: 57 try:
42 br = BuildRequest.objects.select_for_update().get(project = project, pk = i, state__lte = BuildRequest.REQ_QUEUED) 58 br = BuildRequest.objects.get(project=project, pk=i)
43 br.state = BuildRequest.REQ_DELETED 59
60 try:
61 bbctrl = bbcontroller.BitbakeController(br.environment)
62 bbctrl.forceShutDown()
63 except:
64 # We catch a bunch of exceptions here because
65 # this is where the server has not had time to start up
66 # and the build request or build is in transit between
67 # processes.
68 # We can safely just set the build as cancelled
69 # already as it never got started
70 build = br.build
71 build.outcome = Build.CANCELLED
72 build.save()
73
74 # We now hand over to the buildinfohelper to update the
75 # build state once we've finished cancelling
76 br.state = BuildRequest.REQ_CANCELLING
44 br.save() 77 br.save()
78
45 except BuildRequest.DoesNotExist: 79 except BuildRequest.DoesNotExist:
46 pass 80 return JsonResponse({'error':'No such build id %s' % i})
81
82 return JsonResponse({'error': 'ok'})
47 83
48 if 'buildDelete' in request.POST: 84 if 'buildDelete' in request.POST:
49 for i in request.POST['buildDelete'].strip().split(" "): 85 for i in request.POST['buildDelete'].strip().split(" "):
@@ -51,6 +87,7 @@ class XhrBuildRequest(View):
51 BuildRequest.objects.select_for_update().get(project = project, pk = i, state__lte = BuildRequest.REQ_DELETED).delete() 87 BuildRequest.objects.select_for_update().get(project = project, pk = i, state__lte = BuildRequest.REQ_DELETED).delete()
52 except BuildRequest.DoesNotExist: 88 except BuildRequest.DoesNotExist:
53 pass 89 pass
90 return JsonResponse({'error': 'ok' })
54 91
55 if 'targets' in request.POST: 92 if 'targets' in request.POST:
56 ProjectTarget.objects.filter(project = project).delete() 93 ProjectTarget.objects.filter(project = project).delete()
@@ -66,9 +103,8 @@ class XhrBuildRequest(View):
66 task = task) 103 task = task)
67 project.schedule_build() 104 project.schedule_build()
68 105
69 # redirect back to builds page so any new builds in progress etc. 106 return JsonResponse({'error': 'ok' })
70 # are visible 107
71 response = HttpResponse() 108 response = HttpResponse()
72 response.status_code = 302 109 response.status_code = 500
73 response['Location'] = request.build_absolute_uri()
74 return response 110 return response