use of org.btrplace.model.constraint.Preserve 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.constraint.Preserve in project scheduler by btrplace.
the class RelocatableVMTest method testRelocateDueToPreserve.
@Test
public void testRelocateDueToPreserve() throws SchedulerException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
final VM vm1 = mo.newVM();
final VM vm2 = mo.newVM();
final VM vm3 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addRunningVM(vm1, n1);
map.addRunningVM(vm2, n1);
map.addRunningVM(vm3, n2);
org.btrplace.model.view.ShareableResource rc = new ShareableResource("cpu", 10, 10);
rc.setCapacity(n1, 7);
rc.setConsumption(vm1, 3);
rc.setConsumption(vm2, 3);
rc.setConsumption(vm3, 5);
Preserve pr = new Preserve(vm1, "cpu", 5);
ChocoScheduler cra = new DefaultChocoScheduler();
mo.attach(rc);
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Online.newOnline(map.getAllNodes()));
cstrs.addAll(Overbook.newOverbooks(map.getAllNodes(), "cpu", 1));
cstrs.add(pr);
ReconfigurationPlan p = cra.solve(mo, cstrs);
Assert.assertNotNull(p);
}
use of org.btrplace.model.constraint.Preserve in project scheduler by btrplace.
the class RelocatableVMTest method testReinstantiationWithPreserve.
@Test
public void testReinstantiationWithPreserve() throws SchedulerException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
VM vm5 = mo.newVM();
VM vm6 = mo.newVM();
VM vm7 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addRunningVM(vm5, n1);
map.addRunningVM(vm6, n1);
map.addRunningVM(vm7, n2);
ShareableResource rc = new ShareableResource("cpu", 10, 10);
rc.setCapacity(n1, 7);
rc.setConsumption(vm5, 3);
rc.setConsumption(vm6, 3);
rc.setConsumption(vm7, 5);
for (VM vm : map.getAllVMs()) {
mo.getAttributes().put(vm, "template", "small");
mo.getAttributes().put(vm, "clone", true);
}
Preserve pr = new Preserve(vm5, "cpu", 5);
ChocoScheduler cra = new DefaultChocoScheduler();
cra.getDurationEvaluators().register(MigrateVM.class, new ConstantActionDuration<>(20));
mo.attach(rc);
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Online.newOnline(map.getAllNodes()));
cstrs.add(pr);
cra.doOptimize(true);
try {
ReconfigurationPlan p = cra.solve(mo, cstrs);
Assert.assertNotNull(p);
} catch (SchedulerException e) {
Assert.fail(e.getMessage(), e);
}
}
use of org.btrplace.model.constraint.Preserve in project scheduler by btrplace.
the class CShareableResourceTest method testDefaultOverbookRatio.
/**
* The default overbooking ratio of 1 will make this problem having no solution.
*/
@Test
public void testDefaultOverbookRatio() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
Node n1 = mo.newNode();
mo.getMapping().on(n1).run(n1, vm1, vm2);
ShareableResource rc = new ShareableResource("foo", 0, 0);
rc.setConsumption(vm1, 2);
rc.setConsumption(vm2, 3);
rc.setCapacity(n1, 5);
mo.attach(rc);
ChocoScheduler s = new DefaultChocoScheduler();
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.add(new Fence(vm1, n1));
cstrs.add(new Preserve(vm2, "foo", 4));
// rp.solve(0, false);
ReconfigurationPlan p = s.solve(mo, cstrs);
Assert.assertNull(p);
}
use of org.btrplace.model.constraint.Preserve 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);
org.btrplace.model.view.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);
}
Aggregations