Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id D286FE00CFA; Thu, 25 Feb 2016 10:21:34 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID 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_VALID Message has at least one valid DKIM or DK signature * 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily * valid Received: from mail-wm0-f45.google.com (mail-wm0-f45.google.com [74.125.82.45]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id EC707E00CFF for ; Thu, 25 Feb 2016 10:21:33 -0800 (PST) Received: by mail-wm0-f45.google.com with SMTP id a4so39637313wme.1 for ; Thu, 25 Feb 2016 10:21:33 -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=RVuGFygtI6kS3nA/w2SZxt7fg7FI+wk5vEWljs8YezQ=; b=lOExkqhEMfxvcUVAhT6EXGR0+gjz89xY1Rp2Snom8inzFhOO21W3eRkL6QmScVOims 64MTcT6v79TKtbcflK7ZaOsgR8thQbX+TAWAbDEvyh0Xu6pkk7CnzsPu6vEVDhVr7Oqa 7Vn7LZCvULg0p9I5vRIyg+19p+YG6ERJRfp151jkIS0OcfFS3TGUml2sBrpDbQfxJM7b EYSDiUjU1tSpNN+NwXyzAjC7pKBgka5jHsMnlSKfJvY/NSLNb6OMbg29N9P2xuGYSGU6 UHk9BEFc73ke/XJ6URzFmR8hQn52iTeE2RcszwGBqHkRZv1+WivMrw4pKPfeULZCj3JD dSYw== 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=RVuGFygtI6kS3nA/w2SZxt7fg7FI+wk5vEWljs8YezQ=; b=lI71szIwn9A4lXLzJJT5nj6U+KyiKyPxVR35+EHvhnDwSw+IpE+rGRCag4R6grlfnJ Gkb6XcPTYSoTFjCWd8g7fAyPk2MDPWz2E5ZAO4urKRVLtAziFX8FKbnJVA2mK5JLdhYS 2OdZ6V80jS9cjEQBNnfzh2K/+yBR1pk8COMv2WhDybpRqkPO4F3jp1gmYTm5PyR6Y39v Dd9liheeCa/lHGpCdmyTRxsnDQ4sa/GcgmwyEu8cq2tPd0DYobbQvot+h5gCUenotTZC M1VdgNHoBubMtstKl5HW8huYALG7rFT10f4rGoRp7/+lmmS25WHD5vE9CWt3vCPlHYsw GxAg== X-Gm-Message-State: AG10YORKvNzjyXQnWFj55DKPFYFQOgXe/D+n8Zc3emerIfW2zjEf1wkd+N1kOXK1Kb4W7Daf X-Received: by 10.28.211.1 with SMTP id k1mr29054wmg.93.1456424492460; Thu, 25 Feb 2016 10:21:32 -0800 (PST) Received: from draco.icx.intel.com ([83.217.123.106]) by smtp.gmail.com with ESMTPSA id az8sm3084010wjc.17.2016.02.25.10.21.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Feb 2016 10:21:31 -0800 (PST) From: Michael Wood To: toaster@yoctoproject.org Date: Thu, 25 Feb 2016 18:21:17 +0000 Message-Id: <1456424485-6566-4-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1456424485-6566-1-git-send-email-michael.g.wood@intel.com> References: <1456424485-6566-1-git-send-email-michael.g.wood@intel.com> Subject: [PATCH 03/11] 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: Thu, 25 Feb 2016 18:21:34 -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 | 54 +++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/bitbake/lib/toaster/toastergui/api.py b/bitbake/lib/toaster/toastergui/api.py index 1b1f598..42901f75 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/ + 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) + + 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 -- 2.1.4