Changeset 7ee16b3


Ignore:
Timestamp:
May 19, 2010 6:38:05 AM (14 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
966c620
Parents:
8a0c67f
Message:

Allow nodes to meet multiple constraints.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/compose.py

    r8a0c67f r7ee16b3  
    231231        if e.name in names:
    232232            nn= make_new_name(names, "node")
    233             if e.name in marks:
    234                 marks[e.name].name = nn
     233            for c in marks.get(e.name, []):
     234                c.name = nn
    235235            e.name = nn
    236236        else:
     
    254254    """
    255255    got_all = True
     256    node_match = { }
    256257    for c in candidates:
    257258        if not c.match:
     
    265266                    if can.name != c.name and can.topology != c.topology and \
    266267                            not can.match:
    267                         # Now check that the candidate also accepts c
     268                        # Don't allow multiple matches between the same nodes
     269                        # (the "if" above is already pretty crowded).
     270                        if c.name in node_match and \
     271                                can.name in node_match[c.name]:
     272                            continue
     273                        # Now check that can also accepts c
    268274                        for ca in can.accepts:
    269275                            if ca in c.provides:
     
    291297                match.match = c
    292298                c.match = match
     299                # Note the match of the nodes
     300                for a, b in ((c.name, match.name), (match.name, c.name)):
     301                    if a in node_match: node_match[a].append(b)
     302                    else: node_match[a] = [ b]
    293303            else:
    294304                got_all = False
     
    378388    const_re = re.compile("\s*#\s*COMPOSITION:\s*([^:]+:[^:]+:.*)")
    379389
    380     marks = { }
     390    constraints = [ ]
    381391    for l in contents:
    382392        m = const_re.search(l)
     
    389399            p = p.split(",")
    390400            a = a.split(",")
    391             c = constraint(name=nn, required=(r == 'required'),
    392                     provides=p, accepts=a)
    393             marks[nn] = c
    394     return marks
     401            constraints.append(constraint(name=nn, required=(r == 'required'),
     402                    provides=p, accepts=a))
     403    return constraints
    395404
    396405def import_ns2_component(fn):
     
    416425def import_topdl_component(fn):
    417426    """
    418     Pull a component in from a topdl description.  The topology generation is
    419     straightforward and the constraints are pulled from the attributes of
    420     Computer nodes in the experiment.  The compisition_point attribute being
    421     true marks a node as a composition point.  The required, provides and
    422     accepts attributes map directly into those constraint fields.  The dict of
    423     constraints and the topology are returned.
    424     """
    425     top = topdl.topology_from_xml(filename=fn, top='experiment')
    426     cons = constraints_from_xml(filename=fn, top='constraints')
    427     marks= dict([(c.name, c ) for c in cons])
    428     return (top, marks)
    429 
    430 def index_constraints(constraints, provides, accepts):
     427    Pull a component in from a topdl description.
     428    """
     429    return (topdl.topology_from_xml(filename=fn, top='experiment'),
     430            constraints_from_xml(filename=fn, top='constraints'))
     431
     432def index_constraints(constraints, provides, accepts, names):
    431433    """
    432434    Add constraints to the provides and accepts indices based on the attributes
    433     of the contstraints.
     435    of the contstraints.  Also index by name.
    434436    """
    435437    for c in constraints:
     
    438440                if a not in dict: dict[a] = [c]
    439441                else: dict[a].append(c)
     442        if c.name in names: names[c.name].append(c)
     443        else: names[c.name]= [ c ]
    440444
    441445def get_suffix(fn):
     
    548552
    549553    for fn, cnt in files:
    550         top = None
    551554        try:
    552555            s = get_suffix(fn)
    553556            if s and s in importers:
    554                 top, marks = importers[s](fn)
     557                top, cons = importers[s](fn)
    555558            else:
    556559                warn("Unknown suffix on file %s.  Ignored" % fn)
     
    569572            components += 1
    570573            t = top.clone()
    571             m = copy.deepcopy(marks)
     574            c = copy.deepcopy(cons)
     575            marks = { }
    572576            # Bind the constraints in m (the marks copy) to this topology
    573             for c in m.values():
    574                 c.topology = t
    575             index_constraints(m.values(), provides, accepts)
    576             localize_names(t, names, m)
    577             constraints.extend(m.values())
     577            for cc in c:
     578                cc.topology = t
     579            index_constraints(c, provides, accepts, marks)
     580            localize_names(t, names, marks)
     581            constraints.extend(c)
    578582            topos.append(t)
    579583
Note: See TracChangeset for help on using the changeset viewer.