Search in sources :

Example 1 with VMTransitionBuilder

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);
        }
    }
}
Also used : VM(org.btrplace.model.VM) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Mapping(org.btrplace.model.Mapping) VMTransitionBuilder(org.btrplace.scheduler.choco.transition.VMTransitionBuilder) VMState(org.btrplace.model.VMState)

Example 2 with VMTransitionBuilder

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))));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Running(org.btrplace.model.constraint.Running) VMTransitionBuilder(org.btrplace.scheduler.choco.transition.VMTransitionBuilder) TransitionFactory(org.btrplace.scheduler.choco.transition.TransitionFactory) Test(org.testng.annotations.Test)

Aggregations

VM (org.btrplace.model.VM)2 VMTransitionBuilder (org.btrplace.scheduler.choco.transition.VMTransitionBuilder)2 DefaultModel (org.btrplace.model.DefaultModel)1 Mapping (org.btrplace.model.Mapping)1 Model (org.btrplace.model.Model)1 VMState (org.btrplace.model.VMState)1 Running (org.btrplace.model.constraint.Running)1 TransitionFactory (org.btrplace.scheduler.choco.transition.TransitionFactory)1 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)1 Test (org.testng.annotations.Test)1