summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryunlong ying <ying.yunlong@zte.com.cn>2019-04-10 07:46:31 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-10 07:46:31 +0000
commit9f2cc06710ff6f44bcbfe5b1307ee33ec2a8ffd1 (patch)
tree639d8093a21f3fa3212a2bf16c8a4be8adc4551f
parentb8dea42f46e3e866147e652a4bbd2ff5e2f96e1a (diff)
parent386265ebea0d684192de5af5cc8ec22c36ef93a3 (diff)
Merge "Refactor codes for terminate ns"
-rw-r--r--lcm/ns/views/sol/terminate_ns_view.py44
1 files changed, 18 insertions, 26 deletions
diff --git a/lcm/ns/views/sol/terminate_ns_view.py b/lcm/ns/views/sol/terminate_ns_view.py
index 438ca619..af07dbd3 100644
--- a/lcm/ns/views/sol/terminate_ns_view.py
+++ b/lcm/ns/views/sol/terminate_ns_view.py
@@ -26,6 +26,7 @@ from lcm.ns.serializers.sol.terminate_ns_serializers import TerminateNsReqSerial
from lcm.pub.exceptions import BadRequestException
from lcm.ns.const import NS_OCC_BASE_URI
from lcm.ns.serializers.sol.pub_serializers import ProblemDetailsSerializer
+from .common import view_safe_call_with_log
logger = logging.getLogger(__name__)
@@ -39,31 +40,22 @@ class TerminateNsView(APIView):
status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
}
)
+ @view_safe_call_with_log(logger=logger)
def post(self, request, ns_instance_id):
job_id = JobUtil.create_job("NS", JOB_TYPE.TERMINATE_NS, ns_instance_id)
- try:
- logger.debug("Enter TerminateNSView::post %s", request.data)
- req_serializer = TerminateNsReqSerializer(data=request.data)
- if not req_serializer.is_valid():
- logger.debug("request.data is not valid,error: %s" % req_serializer.errors)
- raise BadRequestException(req_serializer.errors)
- terminationTime = ignore_case_get(request.data, 'terminationTime')
- logger.debug("terminationTime is %s" % terminationTime)
- # todo terminationTime
- terminateNsService = TerminateNsService(ns_instance_id, job_id, request.data)
- terminateNsService.start()
- logger.debug("Location: %s" % terminateNsService.occ_id)
- response = Response(data={}, status=status.HTTP_202_ACCEPTED)
- response["Location"] = NS_OCC_BASE_URI % terminateNsService.occ_id
- logger.debug("Leave TerminateNSView")
- return response
- except BadRequestException as e:
- logger.error("Exception in TerminateNsView: %s", e.message)
- JobUtil.add_job_status(job_id, 255, 'NS termination failed: %s' % e.message)
- data = {'status': status.HTTP_400_BAD_REQUEST, 'detail': e.message}
- return Response(data=data, status=status.HTTP_400_BAD_REQUEST)
- except Exception as e:
- logger.error("Exception in TerminateNsView: %s", e.message)
- JobUtil.add_job_status(job_id, 255, 'NS termination failed: %s' % e.message)
- data = {'status': status.HTTP_400_BAD_REQUEST, 'detail': e.message}
- return Response(data=data, 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():
+ logger.debug("request.data is not valid,error: %s" % req_serializer.errors)
+ raise BadRequestException(req_serializer.errors)
+ terminationTime = ignore_case_get(request.data, 'terminationTime')
+ logger.debug("terminationTime is %s" % terminationTime)
+ # todo terminationTime
+ terminateNsService = TerminateNsService(ns_instance_id, job_id, request.data)
+ terminateNsService.start()
+ logger.debug("Location: %s" % terminateNsService.occ_id)
+ response = Response(data={}, status=status.HTTP_202_ACCEPTED)
+ response["Location"] = NS_OCC_BASE_URI % terminateNsService.occ_id
+ logger.debug("Leave TerminateNSView")
+ return response