aboutsummaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorchenjiankun <chenjiankun1@huawei.com>2017-07-19 08:15:31 +0000
committerchenjiankun <chenjiankun1@huawei.com>2017-07-19 08:15:31 +0000
commitf4b282d740f3774b7005b5713884b3c404597548 (patch)
tree0a6f92c9c7630277533308b87057fedee4ba0302 /api
parent6bc4d2c813460cba201c390cc2380fb99bdc2c9d (diff)
Add API(v2) to delete certain project
JIRA: YARDSTICK-734 API: /api/v2/yardstick/projects/<project_id> METHOD: DELETE Change-Id: I6628ec42aa7c4c6ab073ddc33c119ea1c03b81fe Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'api')
-rw-r--r--api/resources/v2/projects.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/api/resources/v2/projects.py b/api/resources/v2/projects.py
index 7d51cf040..376cf1a37 100644
--- a/api/resources/v2/projects.py
+++ b/api/resources/v2/projects.py
@@ -1,13 +1,18 @@
import uuid
+import logging
from datetime import datetime
from api import ApiResource
from api.database.v2.handlers import V2ProjectHandler
+from api.database.v2.handlers import V2TaskHandler
from yardstick.common.utils import result_handler
from yardstick.common.utils import change_obj_to_dict
from yardstick.common import constants as consts
+LOG = logging.getLogger(__name__)
+LOG.setLevel(logging.DEBUG)
+
class V2Projects(ApiResource):
@@ -63,3 +68,30 @@ class V2Project(ApiResource):
project_info['tasks'] = tasks.split(',') if tasks else []
return result_handler(consts.API_SUCCESS, {'project': project_info})
+
+ def delete(self, project_id):
+ try:
+ uuid.UUID(project_id)
+ except ValueError:
+ return result_handler(consts.API_ERROR, 'invalid project id')
+
+ project_handler = V2ProjectHandler()
+ try:
+ project = project_handler.get_by_uuid(project_id)
+ except ValueError:
+ return result_handler(consts.API_ERROR, 'no such project id')
+
+ if project.tasks:
+ LOG.info('delete related task')
+ task_handler = V2TaskHandler()
+ for task_id in project.tasks.split(','):
+ LOG.debug('delete task: %s', task_id)
+ try:
+ task_handler.delete_by_uuid(task_id)
+ except ValueError:
+ LOG.exception('no such task id: %s', task_id)
+
+ LOG.info('delete project in database')
+ project_handler.delete_by_uuid(project_id)
+
+ return result_handler(consts.API_SUCCESS, {'project': project_id})