use of org.btrplace.model.constraint.MaxOnline in project scheduler by btrplace.
the class MaxOnlineBuilder method buildConstraint.
/**
* Build an online constraint.
*
* @param args must be 1 set of nodes. The set must not be empty
* @return a constraint
*/
@Override
public List<MaxOnline> buildConstraint(BtrPlaceTree t, List<BtrpOperand> args) {
if (checkConformance(t, args)) {
@SuppressWarnings("unchecked") List<Node> ns = (List<Node>) params[0].transform(this, t, args.get(0));
if (ns == null) {
return Collections.emptyList();
}
Set<Node> s = new HashSet<>(ns);
if (s.size() != ns.size()) {
// Prevent duplicates
return Collections.emptyList();
}
BtrpNumber n = (BtrpNumber) args.get(1);
if (!n.isInteger()) {
t.ignoreError("Parameter '" + params[1].getName() + "' expects an integer");
return Collections.emptyList();
}
int v = n.getIntValue();
if (v < 0) {
t.ignoreError("Parameter '" + params[1].getName() + "' expects a positive integer (" + v + " given)");
return Collections.emptyList();
}
return Collections.singletonList(new MaxOnline(new HashSet<>(ns), v, true));
}
return Collections.emptyList();
}
use of org.btrplace.model.constraint.MaxOnline in project scheduler by btrplace.
the class Decommissionning method run.
@Override
public void run() {
int ratio = 1;
int nbPCPUs = 4;
int nbNodes = 2;
// The current DC
Model mo = new DefaultModel();
for (int i = 0; i < nbNodes; i++) {
Node n = mo.newNode();
mo.getMapping().addOnlineNode(n);
// 4 VMs per node
for (int j = 0; j < ratio * nbPCPUs; j++) {
VM v = mo.newVM();
mo.getMapping().addRunningVM(v, n);
}
}
// Resource allocation
ShareableResource rc = new ShareableResource("cpu", 8, 1);
mo.attach(rc);
// The new DC
for (int i = 0; i < nbNodes; i++) {
Node n = mo.newNode();
mo.getMapping().addOfflineNode(n);
rc.setCapacity(n, 10);
}
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Offline.newOffline(mo.getMapping().getOnlineNodes()));
MaxOnline m = new MaxOnline(mo.getMapping().getAllNodes(), nbNodes + 1, true);
cstrs.add(m);
ChocoScheduler cra = new DefaultChocoScheduler();
cra.setMaxEnd(3);
cra.setVerbosity(1);
ReconfigurationPlan p = cra.solve(mo, cstrs);
System.out.println(p);
System.out.println(cra.getStatistics());
}
use of org.btrplace.model.constraint.MaxOnline in project scheduler by btrplace.
the class MaxOnlineSplitterTest method testSplit.
@Test
public void testSplit() throws SchedulerException {
MaxOnlineSplitter splitter = new MaxOnlineSplitter();
Model mo = new DefaultModel();
Node[] ns = new Node[10];
for (int i = 0; i < ns.length; i++) {
Node n = mo.newNode();
mo.getMapping().addOnlineNode(n);
ns[i] = n;
}
FixedNodeSetsPartitioning cut = new FixedSizePartitioning(5);
Instance origin = new Instance(mo, Collections.emptyList(), new MinMTTR());
List<Instance> instances = cut.split(new DefaultParameters(), origin);
TIntIntHashMap vmIndex = Instances.makeVMIndex(instances);
TIntIntHashMap nodeIndex = Instances.makeNodeIndex(instances);
MaxOnline m1 = new MaxOnline(new HashSet<>(Arrays.asList(ns[0], ns[1], ns[2], ns[3], ns[4])), 3);
// This one is valid as m1 stay in the first partition
Assert.assertTrue(splitter.split(m1, origin, instances, vmIndex, nodeIndex));
boolean found = false;
for (Instance i : instances) {
if (i.getSatConstraints().contains(m1)) {
if (found) {
Assert.fail(m1 + " is already in a partition");
}
found = true;
}
}
// Invalid, the constraint is over 2 partitions
MaxOnline m2 = new MaxOnline(new HashSet<>(Arrays.asList(ns[0], ns[1], ns[5])), 3);
Assert.assertFalse(splitter.split(m2, origin, instances, vmIndex, nodeIndex));
}
use of org.btrplace.model.constraint.MaxOnline in project scheduler by btrplace.
the class FixedNodeSetsPartitioningTest method testSplitWithUnsplittableConstraint.
@Test(expectedExceptions = { SchedulerException.class })
public void testSplitWithUnsplittableConstraint() throws SchedulerException {
Instance orig = makeInstance();
orig.getSatConstraints().add(new MaxOnline(orig.getModel().getMapping().getAllNodes(), 5));
List<Collection<Node>> parts = splitIn(orig.getModel().getMapping().getAllNodes(), 3);
FixedNodeSetsPartitioning f = new FixedNodeSetsPartitioning(parts);
f.split(new DefaultParameters(), orig);
}
use of org.btrplace.model.constraint.MaxOnline in project scheduler by btrplace.
the class CMaxOnlineTest method testSimpleContinuousCase.
@Test
public void testSimpleContinuousCase() throws SchedulerException {
Model model = new DefaultModel();
Node n1 = model.newNode();
Node n2 = model.newNode();
model.getMapping().addOnlineNode(n1);
model.getMapping().addOfflineNode(n2);
MaxOnline maxOnline = new MaxOnline(model.getMapping().getAllNodes(), 1, true);
List<SatConstraint> constraints = new ArrayList<>();
constraints.add(maxOnline);
constraints.add(new Online(n2));
ChocoScheduler cra = new DefaultChocoScheduler();
// cra.setTimeLimit(5);
cra.setMaxEnd(4);
cra.getMapper().mapConstraint(MaxOnline.class, CMaxOnline.class);
ReconfigurationPlan plan = cra.solve(model, constraints);
Assert.assertNotNull(plan);
Assert.assertTrue(maxOnline.isSatisfied(plan));
}
Aggregations