Merge "fix the bug of database migrate"
authorFu Jinhua <fu.jinhua@zte.com.cn>
Mon, 8 Apr 2019 01:29:37 +0000 (01:29 +0000)
committerGerrit Code Review <gerrit@onap.org>
Mon, 8 Apr 2019 01:29:37 +0000 (01:29 +0000)
lcm/lcm/nf/biz/create_subscription.py
lcm/lcm/nf/tests/test_subscribe_notification.py
lcm/lcm/nf/views/instantiate_vnf_view.py
lcm/lcm/nf/views/lcm_op_occs_view.py
lcm/lcm/nf/views/operate_vnf_view.py
lcm/lcm/nf/views/scale_to_level_view.py
lcm/lcm/nf/views/scale_vnf_view.py
lcm/lcm/nf/views/subscriptions_view.py
lcm/lcm/nf/views/terminate_vnf_view.py

index db529a7..6802c22 100644 (file)
@@ -25,6 +25,7 @@ from rest_framework import status
 from lcm.nf import const
 from lcm.pub.database.models import SubscriptionModel
 from lcm.pub.exceptions import NFLCMException
+from lcm.pub.exceptions import NFLCMExceptionSeeOther
 from lcm.pub.utils.values import ignore_case_get
 
 logger = logging.getLogger(__name__)
@@ -116,8 +117,8 @@ class CreateSubscription:
             return True
         for subscription in subscriptions:
             if self.check_filter_exists(subscription):
-                raise NFLCMException("Already Subscription exists with the "
-                                     "same callbackUri and filter")
+                raise NFLCMExceptionSeeOther("Already Subscription exists with the "
+                                             "same callbackUri and filter")
         return False
 
     def save_db(self):
index 8aeab63..73463ef 100644 (file)
@@ -95,7 +95,8 @@ class TestSubscription(TestCase):
         mock_requests.return_value.status_code = 204
         mock_requests.get.return_value.status_code = 204
         expected_data = {
-            'error': 'Auth type should be BASIC'
+            'detail': 'Auth type should be BASIC',
+            'status': 500
         }
         response = self.client.post("/api/vnflcm/v1/subscriptions", data=dummy_subscription, format='json')
         self.assertEqual(500, response.status_code)
@@ -118,8 +119,9 @@ class TestSubscription(TestCase):
         mock_requests.return_value.status_code = 204
         mock_requests.get.return_value.status_code = 204
         expected_data = {
-            'error': 'If you are setting operationTypes,then ' +
-            'notificationTypes must be VnfLcmOperationOccurrenceNotification'
+            'detail': 'If you are setting operationTypes,then ' +
+            'notificationTypes must be VnfLcmOperationOccurrenceNotification',
+            'status': 500
         }
         response = self.client.post("/api/vnflcm/v1/subscriptions", data=dummy_subscription, format='json')
         self.assertEqual(500, response.status_code)
@@ -150,7 +152,3 @@ class TestSubscription(TestCase):
         self.assertEqual(temp_uuid, response.data["id"])
         response = self.client.post("/api/vnflcm/v1/subscriptions", data=dummy_subscription, format='json')
         self.assertEqual(303, response.status_code)
-        expected_data = {
-            "error": "Already Subscription exists with the same callbackUri and filter"
-        }
-        self.assertEqual(expected_data, response.data)
index 1a7905a..b285cc8 100644 (file)
@@ -24,6 +24,7 @@ from lcm.nf.serializers.instantiate_vnf_request import InstantiateVnfRequestSeri
 from lcm.nf.serializers.job_identifier import JobIdentifierSerializer\r
 from lcm.pub.exceptions import NFLCMException\r
 from lcm.pub.utils.jobutil import JobUtil\r
+from .common import view_safe_call_with_log\r
 \r
 logger = logging.getLogger(__name__)\r
 \r
@@ -36,6 +37,7 @@ class InstantiateVnfView(APIView):
             status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"\r
         }\r
     )\r
