Search in sources :

Example 6 with Allocate

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

use of org.btrplace.plan.event.Allocate 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 : DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) ShareableResource(org.btrplace.model.view.ShareableResource) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) Allocate(org.btrplace.plan.event.Allocate) AllocateEvent(org.btrplace.plan.event.AllocateEvent) Test(org.testng.annotations.Test)

Example 8 with Allocate

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

the class TimeBasedPlanApplierTest method makePlan.

private static ReconfigurationPlan makePlan(Model mo, List<Node> ns, List<VM> vms) {
    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);
    return plan;
}
Also used : BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) MigrateVM(org.btrplace.plan.event.MigrateVM) ShareableResource(org.btrplace.model.view.ShareableResource) Allocate(org.btrplace.plan.event.Allocate)

Example 9 with Allocate

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

the class CShareableResource method insertActions.

@Override
public boolean insertActions(ReconfigurationProblem r, Solution s, ReconfigurationPlan p) {
    Mapping srcMapping = r.getSourceModel().getMapping();
    // Encache the VM -> Action to ease the event injection.
    Map<VM, Action> actions = new HashMap<>();
    p.getActions().stream().filter(RunningVMPlacement.class::isInstance).map(a -> (RunningVMPlacement) a).forEach(a -> actions.put(destVM(a.getVM()), (Action) a));
    for (VM vm : r.getFutureRunningVMs()) {
        Slice dSlice = r.getVMAction(vm).getDSlice();
        Node destNode = r.getNode(s.getIntVal(dSlice.getHoster()));
        if (srcMapping.isRunning(vm) && destNode.equals(srcMapping.getVMLocation(vm))) {
            // Was running and stay on the same node
            // Check if the VM has been cloned
            // TODO: might be too late depending on the symmetry breaking on the actions schedule
            insertAllocateAction(p, vm, destNode, s.getIntVal(dSlice.getStart()));
        } else {
            VM dVM = destVM(vm);
            Action a = actions.get(dVM);
            if (a instanceof MigrateVM) {
                // For a migrated VM, we allocate once the migration over
                insertAllocateEvent(a, Action.Hook.POST, dVM);
            } else {
                // Resume or Boot VM
                // As the VM was not running, we pre-allocate
                insertAllocateEvent(a, Action.Hook.PRE, dVM);
            }
        }
    }
    return true;
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) Arrays(java.util.Arrays) SchedulerException(org.btrplace.scheduler.SchedulerException) TIntArrayList(gnu.trove.list.array.TIntArrayList) Node(org.btrplace.model.Node) Preserve(org.btrplace.model.constraint.Preserve) Overbook(org.btrplace.model.constraint.Overbook) TDoubleList(gnu.trove.list.TDoubleList) ContradictionException(org.chocosolver.solver.exception.ContradictionException) MigrateVM(org.btrplace.plan.event.MigrateVM) HashMap(java.util.HashMap) RoundedUpDivision(org.btrplace.scheduler.choco.extensions.RoundedUpDivision) TObjectIntMap(gnu.trove.map.TObjectIntMap) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) TObjectDoubleHashMap(gnu.trove.map.hash.TObjectDoubleHashMap) HashSet(java.util.HashSet) TObjectDoubleMap(gnu.trove.map.TObjectDoubleMap) VM(org.btrplace.model.VM) SchedulerModelingException(org.btrplace.scheduler.SchedulerModelingException) Mapping(org.btrplace.model.Mapping) Map(java.util.Map) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) SatConstraint(org.btrplace.model.constraint.SatConstraint) Model(org.btrplace.model.Model) TIntList(gnu.trove.list.TIntList) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) Set(java.util.Set) Cause(org.chocosolver.solver.Cause) Parameters(org.btrplace.scheduler.choco.Parameters) AllocateEvent(org.btrplace.plan.event.AllocateEvent) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) IntVar(org.chocosolver.solver.variables.IntVar) List(java.util.List) TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) RunningVMPlacement(org.btrplace.plan.event.RunningVMPlacement) ResourceRelated(org.btrplace.model.view.ResourceRelated) Allocate(org.btrplace.plan.event.Allocate) ShareableResource(org.btrplace.model.view.ShareableResource) Solution(org.chocosolver.solver.Solution) Instance(org.btrplace.model.Instance) ResourceCapacity(org.btrplace.model.constraint.ResourceCapacity) Action(org.btrplace.plan.event.Action) Collections(java.util.Collections) Action(org.btrplace.plan.event.Action) RunningVMPlacement(org.btrplace.plan.event.RunningVMPlacement) HashMap(java.util.HashMap) TObjectDoubleHashMap(gnu.trove.map.hash.TObjectDoubleHashMap) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) Slice(org.btrplace.scheduler.choco.Slice) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Mapping(org.btrplace.model.Mapping) MigrateVM(org.btrplace.plan.event.MigrateVM)

Aggregations

Allocate (org.btrplace.plan.event.Allocate)9 ShareableResource (org.btrplace.model.view.ShareableResource)6 MigrateVM (org.btrplace.plan.event.MigrateVM)6 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)5 Test (org.testng.annotations.Test)5 BootNode (org.btrplace.plan.event.BootNode)4 DefaultReconfigurationPlan (org.btrplace.plan.DefaultReconfigurationPlan)3 AllocateEvent (org.btrplace.plan.event.AllocateEvent)3 BootVM (org.btrplace.plan.event.BootVM)3 ShutdownNode (org.btrplace.plan.event.ShutdownNode)3 ShutdownVM (org.btrplace.plan.event.ShutdownVM)3 HashSet (java.util.HashSet)2 Model (org.btrplace.model.Model)2 Node (org.btrplace.model.Node)2 VM (org.btrplace.model.VM)2 SatConstraint (org.btrplace.model.constraint.SatConstraint)2 Action (org.btrplace.plan.event.Action)2 TDoubleList (gnu.trove.list.TDoubleList)1 TIntList (gnu.trove.list.TIntList)1 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)1