aboutsummaryrefslogtreecommitdiffstats
path: root/bitbake
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
parenteead032aca1592de9a764b530f9c436ff57cee21 (diff)
downloadopenembedded-core-contrib-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')
-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 @@
# Temporary home for the UI's misc API
-from orm.models import Project, ProjectTarget
+from orm.models import Project, ProjectTarget, Build
from bldcontrol.models import BuildRequest
from bldcontrol import bbcontroller
from django.http import HttpResponse, JsonResponse
@@ -32,18 +32,54 @@ class XhrBuildRequest(View):
return HttpResponse()
def post(self, request, *args, **kwargs):
- """ Process HTTP POSTs which make build requests """
+ """
+ Build control
+
+ Entry point: /xhr_buildrequest/<project_id>
+ Method: POST
+
+ Args:
+ id: id of build to change
+ buildCancel = build_request_id ...
+ buildDelete = id ...
+ targets = recipe_name ...
+
+ Returns:
+ {"error": "ok"}
+ or
+ {"error": <error message>}
+ """
project = Project.objects.get(pk=kwargs['pid'])
if 'buildCancel' in request.POST:
for i in request.POST['buildCancel'].strip().split(" "):
try:
- br = BuildRequest.objects.select_for_update().get(project = project, pk = i, state__lte = BuildRequest.REQ_QUEUED)
- br.state = BuildRequest.REQ_DELETED
+ br = BuildRequest.objects.get(project=project, pk=i)
+
+ try:
+ bbctrl = bbcontroller.BitbakeController(br.environment)
+ bbctrl.forceShutDown()
+ except:
+ # We catch a bunch of exceptions here because
+ # this is where the server has not had time to start up
+ # and the build request or build is in transit between
+ # processes.
+ # We can safely just set the build as cancelled
+ # already as it never got started
+ build = br.build
+ build.outcome = Build.CANCELLED
+ build.save()
+
+ # We now hand over to the buildinfohelper to update the
+ # build state once we've finished cancelling
+ br.state = BuildRequest.REQ_CANCELLING
br.save()
+
except BuildRequest.DoesNotExist:
- pass
+ return JsonResponse({'error':'No such build id %s' % i})
+
+ return JsonResponse({'error': 'ok'})
if 'buildDelete' in request.POST:
for i in request.POST['buildDelete'].strip().split(" "):
@@ -51,6 +87,7 @@ class XhrBuildRequest(View):
BuildRequest.objects.select_for_update().get(project = project, pk = i, state__lte = BuildRequest.REQ_DELETED).delete()
except BuildRequest.DoesNotExist:
pass
+ return JsonResponse({'error': 'ok' })
if 'targets' in request.POST:
ProjectTarget.objects.filter(project = project).delete()
@@ -66,9 +103,8 @@ class XhrBuildRequest(View):
task = task)
project.schedule_build()
- # redirect back to builds page so any new builds in progress etc.
- # are visible
+ return JsonResponse({'error': 'ok' })
+
response = HttpResponse()
- response.status_code = 302
- response['Location'] = request.build_absolute_uri()
+ response.status_code = 500
return response