use of org.btrplace.scheduler.choco.transition.VMTransitionBuilder 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.VMTransitionBuilder in project scheduler by btrplace.
the class DefaultChocoSchedulerTest method testTransitionFactoryCustomisation.
/**
* Remove the ready->running transition so the solving process will fail
*
* @throws org.btrplace.scheduler.SchedulerException
*/
@Test
public void testTransitionFactoryCustomisation() throws SchedulerException {
ChocoScheduler cra = new DefaultChocoScheduler();
TransitionFactory tf = cra.getTransitionFactory();
VMTransitionBuilder b = tf.getBuilder(VMState.READY, VMState.RUNNING);
Assert.assertTrue(tf.remove(b));
Model mo = new DefaultModel();
VM v = mo.newVM();
mo.getMapping().addReadyVM(v);
Assert.assertNull(cra.solve(mo, Collections.singletonList(new Running(v))));
}
Aggregations