use of org.btrplace.model.constraint.MinMTTR in project scheduler by btrplace.
the class CSplitTest method testGetMisplaced.
@Test
public void testGetMisplaced() {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
VM vm6 = mo.newVM();
VM vm7 = mo.newVM();
VM vm8 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Node n4 = mo.newNode();
Node n5 = mo.newNode();
Mapping map = mo.getMapping().on(n1, n2, n3, n4, n5).run(n1, vm1, vm2).run(n2, vm3).run(n3, vm4, vm5).run(n4, vm6).run(n5, vm7, vm8);
Collection<VM> g1 = Arrays.asList(vm1, vm2);
Collection<VM> g2 = new HashSet<>(Arrays.asList(vm3, vm4, vm5));
Collection<VM> g3 = new HashSet<>(Arrays.asList(vm6, vm7));
Collection<Collection<VM>> grps = Arrays.asList(g1, g2, g3);
Split s = new Split(grps);
CSplit cs = new CSplit(s);
Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR());
Assert.assertTrue(cs.getMisPlacedVMs(i).isEmpty());
map.addRunningVM(vm5, n1);
Set<VM> bad = cs.getMisPlacedVMs(i);
Assert.assertEquals(bad.size(), 3);
Assert.assertTrue(bad.contains(vm1) && bad.contains(vm2) && bad.contains(vm5));
map.addRunningVM(vm6, n3);
bad = cs.getMisPlacedVMs(i);
Assert.assertTrue(bad.contains(vm4) && bad.contains(vm5) && bad.contains(vm6));
}
use of org.btrplace.model.constraint.MinMTTR in project scheduler by btrplace.
the class IssuesTest method testIssue86.
@Test
public void testIssue86() throws Exception {
Model mo = new DefaultModel();
mo.getMapping().addReadyVM(mo.newVM());
mo.getMapping().addReadyVM(mo.newVM());
mo.getMapping().addReadyVM(mo.newVM());
mo.getMapping().addOnlineNode(mo.newNode());
mo.getMapping().addOnlineNode(mo.newNode());
mo.getMapping().addOnlineNode(mo.newNode());
List<SatConstraint> cstrs = mo.getMapping().getAllVMs().stream().map(Running::new).collect(Collectors.toList());
cstrs.add(new Spread(mo.getMapping().getAllVMs(), false));
cstrs.addAll(mo.getMapping().getOnlineNodes().stream().map(n -> new RunningCapacity(n, 1)).collect(Collectors.toList()));
Instance i = new Instance(mo, cstrs, new MinMTTR());
ChocoScheduler s = new DefaultChocoScheduler();
s.doOptimize(false);
s.doRepair(false);
ReconfigurationPlan p = s.solve(i.getModel(), i.getSatConstraints(), i.getOptConstraint());
Assert.assertNotNull(p);
Assert.assertEquals(3, p.getActions().size());
s.doRepair(true);
p = s.solve(i.getModel(), i.getSatConstraints(), i.getOptConstraint());
Assert.assertNotNull(p);
Assert.assertEquals(3, p.getActions().size());
}
use of org.btrplace.model.constraint.MinMTTR in project scheduler by btrplace.
the class CResourceCapacityTest method testGetMisplaced.
@Test
public void testGetMisplaced() {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Mapping m = mo.getMapping().on(n1, n2, n3).run(n1, vm1, vm2, vm3).run(n2, vm4).ready(vm5);
ShareableResource rc = new ShareableResource("cpu", 5, 5);
rc.setConsumption(vm1, 2);
rc.setConsumption(vm2, 3);
rc.setConsumption(vm3, 3);
rc.setConsumption(vm4, 1);
rc.setConsumption(vm5, 5);
mo.attach(rc);
ResourceCapacity c = new ResourceCapacity(m.getAllNodes(), "cpu", 10);
CResourceCapacity cc = new CResourceCapacity(c);
Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR());
Assert.assertTrue(cc.getMisPlacedVMs(i).isEmpty());
m.addRunningVM(vm5, n3);
Assert.assertEquals(cc.getMisPlacedVMs(i), m.getAllVMs());
}
use of org.btrplace.model.constraint.MinMTTR in project scheduler by btrplace.
the class CResourceCapacityTest method testCapacityEstimation.
/**
* Test how CResourceCapacity notifies the view about the future capacity.
*/
@Test
public void testCapacityEstimation() {
final Model mo = new DefaultModel();
final Node n0 = mo.newNode();
final Node n1 = mo.newNode();
final VM vm = mo.newVM();
final ShareableResource cpu = new ShareableResource("cpu");
mo.attach(cpu);
cpu.setCapacity(n0, 5).setCapacity(n1, 7);
cpu.setConsumption(vm, 3);
mo.getMapping().on(n0, n1).ready(vm);
final List<SatConstraint> cstrs = new ArrayList<>();
cstrs.add(new Running(vm));
final Instance i = new Instance(mo, cstrs, new MinMTTR());
// Because of the worst-fit approach, the VM will go on n1 which has the
// highest capacity.
final ChocoScheduler sched = new DefaultChocoScheduler();
ReconfigurationPlan res = sched.solve(i);
Assert.assertEquals(n1, res.getResult().getMapping().getVMLocation(vm));
// With a ResourceCapacity, we restrict n1 so that now n0 is the node
// that will have the highest capacity. So the wort-fit approach inside
// MinMTTR() should pick n0.
i.getSatConstraints().add(new ResourceCapacity(n1, "cpu", 4));
res = sched.solve(i);
Assert.assertEquals(n0, res.getResult().getMapping().getVMLocation(vm));
}
use of org.btrplace.model.constraint.MinMTTR in project scheduler by btrplace.
the class InstanceTest method testEqualsAndHashcode.
@Test
public void testEqualsAndHashcode() {
Model mo = new DefaultModel();
List<Node> ns = Util.newNodes(mo, 10);
List<VM> vms = Util.newVMs(mo, 10);
Mapping ma = mo.getMapping();
ma.addOnlineNode(ns.get(0));
ma.addOfflineNode(ns.get(0));
ma.addReadyVM(vms.get(0));
List<SatConstraint> cstrs = new ArrayList<>(Online.newOnline(ma.getAllNodes()));
cstrs.add(new Running(vms.get(0)));
Instance i = new Instance(mo, cstrs, new MinMTTR());
Instance i2 = new Instance(mo.copy(), new ArrayList<>(cstrs), new MinMTTR());
Assert.assertEquals(i, i2);
Assert.assertEquals(i, i);
Assert.assertNotEquals(i, null);
Assert.assertNotEquals(ma, i);
Assert.assertEquals(i.hashCode(), i2.hashCode());
i2.getModel().getMapping().addReadyVM(vms.get(2));
Assert.assertNotEquals(i, i2);
}
Aggregations