Search in sources :

Example 1 with SchedulerModelingException

use of org.btrplace.scheduler.SchedulerModelingException in project scheduler by btrplace.

the class CMaxOnline method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
    Model csp = rp.getModel();
    if (constraint.getInvolvedNodes().isEmpty()) {
        // The constraint is entailed as it contains no node.
        return true;
    }
    if (constraint.isContinuous()) {
        CPowerView view = (CPowerView) rp.getView(CPowerView.VIEW_ID);
        if (view == null) {
            view = new CPowerView();
            if (!rp.addView(view)) {
                throw new SchedulerModelingException(rp.getSourceModel(), "Unable to attach view '" + CPowerView.VIEW_ID + "'");
            }
            if (!view.inject(ps, rp)) {
                throw new SchedulerModelingException(rp.getSourceModel(), "Unable to inject view '" + CPowerView.VIEW_ID + "'");
            }
        }
        int numberOfTasks = constraint.getInvolvedNodes().size();
        int i = 0;
        int[] nodeIdx = new int[numberOfTasks];
        for (Node n : constraint.getInvolvedNodes()) {
            nodeIdx[i++] = rp.getNode(n);
        }
        IntVar capacity = rp.fixed(constraint.getAmount(), "capacity");
        // The state of the node:
        IntVar[] heights = new IntVar[numberOfTasks];
        IntVar[] starts = new IntVar[numberOfTasks];
        IntVar[] ends = new IntVar[numberOfTasks];
        // Online duration:
        IntVar[] durations = new IntVar[numberOfTasks];
        // Online duration is modeled as a task
        Task[] taskVars = new Task[numberOfTasks];
        for (int idx = 0; idx < nodeIdx.length; idx++) {
            Node n = rp.getNode(nodeIdx[idx]);
            // ---------------GET PowerStart and PowerEnd of the node------------------
            starts[idx] = view.getPowerStart(rp.getNode(n));
            ends[idx] = view.getPowerEnd(rp.getNode(n));
            // ------------------------------------------------------------------------
            durations[idx] = rp.makeUnboundedDuration(rp.makeVarLabel("Dur(", n, ")"));
            csp.post(csp.arithm(durations[idx], "<=", rp.getEnd()));
            // All tasks have to be scheduled
            heights[idx] = csp.intVar(1);
            taskVars[idx] = new Task(starts[idx], durations[idx], ends[idx]);
        }
        csp.post(csp.cumulative(taskVars, heights, capacity, true));
    }
    // Constraint for discrete model
    List<IntVar> nodesState = new ArrayList<>(constraint.getInvolvedNodes().size());
    for (Node ni : constraint.getInvolvedNodes()) {
        nodesState.add(rp.getNodeAction(ni).getState());
    }
    IntVar mySum = csp.intVar(rp.makeVarLabel("nbOnline"), 0, constraint.getAmount(), true);
    csp.post(csp.sum(nodesState.toArray(new IntVar[nodesState.size()]), "=", mySum));
    csp.post(csp.arithm(mySum, "<=", constraint.getAmount()));
    return true;
}
Also used : Task(org.chocosolver.solver.variables.Task) Node(org.btrplace.model.Node) Model(org.chocosolver.solver.Model) ArrayList(java.util.ArrayList) CPowerView(org.btrplace.scheduler.choco.view.CPowerView) IntVar(org.chocosolver.solver.variables.IntVar) SchedulerModelingException(org.btrplace.scheduler.SchedulerModelingException)

Example 2 with SchedulerModelingException

use of org.btrplace.scheduler.SchedulerModelingException in project scheduler by btrplace.

the class CNetwork method beforeSolve.

