aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFu Jinhua <fu.jinhua@zte.com.cn>2019-03-26 09:51:52 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-26 09:51:52 +0000
commited2ee53dbf5189df383f022e897f53eb02796ebb (patch)
tree4ca210479c8c957cebe69fec3e1bf9bd48929c5a
parentc52d182d9708a0c95d3af733c15b2c5f266f0583 (diff)
parent5dbd3749dc5ba945a09bedcb159799a2fd2704ed (diff)
Merge "seperate NS heal\scale\operation for occs"
-rw-r--r--lcm/ns/biz/ns_heal.py9
-rw-r--r--lcm/ns/urls.py23
-rw-r--r--lcm/ns/views/deprecated/heal_ns_view.py57
-rw-r--r--lcm/ns/views/deprecated/scale_ns_views.py58
-rw-r--r--lcm/ns/views/deprecated/term_ns_view.py2
-rw-r--r--lcm/ns/views/deprecated/update_ns_view.py57
-rw-r--r--lcm/ns/views/sol/heal_ns_view.py33
-rw-r--r--lcm/ns/views/sol/scale_ns_views.py2
-rw-r--r--lcm/ns/views/sol/update_ns_view.py2
9 files changed, 215 insertions, 28 deletions
diff --git a/lcm/ns/biz/ns_heal.py b/lcm/ns/biz/ns_heal.py
index c25be70a..e7d5794a 100644
--- a/lcm/ns/biz/ns_heal.py
+++ b/lcm/ns/biz/ns_heal.py
@@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+
import datetime
import logging
import threading
@@ -23,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.heal_vnfs import NFHealService
+from lcm.ns.biz.ns_lcm_op_occ import NsLcmOpOcc
JOB_ERROR = 255
logger = logging.getLogger(__name__)
@@ -34,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.heal_vnf_data = ''
self.heal_ns_data = ''
@@ -43,9 +45,11 @@ class NSHealService(threading.Thread):
self.do_biz()
except NSLCMException as e:
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 heal fail')
+ NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.message)
def do_biz(self):
self.update_job(1, desc='ns heal start')
@@ -54,6 +58,7 @@ class NSHealService(threading.Thread):
self.do_heal()
self.update_ns_status(NS_INST_STATUS.ACTIVE)
self.update_job(100, desc='ns heal 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/urls.py b/lcm/ns/urls.py
index 153d5702..529883a9 100644
--- a/lcm/ns/urls.py
+++ b/lcm/ns/urls.py
@@ -13,27 +13,33 @@
# limitations under the License.
from django.conf.urls import url
-from lcm.ns.views.sol.scale_ns_views import NSManualScaleView
-from lcm.ns.views.sol.update_ns_view import NSUpdateView
+
+
from rest_framework.urlpatterns import format_suffix_patterns
from lcm.ns.views.deprecated.create_ns_view import CreateNSView
from lcm.ns.views.deprecated.get_del_ns_view import NSDetailView
from lcm.ns.views.deprecated.inst_ns_post_deal_view import NSInstPostDealView
from lcm.ns.views.deprecated.inst_ns_view import NSInstView
-from lcm.ns.views.deprecated.term_ns_view import TerminateNSView
-from lcm.ns.views.sol.heal_ns_view import NSHealView
+from lcm.ns.views.deprecated.term_ns_view import NSTerminateView
+from lcm.ns.views.deprecated.heal_ns_view import NSHealView
+from lcm.ns.views.deprecated.scale_ns_views import NSManualScaleView
+from lcm.ns.views.deprecated.update_ns_view import NSUpdateView
+
from lcm.ns.views.sol.lcm_op_occs_view import QueryMultiNsLcmOpOccs, QuerySingleNsLcmOpOcc
from lcm.ns.views.sol.ns_instances_views import NSInstancesView, IndividualNsInstanceView
from lcm.ns.views.sol.instantiate_ns_views import InstantiateNsView
from lcm.ns.views.sol.terminate_ns_view import TerminateNsView
from lcm.ns.views.sol.subscriptions_view import SubscriptionsView
+from lcm.ns.views.sol.update_ns_view import UpdateNSView
+from lcm.ns.views.sol.scale_ns_views import ScaleNSView
+from lcm.ns.views.sol.heal_ns_view import HealNSView
urlpatterns = [
# API will be deprecated in the future release
url(r'^api/nslcm/v1/ns$', CreateNSView.as_view()),
url(r'^api/nslcm/v1/ns/(?P<ns_instance_id>[0-9a-zA-Z_-]+)/instantiate$', NSInstView.as_view()),
- url(r'^api/nslcm/v1/ns/(?P<ns_instance_id>[0-9a-zA-Z_-]+)/terminate$', TerminateNSView.as_view()),
+ url(r'^api/nslcm/v1/ns/(?P<ns_instance_id>[0-9a-zA-Z_-]+)/terminate$', NSTerminateView.as_view()),
url(r'^api/nslcm/v1/ns/(?P<ns_instance_id>[0-9a-zA-Z_-]+)$', NSDetailView.as_view()),
url(r'^api/nslcm/v1/ns/(?P<ns_instance_id>[0-9a-zA-Z_-]+)/postdeal$', NSInstPostDealView.as_view()),
url(r'^api/nslcm/v1/ns/(?P<ns_instance_id>[0-9a-zA-Z_-]+)/scale$', NSManualScaleView.as_view()),
@@ -44,10 +50,13 @@ urlpatterns = [
url(r'^api/nslcm/v1/ns_instances$', NSInstancesView.as_view()),
url(r'^api/nslcm/v1/ns_instances/(?P<ns_instance_id>[0-9a-zA-Z_-]+)/instantiate$', InstantiateNsView.as_view()),
url(r'^api/nslcm/v1/ns_instances/(?P<ns_instance_id>[0-9a-zA-Z_-]+)/terminate$', TerminateNsView.as_view()),
+ url(r'^api/nslcm/v1/ns_lcm_op_occs/(?P<lcmopoccid>[0-9a-zA-Z_-]+)$', QuerySingleNsLcmOpOcc.as_view()),
+ url(r'^api/nslcm/v1/ns_instances/(?P<ns_instance_id>[0-9a-zA-Z_-]+)/update$', UpdateNSView.as_view()),
+ url(r'^api/nslcm/v1/ns_instances/(?P<ns_instance_id>[0-9a-zA-Z_-]+)/scale$', ScaleNSView.as_view()),
+ url(r'^api/nslcm/v1/ns_instances/(?P<ns_instance_id>[0-9a-zA-Z_-]+)/heal$', HealNSView.as_view()),
url(r'^api/nslcm/v1/ns_instances/(?P<ns_instance_id>[0-9a-zA-Z_-]+)$', IndividualNsInstanceView.as_view()),
url(r'^api/nslcm/v1/subscriptions$', SubscriptionsView.as_view()),
- url(r'^api/nslcm/v1/ns_lcm_op_occs$', QueryMultiNsLcmOpOccs.as_view()),
- url(r'^api/nslcm/v1/ns_lcm_op_occs/(?P<lcmopoccid>[0-9a-zA-Z_-]+)$', QuerySingleNsLcmOpOcc.as_view()),
+ url(r'^api/nslcm/v1/ns_lcm_op_occs$', QueryMultiNsLcmOpOccs.as_view())
]
diff --git a/lcm/ns/views/deprecated/heal_ns_view.py b/lcm/ns/views/deprecated/heal_ns_view.py
new file mode 100644
index 00000000..87519654
--- /dev/null
+++ b/lcm/ns/views/deprecated/heal_ns_view.py
@@ -0,0 +1,57 @@
+# Copyright 2016-2017 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+import logging
+
+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_heal import NSHealService
+from lcm.ns.serializers.deprecated.ns_serializers import _HealNsReqSerializer
+from lcm.ns.serializers.deprecated.ns_serializers import _NsOperateJobSerializer
+from lcm.pub.exceptions import NSLCMException
+from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
+
+logger = logging.getLogger(__name__)
+
+
+class NSHealView(APIView):
+ @swagger_auto_schema(
+ request_body=_HealNsReqSerializer(),
+ responses={
+ status.HTTP_202_ACCEPTED: _NsOperateJobSerializer(),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error"
+ }
+ )
+ def post(self, request, ns_instance_id):
+ try:
+ logger.debug("Enter HealNSView::post %s", request.data)
+ logger.debug("Enter HealNSView:: %s", ns_instance_id)
+ req_serializer = _HealNsReqSerializer(data=request.data)
+ if not req_serializer.is_valid():
+ raise NSLCMException(req_serializer.errors)
+
+ job_id = JobUtil.create_job("VNF", JOB_TYPE.HEAL_VNF, ns_instance_id)
+ NSHealService(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 HealNSView::post ret=%s", resp_serializer.data)
+ return Response(data=resp_serializer.data, status=status.HTTP_202_ACCEPTED)
+ 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)
diff --git a/lcm/ns/views/deprecated/scale_ns_views.py b/lcm/ns/views/deprecated/scale_ns_views.py
new file mode 100644
index 00000000..ee37532c
--- /dev/null
+++ b/lcm/ns/views/deprecated/scale_ns_views.py
@@ -0,0 +1,58 @@
+# Copyright 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# 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.deprecated.ns_serializers import _ManualScaleNsReqSerializer
+from lcm.pub.exceptions import NSLCMException
+from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
+
+logger = logging.getLogger(__name__)
+
+
+class NSManualScaleView(APIView):
+ @swagger_auto_schema(
+ request_body=_ManualScaleNsReqSerializer(help_text="NS manual scale"),
+ responses={
+ status.HTTP_202_ACCEPTED: _NsOperateJobSerializer(),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error"
+ }
+ )
+ def post(self, request, ns_instance_id):
+ logger.debug("Enter NSManualScaleView::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)
+ except Exception as e:
+ logger.error(traceback.format_exc())
+ 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)
diff --git a/lcm/ns/views/deprecated/term_ns_view.py b/lcm/ns/views/deprecated/term_ns_view.py
index b61d6d0c..870615d4 100644
--- a/lcm/ns/views/deprecated/term_ns_view.py
+++ b/lcm/ns/views/deprecated/term_ns_view.py
@@ -26,7 +26,7 @@ from lcm.ns.serializers.deprecated.ns_serializers import _TerminateNsReqSerializ
logger = logging.getLogger(__name__)
-class TerminateNSView(APIView):
+class NSTerminateView(APIView):
@swagger_auto_schema(
request_body=_TerminateNsReqSerializer(),
responses={
diff --git a/lcm/ns/views/deprecated/update_ns_view.py b/lcm/ns/views/deprecated/update_ns_view.py
new file mode 100644
index 00000000..12bcf6ad
--- /dev/null
+++ b/lcm/ns/views/deprecated/update_ns_view.py
@@ -0,0 +1,57 @@
+# Copyright (c) 2018, CMCC Technologies Co., Ltd.
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+
+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_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.utils.jobutil import JobUtil, JOB_TYPE
+
+logger = logging.getLogger(__name__)
+
+
+class NSUpdateView(APIView):
+ @swagger_auto_schema(
+ request_body=UpdateNsReqSerializer(),
+ responses={
+ status.HTTP_202_ACCEPTED: _NsOperateJobSerializer(),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error"
+ }
+ )
+ def post(self, request, 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)
+ 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)
diff --git a/lcm/ns/views/sol/heal_ns_view.py b/lcm/ns/views/sol/heal_ns_view.py
index 0d39cf67..d98c972b 100644
--- a/lcm/ns/views/sol/heal_ns_view.py
+++ b/lcm/ns/views/sol/heal_ns_view.py
@@ -12,26 +12,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
-
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_heal import NSHealService
from lcm.ns.serializers.sol.heal_serializers import HealNsReqSerializer
-from lcm.ns.serializers.deprecated.ns_serializers import _NsOperateJobSerializer
-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
logger = logging.getLogger(__name__)
-class NSHealView(APIView):
+class HealNSView(APIView):
@swagger_auto_schema(
request_body=HealNsReqSerializer(),
responses={
- status.HTTP_202_ACCEPTED: _NsOperateJobSerializer(),
+ status.HTTP_202_ACCEPTED: None,
status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error"
}
)
@@ -41,17 +39,20 @@ class NSHealView(APIView):
logger.debug("Enter HealNSView:: %s", ns_instance_id)
req_serializer = HealNsReqSerializer(data=request.data)
if not req_serializer.is_valid():
- raise NSLCMException(req_serializer.errors)
-
+ 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(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 HealNSView::post ret=%s", resp_serializer.data)
- return Response(data=resp_serializer.data, status=status.HTTP_202_ACCEPTED)
+ nsHealService = NSHealService(ns_instance_id, request.data, job_id)
+ nsHealService.start()
+ response = Response(data={}, status=status.HTTP_202_ACCEPTED)
+ logger.debug("Location: %s" % nsHealService.occ_id)
+ response["Location"] = NS_OCC_BASE_URI % nsHealService.occ_id
+ logger.debug("Leave NSHealView")
+ return response
+ except BadRequestException as e:
+ logger.error("Exception in HealNS: %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)
diff --git a/lcm/ns/views/sol/scale_ns_views.py b/lcm/ns/views/sol/scale_ns_views.py
index 717d6e94..34776049 100644
--- a/lcm/ns/views/sol/scale_ns_views.py
+++ b/lcm/ns/views/sol/scale_ns_views.py
@@ -28,7 +28,7 @@ from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
logger = logging.getLogger(__name__)
-class NSManualScaleView(APIView):
+class ScaleNSView(APIView):
@swagger_auto_schema(
request_body=ManualScaleNsReqSerializer(help_text="NS manual scale"),
responses={
diff --git a/lcm/ns/views/sol/update_ns_view.py b/lcm/ns/views/sol/update_ns_view.py
index 12bcf6ad..5b412eee 100644
--- a/lcm/ns/views/sol/update_ns_view.py
+++ b/lcm/ns/views/sol/update_ns_view.py
@@ -28,7 +28,7 @@ from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
logger = logging.getLogger(__name__)
-class NSUpdateView(APIView):
+class UpdateNSView(APIView):
@swagger_auto_schema(
request_body=UpdateNsReqSerializer(),
responses={