@@ -50,7 +50,7 @@ def __init__(
5050 exclusive -- Exclusivity
5151 unit -- Unit of this resource
5252 size -- Amount of individual resources in this resource pool in unit
53- properties -- Comma-separated list of property strings
53+ properties -- mapping from property name to value
5454 paths -- Fully qualified paths dictionary
5555 status -- Resource status (0 for 'up', 1 for 'down'), defaults to 0
5656 """
@@ -127,31 +127,18 @@ def _extract_id_from_hn(self, hostName):
127127 rc = int (postfix [0 ])
128128 return rc
129129
130- def _add_to_rankdict (self , key , gLabel , rankdict ):
131- if key in rankdict :
132- rankdict [key ].append (gLabel )
133- else :
134- rankdict [key ] = [gLabel ]
135-
136130 def _contains_any (self , prop_str , charset ):
137131 for c in charset :
138132 if c in prop_str :
139133 return True
140134 return False
141135
142- def _per_rank_property_dict (self , properties , rankdict ):
143- for p in properties :
144- # This can be extended later to support scheduler specific
145- # string (@suffix)
146- if self ._contains_any (p , "!&'\" ^`|()" ):
147- raise ValueError (f"invalid character used in property={ p } " )
148- self ._add_to_rankdict ("node" , p , rankdict )
149-
150- def _encode_child (self , ppid , hPath , rank , resType , i , rpd ):
136+ def _encode_child (self , ppid , hPath , rank , resType , i , properties ):
151137 path = f"{ hPath } /{ resType } { i } "
152- properties = []
138+ properties = {}
153139 # This can be extended later to support fine grained property
154- # attachment using rpd
140+ # attachment using properties passed in from parent;
141+ # for now, set empty properties
155142 vtx = FluxionResourcePoolV1 (
156143 self ._uniqId ,
157144 resType ,
@@ -169,14 +156,11 @@ def _encode_child(self, ppid, hPath, rank, resType, i, rpd):
169156 edg = FluxionResourceRelationshipV1 (ppid , vtx .get_id ())
170157 self ._add_and_tick_uniq_id (vtx , edg )
171158
172- def _encode_rank (self , ppid , rank , children , hList , rdict , rpd ):
159+ def _encode_rank (self , ppid , rank , children , hList , rdict , properties ):
173160 if rdict [rank ] >= len (hList ):
174161 raise ValueError (f"nodelist doesn't include node for rank={ rank } " )
175162 hPath = f"/cluster0/{ hList [rdict [rank ]]} "
176163 iden = self ._extract_id_from_hn (hList [rdict [rank ]])
177- properties = []
178- if "node" in rpd :
179- properties = rpd ["node" ]
180164 vtx = FluxionResourcePoolV1 (
181165 self ._uniqId ,
182166 "node" ,
@@ -195,14 +179,13 @@ def _encode_rank(self, ppid, rank, children, hList, rdict, rpd):
195179 self ._add_and_tick_uniq_id (vtx , edg )
196180 for key , val in children .items ():
197181 for i in IDset (val ):
198- self ._encode_child (vtx .get_id (), hPath , rank , str (key ), i , rpd )
182+ self ._encode_child (vtx .get_id (), hPath , rank , str (key ), i , properties )
199183
200184 def _encode_rlite (self , ppid , entry , hList , rdict , pdict ):
201185 for rank in list (IDset (entry ["rank" ])):
202- rpd = {}
203- if rank in pdict :
204- self ._per_rank_property_dict (pdict [rank ], rpd )
205- self ._encode_rank (ppid , rank , entry ["children" ], hList , rdict , rpd )
186+ self ._encode_rank (
187+ ppid , rank , entry ["children" ], hList , rdict , pdict .get (rank , {})
188+ )
206189
207190 def _encode (self ):
208191 hList = Hostlist (self ._rv1NoSched ["execution" ]["nodelist" ])
@@ -217,7 +200,7 @@ def _encode(self):
217200 True ,
218201 "" ,
219202 1 ,
220- [] ,
203+ {} ,
221204 "/cluster0" ,
222205 )
223206 self ._add_and_tick_uniq_id (vtx , None )
@@ -234,11 +217,13 @@ def _encode(self):
234217 props = self ._rv1NoSched ["execution" ]["properties" ]
235218 pdict = {}
236219 for p in props :
220+ if self ._contains_any (p , "!&'\" ^`|()" ):
221+ raise ValueError (f"invalid character used in property={ p } " )
237222 for rank in list (IDset (props [p ])):
238223 if rank in pdict :
239- pdict [rank ]. append ( p )
224+ pdict [rank ][ p ] = ""
240225 else :
241- pdict [rank ] = [ p ]
226+ pdict [rank ] = { p : "" }
242227
243228 for entry in self ._rv1NoSched ["execution" ]["R_lite" ]:
244229 self ._encode_rlite (vtx .get_id (), entry , hList , rdict , pdict )
0 commit comments