Search in sources :

Example 26 with ShareableResource

use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.

the class CMaxOnlineTest method testContinuousRestrictionSimpleCase.

@Test
public void testContinuousRestrictionSimpleCase() throws SchedulerException {
    Model model = new DefaultModel();
    Node n1 = model.newNode();
    Node n2 = model.newNode();
    Node n3 = model.newNode();
    VM vm1 = model.newVM();
    VM vm3 = model.newVM();
    VM vm4 = model.newVM();
    ShareableResource resources = new ShareableResource("cpu", 4, 1);
    resources.setCapacity(n1, 8);
    resources.setConsumption(vm4, 2);
    Mapping map = model.getMapping().on(n1, n3).off(n2).run(n1, vm1, vm4).run(n3, vm3);
    MappingUtils.fill(map, model.getMapping());
    model.attach(resources);
    MaxOnline maxon = new MaxOnline(map.getAllNodes(), 2, true);
    List<SatConstraint> constraints = new ArrayList<>();
    constraints.add(maxon);
    constraints.add(new Online(n2));
    ChocoScheduler cra = new DefaultChocoScheduler();
    // cra.setTimeLimit(3);
    cra.setMaxEnd(3);
    cra.getMapper().mapConstraint(MaxOnline.class, CMaxOnline.class);
    ReconfigurationPlan plan = cra.solve(model, constraints);
    Assert.assertNotNull(plan);
    Assert.assertTrue(maxon.isSatisfied(plan));
}
Also used : SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ShareableResource(org.btrplace.model.view.ShareableResource) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) MaxOnline(org.btrplace.model.constraint.MaxOnline) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Online(org.btrplace.model.constraint.Online) MaxOnline(org.btrplace.model.constraint.MaxOnline) Test(org.testng.annotations.Test)

Example 27 with ShareableResource

use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.

the class CNoDelayTest method testOk2.

@Test
public void testOk2() throws SchedulerException {
    Model model = new DefaultModel();
    Node n1 = model.newNode();
    Node n2 = model.newNode();
    Node n3 = model.newNode();
    VM vm1 = model.newVM();
    VM vm2 = model.newVM();
    VM vm3 = model.newVM();
    VM vm4 = model.newVM();
    ShareableResource resources = new ShareableResource("cpu", 4, 1);
    resources.setCapacity(n2, 3);
    resources.setConsumption(vm1, 4);
    Mapping map = model.getMapping().on(n1, n2, n3).run(n1, vm1).run(n2, vm2).run(n3, vm3).run(n3, vm4);
    MappingUtils.fill(map, model.getMapping());
    model.attach(resources);
    Ban b = new Ban(vm1, Collections.singleton(n1));
    NoDelay nd = new NoDelay(vm4);
    // 1 solution (priority to vm4): vm4 to n2 ; vm3 to n2 ; vm1 to n3
    List<SatConstraint> constraints = new ArrayList<>();
    constraints.add(nd);
    constraints.add(b);
    ChocoScheduler cra = new DefaultChocoScheduler();
    cra.getMapper().mapConstraint(MaxOnline.class, CMaxOnline.class);
    ReconfigurationPlan plan = cra.solve(model, constraints);
    Assert.assertNotNull(plan);
    Assert.assertTrue(nd.isSatisfied(plan));
}
Also used : SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) ShareableResource(org.btrplace.model.view.ShareableResource) Ban(org.btrplace.model.constraint.Ban) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) NoDelay(org.btrplace.model.constraint.NoDelay) Test(org.testng.annotations.Test)

Example 28 with ShareableResource

use of org.btrplace.model.view.ShareableResource 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();
    org.btrplace.model.view.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 : ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ShareableResource(org.btrplace.model.view.ShareableResource) org.btrplace.model.constraint(org.btrplace.model.constraint) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) BootVM(org.btrplace.plan.event.BootVM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) ShareableResource(org.btrplace.model.view.ShareableResource) Test(org.testng.annotations.Test)

Example 29 with ShareableResource

use of org.btrplace.model.view.ShareableResource 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);
    org.btrplace.model.view.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 : Action(org.btrplace.plan.event.Action) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ShareableResource(org.btrplace.model.view.ShareableResource) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) BootVM(org.btrplace.plan.event.BootVM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) ShareableResource(org.btrplace.model.view.ShareableResource) ShutdownVM(org.btrplace.plan.event.ShutdownVM) Allocate(org.btrplace.plan.event.Allocate) Test(org.testng.annotations.Test)

Example 30 with ShareableResource

use of org.btrplace.model.view.ShareableResource 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 : ShareableResource(org.btrplace.model.view.ShareableResource) org.btrplace.model.constraint(org.btrplace.model.constraint) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) BootVM(org.btrplace.plan.event.BootVM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) Test(org.testng.annotations.Test)

Aggregations

ShareableResource (org.btrplace.model.view.ShareableResource)86 Test (org.testng.annotations.Test)61 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)47 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)41 SatConstraint (org.btrplace.model.constraint.SatConstraint)32 ArrayList (java.util.ArrayList)31 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)29 VM (org.btrplace.model.VM)27 Model (org.btrplace.model.Model)25 Node (org.btrplace.model.Node)25 DefaultModel (org.btrplace.model.DefaultModel)22 MigrateVM (org.btrplace.plan.event.MigrateVM)16 Mapping (org.btrplace.model.Mapping)13 Network (org.btrplace.model.view.network.Network)12 Switch (org.btrplace.model.view.network.Switch)12 Offline (org.btrplace.model.constraint.Offline)11 MinMTTRMig (org.btrplace.model.constraint.migration.MinMTTRMig)10 SchedulerException (org.btrplace.scheduler.SchedulerException)10 Fence (org.btrplace.model.constraint.Fence)7 Preserve (org.btrplace.model.constraint.Preserve)7