Search in sources :

Example 6 with AllocateEvent

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

the class DefaultPlanApplierTest method testFireComposedAction.

@Test
public void testFireComposedAction() {
    DefaultPlanApplier app = new MockApplier();
    EventCommittedListener ev = mock(EventCommittedListener.class);
    app.addEventCommittedListener(ev);
    BootVM b = new BootVM(vms.get(0), ns.get(0), 0, 5);
    AllocateEvent pre = new AllocateEvent(vms.get(0), "cpu", 7);
    b.addEvent(Action.Hook.PRE, pre);
    SubstitutedVMEvent post = new SubstitutedVMEvent(vms.get(0), vms.get(3));
    b.addEvent(Action.Hook.POST, post);
    InOrder order = inOrder(ev);
    app.fireAction(b);
    order.verify(ev).committed(pre);
    order.verify(ev).committed(b);
    order.verify(ev).committed(post);
}
Also used : InOrder(org.mockito.InOrder) EventCommittedListener(org.btrplace.plan.event.EventCommittedListener) BootVM(org.btrplace.plan.event.BootVM) SubstitutedVMEvent(org.btrplace.plan.event.SubstitutedVMEvent) AllocateEvent(org.btrplace.plan.event.AllocateEvent) Test(org.testng.annotations.Test)

Example 7 with AllocateEvent

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

the class InstanceConverter method toInstance.

public static Instance toInstance(ReconfigurationPlan p) {
    Model mo = p.getOrigin().copy();
    List<SatConstraint> cstrs = new ArrayList<>();
    Set<VM> knownVMs = new HashSet<>();
    Set<Node> knownNodes = new HashSet<>();
    for (Action a : p.getActions()) {
        if (a instanceof NodeEvent) {
            Node n = ((NodeEvent) a).getNode();
            knownNodes.add(n);
            cstrs.add(new Schedule(n, a.getStart(), a.getEnd()));
            if (a instanceof BootNode) {
                cstrs.add(new Online(n));
            } else if (a instanceof ShutdownNode) {
                cstrs.add(new Offline(n));
            }
        } else if (a instanceof VMEvent) {
            VM v = ((VMEvent) a).getVM();
            knownVMs.add(v);
            cstrs.add(new Schedule(v, a.getStart(), a.getEnd()));
            if (a instanceof BootVM) {
                cstrs.add(new Running(v));
                cstrs.add(new Fence(v, ((BootVM) a).getDestinationNode()));
            } else if (a instanceof MigrateVM) {
                cstrs.add(new Fence(v, ((MigrateVM) a).getDestinationNode()));
                cstrs.add(new Running(v));
            } else if (a instanceof ShutdownVM) {
                cstrs.add(new Ready(v));
            } else if (a instanceof SuspendVM) {
                cstrs.add(new Sleeping(v));
            } else if (a instanceof ResumeVM) {
                cstrs.add(new Running(v));
                cstrs.add(new Fence(v, ((ResumeVM) a).getDestinationNode()));
            } else if (a instanceof Allocate) {
                cstrs.add(new Preserve(v, ((Allocate) a).getResourceId(), ((Allocate) a).getAmount()));
                cstrs.add(new Fence(v, ((Allocate) a).getHost()));
            }
        }
        // Catch the allocate events
        for (Event e : a.getEvents(Action.Hook.PRE)) {
            if (e instanceof AllocateEvent) {
                cstrs.add(new Preserve(((AllocateEvent) e).getVM(), ((AllocateEvent) e).getResourceId(), ((AllocateEvent) e).getAmount()));
            }
        }
        for (Event e : a.getEvents(Action.Hook.POST)) {
            if (e instanceof AllocateEvent) {
                cstrs.add(new Preserve(((AllocateEvent) e).getVM(), ((AllocateEvent) e).getResourceId(), ((AllocateEvent) e).getAmount()));
            }
        }
    }
    // State maintenance
    for (Node n : mo.getMapping().getAllNodes()) {
        if (knownNodes.contains(n)) {
            continue;
        }
        if (mo.getMapping().isOnline(n)) {
            cstrs.add(new Online(n));
        } else if (mo.getMapping().isOffline(n)) {
            cstrs.add(new Offline(n));
        }
    }
    mo.getMapping().getAllVMs().stream().filter(v -> !knownVMs.contains(v)).forEach(v -> {
        if (mo.getMapping().isReady(v)) {
            cstrs.add(new Ready(v));
        } else if (mo.getMapping().isRunning(v)) {
            cstrs.add(new Running(v));
            cstrs.add(new Fence(v, mo.getMapping().getVMLocation(v)));
        } else if (mo.getMapping().isSleeping(v)) {
            cstrs.add(new Sleeping(v));
            cstrs.add(new Fence(v, mo.getMapping().getVMLocation(v)));
        }
    });
    return new Instance(mo, cstrs, new MinMTTR());
}
Also used : Ready(org.btrplace.model.constraint.Ready) Node(org.btrplace.model.Node) Preserve(org.btrplace.model.constraint.Preserve) MigrateVM(org.btrplace.plan.event.MigrateVM) VMEvent(org.btrplace.plan.event.VMEvent) Schedule(org.btrplace.safeplace.testing.verification.btrplace.Schedule) Fence(org.btrplace.model.constraint.Fence) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) BootVM(org.btrplace.plan.event.BootVM) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) VM(org.btrplace.model.VM) Running(org.btrplace.model.constraint.Running) ShutdownVM(org.btrplace.plan.event.ShutdownVM) SuspendVM(org.btrplace.plan.event.SuspendVM) SatConstraint(org.btrplace.model.constraint.SatConstraint) Model(org.btrplace.model.Model) Sleeping(org.btrplace.model.constraint.Sleeping) ResumeVM(org.btrplace.plan.event.ResumeVM) Set(java.util.Set) BootNode(org.btrplace.plan.event.BootNode) Online(org.btrplace.model.constraint.Online) AllocateEvent(org.btrplace.plan.event.AllocateEvent) Event(org.btrplace.plan.event.Event) NodeEvent(org.btrplace.plan.event.NodeEvent) MinMTTR(org.btrplace.model.constraint.MinMTTR) Offline(org.btrplace.model.constraint.Offline) List(java.util.List) ShutdownNode(org.btrplace.plan.event.ShutdownNode) Allocate(org.btrplace.plan.event.Allocate) Instance(org.btrplace.model.Instance) Action(org.btrplace.plan.event.Action) Action(org.btrplace.plan.event.Action) Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) ArrayList(java.util.ArrayList) MinMTTR(org.btrplace.model.constraint.MinMTTR) NodeEvent(org.btrplace.plan.event.NodeEvent) ResumeVM(org.btrplace.plan.event.ResumeVM) Fence(org.btrplace.model.constraint.Fence) HashSet(java.util.HashSet) VMEvent(org.btrplace.plan.event.VMEvent) BootNode(org.btrplace.plan.event.BootNode) SatConstraint(org.btrplace.model.constraint.SatConstraint) Offline(org.btrplace.model.constraint.Offline) MigrateVM(org.btrplace.plan.event.MigrateVM) Preserve(org.btrplace.model.constraint.Preserve) Ready(org.btrplace.model.constraint.Ready) SuspendVM(org.btrplace.plan.event.SuspendVM) Sleeping(org.btrplace.model.constraint.Sleeping) 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) Schedule(org.btrplace.safeplace.testing.verification.btrplace.Schedule) Model(org.btrplace.model.Model) Running(org.btrplace.model.constraint.Running) ShutdownNode(org.btrplace.plan.event.ShutdownNode) BootVM(org.btrplace.plan.event.BootVM) VMEvent(org.btrplace.plan.event.VMEvent) AllocateEvent(org.btrplace.plan.event.AllocateEvent) Event(org.btrplace.plan.event.Event) NodeEvent(org.btrplace.plan.event.NodeEvent) Online(org.btrplace.model.constraint.Online) ShutdownVM(org.btrplace.plan.event.ShutdownVM) Allocate(org.btrplace.plan.event.Allocate) AllocateEvent(org.btrplace.plan.event.AllocateEvent)

