Search in sources :

Example 6 with SatConstraint

use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.

the class ResourceCapacityBuilder method buildConstraint.

@Override
public List<? extends SatConstraint> buildConstraint(BtrPlaceTree t, List<BtrpOperand> args) {
    if (!checkConformance(t, args)) {
        return Collections.emptyList();
    }
    @SuppressWarnings("unchecked") List<Node> ns = (List<Node>) params[0].transform(this, t, args.get(0));
    String rcId = (String) params[1].transform(this, t, args.get(1));
    BtrpNumber n = (BtrpNumber) args.get(2);
    if (!n.isInteger()) {
        t.ignoreError("Parameter '" + params[2].getName() + "' expects an integer");
        return Collections.emptyList();
    }
    int v = n.getIntValue();
    if (v < 0) {
        t.ignoreError("Parameter '" + params[2].getName() + "' expects a positive integer (" + v + " given)");
        return Collections.emptyList();
    }
    return ns != null ? Collections.singletonList(new ResourceCapacity(new HashSet<>(ns), rcId, v)) : Collections.emptyList();
}
Also used : ResourceCapacity(org.btrplace.model.constraint.ResourceCapacity) BtrpNumber(org.btrplace.btrpsl.element.BtrpNumber) Node(org.btrplace.model.Node) List(java.util.List) SatConstraint(org.btrplace.model.constraint.SatConstraint)

Example 7 with SatConstraint

use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.

the class CAmongTest method testWithNoSolution.

/**
 * No solution because constraints force to spread the VMs among 2 groups.
 *
 * @throws org.btrplace.scheduler.SchedulerException
 */
@Test
public void testWithNoSolution() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    VM vm4 = mo.newVM();
    VM vm5 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Node n3 = mo.newNode();
    Node n4 = mo.newNode();
    Mapping map = mo.getMapping().on(n1, n2, n3, n4).run(n1, vm1).run(n2, vm2, vm3).ready(vm4, vm5);
    Set<VM> vms = new HashSet<>(Arrays.asList(vm1, vm2, vm5));
    Collection<Node> s = new HashSet<>(Arrays.asList(n1, n2));
    Collection<Node> s2 = new HashSet<>(Arrays.asList(n3, n4));
    Collection<Collection<Node>> pGrps = new HashSet<>(Arrays.asList(s, s2));
    Among a = new Among(vms, pGrps);
    a.setContinuous(false);
    ChocoScheduler cra = new DefaultChocoScheduler();
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.addAll(Running.newRunning(map.getAllVMs()));
    cstrs.add(new Fence(vm2, Collections.singleton(n3)));
    cstrs.add(new Fence(vm1, Collections.singleton(n1)));
    cstrs.add(a);
    ReconfigurationPlan p = cra.solve(mo, cstrs);
    Assert.assertNull(p);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) Mapping(org.btrplace.model.Mapping) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Collection(java.util.Collection) Among(org.btrplace.model.constraint.Among) Fence(org.btrplace.model.constraint.Fence) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 8 with SatConstraint

use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.

the class CAmongTest method testWithGroupChange.

@Test
public void testWithGroupChange() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    VM vm4 = mo.newVM();
    VM vm5 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Node n3 = mo.newNode();
    Node n4 = mo.newNode();
    Mapping map = mo.getMapping().on(n1, n2, n3, n4).run(n1, vm1).run(n2, vm2, vm3).ready(vm4, vm5);
    Set<VM> vms = new HashSet<>(Arrays.asList(vm1, vm2, vm5));
    Collection<Node> s1 = new HashSet<>(Arrays.asList(n1, n2));
    Collection<Node> s2 = new HashSet<>(Arrays.asList(n3, n4));
    Collection<Collection<Node>> pGrps = Arrays.asList(s1, s2);
    Among a = new Among(vms, pGrps);
    a.setContinuous(false);
    ChocoScheduler cra = new DefaultChocoScheduler();
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.addAll(Running.newRunning(map.getAllVMs()));
    cstrs.add(new Fence(vm2, s2));
    cstrs.add(a);
    ReconfigurationPlan p = cra.solve(mo, cstrs);
    Assert.assertNotNull(p);
// System.out.println(p);
// Assert.assertEquals(a.isSatisfied(p.getResult()), SatConstraint.Sat.SATISFIED);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) Mapping(org.btrplace.model.Mapping) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Collection(java.util.Collection) Among(org.btrplace.model.constraint.Among) Fence(org.btrplace.model.constraint.Fence) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 9 with SatConstraint

use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.

the class CShareableResource method getMisPlacedVMs.

/**
 * {@inheritDoc}
 *
 * @param i the model to use to inspect the VMs.
 * @return the set of VMs that cannot have their associated {@link Preserve} constraint satisfy with regards
 * to a possible {@link Overbook} and single-node {@link ResourceCapacity} constraint.
 */
