use of org.btrplace.plan.event.MigrateVM in project scheduler by btrplace.
the class ReconfigurationPlanCheckerTest method testSequencing.
@Test(dependsOnMethods = { "tesAddandRemove" })
public void testSequencing() throws SatConstraintViolationException {
Model mo = new DefaultModel();
List<Node> ns = Util.newNodes(mo, 10);
List<VM> vms = Util.newVMs(mo, 10);
Mapping m = mo.getMapping();
m.addOnlineNode(ns.get(0));
m.addOnlineNode(ns.get(1));
m.addOfflineNode(ns.get(3));
m.addReadyVM(vms.get(1));
m.addRunningVM(vms.get(0), ns.get(0));
ReconfigurationPlan p = new DefaultReconfigurationPlan(mo);
SatConstraintChecker<?> chk = mock(SatConstraintChecker.class);
MigrateVM m1 = new MigrateVM(vms.get(0), ns.get(0), ns.get(1), 0, 3);
BootVM b1 = new BootVM(vms.get(1), ns.get(0), 1, 5);
BootNode bn = new BootNode(ns.get(3), 3, 6);
p.add(m1);
p.add(b1);
p.add(bn);
Model res = p.getResult();
Assert.assertNotNull(res);
ReconfigurationPlanChecker rc = new ReconfigurationPlanChecker();
rc.addChecker(chk);
InOrder order = inOrder(chk);
rc.check(p);
order.verify(chk).startsWith(mo);
order.verify(chk).start(m1);
order.verify(chk).start(b1);
order.verify(chk).end(m1);
order.verify(chk).start(bn);
order.verify(chk).end(b1);
order.verify(chk).end(bn);
order.verify(chk).endsWith(res);
}
use of org.btrplace.plan.event.MigrateVM 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.MigrateVM 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;
}
use of org.btrplace.plan.event.MigrateVM in project scheduler by btrplace.
the class ReconfigurationPlanFuzzer method setDestinationState.
private void setDestinationState(ReconfigurationPlan p, VM v) {
Mapping map = p.getOrigin().getMapping();
Node host = map.getVMLocation(v);
int n = rnd.nextInt(dstReadyVMs + dstRunningVMs + dstSleepingVMs);
int[] bounds = schedule();
int duration = bounds[1] - bounds[0];
if (n < dstReadyVMs) {
if (host != null) {
p.add(new ShutdownVM(v, host, bounds[0], bounds[1]));
p.getOrigin().getAttributes().put(v, "shutdown", duration);
}
} else if (n < dstReadyVMs + dstRunningVMs) {
if (host == null) {
p.add(new BootVM(v, pick(map.getAllNodes()), bounds[0], bounds[1]));
p.getOrigin().getAttributes().put(v, "boot", duration);
} else {
// was running -> migrate
if (map.isRunning(v)) {
Node dst = pick(map.getAllNodes());
if (!host.equals(dst)) {
p.add(new MigrateVM(v, host, dst, bounds[0], bounds[1]));
p.getOrigin().getAttributes().put(v, "migrate", duration);
}
} else {
// was sleeping -> resume
p.add(new ResumeVM(v, host, pick(map.getAllNodes()), bounds[0], bounds[1]));
p.getOrigin().getAttributes().put(v, "resume", duration);
}
}
} else {
// moving to sleeping state
if (map.isRunning(v)) {
p.add(new SuspendVM(v, host, host, bounds[0], bounds[1]));
p.getOrigin().getAttributes().put(v, "sleeping", duration);
}
}
}
use of org.btrplace.plan.event.MigrateVM in project scheduler by btrplace.
the class RelocatableVMTest method testForcedToMove.
@Test
public void testForcedToMove() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
final VM vm1 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addRunningVM(vm1, n1);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(MigrateVM.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), map.getAllVMs(), Collections.emptySet(), Collections.emptySet()).setParams(ps).build();
rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
rp.getNodeActions().get(1).getState().instantiateTo(1, Cause.Null);
RelocatableVM am = (RelocatableVM) rp.getVMAction(vm1);
Assert.assertTrue(am.getRelocationMethod().isInstantiatedTo(0));
Assert.assertEquals(vm1, am.getVM());
Assert.assertEquals(2, am.getDuration().getDomainSize());
Assert.assertEquals(0, am.getDuration().getLB());
Assert.assertEquals(5, am.getDuration().getUB());
Assert.assertFalse(am.getStart().isInstantiated());
Assert.assertFalse(am.getEnd().isInstantiated());
Assert.assertNotNull(am.getCSlice());
Assert.assertTrue(am.getCSlice().getHoster().isInstantiatedTo(rp.getNode(n1)));
Assert.assertTrue(am.getState().isInstantiatedTo(1));
Assert.assertNotNull(am.getDSlice());
Assert.assertFalse(am.getDSlice().getHoster().isInstantiated());
// No VMs on n1, discrete mode
rp.getModel().post(rp.getModel().arithm(rp.getNbRunningVMs().get(rp.getNode(n1)), "=", 0));
new CMinMTTR().inject(new DefaultParameters(), rp);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
Model m = p.getResult();
Assert.assertEquals(n2, m.getMapping().getVMLocation(vm1));
MigrateVM a = (MigrateVM) p.getActions().iterator().next();
Assert.assertEquals(0, a.getStart());
Assert.assertEquals(5, a.getEnd());
Assert.assertEquals(n1, a.getSourceNode());
Assert.assertEquals(n2, a.getDestinationNode());
Assert.assertEquals(vm1, a.getVM());
}
Aggregations