Exemplo n.º 1
0
    def print_db_delta_prefix(self, kvstore_keyvals, kvstore_prefix_node_names,
                              decision_prefix_dbs, json):
        """Returns status code. 0 = success, 1 = failure"""

        prefix_maps = utils.collate_prefix_keys(kvstore_keyvals)

        for node_name, prefix_db in prefix_maps.items():
            kvstore_prefix_node_names.add(node_name)
            if node_name not in decision_prefix_dbs:
                print(
                    printing.render_vertical_table([[
                        "node {}'s prefix db is missing in Decision".format(
                            node_name)
                    ]]))
                return 1
            decision_prefix_db = decision_prefix_dbs[node_name]
            decision_prefix_set = {}

            utils.update_global_prefix_db(decision_prefix_set,
                                          decision_prefix_db)
            lines = utils.sprint_prefixes_db_delta(decision_prefix_set,
                                                   prefix_db)
            if lines:
                print(
                    printing.render_vertical_table([[
                        "node {}'s prefix db in Decision out of sync with "
                        "KvStore's".format(node_name)
                    ]]))
                print("\n".join(lines))
                return 1
        return 0
Exemplo n.º 2
0
    def print_db_delta(self, key, our_kv_pub_db, value, other_val):
        ''' print db delta '''

        if key.startswith(Consts.PREFIX_DB_MARKER):
            prefix_db = deserialize_thrift_object(value.value,
                                                  lsdb_types.PrefixDatabase)
            other_prefix_db = deserialize_thrift_object(
                other_val.value, lsdb_types.PrefixDatabase)
            other_prefix_set = {}
            utils.update_global_prefix_db(other_prefix_set, other_prefix_db)
            lines = utils.sprint_prefixes_db_delta(other_prefix_set, prefix_db)

        elif key.startswith(Consts.ADJ_DB_MARKER):
            adj_db = deserialize_thrift_object(value.value,
                                               lsdb_types.AdjacencyDatabase)
            other_adj_db = deserialize_thrift_object(
                value.value, lsdb_types.AdjacencyDatabase)
            lines = utils.sprint_adj_db_delta(adj_db, other_adj_db)

        else:
            lines = None

        if lines != []:
            print_publication_delta(
                "Key: {} difference".format(key),
                utils.sprint_pub_update(our_kv_pub_db, key, other_val),
                "\n".join(lines) if lines else "")
Exemplo n.º 3
0
    def print_prefix_delta(
        self,
        key: str,
        value: openr_types.Publication,
        delta: bool,
        global_prefix_db: Dict,
        global_publication_db: Dict,
    ):
        prefix_db = serializer.deserialize_thrift_object(
            value.value, openr_types.PrefixDatabase)
        if delta:
            lines = "\n".join(
                utils.sprint_prefixes_db_delta(global_prefix_db, prefix_db,
                                               key))
        else:
            lines = utils.sprint_prefixes_db_full(prefix_db)

        if lines:
            self.print_publication_delta(
                "{}'s prefixes".format(prefix_db.thisNodeName),
                utils.sprint_pub_update(global_publication_db, key, value),
                lines,
                timestamp=True,
            )

        utils.update_global_prefix_db(global_prefix_db, prefix_db, key)
Exemplo n.º 4
0
    def print_db_delta(self, key, value, kvstore_adj_node_names,
                       kvstore_prefix_node_names, decision_adj_dbs,
                       decision_prefix_dbs):
        if key.startswith(Consts.ADJ_DB_MARKER):
            kvstore_adj_db = deserialize_thrift_object(
                value.value, lsdb_types.AdjacencyDatabase)
            node_name = kvstore_adj_db.thisNodeName
            kvstore_adj_node_names.add(node_name)
            if node_name not in decision_adj_dbs:
                print(
                    printing.render_vertical_table([[
                        "node {}'s adj db is missing in Decision".format(
                            node_name)
                    ]]))
                return
            decision_adj_db = decision_adj_dbs[node_name]
            lines = utils.sprint_adj_db_delta(kvstore_adj_db, decision_adj_db)
            if lines:
                print(
                    printing.render_vertical_table([[
                        "node {}'s adj db in Decision out of sync with KvStore's"
                        .format(node_name)
                    ]]))
                print("\n".join(lines))
            return

        if key.startswith(Consts.PREFIX_DB_MARKER):
            kvstore_prefix_db = deserialize_thrift_object(
                value.value, lsdb_types.PrefixDatabase)
            node_name = kvstore_prefix_db.thisNodeName
            kvstore_prefix_node_names.add(node_name)
            if node_name not in decision_prefix_dbs:
                print(
                    printing.render_vertical_table([[
                        "node {}'s prefix db is missing in Decision".format(
                            node_name)
                    ]]))
                return
            decision_prefix_db = decision_prefix_dbs[node_name]
            decision_prefix_set = {}
            utils.update_global_prefix_db(decision_prefix_set,
                                          decision_prefix_db)
            lines = utils.sprint_prefixes_db_delta(decision_prefix_set,
                                                   kvstore_prefix_db)
            if lines:
                print(
                    printing.render_vertical_table([[
                        "node {}'s prefix db in Decision out of sync with KvStore's"
                        .format(node_name)
                    ]]))
                print("\n".join(lines))
            return