@Override
public Set<VM> getMisPlacedVMs(Instance i) {
    final TObjectDoubleMap<Node> wantedRatios = new TObjectDoubleHashMap<>();
    final int nbVMs = i.getModel().getMapping().getNbVMs();
    final int nbNodes = i.getModel().getMapping().getNbNodes();
    final IntMap wantedAmount = new IntMap(0, nbVMs);
    final IntMap wantedCapacity = new IntMap(0, nbNodes);
    for (SatConstraint c : i.getSatConstraints()) {
        if (!(c instanceof ResourceRelated && ((ResourceRelated) c).getResource().equals(rc.getResourceIdentifier()))) {
            continue;
        }
        if (c instanceof Preserve) {
            // We guarantee the highest request so far.
            VM v = c.getInvolvedVMs().iterator().next();
            int qty = ((Preserve) c).getAmount();
            wantedAmount.put(v.id(), Math.max(wantedAmount.get(v.id()), qty));
        } else if (c instanceof Overbook) {
            Node n = c.getInvolvedNodes().iterator().next();
            double min = ((Overbook) c).getRatio();
            if (wantedRatios.containsKey(n)) {
                min = Math.min(min, wantedRatios.get(n));
            }
            wantedRatios.put(n, min);
        } else if (c instanceof ResourceCapacity && c.getInvolvedNodes().size() == 1) {
            Node n = c.getInvolvedNodes().iterator().next();
            int qty = ((ResourceCapacity) c).getAmount();
            wantedCapacity.put(n.id(), Math.max(qty, wantedCapacity.get(n.id())));
        }
    }
    Mapping m = i.getModel().getMapping();
    Set<VM> candidates = new HashSet<>();
    for (Node n : m.getOnlineNodes()) {
        Set<VM> running = m.getRunningVMs(n);
        if (overloaded(wantedRatios, wantedAmount, wantedCapacity, running, n)) {
            candidates.addAll(running);
        }
    }
    return candidates;
}
Also used : SatConstraint(org.btrplace.model.constraint.SatConstraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) Preserve(org.btrplace.model.constraint.Preserve) TObjectDoubleHashMap(gnu.trove.map.hash.TObjectDoubleHashMap) ResourceCapacity(org.btrplace.model.constraint.ResourceCapacity) ResourceRelated(org.btrplace.model.view.ResourceRelated) Overbook(org.btrplace.model.constraint.Overbook) TObjectIntMap(gnu.trove.map.TObjectIntMap) IntMap(org.btrplace.util.IntMap)

Example 10 with SatConstraint

use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.

the class CAmongTest method testContinuousWithNotAlreadySatisfied.

@Test
public void testContinuousWithNotAlreadySatisfied() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    VM vm4 = mo.newVM();
    VM vm5 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Node n3 = mo.newNode();
    Node n4 = mo.newNode();
    Mapping map = mo.getMapping().on(n1, n2, n3, n4).run(n1, vm1).run(n2, vm2).run(n3, vm3).ready(vm4, vm5);
    Set<VM> vms = new HashSet<>(Arrays.asList(vm1, vm2, vm5));
    Collection<Node> s1 = new HashSet<>(Arrays.asList(n1, n2));
    Collection<Node> s2 = new HashSet<>(Arrays.asList(n3, n4));
    Collection<Collection<Node>> pGrps = new HashSet<>(Arrays.asList(s1, s2));
    Among a = new Among(vms, pGrps);
    a.setContinuous(true);
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.addAll(Running.newRunning(map.getAllVMs()));
    cstrs.add(new Fence(vm2, Collections.singleton(n3)));
    cstrs.add(a);
    ChocoScheduler cra = new DefaultChocoScheduler();
    ReconfigurationPlan p = cra.solve(mo, cstrs);
    Assert.assertNull(p);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) Mapping(org.btrplace.model.Mapping) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Collection(java.util.Collection) Among(org.btrplace.model.constraint.Among) Fence(org.btrplace.model.constraint.Fence) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

SatConstraint (org.btrplace.model.constraint.SatConstraint)111 DefaultModel (org.btrplace.model.DefaultModel)90 Test (org.testng.annotations.Test)82 VM (org.btrplace.model.VM)79 Node (org.btrplace.model.Node)77 Model (org.btrplace.model.Model)76 ArrayList (java.util.ArrayList)74 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)72 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)65 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)51 Mapping (org.btrplace.model.Mapping)50 ShareableResource (org.btrplace.model.view.ShareableResource)41 HashSet (java.util.HashSet)33 Fence (org.btrplace.model.constraint.Fence)27 Offline (org.btrplace.model.constraint.Offline)17 Preserve (org.btrplace.model.constraint.Preserve)16 MigrateVM (org.btrplace.plan.event.MigrateVM)15 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)14 Instance (org.btrplace.model.Instance)14 Network (org.btrplace.model.view.network.Network)14