use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class ReadyBuilderTest method testGoodSignatures.
@Test(dataProvider = "goodReadys")
public void testGoodSignatures(String str, int nbVMs, boolean c) throws Exception {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
Set<SatConstraint> cstrs = b.build("namespace test; VM[1..10] : tiny;\n@N[1..20] : defaultNode;" + str).getConstraints();
Assert.assertEquals(cstrs.size(), nbVMs);
Set<VM> vms = new HashSet<>();
for (SatConstraint x : cstrs) {
Assert.assertTrue(x instanceof Ready);
Assert.assertTrue(vms.addAll(x.getInvolvedVMs()));
Assert.assertEquals(x.isContinuous(), c);
}
}
use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class SleepingBuilderTest method testGoodSignatures.
@Test(dataProvider = "goodsleepings")
public void testGoodSignatures(String str, int nbVMs, boolean c) throws Exception {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
Set<SatConstraint> cstrs = b.build("namespace test; VM[1..10] : tiny;\n@N[1..20] : defaultNode;" + str).getConstraints();
Set<VM> vms = new HashSet<>();
Assert.assertEquals(cstrs.size(), nbVMs);
for (SatConstraint x : cstrs) {
Assert.assertTrue(x instanceof Sleeping);
Assert.assertTrue(vms.addAll(x.getInvolvedVMs()));
Assert.assertEquals(x.isContinuous(), c);
}
}
use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class CMinMigrationsTest method simpleTest.
@Test
public void simpleTest() {
Model mo = new DefaultModel();
Node n0 = mo.newNode();
Node n1 = mo.newNode();
VM vm0 = mo.newVM();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
mo.getMapping().on(n0, n1).run(n0, vm0, vm1, vm2);
ShareableResource mem = new ShareableResource("mem", 5, 1);
// cpu dimension to create the violation
ShareableResource cpu = new ShareableResource("cpu", 5, 1);
// VM0 as the big VM
mem.setConsumption(vm0, 3);
mo.attach(cpu);
mo.attach(mem);
List<SatConstraint> cstrs = new ArrayList<>();
// The 3 VMs no longer feet on n0
cstrs.add(new Preserve(vm0, "cpu", 5));
ChocoScheduler s = new DefaultChocoScheduler();
s.doOptimize(true);
ReconfigurationPlan p = s.solve(mo, cstrs, new MinMigrations());
System.out.println(s.getStatistics());
System.out.println(p);
// VM0 to n1
Assert.assertEquals(p.getActions().size(), 1);
// VM0 to n1
Assert.assertEquals(p.getResult().getMapping().getVMLocation(vm0), n1);
}
use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class DefaultChocoSchedulerTest method testWithUnknownVMs.
/*@Test
public void testGetStatistics() throws SchedulerException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
for (int i = 0; i < 10; i++) {
Node n = mo.newNode();
map.addOnlineNode(n);
map.addRunningVM(mo.newVM(), n);
}
ChocoScheduler cra = new DefaultChocoScheduler();
cra.doOptimize(true);
cra.setTimeLimit(0);
Assert.assertNull(cra.getStatistics());
OptConstraint o = new OptConstraint() {
@Override
public String id() {
return "foo";
}
};
ChocoConstraint co = new ChocoMapperTest.MockCConstraint() {
public ChocoMapperTest.MockCConstraint(OptConstraint f) {}
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
return false;
}
@Override
public Set<VM> getMisPlacedVMs(Model m) {
return Collections.emptySet();
}
};
cra.getMapper().register(o.getClass(), co.getClass());
ReconfigurationPlan p = cra.solve(mo, Collections.<SatConstraint>emptyList(), o);
Mapping res = p.getResult().getMapping();
int nbRunning = 0;
for (Node n : res.getOnlineNodes()) {
if (!res.getRunningVMs(n).isEmpty()) {
nbRunning++;
}
}
Assert.assertEquals(nbRunning, 1);
SolvingStatistics st = cra.getStatistics();
Assert.assertEquals(st.getSolutions().get(0).getOptValue(), 1);
Assert.assertEquals(st.getSolutions().size(), 1);
}
*/
/* @Test
public void testSolvableRepair() throws SchedulerException {
Model mo = new DefaultModel();
final VM vm1 = mo.newVM();
final VM vm2 = mo.newVM();
final VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Node n4 = mo.newNode();
mo.on(n1, n2, n3).run(n1, vm1, vm4).run(n2, vm2).run(n3, vm3, vm5).get();
//A satisfied constraint
Fence c1 = new Fence(vm1, new HashSet<>(Arrays.asList(n1, n2)));
//A constraint that is not satisfied. vm2 is misplaced
Fence c2 = new Fence(vm2, new HashSet<>(Arrays.asList(n1, n3)));
Set<SatConstraint> cstrs = new HashSet<SatConstraint>(Arrays.asList(c1, c2));
mo = new DefaultModel();
mo.on(n1, n2, n3).run(n1, vm1, vm4).run(n2, vm2).run(n3, vm3, vm5).get();
ChocoScheduler cra = new DefaultChocoScheduler();
OptConstraint o = new OptConstraint() {
@Override
public String id() {
return "foo";
}
};
ChocoConstraint co = new ChocoConstraint() {
@Override
public Set<VM> getMisPlacedVMs(Model m) {
return new HashSet<>(Arrays.asList(vm2, vm3));
}
};
cra.getMapper().register(o.getClass(), co.getClass());
cra.doRepair(true);
cra.doOptimize(false);
//Solve a problem with the repair mode
Assert.assertNotNull(cra.solve(mo, cstrs, o));
SolvingStatistics st = cra.getStatistics();
System.out.println(st);
Assert.assertEquals(st.getNbManagedVMs(), 2); //vm2, vm3.
}
*/
@Test(expectedExceptions = { SchedulerException.class })
public void testWithUnknownVMs() throws SchedulerException {
Model mo = new DefaultModel();
final VM vm1 = mo.newVM();
final VM vm2 = mo.newVM();
final VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
VM vm6 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Node n4 = mo.newNode();
mo.getMapping().on(n1, n2, n3).run(n1, vm1, vm4).run(n2, vm2).run(n3, vm3, vm5);
SatConstraint cstr = mock(SatConstraint.class);
when(cstr.getInvolvedVMs()).thenReturn(Arrays.asList(vm1, vm2, vm6));
when(cstr.getInvolvedNodes()).thenReturn(Arrays.asList(n1, n4));
ChocoScheduler cra = new DefaultChocoScheduler();
cra.solve(mo, Collections.singleton(cstr));
}
use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class IssuesTest method testIssue89.
@Test
public static void testIssue89() throws Exception {
final Model model = new DefaultModel();
final Mapping mapping = model.getMapping();
final Node node0 = model.newNode(0);
final int[] ids0 = { 1, 45, 43, 40, 39, 38, 82, 80, 79, 78, 30, 75, 18, 16, 15, 14, 60, 9, 55, 54, 50, 48 };
final Node node1 = model.newNode(1);
final int[] ids1 = { 84, 83, 81, 77, 73, 71, 64, 63, 62, 57, 53, 52, 47, 46, 44, 41, 34, 31, 28, 25, 13, 8, 6, 4, 3, 0 };
final Node node2 = model.newNode(2);
final int[] ids2 = { 21, 67, 42, 36, 35, 33, 76, 74, 23, 69, 68, 20, 61, 12, 11, 10, 5, 51 };
final Node node3 = model.newNode(3);
final int[] ids3 = { 2, 66, 86, 85, 37, 32, 29, 27, 26, 72, 24, 70, 22, 19, 65, 17, 59, 58, 56, 7, 49 };
final ShareableResource cpu = new ShareableResource("cpu", 45, 1);
final ShareableResource mem = new ShareableResource("mem", 90, 2);
populateNodeVm(model, mapping, node0, ids0);
populateNodeVm(model, mapping, node1, ids1);
populateNodeVm(model, mapping, node2, ids2);
populateNodeVm(model, mapping, node3, ids3);
model.attach(cpu);
model.attach(mem);
final Collection<SatConstraint> satConstraints = new ArrayList<>();
// We want to cause Node 3 to go offline to see how the VMs hosted on that
// node will get rebalanced.
satConstraints.add(new Offline(node3));
final OptConstraint optConstraint = new MinMTTR();
DefaultChocoScheduler scheduler = new DefaultChocoScheduler();
scheduler.doOptimize(false);
scheduler.doRepair(true);
scheduler.setTimeLimit(60000);
ReconfigurationPlan plan = scheduler.solve(model, satConstraints, optConstraint);
System.out.println(scheduler.getStatistics());
Assert.assertTrue(plan.isApplyable());
satConstraints.clear();
// This is somewhat similar to making Node 3 going offline by ensuring that
// all VMs can no longer get hosted on that node.
satConstraints.addAll(mapping.getAllVMs().stream().map(vm -> new Ban(vm, Collections.singletonList(node3))).collect(Collectors.toList()));
scheduler = new DefaultChocoScheduler();
scheduler.doOptimize(false);
scheduler.doRepair(true);
plan = scheduler.solve(model, satConstraints, optConstraint);
Assert.assertTrue(plan.isApplyable());
}
Aggregations