Search in sources :

Example 1 with ShutdownNode

use of org.btrplace.plan.event.ShutdownNode 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 ShutdownNode

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

the class DependencyBasedPlanApplierTest method testApply.

@Test
public void testApply() {
    Model mo = new DefaultModel();
    List<VM> vms = Util.newVMs(mo, 10);
    List<Node> ns = Util.newNodes(mo, 10);
    Mapping map = mo.getMapping();
    map.addOnlineNode(ns.get(0));
    map.addOnlineNode(ns.get(1));
    map.addOnlineNode(ns.get(2));
    map.addOfflineNode(ns.get(3));
    map.addRunningVM(vms.get(0), ns.get(2));
    map.addRunningVM(vms.get(1), ns.get(0));
    map.addRunningVM(vms.get(2), ns.get(1));
    map.addRunningVM(vms.get(3), ns.get(1));
    BootNode bN4 = new BootNode(ns.get(3), 3, 5);
    MigrateVM mVM1 = new MigrateVM(vms.get(0), ns.get(2), ns.get(3), 6, 7);
    Allocate aVM3 = new Allocate(vms.get(2), ns.get(1), "cpu", 7, 8, 9);
    MigrateVM mVM2 = new MigrateVM(vms.get(1), ns.get(0), ns.get(1), 1, 3);
    MigrateVM mVM4 = new MigrateVM(vms.get(3), ns.get(1), ns.get(2), 1, 7);
    ShutdownNode sN1 = new ShutdownNode(ns.get(0), 5, 7);
    ShareableResource rc = new ShareableResource("cpu");
    rc.setConsumption(vms.get(2), 3);
    mo.attach(rc);
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
    plan.add(bN4);
    plan.add(mVM1);
    plan.add(aVM3);
    plan.add(mVM2);
    plan.add(mVM4);
    plan.add(sN1);
    Model res = new DependencyBasedPlanApplier().apply(plan);
    Assert.assertNotNull(res);
    Mapping resMapping = res.getMapping();
    Assert.assertTrue(resMapping.isOffline(ns.get(0)));
    Assert.assertTrue(resMapping.isOnline(ns.get(3)));
    rc = ShareableResource.get(res, "cpu");
    Assert.assertEquals(rc.getConsumption(vms.get(2)), 7);
    Assert.assertEquals(resMapping.getVMLocation(vms.get(0)), ns.get(3));
    Assert.assertEquals(resMapping.getVMLocation(vms.get(1)), ns.get(1));
    Assert.assertEquals(resMapping.getVMLocation(vms.get(3)), ns.get(2));
}
Also used : BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) BootNode(org.btrplace.plan.event.BootNode) MigrateVM(org.btrplace.plan.event.MigrateVM) ShareableResource(org.btrplace.model.view.ShareableResource) MigrateVM(org.btrplace.plan.event.MigrateVM) ShutdownNode(org.btrplace.plan.event.ShutdownNode) Allocate(org.btrplace.plan.event.Allocate) Test(org.testng.annotations.Test)

Example 3 with ShutdownNode

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

the class MaxOnlineTest method isSatisfiedReconfigurationPlan.

@Test
public void isSatisfiedReconfigurationPlan() {
    Model model = new DefaultModel();
    Mapping map = model.getMapping();
    Node n1 = model.newNode();
    Node n2 = model.newNode();
    Node n3 = model.newNode();
    map.addOnlineNode(n1);
    map.addOnlineNode(n2);
    map.addOfflineNode(n3);
    Set<Node> s = new HashSet<>(Arrays.asList(n1, n2, n3));
    MaxOnline mo = new MaxOnline(s, 2);
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(model);
    Assert.assertTrue(mo.isSatisfied(plan));
    plan.add(new BootNode(n3, 3, 9));
    Assert.assertFalse(mo.isSatisfied(plan));
    plan.add(new ShutdownNode(n2, 0, 5));
    Assert.assertTrue(mo.isSatisfied(plan));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) BootNode(org.btrplace.plan.event.BootNode) Node(org.btrplace.model.Node) BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) ShutdownNode(org.btrplace.plan.event.ShutdownNode) Mapping(org.btrplace.model.Mapping) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 4 with ShutdownNode

use of org.btrplace.plan.event.ShutdownNode 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)

Example 5 with ShutdownNode

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

the class DefaultReconfigurationPlanTest method testEquals.

@Test
public void testEquals() {
    Model mo = new DefaultModel();
    VM v = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    mo.getMapping().addOnlineNode(n1);
    mo.getMapping().addOnlineNode(n2);
    mo.getMapping().addRunningVM(v, n1);
    ReconfigurationPlan p1 = new DefaultReconfigurationPlan(mo);
    p1.add(new ShutdownNode(n1, 1, 2));
    p1.add(new ShutdownNode(n2, 1, 2));
    ReconfigurationPlan p2 = new DefaultReconfigurationPlan(mo.copy());
    p2.add(new ShutdownNode(n1, 1, 2));
    p2.add(new ShutdownNode(n2, 1, 2));
    Assert.assertEquals(p1, p2);
/*
        java.lang.RuntimeException: The resulting schedule differ. Got:
0:1 {action=suspend(vm=vm#0, from=node#1, to=node#1)}
1:2 {action=shutdown(node=node#0)}
1:2 {action=shutdown(node=node#1)}

Expected:
0:1 {action=suspend(vm=vm#0, from=node#1, to=node#1)}
1:2 {action=shutdown(node=node#0)}
1:2 {action=shutdown(node=node#1)}
         */
}
Also used : MigrateVM(org.btrplace.plan.event.MigrateVM) SuspendVM(org.btrplace.plan.event.SuspendVM) ShutdownNode(org.btrplace.plan.event.ShutdownNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) Test(org.testng.annotations.Test)

Aggregations

ShutdownNode (org.btrplace.plan.event.ShutdownNode)8 Test (org.testng.annotations.Test)6 BootNode (org.btrplace.plan.event.BootNode)5 MigrateVM (org.btrplace.plan.event.MigrateVM)5 Allocate (org.btrplace.plan.event.Allocate)3 SuspendVM (org.btrplace.plan.event.SuspendVM)3 HashSet (java.util.HashSet)2 DefaultModel (org.btrplace.model.DefaultModel)2 Model (org.btrplace.model.Model)2 Node (org.btrplace.model.Node)2 ShareableResource (org.btrplace.model.view.ShareableResource)2 DefaultReconfigurationPlan (org.btrplace.plan.DefaultReconfigurationPlan)2 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)2 ShutdownVM (org.btrplace.plan.event.ShutdownVM)2 Mapping (org.btrplace.model.Mapping)1 VM (org.btrplace.model.VM)1 Action (org.btrplace.plan.event.Action)1 AllocateEvent (org.btrplace.plan.event.AllocateEvent)1 BootVM (org.btrplace.plan.event.BootVM)1 ForgeVM (org.btrplace.plan.event.ForgeVM)1