use of org.btrplace.model.constraint.Fence in project scheduler by btrplace.
the class CQuarantineTest method testWithNoSolution2.
/**
* A VM try to leave the quarantine zone.
*
* @throws org.btrplace.scheduler.SchedulerException
*/
@Test
public void testWithNoSolution2() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
mo.getMapping().on(n1, n2, n3).run(n1, vm1).run(n2, vm2, vm3).run(n3, vm4);
Quarantine q = new Quarantine(n2);
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.add(q);
cstrs.add(new Fence(vm1, Collections.singleton(n2)));
ChocoScheduler cra = new DefaultChocoScheduler();
ReconfigurationPlan p = cra.solve(mo, cstrs);
Assert.assertNull(p);
}
use of org.btrplace.model.constraint.Fence in project scheduler by btrplace.
the class CQuarantineTest method testWithNoSolution1.
/**
* A VM try to come into the quarantine zone.
*
* @throws org.btrplace.scheduler.SchedulerException
*/
@Test
public void testWithNoSolution1() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
mo.getMapping().on(n1, n2, n3).run(n1, vm1).run(n2, vm2, vm3).run(n3, vm4);
Quarantine q = new Quarantine(n1);
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.add(q);
cstrs.add(new Fence(vm4, Collections.singleton(n1)));
ChocoScheduler cra = new DefaultChocoScheduler();
ReconfigurationPlan p = cra.solve(mo, cstrs);
Assert.assertNull(p);
}
use of org.btrplace.model.constraint.Fence in project scheduler by btrplace.
the class CSplitAmongTest method testContinuousWithGroupChange.
@Test
public void testContinuousWithGroupChange() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
VM vm6 = mo.newVM();
VM vm7 = mo.newVM();
VM vm8 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Node n4 = mo.newNode();
Node n5 = mo.newNode();
Mapping map = mo.getMapping().on(n1, n2, n3, n4, n5).run(n1, vm1, vm3).run(n2, vm2).run(n3, vm4, vm6).run(n4, vm5).run(n5, vm7);
// Isolated VM not considered by the constraint
map.addRunningVM(vm8, n1);
Collection<VM> vg1 = new HashSet<>(Arrays.asList(vm1, vm2, vm3));
Collection<VM> vg2 = new HashSet<>(Arrays.asList(vm4, vm5, vm6));
Collection<Node> pg1 = new HashSet<>(Arrays.asList(n1, n2));
Collection<Node> pg2 = new HashSet<>(Arrays.asList(n3, n4));
Collection<Node> pg3 = new HashSet<>(Collections.singletonList(n5));
Collection<Collection<VM>> vgs = new HashSet<>(Arrays.asList(vg1, vg2));
Collection<Collection<Node>> pgs = new HashSet<>(Arrays.asList(pg1, pg2, pg3));
List<SatConstraint> cstrs = new ArrayList<>();
SplitAmong s = new SplitAmong(vgs, pgs);
s.setContinuous(true);
// Move group of VMs 1 to the group of nodes 2. Cannot work as
// the among part of the constraint will be violated
cstrs.add(s);
for (VM v : vg1) {
cstrs.add(new Fence(v, pg2));
}
ChocoScheduler cra = new DefaultChocoScheduler();
Assert.assertNull(cra.solve(mo, cstrs));
}
use of org.btrplace.model.constraint.Fence in project scheduler by btrplace.
the class FenceBuilderTest method testGoodSignatures.
@Test(dataProvider = "goodFences")
public void testGoodSignatures(String str, int nbVMs, int nbNodes, boolean c) throws Exception {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
Set<SatConstraint> cstrs = b.build("namespace test; VM[1..10] : tiny;\n @N[1..20] : defaultNode;\n" + str).getConstraints();
Assert.assertEquals(cstrs.size(), nbVMs);
Set<VM> vms = new HashSet<>();
for (SatConstraint x : cstrs) {
Assert.assertTrue(x instanceof Fence);
Assert.assertEquals(x.getInvolvedNodes().size(), nbNodes);
Assert.assertTrue(vms.addAll(x.getInvolvedVMs()));
Assert.assertEquals(x.isContinuous(), c);
}
}
use of org.btrplace.model.constraint.Fence 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()));
}
Aggregations