Exemplo n.º 1
0
 def do_biz(self):
     self.update_job(JOB_PROGRESS.STARTED, desc='ns scale start')
     self.update_ns_status(NS_INST_STATUS.SCALING)
     self.check_and_set_params()
     self.do_vnfs_scale()
     self.update_job(JOB_PROGRESS.FINISHED, desc='ns scale success')
     NsLcmOpOcc.update(self.occ_id, "COMPLETED")
Exemplo n.º 2
0
 def do_biz(self):
     self.update_job(1, desc='ns heal start')
     self.get_and_check_params()
     self.update_ns_status(NS_INST_STATUS.HEALING)
     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")
Exemplo n.º 3
0
 def do_biz(self):
     self.update_job(JOB_PROGRESS.STARTED, desc='ns update start')
     self.get_and_check_params()
     self.update_ns_status(NS_INST_STATUS.UPDATING)
     self.do_update()
     self.update_ns_status(NS_INST_STATUS.ACTIVE)
     self.update_job(JOB_PROGRESS.FINISHED, desc='ns update success')
     NsLcmOpOcc.update(self.occ_id, "COMPLETED")
Exemplo n.º 4
0
 def run(self):
     try:
         self.do_biz()
     except NSLCMException as e:
         JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, e.args[0])
         NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.args[0])
     except Exception as e:
         logger.error(traceback.format_exc())
         JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, 'ns heal fail')
         NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.args[0])
Exemplo n.º 5
0
 def run(self):
     try:
         self.do_biz()
     except NSLCMException as e:
         JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, e.args[0])
         NsLcmOpOcc.update(self.occ_id,
                           operationState="FAILED",
                           error=e.args[0])
     except Exception as e:
         logger.error(e.args[0])
         logger.error(traceback.format_exc())
         JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR,
                                'ns scale fail')
         NsLcmOpOcc.update(self.occ_id,
                           operationState="FAILED",
                           error=e.args[0])
     finally:
         self.update_ns_status(NS_INST_STATUS.ACTIVE)
Exemplo n.º 6
0
def run_ns_instantiate(input_data, occ_id):
    logger.debug("Enter %s, input_data is %s", fun_name(), input_data)
    ns_instantiate_ok = False
    job_id = ignore_case_get(input_data, "jobId")
    ns_inst_id = ignore_case_get(input_data, "nsInstanceId")
    nsd_json = ignore_case_get(input_data, "object_context")
    ns_param_json = ignore_case_get(input_data, "object_additionalParamForNs")
    vnf_param_json = ignore_case_get(input_data, "object_additionalParamForVnf")
    pnf_param_json = ignore_case_get(input_data, "object_additionalParamForPnf")
    vl_count = int(ignore_case_get(input_data, "vlCount", 0))
    vnf_count = int(ignore_case_get(input_data, "vnfCount", 0))
    sfc_count = int(ignore_case_get(input_data, "sfcCount", 0))
    sdnc_id = ignore_case_get(input_data, "sdnControllerId")
    g_jobs_status[job_id] = [1 for i in range(vnf_count)]
    try:
        update_job(job_id, 10, JOB_ERROR_CODE.NO_ERROR, "Start to create VL")
        for i in range(vl_count):
            create_vl(ns_inst_id, i + 1, nsd_json, ns_param_json)

        update_job(job_id, 30, JOB_ERROR_CODE.NO_ERROR, "Start to create VNF")
        jobs = [create_vnf(ns_inst_id, i + 1, vnf_param_json) for i in range(vnf_count)]
        wait_until_jobs_done(job_id, jobs)

        [confirm_vnf_status(inst_id) for inst_id, _, _ in jobs]

        update_job(job_id, 50, JOB_ERROR_CODE.NO_ERROR, "Start to create PNF")
        create_pnf(pnf_param_json)

        update_job(job_id, 70, JOB_ERROR_CODE.NO_ERROR, "Start to create SFC")
        g_jobs_status[job_id] = [1 for i in range(sfc_count)]
        jobs = [create_sfc(ns_inst_id, i + 1, nsd_json, sdnc_id) for i in range(sfc_count)]
        wait_until_jobs_done(job_id, jobs)

        [confirm_sfc_status(inst_id) for inst_id, _, _ in jobs]

        update_job(job_id, 90, JOB_ERROR_CODE.NO_ERROR, "Start to post deal")
        post_deal(ns_inst_id, "true")

        update_job(job_id, 100, JOB_ERROR_CODE.NO_ERROR, "Create NS successfully.")
        NsLcmOpOcc.update(occ_id, "COMPLETED")
        ns_instantiate_ok = True
    except NSLCMException as e:
        logger.error("Failded to Create NS: %s", e.args[0])
        update_job(job_id, JOB_ERROR, JOB_ERROR_CODE.ERROR, "Failded to Create NS.")
        NsLcmOpOcc.update(occ_id, operationState="FAILED", error=e.args[0])
        post_deal(ns_inst_id, "false")
    except Exception as e:
        logger.error(traceback.format_exc())
        update_job(job_id, JOB_ERROR, JOB_ERROR_CODE.ERROR, "Failded to Create NS.")
        NsLcmOpOcc.update(occ_id, operationState="FAILED", error=e.args[0])
        post_deal(ns_inst_id, "false")
    finally:
        g_jobs_status.pop(job_id)
    return ns_instantiate_ok
