use of org.btrplace.model.constraint.Ban in project scheduler by btrplace.
the class IssuesTest method testIssue89.
@Test
public static void testIssue89() throws Exception {
final Model model = new DefaultModel();
final Mapping mapping = model.getMapping();
final Node node0 = model.newNode(0);
final int[] ids0 = { 1, 45, 43, 40, 39, 38, 82, 80, 79, 78, 30, 75, 18, 16, 15, 14, 60, 9, 55, 54, 50, 48 };
final Node node1 = model.newNode(1);
final int[] ids1 = { 84, 83, 81, 77, 73, 71, 64, 63, 62, 57, 53, 52, 47, 46, 44, 41, 34, 31, 28, 25, 13, 8, 6, 4, 3, 0 };
final Node node2 = model.newNode(2);
final int[] ids2 = { 21, 67, 42, 36, 35, 33, 76, 74, 23, 69, 68, 20, 61, 12, 11, 10, 5, 51 };
final Node node3 = model.newNode(3);
final int[] ids3 = { 2, 66, 86, 85, 37, 32, 29, 27, 26, 72, 24, 70, 22, 19, 65, 17, 59, 58, 56, 7, 49 };
final ShareableResource cpu = new ShareableResource("cpu", 45, 1);
final ShareableResource mem = new ShareableResource("mem", 90, 2);
populateNodeVm(model, mapping, node0, ids0);
populateNodeVm(model, mapping, node1, ids1);
populateNodeVm(model, mapping, node2, ids2);
populateNodeVm(model, mapping, node3, ids3);
model.attach(cpu);
model.attach(mem);
final Collection<SatConstraint> satConstraints = new ArrayList<>();
// We want to cause Node 3 to go offline to see how the VMs hosted on that
// node will get rebalanced.
satConstraints.add(new Offline(node3));
final OptConstraint optConstraint = new MinMTTR();
DefaultChocoScheduler scheduler = new DefaultChocoScheduler();
scheduler.doOptimize(false);
scheduler.doRepair(true);
scheduler.setTimeLimit(60000);
ReconfigurationPlan plan = scheduler.solve(model, satConstraints, optConstraint);
System.out.println(scheduler.getStatistics());
Assert.assertTrue(plan.isApplyable());
satConstraints.clear();
// This is somewhat similar to making Node 3 going offline by ensuring that
// all VMs can no longer get hosted on that node.
satConstraints.addAll(mapping.getAllVMs().stream().map(vm -> new Ban(vm, Collections.singletonList(node3))).collect(Collectors.toList()));
scheduler = new DefaultChocoScheduler();
scheduler.doOptimize(false);
scheduler.doRepair(true);
plan = scheduler.solve(model, satConstraints, optConstraint);
Assert.assertTrue(plan.isApplyable());
}
use of org.btrplace.model.constraint.Ban in project scheduler by btrplace.
the class BanConverterTest method testViables.
@Test
public void testViables() throws JSONConverterException {
ConstraintsConverter conv = new ConstraintsConverter();
conv.register(new BanConverter());
Model mo = new DefaultModel();
Ban d = new Ban(mo.newVM(), Arrays.asList(mo.newNode(), mo.newNode()));
Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(d)), d);
System.out.println(conv.toJSON(d));
}
use of org.btrplace.model.constraint.Ban in project scheduler by btrplace.
the class CNoDelayTest method testOk2.
@Test
public void testOk2() 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("cpu", 4, 1);
resources.setCapacity(n2, 3);
resources.setConsumption(vm1, 4);
Mapping map = model.getMapping().on(n1, n2, n3).run(n1, vm1).run(n2, vm2).run(n3, vm3).run(n3, vm4);
MappingUtils.fill(map, model.getMapping());
model.attach(resources);
Ban b = new Ban(vm1, Collections.singleton(n1));
NoDelay nd = new NoDelay(vm4);
// 1 solution (priority to vm4): vm4 to n2 ; vm3 to n2 ; vm1 to n3
List<SatConstraint> constraints = new ArrayList<>();
constraints.add(nd);
constraints.add(b);
ChocoScheduler cra = new DefaultChocoScheduler();
cra.getMapper().mapConstraint(MaxOnline.class, CMaxOnline.class);
ReconfigurationPlan plan = cra.solve(model, constraints);
Assert.assertNotNull(plan);
Assert.assertTrue(nd.isSatisfied(plan));
}
use of org.btrplace.model.constraint.Ban in project scheduler by btrplace.
the class BanBuilderTest method testGoodSignatures.
@Test(dataProvider = "goodBans")
public void testGoodSignatures(String str, int nbVMs, int nbNodes, 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(), nbVMs);
Set<VM> vms = new HashSet<>();
for (SatConstraint s : cstrs) {
Assert.assertTrue(s instanceof Ban);
Assert.assertEquals(s.getInvolvedVMs().size(), 1);
Assert.assertTrue(vms.addAll(s.getInvolvedVMs()));
Assert.assertEquals(s.getInvolvedNodes().size(), nbNodes);
Assert.assertEquals(s.isContinuous(), c);
}
}
use of org.btrplace.model.constraint.Ban in project scheduler by btrplace.
the class BanSplitter method split.
@Override
public boolean split(Ban cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
final SplittableElementSet<Node> nodeIndex = SplittableElementSet.newNodeIndex(cstr.getInvolvedNodes(), nodePosition);
VM v = cstr.getInvolvedVMs().iterator().next();
int p = vmsPosition.get(v.id());
return partitions.get(p).getSatConstraints().add(new Ban(v, nodeIndex.getSubSet(p)));
}
Aggregations