Exemplo n.º 5
0
    def print_prefix_delta(self, key, value, delta, global_prefix_db,
                           global_publication_db):
        _, reported_node_name = key.split(':', 1)
        prefix_db = deserialize_thrift_object(value.value,
                                              lsdb_types.PrefixDatabase)
        if delta:
            lines = utils.sprint_prefixes_db_delta(global_prefix_db, prefix_db)
        else:
            lines = utils.sprint_prefixes_db_full(prefix_db)

        if lines:
            print_publication_delta(
                "{}'s prefixes".format(reported_node_name),
                utils.sprint_pub_update(global_publication_db, key, value),
                "\n".join(lines))

        utils.update_global_prefix_db(global_prefix_db, prefix_db)
Exemplo n.º 6
0
    def print_db_delta(
        self,
        key,
        value,
        kvstore_adj_node_names,
        kvstore_prefix_node_names,
        decision_adj_dbs,
        decision_prefix_dbs,
        json,
    ):
        """ Returns status code. 0 = success, 1 = failure"""

        if key.startswith(Consts.ADJ_DB_MARKER):
            kvstore_adj_db = deserialize_thrift_object(
                value.value, lsdb_types.AdjacencyDatabase
            )
            node_name = kvstore_adj_db.thisNodeName
            kvstore_adj_node_names.add(node_name)
            if node_name not in decision_adj_dbs:
                print(
                    printing.render_vertical_table(
                        [["node {}'s adj db is missing in Decision".format(node_name)]]
                    )
                )
                return 1
            decision_adj_db = decision_adj_dbs[node_name]

            return_code = 0
            if json:
                tags = ("in_decision", "in_kvstore", "changed_in_decision_and_kvstore")
                adj_list_deltas = utils.find_adj_list_deltas(
                    decision_adj_db.adjacencies, kvstore_adj_db.adjacencies, tags=tags
                )
                deltas_json, return_code = utils.adj_list_deltas_json(
                    adj_list_deltas, tags=tags
                )
                if return_code:
                    utils.print_json(deltas_json)
            else:
                lines = utils.sprint_adj_db_delta(kvstore_adj_db, decision_adj_db)
                if lines:
                    print(
                        printing.render_vertical_table(
                            [
                                [
                                    "node {}'s adj db in Decision out of sync with "
                                    "KvStore's".format(node_name)
                                ]
                            ]
                        )
                    )
                    print("\n".join(lines))
                    return_code = 1

            return return_code

        if key.startswith(Consts.PREFIX_DB_MARKER):
            kvstore_prefix_db = deserialize_thrift_object(
                value.value, lsdb_types.PrefixDatabase
            )
            node_name = kvstore_prefix_db.thisNodeName
            kvstore_prefix_node_names.add(node_name)
            if node_name not in decision_prefix_dbs:
                print(
                    printing.render_vertical_table(
                        [
                            [
                                "node {}'s prefix db is missing in Decision".format(
                                    node_name
                                )
                            ]
                        ]
                    )
                )
                return 1
            decision_prefix_db = decision_prefix_dbs[node_name]
            decision_prefix_set = {}
            utils.update_global_prefix_db(decision_prefix_set, decision_prefix_db)
            lines = utils.sprint_prefixes_db_delta(
                decision_prefix_set, kvstore_prefix_db
            )
            if lines:
                print(
                    printing.render_vertical_table(
                        [
                            [
                                "node {}'s prefix db in Decision out of sync with "
                                "KvStore's".format(node_name)
                            ]
                        ]
                    )
                )
                print("\n".join(lines))
                return 1

            return 0