Exemplo n.º 7
0
def run_ns_instantiate(input_data, occ_id):
    """
    format of input_data
    {
        "jobId": uuid of job,
        "nsInstanceId": id of ns instance,
        "object_context": json format of nsd,
        "object_additionalParamForNs": json format of additional parameters for ns,
        "object_additionalParamForVnf": json format of additional parameters for vnf,
        "object_additionalParamForPnf": json format of additional parameters for pnf,
        "vlCount": int type of VL count,
        "vnfCount: int type of VNF count
    }
    """
    logger.debug("Enter %s, input_data is %s", fun_name(), input_data)
    ns_inst_id = ignore_case_get(input_data, "nsInstanceId")
    job_id = ignore_case_get(input_data, "jobId")
    update_job(job_id, 10, JOB_ERROR_CODE.NO_ERROR,
               "Start to prepare the NS instantiate workflow parameter")
    deploy_graph = build_deploy_graph(input_data)
    TaskSet = build_TaskSet(input_data)
    ns_instantiate_ok = False

    try:
        update_job(job_id, 15, "true", "Start the NS instantiate workflow")
        gf = GraphFlow(deploy_graph, TaskSet, config)
        logger.debug("NS graph flow run up!")
        gf.start()
        gf.join()
        gf.task_manager.wait_tasks_done(gf.sort_nodes)
        if gf.task_manager.is_all_task_finished():
            logger.debug("NS is instantiated!")
            update_job(job_id, 90, JOB_ERROR_CODE.NO_ERROR,
                       "Start to post deal")
            post_deal(ns_inst_id, "true")
            update_job(job_id, JOB_PROGRESS.FINISHED, JOB_ERROR_CODE.NO_ERROR,
                       "Create NS successfully.")
            NsLcmOpOcc.update(occ_id, "COMPLETED")
            ns_instantiate_ok = True
    except NSLCMException as e:
        logger.error("Failded to Create NS: %s", e.args[0])
        update_job(job_id, JOB_PROGRESS.ERROR, JOB_ERROR_CODE.ERROR,
                   "Failded to Create NS.")
        NsLcmOpOcc.update(occ_id, operationState="FAILED", error=e.args[0])
        post_deal(ns_inst_id, "false")
    except Exception as e:
        logger.error(traceback.format_exc())
        update_job(job_id, JOB_PROGRESS.ERROR, JOB_ERROR_CODE.ERROR,
                   "Failded to Create NS.")
        NsLcmOpOcc.update(occ_id, operationState="FAILED", error=e.args[0])
        post_deal(ns_inst_id, "false")
    return ns_instantiate_ok
