Search in sources :

Example 1 with Overbook

use of org.btrplace.model.constraint.Overbook 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 2 with Overbook

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

the class CShareableResourceTest method testWithFloat.

@Test
public void testWithFloat() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Mapping map = mo.getMapping().on(n1, n2).run(n1, vm1, vm2);
    ShareableResource rc = new ShareableResource("foo");
    rc.setCapacity(n1, 32);
    rc.setConsumption(vm1, 3);
    rc.setConsumption(vm2, 2);
    mo.attach(rc);
    ChocoScheduler cra = new DefaultChocoScheduler();
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.addAll(Online.newOnline(map.getAllNodes()));
    Overbook o = new Overbook(n1, "foo", 1.5, false);
    cstrs.add(o);
    Overbook o2 = new Overbook(n2, "foo", 1.5, false);
    cstrs.add(o2);
    cstrs.add(new Preserve(vm1, "foo", 5));
    ReconfigurationPlan p = cra.solve(mo, cstrs);
    Assert.assertNotNull(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) ShareableResource(org.btrplace.model.view.ShareableResource) Preserve(org.btrplace.model.constraint.Preserve) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) VM(org.btrplace.model.VM) Overbook(org.btrplace.model.constraint.Overbook) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 3 with Overbook

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

the class OverbookSplitterTest method simpleTest.

@Test
public void simpleTest() {
    OverbookSplitter splitter = new OverbookSplitter();
    List<Instance> instances = new ArrayList<>();
    Model m0 = new DefaultModel();
    Node n = m0.newNode(0);
    m0.getMapping().addOnlineNode(n);
    m0.getMapping().addOnlineNode(m0.newNode(1));
    Model m1 = new DefaultModel();
    m1.getMapping().addOnlineNode(m1.newNode(2));
    m1.getMapping().addOnlineNode(m1.newNode(3));
    instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
    instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
    Set<Node> all = new HashSet<>(m0.getMapping().getAllNodes());
    all.addAll(m1.getMapping().getAllNodes());
    TIntIntHashMap nodeIndex = Instances.makeNodeIndex(instances);
    // Only nodes in m0
    Overbook oSimple = new Overbook(n, "cpu", 2);
    Assert.assertTrue(splitter.split(oSimple, null, instances, new TIntIntHashMap(), nodeIndex));
    Assert.assertTrue(instances.get(0).getSatConstraints().contains(oSimple));
    Assert.assertFalse(instances.get(1).getSatConstraints().contains(oSimple));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) Overbook(org.btrplace.model.constraint.Overbook) ArrayList(java.util.ArrayList) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) MinMTTR(org.btrplace.model.constraint.MinMTTR) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 4 with Overbook

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

the class COverbookTest method testBasic.

@Test
public void testBasic() throws SchedulerException {
    Node[] nodes = new Node[2];
    VM[] vms = new VM[3];
    Model mo = new DefaultModel();
    Mapping m = mo.getMapping();
    ShareableResource rcCPU = new ShareableResource("cpu");
    for (int i = 0; i < vms.length; i++) {
        if (i < nodes.length) {
            nodes[i] = mo.newNode();
            rcCPU.setCapacity(nodes[i], 2);
            m.addOnlineNode(nodes[i]);
        }
        vms[i] = mo.newVM();
        rcCPU.setConsumption(vms[i], 1);
        m.addReadyVM(vms[i]);
    }
    mo.attach(rcCPU);
    Overbook o = new Overbook(nodes[0], "cpu", 2);
    Overbook o2 = new Overbook(nodes[1], "cpu", 2);
    Collection<SatConstraint> c = new HashSet<>();
    c.add(o);
    c.add(o2);
    c.addAll(Running.newRunning(m.getAllVMs()));
    c.add(new Preserve(vms[0], "cpu", 1));
    c.addAll(Online.newOnline(m.getAllNodes()));
    DefaultChocoScheduler cra = new DefaultChocoScheduler();
    cra.getMapper().mapConstraint(Overbook.class, COverbook.class);
    ReconfigurationPlan p = cra.solve(mo, c);
    Assert.assertNotNull(p);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Mapping(org.btrplace.model.Mapping) ShareableResource(org.btrplace.model.view.ShareableResource) SatConstraint(org.btrplace.model.constraint.SatConstraint) Preserve(org.btrplace.model.constraint.Preserve) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) BootVM(org.btrplace.plan.event.BootVM) VM(org.btrplace.model.VM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) Overbook(org.btrplace.model.constraint.Overbook) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 5 with Overbook

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

the class COverbookTest method testWithIncrease.

/**
 * Test with a root VM that has increasing need and another one that prevent it
 * to get the resources immediately
 */
@Test
public void testWithIncrease() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    Node n1 = mo.newNode();
    Mapping map = mo.getMapping().on(n1).run(n1, vm1, vm2);
    ShareableResource rc = new ShareableResource("foo");
    rc.setCapacity(n1, 5);
    rc.setConsumption(vm1, 3);
    rc.setConsumption(vm2, 2);
    mo.attach(rc);
    ChocoScheduler cra = new DefaultChocoScheduler();
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.addAll(Online.newOnline(map.getAllNodes()));
    Overbook o = new Overbook(n1, "foo", 1);
    o.setContinuous(true);
    cstrs.add(o);
    cstrs.add(new Ready(vm2));
    cstrs.add(new Preserve(vm1, "foo", 5));
    ReconfigurationPlan p = cra.solve(mo, cstrs);
    Assert.assertNotNull(p);
    Assert.assertEquals(p.getSize(), 2);
    Action al = p.getActions().stream().filter(s -> s instanceof Allocate).findAny().get();
    Action sh = p.getActions().stream().filter(s -> s instanceof ShutdownVM).findAny().get();
    Assert.assertTrue(sh.getEnd() <= al.getStart());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Action(org.btrplace.plan.event.Action) 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) ShareableResource(org.btrplace.model.view.ShareableResource) Preserve(org.btrplace.model.constraint.Preserve) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) Ready(org.btrplace.model.constraint.Ready) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) BootVM(org.btrplace.plan.event.BootVM) VM(org.btrplace.model.VM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) Overbook(org.btrplace.model.constraint.Overbook) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) ShutdownVM(org.btrplace.plan.event.ShutdownVM) Allocate(org.btrplace.plan.event.Allocate) Test(org.testng.annotations.Test)

Aggregations

Overbook (org.btrplace.model.constraint.Overbook)11 DefaultModel (org.btrplace.model.DefaultModel)10 Test (org.testng.annotations.Test)10 Model (org.btrplace.model.Model)9 Node (org.btrplace.model.Node)9 SatConstraint (org.btrplace.model.constraint.SatConstraint)8 VM (org.btrplace.model.VM)7 Preserve (org.btrplace.model.constraint.Preserve)7 ShareableResource (org.btrplace.model.view.ShareableResource)7 Mapping (org.btrplace.model.Mapping)6 BootVM (org.btrplace.plan.event.BootVM)6 ShutdownVM (org.btrplace.plan.event.ShutdownVM)6 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)6 HashSet (java.util.HashSet)5 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)5 ArrayList (java.util.ArrayList)4 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)4 Instance (org.btrplace.model.Instance)2 MinMTTR (org.btrplace.model.constraint.MinMTTR)2 TObjectIntMap (gnu.trove.map.TObjectIntMap)1