Search in sources :

Example 1 with ResumeVM

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

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

the class ReconfigurationPlanFuzzer method setDestinationState.

private void setDestinationState(ReconfigurationPlan p, VM v) {
    Mapping map = p.getOrigin().getMapping();
    Node host = map.getVMLocation(v);
    int n = rnd.nextInt(dstReadyVMs + dstRunningVMs + dstSleepingVMs);
    int[] bounds = schedule();
    int duration = bounds[1] - bounds[0];
    if (n < dstReadyVMs) {
        if (host != null) {
            p.add(new ShutdownVM(v, host, bounds[0], bounds[1]));
            p.getOrigin().getAttributes().put(v, "shutdown", duration);
        }
    } else if (n < dstReadyVMs + dstRunningVMs) {
        if (host == null) {
            p.add(new BootVM(v, pick(map.getAllNodes()), bounds[0], bounds[1]));
            p.getOrigin().getAttributes().put(v, "boot", duration);
        } else {
            // was running -> migrate
            if (map.isRunning(v)) {
                Node dst = pick(map.getAllNodes());
                if (!host.equals(dst)) {
                    p.add(new MigrateVM(v, host, dst, bounds[0], bounds[1]));
                    p.getOrigin().getAttributes().put(v, "migrate", duration);
                }
            } else {
                // was sleeping -> resume
                p.add(new ResumeVM(v, host, pick(map.getAllNodes()), bounds[0], bounds[1]));
                p.getOrigin().getAttributes().put(v, "resume", duration);
            }
        }
    } else {
        // moving to sleeping state
        if (map.isRunning(v)) {
            p.add(new SuspendVM(v, host, host, bounds[0], bounds[1]));
            p.getOrigin().getAttributes().put(v, "sleeping", duration);
        }
    }
}
Also used : ResumeVM(org.btrplace.plan.event.ResumeVM) SuspendVM(org.btrplace.plan.event.SuspendVM) Node(org.btrplace.model.Node) BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) BootVM(org.btrplace.plan.event.BootVM) Mapping(org.btrplace.model.Mapping) MigrateVM(org.btrplace.plan.event.MigrateVM) ShutdownVM(org.btrplace.plan.event.ShutdownVM)

Aggregations

Node (org.btrplace.model.Node)2 BootNode (org.btrplace.plan.event.BootNode)2 BootVM (org.btrplace.plan.event.BootVM)2 MigrateVM (org.btrplace.plan.event.MigrateVM)2 ResumeVM (org.btrplace.plan.event.ResumeVM)2 ShutdownNode (org.btrplace.plan.event.ShutdownNode)2 ShutdownVM (org.btrplace.plan.event.ShutdownVM)2 SuspendVM (org.btrplace.plan.event.SuspendVM)2 HashSet (java.util.HashSet)1 DefaultModel (org.btrplace.model.DefaultModel)1 Mapping (org.btrplace.model.Mapping)1 Model (org.btrplace.model.Model)1 VM (org.btrplace.model.VM)1 Allocate (org.btrplace.plan.event.Allocate)1 AllocateEvent (org.btrplace.plan.event.AllocateEvent)1 ForgeVM (org.btrplace.plan.event.ForgeVM)1 KillVM (org.btrplace.plan.event.KillVM)1 SubstitutedVMEvent (org.btrplace.plan.event.SubstitutedVMEvent)1 Test (org.testng.annotations.Test)1