+    @view_safe_call_with_log(logger=logger)\r
     def post(self, request, instanceid):\r
         logger.debug("InstantiateVnf--post::> %s" % request.data)\r
 \r
index de16531..96cdecb 100644 (file)
@@ -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)
index ab8f905..3221806 100644 (file)
@@ -13,7 +13,6 @@
 # limitations under the License.\r
 \r
 import logging\r
-import traceback\r
 \r
 from drf_yasg.utils import swagger_auto_schema\r
 from rest_framework import status\r
@@ -27,6 +26,7 @@ from lcm.pub.exceptions import NFLCMException, NFLCMExceptionNotFound, NFLCMExce
 from lcm.pub.utils.jobutil import JobUtil\r
 from lcm.pub.database.models import NfInstModel\r
 from lcm.nf.const import VNF_STATUS\r
+from .common import view_safe_call_with_log\r
 \r
 logger = logging.getLogger(__name__)\r
 \r
@@ -41,40 +41,22 @@ class OperateVnfView(APIView):
             status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"\r
         }\r
     )\r
+    @view_safe_call_with_log(logger=logger)\r
     def post(self, request, instanceid):\r
         logger.debug("OperateVnf--post::> %s" % request.data)\r
-        try:\r
-            operate_vnf_request_serializer = OperateVnfRequestSerializer(data=request.data)\r
-            if not operate_vnf_request_serializer.is_valid():\r
-                raise NFLCMException(operate_vnf_request_serializer.errors)\r
 \r
-            job_id = JobUtil.create_job('NF', 'OPERATE', instanceid)\r
-            JobUtil.add_job_status(job_id, 0, "OPERATE_VNF_READY")\r
-            self.operate_pre_check(instanceid, job_id)\r
-            OperateVnf(operate_vnf_request_serializer.data, instanceid, job_id).start()\r
-            response = Response(data={"jobId": job_id}, status=status.HTTP_202_ACCEPTED)\r
-            # Location todo, it use job as the status storage\r
-            # response["Location"] = "/api/vnflcm/v1/vnf_lcm_op_occs/%s" % lcmopoccid\r
-            return response\r
-        except NFLCMExceptionNotFound as e:\r
-            probDetail = ProblemDetailsSerializer(data={"status": 404, "detail": "VNF Instance not found"})\r
-            resp_isvalid = probDetail.is_valid()\r
-            if not resp_isvalid:\r
-                raise NFLCMException(probDetail.errors)\r
-            return Response(data=probDetail.data, status=status.HTTP_404_NOT_FOUND)\r
-        except NFLCMExceptionConflict as e:\r
-            probDetail = ProblemDetailsSerializer(data={"status": 409, "detail": "VNF Instance not in Instantiated State"})\r
-            resp_isvalid = probDetail.is_valid()\r
-            if not resp_isvalid:\r
-                raise NFLCMException(probDetail.errors)\r
-            return Response(data=probDetail.data, status=status.HTTP_409_CONFLICT)\r
-        except NFLCMException as e:\r
-            logger.error(e.message)\r
-            return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)\r
-        except Exception as e:\r
-            logger.error(e.message)\r
-            logger.error(traceback.format_exc())\r
-            return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)\r
+        operate_vnf_request_serializer = OperateVnfRequestSerializer(data=request.data)\r
+        if not operate_vnf_request_serializer.is_valid():\r
+            raise NFLCMException(operate_vnf_request_serializer.errors)\r
+\r
+        job_id = JobUtil.create_job('NF', 'OPERATE', instanceid)\r
+        JobUtil.add_job_status(job_id, 0, "OPERATE_VNF_READY")\r
+        self.operate_pre_check(instanceid, job_id)\r
+        OperateVnf(operate_vnf_request_serializer.data, instanceid, job_id).start()\r
+        response = Response(data={"jobId": job_id}, status=status.HTTP_202_ACCEPTED)\r
+        # Location todo, it use job as the status storage\r
+        # response["Location"] = "/api/vnflcm/v1/vnf_lcm_op_occs/%s" % lcmopoccid\r
+        return response\r
 \r
     def operate_pre_check(self, nfInstId, jobId):\r
         vnf_insts = NfInstModel.objects.filter(nfinstid=nfInstId)\r
