use of org.btrplace.model.VM 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.VM in project scheduler by btrplace.
the class IssuesTest method testIssue10.
@Test
public void testIssue10() throws SchedulerException, ContradictionException {
Model model = new DefaultModel();
Node n1 = model.newNode();
Node n2 = model.newNode();
Node n3 = model.newNode();
VM vm1 = model.newVM();
VM vm2 = model.newVM();
Mapping map = model.getMapping().on(n1, n2).off(n3).run(n1, vm1, vm2);
// model.attach(resources);
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(model).build();
// n3 goes online
rp.getNodeAction(n3).getState().instantiateTo(1, Cause.Null);
rp.getModel().post(rp.getModel().arithm(rp.getEnd(), "<=", 10));
int NUMBER_OF_NODE = map.getAllNodes().size();
// Extract all the state of the involved nodes (all nodes in this case)
List<IntVar> VMsOnAllNodes = rp.getNbRunningVMs();
// Each element is the number of VMs on each node
IntVar[] vmsOnInvolvedNodes = new IntVar[NUMBER_OF_NODE];
BoolVar[] idles = new BoolVar[NUMBER_OF_NODE];
int i = 0;
int maxVMs = rp.getSourceModel().getMapping().getAllVMs().size();
for (Node n : map.getAllNodes()) {
vmsOnInvolvedNodes[i] = rp.getModel().intVar("nVMs" + n, -1, maxVMs, true);
IntVar state = rp.getNodeAction(n).getState();
// If the node is offline -> the temporary variable is 1, otherwise, it equals the number of VMs on that node
Constraint elem = rp.getModel().element(vmsOnInvolvedNodes[i], new IntVar[] { rp.getModel().intVar(-1), VMsOnAllNodes.get(rp.getNode(n)) }, state, 0);
rp.getModel().post(elem);
// IF number of VMs on a node is 0 -> Idle
idles[i] = rp.getModel().boolVar("idle" + n);
ChocoUtils.postIfOnlyIf(rp, idles[i], rp.getModel().arithm(vmsOnInvolvedNodes[i], "=", 0));
i++;
}
IntVar sum = rp.getModel().intVar("sum", 0, 1000, true);
rp.getModel().post(rp.getModel().sum(idles, "=", sum));
// idle should be less than Amount for MaxSN (0, in this case)
rp.getModel().post(rp.getModel().arithm(sum, "=", 0));
System.err.flush();
CMinMTTR obj = new CMinMTTR();
obj.inject(new DefaultParameters(), rp);
ReconfigurationPlan plan = rp.solve(0, false);
Assert.assertNotNull(plan);
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class IssuesTest method testIssue5c.
/**
* Test a suspicious bug in issue #5
*/
@Test
public void testIssue5c() throws SchedulerException {
Model model = new DefaultModel();
Node n1 = model.newNode();
Node n2 = model.newNode();
Node n3 = model.newNode();
VM vm1 = model.newVM();
VM vm2 = model.newVM();
VM vm3 = model.newVM();
VM vm4 = model.newVM();
Mapping map = model.getMapping().on(n1, n2, n3).run(n2, vm1, vm2, vm3, vm4);
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(model).build();
List<IntVar> nodes_state = rp.getNbRunningVMs();
IntVar[] nodeVM = new IntVar[map.getAllNodes().size()];
int i = 0;
for (Node n : map.getAllNodes()) {
nodeVM[i++] = nodes_state.get(rp.getNode(n));
// rp.getNodeAction(n).getState().setVal(1);
}
IntVar idle = rp.getModel().intVar("Nidles", 0, map.getAllNodes().size(), true);
rp.getModel().post(rp.getModel().count(0, nodeVM, idle));
rp.getModel().post(rp.getModel().arithm(idle, "<=", 1));
ReconfigurationPlan plan = rp.solve(0, false);
Assert.assertNotNull(plan);
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class IssuesTest method issue72b.
@Test
public void issue72b() throws SchedulerException {
Model mo = new DefaultModel();
Mapping ma = mo.getMapping();
ShareableResource rcCPU = new ShareableResource("cpu", 2, 0);
mo.attach(rcCPU);
List<Node> nodes = new ArrayList<>();
for (int i = 0; i < 2; i++) {
nodes.add(mo.newNode());
ma.addOnlineNode(nodes.get(i));
}
for (int i = 0; i < 1; i++) {
VM v = mo.newVM();
ma.addRunningVM(v, nodes.get(0));
}
for (int i = 0; i < 2; i++) {
VM v = mo.newVM();
ma.addRunningVM(v, nodes.get(1));
}
DefaultParameters ps = new DefaultParameters();
ReconfigurationPlan p = new DefaultChocoScheduler(ps).solve(mo, new ArrayList<>());
Assert.assertNotNull(p);
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class IssuesTest method test16b.
/**
* Unit test derived from Issue 16.
*
* @throws org.btrplace.scheduler.SchedulerException
*/
@Test
public void test16b() throws SchedulerException {
Model model = new DefaultModel();
Node n1 = model.newNode();
Node n2 = model.newNode();
Node n3 = model.newNode();
Node n4 = model.newNode();
VM vm1 = model.newVM();
VM vm2 = model.newVM();
VM vm3 = model.newVM();
VM vm4 = model.newVM();
VM vm5 = model.newVM();
VM vm6 = model.newVM();
model.getMapping().on(n1, n2, n3, n4).run(n1, vm1, vm2).run(n2, vm3, vm4).run(n3, vm5, vm6);
Set<SatConstraint> ctrsC = new HashSet<>();
Set<VM> vms1 = new HashSet<>(Arrays.asList(vm1, vm3, vm5));
Set<VM> vms2 = new HashSet<>(Arrays.asList(vm2, vm4, vm6));
ctrsC.add(new Spread(vms1));
ctrsC.add(new Spread(vms2));
ctrsC.add(new Fence(vm3, Collections.singleton(n1)));
Offline off = new Offline(n2);
ctrsC.add(off);
ChocoScheduler cra = new DefaultChocoScheduler();
ReconfigurationPlan dp = cra.solve(model, ctrsC);
Assert.assertNotNull(dp);
}
Aggregations