def test_generate_and_save_kronos_dependency_local(self):
        input_data_store = LocalFileSystem("analytics_platform/kronos/softnet/test/data/input-kd-data")
        self.assertTrue(input_data_store is not None)

        output_data_store = LocalFileSystem("analytics_platform/kronos/softnet/test/data/output-kd-data")
        self.assertTrue(output_data_store is not None)

        gnosis_ref_arch_json = input_data_store.read_json_file(filename="data_gnosis/gnosis_ref_arch.json")
        self.assertTrue(gnosis_ref_arch_json is not None)

        gnosis_ref_arch_dict = dict(gnosis_ref_arch_json)
        self.assertTrue(gnosis_ref_arch_dict is not None)

        package_topic_json = input_data_store.read_json_file("data_package_topic/package_topic.json")
        self.assertTrue(package_topic_json is not None)

        package_topic_dict = dict(package_topic_json)
        self.assertTrue(package_topic_dict is not None)

        eco_to_package_topic_dict = package_topic_dict["package_topic_map"]
        eco_to_topic_package_dict = package_topic_dict["topic_package_map"]

        eco_to_kronos_dependency_dict = dict()

        for ecosystem in eco_to_package_topic_dict.keys():
            package_to_topic_dict = eco_to_package_topic_dict.get(ecosystem)
            topic_to_package_dict = eco_to_topic_package_dict.get(ecosystem)

            kronos_dependency_obj = KronosDependencyGenerator.generate_kronos_dependency(
                gnosis_ref_arch_dict=gnosis_ref_arch_dict,
                package_to_topic_dict=package_to_topic_dict,
                topic_to_package_dict=topic_to_package_dict)

            self.assertTrue(kronos_dependency_obj is not None)

            eco_to_kronos_dependency_dict[ecosystem] = kronos_dependency_obj

        for ecosystem in eco_to_kronos_dependency_dict.keys():
            kronos_dependency_obj = eco_to_kronos_dependency_dict[ecosystem]
            filename = "data_kronos_dependency/kronos_dependency.json"
            filename_formatted = filename.replace(".", "_" + ecosystem + ".")
            kronos_dependency_obj.save(data_store=output_data_store, filename=filename_formatted)

            kronos_dependency_dict = kronos_dependency_obj.get_dictionary()

            self.assertTrue(kronos_dependency_dict is not None)

            expected_filename_formatted = filename_formatted.replace("/", "/expected_")

            expected_kronos_dependency_obj = KronosDependencyGenerator.load(data_store=output_data_store,
                                                                            filename=expected_filename_formatted)
            self.assertTrue(expected_kronos_dependency_obj is not None)

            expected_kronos_dependency_dict = expected_kronos_dependency_obj.get_dictionary()
            self.assertTrue(expected_kronos_dependency_dict is not None)

            self.assertDictEqual(kronos_dependency_dict, expected_kronos_dependency_dict)
def generate_and_save_kronos_dependency(input_gnosis_data_store,
                                        input_package_topic_data_store,
                                        output_data_store, additional_path):
    gnosis_ref_arch_json = input_gnosis_data_store.read_json_file(
        filename=additional_path + GNOSIS_RA_OUTPUT_PATH)
    gnosis_ref_arch_dict = dict(gnosis_ref_arch_json)
    package_topic_json = input_package_topic_data_store.read_json_file(
        additional_path + GNOSIS_PTM_OUTPUT_PATH)
    package_topic_dict = dict(package_topic_json)

    eco_to_package_topic_dict = package_topic_dict[
        GNOSIS_PTM_PACKAGE_TOPIC_MAP]
    eco_to_topic_package_dict = package_topic_dict[
        GNOSIS_PTM_TOPIC_PACKAGE_MAP]

    eco_to_kronos_dependency_dict = dict()

    for ecosystem in eco_to_package_topic_dict.keys():
        package_to_topic_dict = eco_to_package_topic_dict.get(ecosystem)
        topic_to_package_dict = eco_to_topic_package_dict.get(ecosystem)

        kronos_dependency_obj = KronosDependencyGenerator.generate_kronos_dependency(
            gnosis_ref_arch_dict=gnosis_ref_arch_dict,
            package_to_topic_dict=package_to_topic_dict,
            topic_to_package_dict=topic_to_package_dict)

        eco_to_kronos_dependency_dict[ecosystem] = kronos_dependency_obj

    for ecosystem in eco_to_kronos_dependency_dict.keys():
        kronos_dependency_obj = eco_to_kronos_dependency_dict[ecosystem]
        filename = KD_OUTPUT_FOLDER + "/" + KD_BASE_FILENAME
        filename_formatted = additional_path + filename.replace(
            ".", "_" + ecosystem + ".")
        kronos_dependency_obj.save(data_store=output_data_store,
                                   filename=filename_formatted)