index 9ae2cd3..8d4f41c 100644 (file)
@@ -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
@@ -22,11 +21,14 @@ from rest_framework.views import APIView
 
 from lcm.nf.serializers.scale_vnf_to_level_request_serializer import ScaleVnfToLevelRequestSerializer
 from lcm.nf.serializers.response import ProblemDetailsSerializer
-from lcm.pub.exceptions import NFLCMException, NFLCMExceptionNotFound, NFLCMExceptionConflict
+from lcm.pub.exceptions import NFLCMException
+from lcm.pub.exceptions import NFLCMExceptionNotFound
+from lcm.pub.exceptions import NFLCMExceptionConflict
 from lcm.pub.utils.jobutil import JobUtil
 from lcm.pub.database.models import NfInstModel
 from lcm.nf.const import VNF_STATUS
 from lcm.nf.biz.scale_vnf_to_level import ScaleVnfToLevel
+from .common import view_safe_call_with_log
 
 logger = logging.getLogger(__name__)
 
@@ -41,53 +43,32 @@ class ScaleVnfToLevelView(APIView):
             status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
         }
     )
+    @view_safe_call_with_log(logger=logger)
     def post(self, request, instanceid):
         logger.debug("ScaleVnfToLevel--post::> %s" % request.data)
-        try:
-            scale_to_level_serializer = ScaleVnfToLevelRequestSerializer(data=request.data)
-            if not scale_to_level_serializer.is_valid():
-                raise NFLCMException(scale_to_level_serializer.errors)
 
-            job_id = JobUtil.create_job('NF', 'SCALE_TO_LEVEL', instanceid)
-            JobUtil.add_job_status(job_id, 0, "SCALE_VNF_TO_LEVEL_READY")
-            self.scale_pre_check(instanceid, job_id)
+        scale_to_level_serializer = ScaleVnfToLevelRequestSerializer(data=request.data)
+        if not scale_to_level_serializer.is_valid():
+            raise NFLCMException(scale_to_level_serializer.errors)
 
-            ScaleVnfToLevel(scale_to_level_serializer.data, instanceid, job_id).start()
+        job_id = JobUtil.create_job('NF', 'SCALE_TO_LEVEL', instanceid)
+        JobUtil.add_job_status(job_id, 0, "SCALE_VNF_TO_LEVEL_READY")
+        self.scale_pre_check(instanceid, job_id)
 
