diff --git a/src/python/fluxion/resourcegraph/V1.py b/src/python/fluxion/resourcegraph/V1.py index 1b6b571e2..0a27f1824 100644 --- a/src/python/fluxion/resourcegraph/V1.py +++ b/src/python/fluxion/resourcegraph/V1.py @@ -24,16 +24,16 @@ def __init__( self, vtxId, resType, - basename, - name, - iden, - uniqId, - rank, - exclusive, - unit, - size, - properties, - path, + basename=None, + name=None, + iden=None, + uniqId=None, + rank=None, + exclusive=None, + unit=None, + size=None, + properties=None, + path=None, status=0, ): """Constructor @@ -57,18 +57,28 @@ def __init__( raise ValueError(f"resource type={resType} unsupported by RV1") metadata = { "type": resType, - "basename": basename, - "name": name, - "id": iden, - "uniq_id": uniqId, - "rank": rank, - "exclusive": exclusive, - "unit": unit, - "size": size, - "properties": properties, - "paths": {"containment": path}, } - if status != 0: # reduce the footprint by only adding status if nonzero + if basename is not None: + metadata["basename"] = basename + if name is not None: + metadata["name"] = name + if iden is not None: + metadata["id"] = iden + if uniqId is not None: + metadata["uniq_id"] = uniqId + if rank is not None: + metadata["rank"] = rank + if exclusive is not None: + metadata["exclusive"] = exclusive + if unit: + metadata["unit"] = unit + if size is not None: + metadata["size"] = size + if properties: + metadata["properties"] = properties + if path is not None: + metadata["paths"] = {"containment": path} + if status != 0: metadata["status"] = status super().__init__(vtxId, metadata=metadata) @@ -91,7 +101,6 @@ def __init__(self, parentId, vtxId): parentId, vtxId, directed=True, - metadata={"subsystem": "containment"}, ) @@ -132,75 +141,43 @@ def _contains_any(self, prop_str, charset): return True return False - def _encode_child(self, ppid, hPath, rank, resType, i, properties): - path = f"{hPath}/{resType}{i}" - properties = {} - # This can be extended later to support fine grained property - # attachment using properties passed in from parent; - # for now, set empty properties + def _encode_child(self, ppid, resType, i): vtx = FluxionResourcePoolV1( self._uniqId, resType, - resType, - resType + str(i), - i, - self._uniqId, - rank, - True, - "", - 1, - properties, - path, + iden=i, ) edg = FluxionResourceRelationshipV1(ppid, vtx.get_id()) self._add_and_tick_uniq_id(vtx, edg) - def _encode_rank(self, ppid, rank, children, hList, rdict, properties): - if rdict[rank] >= len(hList): - raise ValueError(f"nodelist doesn't include node for rank={rank}") - hPath = f"/cluster0/{hList[rdict[rank]]}" - iden = self._extract_id_from_hn(hList[rdict[rank]]) + def _encode_rank(self, ppid, rank, children, hostname, properties): + iden = self._extract_id_from_hn(hostname) vtx = FluxionResourcePoolV1( self._uniqId, "node", - "node", - hList[rdict[rank]], - iden, - self._uniqId, - rank, - True, - "", - 1, - properties, - hPath, + name=hostname, + iden=iden, + rank=rank, + properties=properties, ) edg = FluxionResourceRelationshipV1(ppid, vtx.get_id()) self._add_and_tick_uniq_id(vtx, edg) for key, val in children.items(): for i in IDset(val): - self._encode_child(vtx.get_id(), hPath, rank, str(key), i, properties) + self._encode_child(vtx.get_id(), str(key), i) def _encode_rlite(self, ppid, entry, hList, rdict, pdict): for rank in list(IDset(entry["rank"])): - self._encode_rank( - ppid, rank, entry["children"], hList, rdict, pdict.get(rank, {}) - ) + if rdict[rank] >= len(hList): + raise ValueError(f"nodelist doesn't include node for rank={rank}") + hostname = hList[rdict[rank]] + self._encode_rank(ppid, rank, entry["children"], hostname, pdict.get(rank)) def _encode(self): hList = Hostlist(self._rv1NoSched["execution"]["nodelist"]) vtx = FluxionResourcePoolV1( self._uniqId, "cluster", - "cluster", - "cluster0", - 0, - self._uniqId, - -1, - True, - "", - 1, - {}, - "/cluster0", ) self._add_and_tick_uniq_id(vtx, None) i = 0 @@ -223,6 +200,5 @@ def _encode(self): pdict[rank][p] = "" else: pdict[rank] = {p: ""} - for entry in self._rv1NoSched["execution"]["R_lite"]: self._encode_rlite(vtx.get_id(), entry, hList, rdict, pdict)