use of org.btrplace.model.Node 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;
}
use of org.btrplace.model.Node in project scheduler by btrplace.
the class COffline method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
if (cstr.isContinuous() && !cstr.getChecker().startsWith(rp.getSourceModel())) {
rp.getLogger().error("Constraint {} is not satisfied initially", cstr);
return false;
}
Node nId = cstr.getInvolvedNodes().iterator().next();
int id = rp.getNode(nId);
NodeTransition m = rp.getNodeAction(nId);
try {
m.getState().instantiateTo(0, Cause.Null);
if (rp.getSourceModel().getMapping().isOffline(nId)) {
m.getStart().instantiateTo(0, Cause.Null);
}
} catch (ContradictionException ex) {
rp.getLogger().error("Unable to force node '" + nId + "' at being offline", ex);
return false;
}
for (VMTransition am : rp.getVMActions()) {
Slice s = am.getDSlice();
if (s != null) {
try {
s.getHoster().removeValue(id, Cause.Null);
} catch (ContradictionException e) {
rp.getLogger().error("Unable to remove " + am.getVM() + " of node " + nId, e);
}
}
}
return true;
}
use of org.btrplace.model.Node in project scheduler by btrplace.
the class COverbook method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
CShareableResource rcm = (CShareableResource) rp.getView(ShareableResource.VIEW_ID_BASE + cstr.getResource());
if (rcm == null) {
throw new SchedulerModelingException(rp.getSourceModel(), "Unable to get the resource mapping '" + cstr.getResource() + "'");
}
Node u = cstr.getInvolvedNodes().iterator().next();
rcm.capOverbookRatio(rp.getNode(u), cstr.getRatio());
return true;
}
use of org.btrplace.model.Node in project scheduler by btrplace.
the class CResourceCapacity method injectWithSingleNode.
private boolean injectWithSingleNode(CShareableResource rcm, ReconfigurationProblem rp) {
int amount = cstr.getAmount();
Model csp = rp.getModel();
Node n = cstr.getInvolvedNodes().iterator().next();
int nIdx = rp.getNode(n);
IntVar v = rcm.getVirtualUsage().get(nIdx);
csp.post(csp.arithm(v, "<=", amount));
// Continuous in practice ?
if (cstr.isContinuous()) {
if (cstr.isSatisfied(rp.getSourceModel())) {
try {
v.updateUpperBound(cstr.getAmount(), Cause.Null);
} catch (ContradictionException e) {
rp.getLogger().error("Unable to restrict to up to " + cstr.getAmount() + ", the maximum '" + rcm.getResourceIdentifier() + "' usage on " + n, e);
return false;
}
} else {
rp.getLogger().error("The constraint '{}' must be already satisfied to provide a continuous restriction", cstr);
return false;
}
}
return true;
}
use of org.btrplace.model.Node in project scheduler by btrplace.
the class CResourceCapacity method getMisPlacedVMs.
@Override
public Set<VM> getMisPlacedVMs(Instance i) {
if (cstr.getInvolvedNodes().size() <= 1) {
// If there is only a single node, we delegate this work to CShareableResource.
return Collections.emptySet();
}
Mapping map = i.getModel().getMapping();
ShareableResource rc = ShareableResource.get(i.getModel(), cstr.getResource());
if (rc == null) {
return map.getRunningVMs(cstr.getInvolvedNodes());
}
Set<VM> bad = new HashSet<>();
int remainder = cstr.getAmount();
for (Node n : cstr.getInvolvedNodes()) {
for (VM v : map.getRunningVMs(n)) {
remainder -= rc.getConsumption(v);
if (remainder < 0) {
for (Node n2 : cstr.getInvolvedNodes()) {
bad.addAll(map.getRunningVMs(n2));
}
return bad;
}
}
}
return bad;
}
Aggregations