Search in sources :

Example 26 with Action

use of org.btrplace.plan.event.Action in project scheduler by btrplace.

the class DefaultReconfigurationPlanMonitor method commit.

@Override
public Set<Action> commit(Action a) {
    Set<Action> s = new HashSet<>();
    synchronized (lock) {
        boolean ret = a.apply(curModel);
        if (!ret) {
            throw new InfeasibleActionException(curModel, a);
        }
        nbCommitted++;
        // Browse all its dependencies for the action
        Set<Dependency> deps = pre.get(a);
        if (deps != null) {
            for (Dependency dep : deps) {
                Set<Action> actions = dep.getDependencies();
                actions.remove(a);
                if (actions.isEmpty()) {
                    Action x = dep.getAction();
                    s.add(x);
                }
            }
        }
    }
    return s;
}
Also used : Action(org.btrplace.plan.event.Action)

Example 27 with Action

use of org.btrplace.plan.event.Action in project scheduler by btrplace.

the class DefaultReconfigurationPlanMonitor method reset.

private void reset() {
    synchronized (lock) {
        curModel = plan.getOrigin().copy();
        pre.clear();
        nbCommitted = 0;
        for (Action a : plan) {
            Set<Action> deps = plan.getDirectDependencies(a);
            if (deps.isEmpty()) {
                this.dependencies.put(a, new Dependency(a, Collections.emptySet()));
            } else {
                Dependency dep = new Dependency(a, deps);
                this.dependencies.put(a, dep);
                for (Action x : dep.getDependencies()) {
                    Set<Dependency> pres = pre.get(x);
                    if (pres == null) {
                        pres = new HashSet<>();
                        pre.put(x, pres);
                    }
                    pres.add(dep);
                }
            }
        }
    }
}
Also used : Action(org.btrplace.plan.event.Action)

Example 28 with Action

use of org.btrplace.plan.event.Action 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.getOrigin(), 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)

Example 29 with Action

use of org.btrplace.plan.event.Action in project scheduler by btrplace.

the class TimeBasedPlanApplier method toString.

@Override
public String toString(ReconfigurationPlan p) {
    Set<Action> sorted = new TreeSet<>(new TimedBasedActionComparator(true, true));
    sorted.addAll(p.getActions());
    StringBuilder b = new StringBuilder();
    for (Action a : sorted) {
        b.append(a.getStart()).append(':').append(a.getEnd()).append(' ').append(a.toString()).append('\n');
    }
    return b.toString();
}
Also used : Action(org.btrplace.plan.event.Action)

Example 30 with Action

use of org.btrplace.plan.event.Action in project scheduler by btrplace.

the class CShareableResource method insertActions.

@Override
public boolean insertActions(ReconfigurationProblem r, Solution s, ReconfigurationPlan p) {
    Mapping srcMapping = r.getSourceModel().getMapping();
    // Encache the VM -> Action to ease the event injection.
    Map<VM, Action> actions = new HashMap<>();
    p.getActions().stream().filter(RunningVMPlacement.class::isInstance).map(a -> (RunningVMPlacement) a).forEach(a -> actions.put(destVM(a.getVM()), (Action) a));
    for (VM vm : r.getFutureRunningVMs()) {
        Slice dSlice = r.getVMAction(vm).getDSlice();
        Node destNode = r.getNode(s.getIntVal(dSlice.getHoster()));
        if (srcMapping.isRunning(vm) && destNode.equals(srcMapping.getVMLocation(vm))) {
            // Was running and stay on the same node
            // Check if the VM has been cloned
            // TODO: might be too late depending on the symmetry breaking on the actions schedule
            insertAllocateAction(p, vm, destNode, s.getIntVal(dSlice.getStart()));
        } else {
            VM dVM = destVM(vm);
            Action a = actions.get(dVM);
            if (a instanceof MigrateVM) {
                // For a migrated VM, we allocate once the migration over
                insertAllocateEvent(a, Action.Hook.POST, dVM);
            } else {
                // Resume or Boot VM
                // As the VM was not running, we pre-allocate
                insertAllocateEvent(a, Action.Hook.PRE, dVM);
            }
        }
    }
    return true;
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) Arrays(java.util.Arrays) SchedulerException(org.btrplace.scheduler.SchedulerException) TIntArrayList(gnu.trove.list.array.TIntArrayList) Node(org.btrplace.model.Node) Preserve(org.btrplace.model.constraint.Preserve) Overbook(org.btrplace.model.constraint.Overbook) TDoubleList(gnu.trove.list.TDoubleList) ContradictionException(org.chocosolver.solver.exception.ContradictionException) MigrateVM(org.btrplace.plan.event.MigrateVM) HashMap(java.util.HashMap) RoundedUpDivision(org.btrplace.scheduler.choco.extensions.RoundedUpDivision) TObjectIntMap(gnu.trove.map.TObjectIntMap) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) TObjectDoubleHashMap(gnu.trove.map.hash.TObjectDoubleHashMap) HashSet(java.util.HashSet) TObjectDoubleMap(gnu.trove.map.TObjectDoubleMap) VM(org.btrplace.model.VM) SchedulerModelingException(org.btrplace.scheduler.SchedulerModelingException) Mapping(org.btrplace.model.Mapping) Map(java.util.Map) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) SatConstraint(org.btrplace.model.constraint.SatConstraint) Model(org.btrplace.model.Model) TIntList(gnu.trove.list.TIntList) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) Set(java.util.Set) Cause(org.chocosolver.solver.Cause) Parameters(org.btrplace.scheduler.choco.Parameters) AllocateEvent(org.btrplace.plan.event.AllocateEvent) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) IntVar(org.chocosolver.solver.variables.IntVar) List(java.util.List) TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) RunningVMPlacement(org.btrplace.plan.event.RunningVMPlacement) ResourceRelated(org.btrplace.model.view.ResourceRelated) Allocate(org.btrplace.plan.event.Allocate) ShareableResource(org.btrplace.model.view.ShareableResource) Solution(org.chocosolver.solver.Solution) Instance(org.btrplace.model.Instance) ResourceCapacity(org.btrplace.model.constraint.ResourceCapacity) Action(org.btrplace.plan.event.Action) Collections(java.util.Collections) Action(org.btrplace.plan.event.Action) RunningVMPlacement(org.btrplace.plan.event.RunningVMPlacement) HashMap(java.util.HashMap) TObjectDoubleHashMap(gnu.trove.map.hash.TObjectDoubleHashMap) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) Slice(org.btrplace.scheduler.choco.Slice) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Mapping(org.btrplace.model.Mapping) MigrateVM(org.btrplace.plan.event.MigrateVM)

Aggregations

Action (org.btrplace.plan.event.Action)40 Test (org.testng.annotations.Test)25 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)18 MigrateVM (org.btrplace.plan.event.MigrateVM)10 DurationEvaluators (org.btrplace.scheduler.choco.duration.DurationEvaluators)10 HashSet (java.util.HashSet)9 Parameters (org.btrplace.scheduler.choco.Parameters)9 ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)9 VM (org.btrplace.model.VM)8 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)8 DefaultReconfigurationProblemBuilder (org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder)8 Model (org.btrplace.model.Model)7 CMinMTTR (org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR)7 ArrayList (java.util.ArrayList)6 SatConstraint (org.btrplace.model.constraint.SatConstraint)6 Node (org.btrplace.model.Node)5 ShareableResource (org.btrplace.model.view.ShareableResource)5 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)5 BootVM (org.btrplace.plan.event.BootVM)4 ShutdownNode (org.btrplace.plan.event.ShutdownNode)4