Search in sources :

Example 31 with Mapping

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

the class CAmong method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
    int nextGrp = -1;
    int curGrp = -1;
    List<Collection<Node>> groups = new ArrayList<>();
    groups.addAll(cstr.getGroupsOfNodes());
    Set<VM> running = new HashSet<>();
    Mapping src = rp.getSourceModel().getMapping();
    for (VM vm : cstr.getInvolvedVMs()) {
        if (rp.getFutureRunningVMs().contains(vm)) {
            // The VM will be running
            running.add(vm);
            IntVar vAssign = rp.getVMAction(vm).getDSlice().getHoster();
            // If one of the VM is already placed, no need for the constraint, the group will be known
            if (vAssign.isInstantiated()) {
                // Get the group of nodes that match the selected node
                int g = getGroup(rp.getNode(vAssign.getValue()), groups);
                if (errorReported(rp, vm, nextGrp, g)) {
                    return false;
                }
                nextGrp = g;
            }
        }
        if (cstr.isContinuous() && src.isRunning(vm)) {
            // The VM is already running, so we get its current group
            Node curNode = src.getVMLocation(vm);
            int g = getGroup(curNode, groups);
            if (errorReported(rp, vm, curGrp, g)) {
                return false;
            }
            curGrp = g;
        }
    }
    if (cstr.isContinuous() && curGrp != -1) {
        return restrictGroup(ps, rp, running, groups, curGrp);
    } else if (groups.size() == 1) {
        return restrictGroup(ps, rp, running, groups, 0);
    }
    return restrictGroup(ps, rp, running, groups, nextGrp);
}
Also used : VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Mapping(org.btrplace.model.Mapping) IntVar(org.chocosolver.solver.variables.IntVar) Constraint(org.chocosolver.solver.constraints.Constraint) HashSet(java.util.HashSet)

Example 32 with Mapping

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

the class CGather method continuousColocation.

/*
    * Check for the already running VMs and force co-location if any.
     */
private boolean continuousColocation(ReconfigurationProblem rp, List<Slice> dSlices) {
    Set<VM> alreadyRunning = new HashSet<>();
    Mapping map = rp.getSourceModel().getMapping();
    Node loc = null;
    for (VM vm : cstr.getInvolvedVMs()) {
        if (map.isRunning(vm)) {
            alreadyRunning.add(vm);
            Node node = map.getVMLocation(vm);
            if (loc == null) {
                loc = node;
            } else if (!loc.equals(node)) {
                rp.getLogger().error("Some VMs in '{}' are already running but not co-located", cstr.getInvolvedVMs());
                return false;
            }
        }
    }
    if (loc != null) {
        if (cstr.getInvolvedVMs().size() == 1 && dSlices.size() == 1) {
            // The VM may migrate, we don't care as it is alone.
            return true;
        }
        return placeDSlices(rp, dSlices, rp.getNode(loc));
    }
    return true;
}
Also used : VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Mapping(org.btrplace.model.Mapping) HashSet(java.util.HashSet)

Example 33 with Mapping

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

the class CLonely method continuousRestriction.

private static void continuousRestriction(ReconfigurationProblem rp, Collection<VM> vms, Set<VM> otherVMs) {
    // Get the position of all the others c-slices and their associated end moment
    TIntArrayList otherPos = new TIntArrayList();
    TIntArrayList minePos = new TIntArrayList();
    List<IntVar> otherEnds = new ArrayList<>();
    List<IntVar> mineEnds = new ArrayList<>();
    Mapping map = rp.getSourceModel().getMapping();
    for (Node n : map.getOnlineNodes()) {
        for (VM vm : map.getRunningVMs(n)) {
            if (!vms.contains(vm)) {
                otherPos.add(rp.getNode(map.getVMLocation(vm)));
                VMTransition a = rp.getVMAction(vm);
                otherEnds.add(a.getCSlice().getEnd());
            } else {
                minePos.add(rp.getNode(map.getVMLocation(vm)));
                VMTransition a = rp.getVMAction(vm);
                mineEnds.add(a.getCSlice().getEnd());
            }
        }
    }
    for (VM vm : vms) {
        VMTransition a = rp.getVMAction(vm);
        Precedences p = new Precedences(a.getDSlice().getHoster(), a.getDSlice().getStart(), otherPos.toArray(), otherEnds.toArray(new IntVar[otherEnds.size()]));
        rp.getModel().post(p);
    }
    // TODO: The following reveals a model problem. Too many constraints!!
    for (VM vm : otherVMs) {
        VMTransition a = rp.getVMAction(vm);
        Precedences p = new Precedences(a.getDSlice().getHoster(), a.getDSlice().getStart(), minePos.toArray(), mineEnds.toArray(new IntVar[mineEnds.size()]));
        rp.getModel().post(p);
    }
}
Also used : Precedences(org.btrplace.scheduler.choco.extensions.Precedences) Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Mapping(org.btrplace.model.Mapping) IntVar(org.chocosolver.solver.variables.IntVar) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 34 with Mapping

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

