fabric-testbed / InformationModel

FABRIC Information Model library
MIT License
7 stars 1 forks source link

Add children property to CompositeNode #189

Closed kthare10 closed 8 months ago

kthare10 commented 1 year ago

Add nodes property to CompositeNode in fim/user/compsite_node.py to list all the worker nodes embedded inside a composite node. This is needed for ABQM with level=2.

ibaldin commented 10 months ago

Is this property meant to link names or objects? I.e. ABQM level 2 will have Node objects reflecting individual workers and then CompositeNode object reflecting sites where those are?

If it is that the more likely solution is that we need a new relationship type. Please let me know @kthare10

kthare10 commented 10 months ago

ABQM level 2 has two kinds of nodes:

Need a way to traverse both sites as well as workers within each. Agree that having an additional relationship would help.

For now, I have the following hack:

    print(f"{s.name} [Site]")
    print(f"     Maitenance State: {s.maintenance_info}")
    if s.capacities is None:
        continue
    print(f"     cpu: {s.capacities.cpu}/{s.capacity_allocations.cpu if s.capacity_allocations is not None else 0}, "
              f"core: {s.capacities.core}/{s.capacity_allocations.core if s.capacity_allocations is not None else 0}, "
              f"ram: {s.capacities.ram}/{s.capacity_allocations.ram if s.capacity_allocations is not None else 0}, "
              f"disk: {s.capacities.disk}/{s.capacity_allocations.disk if s.capacity_allocations is not None else 0}",
              f"unit: {s.capacities.unit}/{s.capacity_allocations.unit if s.capacity_allocations is not None else 0}")

    ##### Get Workers from Site ##### Hack until FIM fix available
    from fim.graph.abc_property_graph import ABCPropertyGraph
    from fim.view_only_dict import ViewOnlyDict
    from fim.user import Node
    node_id_list = s.topo.graph_model.get_first_neighbor(node_id=s.node_id, rel=ABCPropertyGraph.REL_HAS,
                                                         node_label=ABCPropertyGraph.CLASS_NetworkNode)
    ret = dict()
    for nid in node_id_list:
        _, node_props = s.topo.graph_model.get_node_properties(node_id=nid)
        n = Node(name=node_props[ABCPropertyGraph.PROP_NAME], node_id=nid, topo=s.topo)
        # exclude Facility nodes
        from fim.user import NodeType
        if n.type != NodeType.Facility:
            ret[n.name] = n
    nodes = ViewOnlyDict(ret)
ibaldin commented 10 months ago

So having looked at ABQM code, I'm not sure we can do much better than what we have. If we add a new relationship type to connect worker Nodes to site CompositeNodes you are still left with using get_first_neighbor() to get them.

A property on a graph has to have a simple type, so we can add a property 'Children' (or similar) that will be a list of names of worker nodes, but I'm not sure it gives you anything on top of what you already have (?)

When you say 'traverse', which direction are you traversing in? From CompositeNode of the site down to worker nodes or vice versa?

kthare10 commented 10 months ago

Composite node to worker nodes, I think just encapsulating the above code snipped in list_nodes() or nodes in fim/user/compsite_node.py would make the user call a bit friendly. Keeping get_first_neighbor would be okay.

ibaldin commented 8 months ago

There is now a children property on CompositeNode which produces a read-only dictionary of child Nodes (linked via 'has' property to CompositeNode). The property just calls the code below.


    def __dict_of_children(self) -> ViewOnlyDict:
        """
        List of children Node objects that are connected to CompositeNode
        representing site in ABQM via 'has' relationship
        """
        node_id_list = self.topo.graph_model.get_first_neighbor(node_id=self.node_id, rel=ABCPropertyGraph.REL_HAS,
                                                                node_label=ABCPropertyGraph.CLASS_NetworkNode)
        ret = dict()
        for nid in node_id_list:
            _, node_props = self.topo.graph_model.get_node_properties(node_id=nid)
            n = Node(name=node_props[ABCPropertyGraph.PROP_NAME], node_id=nid, topo=self.topo)
            # exclude Facility nodes
            from fim.user import NodeType
            if n.type != NodeType.Facility:
                ret[n.name] = n
        return ViewOnlyDict(ret)