use of org.btrplace.scheduler.choco.duration.DurationEvaluators in project scheduler by btrplace.
the class ModelCustomization method run.
@Override
public void run() {
Model model = makeModel();
List<SatConstraint> cstrs = makeConstraints(model);
// Set attributes for the VMs
Attributes attrs = model.getAttributes();
for (VM vm : model.getMapping().getAllVMs()) {
attrs.put(vm, "template", vm.id() % 2 == 0 ? "small" : "large");
attrs.put(vm, "clone", true);
attrs.put(vm, "forge", vm.id() % 2 == 0 ? 2 : 10);
// forge == 2 && template == small for vm0, vm2, vm4, vm6, vm8
// forge == 10 && template == large for vm1, vm3, vm5, vm7, vm9
}
// Change the duration evaluator for MigrateVM action
ChocoScheduler cra = new DefaultChocoScheduler();
DurationEvaluators dev = cra.getDurationEvaluators();
dev.register(MigrateVM.class, new LinearToAResourceActionDuration<VM>("mem", 2, 3));
dev.register(BootVM.class, new ConstantActionDuration<>(1));
dev.register(ShutdownVM.class, new ConstantActionDuration<>(1));
// Relocate VM4:
// using a migration: (2 * mem + 3) = (2 * 2 + 3) = 7 sec.
// using a re-instantiation: forge + boot + shutdown = 2 + 1 + 1 = 4 sec.
// Relocate VM5:
// using a migration: (2 * mem + 3) = (2 * 3 + 3) = 9 sec.
// using a re-instantiation: forge + boot + shutdown = 10 + 1 + 1 = 12 sec.
cra.doOptimize(true);
ReconfigurationPlan plan = cra.solve(model, cstrs);
System.out.println(plan);
}
use of org.btrplace.scheduler.choco.duration.DurationEvaluators in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testSimplestInstantiation.
/*private static Model defaultModel() {
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);
return mo;
} */
/**
* Just test the state definition of the actions.
*
* @throws org.btrplace.scheduler.SchedulerException should not occur
*/
@Test
public void testSimplestInstantiation() 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);
VM vm7 = mo.newVM();
Set<VM> toRun = new HashSet<>();
Set<VM> toWait = new HashSet<>();
toWait.add(vm6);
toWait.add(vm7);
toRun.add(vm5);
toRun.add(vm4);
toRun.add(vm1);
mo.getAttributes().put(vm7, "template", "small");
Parameters ps = new DefaultParameters();
DurationEvaluators dEval = ps.getDurationEvaluators();
DefaultReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(toWait, toRun, Collections.singleton(vm3), Collections.singleton(vm2)).setParams(ps).build();
Assert.assertEquals(dEval, rp.getDurationEvaluators());
Assert.assertEquals(rp.getFutureReadyVMs(), toWait);
Assert.assertEquals(rp.getFutureRunningVMs(), toRun);
Assert.assertEquals(rp.getFutureSleepingVMs(), Collections.singleton(vm3));
Assert.assertEquals(rp.getFutureKilledVMs(), Collections.singleton(vm2));
Assert.assertEquals(rp.getVMs().size(), 7);
Assert.assertEquals(rp.getNodes().size(), 3);
Assert.assertEquals(rp.getManageableVMs().size(), rp.getVMs().size(), rp.getManageableVMs().toString());
Assert.assertTrue(rp.getStart().isInstantiated() && rp.getStart().getValue() == 0);
// Test the index values of the nodes and the VMs.
for (int i = 0; i < rp.getVMs().size(); i++) {
VM vm = rp.getVM(i);
Assert.assertEquals(i, rp.getVM(vm));
}
Assert.assertEquals(rp.getVM(mo.newVM()), -1);
for (int i = 0; i < rp.getNodes().size(); i++) {
Node n = rp.getNode(i);
Assert.assertEquals(i, rp.getNode(n));
}
Assert.assertEquals(rp.getNode(mo.newNode()), -1);
}
use of org.btrplace.scheduler.choco.duration.DurationEvaluators in project scheduler by btrplace.
the class BootVMTest method testBasics.
/**
* Just boot a VM on a node.
*/
@Test
public void testBasics() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
final VM vm1 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addReadyVM(vm1);
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();
rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
rp.getNodeActions().get(1).getState().instantiateTo(1, Cause.Null);
BootVM m = (BootVM) rp.getVMActions().get(0);
Assert.assertEquals(vm1, m.getVM());
Assert.assertNull(m.getCSlice());
Assert.assertTrue(m.getDuration().isInstantiatedTo(5));
Assert.assertTrue(m.getState().isInstantiatedTo(1));
Assert.assertFalse(m.getDSlice().getHoster().isInstantiated());
Assert.assertFalse(m.getDSlice().getStart().isInstantiated());
Assert.assertFalse(m.getDSlice().getEnd().isInstantiated());
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
org.btrplace.plan.event.BootVM a = (org.btrplace.plan.event.BootVM) p.getActions().iterator().next();
Node dest = rp.getNode(m.getDSlice().getHoster().getValue());
Assert.assertEquals(vm1, a.getVM());
Assert.assertEquals(dest, a.getDestinationNode());
Assert.assertEquals(5, a.getEnd() - a.getStart());
}
use of org.btrplace.scheduler.choco.duration.DurationEvaluators in project scheduler by btrplace.
the class BootableNodeTest method testBootCascade.
@Test
public void testBootCascade() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
map.addOfflineNode(n1);
map.addOfflineNode(n2);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(BootNode.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
BootableNode na1 = (BootableNode) rp.getNodeAction(n1);
BootableNode na2 = (BootableNode) rp.getNodeAction(n2);
na1.getState().instantiateTo(1, Cause.Null);
na2.getState().instantiateTo(1, Cause.Null);
rp.getModel().post(rp.getModel().arithm(na1.getEnd(), "=", na2.getEnd()));
new CMinMTTR().inject(ps, rp);
Assert.assertNotNull(rp.solve(0, false));
}
use of org.btrplace.scheduler.choco.duration.DurationEvaluators in project scheduler by btrplace.
the class BootableNodeTest method testForcingBoot.
@Test
public void testForcingBoot() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
Node n1 = mo.newNode();
map.addOfflineNode(n1);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(BootNode.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
BootableNode na = (BootableNode) rp.getNodeAction(n1);
na.getState().instantiateTo(1, Cause.Null);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
Assert.assertEquals(na.getDuration().getValue(), 5);
Assert.assertEquals(na.getStart().getValue(), 0);
Assert.assertEquals(na.getEnd().getValue(), 5);
Assert.assertEquals(na.getHostingStart().getValue(), 5);
Assert.assertEquals(na.getHostingEnd().getValue(), 5);
Model res = p.getResult();
Assert.assertTrue(res.getMapping().isOnline(n1));
}
Aggregations