summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfujinhua <fu.jinhua@zte.com.cn>2019-07-11 09:03:30 +0800
committerfujinhua <fu.jinhua@zte.com.cn>2019-07-11 09:03:30 +0800
commitd9949426185df3323dea4db239293328c5395808 (patch)
tree729c78438597be24b4a7c6f1dd86949d6edd79a7
parent16377f0f673d1aba03c1c286faf24ca8a5d97b5b (diff)
Refactor codes for heal ns
Change-Id: Iec034c58757dbdc4bf57b4713649ebd78d61fccc Issue-ID: VFC-1429 Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r--lcm/ns/views/deprecated/heal_ns_view.py39
1 files changed, 17 insertions, 22 deletions
diff --git a/lcm/ns/views/deprecated/heal_ns_view.py b/lcm/ns/views/deprecated/heal_ns_view.py
index d046ae32..473fea73 100644
--- a/lcm/ns/views/deprecated/heal_ns_view.py
+++ b/lcm/ns/views/deprecated/heal_ns_view.py
@@ -22,8 +22,10 @@ from lcm.ns.biz.ns_heal import NSHealService
from lcm.ns.serializers.deprecated.ns_serializers import _HealNsReqSerializer
from lcm.ns.serializers.deprecated.ns_serializers import _NsOperateJobSerializer
from lcm.pub.exceptions import NSLCMException
+from lcm.pub.exceptions import BadRequestException
from lcm.pub.utils.jobutil import JobUtil
from lcm.jobs.enum import JOB_TYPE, JOB_ACTION
+from .common import view_safe_call_with_log
logger = logging.getLogger(__name__)
@@ -36,26 +38,19 @@ class NSHealView(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 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():
- raise NSLCMException(req_serializer.errors)
-
- job_id = JobUtil.create_job(JOB_TYPE.NS, JOB_ACTION.HEAL, ns_instance_id)
- NSHealService(ns_instance_id, request.data, job_id).start()
-
- resp_serializer = _NsOperateJobSerializer(data={'jobId': job_id})
- if not resp_serializer.is_valid():
- raise NSLCMException(resp_serializer.errors)
-
- logger.debug("Leave HealNSView::post ret=%s", resp_serializer.data)
- return Response(data=resp_serializer.data, status=status.HTTP_202_ACCEPTED)
- except NSLCMException as e:
- logger.error("Exception in HealNSView: %s", e.args[0])
- return Response(data={'error': e.args[0]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- except Exception as e:
- logger.error("Exception in HealNSView: %s", e.args[0])
- return Response(data={'error': e.args[0]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ logger.debug("Enter HealNSView::post %s, %s", ns_instance_id, request.data)
+ req_serializer = _HealNsReqSerializer(data=request.data)
+ if not req_serializer.is_valid():
+ raise BadRequestException(req_serializer.errors)
+
+ job_id = JobUtil.create_job(JOB_TYPE.NS, JOB_ACTION.HEAL, ns_instance_id)
+ NSHealService(ns_instance_id, request.data, job_id).start()
+
+ resp_serializer = _NsOperateJobSerializer(data={'jobId': job_id})
+ if not resp_serializer.is_valid():
+ raise NSLCMException(resp_serializer.errors)
+
+ logger.debug("Leave HealNSView::post ret=%s", resp_serializer.data)
+ return Response(data=resp_serializer.data, status=status.HTTP_202_ACCEPTED)