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()));
}
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);
}
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);
}
}
}
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;
}
Aggregations