X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=lcm%2Fns%2Fviews%2Fsol%2Fscale_ns_views.py;h=8a5c19d50348574da00f14b0e79818ef9ddbd8a8;hb=0876c326a9f9809fbb35d512a4a95f9fad00e445;hp=347760497b410b415ef93969d5c5c1127141cdbb;hpb=ed2ee53dbf5189df383f022e897f53eb02796ebb;p=vfc%2Fnfvo%2Flcm.git diff --git a/lcm/ns/views/sol/scale_ns_views.py b/lcm/ns/views/sol/scale_ns_views.py index 34776049..8a5c19d5 100644 --- a/lcm/ns/views/sol/scale_ns_views.py +++ b/lcm/ns/views/sol/scale_ns_views.py @@ -1,4 +1,4 @@ -# Copyright 2016-2017 ZTE Corporation. +# Copyright 2016 ZTE Corporation. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,47 +12,51 @@ # See the License for the specific language governing permissions and # limitations under the License. import logging -import traceback from drf_yasg.utils import swagger_auto_schema from rest_framework import status from rest_framework.response import Response from rest_framework.views import APIView - from lcm.ns.biz.ns_manual_scale import NSManualScaleService -from lcm.ns.serializers.deprecated.ns_serializers import _NsOperateJobSerializer from lcm.ns.serializers.sol.scale_ns_serializers import ManualScaleNsReqSerializer from lcm.pub.exceptions import NSLCMException from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE +from lcm.ns.const import NS_OCC_BASE_URI +from lcm.pub.exceptions import BadRequestException +from lcm.ns.serializers.sol.pub_serializers import ProblemDetailsSerializer logger = logging.getLogger(__name__) class ScaleNSView(APIView): @swagger_auto_schema( - request_body=ManualScaleNsReqSerializer(help_text="NS manual scale"), + request_body=ManualScaleNsReqSerializer(help_text="NS Scale"), responses={ - status.HTTP_202_ACCEPTED: _NsOperateJobSerializer(), - status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error" + status.HTTP_202_ACCEPTED: "HTTP_202_ACCEPTED", + status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer() } ) def post(self, request, ns_instance_id): - logger.debug("Enter NSManualScaleView::post %s, %s", request.data, ns_instance_id) + logger.debug("Enter ScaleNSView::post %s, %s", request.data, ns_instance_id) job_id = JobUtil.create_job("NS", JOB_TYPE.MANUAL_SCALE_VNF, ns_instance_id) try: req_serializer = ManualScaleNsReqSerializer(data=request.data) if not req_serializer.is_valid(): raise NSLCMException(req_serializer.errors) - - NSManualScaleService(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) - - return Response(data=resp_serializer.data, status=status.HTTP_202_ACCEPTED) + nsManualScaleService = NSManualScaleService(ns_instance_id, request.data, job_id) + nsManualScaleService.start() + response = Response(data={}, status=status.HTTP_202_ACCEPTED) + logger.debug("Location: %s" % nsManualScaleService.occ_id) + response["Location"] = NS_OCC_BASE_URI % nsManualScaleService.occ_id + logger.debug("Leave ScaleNSView") + return response + except BadRequestException as e: + logger.error("Exception in ScaleNSView: %s", e.message) + JobUtil.add_job_status(job_id, 255, 'NS scale 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(traceback.format_exc()) + logger.error("Exception in ScaleNSView: %s", e.message) JobUtil.add_job_status(job_id, 255, 'NS scale failed: %s' % e.message) - return Response(data={'error': 'NS scale failed: %s' % ns_instance_id}, - status=status.HTTP_500_INTERNAL_SERVER_ERROR) + data = {'status': status.HTTP_500_INTERNAL_SERVER_ERROR, 'detail': e.message} + return Response(data=data, status=status.HTTP_500_INTERNAL_SERVER_ERROR)