Search in sources :

Example 1 with SuspendVM

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

the class DenyMyVMsActionsTest method testDeny.

@Test
public void testDeny() {
    Model mo = new DefaultModel();
    List<VM> vms = Util.newVMs(mo, 10);
    List<Node> ns = Util.newNodes(mo, 10);
    when(cstr.getInvolvedNodes()).thenReturn(Arrays.asList(ns.get(0), ns.get(1), ns.get(2)));
    when(cstr.getInvolvedVMs()).thenReturn(Arrays.asList(vms.get(0), vms.get(1), vms.get(2)));
    DenyMyVMsActions<SatConstraint> c = new DenyMyVMsActions<SatConstraint>(cstr) {
    };
    Assert.assertFalse(c.start(new BootVM(vms.get(0), ns.get(0), 0, 3)));
    Assert.assertTrue(c.start(new BootVM(vms.get(8), ns.get(0), 0, 3)));
    Assert.assertFalse(c.start(new ResumeVM(vms.get(0), ns.get(0), ns.get(1), 0, 3)));
    Assert.assertTrue(c.start(new ResumeVM(vms.get(6), ns.get(0), ns.get(1), 0, 3)));
    Assert.assertFalse(c.start(new MigrateVM(vms.get(0), ns.get(0), ns.get(1), 0, 3)));
    Assert.assertTrue(c.start(new MigrateVM(vms.get(4), ns.get(0), ns.get(1), 0, 3)));
    Assert.assertFalse(c.start(new SuspendVM(vms.get(0), ns.get(0), ns.get(1), 0, 3)));
    Assert.assertTrue(c.start(new SuspendVM(vms.get(9), ns.get(0), ns.get(1), 0, 3)));
    Assert.assertFalse(c.start(new ShutdownVM(vms.get(0), ns.get(0), 0, 3)));
    Assert.assertTrue(c.start(new ShutdownVM(vms.get(5), ns.get(0), 0, 3)));
    Assert.assertFalse(c.start(new KillVM(vms.get(0), ns.get(0), 0, 3)));
    Assert.assertTrue(c.start(new KillVM(vms.get(6), ns.get(0), 0, 3)));
    Assert.assertFalse(c.start(new ForgeVM(vms.get(0), 0, 3)));
    Assert.assertTrue(c.start(new ForgeVM(vms.get(6), 0, 3)));
    Assert.assertFalse(c.start(new Allocate(vms.get(0), ns.get(0), "cpu", 3, 4, 5)));
    Assert.assertTrue(c.start(new Allocate(vms.get(5), ns.get(0), "cpu", 3, 4, 5)));
    Assert.assertFalse(c.consume(new SubstitutedVMEvent(vms.get(0), vms.get(2))));
    Assert.assertTrue(c.consume(new SubstitutedVMEvent(vms.get(9), vms.get(2))));
    Assert.assertFalse(c.consume(new AllocateEvent(vms.get(2), "cpu", 3)));
    Assert.assertTrue(c.consume(new AllocateEvent(vms.get(9), "cpu", 3)));
}
Also used : KillVM(org.btrplace.plan.event.KillVM) DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) 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) ResumeVM(org.btrplace.plan.event.ResumeVM) 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) 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) ShutdownVM(org.btrplace.plan.event.ShutdownVM) Allocate(org.btrplace.plan.event.Allocate) AllocateEvent(org.btrplace.plan.event.AllocateEvent) Test(org.testng.annotations.Test)

Example 2 with SuspendVM

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

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

the class ReconfigurationPlanConverterTest method testBundle.

@Test
public void testBundle() throws JSONConverterException {
    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();
    Mapping map = mo.getMapping();
    map.addOnlineNode(n1);
    map.addOfflineNode(n2);
    map.addOnlineNode(n3);
    map.addReadyVM(vm1);
    map.addRunningVM(vm2, n1);
    map.addRunningVM(vm3, n1);
    map.addSleepingVM(vm4, n3);
    map.addRunningVM(vm5, n3);
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
    plan.add(new BootVM(vm1, n3, 1, 2));
    final MigrateVM mm = new MigrateVM(vm3, n3, n2, 4, 5, 4000);
    mm.addEvent(Action.Hook.PRE, new AllocateEvent(vm3, "bar", 5));
    mm.addEvent(Action.Hook.POST, new SubstitutedVMEvent(vm4, vm5));
    mm.addEvent(Action.Hook.POST, new AllocateEvent(vm5, "baz", 4));
    plan.add(mm);
    plan.add(new ShutdownVM(vm5, n3, 3, 4));
    plan.add(new Allocate(vm1, n3, "foo", 5, 3, 5));
    plan.add(new SuspendVM(vm3, n3, n3, 3, 5));
    plan.add(new ResumeVM(vm4, n3, n3, 4, 8));
    plan.add(new BootNode(n2, 2, 5));
    plan.add(new ShutdownNode(n1, 5, 10));
    ReconfigurationPlanConverter rcp = ReconfigurationPlanConverter.newBundle();
    String j = rcp.toJSONString(plan);
    ReconfigurationPlan p2 = rcp.fromJSON(j);
    Assert.assertEquals(p2, plan);
}
Also used : 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) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) Mapping(org.btrplace.model.Mapping) MigrateVM(org.btrplace.plan.event.MigrateVM) SubstitutedVMEvent(org.btrplace.plan.event.SubstitutedVMEvent) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) 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) 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) AllocateEvent(org.btrplace.plan.event.AllocateEvent) Test(org.testng.annotations.Test)

