ETSI SOL001 v2.5.1 model types not deployed in upgrade
[sdc.git] / catalog-be / src / main / resources / scripts / sdcBePy / tosca / upgrade / run.py
1 #!/usr/bin/env python3
2
3 import os
4 from pathlib import Path
5
6 from sdcBePy.common import logger
7 from sdcBePy.common.logger import print_and_exit
8 from sdcBePy.common.normative.main import process_element_list, process_type_list
9 from sdcBePy.tosca.main import parse_and_create_proxy
10 from sdcBePy.tosca.models.model_client import ModelClient
11 from sdcBePy.tosca.models.model_import_manager import ModelImportManager
12 from sdcBePy.tosca.models.normativeElementsList import get_normative_element_candidate_list, \
13     get_normative_element_with_metadata_list
14 from sdcBePy.tosca.models.normativeToUpdateList import TypesToUpdate, get_heat_and_normative_to_update_list, \
15     get_onap_sol_to_update_list, get_nfv_to_update_list
16
17
18 def main(sdc_be_proxy):
19     update_version = True
20     update_onap_version = False 
21     update_nfv_version = True
22
23     # use to run script form this dir (not like the command)
24     # base_file_location = os.getcwd() + "/../../../../import/tosca/"
25     base_file_location = os.getcwd() + "/"
26     logger.debug("working directory =" + base_file_location)
27
28     model_import_manager = ModelImportManager(Path(base_file_location) / 'models', ModelClient(sdc_be_proxy))
29     try:
30         model_import_manager.deploy_models()
31     except Exception as ex:
32         logger.log("An error has occurred while uploading the models: ", str(ex))
33         raise ex
34
35     process_element_list(get_normative_element_candidate_list(base_file_location), sdc_be_proxy)
36
37     all_types = get_all_types()
38
39     heat_and_normative_list = get_heat_and_normative_to_update_list(all_types, base_file_location)
40     process_type_list(heat_and_normative_list, sdc_be_proxy, update_version)
41
42     onap_sol_list = get_onap_sol_to_update_list(all_types, base_file_location)
43     process_type_list(onap_sol_list, sdc_be_proxy, update_onap_version)
44
45     nfv_list = get_nfv_to_update_list(all_types, base_file_location)
46     process_type_list(nfv_list, sdc_be_proxy, update_nfv_version)
47     
48     process_element_list(get_normative_element_with_metadata_list(base_file_location), sdc_be_proxy)
49
50     logger.log("Updating end ->", "All normatives updated successfully!")
51     print_and_exit(0, None)
52
53
54 def get_all_types():
55     path = os.path.dirname(__file__)
56     return TypesToUpdate([path + "/../data/typesToUpgrade.json",
57                           path + "/../data/onapTypesToUpgrade.json"])
58
59
60 def run():
61     sdc_be_proxy, _ = parse_and_create_proxy()
62     main(sdc_be_proxy)
63
64
65 if __name__ == "__main__":
66     run()