use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class CSplitAmong method getMisPlacedVMs.
@Override
public Set<VM> getMisPlacedVMs(Instance i) {
// contains the set of VMs hosted on a group id.
@SuppressWarnings("unchecked") Collection<VM>[] usedGrp = new Set[cstr.getGroupsOfNodes().size()];
Mapping map = i.getModel().getMapping();
Set<VM> bad = new HashSet<>();
for (Collection<VM> vms : cstr.getGroupsOfVMs()) {
int grp = -1;
for (VM vm : vms) {
if (map.isRunning(vm)) {
Node n = map.getVMLocation(vm);
int g = getPGroup(n);
if (g == -1) {
// The VM is on a node that belong to none of the given groups
bad.add(vm);
} else if (grp == -1) {
grp = g;
usedGrp[g] = vms;
} else if (g != grp) {
// The VMs spread over multiple group of nodes, the group of VMs is mis-placed
bad.addAll(vms);
if (usedGrp[g] != null) {
bad.addAll(usedGrp[g]);
}
bad.addAll(usedGrp[grp]);
}
}
}
}
return bad;
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class WorstFit method canStay.
/**
* Check if a VM can stay on its current node.
*
* @param vm the VM
* @return {@code true} iff the VM can stay
*/
private boolean canStay(VM vm) {
Mapping m = rp.getSourceModel().getMapping();
if (m.isRunning(vm)) {
int curPos = rp.getNode(m.getVMLocation(vm));
if (!rp.getVMAction(vm).getDSlice().getHoster().contains(curPos)) {
return false;
}
IStateInt[] loads = load(curPos);
return loadWith(curPos, loads, vm) <= 1.0;
}
return false;
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class CShareableResource method getMisPlacedVMs.
/**
* {@inheritDoc}
*
* @param i the model to use to inspect the VMs.
* @return the set of VMs that cannot have their associated {@link Preserve} constraint satisfy with regards
* to a possible {@link Overbook} and single-node {@link ResourceCapacity} constraint.
*/
@Override
public Set<VM> getMisPlacedVMs(Instance i) {
for (SatConstraint c : i.getSatConstraints()) {
if (!(c instanceof ResourceRelated && ((ResourceRelated) c).getResource().equals(rc.getResourceIdentifier()))) {
continue;
}
if (c instanceof Preserve) {
VM v = c.getInvolvedVMs().iterator().next();
wantedAmount.put(v, consumption(v, ((Preserve) c).getAmount()));
} else if (c instanceof Overbook) {
Node n = c.getInvolvedNodes().iterator().next();
wantedRatios.put(n, ratio(n, ((Overbook) c).getRatio()));
} else if (c instanceof ResourceCapacity && c.getInvolvedNodes().size() == 1) {
Node n = c.getInvolvedNodes().iterator().next();
wantedCapacity.put(n, capacity(n, ((ResourceCapacity) c).getAmount()));
}
}
Mapping m = i.getModel().getMapping();
Set<VM> candidates = new HashSet<>();
for (Node n : m.getOnlineNodes()) {
if (overloaded(m, n)) {
candidates.addAll(m.getRunningVMs(n));
}
}
return candidates;
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class DefaultChocoSchedulerTest method testGetStatisticsWithTimeout.
@Test(expectedExceptions = { SchedulerException.class })
public void testGetStatisticsWithTimeout() throws SchedulerException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
for (int i = 0; i < 1000; i++) {
Node n = mo.newNode();
map.addOnlineNode(n);
for (int j = 0; j < 10; j++) {
map.addReadyVM(mo.newVM());
}
}
ChocoScheduler cra = new DefaultChocoScheduler();
cra.setTimeLimit(1);
try {
System.err.println(cra.solve(mo, Running.newRunning(map.getAllVMs())));
} catch (SchedulerException e) {
SolvingStatistics stats = cra.getStatistics();
Assert.assertNotNull(stats);
System.out.println(stats);
Assert.assertTrue(stats.getSolutions().isEmpty());
Assert.assertEquals(stats.getInstance().getModel(), mo);
throw e;
}
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testVMCounting.
/**
* Check the consistency between the variables counting the number of VMs on
* each node, and the placement variable.
*
* @throws org.btrplace.scheduler.SchedulerException
* @throws ContradictionException
*/
@Test
public void testVMCounting() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Node n3 = mo.newNode();
Node n2 = mo.newNode();
Mapping map = mo.getMapping();
for (int i = 0; i < 7; i++) {
VM v = mo.newVM();
map.addReadyVM(v);
}
map.addOnlineNode(n3);
map.addOnlineNode(n2);
Parameters ps = new DefaultParameters();
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), map.getAllVMs(), new HashSet<>(), new HashSet<>()).build();
// Restrict the capacity to 5 at most
for (IntVar capa : rp.getNbRunningVMs()) {
capa.updateUpperBound(5, Cause.Null);
}
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(-1, false);
Assert.assertNotNull(p);
// Check consistency between the counting and the hoster variables
int[] counts = new int[map.getAllNodes().size()];
for (Node n : map.getOnlineNodes()) {
int nIdx = rp.getNode(n);
counts[nIdx] = rp.getNbRunningVMs().get(nIdx).getValue();
}
for (VM vm : rp.getFutureRunningVMs()) {
VMTransition vmo = rp.getVMActions().get(rp.getVM(vm));
int on = vmo.getDSlice().getHoster().getValue();
counts[on]--;
}
for (int count : counts) {
Assert.assertEquals(count, 0);
}
}
Aggregations