Skip to content

Commit

Permalink
handle task kill in wrong state as 400 BadRequest instead of 500. (dm…
Browse files Browse the repository at this point in the history
…wm#8897)

* handle task kill in wrong state as 400 BadRequest instead of 500.

* compliant with pylint.

* changed to more generic exception.

---------

Co-authored-by: Krittin Phornsiricharoenphant <[email protected]>
Co-authored-by: Krittin Phornsiricharoenphant <[email protected]>
  • Loading branch information
3 people authored Jan 29, 2025
1 parent 108d5ec commit 5bdfcbf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/python/CRABInterface/DataWorkflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ServerUtilities import getEpochFromDBTime

from CRABInterface.Utilities import CMSSitesCache, conn_handler, getDBinstance

from CRABInterface.RESTExtensions import BadRequestException

class DataWorkflow(object):
"""Entity that allows to operate on workflow resources.
Expand Down Expand Up @@ -406,7 +406,7 @@ def kill(self, workflow, killwarning=''):
self.api.modify(self.Task.SetStatusWarningTask_sql, status=["KILLED"], command=["KILL"],
taskname=[workflow], warnings=[str(warnings)])
else:
raise ExecutionError("You cannot kill a task if it is in the %s status" % row.task_status)
raise BadRequestException()

return [{"result":retmsg}]

Expand Down
11 changes: 9 additions & 2 deletions src/python/CRABInterface/RESTExtensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
and it shouldn't have any other dependencies a part of that and cherrypy.
"""
from WMCore.REST.Error import MissingObject
from WMCore.REST.Error import MissingObject, RESTError

import cherrypy
import traceback
Expand Down Expand Up @@ -52,7 +52,7 @@ def authz_owner_match(dbapi, workflows, Task):
wfrow = next(dbapi.query(None, None, Task.GetUserFromID_sql, taskname = wf))
except Exception as ex:
excauthz = RuntimeError("The document '%s' is not retrievable '%s'" % (wf, str(ex)))
raise MissingObject("The resource requested does not exist", trace=traceback.format_exc(), errobj = excauthz)
raise MissingObject('The resource requested does not exist', trace=traceback.format_exc(), errobj=excauthz) from ex

if wfrow[0] == cherrypy.request.user['login']:
alldocs.append(wfrow)
Expand All @@ -71,3 +71,10 @@ def authz_owner_match(dbapi, workflows, Task):
def authz_login_valid():
if not cherrypy.request.user['login']:
raise cherrypy.HTTPError(403, "You are not allowed to access this resource. Please run: crab checkusername")

class BadRequestException(RESTError):
"User make any kind of invalid request."
http_code = 400
app_code = 40001
message = "This request are invalid."

0 comments on commit 5bdfcbf

Please sign in to comment.