use of org.btrplace.model.VM in project scheduler by btrplace.
the class InstanceSolverRunner method buildRP.
private ReconfigurationProblem buildRP() throws SchedulerException {
// Build the RP. As VM state management is not possible
// We extract VM-state related constraints first.
// For other constraint, we just create the right choco constraint
Set<VM> toRun = new HashSet<>();
Set<VM> toForge = new HashSet<>();
Set<VM> toKill = new HashSet<>();
Set<VM> toSleep = new HashSet<>();
cConstraints = new ArrayList<>();
for (SatConstraint cstr : cstrs) {
checkNodesExistence(origin, cstr.getInvolvedNodes());
// (when they will be forged)
if (!(cstrs instanceof Ready)) {
checkUnknownVMsInMapping(origin, cstr.getInvolvedVMs());
}
if (cstr instanceof Running) {
toRun.addAll(cstr.getInvolvedVMs());
} else if (cstr instanceof Sleeping) {
toSleep.addAll(cstr.getInvolvedVMs());
} else if (cstr instanceof Ready) {
checkUnknownVMsInMapping(origin, cstr.getInvolvedVMs());
toForge.addAll(cstr.getInvolvedVMs());
} else if (cstr instanceof Killed) {
checkUnknownVMsInMapping(origin, cstr.getInvolvedVMs());
toKill.addAll(cstr.getInvolvedVMs());
}
cConstraints.add(build(cstr));
}
cConstraints.add(build(obj));
views = makeViews();
DefaultReconfigurationProblemBuilder rpb = new DefaultReconfigurationProblemBuilder(origin).setNextVMsStates(toForge, toRun, toSleep, toKill).setParams(params);
if (params.doRepair()) {
Set<VM> toManage = new HashSet<>();
cConstraints.forEach(c -> toManage.addAll(c.getMisPlacedVMs(instance)));
views.forEach(v -> toManage.addAll(v.getMisPlacedVMs(instance)));
rpb.setManageableVMs(toManage);
}
// The core views have been instantiated and available through rp.getViews()
// Set the maximum duration
ReconfigurationProblem p = rpb.build();
try {
p.getEnd().updateUpperBound(params.getMaxEnd(), Cause.Null);
} catch (ContradictionException e) {
p.getLogger().error("Unable to restrict the maximum plan duration to " + params.getMaxEnd(), e);
return null;
}
return p;
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class CNetwork method beforeSolve.
@Override
public boolean beforeSolve(ReconfigurationProblem rp) throws SchedulerException {
Model mo = rp.getSourceModel();
Attributes attrs = mo.getAttributes();
// Pre-compute duration and bandwidth for each VM migration
for (VMTransition migration : rp.getVMActions()) {
if (!(migration instanceof RelocatableVM)) {
continue;
}
// Get vars from migration
VM vm = migration.getVM();
IntVar bandwidth = ((RelocatableVM) migration).getBandwidth();
IntVar duration = migration.getDuration();
Node src = rp.getSourceModel().getMapping().getVMLocation(vm);
// Try to get the destination node
Node dst;
if (!migration.getDSlice().getHoster().isInstantiated()) {
throw new SchedulerModelingException(null, "Destination node for VM '" + vm + "' should be known !");
}
if (!mo.getAttributes().isSet(vm, "memUsed")) {
throw new SchedulerModelingException(null, "Unable to retrieve 'memUsed' attribute for the vm '" + vm + "'");
}
dst = rp.getNode(migration.getDSlice().getHoster().getValue());
if (src.equals(dst)) {
try {
((RelocatableVM) migration).getBandwidth().instantiateTo(0, Cause.Null);
continue;
} catch (ContradictionException e) {
rp.getLogger().error("Contradiction exception when trying to instantiate bandwidth and " + " duration variables for " + vm + " migration", e);
return false;
}
}
// Get attribute vars
int memUsed = attrs.get(vm, "memUsed", -1);
// Get VM memory activity attributes if defined, otherwise set an idle workload on the VM
// Minimal observed value on idle VM
double hotDirtySize = attrs.get(vm, "hotDirtySize", 5.0);
// Minimal observed value on idle VM
double hotDirtyDuration = attrs.get(vm, "hotDirtyDuration", 2.0);
double coldDirtyRate = attrs.get(vm, "coldDirtyRate", 0.0);
// Get the maximal bandwidth available on the migration path
int maxBW = net.getRouting().getMaxBW(src, dst);
// Compute the duration related to each enumerated bandwidth
double durationMin;
double durationColdPages;
double durationHotPages;
double durationTotal;
// Cheat a bit, real is less than theoretical (8->9)
double bandwidthOctet = maxBW / 9.0;
// Estimate the duration for the current bandwidth
durationMin = memUsed / bandwidthOctet;
if (durationMin > hotDirtyDuration) {
durationColdPages = (hotDirtySize + (durationMin - hotDirtyDuration) * coldDirtyRate) / (bandwidthOctet - coldDirtyRate);
durationHotPages = (hotDirtySize / bandwidthOctet * ((hotDirtySize / hotDirtyDuration) / (bandwidthOctet - (hotDirtySize / hotDirtyDuration))));
durationTotal = durationMin + durationColdPages + durationHotPages;
} else {
durationTotal = durationMin + (((hotDirtySize / hotDirtyDuration) * durationMin) / (bandwidthOctet - (hotDirtySize / hotDirtyDuration)));
}
// Instantiate the computed bandwidth and duration
try {
// prevent from a 0 duration when the memory usage is very low
int dd = (int) Math.max(1, Math.round(durationTotal));
duration.instantiateTo(dd, Cause.Null);
bandwidth.instantiateTo(maxBW, Cause.Null);
} catch (ContradictionException e) {
rp.getLogger().error("Contradiction exception when trying to instantiate bandwidth and " + " duration variables for " + vm + " migration: ", e);
return false;
}
}
// Add links and switches constraints
addLinkConstraints(rp);
addSwitchConstraints(rp);
return true;
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class CNetwork method addSwitchConstraints.
/**
* Add the cumulative constraints for each blocking switch (having limited capacity)
*
* @param rp the reconfiguration problem
*/
private void addSwitchConstraints(ReconfigurationProblem rp) {
// Switches capacity limitation
List<Task> tasksList = new ArrayList<>();
List<IntVar> heightsList = new ArrayList<>();
for (Switch sw : net.getSwitches()) {
// Only if the capacity is limited
if (sw.getCapacity() != Integer.MAX_VALUE) {
for (VM vm : rp.getVMs()) {
VMTransition a = rp.getVMAction(vm);
if (a != null && a instanceof RelocatableVM) {
if (a.getDSlice().getHoster().isInstantiated()) {
if (a.getCSlice().getHoster().getValue() != a.getDSlice().getHoster().getValue()) {
Node src = source.getMapping().getVMLocation(vm);
Node dst = rp.getNode(a.getDSlice().getHoster().getValue());
if (!Collections.disjoint(net.getConnectedLinks(sw), net.getRouting().getPath(src, dst))) {
tasksList.add(new Task(a.getStart(), a.getDuration(), a.getEnd()));
heightsList.add(((RelocatableVM) a).getBandwidth());
}
}
}
}
}
if (!tasksList.isEmpty()) {
// Post the cumulative constraint for the current switch
csp.post(csp.cumulative(tasksList.toArray(new Task[tasksList.size()]), heightsList.toArray(new IntVar[heightsList.size()]), csp.intVar(sw.getCapacity()), true));
tasksList.clear();
heightsList.clear();
}
}
}
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class CNetwork method addLinkConstraints.
/**
* Add the cumulative constraints for each link.
*
* Full-duplex links are considered, two cumulative constraints are defined per link by looking at
* the migration direction for each link on the migration path.
*
* @param rp the reconfiguration problem
*/
private void addLinkConstraints(ReconfigurationProblem rp) {
// Links limitation
List<Task> tasksListUp = new ArrayList<>();
List<Task> tasksListDown = new ArrayList<>();
List<IntVar> heightsListUp = new ArrayList<>();
List<IntVar> heightsListDown = new ArrayList<>();
for (Link l : net.getLinks()) {
for (VM vm : rp.getVMs()) {
VMTransition a = rp.getVMAction(vm);
if (a instanceof RelocatableVM && !a.getDSlice().getHoster().isInstantiatedTo(a.getCSlice().getHoster().getValue())) {
Node src = source.getMapping().getVMLocation(vm);
Node dst = rp.getNode(a.getDSlice().getHoster().getValue());
List<Link> path = net.getRouting().getPath(src, dst);
// Check first if the link is on migration path
if (path.contains(l)) {
// Get link direction
LinkDirection linkDirection = net.getRouting().getLinkDirection(src, dst, l);
// UpLink
if (linkDirection == LinkDirection.UPLINK) {
tasksListUp.add(((RelocatableVM) a).getMigrationTask());
heightsListUp.add(((RelocatableVM) a).getBandwidth());
} else // DownLink
{
tasksListDown.add(((RelocatableVM) a).getMigrationTask());
heightsListDown.add(((RelocatableVM) a).getBandwidth());
}
}
}
}
if (!tasksListUp.isEmpty()) {
// Post the cumulative constraint for the current UpLink
csp.post(csp.cumulative(tasksListUp.toArray(new Task[tasksListUp.size()]), heightsListUp.toArray(new IntVar[heightsListUp.size()]), csp.intVar(l.getCapacity()), true));
tasksListUp.clear();
heightsListUp.clear();
}
if (!tasksListDown.isEmpty()) {
// Post the cumulative constraint for the current DownLink
csp.post(csp.cumulative(tasksListDown.toArray(new Task[tasksListDown.size()]), heightsListDown.toArray(new IntVar[heightsListDown.size()]), csp.intVar(l.getCapacity()), true));
tasksListDown.clear();
heightsListDown.clear();
}
}
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class CShareableResource method linkVirtualToPhysicalUsage.
private boolean linkVirtualToPhysicalUsage() throws SchedulerException {
int min = Integer.MAX_VALUE;
// Number of VMs with a 0 usage
int nbZeroes = 0;
for (int vId = 0; vId < vmAllocation.size(); vId++) {
int alloc = vmAllocation.get(vId);
if (alloc > 0) {
min = Math.min(alloc, min);
} else {
nbZeroes++;
}
}
for (int nIdx = 0; nIdx < ratios.size(); nIdx++) {
if (!linkVirtualToPhysicalUsage(nIdx)) {
return false;
}
if (!capHosting(nIdx, min, nbZeroes)) {
return false;
}
}
// The slice scheduling constraint that is necessary
TIntArrayList cUse = new TIntArrayList();
List<IntVar> dUse = new ArrayList<>();
for (VMTransition a : rp.getVMActions()) {
VM vm = a.getVM();
Slice c = a.getCSlice();
Slice d = a.getDSlice();
if (c != null) {
cUse.add(getSourceResource().getConsumption(vm));
}
if (d != null) {
int m = getVMAllocation(rp.getVM(vm));
dUse.add(rp.fixed(m, "vmAllocation('", getResourceIdentifier(), "', '", vm, "'"));
}
}
Cumulatives v = (Cumulatives) rp.getView(Cumulatives.VIEW_ID);
v.addDim(virtRcUsage, cUse.toArray(), dUse.toArray(new IntVar[dUse.size()]));
checkInitialSatisfaction();
return true;
}
Aggregations