-            response = Response(data={"jobId": job_id},
-                                status=status.HTTP_202_ACCEPTED)
-            return response
-        except NFLCMExceptionNotFound as e:
-            probDetail = ProblemDetailsSerializer(data={"status": status.HTTP_404_NOT_FOUND,
-                                                        "detail": "VNF Instance not found"})
-            resp_isvalid = probDetail.is_valid()
-            if not resp_isvalid:
-                raise NFLCMException(probDetail.errors)
-            return Response(data=probDetail.data,
-                            status=status.HTTP_404_NOT_FOUND)
-        except NFLCMExceptionConflict as e:
-            probDetail = ProblemDetailsSerializer(data={"status": status.HTTP_409_CONFLICT,
-                                                        "detail": "VNF Instance not in Instantiated State"})
-            resp_isvalid = probDetail.is_valid()
-            if not resp_isvalid:
-                raise NFLCMException(probDetail.errors)
-            return Response(data=probDetail.data,
-                            status=status.HTTP_409_CONFLICT)
-        except NFLCMException as e:
-            logger.error(e.message)
-            return Response(data={'error': '%s' % e.message},
-                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
-        except Exception as e:
-            logger.error(e.message)
-            logger.error(traceback.format_exc())
-            return Response(data={'error': 'unexpected exception'},
-                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+        ScaleVnfToLevel(scale_to_level_serializer.data, instanceid, job_id).start()
+
+        response = Response(data={"jobId": job_id},
+                            status=status.HTTP_202_ACCEPTED)
+        return response
 
     def scale_pre_check(self, nf_inst_id, job_id):
         vnf_insts = NfInstModel.objects.filter(nfinstid=nf_inst_id)
         if not vnf_insts.exists():
             raise NFLCMExceptionNotFound("VNF nf_inst_id does not exist.")
 
+        if vnf_insts[0].status != 'INSTANTIATED':
+            raise NFLCMExceptionConflict("VNF instantiationState is not INSTANTIATED.")
+
         vnf_insts.update(status=VNF_STATUS.SCALING)
         JobUtil.add_job_status(job_id, 15, 'Nf scaling to level pre-check finish')
         logger.info("Nf scaling to level pre-check finish")
index 570ba74..804ed01 100644 (file)
@@ -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
@@ -22,11 +21,14 @@ from rest_framework.views import APIView
 
 from lcm.nf.serializers.scale_vnf_request import ScaleVnfRequestSerializer
 from lcm.nf.serializers.response import ProblemDetailsSerializer
-from lcm.pub.exceptions import NFLCMException, NFLCMExceptionNotFound, NFLCMExceptionConflict
+from lcm.pub.exceptions import NFLCMException
+from lcm.pub.exceptions import NFLCMExceptionNotFound
+from lcm.pub.exceptions import NFLCMExceptionConflict
 from lcm.pub.utils.jobutil import JobUtil
 from lcm.pub.database.models import NfInstModel
 from lcm.nf.const import VNF_STATUS
 from lcm.nf.biz.scale_vnf import ScaleVnf
+from .common import view_safe_call_with_log
 
 logger = logging.getLogger(__name__)
 
@@ -41,53 +43,32 @@ class ScaleVnfView(APIView):
             status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
         }
     )
+    @view_safe_call_with_log(logger=logger)
     def post(self, request, instanceid):
         logger.debug("ScaleVnf--post::> %s" % request.data)
-        try:
-            scale_vnf_request_serializer = ScaleVnfRequestSerializer(data=request.data)
-            if not scale_vnf_request_serializer.is_valid():
-                raise NFLCMException(scale_vnf_request_serializer.errors)
 
-            job_id = JobUtil.create_job('NF', 'SCALE', instanceid)
-            JobUtil.add_job_status(job_id, 0, "SCALE_VNF_READY")
-            self.scale_pre_check(instanceid, job_id)
+        scale_vnf_request_serializer = ScaleVnfRequestSerializer(data=request.data)
+        if not scale_vnf_request_serializer.is_valid():
+            raise NFLCMException(scale_vnf_request_serializer.errors)
 
-            ScaleVnf(scale_vnf_request_serializer.data, instanceid, job_id).start()
+        job_id = JobUtil.create_job('NF', 'SCALE', instanceid)
+        JobUtil.add_job_status(job_id, 0, "SCALE_VNF_READY")
+        self.scale_pre_check(instanceid, job_id)
 