@Override
public boolean beforeSolve(ReconfigurationProblem rp) throws SchedulerException {
    Model mo = rp.getSourceModel();
    Attributes attrs = mo.getAttributes();
    // Pre-compute duration and bandwidth for each VM migration
    for (VMTransition migration : rp.getVMActions()) {
        if (!(migration instanceof RelocatableVM)) {
            continue;
        }
        // Get vars from migration
        VM vm = migration.getVM();
        IntVar bandwidth = ((RelocatableVM) migration).getBandwidth();
        IntVar duration = migration.getDuration();
        Node src = rp.getSourceModel().getMapping().getVMLocation(vm);
        // Try to get the destination node
        Node dst;
        if (!migration.getDSlice().getHoster().isInstantiated()) {
            throw new SchedulerModelingException(null, "Destination node for VM '" + vm + "' should be known !");
        }
        if (!mo.getAttributes().isSet(vm, "memUsed")) {
            throw new SchedulerModelingException(null, "Unable to retrieve 'memUsed' attribute for the vm '" + vm + "'");
        }
        dst = rp.getNode(migration.getDSlice().getHoster().getValue());
        if (src.equals(dst)) {
            try {
                ((RelocatableVM) migration).getBandwidth().instantiateTo(0, Cause.Null);
                continue;
            } catch (ContradictionException e) {
                rp.getLogger().debug("Contradiction exception when trying to instantiate bandwidth and " + " duration variables for " + vm + " migration", e);
                return false;
            }
        }
        // Get attribute vars
        int memUsed = attrs.get(vm, "memUsed", -1);
        // Get VM memory activity attributes if defined, otherwise set an idle workload on the VM
        // Minimal observed value on idle VM
        double hotDirtySize = attrs.get(vm, "hotDirtySize", 5.0);
        // Minimal observed value on idle VM
        double hotDirtyDuration = attrs.get(vm, "hotDirtyDuration", 2.0);
        double coldDirtyRate = attrs.get(vm, "coldDirtyRate", 0.0);
        // Get the maximal bandwidth available on the migration path
        int maxBW = net.getRouting().getMaxBW(src, dst);
        // Compute the duration related to each enumerated bandwidth
        double durationMin;
        double durationColdPages;
        double durationHotPages;
        double durationTotal;
        // Cheat a bit, real is less than theoretical (8->9)
        double bandwidthOctet = maxBW / 9.0;
        // Estimate the duration for the current bandwidth
        durationMin = memUsed / bandwidthOctet;
        if (durationMin > hotDirtyDuration) {
            durationColdPages = (hotDirtySize + (durationMin - hotDirtyDuration) * coldDirtyRate) / (bandwidthOctet - coldDirtyRate);
            durationHotPages = (hotDirtySize / bandwidthOctet * ((hotDirtySize / hotDirtyDuration) / (bandwidthOctet - (hotDirtySize / hotDirtyDuration))));
            durationTotal = durationMin + durationColdPages + durationHotPages;
        } else {
            durationTotal = durationMin + (((hotDirtySize / hotDirtyDuration) * durationMin) / (bandwidthOctet - (hotDirtySize / hotDirtyDuration)));
        }
        // Instantiate the computed bandwidth and duration
        try {
            // prevent from a 0 duration when the memory usage is very low
            int dd = (int) Math.max(1, Math.round(durationTotal));
            duration.instantiateTo(dd, Cause.Null);
            bandwidth.instantiateTo(maxBW, Cause.Null);
        } catch (ContradictionException e) {
            rp.getLogger().debug("Contradiction exception when trying to instantiate bandwidth and " + " duration variables for " + vm + " migration: ", e);
            return false;
        }
    }
    // Add links and switches constraints
    addLinkConstraints(rp);
    addSwitchConstraints(rp);
    return true;
}
Also used : ContradictionException(org.chocosolver.solver.exception.ContradictionException) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) Attributes(org.btrplace.model.Attributes) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) IntVar(org.chocosolver.solver.variables.IntVar) SchedulerModelingException(org.btrplace.scheduler.SchedulerModelingException)

Example 3 with SchedulerModelingException

use of org.btrplace.scheduler.SchedulerModelingException in project scheduler by btrplace.

