Search in sources :

Example 1 with InconsistentSolutionException

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

the class DefaultChocoScheduler method solve.

@Override
public ReconfigurationPlan solve(Instance i) throws SchedulerException {
    Model mo = i.getModel();
    Collection<SatConstraint> cstrs = i.getSatConstraints();
    // If a network view is attached, ensure that all the migrations' destination node are defined
    Network net = Network.get(mo);
    stages = null;
    if (net != null) {
        // The network view is useless to take placement decisions
        mo.detach(net);
        // Solve a first time using placement oriented MinMTTR optimisation constraint
        ReconfigurationPlan p = runner.solve(params, i);
        stages = new StagedSolvingStatistics(runner.getStatistics());
        if (p == null) {
            return null;
        }
        // Add Fence constraints for each destination node chosen
        List<SatConstraint> newCstrs = p.getActions().stream().filter(a -> a instanceof MigrateVM).map(a -> new Fence(((MigrateVM) a).getVM(), Collections.singleton(((MigrateVM) a).getDestinationNode()))).collect(Collectors.toList());
        Model result = p.getResult();
        if (result == null) {
            throw new InconsistentSolutionException(p, "The plan cannot be applied");
        }
        // Add Root constraints to all staying VMs
        newCstrs.addAll(mo.getMapping().getRunningVMs().stream().filter(v -> p.getOrigin().getMapping().getVMLocation(v).id() == result.getMapping().getVMLocation(v).id()).map(Root::new).collect(Collectors.toList()));
        // Add the old constraints
        newCstrs.addAll(cstrs);
        // Re-attach the network view
        mo.attach(net);
        // New timeout value = elapsed time - initial timeout value
        Parameters ps = new DefaultParameters(params);
        if (ps.getTimeLimit() > 0) {
            // in seconds
            double timeout = params.getTimeLimit() - runner.getStatistics().getMetrics().timeCount() / 1000;
            ps.setTimeLimit((int) timeout);
        }
        return runner.solve(ps, new Instance(mo, newCstrs, i.getOptConstraint()));
    }
    // Solve and return the computed plan
    return runner.solve(params, new Instance(mo, cstrs, i.getOptConstraint()));
}
Also used : ChocoView(org.btrplace.scheduler.choco.view.ChocoView) Root(org.btrplace.model.constraint.Root) SchedulerException(org.btrplace.scheduler.SchedulerException) MigrateVM(org.btrplace.plan.event.MigrateVM) SolvingStatistics(org.btrplace.scheduler.choco.runner.SolvingStatistics) Fence(org.btrplace.model.constraint.Fence) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) SingleRunner(org.btrplace.scheduler.choco.runner.single.SingleRunner) BiConsumer(java.util.function.BiConsumer) ChocoMapper(org.btrplace.scheduler.choco.constraint.ChocoMapper) SatConstraint(org.btrplace.model.constraint.SatConstraint) Model(org.btrplace.model.Model) StagedSolvingStatistics(org.btrplace.scheduler.choco.runner.StagedSolvingStatistics) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) Collection(java.util.Collection) TransitionFactory(org.btrplace.scheduler.choco.transition.TransitionFactory) Collectors(java.util.stream.Collectors) MinMTTR(org.btrplace.model.constraint.MinMTTR) InconsistentSolutionException(org.btrplace.scheduler.InconsistentSolutionException) List(java.util.List) Instance(org.btrplace.model.Instance) InstanceSolver(org.btrplace.scheduler.choco.runner.InstanceSolver) Collections(java.util.Collections) Network(org.btrplace.model.view.network.Network) Settings(org.chocosolver.solver.Settings) InconsistentSolutionException(org.btrplace.scheduler.InconsistentSolutionException) Root(org.btrplace.model.constraint.Root) Instance(org.btrplace.model.Instance) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) StagedSolvingStatistics(org.btrplace.scheduler.choco.runner.StagedSolvingStatistics) Network(org.btrplace.model.view.network.Network) Model(org.btrplace.model.Model) Fence(org.btrplace.model.constraint.Fence)

Example 2 with InconsistentSolutionException

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

the class ReconfigurationPlanChecker method check.

/**
 * Check if a plan satisfies all the {@link SatConstraintChecker}.
 *
 * @param p the plan to check
 * @throws SatConstraintViolationException if a violation is detected
 */
public void check(ReconfigurationPlan p) throws SatConstraintViolationException {
    if (checkers.isEmpty()) {
        return;
    }
    checkModel(p.getOrigin(), true);
    if (!p.getActions().isEmpty()) {
        PriorityQueue<Action> starts = new PriorityQueue<>(p.getActions().size(), STARTS_CMP);
        PriorityQueue<Action> ends = new PriorityQueue<>(p.getActions().size(), ENDS_CMP);
        starts.addAll(p.getActions());
        ends.addAll(p.getActions());
        // Starts the actions
        int curMoment = starts.peek().getStart();
        while (!starts.isEmpty() || !ends.isEmpty()) {
            Action a = ends.peek();
            while (a != null && a.getEnd() == curMoment) {
                ends.remove();
                startingEvent = false;
                visitAndThrowOnViolation(a);
                visitEvents(a, Action.Hook.POST);
                a = ends.peek();
            }
            a = starts.peek();
            while (a != null && a.getStart() == curMoment) {
                starts.remove();
                startingEvent = true;
                visitEvents(a, Action.Hook.PRE);
                visitAndThrowOnViolation(a);
                a = starts.peek();
            }
            int nextEnd = Integer.MAX_VALUE;
            if (!ends.isEmpty()) {
                nextEnd = ends.peek().getEnd();
            }
            int nextStart = Integer.MAX_VALUE;
            if (!starts.isEmpty()) {
                nextStart = starts.peek().getStart();
            }
            curMoment = Math.min(nextEnd, nextStart);
        }
    }
    Model mo = p.getResult();
    if (mo == null) {
        throw new InconsistentSolutionException(p, "The resulting reconfiguration plan is not applyable");
    }
    checkModel(mo, false);
}
Also used : Action(org.btrplace.plan.event.Action) InconsistentSolutionException(org.btrplace.scheduler.InconsistentSolutionException) Model(org.btrplace.model.Model) PriorityQueue(java.util.PriorityQueue) SatConstraint(org.btrplace.model.constraint.SatConstraint)

Aggregations

Model (org.btrplace.model.Model)2 SatConstraint (org.btrplace.model.constraint.SatConstraint)2 InconsistentSolutionException (org.btrplace.scheduler.InconsistentSolutionException)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 PriorityQueue (java.util.PriorityQueue)1 BiConsumer (java.util.function.BiConsumer)1 Collectors (java.util.stream.Collectors)1 Instance (org.btrplace.model.Instance)1 Fence (org.btrplace.model.constraint.Fence)1 MinMTTR (org.btrplace.model.constraint.MinMTTR)1 Root (org.btrplace.model.constraint.Root)1 Network (org.btrplace.model.view.network.Network)1 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)1 Action (org.btrplace.plan.event.Action)1 MigrateVM (org.btrplace.plan.event.MigrateVM)1 SchedulerException (org.btrplace.scheduler.SchedulerException)1 ChocoMapper (org.btrplace.scheduler.choco.constraint.ChocoMapper)1 DurationEvaluators (org.btrplace.scheduler.choco.duration.DurationEvaluators)1