use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.
the class ResourceCapacityChecker method endsWith.
@Override
public boolean endsWith(Model i) {
ShareableResource r = ShareableResource.get(i, getConstraint().getResource());
if (r == null) {
return false;
}
int remainder = getConstraint().getAmount();
for (Node id : getNodes()) {
if (i.getMapping().isOnline(id)) {
remainder -= r.sumConsumptions(i.getMapping().getRunningVMs(id), true);
if (remainder < 0) {
return false;
}
}
}
return true;
}
use of org.btrplace.model.view.ShareableResource 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.view.ShareableResource 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.view.ShareableResource 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.view.ShareableResource in project scheduler by btrplace.
the class CShareableResourceTest method testInsertAction.
/**
* Reproduce issue#145.
*/
/*@Test*/
public void testInsertAction() {
Model mo = new DefaultModel();
ShareableResource cpu = new ShareableResource("cpu");
ShareableResource mem = new ShareableResource("mem");
mo.attach(cpu);
mo.attach(mem);
Node node = mo.newNode();
Node node2 = mo.newNode();
mo.getMapping().on(node, node2);
cpu.setCapacity(node, 100000);
mem.setCapacity(node, 100000);
cpu.setCapacity(node2, 100000);
mem.setCapacity(node2, 100000);
for (int i = 0; i < 10000; i++) {
VM vm = mo.newVM();
mo.getMapping().run(node, vm);
cpu.setConsumption(vm, 1);
mem.setConsumption(vm, 1);
}
ChocoScheduler sched = new DefaultChocoScheduler();
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Running.newRunning(mo.getMapping().getAllVMs()));
cstrs.addAll(NoDelay.newNoDelay(mo.getMapping().getAllVMs()));
cstrs.addAll(Fence.newFence(mo.getMapping().getAllVMs(), Arrays.asList(node2)));
cstrs.addAll(Preserve.newPreserve(mo.getMapping().getAllVMs(), "cpu", 2));
cstrs.addAll(Preserve.newPreserve(mo.getMapping().getAllVMs(), "mem", 2));
ReconfigurationPlan plan = sched.solve(mo, cstrs);
System.out.println(plan);
System.out.println(sched.getStatistics());
}
Aggregations