use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.
the class OverbookTest method testDiscreteIsSatisfied.
@Test
public void testDiscreteIsSatisfied() {
Model mo = new DefaultModel();
Node n0 = mo.newNode();
Node n1 = mo.newNode();
List<VM> vms = Util.newVMs(mo, 10);
Model i = new DefaultModel();
Mapping cfg = i.getMapping();
cfg.addOnlineNode(n0);
cfg.addOnlineNode(n1);
ShareableResource rc = new ShareableResource("cpu");
rc.setCapacity(n0, 1);
rc.setCapacity(n1, 4);
rc.setConsumption(vms.get(0), 2);
rc.setConsumption(vms.get(1), 2);
rc.setConsumption(vms.get(2), 4);
cfg.addRunningVM(vms.get(0), n0);
cfg.addRunningVM(vms.get(1), n1);
cfg.addRunningVM(vms.get(2), n1);
cfg.addRunningVM(vms.get(3), n1);
i.attach(rc);
Overbook o = new Overbook(n0, "cpu", 2);
Assert.assertEquals(o.isSatisfied(i), true);
rc.setConsumption(vms.get(0), 4);
Assert.assertEquals(o.isSatisfied(i), false);
cfg.addRunningVM(vms.get(0), n1);
Assert.assertEquals(new Overbook(n1, "cpu", 2).isSatisfied(i), false);
Overbook o2 = new Overbook(n0, "mem", 2);
Assert.assertEquals(o2.isSatisfied(i), false);
}
use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.
the class PreserveTest method testIsSatisfied.
@Test(dependsOnMethods = { "testInstantiation" })
public void testIsSatisfied() {
Model m = new DefaultModel();
List<VM> vms = Util.newVMs(m, 5);
List<Node> ns = Util.newNodes(m, 5);
ShareableResource rc = new ShareableResource("cpu", 3, 3);
Mapping map = m.getMapping();
map.addOnlineNode(ns.get(0));
map.addOnlineNode(ns.get(1));
map.addRunningVM(vms.get(0), ns.get(0));
map.addSleepingVM(vms.get(1), ns.get(0));
map.addRunningVM(vms.get(2), ns.get(0));
m.attach(rc);
Preserve p = new Preserve(vms.get(0), "cpu", 3);
rc.setConsumption(vms.get(0), 3);
// Not running so we don't care
rc.setConsumption(vms.get(1), 1);
rc.setConsumption(vms.get(2), 3);
Assert.assertEquals(true, p.isSatisfied(m));
// Set to 3 by default
rc.unset(vms.get(2));
Assert.assertEquals(true, p.isSatisfied(m));
Assert.assertEquals(false, new Preserve(vms.get(2), "mem", 3).isSatisfied(m));
ReconfigurationPlan plan = new DefaultReconfigurationPlan(m);
rc.setConsumption(vms.get(1), 1);
Assert.assertFalse(new Preserve(vms.get(2), "cpu", 4).isSatisfied(plan));
plan.add(new Allocate(vms.get(2), ns.get(0), "cpu", 7, 5, 7));
Assert.assertTrue(p.isSatisfied(plan));
rc.setConsumption(vms.get(0), 1);
AllocateEvent e = new AllocateEvent(vms.get(0), "cpu", 4);
Assert.assertFalse(p.isSatisfied(plan));
MigrateVM mig = new MigrateVM(vms.get(0), ns.get(0), ns.get(1), 0, 3);
mig.addEvent(Action.Hook.POST, e);
plan.add(mig);
Assert.assertTrue(p.isSatisfied(plan));
}
use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.
the class PreserveTest method testPreserves.
@Test
public void testPreserves() {
Model mo = new DefaultModel();
List<VM> vms = Util.newVMs(mo, 5);
List<Node> ns = Util.newNodes(mo, 5);
List<Fence> c = Fence.newFence(vms, ns);
ShareableResource rc = new ShareableResource("foo", 0, 0);
mo.attach(rc);
Assert.assertEquals(vms.size(), c.size());
c.stream().forEach((q) -> {
Assert.assertTrue(vms.containsAll(q.getInvolvedVMs()));
Assert.assertEquals(ns, q.getInvolvedNodes());
Assert.assertFalse(q.isContinuous());
});
}
use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.
the class ResourceCapacityTest method testDiscreteIsSatisfied.
@Test
public void testDiscreteIsSatisfied() {
Model mo = new DefaultModel();
List<Node> ns = Util.newNodes(mo, 10);
List<VM> vms = Util.newVMs(mo, 10);
Mapping map = mo.getMapping();
map.addOnlineNode(ns.get(0));
map.addOnlineNode(ns.get(1));
map.addOnlineNode(ns.get(2));
map.addRunningVM(vms.get(0), ns.get(0));
map.addRunningVM(vms.get(1), ns.get(0));
map.addRunningVM(vms.get(2), ns.get(1));
map.addRunningVM(vms.get(3), ns.get(2));
ShareableResource rc = new ShareableResource("foo", 1, 1);
rc.setConsumption(vms.get(1), 2);
mo.attach(rc);
Set<Node> nodes = new HashSet<>(Arrays.asList(ns.get(0), ns.get(1)));
ResourceCapacity cc = new ResourceCapacity(nodes, "foo", 4);
Assert.assertEquals(cc.isSatisfied(mo), true);
Assert.assertEquals(new ResourceCapacity(nodes, "bar", 100).isSatisfied(mo), false);
rc.setConsumption(vms.get(0), 3);
Assert.assertEquals(cc.isSatisfied(mo), false);
map.addSleepingVM(vms.get(1), ns.get(0));
map.addSleepingVM(vms.get(2), ns.get(0));
Assert.assertEquals(cc.isSatisfied(mo), true);
}
use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.
the class DefaultReconfigurationPlanMonitorTest method testComplex.
@Test
public void testComplex() {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
map.addOnlineNode(ns.get(0));
map.addOnlineNode(ns.get(1));
map.addOnlineNode(ns.get(2));
map.addOfflineNode(ns.get(3));
map.addRunningVM(vms.get(0), ns.get(2));
map.addRunningVM(vms.get(1), ns.get(0));
map.addRunningVM(vms.get(2), ns.get(1));
map.addRunningVM(vms.get(3), ns.get(1));
BootNode bN4 = new BootNode(ns.get(3), 3, 5);
MigrateVM mVM1 = new MigrateVM(vms.get(0), ns.get(2), ns.get(3), 6, 7);
Allocate aVM3 = new Allocate(vms.get(2), ns.get(1), "cpu", 7, 8, 9);
MigrateVM mVM2 = new MigrateVM(vms.get(1), ns.get(0), ns.get(1), 1, 3);
MigrateVM mVM4 = new MigrateVM(vms.get(3), ns.get(1), ns.get(2), 1, 7);
ShutdownNode sN1 = new ShutdownNode(ns.get(0), 5, 7);
ShareableResource rc = new ShareableResource("cpu");
rc.setConsumption(vms.get(2), 3);
mo.attach(rc);
ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
plan.add(bN4);
plan.add(mVM1);
plan.add(aVM3);
plan.add(mVM2);
plan.add(mVM4);
plan.add(sN1);
Assert.assertTrue(plan.isApplyable());
}
Aggregations