update the errorCode in job information 85/102285/1
authordyh <dengyuanhong@chinamobile.com>
Tue, 25 Feb 2020 06:26:21 +0000 (14:26 +0800)
committerdyh <dengyuanhong@chinamobile.com>
Tue, 25 Feb 2020 06:26:57 +0000 (14:26 +0800)
Change-Id: Ic44082580d585f538dfed2ea0445e2100e7ce221
Issue-ID: MODELING-318
Signed-off-by: dyh <dengyuanhong@chinamobile.com>
catalog/packages/biz/sdc_vnf_package.py
catalog/pub/utils/jobutil.py

index 2160a00..5f62d7e 100644 (file)
@@ -25,11 +25,11 @@ from catalog.packages.const import PKG_STATUS
 from catalog.pub.config.config import CATALOG_ROOT_PATH, CATALOG_URL_PATH
 from catalog.pub.config.config import REG_TO_MSB_REG_PARAM
 from catalog.pub.database.models import VnfPackageModel
-from catalog.pub.exceptions import CatalogException
+from catalog.pub.exceptions import CatalogException, PackageHasExistsException
 from catalog.pub.msapi import sdc
 from catalog.pub.utils import fileutil
 from catalog.pub.utils import toscaparser
-from catalog.pub.utils.jobutil import JobUtil
+from catalog.pub.utils.jobutil import JobUtil, JOB_ERROR_CODE
 
 logger = logging.getLogger(__name__)
 
@@ -96,15 +96,19 @@ class NfDistributeThread(threading.Thread):
     def run(self):
         try:
             self.on_distribute()
+        except PackageHasExistsException as e:
+            self.rollback_distribute()
+            JobUtil.add_job_status(self.job_id, JOB_ERROR, e.args[0], error_code=JOB_ERROR_CODE.PACKAGE_EXIST)
         except CatalogException as e:
             self.rollback_distribute()
-            JobUtil.add_job_status(self.job_id, JOB_ERROR, e.args[0])
+            JobUtil.add_job_status(self.job_id, JOB_ERROR, e.args[0], error_code=JOB_ERROR_CODE.CATALOG_EXCEPTION)
         except Exception as e:
             logger.error(e.args[0])
             logger.error(traceback.format_exc())
             logger.error(str(sys.exc_info()))
             self.rollback_distribute()
-            JobUtil.add_job_status(self.job_id, JOB_ERROR, "Failed to distribute CSAR(%s)" % self.csar_id)
+            JobUtil.add_job_status(self.job_id, JOB_ERROR, "Failed to distribute CSAR(%s)" % self.csar_id,
+                                   error_code=JOB_ERROR_CODE.SYSTEM_ERROR)
 
     def on_distribute(self):
         JobUtil.create_job(
@@ -116,7 +120,7 @@ class NfDistributeThread(threading.Thread):
 
         if VnfPackageModel.objects.filter(vnfPackageId=self.csar_id):
             err_msg = "NF CSAR(%s) already exists." % self.csar_id
-            JobUtil.add_job_status(self.job_id, JOB_ERROR, err_msg)
+            JobUtil.add_job_status(self.job_id, JOB_ERROR, err_msg, error_code=JOB_ERROR_CODE.PACKAGE_EXIST)
             return
 
         artifact = sdc.get_artifact(sdc.ASSETTYPE_RESOURCES, self.csar_id)
@@ -156,7 +160,7 @@ class NfDistributeThread(threading.Thread):
         vnfd_id = vnfd["vnf"]["properties"].get("descriptor_id", "")
         if VnfPackageModel.objects.filter(vnfdId=vnfd_id):
             logger.error("VNF package(%s) already exists.", vnfd_id)
-            raise CatalogException("VNF package(%s) already exists." % vnfd_id)
+            raise PackageHasExistsException("VNF package(%s) already exists." % vnfd_id)
         JobUtil.add_job_status(self.job_id, 30, "Save CSAR(%s) to database." % self.csar_id)
         vnfd_ver = vnfd["vnf"]["properties"].get("descriptor_version", "")
         vnf_provider = vnfd["vnf"]["properties"].get("provider", "")
index 5c35350..c2e1c15 100644 (file)
@@ -13,8 +13,8 @@
 # limitations under the License.
 import datetime
 import logging
-import uuid
 import traceback
+import uuid
 from functools import reduce
 
 from catalog.pub.database.models import JobStatusModel, JobModel
@@ -29,8 +29,10 @@ def enum(**enums):
 JOB_STATUS = enum(PROCESSING=0, FINISH=1)
 JOB_MODEL_STATUS = enum(STARTED='started', PROCESSING='processing', FINISHED='finished', ERROR='error',
                         TIMEOUT='timeout')
-JOB_TYPE = enum(CREATE_VNF="create vnf", TERMINATE_VNF="terminate vnf", GRANT_VNF="grant vnf", MANUAL_SCALE_VNF="manual scale vnf",
+JOB_TYPE = enum(CREATE_VNF="create vnf", TERMINATE_VNF="terminate vnf", GRANT_VNF="grant vnf",
+                MANUAL_SCALE_VNF="manual scale vnf",
                 HEAL_VNF="heal vnf")
+JOB_ERROR_CODE = enum(NORMAL=0, PACKAGE_EXIST=1, CATALOG_EXCEPTION=2, SYSTEM_ERROR=3)
 
 
 class JobUtil(object):