-            response = Response(data={"jobId": job_id},
-                                status=status.HTTP_202_ACCEPTED)
-            return response
-        except NFLCMExceptionNotFound as e:
-            probDetail = ProblemDetailsSerializer(data={"status": status.HTTP_404_NOT_FOUND,
-                                                        "detail": "VNF Instance not found"})
-            resp_isvalid = probDetail.is_valid()
-            if not resp_isvalid:
-                raise NFLCMException(probDetail.errors)
-            return Response(data=probDetail.data,
-                            status=status.HTTP_404_NOT_FOUND)
-        except NFLCMExceptionConflict as e:
-            probDetail = ProblemDetailsSerializer(data={"status": status.HTTP_409_CONFLICT,
-                                                        "detail": "VNF Instance not in Instantiated State"})
-            resp_isvalid = probDetail.is_valid()
-            if not resp_isvalid:
-                raise NFLCMException(probDetail.errors)
-            return Response(data=probDetail.data,
-                            status=status.HTTP_409_CONFLICT)
-        except NFLCMException as e:
-            logger.error(e.message)
-            return Response(data={'error': '%s' % e.message},
-                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
-        except Exception as e:
-            logger.error(e.message)
-            logger.error(traceback.format_exc())
-            return Response(data={'error': 'unexpected exception'},
-                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+        ScaleVnf(scale_vnf_request_serializer.data, instanceid, job_id).start()
+
+        response = Response(data={"jobId": job_id},
+                            status=status.HTTP_202_ACCEPTED)
+        return response
 
     def scale_pre_check(self, nf_inst_id, job_id):
         vnf_insts = NfInstModel.objects.filter(nfinstid=nf_inst_id)
         if not vnf_insts.exists():
             raise NFLCMExceptionNotFound("VNF nf_inst_id does not exist.")
 
+        if vnf_insts[0].status != 'INSTANTIATED':
+            raise NFLCMExceptionConflict("VNF instantiationState is not INSTANTIATED.")
+
         vnf_insts.update(status=VNF_STATUS.SCALING)
         JobUtil.add_job_status(job_id, 15, 'Nf scaling pre-check finish')
         logger.info("Nf scaling pre-check finish")
index 4c013ee..a9ffed9 100644 (file)
@@ -15,7 +15,6 @@
 import ast\r
 import json\r
 import logging\r
-import traceback\r
 \r
 from drf_yasg.utils import swagger_auto_schema\r
 from lcm.nf.biz.create_subscription import CreateSubscription\r
@@ -29,6 +28,7 @@ from lcm.nf.serializers.lccn_subscription import LccnSubscriptionSerializer
 from lcm.nf.serializers.lccn_subscriptions import LccnSubscriptionsSerializer\r
 from lcm.nf.serializers.response import ProblemDetailsSerializer\r
 from lcm.pub.exceptions import NFLCMException\r
+from .common import view_safe_call_with_log\r
 \r
 logger = logging.getLogger(__name__)\r
 VALID_FILTERS = ["operationTypes", "operationStates", "notificationTypes", "vnfInstanceId"]\r
@@ -53,39 +53,31 @@ class SubscriptionsView(APIView):
             status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()\r
         }\r
     )\r
+    @view_safe_call_with_log(logger=logger)\r
     def post(self, request):\r
         logger.debug("SubscribeNotification--post::> %s" % request.data)\r