Example 4 with SuspendVM

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

the class SeqTest method testContinuousSatisfied2.

@Test
public void testContinuousSatisfied2() {
    Model mo = new DefaultModel();
    List<Node> ns = Util.newNodes(mo, 5);
    List<VM> vms = Util.newVMs(mo, 5);
    Mapping map = mo.getMapping();
    map.addOnlineNode(ns.get(0));
    map.addOnlineNode(ns.get(1));
    map.addReadyVM(vms.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(0));
    ReconfigurationPlan p = new DefaultReconfigurationPlan(mo);
    p.add(new BootVM(vms.get(0), ns.get(0), 0, 1));
    p.add(new SuspendVM(vms.get(2), ns.get(1), ns.get(1), 1, 2));
    p.add(new ShutdownVM(vms.get(3), ns.get(0), 2, 3));
    List<VM> seq = Arrays.asList(vms.get(0), vms.get(1), vms.get(2), vms.get(3));
    Seq cstr = new Seq(seq);
    Assert.assertEquals(cstr.isSatisfied(p), true);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Mapping(org.btrplace.model.Mapping) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) SuspendVM(org.btrplace.plan.event.SuspendVM) ResumeVM(org.btrplace.plan.event.ResumeVM) 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) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) BootVM(org.btrplace.plan.event.BootVM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) Test(org.testng.annotations.Test)

Example 5 with SuspendVM

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

the class SeqTest method testContinuousIsSatisfied.

@Test
public void testContinuousIsSatisfied() {
    Model mo = new DefaultModel();
    List<Node> ns = Util.newNodes(mo, 5);
    List<VM> vms = Util.newVMs(mo, 5);
    Mapping map = mo.getMapping();
    map.addOnlineNode(ns.get(0));
    map.addOnlineNode(ns.get(1));
    map.addRunningVM(vms.get(0), ns.get(0));
    map.addReadyVM(vms.get(1));
    map.addSleepingVM(vms.get(2), ns.get(0));
    map.addRunningVM(vms.get(3), ns.get(0));
    List<VM> l = Arrays.asList(vms.get(0), vms.get(1), vms.get(2), vms.get(3));
    Seq c = new Seq(l);
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
    plan.add(new MigrateVM(vms.get(3), ns.get(0), ns.get(1), 0, 1));
    plan.add(new SuspendVM(vms.get(0), ns.get(0), ns.get(0), 2, 3));
    plan.add(new BootVM(vms.get(1), ns.get(0), 3, 4));
    plan.add(new ResumeVM(vms.get(2), ns.get(0), ns.get(0), 4, 5));
    Assert.assertEquals(c.isSatisfied(plan), true);
    // Overlap
    plan = new DefaultReconfigurationPlan(mo);
    plan.add(new BootVM(vms.get(1), ns.get(0), 3, 4));
    plan.add(new ResumeVM(vms.get(2), ns.get(0), ns.get(0), 3, 5));
    Assert.assertEquals(c.isSatisfied(plan), false);
    // Not the right precedence
    plan = new DefaultReconfigurationPlan(mo);
    plan.add(new BootVM(vms.get(1), ns.get(0), 3, 4));
    plan.add(new ResumeVM(vms.get(2), ns.get(0), ns.get(0), 0, 1));
    Assert.assertEquals(c.isSatisfied(plan), false);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Mapping(org.btrplace.model.Mapping) MigrateVM(org.btrplace.plan.event.MigrateVM) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ResumeVM(org.btrplace.plan.event.ResumeVM) SuspendVM(org.btrplace.plan.event.SuspendVM) ResumeVM(org.btrplace.plan.event.ResumeVM) 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) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) BootVM(org.btrplace.plan.event.BootVM) Test(org.testng.annotations.Test)

Aggregations

MigrateVM (org.btrplace.plan.event.MigrateVM)10 SuspendVM (org.btrplace.plan.event.SuspendVM)10 Node (org.btrplace.model.Node)9 ShutdownVM (org.btrplace.plan.event.ShutdownVM)9 Model (org.btrplace.model.Model)8 VM (org.btrplace.model.VM)8 BootVM (org.btrplace.plan.event.BootVM)8 ResumeVM (org.btrplace.plan.event.ResumeVM)8 Test (org.testng.annotations.Test)8 DefaultModel (org.btrplace.model.DefaultModel)7 ShutdownNode (org.btrplace.plan.event.ShutdownNode)6 Mapping (org.btrplace.model.Mapping)5 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)5 BootNode (org.btrplace.plan.event.BootNode)5 DefaultReconfigurationPlan (org.btrplace.plan.DefaultReconfigurationPlan)4 Allocate (org.btrplace.plan.event.Allocate)4 AllocateEvent (org.btrplace.plan.event.AllocateEvent)4 ForgeVM (org.btrplace.plan.event.ForgeVM)3 KillVM (org.btrplace.plan.event.KillVM)3 SubstitutedVMEvent (org.btrplace.plan.event.SubstitutedVMEvent)3