use of org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testVMCounting.
/**
* Check the consistency between the variables counting the number of VMs on
* each node, and the placement variable.
*
* @throws org.btrplace.scheduler.SchedulerException
* @throws ContradictionException
*/
@Test
public void testVMCounting() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Node n3 = mo.newNode();
Node n2 = mo.newNode();
Mapping map = mo.getMapping();
for (int i = 0; i < 7; i++) {
VM v = mo.newVM();
map.addReadyVM(v);
}
map.addOnlineNode(n3);
map.addOnlineNode(n2);
Parameters ps = new DefaultParameters();
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), map.getAllVMs(), new HashSet<>(), new HashSet<>()).build();
// Restrict the capacity to 5 at most
for (IntVar capa : rp.getNbRunningVMs()) {
capa.updateUpperBound(5, Cause.Null);
}
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(-1, false);
Assert.assertNotNull(p);
// Check consistency between the counting and the hoster variables
int[] counts = new int[map.getAllNodes().size()];
for (Node n : map.getOnlineNodes()) {
int nIdx = rp.getNode(n);
counts[nIdx] = rp.getNbRunningVMs().get(nIdx).getValue();
}
for (VM vm : rp.getFutureRunningVMs()) {
VMTransition vmo = rp.getVMActions().get(rp.getVM(vm));
int on = vmo.getDSlice().getHoster().getValue();
counts[on]--;
}
for (int count : counts) {
Assert.assertEquals(count, 0);
}
}
use of org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR 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.scheduler.choco.constraint.mttr.CMinMTTR in project scheduler by btrplace.
the class BootVMTest method testBootSequence.
/**
* Test that check when the action is shorter than the end of
* the reconfiguration process.
* In practice, 2 boot actions have to be executed sequentially
*/
@Test
public void testBootSequence() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
final VM vm1 = mo.newVM();
final VM vm2 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addReadyVM(vm1);
map.addReadyVM(vm2);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(org.btrplace.plan.event.BootVM.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), map.getAllVMs(), new HashSet<>(), new HashSet<>()).build();
BootVM m1 = (BootVM) rp.getVMActions().get(rp.getVM(vm1));
BootVM m2 = (BootVM) rp.getVMActions().get(rp.getVM(vm2));
rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
rp.getNodeActions().get(1).getState().instantiateTo(1, Cause.Null);
rp.getModel().post(rp.getModel().arithm(m2.getStart(), ">=", m1.getEnd()));
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
Iterator<Action> ite = p.iterator();
org.btrplace.plan.event.BootVM b1 = (org.btrplace.plan.event.BootVM) ite.next();
org.btrplace.plan.event.BootVM b2 = (org.btrplace.plan.event.BootVM) ite.next();
Assert.assertEquals(vm1, b1.getVM());
Assert.assertEquals(vm2, b2.getVM());
Assert.assertTrue(b1.getEnd() <= b2.getStart());
Assert.assertEquals(5, b1.getEnd() - b1.getStart());
Assert.assertEquals(5, b2.getEnd() - b2.getStart());
}
use of org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR in project scheduler by btrplace.
the class BootableNodeTest method testDelayedBooting.
@Test
public void testDelayedBooting() throws ContradictionException, SchedulerException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
Node n2 = mo.newNode();
map.addOfflineNode(n2);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(BootNode.class, new ConstantActionDuration<>(2));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
BootableNode ma2 = (BootableNode) rp.getNodeAction(n2);
ma2.getState().instantiateTo(1, Cause.Null);
ma2.getStart().updateLowerBound(5, Cause.Null);
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(0, false);
// ChocoLogging.flushLogs();
Assert.assertNotNull(p);
}
use of org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR in project scheduler by btrplace.
the class BootableNodeTest method testActionDurationSimple.
/**
* Unit test for issue #3
*/
@Test
public void testActionDurationSimple() throws SchedulerException, ContradictionException {
Model model = new DefaultModel();
Mapping map = model.getMapping();
Node n1 = model.newNode();
Node n4 = model.newNode();
map.addOnlineNode(n1);
map.addOfflineNode(n4);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(ShutdownNode.class, new ConstantActionDuration<>(5));
dev.register(BootNode.class, new ConstantActionDuration<>(3));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(model).setParams(ps).build();
ShutdownableNode sn1 = (ShutdownableNode) rp.getNodeAction(n1);
sn1.getState().instantiateTo(0, Cause.Null);
BootableNode bn4 = (BootableNode) rp.getNodeAction(n4);
bn4.getState().instantiateTo(0, Cause.Null);
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
Assert.assertEquals(bn4.getStart().getValue(), 0);
Assert.assertEquals(bn4.getDuration().getValue(), 0);
Assert.assertEquals(bn4.getEnd().getValue(), 0);
Assert.assertEquals(bn4.getHostingStart().getValue(), 0);
Assert.assertEquals(bn4.getHostingEnd().getValue(), 0);
Assert.assertEquals(p.getSize(), 1);
Model res = p.getResult();
Assert.assertTrue(res.getMapping().getOfflineNodes().contains(n1));
Assert.assertTrue(res.getMapping().getOfflineNodes().contains(n4));
}
Aggregations