aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authordavsad <david.sadlier@est.tech>2021-09-01 07:57:45 +0100
committerMichael Morris <michael.morris@est.tech>2021-09-10 14:01:15 +0000
commita6fd5e3c0145b6d7fe3d9e77dd2a3d8ba98774b4 (patch)
treee4d8aa4b145f8ee580b7614bbdb2715213417dcd /catalog-be
parent009d2b3cfe2d27abd79f47aa076849786327654a (diff)
ETSI SOL001 v2.5.1 model types not deployed in upgrade
Issue-ID: SDC-3707 Signed-off-by: davsad <david.sadlier@est.tech> Change-Id: If1bda517a9295ad380bf4e5e2fc35f15a1ff708e
Diffstat (limited to 'catalog-be')
-rwxr-xr-xcatalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py7
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/run.py2
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/model_client.py10
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/model_import_manager.py70
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/run.py2
5 files changed, 63 insertions, 28 deletions
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py b/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py
index 0c71a382d1..ecd07264b4 100755
--- a/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py
@@ -5,7 +5,6 @@ import pycurl
from sdcBePy.common.helpers import check_arguments_not_none
-
def get_url(ip, port, protocol):
return "%s://%s:%s" % (protocol, ip, port)
@@ -55,6 +54,9 @@ class SdcBeProxy:
def get_normatives(self):
return self.con.get("/sdc2/rest/v1/screen", with_buffer=True)
+ def get_model_list(self):
+ return self.con.get("/sdc2/rest/v1/catalog/model", with_buffer=True)
+
def post_file(self, path, multi_part_form_data, buffer=None):
return self.con.post_file(path, multi_part_form_data, buffer)
@@ -67,8 +69,7 @@ class SdcBeProxy:
self.con.buffer.seek(0)
response = value.decode(self.CHARTSET).split(self.BODY_SEPARATOR)
- return response[1] if len(response) == 2 else response[0]
-
+ return response[len(response) - 1] if len(response) > 1 else response[0]
class CurlConnector:
CONTENT_TYPE_HEADER = "Content-Type: application/json"
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/run.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/run.py
index 41437707aa..39e802bf87 100644
--- a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/run.py
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/run.py
@@ -25,7 +25,7 @@ def main(sdc_be_proxy, update_version):
process_element_list(normativeElementsList.get_normative_element_with_metadata_list(base_file_location), sdc_be_proxy)
#Add model based normatives
model_import_manager = ModelImportManager(Path(base_file_location) / 'models', ModelClient(sdc_be_proxy))
- model_import_manager.create_models()
+ model_import_manager.deploy_models()
except Exception as ex:
logger.log("An error has occurred while uploading elements and types: ", str(ex))
raise ex
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/model_client.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/model_client.py
index fd1cecd429..88128ea71d 100644
--- a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/model_client.py
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/model_client.py
@@ -77,7 +77,7 @@ class ModelClient:
raise Exception(error_msg)
logger.log("Updated model", model_name)
- def import_model_elements(self, model_payload_dict, tosca_elements_import_path, with_metadata=False):
+ def import_model_elements(self, model_payload_dict, tosca_elements_import_path, with_metadata):
model_name = model_payload_dict['name']
logger.debug("Starting import of normative elements for model '{}'".format(model_name))
if with_metadata:
@@ -92,6 +92,14 @@ class ModelClient:
process_type_list(types_list, self.__sdc_be_proxy, upgrade)
logger.log("Finished importing normative types for model", model_name)
+ def get_model_list(self):
+ response = self.__sdc_be_proxy.get_model_list()
+ if response == 200:
+ models = self.__sdc_be_proxy.get_response_from_buffer()
+ return json.loads(models)
+ else:
+ return []
+
@staticmethod
def __parse_to_json_str(model_payload_dict):
return json.dumps(model_payload_dict)
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/model_import_manager.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/model_import_manager.py
index 51c6e4ea97..57b0f1399f 100644
--- a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/model_import_manager.py
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/model_import_manager.py
@@ -30,7 +30,8 @@ class ModelImportManager:
IMPORTS_FOLDER_NAME = 'imports'
ACTION_UPGRADE = 'upgrade'
ACTION_INIT = 'init'
- NODE_TYPES = 'node-types/'
+ TYPES_FOLDER = 'tosca'
+ NODE_FOLDER = 'node-types'
def __init__(self, model_imports_path, model_client):
self.__model_base_path = model_imports_path
@@ -38,25 +39,31 @@ class ModelImportManager:
self.__model_upgrade_path = self.__model_base_path / self.UPGRADE_FOLDER_NAME
self.__model_client = model_client
- def create_models(self):
+ def deploy_models(self):
+ existing_models = self.__model_client.get_model_list()
for model_folder_name in self.__get_model_init_list():
- model_imports_zip_path = self.__zip_model_imports(model_folder_name, self.ACTION_INIT)
model_payload_dict = self.__read_model_payload(model_folder_name, self.ACTION_INIT)
- self.__model_client.create_model(model_payload_dict, model_imports_zip_path)
- tosca_path = self.__get_model_tosca_path(self.ACTION_INIT, model_folder_name)
- self.__model_client.import_model_elements(model_payload_dict, tosca_path)
- if os.path.isdir(tosca_path + self.NODE_TYPES):
- self.__model_client.import_model_types(model_payload_dict, self.__get_model_normative_type_candidate(tosca_path), False)
- self.__model_client.import_model_elements(model_payload_dict, tosca_path, True)
-
- def update_models(self):
+ if (not existing_models or not any(m for m in existing_models if model_payload_dict['name'] == m['name'])):
+ self.__create_models(model_folder_name, model_payload_dict)
+
for model_folder_name in self.__get_model_upgrade_list():
- model_imports_zip_path = self.__zip_model_imports(model_folder_name, self.ACTION_UPGRADE)
model_payload_dict = self.__read_model_payload(model_folder_name, self.ACTION_UPGRADE)
- self.__model_client.update_model_imports(model_payload_dict, model_imports_zip_path)
- tosca_path = self.__get_model_tosca_path(self.ACTION_UPGRADE, model_folder_name)
- if os.path.isdir(tosca_path + self.NODE_TYPES):
- self.__model_client.import_model_types(model_payload_dict, self.__get_model_normative_type_candidate(tosca_path), True)
+ if (existing_models and any(m for m in existing_models if model_payload_dict['name'] == m['name'])):
+ self.__update_models(model_folder_name, model_payload_dict)
+
+ def __create_models(self, model_folder_name, model_payload_dict):
+ model_imports_zip_path = self.__zip_model_imports(model_folder_name, self.ACTION_INIT)
+ self.__model_client.create_model(model_payload_dict, model_imports_zip_path)
+ self.__init_model_non_node_types(model_folder_name, model_payload_dict)
+ self.__init_model_node_types(model_folder_name, model_payload_dict)
+ self.__init_model_non_node_types(model_folder_name, model_payload_dict, True);
+
+ def __update_models(self, model_folder_name, model_payload_dict):
+ model_imports_zip_path = self.__zip_model_imports(model_folder_name, self.ACTION_UPGRADE)
+ self.__model_client.update_model_imports(model_payload_dict, model_imports_zip_path)
+ self.__upgrade_model_non_node_types(model_folder_name, model_payload_dict)
+ self.__upgrade_model_node_types(model_folder_name, model_payload_dict)
+ self.__upgrade_model_non_node_types(model_folder_name, model_payload_dict, True)
def __get_model_init_list(self):
return self.__get_model_list(self.__model_init_path)
@@ -72,9 +79,8 @@ class ModelImportManager:
break
return model_list
- def __get_model_normative_type_candidate(self, tosca_path):
- path = tosca_path + self.NODE_TYPES
- return [NormativeTypeCandidate(path, self.__read_model_type_json(path))]
+ def __get_node_type_list(self, path):
+ return [NormativeTypeCandidate(str(os.path.join(path, '')), self.__read_model_type_json(path))]
def __zip_model_imports(self, model, action_type) -> Path:
base_path = self.__get_base_action_path(action_type)
@@ -96,7 +102,7 @@ class ModelImportManager:
return json.dumps(json_data)
def __read_model_type_json(self, tosca_path):
- path = tosca_path + "types.json"
+ path = tosca_path / "types.json"
if not os.path.isfile(path):
return []
json_file = open(path)
@@ -111,5 +117,25 @@ class ModelImportManager:
def __get_base_action_path(self, action_type) -> Path:
return self.__model_init_path if action_type == self.INIT_FOLDER_NAME else self.__model_upgrade_path
- def __get_model_tosca_path(self, action, model):
- return str(self.__get_base_action_path(action) / model) + "/tosca/"
+ def __get_tosca_path(self, action, model):
+ return self.__get_base_action_path(action) / model / self.TYPES_FOLDER
+
+ def __init_model_non_node_types(self, model, model_payload_dict, with_metadata=False):
+ path = self.__get_tosca_path(self.ACTION_INIT, model)
+ if os.path.isdir(path):
+ self.__model_client.import_model_elements(model_payload_dict, str(os.path.join(path, '')) , with_metadata)
+
+ def __upgrade_model_non_node_types(self, model, model_payload_dict, with_metadata=False):
+ path = self.__get_tosca_path(self.ACTION_UPGRADE, model)
+ if os.path.isdir(path):
+ self.__model_client.import_model_elements(model_payload_dict, str(os.path.join(path, '')), with_metadata)
+
+ def __init_model_node_types(self, model, model_payload_dict, upgrade=False):
+ path = self.__get_tosca_path(self.ACTION_INIT, model) / self.NODE_FOLDER
+ if os.path.isdir(path):
+ self.__model_client.import_model_types(model_payload_dict, self.__get_node_type_list(path), upgrade)
+
+ def __upgrade_model_node_types(self, model, model_payload_dict, upgrade=True):
+ path = self.__get_tosca_path(self.ACTION_UPGRADE, model) / self.NODE_FOLDER
+ if os.path.isdir(path):
+ self.__model_client.import_model_types(model_payload_dict, self.__get_node_type_list(path), upgrade)
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/run.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/run.py
index 44a25a0136..663d27b435 100644
--- a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/run.py
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/run.py
@@ -27,7 +27,7 @@ def main(sdc_be_proxy):
model_import_manager = ModelImportManager(Path(base_file_location) / 'models', ModelClient(sdc_be_proxy))
try:
- model_import_manager.update_models()
+ model_import_manager.deploy_models()
except Exception as ex:
logger.log("An error has occurred while uploading the models: ", str(ex))
raise ex