Search in sources :

Example 21 with MigrateVM

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

the class ReconfigurationPlanCheckerTest method testSequencing.

@Test(dependsOnMethods = { "tesAddandRemove" })
public void testSequencing() throws SatConstraintViolationException {
    Model mo = new DefaultModel();
    List<Node> ns = Util.newNodes(mo, 10);
    List<VM> vms = Util.newVMs(mo, 10);
    Mapping m = mo.getMapping();
    m.addOnlineNode(ns.get(0));
    m.addOnlineNode(ns.get(1));
    m.addOfflineNode(ns.get(3));
    m.addReadyVM(vms.get(1));
    m.addRunningVM(vms.get(0), ns.get(0));
    ReconfigurationPlan p = new DefaultReconfigurationPlan(mo);
    SatConstraintChecker<?> chk = mock(SatConstraintChecker.class);
    MigrateVM m1 = new MigrateVM(vms.get(0), ns.get(0), ns.get(1), 0, 3);
    BootVM b1 = new BootVM(vms.get(1), ns.get(0), 1, 5);
    BootNode bn = new BootNode(ns.get(3), 3, 6);
    p.add(m1);
    p.add(b1);
    p.add(bn);
    Model res = p.getResult();
    Assert.assertNotNull(res);
    ReconfigurationPlanChecker rc = new ReconfigurationPlanChecker();
    rc.addChecker(chk);
    InOrder order = inOrder(chk);
    rc.check(p);
    order.verify(chk).startsWith(mo);
    order.verify(chk).start(m1);
    order.verify(chk).start(b1);
    order.verify(chk).end(m1);
    order.verify(chk).start(bn);
    order.verify(chk).end(b1);
    order.verify(chk).end(bn);
    order.verify(chk).endsWith(res);
}
Also used : InOrder(org.mockito.InOrder) BootNode(org.btrplace.plan.event.BootNode) BootNode(org.btrplace.plan.event.BootNode) MigrateVM(org.btrplace.plan.event.MigrateVM) MigrateVM(org.btrplace.plan.event.MigrateVM) BootVM(org.btrplace.plan.event.BootVM) BootVM(org.btrplace.plan.event.BootVM) Test(org.testng.annotations.Test)

Example 22 with MigrateVM

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

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

Example 24 with MigrateVM

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

Example 25 with MigrateVM

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

the class RelocatableVMTest method testForcedToMove.

@Test
public void testForcedToMove() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    final VM vm1 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    map.addOnlineNode(n1);
    map.addOnlineNode(n2);
    map.addRunningVM(vm1, n1);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(MigrateVM.class, new ConstantActionDuration<>(5));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), map.getAllVMs(), Collections.emptySet(), Collections.emptySet()).setParams(ps).build();
    rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
    rp.getNodeActions().get(1).getState().instantiateTo(1, Cause.Null);
    RelocatableVM am = (RelocatableVM) rp.getVMAction(vm1);
    Assert.assertTrue(am.getRelocationMethod().isInstantiatedTo(0));
    Assert.assertEquals(vm1, am.getVM());
    Assert.assertEquals(2, am.getDuration().getDomainSize());
    Assert.assertEquals(0, am.getDuration().getLB());
    Assert.assertEquals(5, am.getDuration().getUB());
    Assert.assertFalse(am.getStart().isInstantiated());
    Assert.assertFalse(am.getEnd().isInstantiated());
    Assert.assertNotNull(am.getCSlice());
    Assert.assertTrue(am.getCSlice().getHoster().isInstantiatedTo(rp.getNode(n1)));
    Assert.assertTrue(am.getState().isInstantiatedTo(1));
    Assert.assertNotNull(am.getDSlice());
    Assert.assertFalse(am.getDSlice().getHoster().isInstantiated());
    // No VMs on n1, discrete mode
    rp.getModel().post(rp.getModel().arithm(rp.getNbRunningVMs().get(rp.getNode(n1)), "=", 0));
    new CMinMTTR().inject(new DefaultParameters(), rp);
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    Model m = p.getResult();
    Assert.assertEquals(n2, m.getMapping().getVMLocation(vm1));
    MigrateVM a = (MigrateVM) p.getActions().iterator().next();
    Assert.assertEquals(0, a.getStart());
    Assert.assertEquals(5, a.getEnd());
    Assert.assertEquals(n1, a.getSourceNode());
    Assert.assertEquals(n2, a.getDestinationNode());
    Assert.assertEquals(vm1, a.getVM());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Parameters(org.btrplace.scheduler.choco.Parameters) Node(org.btrplace.model.Node) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Mapping(org.btrplace.model.Mapping) MigrateVM(org.btrplace.plan.event.MigrateVM) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) Test(org.testng.annotations.Test)

Aggregations

MigrateVM (org.btrplace.plan.event.MigrateVM)31 Test (org.testng.annotations.Test)25 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)24 DefaultReconfigurationPlan (org.btrplace.plan.DefaultReconfigurationPlan)12 ShareableResource (org.btrplace.model.view.ShareableResource)10 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)9 SatConstraint (org.btrplace.model.constraint.SatConstraint)8 ArrayList (java.util.ArrayList)7 Network (org.btrplace.model.view.network.Network)7 BootVM (org.btrplace.plan.event.BootVM)7 Node (org.btrplace.model.Node)6 Allocate (org.btrplace.plan.event.Allocate)6 BootNode (org.btrplace.plan.event.BootNode)6 ShutdownVM (org.btrplace.plan.event.ShutdownVM)6 List (java.util.List)5 Model (org.btrplace.model.Model)5 VM (org.btrplace.model.VM)5 MinMTTRMig (org.btrplace.model.constraint.migration.MinMTTRMig)5 Switch (org.btrplace.model.view.network.Switch)5 Action (org.btrplace.plan.event.Action)5