-# Copyright (c) 2019, CMCC Technologies Co., Ltd.
+# Copyright (c) 2019, ZTE Corporation.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
from lcm.pub.utils.jobutil import JobUtil, JOB_MODEL_STATUS
from lcm.pub.utils.values import ignore_case_get
from lcm.pub.utils.enumutil import enum
+from lcm.ns.biz.ns_lcm_op_occ import NsLcmOpOcc
JOB_ERROR = 255
logger = logging.getLogger(__name__)
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.update_type = ''
self.operate_vnf_data = ''
except NSLCMException as e:
logger.error(traceback.format_exc())
JobUtil.add_job_status(self.job_id, JOB_ERROR, e.message)
- except:
+ NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.message)
+ except Exception as e:
logger.error(traceback.format_exc())
JobUtil.add_job_status(self.job_id, JOB_ERROR, 'ns update fail')
+ NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.message)
def do_biz(self):
self.update_job(1, desc='ns update start')
self.do_update()
self.update_ns_status(NS_INST_STATUS.ACTIVE)
self.update_job(100, desc='ns update success')
+ NsLcmOpOcc.update(self.occ_id, "COMPLETED")
def get_and_check_params(self):
ns_info = NSInstModel.objects.filter(id=self.ns_instance_id)
-# 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.
from lcm.pub.exceptions import BadRequestException
from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
from lcm.ns.const import NS_OCC_BASE_URI
+from lcm.ns.serializers.sol.pub_serializers import ProblemDetailsSerializer
logger = logging.getLogger(__name__)
request_body=HealNsReqSerializer(),
responses={
status.HTTP_202_ACCEPTED: None,
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error"
+ status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
}
)
def post(self, request, ns_instance_id):
from lcm.ns.serializers.sol.inst_ns_serializers import InstantNsReqSerializer
from lcm.pub.exceptions import BadRequestException
from lcm.ns.const import NS_OCC_BASE_URI
+from lcm.ns.serializers.sol.pub_serializers import ProblemDetailsSerializer
logger = logging.getLogger(__name__)
request_body=InstantNsReqSerializer(),
responses={
status.HTTP_202_ACCEPTED: None,
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error"
+ status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
}
)
def post(self, request, ns_instance_id):
- logger.debug("Enter NSInstView::post::ns_instance_id=%s", ns_instance_id)
+ logger.debug("Enter InstantiateNsView::post::ns_instance_id=%s", ns_instance_id)
logger.debug("request.data=%s", request.data)
try:
req_serializer = InstantNsReqSerializer(data=request.data)
response = Response(data={}, status=status.HTTP_202_ACCEPTED)
logger.debug("Location: %s" % ack['occ_id'])
response["Location"] = NS_OCC_BASE_URI % nsLcmOpOccId
- logger.debug("Leave NSInstView::post::ack=%s", ack)
+ logger.debug("Leave InstantiateNsView::post::ack=%s", ack)
return response
except BadRequestException as e:
- logger.error("Exception in CreateNS: %s", e.message)
+ logger.error("Exception in InstantiateNsView: %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)
+ logger.error("Exception in InstantiateNsView: %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)
-# 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.
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: None,
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error"
+ 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)
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")
+ logger.debug("Leave ScaleNSView")
return response
except BadRequestException as e:
- logger.error("Exception in HealNS: %s", e.message)
+ 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("Exception in HealNSView: %s", e.message)
+ 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_500_INTERNAL_SERVER_ERROR, 'detail': e.message}
return Response(data=data, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
from lcm.ns.serializers.sol.terminate_ns_serializers import TerminateNsReqSerializer
from lcm.pub.exceptions import BadRequestException
from lcm.ns.const import NS_OCC_BASE_URI
+from lcm.ns.serializers.sol.pub_serializers import ProblemDetailsSerializer
logger = logging.getLogger(__name__)
request_body=TerminateNsReqSerializer(),
responses={
status.HTTP_202_ACCEPTED: None,
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error"
+ status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
}
)
def post(self, request, ns_instance_id):
logger.debug("Location: %s" % terminateNsService.occ_id)
response = Response(data={}, status=status.HTTP_202_ACCEPTED)
response["Location"] = NS_OCC_BASE_URI % terminateNsService.occ_id
+ logger.debug("Leave TerminateNSView")
return response
except BadRequestException as e:
- logger.error("Exception in CreateNS: %s", e.message)
+ logger.error("Exception in TerminateNsView: %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)
+ logger.error("Exception in TerminateNsView: %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)
from rest_framework.views import APIView
from lcm.ns.biz.ns_update import NSUpdateService
-from lcm.ns.serializers.deprecated.ns_serializers import _NsOperateJobSerializer
from lcm.ns.serializers.sol.update_serializers import UpdateNsReqSerializer
-from lcm.pub.exceptions import NSLCMException
+from lcm.pub.exceptions import BadRequestException
from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
+from lcm.ns.const import NS_OCC_BASE_URI
+from lcm.ns.serializers.sol.pub_serializers import ProblemDetailsSerializer
logger = logging.getLogger(__name__)
@swagger_auto_schema(
request_body=UpdateNsReqSerializer(),
responses={
- status.HTTP_202_ACCEPTED: _NsOperateJobSerializer(),
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error"
+ status.HTTP_202_ACCEPTED: None,
+ status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
}
)
def post(self, request, ns_instance_id):
+ job_id = JobUtil.create_job("NS", JOB_TYPE.UPDATE_NS, ns_instance_id)
try:
logger.debug("Enter UpdateNSView::post %s, %s", request.data, ns_instance_id)
req_serializer = UpdateNsReqSerializer(data=request.data)
if not req_serializer.is_valid():
- raise NSLCMException(req_serializer.errors)
-
- job_id = JobUtil.create_job("NS", JOB_TYPE.UPDATE_NS, ns_instance_id)
- NSUpdateService(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)
-
- logger.debug("Leave UpdateNSView::post ret=%s", resp_serializer.data)
- return Response(data=resp_serializer.data, status=status.HTTP_202_ACCEPTED)
+ logger.debug("request.data is not valid,error: %s" % req_serializer.errors)
+ raise BadRequestException(req_serializer.errors)
+ nsUpdateService = NSUpdateService(ns_instance_id, request.data, job_id)
+ nsUpdateService.start()
+ response = Response(data={}, status=status.HTTP_202_ACCEPTED)
+ logger.debug("Location: %s" % nsUpdateService.occ_id)
+ response["Location"] = NS_OCC_BASE_URI % nsUpdateService.occ_id
+ logger.debug("Leave UpdateNSView")
+ return response
+ except BadRequestException as e:
+ logger.error("Exception in UpdateNSView: %s", e.message)
+ JobUtil.add_job_status(job_id, 255, 'NS update 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 UpdateNSView: %s", e.message)
- return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ JobUtil.add_job_status(job_id, 255, 'NS update 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)