use of org.btrplace.plan.event.RunningVMPlacement 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