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;
}
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);
}
}
}
}
}
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);
}
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();
}
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;
}
Aggregations