Search in sources :

Example 71 with Node

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

the class DefaultReconfigurationProblem method makeCardinalityVariables.

/**
 * Create the cardinality variables.
 */
private void makeCardinalityVariables() {
    vmsCountOnNodes = new ArrayList<>(nodes.size());
    int nbVMs = vms.size();
    for (Node n : nodes) {
        vmsCountOnNodes.add(csp.intVar(makeVarLabel("nbVMsOn('", n, "')"), 0, nbVMs, true));
    }
    vmsCountOnNodes = Collections.unmodifiableList(vmsCountOnNodes);
}
Also used : Node(org.btrplace.model.Node)

Example 72 with Node

use of org.btrplace.model.Node 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 73 with Node

use of org.btrplace.model.Node 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 74 with Node

use of org.btrplace.model.Node 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 75 with Node

use of org.btrplace.model.Node 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)

Aggregations

Node (org.btrplace.model.Node)188 VM (org.btrplace.model.VM)110 Model (org.btrplace.model.Model)92 DefaultModel (org.btrplace.model.DefaultModel)91 Test (org.testng.annotations.Test)85 Mapping (org.btrplace.model.Mapping)68 HashSet (java.util.HashSet)48 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)43 SatConstraint (org.btrplace.model.constraint.SatConstraint)35 ArrayList (java.util.ArrayList)34 IntVar (org.chocosolver.solver.variables.IntVar)29 ShareableResource (org.btrplace.model.view.ShareableResource)28 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)23 MigrateVM (org.btrplace.plan.event.MigrateVM)22 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)19 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)19 ShutdownableNode (org.btrplace.scheduler.choco.transition.ShutdownableNode)19 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)18 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)16 BootVM (org.btrplace.scheduler.choco.transition.BootVM)16