use of org.btrplace.model.constraint.MaxOnline in project scheduler by btrplace.
the class CMaxOnlineTest method testContinuousRestrictionSimpleCase.
@Test
public void testContinuousRestrictionSimpleCase() throws SchedulerException {
Model model = new DefaultModel();
Node n1 = model.newNode();
Node n2 = model.newNode();
Node n3 = model.newNode();
VM vm1 = model.newVM();
VM vm3 = model.newVM();
VM vm4 = model.newVM();
ShareableResource resources = new ShareableResource("cpu", 4, 1);
resources.setCapacity(n1, 8);
resources.setConsumption(vm4, 2);
Mapping map = model.getMapping().on(n1, n3).off(n2).run(n1, vm1, vm4).run(n3, vm3);
MappingUtils.fill(map, model.getMapping());
model.attach(resources);
MaxOnline maxon = new MaxOnline(map.getAllNodes(), 2, true);
List<SatConstraint> constraints = new ArrayList<>();
constraints.add(maxon);
constraints.add(new Online(n2));
ChocoScheduler cra = new DefaultChocoScheduler();
// cra.setTimeLimit(3);
cra.setMaxEnd(3);
cra.getMapper().mapConstraint(MaxOnline.class, CMaxOnline.class);
ReconfigurationPlan plan = cra.solve(model, constraints);
Assert.assertNotNull(plan);
Assert.assertTrue(maxon.isSatisfied(plan));
}
use of org.btrplace.model.constraint.MaxOnline in project scheduler by btrplace.
the class CMaxOnlineTest method discreteMaxOnlineTest2.
@Test
public void discreteMaxOnlineTest2() throws SchedulerException {
Model model = new DefaultModel();
Node n1 = model.newNode();
Node n2 = model.newNode();
Node n3 = model.newNode();
VM vm1 = model.newVM();
VM vm2 = model.newVM();
VM vm3 = model.newVM();
VM vm4 = model.newVM();
ShareableResource resources = new ShareableResource("vcpu", 1, 1);
resources.setCapacity(n1, 4);
resources.setCapacity(n2, 8);
resources.setCapacity(n3, 2);
resources.setConsumption(vm4, 2);
Mapping map = model.getMapping().on(n1, n2, n3).run(n1, vm1, vm4).run(n2, vm2).run(n3, vm3);
model.attach(resources);
MappingUtils.fill(map, model.getMapping());
Set<Node> nodes = map.getAllNodes();
MaxOnline maxon = new MaxOnline(nodes, 2);
Set<Node> nodes2 = new HashSet<>(Arrays.asList(n1, n2));
MaxOnline maxon2 = new MaxOnline(nodes2, 1);
List<SatConstraint> constraints = new ArrayList<>();
constraints.add(maxon);
constraints.add(maxon2);
ChocoScheduler cra = new DefaultChocoScheduler();
cra.setMaxEnd(4);
cra.getMapper().mapConstraint(MaxOnline.class, CMaxOnline.class);
ReconfigurationPlan plan = cra.solve(model, constraints);
Assert.assertNotNull(plan);
Assert.assertTrue(maxon.isSatisfied(plan.getResult()));
}
use of org.btrplace.model.constraint.MaxOnline in project scheduler by btrplace.
the class MaxOnlineBuilderTest method testGoodSignatures.
@Test(dataProvider = "goodMaxOnline")
public void testGoodSignatures(String str, int nbNodes) throws Exception {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
MaxOnline x = (MaxOnline) b.build("namespace test; VM[1..10] : tiny;\n@N[1..10] : mock;" + str).getConstraints().iterator().next();
Assert.assertEquals(x.getInvolvedNodes().size(), nbNodes);
Assert.assertEquals(x.isContinuous(), !str.startsWith(">>"));
}
use of org.btrplace.model.constraint.MaxOnline in project scheduler by btrplace.
the class MaxOnlineConverterTest method testViables.
@Test
public void testViables() throws JSONConverterException {
Model model = new DefaultModel();
Set<Node> s = new HashSet<>(Arrays.asList(model.newNode(), model.newNode(), model.newNode()));
MaxOnline mo = new MaxOnline(s, 2);
ConstraintsConverter conv = new ConstraintsConverter();
conv.register(new MaxOnlineConverter());
Constraint new_max = conv.fromJSON(model, conv.toJSON(mo));
Assert.assertEquals(mo, new_max);
System.out.println(conv.toJSON(mo));
}
use of org.btrplace.model.constraint.MaxOnline in project scheduler by btrplace.
the class CMaxOnlineTest method complexContinuousTest2.
@Test
public void complexContinuousTest2() throws SchedulerException {
Model model = new DefaultModel();
Node n1 = model.newNode(1);
Node n2 = model.newNode(2);
Node n3 = model.newNode(3);
Node n4 = model.newNode(4);
Node n5 = model.newNode(5);
VM vm1 = model.newVM();
VM vm2 = model.newVM();
VM vm3 = model.newVM();
VM vm4 = model.newVM();
ShareableResource resources = new ShareableResource("cpu", 2, 1);
resources.setCapacity(n1, 4);
resources.setCapacity(n2, 8);
resources.setConsumption(vm4, 2);
Mapping map = model.getMapping().on(n1, n2, n3).off(n4, n5).run(n1, vm1, vm4).run(n2, vm2).run(n3, vm3);
MappingUtils.fill(map, model.getMapping());
model.attach(resources);
MaxOnline maxOn = new MaxOnline(map.getAllNodes(), 4, true);
MaxOnline maxOn2 = new MaxOnline(new HashSet<>(Arrays.asList(n2, n3, n4)), 2, true);
List<SatConstraint> constraints = new ArrayList<>();
constraints.add(maxOn);
constraints.add(maxOn2);
constraints.addAll(Online.newOnline(n4, n5));
ChocoScheduler cra = new DefaultChocoScheduler();
cra.setTimeLimit(3);
cra.setMaxEnd(10);
cra.getMapper().mapConstraint(MaxOnline.class, CMaxOnline.class);
ReconfigurationPlan plan = cra.solve(model, constraints);
Assert.assertNotNull(plan);
Assert.assertTrue(maxOn.isSatisfied(plan));
}
Aggregations