use of org.btrplace.model.constraint.Overbook 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) {
final TObjectDoubleMap<Node> wantedRatios = new TObjectDoubleHashMap<>();
final int nbVMs = i.getModel().getMapping().getNbVMs();
final int nbNodes = i.getModel().getMapping().getNbNodes();
final IntMap wantedAmount = new IntMap(0, nbVMs);
final IntMap wantedCapacity = new IntMap(0, nbNodes);
for (SatConstraint c : i.getSatConstraints()) {
if (!(c instanceof ResourceRelated && ((ResourceRelated) c).getResource().equals(rc.getResourceIdentifier()))) {
continue;
}
if (c instanceof Preserve) {
// We guarantee the highest request so far.
VM v = c.getInvolvedVMs().iterator().next();
int qty = ((Preserve) c).getAmount();
wantedAmount.put(v.id(), Math.max(wantedAmount.get(v.id()), qty));
} else if (c instanceof Overbook) {
Node n = c.getInvolvedNodes().iterator().next();
double min = ((Overbook) c).getRatio();
if (wantedRatios.containsKey(n)) {
min = Math.min(min, wantedRatios.get(n));
}
wantedRatios.put(n, min);
} else if (c instanceof ResourceCapacity && c.getInvolvedNodes().size() == 1) {
Node n = c.getInvolvedNodes().iterator().next();
int qty = ((ResourceCapacity) c).getAmount();
wantedCapacity.put(n.id(), Math.max(qty, wantedCapacity.get(n.id())));
}
}
Mapping m = i.getModel().getMapping();
Set<VM> candidates = new HashSet<>();
for (Node n : m.getOnlineNodes()) {
Set<VM> running = m.getRunningVMs(n);
if (overloaded(wantedRatios, wantedAmount, wantedCapacity, running, n)) {
candidates.addAll(running);
}
}
return candidates;
}
use of org.btrplace.model.constraint.Overbook in project scheduler by btrplace.
the class CShareableResourceTest method testWithFloat.
@Test
public void testWithFloat() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Mapping map = mo.getMapping().on(n1, n2).run(n1, vm1, vm2);
ShareableResource rc = new ShareableResource("foo");
rc.setCapacity(n1, 32);
rc.setConsumption(vm1, 3);
rc.setConsumption(vm2, 2);
mo.attach(rc);
ChocoScheduler cra = new DefaultChocoScheduler();
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Online.newOnline(map.getAllNodes()));
Overbook o = new Overbook(n1, "foo", 1.5, false);
cstrs.add(o);
Overbook o2 = new Overbook(n2, "foo", 1.5, false);
cstrs.add(o2);
cstrs.add(new Preserve(vm1, "foo", 5));
ReconfigurationPlan p = cra.solve(mo, cstrs);
Assert.assertNotNull(p);
}
use of org.btrplace.model.constraint.Overbook in project scheduler by btrplace.
the class OverbookSplitterTest method simpleTest.
@Test
public void simpleTest() {
OverbookSplitter splitter = new OverbookSplitter();
List<Instance> instances = new ArrayList<>();
Model m0 = new DefaultModel();
Node n = m0.newNode(0);
m0.getMapping().addOnlineNode(n);
m0.getMapping().addOnlineNode(m0.newNode(1));
Model m1 = new DefaultModel();
m1.getMapping().addOnlineNode(m1.newNode(2));
m1.getMapping().addOnlineNode(m1.newNode(3));
instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
Set<Node> all = new HashSet<>(m0.getMapping().getAllNodes());
all.addAll(m1.getMapping().getAllNodes());
TIntIntHashMap nodeIndex = Instances.makeNodeIndex(instances);
// Only nodes in m0
Overbook oSimple = new Overbook(n, "cpu", 2);
Assert.assertTrue(splitter.split(oSimple, null, instances, new TIntIntHashMap(), nodeIndex));
Assert.assertTrue(instances.get(0).getSatConstraints().contains(oSimple));
Assert.assertFalse(instances.get(1).getSatConstraints().contains(oSimple));
}
use of org.btrplace.model.constraint.Overbook in project scheduler by btrplace.
the class COverbookTest method testBasic.
@Test
public void testBasic() throws SchedulerException {
Node[] nodes = new Node[2];
VM[] vms = new VM[3];
Model mo = new DefaultModel();
Mapping m = mo.getMapping();
ShareableResource rcCPU = new ShareableResource("cpu");
for (int i = 0; i < vms.length; i++) {
if (i < nodes.length) {
nodes[i] = mo.newNode();
rcCPU.setCapacity(nodes[i], 2);
m.addOnlineNode(nodes[i]);
}
vms[i] = mo.newVM();
rcCPU.setConsumption(vms[i], 1);
m.addReadyVM(vms[i]);
}
mo.attach(rcCPU);
Overbook o = new Overbook(nodes[0], "cpu", 2);
Overbook o2 = new Overbook(nodes[1], "cpu", 2);
Collection<SatConstraint> c = new HashSet<>();
c.add(o);
c.add(o2);
c.addAll(Running.newRunning(m.getAllVMs()));
c.add(new Preserve(vms[0], "cpu", 1));
c.addAll(Online.newOnline(m.getAllNodes()));
DefaultChocoScheduler cra = new DefaultChocoScheduler();
cra.getMapper().mapConstraint(Overbook.class, COverbook.class);
ReconfigurationPlan p = cra.solve(mo, c);
Assert.assertNotNull(p);
}
use of org.btrplace.model.constraint.Overbook in project scheduler by btrplace.
the class COverbookTest method testWithIncrease.
/**
* Test with a root VM that has increasing need and another one that prevent it
* to get the resources immediately
*/
@Test
public void testWithIncrease() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
Node n1 = mo.newNode();
Mapping map = mo.getMapping().on(n1).run(n1, vm1, vm2);
ShareableResource rc = new ShareableResource("foo");
rc.setCapacity(n1, 5);
rc.setConsumption(vm1, 3);
rc.setConsumption(vm2, 2);
mo.attach(rc);
ChocoScheduler cra = new DefaultChocoScheduler();
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Online.newOnline(map.getAllNodes()));
Overbook o = new Overbook(n1, "foo", 1);
o.setContinuous(true);
cstrs.add(o);
cstrs.add(new Ready(vm2));
cstrs.add(new Preserve(vm1, "foo", 5));
ReconfigurationPlan p = cra.solve(mo, cstrs);
Assert.assertNotNull(p);
Assert.assertEquals(p.getSize(), 2);
Action al = p.getActions().stream().filter(s -> s instanceof Allocate).findAny().get();
Action sh = p.getActions().stream().filter(s -> s instanceof ShutdownVM).findAny().get();
Assert.assertTrue(sh.getEnd() <= al.getStart());
}
Aggregations