diff options
author | fujinhua <fu.jinhua@zte.com.cn> | 2019-04-10 09:15:53 +0800 |
---|---|---|
committer | fujinhua <fu.jinhua@zte.com.cn> | 2019-04-10 09:15:53 +0800 |
commit | b47a3175534da93d5452090f5c16f1a4ac1893d8 (patch) | |
tree | 003d629e75f8dcc4b008613b459f1351fb7baef7 | |
parent | 332668f9a48bbea03779c8b88f7d5e0d720fd1c0 (diff) |
Refactor codes for heal ns
Change-Id: Iefaa2c7e6e07e1e3787c56795d4bdc8d16daaeb0
Issue-ID: VFC-1306
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r-- | lcm/ns/views/sol/heal_ns_view.py | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/lcm/ns/views/sol/heal_ns_view.py b/lcm/ns/views/sol/heal_ns_view.py index 6c844e12..6faefd95 100644 --- a/lcm/ns/views/sol/heal_ns_view.py +++ b/lcm/ns/views/sol/heal_ns_view.py @@ -22,6 +22,7 @@ from lcm.pub.exceptions import BadRequestException from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE 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__) @@ -34,29 +35,21 @@ class HealNSView(APIView): status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer() } ) + @view_safe_call_with_log(logger=logger) def post(self, request, ns_instance_id): + logger.debug("Enter HealNSView::post %s", request.data) + logger.debug("Enter HealNSView:: %s", ns_instance_id) + req_serializer = HealNsReqSerializer(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) + job_id = JobUtil.create_job("VNF", JOB_TYPE.HEAL_VNF, ns_instance_id) - try: - logger.debug("Enter HealNSView::post %s", request.data) - logger.debug("Enter HealNSView:: %s", ns_instance_id) - req_serializer = HealNsReqSerializer(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) - nsHealService = NSHealService(ns_instance_id, request.data, job_id) - nsHealService.start() - response = Response(data={}, status=status.HTTP_202_ACCEPTED) - logger.debug("Location: %s" % nsHealService.occ_id) - response["Location"] = NS_OCC_BASE_URI % nsHealService.occ_id - logger.debug("Leave NSHealView") - return response - except BadRequestException as e: - logger.error("Exception in HealNS: %s", e.message) - JobUtil.add_job_status(job_id, 255, 'NS heal 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 HealNSView: %s", e.message) - JobUtil.add_job_status(job_id, 255, 'NS heal failed: %s' % e.message) - data = {'status': status.HTTP_500_INTERNAL_SERVER_ERROR, 'detail': e.message} - return Response(data=data, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + + nsHealService = NSHealService(ns_instance_id, request.data, job_id) + nsHealService.start() + response = Response(data={}, status=status.HTTP_202_ACCEPTED) + logger.debug("Location: %s" % nsHealService.occ_id) + response["Location"] = NS_OCC_BASE_URI % nsHealService.occ_id + logger.debug("Leave NSHealView") + return response |