Example 8 with AllocateEvent

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

the class PreserveTest method testIsSatisfied.

@Test(dependsOnMethods = { "testInstantiation" })
public void testIsSatisfied() {
    Model m = new DefaultModel();
    List<VM> vms = Util.newVMs(m, 5);
    List<Node> ns = Util.newNodes(m, 5);
    ShareableResource rc = new ShareableResource("cpu", 3, 3);
    Mapping map = m.getMapping();
    map.addOnlineNode(ns.get(0));
    map.addOnlineNode(ns.get(1));
    map.addRunningVM(vms.get(0), ns.get(0));
    map.addSleepingVM(vms.get(1), ns.get(0));
    map.addRunningVM(vms.get(2), ns.get(0));
    m.attach(rc);
    Preserve p = new Preserve(vms.get(0), "cpu", 3);
    rc.setConsumption(vms.get(0), 3);
    // Not running so we don't care
    rc.setConsumption(vms.get(1), 1);
    rc.setConsumption(vms.get(2), 3);
    Assert.assertEquals(true, p.isSatisfied(m));
    // Set to 3 by default
    rc.unset(vms.get(2));
    Assert.assertEquals(true, p.isSatisfied(m));
    Assert.assertEquals(false, new Preserve(vms.get(2), "mem", 3).isSatisfied(m));
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(m);
    rc.setConsumption(vms.get(1), 1);
    Assert.assertFalse(new Preserve(vms.get(2), "cpu", 4).isSatisfied(plan));
    plan.add(new Allocate(vms.get(2), ns.get(0), "cpu", 7, 5, 7));
    Assert.assertTrue(p.isSatisfied(plan));
    rc.setConsumption(vms.get(0), 1);
    AllocateEvent e = new AllocateEvent(vms.get(0), "cpu", 4);
    Assert.assertFalse(p.isSatisfied(plan));
    MigrateVM mig = new MigrateVM(vms.get(0), ns.get(0), ns.get(1), 0, 3);
    mig.addEvent(Action.Hook.POST, e);
    plan.add(mig);
    Assert.assertTrue(p.isSatisfied(plan));
}
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) ShareableResource(org.btrplace.model.view.ShareableResource) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Allocate(org.btrplace.plan.event.Allocate) AllocateEvent(org.btrplace.plan.event.AllocateEvent) Test(org.testng.annotations.Test)

Aggregations

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