use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testVMStaySleeping.
@Test
public void testVMStaySleeping() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
Node n1 = mo.newNode();
mo.getMapping().addOnlineNode(n1);
mo.getMapping().addSleepingVM(vm1, n1);
DefaultReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(new HashSet<>(), new HashSet<>(), Collections.singleton(vm1), new HashSet<>()).build();
VMTransition a = rp.getVMActions().get(0);
Assert.assertEquals(a, rp.getVMAction(vm1));
Assert.assertEquals(StayAwayVM.class, a.getClass());
}
use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class DefaultReconfigurationProblem method makeVMTransitions.
private void makeVMTransitions() {
Mapping map = model.getMapping();
vmActions = new ArrayList<>(vms.size());
for (VM vmId : vms) {
VMState curState = map.getState(vmId);
if (curState == null) {
curState = VMState.INIT;
}
VMState nextState;
if (running.contains(vmId)) {
nextState = VMState.RUNNING;
} else if (sleeping.contains(vmId)) {
nextState = VMState.SLEEPING;
} else if (ready.contains(vmId)) {
nextState = VMState.READY;
} else if (killed.contains(vmId)) {
nextState = VMState.KILLED;
} else {
// by default, maintain state
nextState = curState;
switch(nextState) {
case READY:
ready.add(vmId);
break;
case RUNNING:
running.add(vmId);
break;
case SLEEPING:
sleeping.add(vmId);
break;
default:
throw new LifeCycleViolationException(model, vmId, curState, nextState);
}
}
VMTransitionBuilder am = amFactory.getBuilder(curState, nextState);
if (am == null) {
throw new LifeCycleViolationException(model, vmId, curState, nextState);
}
VMTransition t = am.build(this, vmId);
vmActions.add(t);
if (t.isManaged()) {
manageable.add(vmId);
}
}
}
use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class DefaultReconfigurationProblem method addContinuousResourceCapacities.
private void addContinuousResourceCapacities() {
TIntArrayList cUse = new TIntArrayList();
List<IntVar> iUse = new ArrayList<>();
for (int j = 0; j < getVMs().size(); j++) {
VMTransition a = vmActions.get(j);
if (a.getDSlice() != null) {
iUse.add(csp.intVar(1));
}
if (a.getCSlice() != null) {
cUse.add(1);
}
}
ChocoView v = getView(Cumulatives.VIEW_ID);
if (v == null) {
throw SchedulerModelingException.missingView(model, Cumulatives.VIEW_ID);
}
((Cumulatives) v).addDim(getNbRunningVMs(), cUse.toArray(), iUse.toArray(new IntVar[iUse.size()]));
}
use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class CGather method getDSlices.
private List<Slice> getDSlices(ReconfigurationProblem rp) {
List<Slice> dSlices = new ArrayList<>();
for (VM vm : cstr.getInvolvedVMs()) {
VMTransition a = rp.getVMAction(vm);
Slice dSlice = a.getDSlice();
if (dSlice != null) {
dSlices.add(dSlice);
}
}
return dSlices;
}
use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class CLonely method continuousRestriction.
private static void continuousRestriction(ReconfigurationProblem rp, Collection<VM> vms, Set<VM> otherVMs) {
// Get the position of all the others c-slices and their associated end moment
TIntArrayList otherPos = new TIntArrayList();
TIntArrayList minePos = new TIntArrayList();
List<IntVar> otherEnds = new ArrayList<>();
List<IntVar> mineEnds = new ArrayList<>();
Mapping map = rp.getSourceModel().getMapping();
for (Node n : map.getOnlineNodes()) {
for (VM vm : map.getRunningVMs(n)) {
if (!vms.contains(vm)) {
otherPos.add(rp.getNode(map.getVMLocation(vm)));
VMTransition a = rp.getVMAction(vm);
otherEnds.add(a.getCSlice().getEnd());
} else {
minePos.add(rp.getNode(map.getVMLocation(vm)));
VMTransition a = rp.getVMAction(vm);
mineEnds.add(a.getCSlice().getEnd());
}
}
}
for (VM vm : vms) {
VMTransition a = rp.getVMAction(vm);
Precedences p = new Precedences(a.getDSlice().getHoster(), a.getDSlice().getStart(), otherPos.toArray(), otherEnds.toArray(new IntVar[otherEnds.size()]));
rp.getModel().post(p);
}
// TODO: The following reveals a model problem. Too many constraints!!
for (VM vm : otherVMs) {
VMTransition a = rp.getVMAction(vm);
Precedences p = new Precedences(a.getDSlice().getHoster(), a.getDSlice().getStart(), minePos.toArray(), mineEnds.toArray(new IntVar[mineEnds.size()]));
rp.getModel().post(p);
}
}
Aggregations