use of org.btrplace.model.constraint.Spread in project scheduler by btrplace.
the class IssuesTest method testIssue86.
@Test
public void testIssue86() throws Exception {
Model mo = new DefaultModel();
mo.getMapping().addReadyVM(mo.newVM());
mo.getMapping().addReadyVM(mo.newVM());
mo.getMapping().addReadyVM(mo.newVM());
mo.getMapping().addOnlineNode(mo.newNode());
mo.getMapping().addOnlineNode(mo.newNode());
mo.getMapping().addOnlineNode(mo.newNode());
List<SatConstraint> cstrs = mo.getMapping().getAllVMs().stream().map(Running::new).collect(Collectors.toList());
cstrs.add(new Spread(mo.getMapping().getAllVMs(), false));
cstrs.addAll(mo.getMapping().getOnlineNodes().stream().map(n -> new RunningCapacity(n, 1)).collect(Collectors.toList()));
Instance i = new Instance(mo, cstrs, new MinMTTR());
ChocoScheduler s = new DefaultChocoScheduler();
s.doOptimize(false);
s.doRepair(false);
ReconfigurationPlan p = s.solve(i.getModel(), i.getSatConstraints(), i.getOptConstraint());
Assert.assertNotNull(p);
Assert.assertEquals(3, p.getActions().size());
s.doRepair(true);
p = s.solve(i.getModel(), i.getSatConstraints(), i.getOptConstraint());
Assert.assertNotNull(p);
Assert.assertEquals(3, p.getActions().size());
}
use of org.btrplace.model.constraint.Spread in project scheduler by btrplace.
the class IssuesTest method test16b.
/**
* Unit test derived from Issue 16.
*
* @throws org.btrplace.scheduler.SchedulerException
*/
@Test
public void test16b() throws SchedulerException {
Model model = new DefaultModel();
Node n1 = model.newNode();
Node n2 = model.newNode();
Node n3 = model.newNode();
Node n4 = model.newNode();
VM vm1 = model.newVM();
VM vm2 = model.newVM();
VM vm3 = model.newVM();
VM vm4 = model.newVM();
VM vm5 = model.newVM();
VM vm6 = model.newVM();
model.getMapping().on(n1, n2, n3, n4).run(n1, vm1, vm2).run(n2, vm3, vm4).run(n3, vm5, vm6);
Set<SatConstraint> ctrsC = new HashSet<>();
Set<VM> vms1 = new HashSet<>(Arrays.asList(vm1, vm3, vm5));
Set<VM> vms2 = new HashSet<>(Arrays.asList(vm2, vm4, vm6));
ctrsC.add(new Spread(vms1));
ctrsC.add(new Spread(vms2));
ctrsC.add(new Fence(vm3, Collections.singleton(n1)));
Offline off = new Offline(n2);
ctrsC.add(off);
ChocoScheduler cra = new DefaultChocoScheduler();
ReconfigurationPlan dp = cra.solve(model, ctrsC);
Assert.assertNotNull(dp);
}
use of org.btrplace.model.constraint.Spread in project scheduler by btrplace.
the class Bench method makeApp.
private static int makeApp(Instance i, int remainder, List<Collection<Node>> edges) {
int curMax = Math.min(remainder, 30);
if (remainder - 30 < 6) {
curMax = remainder / 2;
} else {
curMax = Math.min(curMax, rnd.nextInt(30 - 6) + 6);
}
// at least 2 VMs, at most max - 4 (2 per tiers)
int nbT1 = curMax == 6 ? 2 : rnd.nextInt(curMax - 4 - 2) + 2;
curMax -= nbT1;
int nbT2 = curMax == 4 ? 2 : rnd.nextInt(curMax - 2 - 2) + 2;
int nbT3 = curMax - nbT2;
int nbVMs = nbT1 + nbT2 + nbT3;
Model mo = i.getModel();
Set<VM> t1 = makeVMSet(mo, nbT1);
Set<VM> t2 = makeVMSet(mo, nbT2);
Set<VM> t3 = makeVMSet(mo, nbT3);
// Make the constraints
i.getSatConstraints().add(new Spread(t1, true));
i.getSatConstraints().add(new Spread(t2, true));
i.getSatConstraints().add(new Spread(t3, true));
i.getSatConstraints().add(new Among(t3, edges, false));
// Place the VMs
// Pick a random edge, and place every VMs on it
int myEdge = rnd.nextInt(edges.size());
Collection<Node> nodes = edges.get(myEdge);
Node n = nodes.iterator().next();
t1.stream().map(v -> mo.getMapping().addRunningVM(v, n));
t2.stream().map(v -> mo.getMapping().addRunningVM(v, n));
t3.stream().map(v -> mo.getMapping().addRunningVM(v, n));
return nbVMs;
}
use of org.btrplace.model.constraint.Spread in project scheduler by btrplace.
the class ChocoMapperTest method testMap.
@Test(dependsOnMethods = { "testInstantiate" })
public void testMap() {
Model mo = new DefaultModel();
ChocoMapper map = ChocoMapper.newBundle();
Spread s = new Spread(Collections.singleton(mo.newVM()));
ChocoConstraint c = map.get(s);
Assert.assertTrue(c.getClass().equals(CSpread.class));
map.unMapConstraint(Spread.class);
map.mapConstraint(Spread.class, CSpread.class);
c = map.get(s);
Assert.assertTrue(c.getClass().equals(CSpread.class));
}
use of org.btrplace.model.constraint.Spread in project scheduler by btrplace.
the class CMinMigrationsTest method testWithFreeNodes.
/**
* Issue #137.
* ShutdownableNode.isOnline() is not instantiated at the end of the problem
*/
@Test
public void testWithFreeNodes() {
Model mo = new DefaultModel();
Node n0 = mo.newNode();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
VM v1 = mo.newVM();
VM v2 = mo.newVM();
DefaultChocoScheduler s = new DefaultChocoScheduler();
mo.getMapping().on(n0, n1, n2).run(n0, v1, v2);
Instance i = new Instance(mo, Arrays.asList(new Spread(mo.getMapping().getAllVMs(), false)), new MinMigrations());
ReconfigurationPlan p = s.solve(i);
Assert.assertNotNull(p);
}
Aggregations