use of org.btrplace.model.constraint.Among 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.Among in project scheduler by btrplace.
the class AmongSplitterTest method testSplittable.
@Test
public void testSplittable() throws SchedulerException {
List<VM> vms = Arrays.asList(vm1, vm2, vm3);
Collection<Collection<Node>> parts = new ArrayList<>();
parts.add(Arrays.asList(n1, n2));
parts.add(Collections.singletonList(n3));
parts.add(Collections.singletonList(n4));
Among single = new Among(vms, parts);
/*
N1 v1 v2
N2 v3
---
N3 v4
--
N4 v5
*/
FixedNodeSetsPartitioning partitionner = new FixedNodeSetsPartitioning(parts);
partitionner.setPartitions(parts);
List<Instance> instances = partitionner.split(new DefaultParameters(), new Instance(mo, Collections.emptyList(), new MinMTTR()));
TIntIntHashMap vmIndex = Instances.makeVMIndex(instances);
TIntIntHashMap nodeIndex = Instances.makeNodeIndex(instances);
splitter.split(single, new Instance(mo, new MinMTTR()), instances, vmIndex, nodeIndex);
Among a = (Among) instances.get(0).getSatConstraints().iterator().next();
Assert.assertEquals(a.getGroupsOfNodes().size(), 1);
Assert.assertEquals(a.getInvolvedNodes(), Arrays.asList(n1, n2));
for (Instance i : instances) {
System.out.println(i.getSatConstraints());
}
}
use of org.btrplace.model.constraint.Among in project scheduler by btrplace.
the class AmongBuilderTest method testGoodSignatures.
@Test(dataProvider = "goodAmongs")
public void testGoodSignatures(String str, int nbVMs, int nbNs1, int nbNs2, boolean c) throws Exception {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
Set<SatConstraint> cstrs = b.build("namespace test; VM[1..10] : tiny;\n@N[1..10] : defaultNode;\n" + str).getConstraints();
Assert.assertEquals(cstrs.size(), 1);
Among x = (Among) cstrs.iterator().next();
Assert.assertEquals(x.getGroupsOfNodes().iterator().next().size(), nbNs1);
Assert.assertEquals(x.getInvolvedNodes().size(), nbNs1 + nbNs2);
Assert.assertEquals(x.getInvolvedVMs().size(), nbVMs);
Assert.assertEquals(x.isContinuous(), c);
}
use of org.btrplace.model.constraint.Among in project scheduler by btrplace.
the class AmongSplitter method split.
@Override
public boolean split(final Among cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, final TIntIntHashMap nodePosition) {
final boolean c = cstr.isContinuous();
return SplittableElementSet.newVMIndex(cstr.getInvolvedVMs(), vmsPosition).forEachPartition((index, idx, from, to) -> {
if (to - from >= 2) {
ElementSubSet<VM> vms = new ElementSubSet<>(index, idx, from, to);
// Get the servers on the partition
// Filter out the other nodes in the original constraint
final Collection<Collection<Node>> subParams = new ArrayList<>();
for (Collection<Node> ns : cstr.getGroupsOfNodes()) {
SplittableElementSet<Node> nodeIndex = SplittableElementSet.newNodeIndex(ns, nodePosition);
Set<Node> s = nodeIndex.getSubSet(idx);
if (s != null && !s.isEmpty()) {
subParams.add(s);
}
}
partitions.get(idx).getSatConstraints().add(new Among(vms, subParams, c));
}
return true;
});
}
use of org.btrplace.model.constraint.Among in project scheduler by btrplace.
the class AmongConverterTest method testViables.
@Test
public void testViables() throws JSONConverterException {
ConstraintsConverter conv = new ConstraintsConverter();
conv.register(new AmongConverter());
Model mo = new DefaultModel();
List<VM> s1 = Arrays.asList(mo.newVM(), mo.newVM(), mo.newVM());
Collection<Node> p1 = Arrays.asList(mo.newNode(), mo.newNode());
List<Node> p2 = Arrays.asList(mo.newNode(), mo.newNode());
List<Node> p3 = Collections.singletonList(mo.newNode());
Set<Collection<Node>> pgrps = new HashSet<>(Arrays.asList(p1, p2, p3));
Among d = new Among(s1, pgrps, false);
Among c = new Among(s1, pgrps, true);
Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(d)), d);
Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(c)), c);
System.out.println(conv.toJSON(d));
}
Aggregations