Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id CD9F6E00C3C; Mon, 22 Feb 2016 03:31:22 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily * valid * -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature * -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low * trust * [209.85.192.176 listed in list.dnswl.org] Received: from mail-pf0-f176.google.com (mail-pf0-f176.google.com [209.85.192.176]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id BB7A4E00C31 for ; Mon, 22 Feb 2016 03:31:21 -0800 (PST) Received: by mail-pf0-f176.google.com with SMTP id x65so91516401pfb.1 for ; Mon, 22 Feb 2016 03:31:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ri5dU9Ruxhyq37lSIeJjTYagdB+EOFXIAFkwxat/vsk=; b=kr5aOUEPcoZLZCuGO3k4Xk702qUY0k3GJ4Qi/Y3D5wm1Qn50bvq8FO9HwnJ0KpcrnA XxAM9sliOhAFNb9MSi7Nm69qDLb2B5Rv4VcwrAvjX1lB/a1oQMGjm9qS5MgmUO0y/fgW Ua8HZT8ey2eE7VrBzgSntpB0oGMI0nlQ4rR4/GtZiL2aPKZHSifdlc20nYYsbfCtsjEi Wg1X/c2UQlfzWCoVw2XO/naW+ZTlP22fNpYe0qwAKuWEfxv0ClqE3zfhQbuYryDbbrjG GZnNh8vSVd1lBNZssR9EMU0UC0eabLyAsWa7pudxWrCz9ctPG4KhUw2UQlZ5X935KzoQ 3vhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ri5dU9Ruxhyq37lSIeJjTYagdB+EOFXIAFkwxat/vsk=; b=STKLUZHu4gcbqE2hR6Fd5TVQHAoxUSG4Wi09kW4CYvJ5e1pCXPXgcsrluPiXyOAUBU NqldfWCSfzVTUZO88IC93ra4XbfZv/jgyRGx0hvRudhPGtNlFcOIparDNYKSPtRMNM7U iILwUjFqkbtCYXZA49gZGrRKshtL9A/MDKgeuNf4Aa8L9dLKAgWbSveCtMZzBekpBz7H E1Xg0HlwFMxhXP0jmqYp6nePPrL4CTsdiXWFqsHtxUaAvDgzNlXGy1Cx5ccmpu7CYmu7 Xl0WLdZwlDkjv6T/2GNIZ6ghStQxHc7smXJQoSRSqKGfBX+mKCbIgnZAXMKbq244+SZt PGVw== X-Gm-Message-State: AG10YOTUmgn2C+TKioS0pVG6DOYoIMqymgwRsHrIW9i0gz+TJrH3XpfQNCz3wQdCiY0GdkLb X-Received: by 10.98.17.129 with SMTP id 1mr37381706pfr.30.1456140680983; Mon, 22 Feb 2016 03:31:20 -0800 (PST) Received: from dorado.ger.corp.intel.com (fmdmzpr01-ext.fm.intel.com. [192.55.54.36]) by smtp.gmail.com with ESMTPSA id n78sm36216801pfb.53.2016.02.22.03.31.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Feb 2016 03:31:20 -0800 (PST) From: Michael Wood To: toaster@yoctoproject.org Date: Mon, 22 Feb 2016 11:30:59 +0000 Message-Id: <1456140666-5344-4-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456140666-5344-1-git-send-email-michael.g.wood@intel.com> References: <1456140666-5344-1-git-send-email-michael.g.wood@intel.com> Subject: [PATCH 03/10] toaster: xhr Update the implementation of the build cancellation request X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Feb 2016 11:31:22 -0000 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 Signed-off-by: Michael Wood --- bitbake/lib/toaster/toastergui/api.py | 53 +++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/bitbake/lib/toaster/toastergui/api.py b/bitbake/lib/toaster/toastergui/api.py index 1b1f598..a1e0bc8 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,53 @@ class XhrBuildRequest(View): return HttpResponse() def post(self, request, *args, **kwargs): - """ Process HTTP POSTs which make build requests """ + """ + Build control + + Entry point: /xhr_buildrequest/ + Method: POST + + Args: + id: id of build to change + buildCancel = build_request_id ... + buildDelete = id ... + targets = recipe_name ... + + Returns: + {"error": "ok"} + or + {"error": } + """ 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) + + # We now hand over to the buildinfohelper to update the + # build state once we've finished cancelling + br.state = BuildRequest.REQ_CANCELLING br.save() + + 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 + br.build.outcome = Build.CANCELLED + br.build.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 +86,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 +102,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 -- 2.5.0