Search in sources :

Example 1 with ShutdownVM

use of org.btrplace.plan.event.ShutdownVM in project scheduler by btrplace.

the class AllowAllConstraintCheckerTest method testAcceptance.

@Test
public void testAcceptance() {
    SatConstraint cstr = mock(SatConstraint.class);
    AllowAllConstraintChecker<?> c = mock(AllowAllConstraintChecker.class, CALLS_REAL_METHODS);
    Model mo = new DefaultModel();
    List<VM> vms = Util.newVMs(mo, 10);
    List<Node> ns = Util.newNodes(mo, 10);
    when(cstr.getInvolvedNodes()).thenReturn(ns);
    when(cstr.getInvolvedVMs()).thenReturn(vms);
    MigrateVM m = new MigrateVM(vms.get(0), ns.get(0), ns.get(1), 0, 3);
    Assert.assertTrue(c.start(m));
    verify(c).startRunningVMPlacement(m);
    c.end(m);
    verify(c).endRunningVMPlacement(m);
    BootVM b = new BootVM(vms.get(0), ns.get(0), 0, 3);
    Assert.assertTrue(c.start(b));
    verify(c).startRunningVMPlacement(b);
    c.end(b);
    verify(c).endRunningVMPlacement(b);
    ResumeVM r = new ResumeVM(vms.get(0), ns.get(0), ns.get(1), 0, 3);
    Assert.assertTrue(c.start(r));
    verify(c).startRunningVMPlacement(r);
    c.end(r);
    verify(c).endRunningVMPlacement(r);
    // do not use the mock as the constructor is important
    // while earlier, the mock was needed for the verify()
    c = new AllowAllConstraintChecker<>(cstr);
    Set<VM> allVMs = new HashSet<>();
    for (Node n : mo.getMapping().getOnlineNodes()) {
        allVMs.addAll(mo.getMapping().getRunningVMs(n));
        allVMs.addAll(mo.getMapping().getSleepingVMs(n));
    }
    allVMs.addAll(mo.getMapping().getReadyVMs());
    c.track(allVMs);
    SuspendVM s = new SuspendVM(vms.get(0), ns.get(0), ns.get(1), 0, 3);
    Assert.assertTrue(c.start(s));
    ShutdownVM s2 = new ShutdownVM(vms.get(0), ns.get(0), 0, 3);
    Assert.assertTrue(c.start(s2));
    KillVM k = new KillVM(vms.get(0), ns.get(0), 0, 3);
    Assert.assertTrue(c.start(k));
    ForgeVM f = new ForgeVM(vms.get(0), 0, 3);
    Assert.assertTrue(c.start(f));
    BootNode bn = new BootNode(ns.get(0), 0, 3);
    Assert.assertTrue(c.start(bn));
    ShutdownNode sn = new ShutdownNode(ns.get(0), 0, 3);
    Assert.assertTrue(c.start(sn));
    SubstitutedVMEvent ss = new SubstitutedVMEvent(vms.get(9), vms.get(2));
    Assert.assertTrue(c.consume(ss));
    Allocate a = new Allocate(vms.get(0), ns.get(0), "cpu", 3, 4, 5);
    Assert.assertTrue(c.start(a));
    AllocateEvent ae = new AllocateEvent(vms.get(0), "cpu", 3);
    Assert.assertTrue(c.consume(ae));
}
Also used : KillVM(org.btrplace.plan.event.KillVM) DefaultModel(org.btrplace.model.DefaultModel) BootNode(org.btrplace.plan.event.BootNode) Node(org.btrplace.model.Node) BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) MigrateVM(org.btrplace.plan.event.MigrateVM) ForgeVM(org.btrplace.plan.event.ForgeVM) SubstitutedVMEvent(org.btrplace.plan.event.SubstitutedVMEvent) ResumeVM(org.btrplace.plan.event.ResumeVM) SuspendVM(org.btrplace.plan.event.SuspendVM) MigrateVM(org.btrplace.plan.event.MigrateVM) BootVM(org.btrplace.plan.event.BootVM) VM(org.btrplace.model.VM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) SuspendVM(org.btrplace.plan.event.SuspendVM) ResumeVM(org.btrplace.plan.event.ResumeVM) ForgeVM(org.btrplace.plan.event.ForgeVM) KillVM(org.btrplace.plan.event.KillVM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) BootVM(org.btrplace.plan.event.BootVM) ShutdownNode(org.btrplace.plan.event.ShutdownNode) ShutdownVM(org.btrplace.plan.event.ShutdownVM) Allocate(org.btrplace.plan.event.Allocate) HashSet(java.util.HashSet) AllocateEvent(org.btrplace.plan.event.AllocateEvent) Test(org.testng.annotations.Test)

Example 2 with ShutdownVM

use of org.btrplace.plan.event.ShutdownVM in project scheduler by btrplace.

the class LonelyTest method testContinuousIsSatisfied.