-        try:\r
-            lccn_subscription_request_serializer = LccnSubscriptionRequestSerializer(data=request.data)\r
-            if not lccn_subscription_request_serializer.is_valid():\r
-                raise NFLCMException(lccn_subscription_request_serializer.errors)\r
-            subscription = CreateSubscription(\r
-                lccn_subscription_request_serializer.data).do_biz()\r
-            lccn_notifications_filter = {\r
-                "notificationTypes": ast.literal_eval(subscription.notification_types),\r
-                "operationTypes": ast.literal_eval(subscription.operation_types),\r
-                "operationStates": ast.literal_eval(subscription.operation_states),\r
-                "vnfInstanceSubscriptionFilter": json.loads(subscription.vnf_instance_filter)\r
-            }\r
-            subscription_data = {\r
-                "id": subscription.subscription_id,\r
-                "callbackUri": subscription.callback_uri,\r
-                "_links": json.loads(subscription.links),\r
-                "filter": lccn_notifications_filter\r
-            }\r
-            sub_resp_serializer = LccnSubscriptionSerializer(data=subscription_data)\r
-            if not sub_resp_serializer.is_valid():\r
-                raise NFLCMException(sub_resp_serializer.errors)\r
-            return Response(data=sub_resp_serializer.data, status=status.HTTP_201_CREATED)\r
-        except NFLCMException as e:\r
-            logger.error(e.message)\r
-            if "exists" in e.message:\r
-                return Response(data={'error': '%s' % e.message}, status=status.HTTP_303_SEE_OTHER)\r
-            return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)\r
-        except Exception as e:\r
-            logger.error(e.message)\r
-            logger.error(traceback.format_exc())\r
-            return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)\r
+\r
+        lccn_subscription_request_serializer = LccnSubscriptionRequestSerializer(data=request.data)\r
+        if not lccn_subscription_request_serializer.is_valid():\r
+            raise NFLCMException(lccn_subscription_request_serializer.errors)\r
+        subscription = CreateSubscription(\r
+            lccn_subscription_request_serializer.data).do_biz()\r
+        lccn_notifications_filter = {\r
+            "notificationTypes": ast.literal_eval(subscription.notification_types),\r
+            "operationTypes": ast.literal_eval(subscription.operation_types),\r
+            "operationStates": ast.literal_eval(subscription.operation_states),\r
+            "vnfInstanceSubscriptionFilter": json.loads(subscription.vnf_instance_filter)\r
+        }\r
+        subscription_data = {\r
+            "id": subscription.subscription_id,\r
+            "callbackUri": subscription.callback_uri,\r
+            "_links": json.loads(subscription.links),\r
+            "filter": lccn_notifications_filter\r
+        }\r
+        sub_resp_serializer = LccnSubscriptionSerializer(data=subscription_data)\r
+        if not sub_resp_serializer.is_valid():\r
+            raise NFLCMException(sub_resp_serializer.errors)\r
+        return Response(data=sub_resp_serializer.data, status=status.HTTP_201_CREATED)\r
 \r
     @swagger_auto_schema(\r
         responses={\r
@@ -94,28 +86,22 @@ class SubscriptionsView(APIView):
             status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()\r
         }\r
     )\r
+    @view_safe_call_with_log(logger=logger)\r
     def get(self, request):\r
         logger.debug("SubscribeNotification--get::> %s" % request.query_params)\r
-        try:\r
-            if request.query_params and not set(request.query_params).issubset(set(VALID_FILTERS)):\r
-                problem_details_serializer = get_problem_details_serializer(status.HTTP_400_BAD_REQUEST, "Not a valid filter")\r
-                return Response(data=problem_details_serializer.data, status=status.HTTP_400_BAD_REQUEST)\r
-            resp_data = QuerySubscription(request.query_params).query_multi_subscriptions()\r
 \r
-            subscriptions_serializer = LccnSubscriptionsSerializer(data=resp_data)\r
-            if not subscriptions_serializer.is_valid():\r
-                raise NFLCMException(subscriptions_serializer.errors)\r
+        if request.query_params and not set(request.query_params).issubset(set(VALID_FILTERS)):\r
+            problem_details_serializer = get_problem_details_serializer(\r
+                status.HTTP_400_BAD_REQUEST,\r
+                "Not a valid filter"\r
+            )\r
+            return Response(data=problem_details_serializer.data,\r
+                            status=status.HTTP_400_BAD_REQUEST)\r
+        resp_data = QuerySubscription(request.query_params).query_multi_subscriptions()\r
 \r
-            logger.debug("SubscribeNotification--get::> Remove default fields if exclude_default" +\r
-                         " is specified")\r
-            return Response(data=subscriptions_serializer.data, status=status.HTTP_200_OK)\r
-        except NFLCMException as e:\r
-            logger.error(e.message)\r
-            problem_details_serializer = get_problem_details_serializer(status.HTTP_500_INTERNAL_SERVER_ERROR, traceback.format_exc())\r
-            return Response(data=problem_details_serializer.data, status=status.HTTP_500_INTERNAL_SERVER_ERROR)\r
+        subscriptions_serializer = LccnSubscriptionsSerializer(data=resp_data)\r
+        if not subscriptions_serializer.is_valid():\r
+            raise NFLCMException(subscriptions_serializer.errors)\r
 \r
