Search in sources :

Example 6 with Overbook

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

the class COverbookTest method testGetMisplaced.

@Test
public void testGetMisplaced() 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();
    VM vm6 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Node n3 = mo.newNode();
    mo.getMapping().on(n1, n2, n3).run(n1, vm1).run(n2, vm2, vm3).run(n3, vm4, vm5, vm6);
    ShareableResource rcCPU = new ShareableResource("cpu", 1, 1);
    mo.attach(rcCPU);
    Overbook o1 = new Overbook(n1, "cpu", 1);
    Overbook o2 = new Overbook(n2, "cpu", 2);
    Overbook o3 = new Overbook(n3, "cpu", 3);
    COverbook co1 = new COverbook(o1);
    COverbook co2 = new COverbook(o2);
    COverbook co3 = new COverbook(o3);
    Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR());
    Assert.assertTrue(co1.getMisPlacedVMs(i).isEmpty());
    Assert.assertTrue(co2.getMisPlacedVMs(i).isEmpty());
    Assert.assertEquals(o3.getInvolvedVMs(), co3.getMisPlacedVMs(i));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) BootVM(org.btrplace.plan.event.BootVM) VM(org.btrplace.model.VM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) Node(org.btrplace.model.Node) Overbook(org.btrplace.model.constraint.Overbook) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) MinMTTR(org.btrplace.model.constraint.MinMTTR) ShareableResource(org.btrplace.model.view.ShareableResource) Test(org.testng.annotations.Test)

Example 7 with Overbook

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

the class COverbookTest method testNoSolution.

@Test
public void testNoSolution() throws SchedulerException {
    Node[] nodes = new Node[2];
    VM[] vms = new VM[7];
    Model mo = new DefaultModel();
    Mapping m = mo.getMapping();
    ShareableResource rcMem = new ShareableResource("mem");
    for (int i = 0; i < vms.length; i++) {
        if (i < nodes.length) {
            nodes[i] = mo.newNode();
            rcMem.setCapacity(nodes[i], 3);
            m.addOnlineNode(nodes[i]);
        }
        vms[i] = mo.newVM();
        rcMem.setConsumption(vms[i], 1);
        m.addReadyVM(vms[i]);
    }
    mo.attach(rcMem);
    Collection<SatConstraint> c = new HashSet<>();
    c.add(new Overbook(nodes[0], "mem", 1));
    c.add(new Overbook(nodes[1], "mem", 1));
    c.addAll(Running.newRunning(m.getAllVMs()));
    for (VM v : vms) {
        c.add(new Preserve(v, "mem", 1));
    }
    ChocoScheduler cra = new DefaultChocoScheduler();
    cra.getDurationEvaluators().register(BootVM.class, new LinearToAResourceActionDuration<VM>("mem", 2, 3));
    Assert.assertNull(cra.solve(mo, c));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) 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) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) 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 8 with Overbook

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

the class COverbookTest method testMultipleOverbook.

/**
 * One overbook factor per node.
 *
 * @throws org.btrplace.scheduler.SchedulerException should not occur
 */
@Test
public void testMultipleOverbook() throws SchedulerException {
    Node[] nodes = new Node[3];
    VM[] vms = new VM[11];
    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);
    Collection<SatConstraint> c = new HashSet<>();
    c.add(new Overbook(nodes[0], "cpu", 1));
    c.add(new Overbook(nodes[1], "cpu", 2));
    c.add(new Overbook(nodes[2], "cpu", 3));
    c.addAll(Running.newRunning(m.getAllVMs()));
    c.add(new Preserve(vms[0], "cpu", 1));
    DefaultChocoScheduler cra = new DefaultChocoScheduler();
    cra.setTimeLimit(-1);
    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 9 with Overbook

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

the class OverbookBuilderTest method testGoodSignatures.

@Test(dataProvider = "goodOverbooks")
public void testGoodSignatures(String str, int nbNodes, String rcId, double ratio) throws Exception {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    Set<SatConstraint> cstrs = b.build("namespace test; VM[1..10] : tiny;\n@N[1..20] : defaultNode;\n" + str).getConstraints();
    Assert.assertEquals(cstrs.size(), nbNodes);
    Set<Node> nodes = new HashSet<>();
    for (SatConstraint s : cstrs) {
        Assert.assertTrue(s instanceof Overbook);
        Assert.assertTrue(nodes.addAll(s.getInvolvedNodes()));
        Assert.assertEquals(s.getInvolvedNodes().size(), 1);
        Assert.assertEquals(((Overbook) s).getResource(), rcId);
        Assert.assertEquals(((Overbook) s).getRatio(), ratio);
        Assert.assertEquals(s.isContinuous(), !str.startsWith(">>"));
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) SatConstraint(org.btrplace.model.constraint.SatConstraint) Node(org.btrplace.model.Node) Overbook(org.btrplace.model.constraint.Overbook) ScriptBuilder(org.btrplace.btrpsl.ScriptBuilder) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 10 with Overbook

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

the class OverbookConverterTest method testViables.

@Test
public void testViables() throws JSONConverterException {
    Model mo = new DefaultModel();
    ConstraintsConverter conv = new ConstraintsConverter();
    conv.register(new OverbookConverter());
    Overbook d = new Overbook(mo.newNode(), "foo", 1.4);
    Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(d)), d);
    System.out.println(conv.toJSON(d));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Overbook(org.btrplace.model.constraint.Overbook) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) 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