use of org.btrplace.model.Instance in project scheduler by btrplace.
the class CMinMigrationsTest method main.
public static void main(String[] args) {
String root = "/Users/fabien.hermenier/Documents/BtrPlace/nutanix/instances";
List<OptConstraint> objs = Arrays.asList(/*new MinMTTR(),*/
new MinMigrations());
boolean verbose = true;
for (OptConstraint o : objs) {
System.out.print(" " + o);
}
System.out.println();
for (int idx = 1; idx <= 256; idx += 5) {
String path = root + "/lazan/lazan-" + idx + ".json.gz";
if (verbose) {
System.out.println("--- " + idx + " --- ");
} else {
System.out.print(idx);
}
List<Long> res = new ArrayList<>();
for (OptConstraint o : objs) {
if (verbose) {
System.out.println("\t" + o);
}
Instance i = JSON.readInstance(new File(path));
if (Network.get(i.getModel()) != null) {
i.getModel().detach(Network.get(i.getModel()));
}
i = new Instance(i.getModel(), i.getSatConstraints(), o);
ChocoScheduler s = new DefaultChocoScheduler();
s.doOptimize(false);
s.setTimeLimit(30);
s.doRepair(false);
ReconfigurationPlan p = s.solve(i);
Assert.assertNotNull(p);
res.add(p.getActions().stream().filter(x -> x instanceof MigrateVM).mapToLong(x -> x.getEnd() - x.getStart()).sum());
// res.add((long)s.getStatistics().lastSolution().getDuration());
if (verbose) {
System.out.println(s.getStatistics());
// System.out.println(p);
}
}
if (!verbose) {
for (Long l : res) {
System.out.print("\t" + l);
}
System.out.println();
}
}
}
use of org.btrplace.model.Instance in project scheduler by btrplace.
the class DefaultChocoScheduler method solve.
@Override
public ReconfigurationPlan solve(Instance i) throws SchedulerException {
Model mo = i.getModel();
Collection<SatConstraint> cstrs = i.getSatConstraints();
// If a network view is attached, ensure that all the migrations' destination node are defined
Network net = Network.get(mo);
stages = null;
if (net != null) {
// The network view is useless to take placement decisions
mo.detach(net);
// Solve a first time using placement oriented MinMTTR optimisation constraint
ReconfigurationPlan p = runner.solve(params, i);
stages = new StagedSolvingStatistics(runner.getStatistics());
if (p == null) {
return null;
}
// Add Fence constraints for each destination node chosen
List<SatConstraint> newCstrs = p.getActions().stream().filter(a -> a instanceof MigrateVM).map(a -> new Fence(((MigrateVM) a).getVM(), Collections.singleton(((MigrateVM) a).getDestinationNode()))).collect(Collectors.toList());
Model result = p.getResult();
if (result == null) {
throw new InconsistentSolutionException(mo, p, "The plan cannot be applied");
}
// Add Root constraints to all staying VMs
newCstrs.addAll(mo.getMapping().getRunningVMs().stream().filter(v -> p.getOrigin().getMapping().getVMLocation(v).id() == result.getMapping().getVMLocation(v).id()).map(Root::new).collect(Collectors.toList()));
// Add the old constraints
newCstrs.addAll(cstrs);
// Re-attach the network view
mo.attach(net);
// New timeout value = elapsed time - initial timeout value
Parameters ps = new DefaultParameters(params);
if (ps.getTimeLimit() > 0) {
// in seconds
double timeout = params.getTimeLimit() - runner.getStatistics().getMetrics().timeCount() / 1000;
ps.setTimeLimit((int) timeout);
}
return runner.solve(ps, new Instance(mo, newCstrs, i.getOptConstraint()));
}
// Solve and return the computed plan
return runner.solve(params, new Instance(mo, cstrs, i.getOptConstraint()));
}
use of org.btrplace.model.Instance in project scheduler by btrplace.
the class DefaultChocoSchedulerTest method testOnSolutionHook.
@Test
public void testOnSolutionHook() {
ChocoScheduler cra = new DefaultChocoScheduler();
Model mo = new DefaultModel();
VM vm = mo.newVM();
Node node = mo.newNode();
mo.getMapping().on(node).run(node, vm);
Instance i = new Instance(mo, Running.newRunning(Arrays.asList(vm)), new MinMTTR());
List<ReconfigurationPlan> onSolutions = new ArrayList<>();
cra.addSolutionListener((rp, plan) -> onSolutions.add(plan));
Assert.assertEquals(1, cra.solutionListeners().size());
ReconfigurationPlan plan = cra.solve(i);
Assert.assertEquals(1, onSolutions.size());
Assert.assertEquals(plan, onSolutions.get(0));
}
use of org.btrplace.model.Instance in project scheduler by btrplace.
the class IssuesTest method computable.
/**
* A helper to check that an instance has a solution.
*
* @param file the serialised instance. Must be in 'src/test/resources/'
*/
private static void computable(String file) {
Instance i = JSON.readInstance(new File("src/test/resources/" + file));
ChocoScheduler s = new DefaultChocoScheduler();
ReconfigurationPlan p = s.solve(i);
System.out.println(s.getStatistics());
Assert.assertNotNull(p);
System.out.println(p.getSize() + " action(s)");
}
use of org.btrplace.model.Instance in project scheduler by btrplace.
the class IssuesTest method issue72.
@Test
public void issue72() throws Exception {
String input = "{\"model\":{\"mapping\":{\"readyVMs\":[],\"onlineNodes\":{\"0\":{\"sleepingVMs\":[],\"runningVMs\":[9,8,7,6,5,4,3,2,1,0]},\"1\":{\"sleepingVMs\":[],\"runningVMs\":[19,18,17,16,15,14,13,12,11,10]}},\"offlineNodes\":[]},\"attributes\":{\"nodes\":{},\"vms\":{}},\"views\":[{\"defConsumption\":0,\"nodes\":{\"0\":32768,\"1\":32768},\"rcId\":\"mem\",\"id\":\"shareableResource\",\"defCapacity\":8192,\"vms\":{\"11\":1024,\"12\":1024,\"13\":1024,\"14\":1024,\"15\":1024,\"16\":1024,\"17\":1024,\"18\":1024,\"19\":1024,\"0\":1024,\"1\":1024,\"2\":1024,\"3\":1024,\"4\":1024,\"5\":1024,\"6\":1024,\"7\":1024,\"8\":1024,\"9\":1024,\"10\":1024}},{\"defConsumption\":0,\"nodes\":{\"0\":700,\"1\":700},\"rcId\":\"cpu\",\"id\":\"shareableResource\",\"defCapacity\":8000,\"vms\":{\"11\":0,\"12\":0,\"13\":0,\"14\":0,\"15\":0,\"16\":70,\"17\":0,\"18\":60,\"19\":0,\"0\":100,\"1\":0,\"2\":0,\"3\":0,\"4\":0,\"5\":0,\"6\":0,\"7\":0,\"8\":90,\"9\":0,\"10\":0}}]},\"constraints\":[],\"objective\":{\"id\":\"minimizeMTTR\"}}";
Instance i = JSON.readInstance(new StringReader(input));
ChocoScheduler s = new DefaultChocoScheduler();
s.setTimeLimit(-1);
i.getModel().detach(ShareableResource.get(i.getModel(), "mem"));
i.getModel().detach(ShareableResource.get(i.getModel(), "cpu"));
List<SatConstraint> cstrs = new ArrayList<>();
ReconfigurationPlan p = s.solve(i.getModel(), cstrs, i.getOptConstraint());
Assert.assertTrue(p.getActions().isEmpty());
}
Aggregations