ETSI SOL001 v2.5.1 model types not deployed in upgrade
[sdc.git] / catalog-be / src / main / resources / scripts / sdcBePy / tosca / imports / run.py
1 #!/usr/bin/env python3
2
3 import os
4 from pathlib import Path
5
6 import sdcBePy.common.logger as logger
7 from sdcBePy.common.normative.main import process_element_list, process_type_list
8 from sdcBePy.tosca.main import parse_and_create_proxy
9 from sdcBePy.tosca.models import normativeElementsList
10 from sdcBePy.tosca.models import normativeTypesList
11 from sdcBePy.tosca.models.model_client import ModelClient
12 from sdcBePy.tosca.models.model_import_manager import ModelImportManager
13
14
15 def main(sdc_be_proxy, update_version):
16     # use to run script form this dir (not like the command)
17     # base_file_location = os.getcwd() + "/../../../import/tosca/"
18     base_file_location = os.getcwd() + os.path.sep
19     logger.debug("working directory =" + base_file_location)
20     if sdc_be_proxy.disable_locking("true") != 200:
21         raise RuntimeError("Failed to disable locking")
22     try:
23         process_element_list(normativeElementsList.get_normative_element_candidate_list(base_file_location), sdc_be_proxy)
24         process_type_list(normativeTypesList.get_normative_type_candidate_list(base_file_location), sdc_be_proxy, update_version)
25         process_element_list(normativeElementsList.get_normative_element_with_metadata_list(base_file_location), sdc_be_proxy)
26         #Add model based normatives
27         model_import_manager = ModelImportManager(Path(base_file_location) / 'models', ModelClient(sdc_be_proxy))
28         model_import_manager.deploy_models()
29     except Exception as ex:
30         logger.log("An error has occurred while uploading elements and types: ", str(ex))
31         raise ex
32     finally:
33         if sdc_be_proxy.disable_locking("false") != 200:
34             raise RuntimeError("Failed to enable locking")
35     logger.log("Script end ->", "All normatives imported successfully!")
36     logger.print_and_exit(0, None)
37
38 def run():
39     sdc_be_proxy, update_version = parse_and_create_proxy()
40     main(sdc_be_proxy, update_version)
41
42
43 if __name__ == "__main__":
44     run()