Search in sources :

Example 1 with FixedNodeSetsPartitioning

use of org.btrplace.scheduler.runner.disjoint.FixedNodeSetsPartitioning 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 2 with FixedNodeSetsPartitioning

use of org.btrplace.scheduler.runner.disjoint.FixedNodeSetsPartitioning in project scheduler by btrplace.

the class AmongSplitterTest method testSplittable.

@Test
public void testSplittable() throws SchedulerException {
    List<VM> vms = Arrays.asList(vm1, vm2, vm3);
    Collection<Collection<Node>> parts = new ArrayList<>();
    parts.add(Arrays.asList(n1, n2));
    parts.add(Collections.singletonList(n3));
    parts.add(Collections.singletonList(n4));
    Among single = new Among(vms, parts);
    /*
         N1 v1 v2
         N2 v3
         ---
         N3 v4
         --
         N4 v5
         */
    FixedNodeSetsPartitioning partitionner = new FixedNodeSetsPartitioning(parts);
    partitionner.setPartitions(parts);
    List<Instance> instances = partitionner.split(new DefaultParameters(), new Instance(mo, Collections.emptyList(), new MinMTTR()));
    TIntIntHashMap vmIndex = Instances.makeVMIndex(instances);
    TIntIntHashMap nodeIndex = Instances.makeNodeIndex(instances);
    splitter.split(single, new Instance(mo, new MinMTTR()), instances, vmIndex, nodeIndex);
    Among a = (Among) instances.get(0).getSatConstraints().iterator().next();
    Assert.assertEquals(a.getGroupsOfNodes().size(), 1);
    Assert.assertEquals(a.getInvolvedNodes(), Arrays.asList(n1, n2));
    for (Instance i : instances) {
        System.out.println(i.getSatConstraints());
    }
}
Also used : FixedNodeSetsPartitioning(org.btrplace.scheduler.runner.disjoint.FixedNodeSetsPartitioning) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) MinMTTR(org.btrplace.model.constraint.MinMTTR) Among(org.btrplace.model.constraint.Among) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) Test(org.testng.annotations.Test)

Aggregations

TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)2 MinMTTR (org.btrplace.model.constraint.MinMTTR)2 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)2 FixedNodeSetsPartitioning (org.btrplace.scheduler.runner.disjoint.FixedNodeSetsPartitioning)2 Test (org.testng.annotations.Test)2 DefaultModel (org.btrplace.model.DefaultModel)1 Instance (org.btrplace.model.Instance)1 Model (org.btrplace.model.Model)1 Node (org.btrplace.model.Node)1 Among (org.btrplace.model.constraint.Among)1 MaxOnline (org.btrplace.model.constraint.MaxOnline)1 FixedSizePartitioning (org.btrplace.scheduler.runner.disjoint.FixedSizePartitioning)1