the class CLonely method getMisPlacedVMs.

@Override
public Set<VM> getMisPlacedVMs(Instance i) {
    Set<VM> bad = new HashSet<>();
    Set<Node> hosts = new HashSet<>();
    Collection<VM> vms = cstr.getInvolvedVMs();
    Mapping map = i.getModel().getMapping();
    for (VM vm : vms) {
        if (map.isRunning(vm)) {
            hosts.add(map.getVMLocation(vm));
        }
    }
    for (Node n : hosts) {
        // is a bad node. All the hosted VMs are candidate for relocation. Not optimal, but safe
        for (VM vm : map.getRunningVMs(n)) {
            if (!vms.contains(vm)) {
                bad.addAll(map.getRunningVMs(n));
                break;
            }
        }
    }
    return bad;
}
Also used : VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Mapping(org.btrplace.model.Mapping) HashSet(java.util.HashSet)

Example 35 with Mapping

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

the class CResourceCapacity method getMisPlacedVMs.

@Override
public Set<VM> getMisPlacedVMs(Instance i) {
    if (cstr.getInvolvedNodes().size() <= 1) {
        // If there is only a single node, we delegate this work to CShareableResource.
        return Collections.emptySet();
    }
    Mapping map = i.getModel().getMapping();
    ShareableResource rc = ShareableResource.get(i.getModel(), cstr.getResource());
    if (rc == null) {
        return map.getRunningVMs(cstr.getInvolvedNodes());
    }
    Set<VM> bad = new HashSet<>();
    int remainder = cstr.getAmount();
    for (Node n : cstr.getInvolvedNodes()) {
        for (VM v : map.getRunningVMs(n)) {
            remainder -= rc.getConsumption(v);
            if (remainder < 0) {
                for (Node n2 : cstr.getInvolvedNodes()) {
                    bad.addAll(map.getRunningVMs(n2));
                }
                return bad;
            }
        }
    }
    return bad;
}
Also used : VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Mapping(org.btrplace.model.Mapping) CShareableResource(org.btrplace.scheduler.choco.view.CShareableResource) ShareableResource(org.btrplace.model.view.ShareableResource) HashSet(java.util.HashSet)

Aggregations

Mapping (org.btrplace.model.Mapping)83 Node (org.btrplace.model.Node)68 VM (org.btrplace.model.VM)62 Model (org.btrplace.model.Model)42 DefaultModel (org.btrplace.model.DefaultModel)39 Test (org.testng.annotations.Test)39 HashSet (java.util.HashSet)29 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)23 ShareableResource (org.btrplace.model.view.ShareableResource)16 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)16 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)15 ShutdownableNode (org.btrplace.scheduler.choco.transition.ShutdownableNode)15 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)15 IntVar (org.chocosolver.solver.variables.IntVar)15 SatConstraint (org.btrplace.model.constraint.SatConstraint)14 BootVM (org.btrplace.scheduler.choco.transition.BootVM)14 ForgeVM (org.btrplace.scheduler.choco.transition.ForgeVM)14 KillVM (org.btrplace.scheduler.choco.transition.KillVM)14 ResumeVM (org.btrplace.scheduler.choco.transition.ResumeVM)14 ShutdownVM (org.btrplace.scheduler.choco.transition.ShutdownVM)14