Exemplo n.º 8
0
    def run(self):
        try:
            if not NSInstModel.objects.filter(id=self.ns_inst_id):
                JobUtil.add_job_status(self.job_id, JOB_PROGRESS.FINISHED,
                                       "Need not terminate.", '')
                NsLcmOpOcc.update(self.occ_id, "COMPLETED")
                return
            JobUtil.add_job_status(self.job_id, 10, "Starting terminate...",
                                   '')
            NSInstModel.objects.filter(id=self.ns_inst_id).update(
                status=NS_INST_STATUS.TERMINATING)

            self.cancel_sfc_list()
            self.cancel_vnf_list()
            self.cancel_vl_list()
            self.cancel_pnf_list()

            self.modify_package_state()
            NSInstModel.objects.filter(id=self.ns_inst_id).update(
                status='NOT_INSTANTIATED')
            JobUtil.add_job_status(self.job_id, JOB_PROGRESS.FINISHED,
                                   "ns terminate ends.", '')
            NsLcmOpOcc.update(self.occ_id, "COMPLETED")
        except NSLCMException as e:
            JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, e.args[0])
            NsLcmOpOcc.update(self.occ_id,
                              operationState="FAILED",
                              error=e.args[0])
            build_in.post_deal(self.ns_inst_id, "false")
        except Exception as e:
            logger.error(e.args[0])
            logger.error(traceback.format_exc())
            JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR,
                                   "ns terminate fail.")
            NsLcmOpOcc.update(self.occ_id,
                              operationState="FAILED",
                              error=e.args[0])
            build_in.post_deal(self.ns_inst_id, "false")
