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