overlapping constraints (ec2-instance-type with arch/cpu/mem)

Gustavo Niemeyer gustavo.niemeyer at canonical.com
Sat Dec 17 00:25:03 UTC 2011


> The spec said that "the tightest constraints win", but that's wrong
> because:

It should say "the most specific wins", and that applies both to the
inner settings and to the settings level (service vs. env).

Here is the suggested pseudocode:

    apply = set()

loop1:
    for c1 in constraints(service):
        for c2 in constraints(service):
            if c2.more_specific(c1):
                continue loop1
        apply.add(c1)

loop2:
    for c1 in constraints(environment):
        for c2 in constraints(environment):
            if c2.more_specific(c1):
                continue loop2
        for c2 in apply:
            if c2.conflicts(c1):
                continue loop2
        apply.add(c2)


Applying that logic over your examples (which are all rather trivial
with that logic):

> env: [mem=16G]
> service: [ec2-instance-type=m1.small]

apply: ec2-instance-type=m1.small

> env: [ec2-instance-type=m1.small]
> service: [mem=16G]

apply: mem=16GB

> env: [ec2-instance-type=m1.small]
> service: [mem=16G]

apply: mem=16GB

> env: [mem=16G]
> service: [ec2-instance-type=m1.small]

apply: ec2-instance-type=m1.small

> env: [ec2-instance-type=m1.small]
> service: [mem=16G]

apply: mem=16GB

> Thoughts?

Does that make sense?

-- 
Gustavo Niemeyer
http://niemeyer.net
http://niemeyer.net/plus
http://niemeyer.net/twitter
http://niemeyer.net/blog

-- I'm not absolutely sure of anything.



More information about the Juju mailing list