use of org.btrplace.plan.event.Action 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.plan.event.Action in project scheduler by btrplace.
the class ReconfigurationSimulator method at.
private void at(List<Action> starts, List<Action> ends) {
// Apply all the actions simultaneously, starting by the ending
start = false;
for (Action a : ends) {
a.visit(this);
}
start = true;
for (Action a : starts) {
a.visit(this);
}
}
use of org.btrplace.plan.event.Action in project scheduler by btrplace.
the class StaticPartitioning method merge.
private ReconfigurationPlan merge(Instance i, Collection<SolvingStatistics> results) throws SplitException {
ReconfigurationPlan plan = new DefaultReconfigurationPlan(i.getModel());
// Only if there is a solution
for (SolvingStatistics result : results) {
getStatistics().addPartitionStatistics(result);
ReconfigurationPlan p = result.lastSolution();
if (p == null) {
return null;
}
for (Action a : p) {
if (!plan.add(a)) {
throw new SplitException(plan.getOrigin(), "Unable to add action '" + a + "' while merging the sub-plans");
}
}
}
return plan;
}
use of org.btrplace.plan.event.Action in project scheduler by btrplace.
the class ReconfigurationPlanConverter method fromJSON.
@Override
public ReconfigurationPlan fromJSON(JSONObject ob) throws JSONConverterException {
checkKeys(ob, ORIGIN_LABEL, ACTIONS_LABEL);
Model m = mc.fromJSON((JSONObject) ob.get(ORIGIN_LABEL));
ActionConverter ac = new ActionConverter(m);
ReconfigurationPlan plan = new DefaultReconfigurationPlan(m);
for (Action a : ac.listFromJSON((JSONArray) ob.get(ACTIONS_LABEL))) {
plan.add(a);
}
return plan;
}
use of org.btrplace.plan.event.Action in project scheduler by btrplace.
the class COverbookTest method testWithIncrease.
/**
* Test with a root VM that has increasing need and another one that prevent it
* to get the resources immediately
*/
@Test
public void testWithIncrease() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
Node n1 = mo.newNode();
Mapping map = mo.getMapping().on(n1).run(n1, vm1, vm2);
org.btrplace.model.view.ShareableResource rc = new ShareableResource("foo");
rc.setCapacity(n1, 5);
rc.setConsumption(vm1, 3);
rc.setConsumption(vm2, 2);
mo.attach(rc);
ChocoScheduler cra = new DefaultChocoScheduler();
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Online.newOnline(map.getAllNodes()));
Overbook o = new Overbook(n1, "foo", 1);
o.setContinuous(true);
cstrs.add(o);
cstrs.add(new Ready(vm2));
cstrs.add(new Preserve(vm1, "foo", 5));
ReconfigurationPlan p = cra.solve(mo, cstrs);
Assert.assertNotNull(p);
Assert.assertEquals(p.getSize(), 2);
Action al = p.getActions().stream().filter(s -> s instanceof Allocate).findAny().get();
Action sh = p.getActions().stream().filter(s -> s instanceof ShutdownVM).findAny().get();
Assert.assertTrue(sh.getEnd() <= al.getStart());
}
Aggregations