# 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
from lcm.nf.biz.heal_vnf import HealVnf\r
from lcm.nf.serializers.heal_vnf_req import HealVnfRequestSerializer\r
from lcm.nf.serializers.response import ProblemDetailsSerializer\r
-from lcm.pub.exceptions import NFLCMException, NFLCMExceptionNotFound, NFLCMExceptionConflict\r
+from lcm.pub.exceptions import NFLCMException, NFLCMExceptionNotFound\r
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
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("HealVnf--post::> %s" % request.data)\r
- try:\r
- heal_vnf_request_serializer = HealVnfRequestSerializer(data=request.data)\r
- if not heal_vnf_request_serializer.is_valid():\r
- raise NFLCMException(heal_vnf_request_serializer.errors)\r
\r
- job_id = JobUtil.create_job('NF', 'HEAL', instanceid)\r
- JobUtil.add_job_status(job_id, 0, "HEAL_VNF_READY")\r
- self.heal_pre_check(instanceid, job_id)\r
- HealVnf(heal_vnf_request_serializer.data, instanceid, job_id).start()\r
- response = Response(data={"jobId": job_id}, status=status.HTTP_202_ACCEPTED)\r
- # todo, heal_vnf codes uses job as the status storage, not in VNFLcmOpOccModel.\r
- # response["Location"] = "/api/vnflcm/v1/vnf_lc_ops/%s" % lcmopoccid\r
- return response\r
- except NFLCMExceptionNotFound as e:\r
- probDetail = ProblemDetailsSerializer(data={"status": status.HTTP_404_NOT_FOUND, "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": status.HTTP_409_CONFLICT, "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
+ heal_vnf_request_serializer = HealVnfRequestSerializer(data=request.data)\r
+ if not heal_vnf_request_serializer.is_valid():\r
+ raise NFLCMException(heal_vnf_request_serializer.errors)\r
+\r
+ job_id = JobUtil.create_job('NF', 'HEAL', instanceid)\r
+ JobUtil.add_job_status(job_id, 0, "HEAL_VNF_READY")\r
+ self.heal_pre_check(instanceid, job_id)\r
+ HealVnf(heal_vnf_request_serializer.data, instanceid, job_id).start()\r
+ response = Response(data={"jobId": job_id}, status=status.HTTP_202_ACCEPTED)\r
+ # todo, heal_vnf codes uses job as the status storage, not in VNFLcmOpOccModel.\r
+ # response["Location"] = "/api/vnflcm/v1/vnf_lc_ops/%s" % lcmopoccid\r
+ return response\r
\r
def heal_pre_check(self, nf_inst_id, job_id):\r
vnf_insts = NfInstModel.objects.filter(nfinstid=nf_inst_id)\r