@Test(dependsOnMethods = { "testInstantiation" })
public void testContinuousIsSatisfied() {
    Model mo = new DefaultModel();
    List<VM> vms = Util.newVMs(mo, 10);
    List<Node> ns = Util.newNodes(mo, 10);
    Set<VM> s = new HashSet<>(Arrays.asList(vms.get(0), vms.get(1)));
    Mapping map = mo.getMapping();
    map.addOnlineNode(ns.get(0));
    map.addOnlineNode(ns.get(1));
    map.addOnlineNode(ns.get(2));
    map.addRunningVM(vms.get(0), ns.get(0));
    map.addRunningVM(vms.get(1), ns.get(0));
    map.addRunningVM(vms.get(2), ns.get(1));
    map.addRunningVM(vms.get(3), ns.get(1));
    Lonely l = new Lonely(s, true);
    ReconfigurationPlan p = new DefaultReconfigurationPlan(mo);
    Assert.assertEquals(l.isSatisfied(p), true);
    p.add(new MigrateVM(vms.get(1), ns.get(0), ns.get(1), 2, 4));
    Assert.assertEquals(l.isSatisfied(p), false);
    p.add(new ShutdownVM(vms.get(2), ns.get(1), 0, 1));
    Assert.assertEquals(l.isSatisfied(p), false);
    p.add(new MigrateVM(vms.get(3), ns.get(1), ns.get(2), 1, 2));
    Assert.assertEquals(l.isSatisfied(p), true);
}
Also used : DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ShutdownVM(org.btrplace.plan.event.ShutdownVM) MigrateVM(org.btrplace.plan.event.MigrateVM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 3 with ShutdownVM

use of org.btrplace.plan.event.ShutdownVM in project scheduler by btrplace.

the class OverbookTest method testContinuousIsSatisfied.

@Test
public void testContinuousIsSatisfied() {
    Model mo = new DefaultModel();
    List<VM> vms = Util.newVMs(mo, 10);
    Node n0 = mo.newNode();
    Node n1 = mo.newNode();
    Model i = new DefaultModel();
    Mapping cfg = i.getMapping();
    cfg.addOnlineNode(n0);
    cfg.addOnlineNode(n1);
    ShareableResource rc = new ShareableResource("cpu");
    rc.setCapacity(n0, 1);
    rc.setCapacity(n1, 4);
    rc.setConsumption(vms.get(0), 2);
    rc.setConsumption(vms.get(1), 2);
    rc.setConsumption(vms.get(2), 4);
    cfg.addRunningVM(vms.get(0), n0);
    cfg.addRunningVM(vms.get(1), n1);
    cfg.addRunningVM(vms.get(2), n1);
    cfg.addRunningVM(vms.get(3), n1);
    i.attach(rc);
    Overbook o = new Overbook(n1, "cpu", 2);
    o.setContinuous(true);
    ReconfigurationPlan p = new DefaultReconfigurationPlan(i);
    Assert.assertEquals(o.isSatisfied(p), true);
    p.add(new Allocate(vms.get(0), n0, "cpu", 1, 2, 5));
    Assert.assertEquals(o.isSatisfied(p), true);
    p.add(new Allocate(vms.get(1), n1, "cpu", 5, 2, 5));
    Assert.assertEquals(o.isSatisfied(p), false);
    p.add(new Allocate(vms.get(2), n1, "cpu", 2, 0, 1));
    Assert.assertEquals(o.isSatisfied(p), true);
    p.add(new Allocate(vms.get(3), n1, "cpu", 3, 4, 6));
    Assert.assertEquals(o.isSatisfied(p), false);
    p.add(new ShutdownVM(vms.get(2), n1, 2, 3));
    Assert.assertEquals(o.isSatisfied(p), true);
}
Also used : DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ShutdownVM(org.btrplace.plan.event.ShutdownVM) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ShareableResource(org.btrplace.model.view.ShareableResource) ShutdownVM(org.btrplace.plan.event.ShutdownVM) Allocate(org.btrplace.plan.event.Allocate) Test(org.testng.annotations.Test)

Example 4 with ShutdownVM

use of org.btrplace.plan.event.ShutdownVM 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 5 with ShutdownVM

use of org.btrplace.plan.event.ShutdownVM in project scheduler by btrplace.

the class OfflineTest method testContinuousIsSatisfied.

@Test
public void testContinuousIsSatisfied() {
    Model mo = new DefaultModel();
    List<Node> ns = Util.newNodes(mo, 10);
    List<VM> vms = Util.newVMs(mo, 10);
    Mapping map = mo.getMapping();
    map.addOnlineNode(ns.get(0));
    map.addOnlineNode(ns.get(1));
    Offline off = new Offline(ns.get(0));
    map.addRunningVM(vms.get(0), ns.get(0));
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
    Assert.assertEquals(off.isSatisfied(plan), false);
    plan.add(new ShutdownNode(ns.get(1), 0, 1));
    plan.add(new ShutdownVM(vms.get(0), ns.get(0), 0, 1));
    Assert.assertEquals(off.isSatisfied(plan), false);
    plan.add(new ShutdownNode(ns.get(0), 1, 2));
    Assert.assertEquals(off.isSatisfied(plan), true);
}
Also used : DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ShutdownNode(org.btrplace.plan.event.ShutdownNode) ShutdownVM(org.btrplace.plan.event.ShutdownVM) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ShutdownNode(org.btrplace.plan.event.ShutdownNode) ShutdownVM(org.btrplace.plan.event.ShutdownVM) Test(org.testng.annotations.Test)

Aggregations

ShutdownVM (org.btrplace.plan.event.ShutdownVM)10 Test (org.testng.annotations.Test)9 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)8 DefaultReconfigurationPlan (org.btrplace.plan.DefaultReconfigurationPlan)6 BootVM (org.btrplace.plan.event.BootVM)6 MigrateVM (org.btrplace.plan.event.MigrateVM)5 Allocate (org.btrplace.plan.event.Allocate)3 ShutdownNode (org.btrplace.plan.event.ShutdownNode)3 SuspendVM (org.btrplace.plan.event.SuspendVM)3 HashSet (java.util.HashSet)2 Node (org.btrplace.model.Node)2 ShareableResource (org.btrplace.model.view.ShareableResource)2 Action (org.btrplace.plan.event.Action)2 BootNode (org.btrplace.plan.event.BootNode)2 ResumeVM (org.btrplace.plan.event.ResumeVM)2 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)2 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)2 DefaultModel (org.btrplace.model.DefaultModel)1 Mapping (org.btrplace.model.Mapping)1 Model (org.btrplace.model.Model)1