use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.
the class LonelyTest method testContinuousIsSatisfied.
@Test(dependsOnMethods = { "testInstantiation" })
public void testContinuousIsSatisfied() {
Model mo = new DefaultModel();
List<VM> vms = Util.newVMs(mo, 10);
List<Node> ns = Util.newNodes(mo, 10);
Set<VM> s = new HashSet<>(Arrays.asList(vms.get(0), vms.get(1)));
Mapping map = mo.getMapping();
map.addOnlineNode(ns.get(0));
map.addOnlineNode(ns.get(1));
map.addOnlineNode(ns.get(2));
map.addRunningVM(vms.get(0), ns.get(0));
map.addRunningVM(vms.get(1), ns.get(0));
map.addRunningVM(vms.get(2), ns.get(1));
map.addRunningVM(vms.get(3), ns.get(1));
Lonely l = new Lonely(s, true);
ReconfigurationPlan p = new DefaultReconfigurationPlan(mo);
Assert.assertEquals(l.isSatisfied(p), true);
p.add(new MigrateVM(vms.get(1), ns.get(0), ns.get(1), 2, 4));
Assert.assertEquals(l.isSatisfied(p), false);
p.add(new ShutdownVM(vms.get(2), ns.get(1), 0, 1));
Assert.assertEquals(l.isSatisfied(p), false);
p.add(new MigrateVM(vms.get(3), ns.get(1), ns.get(2), 1, 2));
Assert.assertEquals(l.isSatisfied(p), true);
}
use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.
the class OverbookTest method testContinuousIsSatisfied.
@Test
public void testContinuousIsSatisfied() {
Model mo = new DefaultModel();
List<VM> vms = Util.newVMs(mo, 10);
Node n0 = mo.newNode();
Node n1 = mo.newNode();
Model i = new DefaultModel();
Mapping cfg = i.getMapping();
cfg.addOnlineNode(n0);
cfg.addOnlineNode(n1);
ShareableResource rc = new ShareableResource("cpu");
rc.setCapacity(n0, 1);
rc.setCapacity(n1, 4);
rc.setConsumption(vms.get(0), 2);
rc.setConsumption(vms.get(1), 2);
rc.setConsumption(vms.get(2), 4);
cfg.addRunningVM(vms.get(0), n0);
cfg.addRunningVM(vms.get(1), n1);
cfg.addRunningVM(vms.get(2), n1);
cfg.addRunningVM(vms.get(3), n1);
i.attach(rc);
Overbook o = new Overbook(n1, "cpu", 2);
o.setContinuous(true);
ReconfigurationPlan p = new DefaultReconfigurationPlan(i);
Assert.assertEquals(o.isSatisfied(p), true);
p.add(new Allocate(vms.get(0), n0, "cpu", 1, 2, 5));
Assert.assertEquals(o.isSatisfied(p), true);
p.add(new Allocate(vms.get(1), n1, "cpu", 5, 2, 5));
Assert.assertEquals(o.isSatisfied(p), false);
p.add(new Allocate(vms.get(2), n1, "cpu", 2, 0, 1));
Assert.assertEquals(o.isSatisfied(p), true);
p.add(new Allocate(vms.get(3), n1, "cpu", 3, 4, 6));
Assert.assertEquals(o.isSatisfied(p), false);
p.add(new ShutdownVM(vms.get(2), n1, 2, 3));
Assert.assertEquals(o.isSatisfied(p), true);
}
use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.
the class ResourceCapacityTest method testContinuousIsSatisfied.
@Test
public void testContinuousIsSatisfied() {
Model mo = new DefaultModel();
List<Node> ns = Util.newNodes(mo, 10);
List<VM> vms = Util.newVMs(mo, 10);
Mapping map = mo.getMapping();
map.addOnlineNode(ns.get(0));
map.addOnlineNode(ns.get(1));
map.addOnlineNode(ns.get(2));
map.addRunningVM(vms.get(0), ns.get(0));
map.addRunningVM(vms.get(1), ns.get(0));
map.addRunningVM(vms.get(2), ns.get(1));
map.addRunningVM(vms.get(3), ns.get(2));
map.addReadyVM(vms.get(4));
ShareableResource rc = new ShareableResource("foo", 1, 1);
mo.attach(rc);
Set<Node> nodes = new HashSet<>(Arrays.asList(ns.get(0), ns.get(1)));
ResourceCapacity cc = new ResourceCapacity(nodes, "foo", 4, true);
ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
Assert.assertEquals(cc.isSatisfied(plan), true);
// 3/4
MigrateVM m = new MigrateVM(vms.get(3), ns.get(2), ns.get(1), 0, 1);
m.addEvent(Action.Hook.POST, new AllocateEvent(vms.get(3), "foo", 2));
plan.add(m);
// 5/4
plan.add(new ShutdownVM(vms.get(2), ns.get(1), 1, 2));
// 4/4
plan.add(new BootVM(vms.get(4), ns.get(2), 2, 3));
// 4/4
plan.add(new Allocate(vms.get(1), ns.get(0), "foo", 2, 2, 3));
// 5/4
plan.add(new MigrateVM(vms.get(0), ns.get(0), ns.get(2), 3, 4));
System.out.println(plan);
Assert.assertEquals(cc.isSatisfied(plan), true);
}
use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.
the class InstanceSolverRunner method call.
@Override
// for the LifeCycleViolationException
@SuppressWarnings("squid:S1166")
public SolvingStatistics call() throws SchedulerException {
stats = new SingleRunnerStatistics(params, instance, System.currentTimeMillis());
rp = null;
// Build the core problem
long d = -System.currentTimeMillis();
try {
rp = buildRP();
} catch (@SuppressWarnings("unused") LifeCycleViolationException ex) {
// If there is a violation of the cycle it is not a bug that should be propagated
// it it just indicating there is no solution
stats.setCompleted(true);
stats.setMetrics(new Metrics());
return stats;
} finally {
d += System.currentTimeMillis();
stats.setCoreBuildDuration(d);
}
stats.setNbManagedVMs(rp.getManageableVMs().size());
// Customize the core problem
d = -System.currentTimeMillis();
if (!specialise()) {
d += System.currentTimeMillis();
stats.setSpecialisationDuration(d);
stats.setCompleted(true);
return getStatistics();
}
d += System.currentTimeMillis();
stats.setSpecialisationDuration(d);
// statistics
stats.setMetrics(new Metrics(rp.getSolver().getMeasures()));
rp.getLogger().debug(stats.toString());
// The solution monitor to store the measures at each solution
rp.getSolver().plugMonitor((IMonitorSolution) () -> {
Solution solution = new Solution(rp.getModel());
solution.record();
ReconfigurationPlan plan = rp.buildReconfigurationPlan(solution, origin);
views.forEach(v -> v.insertActions(rp, solution, plan));
MeasuresRecorder m = rp.getSolver().getMeasures();
SolutionStatistics st = new SolutionStatistics(new Metrics(m), plan);
IntVar o = rp.getObjective();
if (o != null) {
st.setObjective(solution.getIntVal(o));
}
stats.addSolution(st);
params.solutionListeners().forEach(c -> c.accept(rp, plan));
});
setVerbosity();
// The actual solving process
rp.solve(params.getTimeLimit(), params.doOptimize());
return getStatistics();
}
use of org.btrplace.plan.ReconfigurationPlan 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);
}
}
Aggregations