Exemplo n.º 9
0
    def do_biz(self):
        job_id = JobUtil.create_job("NS", "NS_INST", self.ns_inst_id)
        occ_id = NsLcmOpOcc.create(self.ns_inst_id, "INSTANTIATE",
                                   "PROCESSING", False, self.req_data)
        NSInstModel.objects.filter(id=self.ns_inst_id).update(
            status=NS_INST_STATUS.INSTANTIATING)

        try:
            logger.debug('ns-instant(%s) workflow starting...' %
                         self.ns_inst_id)
            logger.debug('req_data=%s' % self.req_data)
            ns_inst = NSInstModel.objects.get(id=self.ns_inst_id)
            vim_id = {}

            input_parameters = []
            if 'additionalParamForNs' in self.req_data:
                for key, val in list(
                        self.req_data['additionalParamForNs'].items()):
                    input_parameters.append({"key": key, "value": val})

                if 'location' in self.req_data['additionalParamForNs']:
                    cloud_owner = self.req_data['additionalParamForNs'][
                        'location'].split('_')[0]
                    cloud_regionid = self.req_data["additionalParamForNs"][
                        "location"].split('_')[1]
                    vim_id = {
                        "cloud_owner": cloud_owner,
                        "cloud_regionid": cloud_regionid
                    }
                params_json = json.JSONEncoder().encode(
                    self.req_data["additionalParamForNs"])
            else:
                params_json = json.JSONEncoder().encode({})

            location_constraints = [] if not self.req_data.get('locationConstraints')\
                else self.req_data['locationConstraints']
            vnf_vim = self.get_vnf_vim_info(location_constraints)

            JobUtil.add_job_status(
                job_id, 5, 'Start query nsd(%s)' % ns_inst.nspackage_id)
            dst_plan = sdc_run_catalog.parse_nsd(ns_inst.nspackage_id,
                                                 input_parameters)
            logger.debug('tosca plan dest: %s' % dst_plan)
            logger.debug('Start query nsd(%s)' % ns_inst.nspackage_id)
            sdc_run_catalog.modify_nsd_state(ns_inst.nspackage_id)
            NSInstModel.objects.filter(id=self.ns_inst_id).update(
                nsd_model=dst_plan)

            params_vnf = []
            plan_dict = json.JSONDecoder().decode(dst_plan)
            for vnf in ignore_case_get(plan_dict, "vnfs"):
                vnfd_id = vnf['properties']['id']
                vnfm_type = vnf['properties'].get("vnfm_info", "undefined")
                logger.debug("vnfd_id: %s, vnfm_type : %s", vnfd_id, vnfm_type)
                if isinstance(vnfm_type, list):
                    vnfm_type = vnfm_type[0]
                vimid = self.get_vnf_vim_id(vim_id, vnf_vim, vnfd_id)
                s_vimid = "%s_%s" % (vimid["cloud_owner"],
                                     vimid["cloud_regionid"])
                vnfm_info = extsys.select_vnfm(vnfm_type=vnfm_type,
                                               vim_id=s_vimid)

                params_vnf.append({
                    "vnfProfileId": vnf["vnf_id"],
                    "additionalParam": {
                        "properties":
                        json.JSONEncoder().encode(vnf['properties']),
                        "vimId": vimid,
                        "vnfmInstanceId": vnfm_info["vnfmId"],
                        "vnfmType": vnfm_type,
                        "inputs": params_json
                    }
                })

            self.set_vl_vim_id(vim_id, vnf_vim, plan_dict)
            dst_plan = json.JSONEncoder().encode(plan_dict)
            logger.debug('tosca plan dest add vimid:%s' % dst_plan)
            NSInstModel.objects.filter(id=self.ns_inst_id).update(
                nsd_model=dst_plan)

            pnf_params_json = json.JSONEncoder().encode(
                self.init_pnf_para(plan_dict))

            vnf_params_json = json.JSONEncoder().encode(params_vnf)
            plan_input = {
                'jobId': job_id,
                'nsInstanceId': self.ns_inst_id,
                'object_context': dst_plan,
                'object_additionalParamForNs': params_json,
                'object_additionalParamForVnf': vnf_params_json,
                'object_additionalParamForPnf': pnf_params_json
            }
            plan_input.update(**self.get_model_count(dst_plan))

            if 'additionalParamForNs' in self.req_data:
                plan_input["sdnControllerId"] = ignore_case_get(
                    self.req_data['additionalParamForNs'], "sdncontroller")

            ServiceBaseInfoModel(service_id=self.ns_inst_id,
                                 service_name=ns_inst.name,
                                 service_type='NFVO',
                                 description=ns_inst.description,
                                 active_status='--',
                                 status=ns_inst.status,
                                 creator='--',
                                 create_time=int(time.time() * 1000)).save()

            if config.WORKFLOW_OPTION == "wso2":
                service_tpl = get_servicetemplate(ns_inst.nsd_id)
                DefPkgMappingModel(
                    service_id=self.ns_inst_id,
                    service_def_id=service_tpl['csarId'],
                    template_name=service_tpl['templateName'],
                    template_id=service_tpl['serviceTemplateId']).save()

                for key, val in list(
                        self.req_data['additionalParamForNs'].items()):
                    InputParamMappingModel(service_id=self.ns_inst_id,
                                           input_key=key,
                                           input_value=val).save()

                for vnffg in ignore_case_get(plan_dict, "vnffgs"):
                    VNFFGInstModel(vnffgdid=vnffg["vnffg_id"],
                                   vnffginstid=str(uuid.uuid4()),
                                   nsinstid=self.ns_inst_id,
                                   endpointnumber=0).save()
            else:
                # TODO
                pass
            logger.debug("workflow option: %s" % config.WORKFLOW_OPTION)
            if config.WORKFLOW_OPTION == "wso2":
                return self.start_wso2_workflow(job_id,
                                                ns_inst,
                                                plan_input,
                                                occ_id=occ_id)
            elif config.WORKFLOW_OPTION == "activiti":
                return self.start_activiti_workflow(job_id,
                                                    plan_input,
                                                    occ_id=occ_id)
            elif config.WORKFLOW_OPTION == "grapflow":
                return self.start_buildin_grapflow(job_id,
                                                   plan_input,
                                                   occ_id=occ_id)
            else:
                return self.start_buildin_workflow(job_id,
                                                   plan_input,
                                                   occ_id=occ_id)

        except Exception as e:
            logger.error(traceback.format_exc())
            logger.error("ns-instant(%s) workflow error:%s" %
                         (self.ns_inst_id, e.args[0]))
            NsLcmOpOcc.update(occ_id, operationState="FAILED", error=e.args[0])
            JobUtil.add_job_status(job_id, 255, 'NS instantiation failed')
            build_in.post_deal(self.ns_inst_id, "false")
            return dict(data={'error': e.args[0]},
                        status=status.HTTP_500_INTERNAL_SERVER_ERROR)