use of org.btrplace.model.constraint.Ban in project scheduler by btrplace.
the class BanSplitterTest method simpleTest.
@Test
public void simpleTest() {
BanSplitter splitter = new BanSplitter();
List<Instance> instances = new ArrayList<>();
Model origin = new DefaultModel();
Node n1 = origin.newNode();
Node n2 = origin.newNode();
VM vm1 = origin.newVM();
VM vm2 = origin.newVM();
VM vm3 = origin.newVM();
VM vm4 = origin.newVM();
/**
* READY: vm1
* n1 vm2
* n2 (vm3) vm4
*/
origin.getMapping().addOnlineNode(n1);
origin.getMapping().addReadyVM(vm1);
origin.getMapping().addRunningVM(vm2, n1);
origin.getMapping().addOnlineNode(n2);
origin.getMapping().addSleepingVM(vm3, n2);
origin.getMapping().addRunningVM(vm4, n2);
Model m0 = new DefaultModel();
m0.newNode(n1.id());
m0.newVM(vm1.id());
m0.newVM(vm2.id());
m0.getMapping().addOnlineNode(n1);
m0.getMapping().addReadyVM(vm1);
m0.getMapping().addRunningVM(vm2, n1);
Model m1 = new DefaultModel();
m1.newNode(n2.id());
m1.newVM(vm3.id());
m1.newVM(vm4.id());
m1.getMapping().addOnlineNode(n2);
m1.getMapping().addSleepingVM(vm3, n2);
m1.getMapping().addRunningVM(vm4, n2);
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 vmIndex = Instances.makeVMIndex(instances);
TIntIntHashMap nodeIndex = Instances.makeNodeIndex(instances);
// Only VMs & nodes in m0
Ban single = new Ban(vm1, m0.getMapping().getAllNodes());
Assert.assertTrue(splitter.split(single, null, instances, vmIndex, nodeIndex));
Assert.assertTrue(instances.get(0).getSatConstraints().contains(single));
Assert.assertFalse(instances.get(1).getSatConstraints().contains(single));
// All the VMs, nodes in m1.
Ban among = new Ban(vm3, m1.getMapping().getAllNodes());
Assert.assertTrue(splitter.split(among, null, instances, vmIndex, nodeIndex));
Assert.assertTrue(instances.get(0).getSatConstraints().contains(new Ban(vm1, m0.getMapping().getAllNodes())));
Assert.assertTrue(instances.get(1).getSatConstraints().contains(new Ban(vm3, m1.getMapping().getAllNodes())));
}
use of org.btrplace.model.constraint.Ban in project scheduler by btrplace.
the class CNoDelayTest method testOk1.
@Test
public void testOk1() 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(vm3);
// 1 solution (priority to vm3): vm3 to n2 ; vm4 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 CNoDelayTest method testKo.
@Test
public void testKo() 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(vm1);
// No solution: unable to migrate vm1 at t=0
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.assertNull(plan);
}
Aggregations