summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordengyh <dengyuanhong@chinamobile.com>2020-10-22 10:50:20 +0800
committerYuanhong Deng <dengyuanhong@chinamobile.com>2020-10-23 02:48:36 +0000
commitb9178eb87ddbe3777b0aeae4028f94669950f894 (patch)
treeacfb6b4de0fe8125f57f9d2ea9a9cfc5688c55f6
parent0c9e5344629c48467db78973111e02f75020702e (diff)
Refactor the code of SDCController
Issue-ID: MODELING-440 Change-Id: I3020d964ca1d9b1d054bc4deca75a7fa6fdac34e Signed-off-by: dengyh <dengyuanhong@chinamobile.com>
-rw-r--r--catalog/pub/config/config.py4
-rw-r--r--catalog/pub/msapi/sdc_controller.py40
-rw-r--r--catalog/urls.py2
3 files changed, 8 insertions, 38 deletions
diff --git a/catalog/pub/config/config.py b/catalog/pub/config/config.py
index 49d1d84..4adba1c 100644
--- a/catalog/pub/config/config.py
+++ b/catalog/pub/config/config.py
@@ -16,7 +16,7 @@ import os
# [MSB]
MSB_BASE_URL = os.getenv("MSB_ADDR", "http://127.0.0.1:80")
-MSB_ENABLED = os.getenv("MSB_ENABLED", "true")
+MSB_ENABLED = os.getenv("MSB_ENABLED", "false")
# [SDC config]
if MSB_ENABLED == "true":
@@ -29,7 +29,7 @@ SDC_PASSWD = "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U"
SERVICE_IP = os.getenv("SERVICE_IP", "127.0.0.1")
# [DMAAP config]
-DMAAP_ENABLED = os.getenv("DMAAP_ENABLED", False)
+DMAAP_ENABLED = os.getenv("DMAAP_ENABLED", "false")
DMAAP_MR_BASE_URL = os.getenv("DMAAP_ADDR")
CONSUMER_GROUP = "consumerGroup"
CONSUMER_ID = "consumerId"
diff --git a/catalog/pub/msapi/sdc_controller.py b/catalog/pub/msapi/sdc_controller.py
index 8bad857..a96e68b 100644
--- a/catalog/pub/msapi/sdc_controller.py
+++ b/catalog/pub/msapi/sdc_controller.py
@@ -1,7 +1,6 @@
# Copyright 2019 CMCC Technologies Co., Ltd.
import json
import logging
-import os
import time
import traceback
import uuid
@@ -9,11 +8,9 @@ from threading import Thread
from apscheduler.schedulers.background import BackgroundScheduler
-from catalog.pub.database.models import NSPackageModel, VnfPackageModel
+from catalog.pub.database.models import VnfPackageModel
from catalog.pub.exceptions import CatalogException
-from catalog.packages.biz import sdc_vnf_package
-from catalog.pub.utils import fileutil
-from catalog.packages.biz.ns_descriptor import NsDescriptor
+from catalog.packages.biz import sdc_vnf_package, sdc_ns_package
from catalog.pub.utils.jobutil import JobUtil
from catalog.pub.utils.values import ignore_case_get
@@ -227,36 +224,9 @@ def process_notification(msg):
job_status = JobUtil.query_job_status(jobID)
if job_status[0].status == 'error':
raise CatalogException("VF resource fail to distributed.")
-
- service_artifacts = msg['serviceArtifacts']
- for artifact in service_artifacts:
- if artifact['artifactType'] == 'TOSCA_CSAR':
- csar_id = artifact['artifactUUID']
- if not NSPackageModel.objects.filter(nsPackageId=artifact['artifactUUID']):
- download_url = artifact['artifactURL']
- localhost_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
- ns_csar_base = os.path.join(localhost_dir, "csars", "ns")
- local_path = os.path.join(ns_csar_base, msg['distributionID'])
- file_name = artifact['artifactName']
- # csar_version = artifact['artifactVersion']
-
- # download csar package
- local_file_name = sdc.download_artifacts(download_url, local_path, file_name)
- if local_file_name.endswith(".csar") or local_file_name.endswith(".zip"):
- artifact_vnf_file = fileutil.unzip_file(local_file_name, local_path,
- "Artifacts/Deployment/OTHER/ns.csar")
- if os.path.exists(artifact_vnf_file):
- local_file_name = artifact_vnf_file
-
- data = {
- 'userDefinedData': {}
- }
- nsd = NsDescriptor()
- nsd.create(data, csar_id)
- nsd.parse_nsd_and_save(csar_id, local_file_name)
- logger.debug("CSAR(%s) distriuted successfully.", csar_id)
- else:
- logger.debug("CSAR(%s) has been distriuted", csar_id)
+ csar_id = msg['serviceUUID']
+ sdc_ns_package.ns_on_distribute(csar_id)
+ logger.debug("Csar package [%s] has been destributed successfully", csar_id)
except CatalogException as e:
logger.error("Failed to download the resource")
logger.error(str(e))
diff --git a/catalog/urls.py b/catalog/urls.py
index 9429e5d..c7d4aa6 100644
--- a/catalog/urls.py
+++ b/catalog/urls.py
@@ -39,5 +39,5 @@ if REG_TO_MSB_WHEN_START:
for reg_param in REG_TO_MSB_REG_PARAM:
req_by_msb(REG_TO_MSB_REG_URL, "POST", json.JSONEncoder().encode(reg_param))
-if DMAAP_ENABLED:
+if DMAAP_ENABLED == "true":
SDCController().start()