aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormaopengzhang <zhang.maopeng1@zte.com.cn>2019-03-26 15:44:32 +0800
committermaopengzhang <zhang.maopeng1@zte.com.cn>2019-03-26 15:44:32 +0800
commitf329c36b11390cf8f6718bc366e67e07bb4b787b (patch)
tree89f5fa76be756e89f9dc83796466139d379756c9
parent1be57ef9fe3b8e41c03d75717fba78cc24dca10b (diff)
add NS update for occs
add NS update for occs Change-Id: I6adeaa54a31c47211d4ea7c2c23858499060dc2e Issue-ID: VFC-1059 Signed-off-by: maopengzhang <zhang.maopeng1@zte.com.cn>
-rw-r--r--lcm/ns/biz/create_subscription.py2
-rw-r--r--lcm/ns/biz/ns_update.py8
-rw-r--r--lcm/ns/views/sol/heal_ns_view.py5
-rw-r--r--lcm/ns/views/sol/instantiate_ns_views.py11
-rw-r--r--lcm/ns/views/sol/scale_ns_views.py15
-rw-r--r--lcm/ns/views/sol/terminate_ns_view.py8
-rw-r--r--lcm/ns/views/sol/update_ns_view.py39
7 files changed, 52 insertions, 36 deletions
diff --git a/lcm/ns/biz/create_subscription.py b/lcm/ns/biz/create_subscription.py
index e0831d79..907353a9 100644
--- a/lcm/ns/biz/create_subscription.py
+++ b/lcm/ns/biz/create_subscription.py
@@ -1,4 +1,4 @@
-# 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.
diff --git a/lcm/ns/biz/ns_update.py b/lcm/ns/biz/ns_update.py
index eba18c68..110bf14b 100644
--- a/lcm/ns/biz/ns_update.py
+++ b/lcm/ns/biz/ns_update.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.pub.utils.enumutil import enum
+from lcm.ns.biz.ns_lcm_op_occ import NsLcmOpOcc
JOB_ERROR = 255
logger = logging.getLogger(__name__)
@@ -37,7 +38,7 @@ class NSUpdateService(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.update_type = ''
self.operate_vnf_data = ''
@@ -47,9 +48,11 @@ class NSUpdateService(threading.Thread):
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')
@@ -58,6 +61,7 @@ class NSUpdateService(threading.Thread):
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)
diff --git a/lcm/ns/views/sol/heal_ns_view.py b/lcm/ns/views/sol/heal_ns_view.py
index d1ba916b..278418f4 100644
--- a/lcm/ns/views/sol/heal_ns_view.py
+++ b/lcm/ns/views/sol/heal_ns_view.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.
@@ -21,6 +21,7 @@ from lcm.ns.serializers.sol.heal_serializers import HealNsReqSerializer
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__)
@@ -30,7 +31,7 @@ class HealNSView(APIView):
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):
diff --git a/lcm/ns/views/sol/instantiate_ns_views.py b/lcm/ns/views/sol/instantiate_ns_views.py
index 83331007..2e7da17c 100644
--- a/lcm/ns/views/sol/instantiate_ns_views.py
+++ b/lcm/ns/views/sol/instantiate_ns_views.py
@@ -22,6 +22,7 @@ from lcm.ns.biz.ns_instant import InstantNSService
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__)
@@ -31,11 +32,11 @@ class InstantiateNsView(APIView):
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)
@@ -47,13 +48,13 @@ class InstantiateNsView(APIView):
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)
diff --git a/lcm/ns/views/sol/scale_ns_views.py b/lcm/ns/views/sol/scale_ns_views.py
index a86805ce..570195d7 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.
@@ -23,20 +23,21 @@ 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: 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)
@@ -47,15 +48,15 @@ class ScaleNSView(APIView):
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)
diff --git a/lcm/ns/views/sol/terminate_ns_view.py b/lcm/ns/views/sol/terminate_ns_view.py
index d031a513..e5e072a7 100644
--- a/lcm/ns/views/sol/terminate_ns_view.py
+++ b/lcm/ns/views/sol/terminate_ns_view.py
@@ -25,6 +25,7 @@ from lcm.pub.utils.values import ignore_case_get
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__)
@@ -35,7 +36,7 @@ class TerminateNsView(APIView):
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):
@@ -54,14 +55,15 @@ class TerminateNsView(APIView):
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)
diff --git a/lcm/ns/views/sol/update_ns_view.py b/lcm/ns/views/sol/update_ns_view.py
index 5b412eee..91b916db 100644
--- a/lcm/ns/views/sol/update_ns_view.py
+++ b/lcm/ns/views/sol/update_ns_view.py
@@ -20,10 +20,11 @@ from rest_framework.response import Response
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__)
@@ -32,26 +33,32 @@ class UpdateNSView(APIView):
@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)