예제 #3
0
def load_eco_to_kronos_dependency_dict(input_kronos_dependency_data_store, additional_path):
    eco_to_kronos_dependency_dict = dict()
    kd_filenames = input_kronos_dependency_data_store.list_files(
        os.path.join(additional_path, softnet_constants.KD_OUTPUT_FOLDER))
    for kd_filename in kd_filenames:
        ecosystem = kd_filename.split("/")[-1].split(".")[0].split("_")[-1]
        kronos_dependency_obj = KronosDependencyGenerator.load(
            data_store=input_kronos_dependency_data_store,
            filename=kd_filename)
        kronos_dependency_dict = kronos_dependency_obj.get_dictionary()
        eco_to_kronos_dependency_dict[ecosystem] = kronos_dependency_dict
    return eco_to_kronos_dependency_dict
def generate_and_save_kronos_dependency(input_gnosis_data_store,
                                        input_package_topic_data_store,
                                        output_data_store, additional_path):
    """Generate Kronos dependency and save it to the selected storage."""
    gnosis_ref_arch_json = \
        input_gnosis_data_store.read_json_file(filename=os.path.join(
                                               additional_path,
                                               softnet_constants.GNOSIS_RA_OUTPUT_PATH))
    gnosis_ref_arch_dict = dict(gnosis_ref_arch_json)
    package_topic_json = \
        input_package_topic_data_store.read_json_file(os.path.join(
                                                      additional_path,
                                                      softnet_constants.GNOSIS_PTM_OUTPUT_PATH))
    package_topic_dict = dict(package_topic_json)

    eco_to_package_topic_dict = package_topic_dict[
        softnet_constants.GNOSIS_PTM_PACKAGE_TOPIC_MAP]
    eco_to_topic_package_dict = package_topic_dict[
        softnet_constants.GNOSIS_PTM_TOPIC_PACKAGE_MAP]

    eco_to_kronos_dependency_dict = dict()

    for ecosystem in eco_to_package_topic_dict.keys():
        package_to_topic_dict = eco_to_package_topic_dict.get(ecosystem)
        topic_to_package_dict = eco_to_topic_package_dict.get(ecosystem)

        kronos_dependency_obj = KronosDependencyGenerator.generate_kronos_dependency(
            gnosis_ref_arch_dict=gnosis_ref_arch_dict,
            package_to_topic_dict=package_to_topic_dict,
            topic_to_package_dict=topic_to_package_dict)

        eco_to_kronos_dependency_dict[ecosystem] = kronos_dependency_obj

    for ecosystem in eco_to_kronos_dependency_dict.keys():
        kronos_dependency_obj = eco_to_kronos_dependency_dict[ecosystem]
        filename = os.path.join(softnet_constants.KD_OUTPUT_FOLDER,
                                softnet_constants.KD_BASE_FILENAME)
        filename_formatted = os.path.join(
            additional_path, filename.replace(".", "_{}.".format(ecosystem)))
        kronos_dependency_obj.save(data_store=output_data_store,
                                   filename=filename_formatted)