use of org.btrplace.model.Node in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testManageableVMs.
@Test
public void testManageableVMs() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
VM vm6 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Mapping map = mo.getMapping();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addOfflineNode(n3);
map.addRunningVM(vm1, n1);
map.addRunningVM(vm2, n1);
map.addRunningVM(vm3, n2);
map.addSleepingVM(vm4, n2);
map.addReadyVM(vm5);
map.addReadyVM(vm6);
Set<VM> runnings = new HashSet<>(map.getRunningVMs());
runnings.add(vm6);
runnings.add(vm5);
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), runnings, map.getSleepingVMs(), Collections.emptySet()).setManageableVMs(map.getRunningVMs(n1)).build();
/*
vm1: running -> running
vm2: running-> running
vm3: running -> running
vm4: sleeping -> sleeping
vm5: ready -> running
vm6: ready -> running
* manageable_runnings: vm1, vm2
* manageable: vm1, vm2, vm5, vm6 (with ids: vm#0, vm#1, vm#4, vm#5)
*/
Set<VM> manageable = rp.getManageableVMs();
Assert.assertEquals(manageable.size(), 4, manageable.toString());
Assert.assertTrue(manageable.containsAll(Arrays.asList(vm6, vm5, vm1, vm2)));
// Check the action model that has been used for each of the VM.
for (VM vm : map.getAllVMs()) {
Assert.assertEquals(manageable.contains(vm), rp.getVMAction(vm).isManaged());
}
}
use of org.btrplace.model.Node in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testVMToShutdown.
@Test
public void testVMToShutdown() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
VM vm6 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Mapping map = mo.getMapping();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addOfflineNode(n3);
map.addRunningVM(vm1, n1);
map.addRunningVM(vm2, n1);
map.addRunningVM(vm3, n2);
map.addSleepingVM(vm4, n2);
map.addReadyVM(vm5);
map.addReadyVM(vm6);
Mapping m = mo.getMapping();
m.addOnlineNode(n1);
m.addRunningVM(vm1, n1);
DefaultReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.singleton(vm1), new HashSet<>(), new HashSet<>(), new HashSet<>()).build();
VMTransition a = rp.getVMActions().get(0);
Assert.assertEquals(a, rp.getVMAction(vm1));
Assert.assertEquals(ShutdownVM.class, a.getClass());
}
use of org.btrplace.model.Node in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testVMStaySleeping.
@Test
public void testVMStaySleeping() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
Node n1 = mo.newNode();
mo.getMapping().addOnlineNode(n1);
mo.getMapping().addSleepingVM(vm1, n1);
DefaultReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(new HashSet<>(), new HashSet<>(), Collections.singleton(vm1), new HashSet<>()).build();
VMTransition a = rp.getVMActions().get(0);
Assert.assertEquals(a, rp.getVMAction(vm1));
Assert.assertEquals(StayAwayVM.class, a.getClass());
}
use of org.btrplace.model.Node in project scheduler by btrplace.
the class DefaultReconfigurationProblem method makeNodeTransitions.
private void makeNodeTransitions() {
Mapping m = model.getMapping();
nodeActions = new ArrayList<>(nodes.size());
for (Node nId : nodes) {
NodeState state = m.getState(nId);
NodeTransitionBuilder b = amFactory.getBuilder(state);
if (b == null) {
throw new LifeCycleViolationException(model, nId, state, EnumSet.of(NodeState.OFFLINE, NodeState.ONLINE));
}
nodeActions.add(b.build(this, nId));
}
}
use of org.btrplace.model.Node in project scheduler by btrplace.
the class DefaultReconfigurationProblem method makeCardinalityVariables.
/**
* Create the cardinality variables.
*/
private void makeCardinalityVariables() {
vmsCountOnNodes = new ArrayList<>(nodes.size());
int nbVMs = vms.size();
for (Node n : nodes) {
vmsCountOnNodes.add(csp.intVar(makeVarLabel("nbVMsOn('", n, "')"), 0, nbVMs, true));
}
vmsCountOnNodes = Collections.unmodifiableList(vmsCountOnNodes);
}
Aggregations