Search in sources :

Example 1 with MaxOnline

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();
}
Also used : MaxOnline(org.btrplace.model.constraint.MaxOnline) BtrpNumber(org.btrplace.btrpsl.element.BtrpNumber) Node(org.btrplace.model.Node) List(java.util.List) HashSet(java.util.HashSet)

Example 2 with MaxOnline

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());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) ShareableResource(org.btrplace.model.view.ShareableResource) SatConstraint(org.btrplace.model.constraint.SatConstraint) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) MaxOnline(org.btrplace.model.constraint.MaxOnline) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel)

Example 3 with MaxOnline

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));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) MinMTTR(org.btrplace.model.constraint.MinMTTR) FixedNodeSetsPartitioning(org.btrplace.scheduler.runner.disjoint.FixedNodeSetsPartitioning) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) MaxOnline(org.btrplace.model.constraint.MaxOnline) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) FixedSizePartitioning(org.btrplace.scheduler.runner.disjoint.FixedSizePartitioning) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) Test(org.testng.annotations.Test)

Example 4 with MaxOnline

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);
}
Also used : DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Instance(org.btrplace.model.Instance) MaxOnline(org.btrplace.model.constraint.MaxOnline) Collection(java.util.Collection) Test(org.testng.annotations.Test)

Example 5 with MaxOnline

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));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) MaxOnline(org.btrplace.model.constraint.MaxOnline) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) ArrayList(java.util.ArrayList) Online(org.btrplace.model.constraint.Online) MaxOnline(org.btrplace.model.constraint.MaxOnline) Test(org.testng.annotations.Test)

Aggregations

MaxOnline (org.btrplace.model.constraint.MaxOnline)11 DefaultModel (org.btrplace.model.DefaultModel)9 Node (org.btrplace.model.Node)9 Test (org.testng.annotations.Test)9 Model (org.btrplace.model.Model)8 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)6 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)6 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)6 ArrayList (java.util.ArrayList)5 VM (org.btrplace.model.VM)5 SatConstraint (org.btrplace.model.constraint.SatConstraint)5 Mapping (org.btrplace.model.Mapping)4 ShareableResource (org.btrplace.model.view.ShareableResource)4 HashSet (java.util.HashSet)3 Instance (org.btrplace.model.Instance)2 Online (org.btrplace.model.constraint.Online)2 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)2 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)1 Collection (java.util.Collection)1 List (java.util.List)1