Merge "[APIv2] Refactor job cancel operation"

This commit is contained in:
Jenkins 2017-05-05 13:14:42 +00:00 committed by Gerrit Code Review
commit a1db392af7
4 changed files with 8 additions and 23 deletions

View File

@ -63,17 +63,6 @@ def jobs_get(job_id):
return u.render(result) return u.render(result)
@rest.get('/jobs/<job_id>/cancel')
@acl.enforce("data-processing:job-executions:cancel")
@v.check_exists(api.get_job_execution, id='job_id')
@v.validate(None, v_j_e.check_job_execution_cancel)
def jobs_cancel(job_id):
result = u.to_wrapped_dict_no_render(api.cancel_job_execution, job_id)
result['engine_job_id'] = result['oozie_job_id']
del result['oozie_job_id']
return u.render(result)
@rest.patch('/jobs/<job_id>') @rest.patch('/jobs/<job_id>')
@acl.enforce("data-processing:job-executions:modify") @acl.enforce("data-processing:job-executions:modify")
@v.check_exists(api.get_job_execution, id='job_id') @v.check_exists(api.get_job_execution, id='job_id')

View File

@ -83,24 +83,18 @@ def get_job_execution(id, refresh_status=False):
return conductor.job_execution_get(context.ctx(), id) return conductor.job_execution_get(context.ctx(), id)
def cancel_job_execution(id):
context.set_current_job_execution_id(id)
job_execution = conductor.job_execution_get(context.ctx(), id)
api.OPS.cancel_job_execution(id)
return job_execution
def update_job_execution(id, values): def update_job_execution(id, values):
_update_status(values.pop("info", None)) _update_status(values.pop("info", None), id)
return conductor.job_execution_update(context.ctx(), id, values) return conductor.job_execution_update(context.ctx(), id, values)
def _update_status(info): def _update_status(info, id):
if info: if info:
status = info.get("status", None) status = info.get("status", None)
if status == edp.JOB_ACTION_SUSPEND: if status == edp.JOB_ACTION_SUSPEND:
api.OPS.job_execution_suspend(id) api.OPS.job_execution_suspend(id)
if status == edp.JOB_ACTION_CANCEL:
api.OPS.cancel_job_execution(id)
def delete_job_execution(id): def delete_job_execution(id):

View File

@ -74,7 +74,7 @@ JOB_EXEC_UPDATE_SCHEMA = {
"type": "simple_config", "type": "simple_config",
"properties": { "properties": {
"status": { "status": {
"enum": ["suspend"] "enum": ["suspend", "cancel"]
} }
}, },
"additionalProperties": False "additionalProperties": False

View File

@ -89,9 +89,11 @@ JOB_TYPES_ACCEPTABLE_CONFIGS = {
# job actions # job actions
JOB_ACTION_SUSPEND = 'suspend' JOB_ACTION_SUSPEND = 'suspend'
JOB_ACTION_CANCEL = 'cancel'
JOB_ACTION_TYPES_ACCEPTABLE = [ JOB_ACTION_TYPES_ACCEPTABLE = [
JOB_ACTION_SUSPEND JOB_ACTION_SUSPEND,
JOB_ACTION_CANCEL
] ]
ADAPT_FOR_OOZIE = 'edp.java.adapt_for_oozie' ADAPT_FOR_OOZIE = 'edp.java.adapt_for_oozie'