Search in sources :

Example 96 with ReconfigurationPlan

use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.

the class SplitAmongTest method testContinuousIsSatisfied.

@Test
public void testContinuousIsSatisfied() {
    Model mo = new DefaultModel();
    List<Node> ns = Util.newNodes(mo, 5);
    List<VM> vms = Util.newVMs(mo, 5);
    Collection<VM> vs1 = Arrays.asList(vms.get(0), vms.get(1));
    Collection<VM> vs2 = Arrays.asList(vms.get(2), vms.get(3));
    Collection<Collection<VM>> vGrps = Arrays.asList(vs1, vs2);
    Collection<Node> ps1 = Arrays.asList(ns.get(0), ns.get(1));
    Collection<Node> ps2 = Arrays.asList(ns.get(2), ns.get(3));
    Collection<Collection<Node>> pGrps = Arrays.asList(ps1, ps2);
    Mapping map = mo.getMapping();
    map.addOnlineNode(ns.get(0));
    map.addOnlineNode(ns.get(1));
    map.addOnlineNode(ns.get(2));
    map.addOnlineNode(ns.get(3));
    map.addRunningVM(vms.get(0), ns.get(0));
    map.addRunningVM(vms.get(1), ns.get(0));
    map.addRunningVM(vms.get(2), ns.get(2));
    map.addRunningVM(vms.get(3), ns.get(3));
    SplitAmong sp = new SplitAmong(vGrps, pGrps, true);
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
    Assert.assertEquals(sp.isSatisfied(plan), true);
    plan.add(new MigrateVM(vms.get(0), ns.get(0), ns.get(1), 3, 4));
    Assert.assertEquals(sp.isSatisfied(plan), true);
    map.addRunningVM(vms.get(4), ns.get(3));
    Assert.assertEquals(sp.isSatisfied(plan), true);
    plan.add(new MigrateVM(vms.get(1), ns.get(0), ns.get(2), 0, 2));
    Assert.assertEquals(sp.isSatisfied(plan), false);
}
Also used : DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) Collection(java.util.Collection) Test(org.testng.annotations.Test)

Example 97 with ReconfigurationPlan

use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.

the class SplitTest method testContinuousIsSatisfied.

@Test
public void testContinuousIsSatisfied() {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    List<Node> ns = Util.newNodes(mo, 3);
    List<VM> vms = Util.newVMs(mo, 5);
    map.addOnlineNode(ns.get(0));
    map.addOnlineNode(ns.get(1));
    map.addOnlineNode(ns.get(2));
    Collection<VM> s1 = Arrays.asList(vms.get(0), vms.get(1));
    Collection<VM> s2 = Arrays.asList(vms.get(2), vms.get(3));
    Collection<VM> s3 = Collections.singleton(vms.get(4));
    Collection<Collection<VM>> args = Arrays.asList(s1, s2, s3);
    map.addRunningVM(vms.get(0), ns.get(0));
    map.addRunningVM(vms.get(1), ns.get(0));
    map.addRunningVM(vms.get(2), ns.get(1));
    map.addRunningVM(vms.get(3), ns.get(1));
    Split sp = new Split(args, true);
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
    Assert.assertEquals(sp.isSatisfied(plan), true);
    // Violation
    map.addRunningVM(vms.get(2), ns.get(0));
    Assert.assertEquals(sp.isSatisfied(plan), false);
    plan.add(new MigrateVM(vms.get(2), ns.get(0), ns.get(1), 0, 1));
    // False cause there is the initial violation
    Assert.assertEquals(sp.isSatisfied(plan), false);
    sp.setContinuous(false);
    Assert.assertEquals(sp.isSatisfied(plan), true);
    sp.setContinuous(true);
    // Temporary overlap
    plan.add(new MigrateVM(vms.get(2), ns.get(1), ns.get(0), 5, 6));
    plan.add(new MigrateVM(vms.get(2), ns.get(0), ns.get(1), 6, 7));
    Assert.assertEquals(sp.isSatisfied(plan), false);
    // Liberate ns.get(0) from vms.get(0) and vms.get(1) before
    plan.add(new SuspendVM(vms.get(0), ns.get(0), ns.get(0), 2, 3));
    plan.add(new ShutdownVM(vms.get(1), ns.get(0), 2, 3));
    sp.setContinuous(false);
    Assert.assertEquals(sp.isSatisfied(plan), true);
}
Also used : DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) SuspendVM(org.btrplace.plan.event.SuspendVM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) MigrateVM(org.btrplace.plan.event.MigrateVM) SuspendVM(org.btrplace.plan.event.SuspendVM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) Test(org.testng.annotations.Test)

Example 98 with ReconfigurationPlan

use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.

the class SpreadTest method testContinuousIsSatisfied.

@Test
public void testContinuousIsSatisfied() {
    Model mo = new DefaultModel();
    List<Node> ns = Util.newNodes(mo, 4);
    List<VM> vms = Util.newVMs(mo, 4);
    Mapping map = mo.getMapping();
    map.addOnlineNode(ns.get(0));
    map.addOnlineNode(ns.get(1));
    map.addOnlineNode(ns.get(2));
    map.addOnlineNode(ns.get(3));
    map.addRunningVM(vms.get(0), ns.get(0));
    map.addRunningVM(vms.get(1), ns.get(1));
    Spread s = new Spread(map.getAllVMs());
    ReconfigurationPlan p = new DefaultReconfigurationPlan(mo);
    Assert.assertEquals(s.isSatisfied(p), true);
    MigrateVM m1 = new MigrateVM(vms.get(0), ns.get(0), ns.get(1), 1, 2);
    p.add(m1);
    Assert.assertEquals(s.isSatisfied(p), false);
    // No overlapping at moment 1
    MigrateVM m2 = new MigrateVM(vms.get(1), ns.get(1), ns.get(2), 0, 1);
    p.add(m2);
    Assert.assertEquals(s.isSatisfied(p), true);
    map.addRunningVM(vms.get(2), ns.get(1));
    s = new Spread(map.getAllVMs());
    p = new DefaultReconfigurationPlan(mo);
    System.out.println(p.getOrigin() + "\n" + p.getResult());
    Assert.assertEquals(s.isSatisfied(p), false);
    p.add(new MigrateVM(vms.get(2), ns.get(1), ns.get(2), 0, 5));
    Assert.assertEquals(s.isSatisfied(p), true);
}
Also used : DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) Test(org.testng.annotations.Test)

Example 99 with ReconfigurationPlan

use of org.btrplace.plan.ReconfigurationPlan 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 100 with ReconfigurationPlan

use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.

the class DefaultChocoSchedulerTest method testOnSolutionHook.

@Test
public void testOnSolutionHook() {
    ChocoScheduler cra = new DefaultChocoScheduler();
    Model mo = new DefaultModel();
    VM vm = mo.newVM();
    Node node = mo.newNode();
    mo.getMapping().on(node).run(node, vm);
    Instance i = new Instance(mo, Running.newRunning(Arrays.asList(vm)), new MinMTTR());
    List<ReconfigurationPlan> onSolutions = new ArrayList<>();
    cra.addSolutionListener((rp, plan) -> onSolutions.add(plan));
    Assert.assertEquals(1, cra.solutionListeners().size());
    ReconfigurationPlan plan = cra.solve(i);
    Assert.assertEquals(1, onSolutions.size());
    Assert.assertEquals(plan, onSolutions.get(0));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) MinMTTR(org.btrplace.model.constraint.MinMTTR) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Aggregations

ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)185 Test (org.testng.annotations.Test)160 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)94 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)74 SatConstraint (org.btrplace.model.constraint.SatConstraint)53 ShareableResource (org.btrplace.model.view.ShareableResource)52 Model (org.btrplace.model.Model)49 ArrayList (java.util.ArrayList)46 Node (org.btrplace.model.Node)45 DefaultModel (org.btrplace.model.DefaultModel)44 VM (org.btrplace.model.VM)41 MigrateVM (org.btrplace.plan.event.MigrateVM)37 DurationEvaluators (org.btrplace.scheduler.choco.duration.DurationEvaluators)34 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)32 Parameters (org.btrplace.scheduler.choco.Parameters)29 ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)29 DefaultReconfigurationProblemBuilder (org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder)28 DefaultReconfigurationPlan (org.btrplace.plan.DefaultReconfigurationPlan)24 Mapping (org.btrplace.model.Mapping)23 HashSet (java.util.HashSet)22