use of org.btrplace.plan.event.Allocate in project scheduler by btrplace.
the class COverbookTest method testWithIncrease.
/**
* Test with a root VM that has increasing need and another one that prevent it
* to get the resources immediately
*/
@Test
public void testWithIncrease() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
Node n1 = mo.newNode();
Mapping map = mo.getMapping().on(n1).run(n1, vm1, vm2);
org.btrplace.model.view.ShareableResource rc = new ShareableResource("foo");
rc.setCapacity(n1, 5);
rc.setConsumption(vm1, 3);
rc.setConsumption(vm2, 2);
mo.attach(rc);
ChocoScheduler cra = new DefaultChocoScheduler();
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Online.newOnline(map.getAllNodes()));
Overbook o = new Overbook(n1, "foo", 1);
o.setContinuous(true);
cstrs.add(o);
cstrs.add(new Ready(vm2));
cstrs.add(new Preserve(vm1, "foo", 5));
ReconfigurationPlan p = cra.solve(mo, cstrs);
Assert.assertNotNull(p);
Assert.assertEquals(p.getSize(), 2);
Action al = p.getActions().stream().filter(s -> s instanceof Allocate).findAny().get();
Action sh = p.getActions().stream().filter(s -> s instanceof ShutdownVM).findAny().get();
Assert.assertTrue(sh.getEnd() <= al.getStart());
}
use of org.btrplace.plan.event.Allocate 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.plan.event.Allocate in project scheduler by btrplace.
the class TimeBasedPlanApplierTest method makePlan.
private static ReconfigurationPlan makePlan(Model mo, List<Node> ns, List<VM> vms) {
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);
return plan;
}
use of org.btrplace.plan.event.Allocate in project scheduler by btrplace.
the class CShareableResource method insertActions.
@Override
public boolean insertActions(ReconfigurationProblem r, Solution s, ReconfigurationPlan p) {
Mapping srcMapping = r.getSourceModel().getMapping();
// Encache the VM -> Action to ease the event injection.
Map<VM, Action> actions = new HashMap<>();
p.getActions().stream().filter(RunningVMPlacement.class::isInstance).map(a -> (RunningVMPlacement) a).forEach(a -> actions.put(destVM(a.getVM()), (Action) a));
for (VM vm : r.getFutureRunningVMs()) {
Slice dSlice = r.getVMAction(vm).getDSlice();
Node destNode = r.getNode(s.getIntVal(dSlice.getHoster()));
if (srcMapping.isRunning(vm) && destNode.equals(srcMapping.getVMLocation(vm))) {
// Was running and stay on the same node
// Check if the VM has been cloned
// TODO: might be too late depending on the symmetry breaking on the actions schedule
insertAllocateAction(p, vm, destNode, s.getIntVal(dSlice.getStart()));
} else {
VM dVM = destVM(vm);
Action a = actions.get(dVM);
if (a instanceof MigrateVM) {
// For a migrated VM, we allocate once the migration over
insertAllocateEvent(a, Action.Hook.POST, dVM);
} else {
// Resume or Boot VM
// As the VM was not running, we pre-allocate
insertAllocateEvent(a, Action.Hook.PRE, dVM);
}
}
}
return true;
}
Aggregations