Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add children property to CompositeNode #189

Closed
kthare10 opened this issue Jul 11, 2023 · 5 comments
Closed

Add children property to CompositeNode #189

kthare10 opened this issue Jul 11, 2023 · 5 comments
Assignees
Labels
1.6 For release 1.6

Comments

@kthare10
Copy link
Collaborator

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 ibaldin added the 1.6 For release 1.6 label Aug 23, 2023
@ibaldin ibaldin self-assigned this Aug 23, 2023
@ibaldin
Copy link
Contributor

ibaldin commented Sep 13, 2023

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
Copy link
Collaborator Author

ABQM level 2 has two kinds of nodes:

  • Composite Node representing the sites
  • Worker nodes inside a site node

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
Copy link
Contributor

ibaldin commented Sep 15, 2023

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
Copy link
Collaborator Author

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 ibaldin mentioned this issue Nov 8, 2023
ibaldin pushed a commit that referenced this issue Nov 8, 2023
…urns a dictionary of Node objects attached via has relationship
@ibaldin ibaldin closed this as completed Nov 8, 2023
@ibaldin
Copy link
Contributor

ibaldin commented Nov 12, 2023

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)

@ibaldin ibaldin changed the title Add nodes property to CompositeNode Add children property to CompositeNode Nov 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.6 For release 1.6
Projects
None yet
Development

No branches or pull requests

2 participants