Add lcm op occ to chg flavour 23/86123/3
authorfujinhua <fu.jinhua@zte.com.cn>
Wed, 24 Apr 2019 07:54:04 +0000 (15:54 +0800)
committerfujinhua <fu.jinhua@zte.com.cn>
Wed, 24 Apr 2019 08:04:43 +0000 (16:04 +0800)
Change-Id: I833293a5876dd51a4035b05e6043af10ed6c776f
Issue-ID: VFC-1306
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
lcm/lcm/nf/biz/change_vnf_flavour.py

index f487168..7e1eaa7 100644 (file)
@@ -20,12 +20,15 @@ from threading import Thread
 from lcm.nf.biz.grant_vnf import grant_resource
 from lcm.nf.const import GRANT_TYPE, CHANGE_TYPE
 from lcm.nf.const import VNF_STATUS
+from lcm.nf.const import OPERATION_TYPE, OPERATION_TASK
+from lcm.nf.const import OPERATION_STATE_TYPE
 from lcm.pub.utils.notificationsutil import NotificationsUtil, prepare_notification_data
 from lcm.pub.utils.values import ignore_case_get
 from lcm.pub.utils.timeutil import now_time
 from lcm.pub.utils.jobutil import JobUtil
 from lcm.pub.exceptions import NFLCMException
 from lcm.pub.database.models import NfInstModel
+from .operate_vnf_lcm_op_occ import VnfLcmOpOcc
 
 logger = logging.getLogger(__name__)
 
@@ -37,13 +40,21 @@ class ChangeVnfFlavour(Thread):
         self.nf_inst_id = nf_inst_id
         self.job_id = job_id
         self.vnf_insts = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
+        self.lcm_op_occ = VnfLcmOpOcc(
+            vnf_inst_id=nf_inst_id,
+            lcm_op_id=job_id,
+            operation=OPERATION_TYPE.CHANGE_FLAVOUR,
+            task=OPERATION_TASK.CHANGE_FLAVOUR
+        )
 
     def run(self):
         try:
+            self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.STARTING)
             JobUtil.add_job_status(self.job_id,
                                    10,
                                    "Start to apply grant.")
             self.apply_grant()
+            self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.PROCESSING)
             JobUtil.add_job_status(self.job_id,
                                    50,
                                    "Start to change vnf flavour.")
@@ -53,6 +64,7 @@ class ChangeVnfFlavour(Thread):
                 lastuptime=now_time()
             )
             self.send_notification()
+            self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.COMPLETED)
             JobUtil.add_job_status(self.job_id,
                                    100,
                                    "Change vnf flavour success.")
@@ -91,4 +103,5 @@ class ChangeVnfFlavour(Thread):
         logger.error('Chnage vnf flavour failed, detail message: %s', error_msg)
         self.vnf_insts.update(status=VNF_STATUS.FAILED,
                               lastuptime=now_time())
+        self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.FAILED)
         JobUtil.add_job_status(self.job_id, 255, error_msg)