use of org.btrplace.model.constraint.Spread in project scheduler by btrplace.
the class SpreadBuilderTest method testGoodSignatures.
@Test(dataProvider = "goodSpreads")
public void testGoodSignatures(String str, int nbVMs) throws Exception {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
Spread x = (Spread) b.build("namespace test; VM[1..10] : tiny;\n" + str).getConstraints().iterator().next();
Assert.assertEquals(x.getInvolvedVMs().size(), nbVMs);
Assert.assertEquals(x.isContinuous(), !str.startsWith(">>"));
}
use of org.btrplace.model.constraint.Spread in project scheduler by btrplace.
the class SpreadConverterTest method testViables.
@Test
public void testViables() throws JSONConverterException {
Model mo = new DefaultModel();
Spread d = new Spread(new HashSet<>(Arrays.asList(mo.newVM(), mo.newVM())), false);
Spread c = new Spread(new HashSet<>(Arrays.asList(mo.newVM(), mo.newVM())), true);
ConstraintsConverter conv = new ConstraintsConverter();
conv.register(new SpreadConverter());
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.Spread in project scheduler by btrplace.
the class SpreadBuilder method buildConstraint.
@Override
public List<Spread> buildConstraint(BtrPlaceTree t, List<BtrpOperand> args) {
if (checkConformance(t, args)) {
@SuppressWarnings("unchecked") List<VM> vms = (List<VM>) params[0].transform(this, t, args.get(0));
if (vms == null) {
return Collections.emptyList();
}
Set<VM> s = new HashSet<>(vms);
if (s.size() != vms.size()) {
return Collections.emptyList();
}
return Collections.singletonList(new Spread(new HashSet<>(vms), true));
}
return Collections.emptyList();
}
use of org.btrplace.model.constraint.Spread in project scheduler by btrplace.
the class SpreadSplitterTest method simpleTest.
@Test
public void simpleTest() {
SpreadSplitter splitter = new SpreadSplitter();
List<Instance> instances = new ArrayList<>();
Model m0 = new DefaultModel();
m0.getMapping().addReadyVM(m0.newVM(1));
Node n1 = m0.newNode();
m0.getMapping().addOnlineNode(n1);
m0.getMapping().addRunningVM(m0.newVM(2), n1);
Model m1 = new DefaultModel();
m1.getMapping().addReadyVM(m1.newVM(3));
Node n2 = m1.newNode();
Node n3 = m1.newNode();
m1.getMapping().addOnlineNode(n2);
m1.getMapping().addOnlineNode(n3);
m1.getMapping().addSleepingVM(m1.newVM(4), n2);
m1.getMapping().addRunningVM(m1.newVM(5), n3);
instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
Set<VM> all = new HashSet<>(m0.getMapping().getAllVMs());
all.addAll(m1.getMapping().getAllVMs());
TIntIntHashMap index = Instances.makeVMIndex(instances);
// Only VMs in m0
Spread spreadSingle = new Spread(m0.getMapping().getAllVMs());
Assert.assertTrue(splitter.split(spreadSingle, null, instances, index, new TIntIntHashMap()));
Assert.assertTrue(instances.get(0).getSatConstraints().contains(spreadSingle));
Assert.assertFalse(instances.get(1).getSatConstraints().contains(spreadSingle));
// All the VMs, test the split
Spread spreadAmong = new Spread(all, false);
Assert.assertTrue(splitter.split(spreadAmong, null, instances, index, new TIntIntHashMap()));
Assert.assertTrue(instances.get(0).getSatConstraints().contains(new Spread(m0.getMapping().getAllVMs(), false)));
Assert.assertTrue(instances.get(1).getSatConstraints().contains(new Spread(m1.getMapping().getAllVMs(), false)));
}
Aggregations