Search in sources :

Example 1 with VMState

use of org.btrplace.model.VMState in project scheduler by btrplace.

the class TransitionFactoryTest method testRemove.

@Test
public void testRemove() {
    TransitionFactory amf = TransitionFactory.newBundle();
    MockVMBuilder vmb = new MockVMBuilder();
    amf.remove(vmb);
    for (VMState src : vmb.getSourceStates()) {
        Assert.assertNull(amf.getBuilder(src, vmb.getDestinationState()));
    }
    MockNodeBuilder nb = new MockNodeBuilder();
    amf.remove(nb);
    Assert.assertNull(amf.getBuilder(nb.getSourceState()));
}
Also used : VMState(org.btrplace.model.VMState) Test(org.testng.annotations.Test)

Example 2 with VMState

use of org.btrplace.model.VMState in project scheduler by btrplace.

the class TransitionFactoryTest method testAdd.

@Test
public void testAdd() {
    TransitionFactory amf = TransitionFactory.newBundle();
    MockVMBuilder vmb = new MockVMBuilder();
    amf.add(vmb);
    for (VMState src : vmb.getSourceStates()) {
        Assert.assertEquals(amf.getBuilder(src, vmb.getDestinationState()), vmb);
    }
    MockNodeBuilder nb = new MockNodeBuilder();
    amf.add(nb);
    Assert.assertEquals(amf.getBuilder(nb.getSourceState()), nb);
}
Also used : VMState(org.btrplace.model.VMState) Test(org.testng.annotations.Test)

Example 3 with VMState

use of org.btrplace.model.VMState 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 4 with VMState

use of org.btrplace.model.VMState in project scheduler by btrplace.

the class DefaultReconfigurationProblem method distinctVMStates.

/**
 * Check if every VM has a single destination state
 *
 * @return {@code true} if states are distinct
 */
private boolean distinctVMStates() {
    boolean ok = vms.size() == running.size() + sleeping.size() + ready.size() + killed.size();
    // It is sure there is no solution as a VM cannot have multiple destination state
    Map<VM, VMState> states = new HashMap<>();
    for (VM v : running) {
        states.put(v, VMState.RUNNING);
    }
    for (VM v : ready) {
        VMState prev = states.put(v, VMState.READY);
        if (prev != null) {
            getLogger().debug("multiple destination state for {}: {} and {}", v, prev, VMState.READY);
        }
    }
    for (VM v : sleeping) {
        VMState prev = states.put(v, VMState.SLEEPING);
        if (prev != null) {
            getLogger().debug("multiple destination state for {}: {} and {}", v, prev, VMState.SLEEPING);
        }
    }
    for (VM v : killed) {
        VMState prev = states.put(v, VMState.KILLED);
        if (prev != null) {
            getLogger().debug("multiple destination state for {}: {} and {}", v, prev, VMState.KILLED);
        }
    }
    return ok;
}
Also used : TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) HashMap(java.util.HashMap) VM(org.btrplace.model.VM) VMState(org.btrplace.model.VMState)

Aggregations

VMState (org.btrplace.model.VMState)4 VM (org.btrplace.model.VM)2 Test (org.testng.annotations.Test)2 TObjectIntHashMap (gnu.trove.map.hash.TObjectIntHashMap)1 HashMap (java.util.HashMap)1 Mapping (org.btrplace.model.Mapping)1 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)1 VMTransitionBuilder (org.btrplace.scheduler.choco.transition.VMTransitionBuilder)1