use of org.btrplace.scheduler.choco.transition.VMTransition 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.scheduler.choco.transition.VMTransition 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;
}
use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class CShareableResource method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem p) throws SchedulerException {
this.rp = p;
this.references = new HashMap<>();
this.clones = new HashMap<>();
csp = p.getModel();
this.source = p.getSourceModel();
List<Node> nodes = p.getNodes();
phyRcUsage = new ArrayList<>(nodes.size());
virtRcUsage = new ArrayList<>(nodes.size());
this.ratios = new TDoubleArrayList(nodes.size());
id = ShareableResource.VIEW_ID_BASE + rc.getResourceIdentifier();
for (Node nId : p.getNodes()) {
phyRcUsage.add(csp.intVar(p.makeVarLabel("phyRcUsage('", rc.getResourceIdentifier(), "', '", nId, "')"), 0, rc.getCapacity(nId), true));
virtRcUsage.add(csp.intVar(p.makeVarLabel("virtRcUsage('", rc.getResourceIdentifier(), "', '", nId, "')"), 0, Integer.MAX_VALUE / 100, true));
ratios.add(UNCHECKED_RATIO);
}
phyRcUsage = Collections.unmodifiableList(phyRcUsage);
virtRcUsage = Collections.unmodifiableList(virtRcUsage);
// Bin packing for the node vmAllocation
vmAllocation = new TIntArrayList();
for (VM vmId : p.getVMs()) {
VMTransition a = p.getVMAction(vmId);
Slice slice = a.getDSlice();
if (slice == null) {
// The VMs will not be running, so its consumption is set to 0
vmAllocation.add(0);
} else {
// We don't know about the next VM usage for the moment, -1 is used by default to allow to detect an
// non-updated value.
vmAllocation.add(-1);
}
}
return true;
}
use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class DefaultCumulatives method symmetryBreakingForStayingVMs.
/**
* Symmetry breaking for VMs that stay running, on the same node.
*
* @return {@code true} iff the symmetry breaking does not lead to a problem without solutions
*/
private boolean symmetryBreakingForStayingVMs(ReconfigurationProblem rp) {
for (VM vm : rp.getFutureRunningVMs()) {
VMTransition a = rp.getVMAction(vm);
Slice dSlice = a.getDSlice();
Slice cSlice = a.getCSlice();
if (dSlice != null && cSlice != null) {
BoolVar stay = ((KeepRunningVM) a).isStaying();
Boolean ret = strictlyDecreasingOrUnchanged(vm);
if (Boolean.TRUE.equals(ret) && !zeroDuration(rp, stay, cSlice)) {
return false;
// Else, the resource usage is decreasing, so
// we set the cSlice duration to 0 to directly reduces the resource allocation
} else if (Boolean.FALSE.equals(ret) && !zeroDuration(rp, stay, dSlice)) {
// (the allocation will be performed at the end of the reconfiguration process)
return false;
}
}
}
return true;
}
use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testMinimize.
/**
* Test a minimization problem: use the minimum number of nodes.
*
* @throws org.btrplace.scheduler.SchedulerException
*/
@Test
public void testMinimize() throws SchedulerException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
for (int i = 0; i < 10; i++) {
Node n = mo.newNode();
VM vm = mo.newVM();
map.addOnlineNode(n);
map.addRunningVM(vm, n);
}
Parameters ps = new DefaultParameters();
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
Solver s = rp.getSolver();
IntVar nbNodes = rp.getModel().intVar("nbNodes", 1, map.getAllNodes().size(), true);
Stream<Slice> dSlices = rp.getVMActions().stream().filter(t -> t.getDSlice() != null).map(VMTransition::getDSlice);
IntVar[] hosters = dSlices.map(Slice::getHoster).toArray(IntVar[]::new);
rp.getModel().post(rp.getModel().atMostNValues(hosters, nbNodes, true));
rp.setObjective(true, nbNodes);
ReconfigurationPlan plan = rp.solve(-1, true);
Assert.assertNotNull(plan);
Assert.assertEquals(s.getMeasures().getSolutionCount(), 1);
Mapping dst = plan.getResult().getMapping();
Assert.assertEquals(usedNodes(dst), 1);
}
Aggregations