use of org.btrplace.scheduler.choco.Parameters in project scheduler by btrplace.
the class ShutdownableNodeTest method testForcedOffline.
@Test
public void testForcedOffline() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
Node n1 = mo.newNode();
map.addOnlineNode(n1);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(ShutdownNode.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
ShutdownableNode ma = (ShutdownableNode) rp.getNodeAction(n1);
ma.getState().instantiateTo(0, Cause.Null);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
Assert.assertEquals(ma.getDuration().getValue(), 5);
Assert.assertEquals(ma.getStart().getValue(), 0);
Assert.assertEquals(ma.getEnd().getValue(), 5);
Assert.assertEquals(ma.getHostingStart().getValue(), 0);
Assert.assertEquals(ma.getHostingEnd().getValue(), 0);
Assert.assertEquals(p.getSize(), 1);
Model res = p.getResult();
Assert.assertTrue(res.getMapping().getOfflineNodes().contains(n1));
}
use of org.btrplace.scheduler.choco.Parameters in project scheduler by btrplace.
the class SuspendVMTest method testSuspendSequences.
/**
* Test that check that the action duration is lesser than
* the cSlice duration. This allows actions scheduling
* In practice, for this test, 2 suspend actions have to be executed sequentially
*/
@Test
public void testSuspendSequences() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
Node n1 = mo.newNode();
Mapping map = mo.getMapping();
map.addOnlineNode(n1);
map.addRunningVM(vm1, n1);
map.addRunningVM(vm2, n1);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(org.btrplace.plan.event.SuspendVM.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), new HashSet<>(), map.getAllVMs(), new HashSet<>()).build();
SuspendVM m1 = (SuspendVM) rp.getVMActions().get(rp.getVM(vm1));
SuspendVM m2 = (SuspendVM) rp.getVMActions().get(rp.getVM(vm2));
rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
org.chocosolver.solver.Model csp = rp.getModel();
csp.post(csp.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.SuspendVM b1 = (org.btrplace.plan.event.SuspendVM) ite.next();
org.btrplace.plan.event.SuspendVM b2 = (org.btrplace.plan.event.SuspendVM) 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.Parameters in project scheduler by btrplace.
the class SuspendVMTest method testBasic.
@Test
public void testBasic() throws ContradictionException, SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
Node n1 = mo.newNode();
Mapping map = mo.getMapping();
map.addOnlineNode(n1);
map.addRunningVM(vm1, n1);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(org.btrplace.plan.event.SuspendVM.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), new HashSet<>(), map.getAllVMs(), new HashSet<>()).build();
rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
SuspendVM m = (SuspendVM) rp.getVMActions().get(0);
Assert.assertEquals(vm1, m.getVM());
Assert.assertNull(m.getDSlice());
Assert.assertTrue(m.getDuration().isInstantiatedTo(5));
Assert.assertTrue(m.getState().isInstantiatedTo(0));
Assert.assertTrue(m.getCSlice().getHoster().isInstantiatedTo(0));
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(0, false);
org.btrplace.plan.event.SuspendVM a = (org.btrplace.plan.event.SuspendVM) p.getActions().iterator().next();
Assert.assertEquals(n1, a.getSourceNode());
Assert.assertEquals(vm1, a.getVM());
Assert.assertEquals(5, a.getEnd() - a.getStart());
}
use of org.btrplace.scheduler.choco.Parameters in project scheduler by btrplace.
the class StaticPartitioningTest method testSolvingIncorrectPartitioning.
@Test(expectedExceptions = { SchedulerException.class })
public void testSolvingIncorrectPartitioning() throws SchedulerException {
SynchronizedElementBuilder eb = new SynchronizedElementBuilder(new DefaultElementBuilder());
Model origin = new DefaultModel(eb);
Node n1 = origin.newNode();
Node n2 = origin.newNode();
VM vm1 = origin.newVM();
VM vm2 = origin.newVM();
/*
* 2 nodes among 2 instances, 2 VMs to boot on the nodes
*/
origin.getMapping().addOnlineNode(n1);
origin.getMapping().addOfflineNode(n2);
origin.getMapping().addReadyVM(vm1);
origin.getMapping().addReadyVM(vm2);
Model s1 = new SubModel(origin, eb, Collections.singletonList(n1), Collections.singleton(vm1));
Model s2 = new SubModel(origin, eb, Collections.singletonList(n2), Collections.singleton(vm2));
Instance i0 = new Instance(origin, new MinMTTR());
final Instance i1 = new Instance(s1, Running.newRunning(Collections.singletonList(vm1)), new MinMTTR());
final Instance i2 = new Instance(s2, new MinMTTR());
// Error, vm1 is in s1, not s2
i2.getSatConstraints().add(new Running(vm1));
StaticPartitioning st = new StaticPartitioning() {
@Override
public List<Instance> split(Parameters ps, Instance i) throws SchedulerException {
return Arrays.asList(i1, i2);
}
};
Parameters p = new DefaultChocoScheduler();
st.solve(p, i0);
}
use of org.btrplace.scheduler.choco.Parameters in project scheduler by btrplace.
the class CMinMigrations method injectPlacementHeuristic.
private void injectPlacementHeuristic(ReconfigurationProblem p, Parameters ps, IntVar cost) {
List<CShareableResource> rcs = rp.getSourceModel().getViews().stream().filter(v -> v instanceof ShareableResource).map(v -> (CShareableResource) rp.getView(v.getIdentifier())).collect(Collectors.toList());
useResources = !rcs.isEmpty();
Model mo = p.getSourceModel();
Mapping map = mo.getMapping();
OnStableNodeFirst schedHeuristic = new OnStableNodeFirst(p);
// Get the VMs to place
Set<VM> onBadNodes = new HashSet<>(p.getManageableVMs());
// Get the VMs that runs and have a pretty low chances to move
Set<VM> onGoodNodes = map.getRunningVMs(map.getOnlineNodes());
onGoodNodes.removeAll(onBadNodes);
List<VMTransition> goodActions = p.getVMActions(onGoodNodes);
List<VMTransition> badActions = p.getVMActions(onBadNodes);
Solver s = p.getSolver();
// Get the VMs to move for exclusion issue
Set<VM> vmsToExclude = new HashSet<>(p.getManageableVMs());
for (Iterator<VM> ite = vmsToExclude.iterator(); ite.hasNext(); ) {
VM vm = ite.next();
if (!(map.isRunning(vm) && p.getFutureRunningVMs().contains(vm))) {
ite.remove();
}
}
List<AbstractStrategy<?>> strategies = new ArrayList<>();
Map<IntVar, VM> pla = VMPlacementUtils.makePlacementMap(p);
if (!vmsToExclude.isEmpty()) {
List<VMTransition> actions = new LinkedList<>();
// Get all the involved slices
for (VM vm : vmsToExclude) {
if (p.getFutureRunningVMs().contains(vm)) {
actions.add(p.getVMAction(vm));
}
}
placeVMs(ps, strategies, actions, schedHeuristic, pla);
}
TObjectIntMap<VM> costs = CShareableResource.getWeights(rp, rcs);
badActions.sort((v2, v1) -> costs.get(v1.getVM()) - costs.get(v2.getVM()));
goodActions.sort((v2, v1) -> costs.get(v1.getVM()) - costs.get(v2.getVM()));
placeVMs(ps, strategies, badActions, schedHeuristic, pla);
placeVMs(ps, strategies, goodActions, schedHeuristic, pla);
// Reinstantations. Try to reinstantiate first
List<IntVar> migs = new ArrayList<>();
for (VMTransition t : rp.getVMActions()) {
if (t instanceof RelocatableVM) {
migs.add(((RelocatableVM) t).getRelocationMethod());
}
}
strategies.add(Search.intVarSearch(new FirstFail(rp.getModel()), new IntDomainMax(), migs.toArray(new IntVar[migs.size()])));
if (!p.getNodeActions().isEmpty()) {
// Boot some nodes if needed
IntVar[] starts = p.getNodeActions().stream().map(Transition::getStart).toArray(IntVar[]::new);
strategies.add(new IntStrategy(starts, new FirstFail(rp.getModel()), new IntDomainMin()));
// Fix the duration. The side effect will be that states will be fixed as well
// with the objective to not do un-necessary actions
IntVar[] durations = p.getNodeActions().stream().map(Transition::getDuration).toArray(IntVar[]::new);
strategies.add(new IntStrategy(durations, new FirstFail(rp.getModel()), new IntDomainMin()));
}
postCostConstraints();
// /SCHEDULING PROBLEM
MovementGraph gr = new MovementGraph(rp);
IntVar[] starts = dSlices(rp.getVMActions()).map(Slice::getStart).filter(v -> !v.isInstantiated()).toArray(IntVar[]::new);
strategies.add(new IntStrategy(starts, new StartOnLeafNodes(rp, gr), new IntDomainMin()));
strategies.add(new IntStrategy(schedHeuristic.getScope(), schedHeuristic, new IntDomainMin()));
IntVar[] ends = rp.getVMActions().stream().map(Transition::getEnd).filter(v -> !v.isInstantiated()).toArray(IntVar[]::new);
strategies.add(Search.intVarSearch(new MyInputOrder<>(s), new IntDomainMin(), ends));
// At this stage only it matters to plug the cost constraints
strategies.add(new IntStrategy(new IntVar[] { p.getEnd(), cost }, new MyInputOrder<>(s, this), new IntDomainMin()));
s.setSearch(new StrategiesSequencer(s.getEnvironment(), strategies.toArray(new AbstractStrategy[strategies.size()])));
}
Aggregations