use of org.btrplace.plan.event.Allocate in project scheduler by btrplace.
the class AllowAllConstraintCheckerTest method testAcceptance.
@Test
public void testAcceptance() {
SatConstraint cstr = mock(SatConstraint.class);
AllowAllConstraintChecker<?> c = mock(AllowAllConstraintChecker.class, CALLS_REAL_METHODS);
Model mo = new DefaultModel();
List<VM> vms = Util.newVMs(mo, 10);
List<Node> ns = Util.newNodes(mo, 10);
when(cstr.getInvolvedNodes()).thenReturn(ns);
when(cstr.getInvolvedVMs()).thenReturn(vms);
MigrateVM m = new MigrateVM(vms.get(0), ns.get(0), ns.get(1), 0, 3);
Assert.assertTrue(c.start(m));
verify(c).startRunningVMPlacement(m);
c.end(m);
verify(c).endRunningVMPlacement(m);
BootVM b = new BootVM(vms.get(0), ns.get(0), 0, 3);
Assert.assertTrue(c.start(b));
verify(c).startRunningVMPlacement(b);
c.end(b);
verify(c).endRunningVMPlacement(b);
ResumeVM r = new ResumeVM(vms.get(0), ns.get(0), ns.get(1), 0, 3);
Assert.assertTrue(c.start(r));
verify(c).startRunningVMPlacement(r);
c.end(r);
verify(c).endRunningVMPlacement(r);
// do not use the mock as the constructor is important
// while earlier, the mock was needed for the verify()
c = new AllowAllConstraintChecker<>(cstr);
Set<VM> allVMs = new HashSet<>();
for (Node n : mo.getMapping().getOnlineNodes()) {
allVMs.addAll(mo.getMapping().getRunningVMs(n));
allVMs.addAll(mo.getMapping().getSleepingVMs(n));
}
allVMs.addAll(mo.getMapping().getReadyVMs());
c.track(allVMs);
SuspendVM s = new SuspendVM(vms.get(0), ns.get(0), ns.get(1), 0, 3);
Assert.assertTrue(c.start(s));
ShutdownVM s2 = new ShutdownVM(vms.get(0), ns.get(0), 0, 3);
Assert.assertTrue(c.start(s2));
KillVM k = new KillVM(vms.get(0), ns.get(0), 0, 3);
Assert.assertTrue(c.start(k));
ForgeVM f = new ForgeVM(vms.get(0), 0, 3);
Assert.assertTrue(c.start(f));
BootNode bn = new BootNode(ns.get(0), 0, 3);
Assert.assertTrue(c.start(bn));
ShutdownNode sn = new ShutdownNode(ns.get(0), 0, 3);
Assert.assertTrue(c.start(sn));
SubstitutedVMEvent ss = new SubstitutedVMEvent(vms.get(9), vms.get(2));
Assert.assertTrue(c.consume(ss));
Allocate a = new Allocate(vms.get(0), ns.get(0), "cpu", 3, 4, 5);
Assert.assertTrue(c.start(a));
AllocateEvent ae = new AllocateEvent(vms.get(0), "cpu", 3);
Assert.assertTrue(c.consume(ae));
}
use of org.btrplace.plan.event.Allocate in project scheduler by btrplace.
the class OverbookTest method testContinuousIsSatisfied.
@Test
public void testContinuousIsSatisfied() {
Model mo = new DefaultModel();
List<VM> vms = Util.newVMs(mo, 10);
Node n0 = mo.newNode();
Node n1 = mo.newNode();
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(n1, "cpu", 2);
o.setContinuous(true);
ReconfigurationPlan p = new DefaultReconfigurationPlan(i);
Assert.assertEquals(o.isSatisfied(p), true);
p.add(new Allocate(vms.get(0), n0, "cpu", 1, 2, 5));
Assert.assertEquals(o.isSatisfied(p), true);
p.add(new Allocate(vms.get(1), n1, "cpu", 5, 2, 5));
Assert.assertEquals(o.isSatisfied(p), false);
p.add(new Allocate(vms.get(2), n1, "cpu", 2, 0, 1));
Assert.assertEquals(o.isSatisfied(p), true);
p.add(new Allocate(vms.get(3), n1, "cpu", 3, 4, 6));
Assert.assertEquals(o.isSatisfied(p), false);
p.add(new ShutdownVM(vms.get(2), n1, 2, 3));
Assert.assertEquals(o.isSatisfied(p), true);
}
use of org.btrplace.plan.event.Allocate in project scheduler by btrplace.
the class DependencyBasedPlanApplierTest method testApply.
@Test
public void testApply() {
Model mo = new DefaultModel();
List<VM> vms = Util.newVMs(mo, 10);
List<Node> ns = Util.newNodes(mo, 10);
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);
Model res = new DependencyBasedPlanApplier().apply(plan);
Assert.assertNotNull(res);
Mapping resMapping = res.getMapping();
Assert.assertTrue(resMapping.isOffline(ns.get(0)));
Assert.assertTrue(resMapping.isOnline(ns.get(3)));
rc = ShareableResource.get(res, "cpu");
Assert.assertEquals(rc.getConsumption(vms.get(2)), 7);
Assert.assertEquals(resMapping.getVMLocation(vms.get(0)), ns.get(3));
Assert.assertEquals(resMapping.getVMLocation(vms.get(1)), ns.get(1));
Assert.assertEquals(resMapping.getVMLocation(vms.get(3)), ns.get(2));
}
use of org.btrplace.plan.event.Allocate in project scheduler by btrplace.
the class CShareableResource method insertAllocateAction.
private boolean insertAllocateAction(ReconfigurationPlan p, VM vm, Node destNode, int st) {
String rcId = getResourceIdentifier();
int prev = rc.getConsumption(vm);
int now = getVMAllocation(rp.getVM(vm));
if (prev != now) {
Allocate a = new Allocate(vm, destNode, rcId, now, st, st);
return p.add(a);
}
return false;
}
use of org.btrplace.plan.event.Allocate in project scheduler by btrplace.
the class ReconfigurationPlanConverterTest method testConversion.
@Test
public void testConversion() throws JSONConverterException {
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 map = mo.getMapping();
map.addOnlineNode(n1);
map.addOfflineNode(n2);
map.addOnlineNode(n3);
map.addReadyVM(vm1);
map.addRunningVM(vm2, n1);
map.addRunningVM(vm3, n1);
map.addSleepingVM(vm4, n3);
map.addRunningVM(vm5, n3);
ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
plan.add(new MigrateVM(vm2, n1, n3, 0, 1));
plan.add(new BootVM(vm1, n3, 1, 2));
plan.add(new BootNode(n2, 2, 5));
plan.add(new Allocate(vm1, n3, "foo", 5, 3, 5));
ReconfigurationPlanConverter rcp = new ReconfigurationPlanConverter();
String j = rcp.toJSONString(plan);
ReconfigurationPlan p2 = rcp.fromJSON(j);
Assert.assertEquals(p2, plan);
}
Aggregations