use of org.btrplace.model.constraint.Root 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(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.constraint.Root in project scheduler by btrplace.
the class RootBuilderTest method testGoodSignatures.
@Test(dataProvider = "goodRoots")
public void testGoodSignatures(String str, int nbVMs) throws Exception {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
Set<SatConstraint> cstrs = b.build("namespace test; VM[1..10] : tiny;\n" + str).getConstraints();
Assert.assertEquals(cstrs.size(), nbVMs);
Set<VM> vms = new HashSet<>();
for (SatConstraint x : cstrs) {
Assert.assertTrue(x instanceof Root);
Assert.assertTrue(vms.addAll(x.getInvolvedVMs()));
Assert.assertEquals(x.isContinuous(), true);
}
}
use of org.btrplace.model.constraint.Root in project scheduler by btrplace.
the class CRootTest method testBasic.
@Test
public void testBasic() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Mapping map = mo.getMapping().on(n1, n2).run(n1, vm1, vm2).ready(vm3);
ChocoScheduler cra = new DefaultChocoScheduler();
cra.doRepair(false);
Root r1 = new Root(vm1);
List<SatConstraint> l = new ArrayList<>();
l.add(r1);
l.addAll(Online.newOnline(map.getAllNodes()));
ReconfigurationPlan p = cra.solve(mo, l);
Assert.assertNotNull(p);
Model res = p.getResult();
Assert.assertEquals(n1, res.getMapping().getVMLocation(vm1));
}
use of org.btrplace.model.constraint.Root in project scheduler by btrplace.
the class RootConverterTest method testViables.
@Test
public void testViables() throws JSONConverterException {
Model mo = new DefaultModel();
ConstraintsConverter conv = new ConstraintsConverter();
conv.register(new RootConverter());
Root d = new Root(mo.newVM());
Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(d)), d);
System.out.println(conv.toJSON(d));
}
use of org.btrplace.model.constraint.Root in project scheduler by btrplace.
the class RootSplitterTest method simpleTest.
@Test
public void simpleTest() {
RootSplitter splitter = new RootSplitter();
List<Instance> instances = new ArrayList<>();
Model m0 = new DefaultModel();
VM v = m0.newVM(1);
m0.getMapping().addReadyVM(v);
m0.getMapping().addRunningVM(m0.newVM(2), m0.newNode(1));
Model m1 = new DefaultModel();
m1.getMapping().addReadyVM(m1.newVM(3));
m1.getMapping().addSleepingVM(m1.newVM(4), m1.newNode(2));
m1.getMapping().addRunningVM(m1.newVM(5), m1.newNode(3));
instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
Set<VM> all = new HashSet<>(m0.getMapping().getAllVMs());
all.addAll(m1.getMapping().getAllVMs());
TIntIntHashMap index = Instances.makeVMIndex(instances);
// Only VMs in m0
Root single = new Root(v);
Assert.assertTrue(splitter.split(single, null, instances, index, new TIntIntHashMap()));
Assert.assertTrue(instances.get(0).getSatConstraints().contains(single));
Assert.assertFalse(instances.get(1).getSatConstraints().contains(single));
}
Aggregations