Search in sources :

Example 16 with VMTransition

use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.

the class COffline method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
    if (cstr.isContinuous() && !cstr.getChecker().startsWith(rp.getSourceModel())) {
        rp.getLogger().error("Constraint {} is not satisfied initially", cstr);
        return false;
    }
    Node nId = cstr.getInvolvedNodes().iterator().next();
    int id = rp.getNode(nId);
    NodeTransition m = rp.getNodeAction(nId);
    try {
        m.getState().instantiateTo(0, Cause.Null);
        if (rp.getSourceModel().getMapping().isOffline(nId)) {
            m.getStart().instantiateTo(0, Cause.Null);
        }
    } catch (ContradictionException ex) {
        rp.getLogger().error("Unable to force node '" + nId + "' at being offline", ex);
        return false;
    }
    for (VMTransition am : rp.getVMActions()) {
        Slice s = am.getDSlice();
        if (s != null) {
            try {
                s.getHoster().removeValue(id, Cause.Null);
            } catch (ContradictionException e) {
                rp.getLogger().error("Unable to remove " + am.getVM() + " of node " + nId, e);
            }
        }
    }
    return true;
}
Also used : ContradictionException(org.chocosolver.solver.exception.ContradictionException) Slice(org.btrplace.scheduler.choco.Slice) Node(org.btrplace.model.Node) NodeTransition(org.btrplace.scheduler.choco.transition.NodeTransition) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition)

Example 17 with VMTransition

use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.

the class CRoot method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
    VM vm = cstr.getInvolvedVMs().iterator().next();
    VMTransition m = rp.getVMAction(vm);
    Slice cSlice = m.getCSlice();
    Slice dSlice = m.getDSlice();
    if (cSlice != null && dSlice != null) {
        try {
            dSlice.getHoster().instantiateTo(cSlice.getHoster().getValue(), Cause.Null);
        } catch (ContradictionException ex) {
            Node n = rp.getSourceModel().getMapping().getVMLocation(vm);
            rp.getLogger().error("Unable to force '" + vm + "' to be running on node '" + n + "'", ex);
            return false;
        }
    }
    return true;
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) ContradictionException(org.chocosolver.solver.exception.ContradictionException) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition)

Example 18 with VMTransition

use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.

the class CSequentialVMTransitions method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
    List<VM> seq = cstr.getInvolvedVMs();
    List<VMTransition> ams = new ArrayList<>();
    for (VM vmId : seq) {
        VMTransition am = rp.getVMAction(vmId);
        // Avoid VMs with no action model or Transition that do not denotes a state transition
        if (am == null || am instanceof StayAwayVM || am instanceof RelocatableVM) {
            continue;
        }
        ams.add(am);
    }
    if (ams.size() > 1) {
        Iterator<VMTransition> ite = ams.iterator();
        VMTransition prev = ite.next();
        Model csp = rp.getModel();
        while (ite.hasNext()) {
            VMTransition cur = ite.next();
            csp.post(csp.arithm(prev.getEnd(), "<=", cur.getStart()));
            prev = cur;
        }
    }
    return true;
}
Also used : StayAwayVM(org.btrplace.scheduler.choco.transition.StayAwayVM) VM(org.btrplace.model.VM) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) StayAwayVM(org.btrplace.scheduler.choco.transition.StayAwayVM) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Model(org.chocosolver.solver.Model) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM)

Example 19 with VMTransition

use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.

the class CMinMTTRMig method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
    this.rp = rp;
    List<IntVar> endVars = new ArrayList<>();
    // Define the cost constraint: sum of all actions' end time
    for (VMTransition m : rp.getVMActions()) {
        endVars.add(m.getEnd());
    }
    for (NodeTransition m : rp.getNodeActions()) {
        endVars.add(m.getEnd());
    }
    IntVar[] costs = endVars.toArray(new IntVar[endVars.size()]);
    IntVar cost = rp.getModel().intVar(rp.makeVarLabel("costEndVars"), 0, Integer.MAX_VALUE / 100, true);
    costConstraints.add(rp.getModel().sum(costs, "=", cost));
    // Set the objective, minimize the cost
    rp.setObjective(true, cost);
    // Inject the scheduling heuristic
    injectSchedulingHeuristic(cost);
    // Post the cost constraint
    postCostConstraints();
    return true;
}
Also used : ArrayList(java.util.ArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) NodeTransition(org.btrplace.scheduler.choco.transition.NodeTransition) IntVar(org.chocosolver.solver.variables.IntVar)

Example 20 with VMTransition

use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.

the class CMinMigrations method postCostConstraints.

@Override
public void postCostConstraints() {
    if (!costActivated) {
        costActivated = true;
        rp.getLogger().debug("Post the cost-oriented constraints");
        List<IntVar> stays = new ArrayList<>();
        for (VMTransition t : rp.getVMActions()) {
            if (t instanceof RelocatableVM && rp.getManageableVMs().contains(t.getVM())) {
                stays.add(t.getDuration());
            }
        }
        // With choco 4.0.1, we cannot post a simple sum() constraint due to hardcore
        // simplification it made. So we bypass the optimisation phase and post the propagator
        rp.getModel().post(rp.getModel().sum(stays.toArray(new IntVar[0]), "=", cost));
    /*stays.add(cost);
            Propagator<IntVar> p =
                    new PropSum(stays.toArray(new IntVar[0]), stays.size() - 1, Operator.EQ, 0);
            rp.getModel().post(new org.chocosolver.solver.constraints.Constraint("sumCost", p));
*/
    }
}
Also used : ArrayList(java.util.ArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) IntVar(org.chocosolver.solver.variables.IntVar)

Aggregations

VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)41 VM (org.btrplace.model.VM)34 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)23 Node (org.btrplace.model.Node)22 IntVar (org.chocosolver.solver.variables.IntVar)22 ArrayList (java.util.ArrayList)18 Model (org.btrplace.model.Model)17 HashSet (java.util.HashSet)16 Mapping (org.btrplace.model.Mapping)16 Slice (org.btrplace.scheduler.choco.Slice)16 DefaultModel (org.btrplace.model.DefaultModel)12 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)12 ShutdownableNode (org.btrplace.scheduler.choco.transition.ShutdownableNode)12 StayAwayVM (org.btrplace.scheduler.choco.transition.StayAwayVM)12 Test (org.testng.annotations.Test)12 BootVM (org.btrplace.scheduler.choco.transition.BootVM)11 ForgeVM (org.btrplace.scheduler.choco.transition.ForgeVM)11 KillVM (org.btrplace.scheduler.choco.transition.KillVM)11 ResumeVM (org.btrplace.scheduler.choco.transition.ResumeVM)11 ShutdownVM (org.btrplace.scheduler.choco.transition.ShutdownVM)11