-        except Exception as e:\r
-            logger.error(e.message)\r
-            logger.error(traceback.format_exc())\r
-            problem_details_serializer = get_problem_details_serializer(status.HTTP_500_INTERNAL_SERVER_ERROR, traceback.format_exc())\r
-            return Response(data=problem_details_serializer.data, status=status.HTTP_500_INTERNAL_SERVER_ERROR)\r
+        logger.debug("SubscribeNotification--get::> Remove default fields")\r
+        return Response(data=subscriptions_serializer.data, status=status.HTTP_200_OK)\r
index c1903b7..0530437 100644 (file)
@@ -13,7 +13,6 @@
 # limitations under the License.\r
 \r
 import logging\r
-import traceback\r
 \r
 from drf_yasg.utils import swagger_auto_schema\r
 from rest_framework import status\r
@@ -25,7 +24,7 @@ from lcm.nf.serializers.terminate_vnf_req import TerminateVnfRequestSerializer
 from lcm.nf.serializers.job_identifier import JobIdentifierSerializer\r
 from lcm.pub.exceptions import NFLCMException\r
 from lcm.pub.utils.jobutil import JobUtil\r
-\r
+from .common import view_safe_call_with_log\r
 \r
 logger = logging.getLogger(__name__)\r
 \r
@@ -38,26 +37,20 @@ class TerminateVnfView(APIView):
             status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"\r
         }\r
     )\r
+    @view_safe_call_with_log(logger=logger)\r
     def post(self, request, instanceid):\r
         logger.debug("TerminateVnf--post::> %s" % request.data)\r
-        try:\r
-            terminate_vnf_request_serializer = TerminateVnfRequestSerializer(data=request.data)\r
-            if not terminate_vnf_request_serializer.is_valid():\r
-                raise NFLCMException(terminate_vnf_request_serializer.errors)\r
-\r
-            job_id = JobUtil.create_job('NF', 'TERMINATE', instanceid)\r
-            JobUtil.add_job_status(job_id, 0, "TERM_VNF_READY")\r
-            TerminateVnf(terminate_vnf_request_serializer.data, instanceid, job_id).start()\r
-\r
-            terminate_vnf_response_serializer = JobIdentifierSerializer(data={"jobId": job_id})\r
-            if not terminate_vnf_response_serializer.is_valid():\r
-                raise NFLCMException(terminate_vnf_response_serializer.errors)\r
-\r
-            return Response(data=terminate_vnf_response_serializer.data, status=status.HTTP_202_ACCEPTED)\r
-        except NFLCMException as e:\r
-            logger.error(e.message)\r
-            return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)\r
-        except Exception as e:\r
-            logger.error(e.message)\r
-            logger.error(traceback.format_exc())\r
-            return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)\r
+\r
+        terminate_vnf_request_serializer = TerminateVnfRequestSerializer(data=request.data)\r
+        if not terminate_vnf_request_serializer.is_valid():\r
+            raise NFLCMException(terminate_vnf_request_serializer.errors)\r
+\r
+        job_id = JobUtil.create_job('NF', 'TERMINATE', instanceid)\r
+        JobUtil.add_job_status(job_id, 0, "TERM_VNF_READY")\r
+        TerminateVnf(terminate_vnf_request_serializer.data, instanceid, job_id).start()\r
+\r
+        terminate_vnf_response_serializer = JobIdentifierSerializer(data={"jobId": job_id})\r
+        if not terminate_vnf_response_serializer.is_valid():\r
+            raise NFLCMException(terminate_vnf_response_serializer.errors)\r
+\r
+        return Response(data=terminate_vnf_response_serializer.data, status=status.HTTP_202_ACCEPTED)\r