From 3c24a9b00e40c5a28060908969ad50bb1189feaa Mon Sep 17 00:00:00 2001 From: Shu Yingya Date: Wed, 8 Mar 2017 19:18:26 +0800 Subject: [PATCH] [APIv2] Refactor job cancel operation Remove endpoint "/jobs/{job_id}/cancel" for cancelling a job. we can request a cancelled state on a PATCH to the new /jobs/{job_id} endpoint to make code more consistency. The request body should be: {"info": {"status": "cancel"}} Change-Id: I4a427d99e533979be42a84d388324ec2f933acc2 Partial-Implements: bp v2-api-experimental-impl --- sahara/api/v2/jobs.py | 11 ----------- sahara/service/api/v2/jobs.py | 14 ++++---------- .../validations/edp/job_execution_schema.py | 2 +- sahara/utils/edp.py | 4 +++- 4 files changed, 8 insertions(+), 23 deletions(-) diff --git a/sahara/api/v2/jobs.py b/sahara/api/v2/jobs.py index 34a2e6c6..8fedc252 100644 --- a/sahara/api/v2/jobs.py +++ b/sahara/api/v2/jobs.py @@ -63,17 +63,6 @@ def jobs_get(job_id): return u.render(result) -@rest.get('/jobs//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/') @acl.enforce("data-processing:job-executions:modify") @v.check_exists(api.get_job_execution, id='job_id') diff --git a/sahara/service/api/v2/jobs.py b/sahara/service/api/v2/jobs.py index b4b58b27..f814fb77 100644 --- a/sahara/service/api/v2/jobs.py +++ b/sahara/service/api/v2/jobs.py @@ -83,24 +83,18 @@ def get_job_execution(id, refresh_status=False): 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): - _update_status(values.pop("info", None)) + _update_status(values.pop("info", None), id) return conductor.job_execution_update(context.ctx(), id, values) -def _update_status(info): +def _update_status(info, id): if info: status = info.get("status", None) if status == edp.JOB_ACTION_SUSPEND: api.OPS.job_execution_suspend(id) + if status == edp.JOB_ACTION_CANCEL: + api.OPS.cancel_job_execution(id) def delete_job_execution(id): diff --git a/sahara/service/validations/edp/job_execution_schema.py b/sahara/service/validations/edp/job_execution_schema.py index c553ab75..03a3e94c 100644 --- a/sahara/service/validations/edp/job_execution_schema.py +++ b/sahara/service/validations/edp/job_execution_schema.py @@ -74,7 +74,7 @@ JOB_EXEC_UPDATE_SCHEMA = { "type": "simple_config", "properties": { "status": { - "enum": ["suspend"] + "enum": ["suspend", "cancel"] } }, "additionalProperties": False diff --git a/sahara/utils/edp.py b/sahara/utils/edp.py index 214c1308..e48201bf 100644 --- a/sahara/utils/edp.py +++ b/sahara/utils/edp.py @@ -89,9 +89,11 @@ JOB_TYPES_ACCEPTABLE_CONFIGS = { # job actions JOB_ACTION_SUSPEND = 'suspend' +JOB_ACTION_CANCEL = 'cancel' JOB_ACTION_TYPES_ACCEPTABLE = [ - JOB_ACTION_SUSPEND + JOB_ACTION_SUSPEND, + JOB_ACTION_CANCEL ] ADAPT_FOR_OOZIE = 'edp.java.adapt_for_oozie'