summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFu Jinhua <fu.jinhua@zte.com.cn>2018-08-28 11:52:13 +0000
committerGerrit Code Review <gerrit@onap.org>2018-08-28 11:52:13 +0000
commit5f53ec675ea9ba441c2047e2ab1e918fb5147c9e (patch)
tree7f500db11be491561b13bcffcdd4b65e9de5c67f
parent986a280b3f4602a7271a167c986d4ab9f36af22d (diff)
parent18380b1d587c0f6162468bb05689b7b52069db8d (diff)
Merge "Deal with nfPackage"
-rw-r--r--catalog/packages/biz/vnf_package.py8
-rw-r--r--catalog/packages/views/vnf_package_views.py6
2 files changed, 13 insertions, 1 deletions
diff --git a/catalog/packages/biz/vnf_package.py b/catalog/packages/biz/vnf_package.py
index da5cc566..7f3511d8 100644
--- a/catalog/packages/biz/vnf_package.py
+++ b/catalog/packages/biz/vnf_package.py
@@ -89,6 +89,8 @@ def delete_vnf_pkg(vnf_pkg_id):
def parse_vnfd_and_save(vnf_pkg_id, vnf_pkg_path):
+ vnf_pkg = VnfPackageModel.objects.filter(vnfPackageId=vnf_pkg_id)
+ vnf_pkg.update(onboardingState="PROCESSING")
vnfd_json = toscaparser.parse_vnfd(vnf_pkg_path)
vnfd = json.JSONDecoder().decode(vnfd_json)
@@ -136,6 +138,7 @@ class VnfPkgUploadThread(threading.Thread):
vnf_pkg = VnfPackageModel.objects.filter(vnfPackageId=self.vnf_pkg_id)
if vnf_pkg[0].onboardingState != "CREATED":
raise CatalogException("VNF package (%s) is not created" % self.vnf_pkg_id)
+ vnf_pkg.update(onboardingState="UPLOADING")
uri = ignore_case_get(self.data, "addressInformation")
upload_path = os.path.join(CATALOG_ROOT_PATH, self.vnf_pkg_id)
if not os.path.exists(upload_path):
@@ -194,3 +197,8 @@ def fetch_vnf_pkg(request, vnf_pkg_id):
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment; filename=%s' % file_name.encode('utf-8')
return response
+
+
+def handle_upload_failed(vnf_pkg_id):
+ vnf_pkg = VnfPackageModel.objects.filter(vnfPackageId=vnf_pkg_id)
+ vnf_pkg.update(onboardingState="CREATED")
diff --git a/catalog/packages/views/vnf_package_views.py b/catalog/packages/views/vnf_package_views.py
index 2bdd3eb8..26244dd9 100644
--- a/catalog/packages/views/vnf_package_views.py
+++ b/catalog/packages/views/vnf_package_views.py
@@ -27,7 +27,7 @@ from catalog.packages.serializers.create_vnf_pkg_info_req import CreateVnfPkgInf
from catalog.packages.serializers.vnf_pkg_info import VnfPkgInfoSerializer
from catalog.packages.serializers.vnf_pkg_infos import VnfPkgInfosSerializer
from catalog.packages.biz.vnf_package import create_vnf_pkg, query_multiple, VnfPkgUploadThread, \
- query_single, delete_vnf_pkg, parse_vnfd_and_save, fetch_vnf_pkg
+ query_single, delete_vnf_pkg, parse_vnfd_and_save, fetch_vnf_pkg, handle_upload_failed
from catalog.pub.database.models import VnfPackageModel
logger = logging.getLogger(__name__)
@@ -128,10 +128,12 @@ def upload_vnf_pkg_content(request, vnfPkgId):
parse_vnfd_and_save(vnfPkgId, upload_file_name)
return Response(None, status=status.HTTP_202_ACCEPTED)
except CatalogException:
+ handle_upload_failed(vnfPkgId)
logger.error(traceback.format_exc())
return Response(data={'error': 'Upload VNF package failed.'},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
except Exception as e:
+ handle_upload_failed(vnfPkgId)
logger.error(e.message)
logger.error(traceback.format_exc())
return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
@@ -168,9 +170,11 @@ def upload_vnf_pkg_from_uri(request, vnfPkgId):
VnfPkgUploadThread(req_serializer.data, vnfPkgId).start()
return Response(None, status=status.HTTP_202_ACCEPTED)
except CatalogException:
+ handle_upload_failed(vnfPkgId)
logger.error(traceback.format_exc())
return Response(data={'error': 'Upload VNF package failed.'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
except Exception as e:
+ handle_upload_failed(vnfPkgId)
logger.error(e.message)
logger.error(traceback.format_exc())
return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)