diff options
author | fujinhua <fu.jinhua@zte.com.cn> | 2019-04-06 08:33:26 +0800 |
---|---|---|
committer | fujinhua <fu.jinhua@zte.com.cn> | 2019-04-06 08:33:26 +0800 |
commit | 2470d94d82a01b7b220d81263ff56465fe5432e7 (patch) | |
tree | aaeac8e13cb652e60b358ad5faceda4140b97d1e | |
parent | 3cd63752dfcdc32454e26b04a79ee7ddb7eb0c99 (diff) |
Refactor codes for lcm op occ
Change-Id: Ic54ed83659699af0dfb57a6a96cfe94726cc9cd4
Issue-ID: VFC-1306
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r-- | lcm/lcm/nf/views/lcm_op_occs_view.py | 67 |
1 files changed, 25 insertions, 42 deletions
diff --git a/lcm/lcm/nf/views/lcm_op_occs_view.py b/lcm/lcm/nf/views/lcm_op_occs_view.py index de165317..96cdecb0 100644 --- a/lcm/lcm/nf/views/lcm_op_occs_view.py +++ b/lcm/lcm/nf/views/lcm_op_occs_view.py @@ -13,7 +13,6 @@ # limitations under the License. import logging -import traceback from drf_yasg.utils import swagger_auto_schema from rest_framework import status @@ -25,6 +24,7 @@ from lcm.nf.serializers.response import ProblemDetailsSerializer from lcm.nf.serializers.vnf_lcm_op_occ import VNFLCMOpOccSerializer from lcm.nf.serializers.vnf_lcm_op_occs import VNFLCMOpOccsSerializer from lcm.pub.exceptions import NFLCMException +from .common import view_safe_call_with_log logger = logging.getLogger(__name__) EXCLUDE_DEFAULT = ['operationParams', 'error', 'resourceChanges', 'changedInfo', 'changedExtConnectivity'] @@ -51,36 +51,26 @@ class QueryMultiVnfLcmOpOccs(APIView): status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer() } ) + @view_safe_call_with_log(logger=logger) def get(self, request): logger.debug("QueryMultiVnfLcmOpOccs--get::> %s" % request.query_params) - try: - if request.query_params and not set(request.query_params).issubset(set(VALID_FILTERS)): - problem_details_serializer = get_problem_details_serializer(status.HTTP_400_BAD_REQUEST, "Not a valid filter") - return Response(data=problem_details_serializer.data, status=status.HTTP_400_BAD_REQUEST) - resp_data = QueryVnfLcmOpOcc(request.query_params).query_multi_vnf_lcm_op_occ() + if request.query_params and not set(request.query_params).issubset(set(VALID_FILTERS)): + problem_details_serializer = get_problem_details_serializer(status.HTTP_400_BAD_REQUEST, "Not a valid filter") + return Response(data=problem_details_serializer.data, status=status.HTTP_400_BAD_REQUEST) + resp_data = QueryVnfLcmOpOcc(request.query_params).query_multi_vnf_lcm_op_occ() - vnf_lcm_op_occs_serializer = VNFLCMOpOccsSerializer(data=resp_data) - if not vnf_lcm_op_occs_serializer.is_valid(): - raise NFLCMException(vnf_lcm_op_occs_serializer.errors) + vnf_lcm_op_occs_serializer = VNFLCMOpOccsSerializer(data=resp_data) + if not vnf_lcm_op_occs_serializer.is_valid(): + raise NFLCMException(vnf_lcm_op_occs_serializer.errors) - logger.debug("QueryMultiVnfLcmOpOccs--get::> Remove default fields if exclude_default" + - " is specified") - # TODO(bharath): Add support for "fields", "exclude_fields" in query parameters - if 'exclude_default' in request.query_params.keys(): - for field in EXCLUDE_DEFAULT: - for lcm_op in vnf_lcm_op_occs_serializer.data: - del lcm_op[field] - return Response(data=vnf_lcm_op_occs_serializer.data, status=status.HTTP_200_OK) - except NFLCMException as e: - logger.error(e.message) - problem_details_serializer = get_problem_details_serializer(status.HTTP_500_INTERNAL_SERVER_ERROR, e.message) - return Response(data=problem_details_serializer.data, status=status.HTTP_500_INTERNAL_SERVER_ERROR) - - except Exception as e: - logger.error(e.message) - logger.error(traceback.format_exc()) - problem_details_serializer = get_problem_details_serializer(status.HTTP_500_INTERNAL_SERVER_ERROR, e.message) - return Response(data=problem_details_serializer.data, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + logger.debug("QueryMultiVnfLcmOpOccs--get::> Remove default fields if exclude_default" + + " is specified") + # TODO(bharath): Add support for "fields", "exclude_fields" in query parameters + if 'exclude_default' in request.query_params.keys(): + for field in EXCLUDE_DEFAULT: + for lcm_op in vnf_lcm_op_occs_serializer.data: + del lcm_op[field] + return Response(data=vnf_lcm_op_occs_serializer.data, status=status.HTTP_200_OK) class QuerySingleVnfLcmOpOcc(APIView): @@ -90,22 +80,15 @@ class QuerySingleVnfLcmOpOcc(APIView): status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer() } ) + @view_safe_call_with_log(logger=logger) def get(self, request, lcmopoccid): logger.debug("QuerySingleVnfLcmOpOcc--get::> %s" % request.query_params) - try: - resp_data = QueryVnfLcmOpOcc(request.query_params, lcm_op_occ_id=lcmopoccid).query_single_vnf_lcm_op_occ() - vnf_lcm_op_occ_serializer = VNFLCMOpOccSerializer(data=resp_data) - if not vnf_lcm_op_occ_serializer.is_valid(): - raise NFLCMException(vnf_lcm_op_occ_serializer.errors) + resp_data = QueryVnfLcmOpOcc(request.query_params, + lcm_op_occ_id=lcmopoccid).query_single_vnf_lcm_op_occ() + + vnf_lcm_op_occ_serializer = VNFLCMOpOccSerializer(data=resp_data) + if not vnf_lcm_op_occ_serializer.is_valid(): + raise NFLCMException(vnf_lcm_op_occ_serializer.errors) - return Response(data=vnf_lcm_op_occ_serializer.data, status=status.HTTP_200_OK) - except NFLCMException as e: - logger.error(e.message) - problem_details_serializer = get_problem_details_serializer(status.HTTP_500_INTERNAL_SERVER_ERROR, e.message) - return Response(data=problem_details_serializer.data, status=status.HTTP_500_INTERNAL_SERVER_ERROR) - except Exception as e: - logger.error(e.message) - logger.error(traceback.format_exc()) - problem_details_serializer = get_problem_details_serializer(status.HTTP_500_INTERNAL_SERVER_ERROR, e.message) - return Response(data=problem_details_serializer.data, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + return Response(data=vnf_lcm_op_occ_serializer.data, status=status.HTTP_200_OK) |