summaryrefslogtreecommitdiffstats
path: root/api/resources
diff options
context:
space:
mode:
authorJing Lu <lvjing5@huawei.com>2017-07-21 01:10:35 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-07-21 01:10:35 +0000
commit134f17488b8d0038999a1395c55992a41abae226 (patch)
tree25b022b88c7bb615a16b1a5acabb18c1b19754a4 /api/resources
parent1cff540d812ace29fa45bc789ad3a329435aa3ba (diff)
parenta0b4e917f6f86945341825fe630ba532061992fa (diff)
Merge "Add API(v2) to delete certain task"
Diffstat (limited to 'api/resources')
-rw-r--r--api/resources/v2/tasks.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/api/resources/v2/tasks.py b/api/resources/v2/tasks.py
index 7cc4f5d14..2c4ff2c00 100644
--- a/api/resources/v2/tasks.py
+++ b/api/resources/v2/tasks.py
@@ -73,6 +73,35 @@ class V2Task(ApiResource):
return result_handler(consts.API_SUCCESS, {'task': task_info})
+ def delete(self, task_id):
+ try:
+ uuid.UUID(task_id)
+ except ValueError:
+ return result_handler(consts.API_ERROR, 'invalid task id')
+
+ task_handler = V2TaskHandler()
+ try:
+ project_id = task_handler.get_by_uuid(task_id).project_id
+ except ValueError:
+ return result_handler(consts.API_ERROR, 'no such task id')
+
+ LOG.info('delete task in database')
+ task_handler.delete_by_uuid(task_id)
+
+ project_handler = V2ProjectHandler()
+ project = project_handler.get_by_uuid(project_id)
+
+ if project.tasks:
+ LOG.info('update tasks in project')
+ new_task_list = project.tasks.split(',').remove(task_id)
+ if new_task_list:
+ new_tasks = ','.join(new_task_list)
+ else:
+ new_tasks = None
+ project_handler.update_attr(project_id, {'tasks': new_tasks})
+
+ return result_handler(consts.API_SUCCESS, {'task': task_id})
+
def put(self, task_id):
try: