Search in sources :

Example 16 with VM

use of org.btrplace.model.VM in project scheduler by btrplace.

the class KilledSplitterTest method simpleTest.

@Test
public void simpleTest() {
    KilledSplitter splitter = new KilledSplitter();
    List<Instance> instances = new ArrayList<>();
    Model m0 = new DefaultModel();
    VM v = m0.newVM(1);
    m0.getMapping().addReadyVM(v);
    m0.getMapping().addRunningVM(m0.newVM(2), m0.newNode(1));
    Model m1 = new DefaultModel();
    m1.getMapping().addReadyVM(m1.newVM(3));
    m1.getMapping().addSleepingVM(m1.newVM(4), m1.newNode(2));
    m1.getMapping().addRunningVM(m1.newVM(5), m1.newNode(3));
    instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
    instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
    TIntIntHashMap index = Instances.makeVMIndex(instances);
    Set<VM> all = new HashSet<>(m0.getMapping().getAllVMs());
    all.addAll(m1.getMapping().getAllVMs());
    // Only VMs in m0
    Killed single = new Killed(v);
    Assert.assertTrue(splitter.split(single, null, instances, index, new TIntIntHashMap()));
    Assert.assertTrue(instances.get(0).getSatConstraints().contains(single));
    Assert.assertFalse(instances.get(1).getSatConstraints().contains(single));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) VM(org.btrplace.model.VM) ArrayList(java.util.ArrayList) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) MinMTTR(org.btrplace.model.constraint.MinMTTR) Killed(org.btrplace.model.constraint.Killed) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 17 with VM

use of org.btrplace.model.VM in project scheduler by btrplace.

the class CSplitAmong method getMisPlacedVMs.

@Override
public Set<VM> getMisPlacedVMs(Instance i) {
    // contains the set of VMs hosted on a group id.
    @SuppressWarnings("unchecked") Collection<VM>[] usedGrp = new Set[cstr.getGroupsOfNodes().size()];
    Mapping map = i.getModel().getMapping();
    Set<VM> bad = new HashSet<>();
    for (Collection<VM> vms : cstr.getGroupsOfVMs()) {
        int grp = -1;
        for (VM vm : vms) {
            if (map.isRunning(vm)) {
                Node n = map.getVMLocation(vm);
                int g = getPGroup(n);
                if (g == -1) {
                    // The VM is on a node that belong to none of the given groups
                    bad.add(vm);
                } else if (grp == -1) {
                    grp = g;
                    usedGrp[g] = vms;
                } else if (g != grp) {
                    // The VMs spread over multiple group of nodes, the group of VMs is mis-placed
                    bad.addAll(vms);
                    if (usedGrp[g] != null) {
                        bad.addAll(usedGrp[g]);
                    }
                    bad.addAll(usedGrp[grp]);
                }
            }
        }
    }
    return bad;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Collection(java.util.Collection) Mapping(org.btrplace.model.Mapping) HashSet(java.util.HashSet)

Example 18 with VM

use of org.btrplace.model.VM in project scheduler by btrplace.

the class CSpread method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) {
    if (cstr.isContinuous()) {
        Set<Node> usedNodes = new HashSet<>();
        for (VM vm : cstr.getInvolvedVMs()) {
            Node node = rp.getSourceModel().getMapping().getVMLocation(vm);
            if (node != null && !usedNodes.add(node)) {
                rp.getLogger().error("Constraint {} is not satisfied initially", cstr);
                // System.out.println(rp.getSourceModel().getMapping());
                return false;
            }
        }
    }
    List<IntVar> running = placementVariables(rp);
    Model csp = rp.getModel();
    if (running.isEmpty()) {
        return true;
    }
    // The lazy spread implementation for the placement
    csp.post(csp.allDifferent(running.toArray(new IntVar[running.size()]), "AC"));
    if (cstr.isContinuous()) {
        List<VM> vms = new ArrayList<>(cstr.getInvolvedVMs());
        for (int i = 0; i < vms.size(); i++) {
            VM vm = vms.get(i);
            VMTransition aI = rp.getVMAction(vm);
            for (int j = 0; j < i; j++) {
                VM vmJ = vms.get(j);
                VMTransition aJ = rp.getVMAction(vmJ);
                disallowOverlap(rp, aI, aJ);
            }
        }
    }
    return true;
}
Also used : Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) Model(org.chocosolver.solver.Model) ArrayList(java.util.ArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) IntVar(org.chocosolver.solver.variables.IntVar) HashSet(java.util.HashSet)

Example 19 with VM

use of org.btrplace.model.VM in project scheduler by btrplace.

the class CSpread method placementVariables.

private List<IntVar> placementVariables(ReconfigurationProblem rp) {
    List<IntVar> running = new ArrayList<>();
    for (VM vmId : cstr.getInvolvedVMs()) {
        if (rp.getFutureRunningVMs().contains(vmId)) {
            VMTransition a = rp.getVMAction(vmId);
            Slice d = a.getDSlice();
            if (d != null) {
                running.add(d.getHoster());
            }
        }
    }
    return running;
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) VM(org.btrplace.model.VM) ArrayList(java.util.ArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) IntVar(org.chocosolver.solver.variables.IntVar)

Example 20 with VM

use of org.btrplace.model.VM in project scheduler by btrplace.

the class CMinMigrations method placeVMs.

/*
     * Try to place the VMs associated on the actions in a random node while trying first to stay on the current node
     */
private void placeVMs(Parameters ps, List<AbstractStrategy<?>> strategies, List<VMTransition> actions, OnStableNodeFirst schedHeuristic, Map<IntVar, VM> map) {
    IntValueSelector rnd = new WorstFit(map, rp, new BiggestDimension());
    if (!useResources) {
        rnd = new RandomVMPlacement(rp, map, true, ps.getRandomSeed());
    }
    IntVar[] hosts = dSlices(actions).map(Slice::getHoster).filter(v -> !v.isInstantiated()).toArray(IntVar[]::new);
    if (hosts.length > 0) {
        strategies.add(new IntStrategy(hosts, new HostingVariableSelector(rp.getModel(), schedHeuristic), rnd));
    }
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) OnStableNodeFirst(org.btrplace.scheduler.choco.constraint.mttr.OnStableNodeFirst) SchedulerException(org.btrplace.scheduler.SchedulerException) Transition(org.btrplace.scheduler.choco.transition.Transition) StrategiesSequencer(org.chocosolver.solver.search.strategy.strategy.StrategiesSequencer) Solver(org.chocosolver.solver.Solver) Search(org.chocosolver.solver.search.strategy.Search) CObjective(org.btrplace.scheduler.choco.constraint.CObjective) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) IntDomainMin(org.chocosolver.solver.search.strategy.selectors.values.IntDomainMin) TObjectIntMap(gnu.trove.map.TObjectIntMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) VM(org.btrplace.model.VM) FirstFail(org.chocosolver.solver.search.strategy.selectors.variables.FirstFail) Mapping(org.btrplace.model.Mapping) WorstFit(org.btrplace.scheduler.choco.constraint.mttr.WorstFit) Map(java.util.Map) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) StartOnLeafNodes(org.btrplace.scheduler.choco.constraint.mttr.StartOnLeafNodes) CShareableResource(org.btrplace.scheduler.choco.view.CShareableResource) MinMigrations(org.btrplace.model.constraint.MinMigrations) LinkedList(java.util.LinkedList) RandomVMPlacement(org.btrplace.scheduler.choco.constraint.mttr.RandomVMPlacement) Model(org.btrplace.model.Model) BiggestDimension(org.btrplace.scheduler.choco.constraint.mttr.load.BiggestDimension) Iterator(java.util.Iterator) MovementGraph(org.btrplace.scheduler.choco.constraint.mttr.MovementGraph) HostingVariableSelector(org.btrplace.scheduler.choco.constraint.mttr.HostingVariableSelector) Set(java.util.Set) MyInputOrder(org.btrplace.scheduler.choco.constraint.mttr.MyInputOrder) Parameters(org.btrplace.scheduler.choco.Parameters) Collectors(java.util.stream.Collectors) VMPlacementUtils(org.btrplace.scheduler.choco.constraint.mttr.VMPlacementUtils) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Objects(java.util.Objects) IntVar(org.chocosolver.solver.variables.IntVar) List(java.util.List) Stream(java.util.stream.Stream) IntStrategy(org.chocosolver.solver.search.strategy.strategy.IntStrategy) ShareableResource(org.btrplace.model.view.ShareableResource) IntValueSelector(org.chocosolver.solver.search.strategy.selectors.values.IntValueSelector) Instance(org.btrplace.model.Instance) AbstractStrategy(org.chocosolver.solver.search.strategy.strategy.AbstractStrategy) IntDomainMax(org.chocosolver.solver.search.strategy.selectors.values.IntDomainMax) Collections(java.util.Collections) BiggestDimension(org.btrplace.scheduler.choco.constraint.mttr.load.BiggestDimension) IntStrategy(org.chocosolver.solver.search.strategy.strategy.IntStrategy) HostingVariableSelector(org.btrplace.scheduler.choco.constraint.mttr.HostingVariableSelector) Slice(org.btrplace.scheduler.choco.Slice) WorstFit(org.btrplace.scheduler.choco.constraint.mttr.WorstFit) RandomVMPlacement(org.btrplace.scheduler.choco.constraint.mttr.RandomVMPlacement) IntVar(org.chocosolver.solver.variables.IntVar) IntValueSelector(org.chocosolver.solver.search.strategy.selectors.values.IntValueSelector)

Aggregations

VM (org.btrplace.model.VM)192 Node (org.btrplace.model.Node)110 Model (org.btrplace.model.Model)92 DefaultModel (org.btrplace.model.DefaultModel)91 Test (org.testng.annotations.Test)91 Mapping (org.btrplace.model.Mapping)64 HashSet (java.util.HashSet)58 ArrayList (java.util.ArrayList)43 SatConstraint (org.btrplace.model.constraint.SatConstraint)40 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)39 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)35 IntVar (org.chocosolver.solver.variables.IntVar)35 ShareableResource (org.btrplace.model.view.ShareableResource)32 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)27 MigrateVM (org.btrplace.plan.event.MigrateVM)25 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)17 StayAwayVM (org.btrplace.scheduler.choco.transition.StayAwayVM)17 Slice (org.btrplace.scheduler.choco.Slice)16 BootVM (org.btrplace.scheduler.choco.transition.BootVM)16 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)16