use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class ResourceCapacityBuilder method buildConstraint.
@Override
public List<? extends SatConstraint> buildConstraint(BtrPlaceTree t, List<BtrpOperand> args) {
if (!checkConformance(t, args)) {
return Collections.emptyList();
}
@SuppressWarnings("unchecked") List<Node> ns = (List<Node>) params[0].transform(this, t, args.get(0));
String rcId = (String) params[1].transform(this, t, args.get(1));
BtrpNumber n = (BtrpNumber) args.get(2);
if (!n.isInteger()) {
t.ignoreError("Parameter '" + params[2].getName() + "' expects an integer");
return Collections.emptyList();
}
int v = n.getIntValue();
if (v < 0) {
t.ignoreError("Parameter '" + params[2].getName() + "' expects a positive integer (" + v + " given)");
return Collections.emptyList();
}
return ns != null ? Collections.singletonList(new ResourceCapacity(new HashSet<>(ns), rcId, v)) : Collections.emptyList();
}
use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class CAmongTest method testWithNoSolution.
/**
* No solution because constraints force to spread the VMs among 2 groups.
*
* @throws org.btrplace.scheduler.SchedulerException
*/
@Test
public void testWithNoSolution() 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();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Node n4 = mo.newNode();
Mapping map = mo.getMapping().on(n1, n2, n3, n4).run(n1, vm1).run(n2, vm2, vm3).ready(vm4, vm5);
Set<VM> vms = new HashSet<>(Arrays.asList(vm1, vm2, vm5));
Collection<Node> s = new HashSet<>(Arrays.asList(n1, n2));
Collection<Node> s2 = new HashSet<>(Arrays.asList(n3, n4));
Collection<Collection<Node>> pGrps = new HashSet<>(Arrays.asList(s, s2));
Among a = new Among(vms, pGrps);
a.setContinuous(false);
ChocoScheduler cra = new DefaultChocoScheduler();
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Running.newRunning(map.getAllVMs()));
cstrs.add(new Fence(vm2, Collections.singleton(n3)));
cstrs.add(new Fence(vm1, Collections.singleton(n1)));
cstrs.add(a);
ReconfigurationPlan p = cra.solve(mo, cstrs);
Assert.assertNull(p);
}
use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class CAmongTest method testWithGroupChange.
@Test
public void testWithGroupChange() 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();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Node n4 = mo.newNode();
Mapping map = mo.getMapping().on(n1, n2, n3, n4).run(n1, vm1).run(n2, vm2, vm3).ready(vm4, vm5);
Set<VM> vms = new HashSet<>(Arrays.asList(vm1, vm2, vm5));
Collection<Node> s1 = new HashSet<>(Arrays.asList(n1, n2));
Collection<Node> s2 = new HashSet<>(Arrays.asList(n3, n4));
Collection<Collection<Node>> pGrps = Arrays.asList(s1, s2);
Among a = new Among(vms, pGrps);
a.setContinuous(false);
ChocoScheduler cra = new DefaultChocoScheduler();
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Running.newRunning(map.getAllVMs()));
cstrs.add(new Fence(vm2, s2));
cstrs.add(a);
ReconfigurationPlan p = cra.solve(mo, cstrs);
Assert.assertNotNull(p);
// System.out.println(p);
// Assert.assertEquals(a.isSatisfied(p.getResult()), SatConstraint.Sat.SATISFIED);
}
use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class CShareableResource method getMisPlacedVMs.
/**
* {@inheritDoc}
*
* @param i the model to use to inspect the VMs.
* @return the set of VMs that cannot have their associated {@link Preserve} constraint satisfy with regards
* to a possible {@link Overbook} and single-node {@link ResourceCapacity} constraint.
*/
@Override
public Set<VM> getMisPlacedVMs(Instance i) {
final TObjectDoubleMap<Node> wantedRatios = new TObjectDoubleHashMap<>();
final int nbVMs = i.getModel().getMapping().getNbVMs();
final int nbNodes = i.getModel().getMapping().getNbNodes();
final IntMap wantedAmount = new IntMap(0, nbVMs);
final IntMap wantedCapacity = new IntMap(0, nbNodes);
for (SatConstraint c : i.getSatConstraints()) {
if (!(c instanceof ResourceRelated && ((ResourceRelated) c).getResource().equals(rc.getResourceIdentifier()))) {
continue;
}
if (c instanceof Preserve) {
// We guarantee the highest request so far.
VM v = c.getInvolvedVMs().iterator().next();
int qty = ((Preserve) c).getAmount();
wantedAmount.put(v.id(), Math.max(wantedAmount.get(v.id()), qty));
} else if (c instanceof Overbook) {
Node n = c.getInvolvedNodes().iterator().next();
double min = ((Overbook) c).getRatio();
if (wantedRatios.containsKey(n)) {
min = Math.min(min, wantedRatios.get(n));
}
wantedRatios.put(n, min);
} else if (c instanceof ResourceCapacity && c.getInvolvedNodes().size() == 1) {
Node n = c.getInvolvedNodes().iterator().next();
int qty = ((ResourceCapacity) c).getAmount();
wantedCapacity.put(n.id(), Math.max(qty, wantedCapacity.get(n.id())));
}
}
Mapping m = i.getModel().getMapping();
Set<VM> candidates = new HashSet<>();
for (Node n : m.getOnlineNodes()) {
Set<VM> running = m.getRunningVMs(n);
if (overloaded(wantedRatios, wantedAmount, wantedCapacity, running, n)) {
candidates.addAll(running);
}
}
return candidates;
}
use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class CAmongTest method testContinuousWithNotAlreadySatisfied.
@Test
public void testContinuousWithNotAlreadySatisfied() 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();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Node n4 = mo.newNode();
Mapping map = mo.getMapping().on(n1, n2, n3, n4).run(n1, vm1).run(n2, vm2).run(n3, vm3).ready(vm4, vm5);
Set<VM> vms = new HashSet<>(Arrays.asList(vm1, vm2, vm5));
Collection<Node> s1 = new HashSet<>(Arrays.asList(n1, n2));
Collection<Node> s2 = new HashSet<>(Arrays.asList(n3, n4));
Collection<Collection<Node>> pGrps = new HashSet<>(Arrays.asList(s1, s2));
Among a = new Among(vms, pGrps);
a.setContinuous(true);
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Running.newRunning(map.getAllVMs()));
cstrs.add(new Fence(vm2, Collections.singleton(n3)));
cstrs.add(a);
ChocoScheduler cra = new DefaultChocoScheduler();
ReconfigurationPlan p = cra.solve(mo, cstrs);
Assert.assertNull(p);
}
Aggregations