diff options
-rw-r--r-- | lcm/ns/biz/ns_heal.py | 2 | ||||
-rw-r--r-- | lcm/ns/biz/ns_manual_scale.py | 9 | ||||
-rw-r--r-- | lcm/ns/views/sol/heal_ns_view.py | 7 | ||||
-rw-r--r-- | lcm/ns/views/sol/scale_ns_views.py | 33 | ||||
-rw-r--r-- | lcm/ns/views/sol/terminate_ns_view.py | 4 |
5 files changed, 34 insertions, 21 deletions
diff --git a/lcm/ns/biz/ns_heal.py b/lcm/ns/biz/ns_heal.py index e7d5794a..91e455fd 100644 --- a/lcm/ns/biz/ns_heal.py +++ b/lcm/ns/biz/ns_heal.py @@ -36,7 +36,7 @@ class NSHealService(threading.Thread): self.ns_instance_id = ns_instance_id self.request_data = request_data self.job_id = job_id - self.occ_id = NsLcmOpOcc.create(ns_instance_id, "TERMINATE", "PROCESSING", False, request_data) + self.occ_id = NsLcmOpOcc.create(ns_instance_id, "HEAL", "PROCESSING", False, request_data) self.heal_vnf_data = '' self.heal_ns_data = '' diff --git a/lcm/ns/biz/ns_manual_scale.py b/lcm/ns/biz/ns_manual_scale.py index e7121461..668ad486 100644 --- a/lcm/ns/biz/ns_manual_scale.py +++ b/lcm/ns/biz/ns_manual_scale.py @@ -24,6 +24,7 @@ from lcm.pub.exceptions import NSLCMException from lcm.pub.utils.jobutil import JobUtil, JOB_MODEL_STATUS from lcm.pub.utils.values import ignore_case_get from lcm.ns_vnfs.biz.scale_vnfs import NFManualScaleService +from lcm.ns.biz.ns_lcm_op_occ import NsLcmOpOcc JOB_ERROR = 255 SCALE_TYPE = ("SCALE_NS", "SCALE_VNF") @@ -36,6 +37,7 @@ class NSManualScaleService(threading.Thread): self.ns_instance_id = ns_instance_id self.request_data = request_data self.job_id = job_id + self.occ_id = NsLcmOpOcc.create(ns_instance_id, "SCALE", "PROCESSING", False, request_data) self.scale_vnf_data = '' def run(self): @@ -43,10 +45,12 @@ class NSManualScaleService(threading.Thread): self.do_biz() except NSLCMException as e: JobUtil.add_job_status(self.job_id, JOB_ERROR, e.message) - except Exception as ex: - logger.error(ex.message) + NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.message) + except Exception as e: + logger.error(e.message) logger.error(traceback.format_exc()) JobUtil.add_job_status(self.job_id, JOB_ERROR, 'ns scale fail') + NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.message) finally: self.update_ns_status(NS_INST_STATUS.ACTIVE) @@ -56,6 +60,7 @@ class NSManualScaleService(threading.Thread): self.check_and_set_params() self.do_vnfs_scale() self.update_job(100, desc='ns scale success') + NsLcmOpOcc.update(self.occ_id, "COMPLETED") def check_and_set_params(self): scale_type = ignore_case_get(self.request_data, 'scaleType') diff --git a/lcm/ns/views/sol/heal_ns_view.py b/lcm/ns/views/sol/heal_ns_view.py index d98c972b..d1ba916b 100644 --- a/lcm/ns/views/sol/heal_ns_view.py +++ b/lcm/ns/views/sol/heal_ns_view.py @@ -34,6 +34,7 @@ class HealNSView(APIView): } ) def post(self, request, ns_instance_id): + job_id = JobUtil.create_job("VNF", JOB_TYPE.HEAL_VNF, ns_instance_id) try: logger.debug("Enter HealNSView::post %s", request.data) logger.debug("Enter HealNSView:: %s", ns_instance_id) @@ -41,7 +42,6 @@ class HealNSView(APIView): if not req_serializer.is_valid(): logger.debug("request.data is not valid,error: %s" % req_serializer.errors) raise BadRequestException(req_serializer.errors) - job_id = JobUtil.create_job("VNF", JOB_TYPE.HEAL_VNF, ns_instance_id) nsHealService = NSHealService(ns_instance_id, request.data, job_id) nsHealService.start() response = Response(data={}, status=status.HTTP_202_ACCEPTED) @@ -51,8 +51,11 @@ class HealNSView(APIView): return response except BadRequestException as e: logger.error("Exception in HealNS: %s", e.message) + JobUtil.add_job_status(job_id, 255, 'NS heal 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("Exception in HealNSView: %s", e.message) - return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + JobUtil.add_job_status(job_id, 255, 'NS heal failed: %s' % e.message) + data = {'status': status.HTTP_500_INTERNAL_SERVER_ERROR, 'detail': e.message} + return Response(data=data, status=status.HTTP_500_INTERNAL_SERVER_ERROR) diff --git a/lcm/ns/views/sol/scale_ns_views.py b/lcm/ns/views/sol/scale_ns_views.py index 34776049..a86805ce 100644 --- a/lcm/ns/views/sol/scale_ns_views.py +++ b/lcm/ns/views/sol/scale_ns_views.py @@ -12,18 +12,17 @@ # 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 logger = logging.getLogger(__name__) @@ -32,7 +31,7 @@ class ScaleNSView(APIView): @swagger_auto_schema( request_body=ManualScaleNsReqSerializer(help_text="NS manual scale"), responses={ - status.HTTP_202_ACCEPTED: _NsOperateJobSerializer(), + status.HTTP_202_ACCEPTED: None, status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error" } ) @@ -43,16 +42,20 @@ class ScaleNSView(APIView): 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 NSHealView") + return response + except BadRequestException as e: + logger.error("Exception in HealNS: %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 HealNSView: %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) diff --git a/lcm/ns/views/sol/terminate_ns_view.py b/lcm/ns/views/sol/terminate_ns_view.py index c6213820..d031a513 100644 --- a/lcm/ns/views/sol/terminate_ns_view.py +++ b/lcm/ns/views/sol/terminate_ns_view.py @@ -39,6 +39,7 @@ class TerminateNsView(APIView): } ) def post(self, request, ns_instance_id): + job_id = JobUtil.create_job("NS", JOB_TYPE.TERMINATE_NS, ns_instance_id) try: logger.debug("Enter TerminateNSView::post %s", request.data) req_serializer = TerminateNsReqSerializer(data=request.data) @@ -48,7 +49,6 @@ class TerminateNsView(APIView): terminationTime = ignore_case_get(request.data, 'terminationTime') logger.debug("terminationTime is %s" % terminationTime) # todo terminationTime - job_id = JobUtil.create_job("NS", JOB_TYPE.TERMINATE_NS, ns_instance_id) terminateNsService = TerminateNsService(ns_instance_id, job_id, request.data) terminateNsService.start() logger.debug("Location: %s" % terminateNsService.occ_id) @@ -57,9 +57,11 @@ class TerminateNsView(APIView): return response except BadRequestException as e: logger.error("Exception in CreateNS: %s", e.message) + JobUtil.add_job_status(job_id, 255, 'NS termination 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("Exception in CreateNS: %s", e.message) + JobUtil.add_job_status(job_id, 255, 'NS termination failed: %s' % e.message) data = {'status': status.HTTP_400_BAD_REQUEST, 'detail': e.message} return Response(data=data, status=status.HTTP_500_INTERNAL_SERVER_ERROR) |