use of org.btrplace.model.VM in project scheduler by btrplace.
the class ReadyBuilderTest method testGoodSignatures.
@Test(dataProvider = "goodReadys")
public void testGoodSignatures(String str, int nbVMs, boolean c) throws Exception {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
Set<SatConstraint> cstrs = b.build("namespace test; VM[1..10] : tiny;\n@N[1..20] : defaultNode;" + str).getConstraints();
Assert.assertEquals(cstrs.size(), nbVMs);
Set<VM> vms = new HashSet<>();
for (SatConstraint x : cstrs) {
Assert.assertTrue(x instanceof Ready);
Assert.assertTrue(vms.addAll(x.getInvolvedVMs()));
Assert.assertEquals(x.isContinuous(), c);
}
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class SleepingBuilderTest method testGoodSignatures.
@Test(dataProvider = "goodsleepings")
public void testGoodSignatures(String str, int nbVMs, boolean c) throws Exception {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
Set<SatConstraint> cstrs = b.build("namespace test; VM[1..10] : tiny;\n@N[1..20] : defaultNode;" + str).getConstraints();
Set<VM> vms = new HashSet<>();
Assert.assertEquals(cstrs.size(), nbVMs);
for (SatConstraint x : cstrs) {
Assert.assertTrue(x instanceof Sleeping);
Assert.assertTrue(vms.addAll(x.getInvolvedVMs()));
Assert.assertEquals(x.isContinuous(), c);
}
}
use of org.btrplace.model.VM 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.VM in project scheduler by btrplace.
the class CAmong method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
int nextGrp = -1;
int curGrp = -1;
List<Collection<Node>> groups = new ArrayList<>();
groups.addAll(cstr.getGroupsOfNodes());
Set<VM> running = new HashSet<>();
Mapping src = rp.getSourceModel().getMapping();
for (VM vm : cstr.getInvolvedVMs()) {
if (rp.getFutureRunningVMs().contains(vm)) {
// The VM will be running
running.add(vm);
IntVar vAssign = rp.getVMAction(vm).getDSlice().getHoster();
// If one of the VM is already placed, no need for the constraint, the group will be known
if (vAssign.isInstantiated()) {
// Get the group of nodes that match the selected node
int g = getGroup(rp.getNode(vAssign.getValue()), groups);
if (errorReported(rp, vm, nextGrp, g)) {
return false;
}
nextGrp = g;
}
}
if (cstr.isContinuous() && src.isRunning(vm)) {
// The VM is already running, so we get its current group
Node curNode = src.getVMLocation(vm);
int g = getGroup(curNode, groups);
if (errorReported(rp, vm, curGrp, g)) {
return false;
}
curGrp = g;
}
}
if (cstr.isContinuous() && curGrp != -1) {
return restrictGroup(ps, rp, running, groups, curGrp);
} else if (groups.size() == 1) {
return restrictGroup(ps, rp, running, groups, 0);
}
return restrictGroup(ps, rp, running, groups, nextGrp);
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class CGather method continuousColocation.
/*
* Check for the already running VMs and force co-location if any.
*/
private boolean continuousColocation(ReconfigurationProblem rp, List<Slice> dSlices) {
Set<VM> alreadyRunning = new HashSet<>();
Mapping map = rp.getSourceModel().getMapping();
Node loc = null;
for (VM vm : cstr.getInvolvedVMs()) {
if (map.isRunning(vm)) {
alreadyRunning.add(vm);
Node node = map.getVMLocation(vm);
if (loc == null) {
loc = node;
} else if (!loc.equals(node)) {
rp.getLogger().error("Some VMs in '{}' are already running but not co-located", cstr.getInvolvedVMs());
return false;
}
}
}
if (loc != null) {
if (cstr.getInvolvedVMs().size() == 1 && dSlices.size() == 1) {
// The VM may migrate, we don't care as it is alone.
return true;
}
return placeDSlices(rp, dSlices, rp.getNode(loc));
}
return true;
}
Aggregations