diff options
author | maopeng zhang <zhang.maopeng1@zte.com.cn> | 2019-07-10 03:38:59 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-07-10 03:38:59 +0000 |
commit | bc7bd1eb46a3d1e7bb70b0faaac728ab7f9d4f62 (patch) | |
tree | 0f248eb65ffe1e6174f2c95b2c4f2036913d33ec | |
parent | e1966fa785bc082053c66d0f84ba6c44ead35156 (diff) | |
parent | 49736a7643e8d338116619f53bebb2906540f5c9 (diff) |
Merge "Refactor codes for term ns"
-rw-r--r-- | lcm/ns/views/deprecated/term_ns_view.py | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/lcm/ns/views/deprecated/term_ns_view.py b/lcm/ns/views/deprecated/term_ns_view.py index 652b8db0..dd6e98a3 100644 --- a/lcm/ns/views/deprecated/term_ns_view.py +++ b/lcm/ns/views/deprecated/term_ns_view.py @@ -25,6 +25,7 @@ from lcm.pub.utils.jobutil import JobUtil from lcm.jobs.enum import JOB_TYPE, JOB_ACTION from lcm.ns.serializers.deprecated.ns_serializers import _TerminateNsReqSerializer from lcm.ns.serializers.deprecated.ns_serializers import _NsOperateJobSerializer +from .common import view_safe_call_with_log logger = logging.getLogger(__name__) @@ -38,23 +39,19 @@ class NSTerminateView(APIView): status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error" } ) + @view_safe_call_with_log(logger=logger) def post(self, request, ns_instance_id): - try: - logger.debug("Enter TerminateNSView::post %s", request.data) - req_serializer = _TerminateNsReqSerializer(data=request.data) - if not req_serializer.is_valid(): - raise BadRequestException(req_serializer.errors) - - job_id = JobUtil.create_job(JOB_TYPE.NS, JOB_ACTION.TERMINATE, ns_instance_id) - TerminateNsService(ns_instance_id, job_id, request.data).start() - - resp_serializer = _NsOperateJobSerializer(data={'jobId': job_id}) - if not resp_serializer.is_valid(): - raise NSLCMException(resp_serializer.errors) - logger.debug("Leave TerminateNSView::post ret=%s", resp_serializer.data) - return Response(data=resp_serializer.data, status=status.HTTP_202_ACCEPTED) - except BadRequestException as e: - return Response(data={'error': e.args[0]}, status=status.HTTP_400_BAD_REQUEST) - except Exception as e: - logger.error("Exception in CreateNS: %s", e.args[0]) - return Response(data={'error': e.args[0]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + logger.debug("Enter TerminateNSView::post %s", request.data) + req_serializer = _TerminateNsReqSerializer(data=request.data) + if not req_serializer.is_valid(): + raise BadRequestException(req_serializer.errors) + + job_id = JobUtil.create_job(JOB_TYPE.NS, JOB_ACTION.TERMINATE, ns_instance_id) + TerminateNsService(ns_instance_id, job_id, request.data).start() + + resp_serializer = _NsOperateJobSerializer(data={'jobId': job_id}) + if not resp_serializer.is_valid(): + raise NSLCMException(resp_serializer.errors) + + logger.debug("Leave TerminateNSView::post ret=%s", resp_serializer.data) + return Response(data=resp_serializer.data, status=status.HTTP_202_ACCEPTED) |