use of org.btrplace.model.constraint.Split in project scheduler by btrplace.
the class CSplitTest method testSimpleDiscrete.
@Test
public void testSimpleDiscrete() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
VM vm6 = mo.newVM();
VM vm7 = mo.newVM();
VM vm8 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Node n4 = mo.newNode();
Node n5 = mo.newNode();
mo.getMapping().on(n1, n2, n3, n4, n5).run(n1, vm1, vm2, vm3).run(n3, vm4, vm5, vm6).run(n5, vm7, vm8);
Collection<VM> g1 = Arrays.asList(vm1, vm2);
Collection<VM> g2 = Arrays.asList(vm3, vm4, vm5);
Collection<VM> g3 = Arrays.asList(vm6, vm7);
Collection<Collection<VM>> grps = Arrays.asList(g1, g2, g3);
Split s = new Split(grps);
ChocoScheduler cra = new DefaultChocoScheduler();
ReconfigurationPlan p = cra.solve(mo, Collections.singleton(s));
Assert.assertNotNull(p);
Assert.assertTrue(p.getSize() > 0);
}
use of org.btrplace.model.constraint.Split in project scheduler by btrplace.
the class CSplitTest method testGetMisplaced.
@Test
public void testGetMisplaced() {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
VM vm6 = mo.newVM();
VM vm7 = mo.newVM();
VM vm8 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Node n4 = mo.newNode();
Node n5 = mo.newNode();
Mapping map = mo.getMapping().on(n1, n2, n3, n4, n5).run(n1, vm1, vm2).run(n2, vm3).run(n3, vm4, vm5).run(n4, vm6).run(n5, vm7, vm8);
Collection<VM> g1 = Arrays.asList(vm1, vm2);
Collection<VM> g2 = new HashSet<>(Arrays.asList(vm3, vm4, vm5));
Collection<VM> g3 = new HashSet<>(Arrays.asList(vm6, vm7));
Collection<Collection<VM>> grps = Arrays.asList(g1, g2, g3);
Split s = new Split(grps);
CSplit cs = new CSplit(s);
Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR());
Assert.assertTrue(cs.getMisPlacedVMs(i).isEmpty());
map.addRunningVM(vm5, n1);
Set<VM> bad = cs.getMisPlacedVMs(i);
Assert.assertEquals(bad.size(), 3);
Assert.assertTrue(bad.contains(vm1) && bad.contains(vm2) && bad.contains(vm5));
map.addRunningVM(vm6, n3);
bad = cs.getMisPlacedVMs(i);
Assert.assertTrue(bad.contains(vm4) && bad.contains(vm5) && bad.contains(vm6));
}
use of org.btrplace.model.constraint.Split in project scheduler by btrplace.
the class SplitSplitter method split.
@Override
public boolean split(final Split cstr, Instance origin, final List<Instance> partitions, final TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
final boolean c = cstr.isContinuous();
return SplittableElementSet.newVMIndex(cstr.getInvolvedVMs(), vmsPosition).forEachPartition((index, idx, from, to) -> {
if (to - from >= 2) {
// More than 1 VM involved in a split constraint for this partition
// if these VMs belong to at least 2 groups, we must post a split constraints
// for the VMs on these groups
Collection<Collection<VM>> sets = new ArrayList<>();
for (Collection<VM> vms : cstr.getSets()) {
SplittableElementSet<VM> subSplit = SplittableElementSet.newVMIndex(vms, vmsPosition);
Set<VM> s = subSplit.getSubSet(idx);
if (!s.isEmpty()) {
sets.add(s);
}
}
if (sets.size() > 1) {
partitions.get(idx).getSatConstraints().add(new Split(sets, c));
}
}
return true;
});
}
use of org.btrplace.model.constraint.Split in project scheduler by btrplace.
the class SplitConverterTest method testViables.
@Test
public void testViables() throws JSONConverterException {
Model mo = new DefaultModel();
Collection<VM> s1 = Arrays.asList(mo.newVM(), mo.newVM());
Collection<VM> s2 = Arrays.asList(mo.newVM(), mo.newVM());
Collection<VM> s3 = Collections.singletonList(mo.newVM());
Collection<Collection<VM>> vgrps = new HashSet<>(Arrays.asList(s1, s2, s3));
Split d = new Split(vgrps, false);
Split c = new Split(vgrps, true);
ConstraintsConverter conv = new ConstraintsConverter();
conv.register(new SplitConverter());
Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(d)), d);
Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(c)), c);
System.out.println(conv.toJSON(d));
}
use of org.btrplace.model.constraint.Split in project scheduler by btrplace.
the class CSplitTest method testContinuous.
// @Test
@Test(enabled = false)
public void testContinuous() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
VM vm6 = mo.newVM();
VM vm7 = mo.newVM();
VM vm8 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Node n4 = mo.newNode();
Node n5 = mo.newNode();
Mapping map = mo.getMapping().on(n1, n2, n3, n4, n5).run(n1, vm1, vm2).run(n3, vm3, vm4, vm5).run(n5, vm6, vm7, vm8);
Collection<VM> g1 = Arrays.asList(vm1, vm2);
Collection<VM> g2 = Arrays.asList(vm3, vm4, vm5);
Collection<VM> g3 = Arrays.asList(vm6, vm7);
Collection<Collection<VM>> grps = Arrays.asList(g1, g2, g3);
Split s = new Split(grps);
s.setContinuous(true);
ChocoScheduler cra = new DefaultChocoScheduler();
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.add(s);
// go away before the other arrive.
for (VM v : map.getRunningVMs(n1)) {
cstrs.add(new Fence(v, Collections.singleton(n3)));
}
// cra.setTimeLimit(2);
ReconfigurationPlan p = cra.solve(mo, cstrs);
Assert.assertNotNull(p);
Assert.assertTrue(p.getSize() > 0);
}
Aggregations