Import multiple node types in a single endpoint
[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.node_type_client import NodeTypeClient
13 from sdcBePy.tosca.models.normativeElementsList import get_normative_element_candidate_list, \
14     get_normative_element_with_metadata_list
15 from sdcBePy.tosca.models.normativeToUpdateList import TypesToUpdate, get_heat_and_normative_to_update_list, \
16     get_onap_sol_to_update_list, get_nfv_to_update_list
17
18
19 def main(sdc_be_proxy):
20     update_version = True
21     update_onap_version = False 
22     update_nfv_version = True
23
24     # use to run script form this dir (not like the command)
25     # base_file_location = os.getcwd() + "/../../../../import/tosca/"
26     base_file_location = os.getcwd() + "/"
27     logger.debug("working directory =" + base_file_location)
28
29     model_import_manager = ModelImportManager(Path(base_file_location) / 'models', ModelClient(sdc_be_proxy),
30                                               NodeTypeClient(sdc_be_proxy))
31     try:
32         model_import_manager.deploy_models()
33     except Exception as ex:
34         logger.log("An error has occurred while uploading the models: ", str(ex))
35         raise ex
36
37     process_element_list(get_normative_element_candidate_list(base_file_location), sdc_be_proxy)
38
39     all_types = get_all_types()
40
41     heat_and_normative_list = get_heat_and_normative_to_update_list(all_types, base_file_location)
42     process_type_list(heat_and_normative_list, sdc_be_proxy, update_version)
43
44     onap_sol_list = get_onap_sol_to_update_list(all_types, base_file_location)
45     process_type_list(onap_sol_list, sdc_be_proxy, update_onap_version)
46
47     nfv_list = get_nfv_to_update_list(all_types, base_file_location)
48     process_type_list(nfv_list, sdc_be_proxy, update_nfv_version)
49     
50     process_element_list(get_normative_element_with_metadata_list(base_file_location), sdc_be_proxy)
51
52     logger.log("Updating end ->", "All normatives updated successfully!")
53     print_and_exit(0, None)
54
55
56 def get_all_types():
57     path = os.path.dirname(__file__)
58     return TypesToUpdate([path + "/../data/typesToUpgrade.json",
59                           path + "/../data/onapTypesToUpgrade.json"])
60
61
62 def run():
63     sdc_be_proxy, _ = parse_and_create_proxy()
64     main(sdc_be_proxy)
65
66
67 if __name__ == "__main__":
68     run()