the class CShareableResource method checkInitialSatisfaction.

/**
 * Check if the initial capacity &gt; sum current consumption
 * The ratio is instantiated now so the computation is correct
 */
private void checkInitialSatisfaction() {
    // Seems to me we don't support ratio change
    for (Node n : rp.getSourceModel().getMapping().getOnlineNodes()) {
        int nIdx = rp.getNode(n);
        double ratio = getOverbookRatio(nIdx);
        double capa = getSourceResource().getCapacity(n) * ratio;
        int usage = 0;
        for (VM vm : rp.getSourceModel().getMapping().getRunningVMs(n)) {
            usage += getSourceResource().getConsumption(vm);
            if (usage > capa) {
                // because such a situation does not physically makes sense (one cannot run at 110%)
                throw new SchedulerModelingException(rp.getSourceModel(), "Usage of virtual resource " + getResourceIdentifier() + " on node " + n + " (" + usage + ") exceeds its capacity (" + capa + ")");
            }
        }
    }
}
Also used : SatConstraint(org.btrplace.model.constraint.SatConstraint) SchedulerModelingException(org.btrplace.scheduler.SchedulerModelingException)

Example 4 with SchedulerModelingException

use of org.btrplace.scheduler.SchedulerModelingException in project scheduler by btrplace.

the class InstanceSolverRunner method checkUnknownVMsInMapping.

private static boolean checkUnknownVMsInMapping(Model m, Collection<VM> vms) throws SchedulerException {
    for (VM v : vms) {
        // This loop prevent from a useless allocation of memory when there is no issue
        if (!m.getMapping().contains(v)) {
            Set<VM> unknown = new HashSet<>(vms);
            unknown.removeAll(m.getMapping().getAllVMs());
            throw new SchedulerModelingException(m, "Unknown VMs: " + unknown);
        }
    }
    return true;
}
Also used : VM(org.btrplace.model.VM) SchedulerModelingException(org.btrplace.scheduler.SchedulerModelingException)

Example 5 with SchedulerModelingException

use of org.btrplace.scheduler.SchedulerModelingException in project scheduler by btrplace.

the class InstanceSolverRunner method build.

/**
 * Build a sat constraint
 *
 * @param cstr the model-side constraint
 * @return the solver-side constraint
 * @throws SchedulerException if the process failed
 */
private ChocoConstraint build(Constraint cstr) throws SchedulerException {
    ChocoMapper mapper = params.getMapper();
    ChocoConstraint cc = mapper.get(cstr);
    if (cc == null) {
        throw new SchedulerModelingException(origin, "No implementation mapped to '" + cstr.getClass().getSimpleName() + "'");
    }
    return cc;
}
Also used : ChocoMapper(org.btrplace.scheduler.choco.constraint.ChocoMapper) ChocoConstraint(org.btrplace.scheduler.choco.constraint.ChocoConstraint) SchedulerModelingException(org.btrplace.scheduler.SchedulerModelingException)

Aggregations

SchedulerModelingException (org.btrplace.scheduler.SchedulerModelingException)5 Node (org.btrplace.model.Node)2 VM (org.btrplace.model.VM)2 IntVar (org.chocosolver.solver.variables.IntVar)2 ArrayList (java.util.ArrayList)1 Attributes (org.btrplace.model.Attributes)1 Model (org.btrplace.model.Model)1 SatConstraint (org.btrplace.model.constraint.SatConstraint)1 ChocoConstraint (org.btrplace.scheduler.choco.constraint.ChocoConstraint)1 ChocoMapper (org.btrplace.scheduler.choco.constraint.ChocoMapper)1 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)1 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)1 CPowerView (org.btrplace.scheduler.choco.view.CPowerView)1 Model (org.chocosolver.solver.Model)1 ContradictionException (org.chocosolver.solver.exception.ContradictionException)1 Task (org.chocosolver.solver.variables.Task)1