Search in sources :

Example 1 with Split

use of org.btrplace.model.constraint.Split in project scheduler by btrplace.

the class CSplitTest method testSimpleDiscrete.

@Test
public void testSimpleDiscrete() 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();
    mo.getMapping().on(n1, n2, n3, n4, n5).run(n1, vm1, vm2, vm3).run(n3, vm4, vm5, vm6).run(n5, vm7, vm8);
    Collection<VM> g1 = Arrays.asList(vm1, vm2);
    Collection<VM> g2 = Arrays.asList(vm3, vm4, vm5);
    Collection<VM> g3 = Arrays.asList(vm6, vm7);
    Collection<Collection<VM>> grps = Arrays.asList(g1, g2, g3);
    Split s = new Split(grps);
    ChocoScheduler cra = new DefaultChocoScheduler();
    ReconfigurationPlan p = cra.solve(mo, Collections.singleton(s));
    Assert.assertNotNull(p);
    Assert.assertTrue(p.getSize() > 0);
}
Also used : DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Split(org.btrplace.model.constraint.Split) Test(org.testng.annotations.Test)

Example 2 with Split

use of org.btrplace.model.constraint.Split in project scheduler by btrplace.

the class CSplitTest method testGetMisplaced.

@Test
public void testGetMisplaced() {
    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, vm2).run(n2, vm3).run(n3, vm4, vm5).run(n4, vm6).run(n5, vm7, vm8);
    Collection<VM> g1 = Arrays.asList(vm1, vm2);
    Collection<VM> g2 = new HashSet<>(Arrays.asList(vm3, vm4, vm5));
    Collection<VM> g3 = new HashSet<>(Arrays.asList(vm6, vm7));
    Collection<Collection<VM>> grps = Arrays.asList(g1, g2, g3);
    Split s = new Split(grps);
    CSplit cs = new CSplit(s);
    Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR());
    Assert.assertTrue(cs.getMisPlacedVMs(i).isEmpty());
    map.addRunningVM(vm5, n1);
    Set<VM> bad = cs.getMisPlacedVMs(i);
    Assert.assertEquals(bad.size(), 3);
    Assert.assertTrue(bad.contains(vm1) && bad.contains(vm2) && bad.contains(vm5));
    map.addRunningVM(vm6, n3);
    bad = cs.getMisPlacedVMs(i);
    Assert.assertTrue(bad.contains(vm4) && bad.contains(vm5) && bad.contains(vm6));
}
Also used : MinMTTR(org.btrplace.model.constraint.MinMTTR) Split(org.btrplace.model.constraint.Split) Test(org.testng.annotations.Test)

Example 3 with Split

use of org.btrplace.model.constraint.Split in project scheduler by btrplace.

the class SplitSplitter method split.

@Override
public boolean split(final Split cstr, Instance origin, final List<Instance> partitions, final TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
    final boolean c = cstr.isContinuous();
    return SplittableElementSet.newVMIndex(cstr.getInvolvedVMs(), vmsPosition).forEachPartition((index, idx, from, to) -> {
        if (to - from >= 2) {
            // More than 1 VM involved in a split constraint for this partition
            // if these VMs belong to at least 2 groups, we must post a split constraints
            // for the VMs on these groups
            Collection<Collection<VM>> sets = new ArrayList<>();
            for (Collection<VM> vms : cstr.getSets()) {
                SplittableElementSet<VM> subSplit = SplittableElementSet.newVMIndex(vms, vmsPosition);
                Set<VM> s = subSplit.getSubSet(idx);
                if (!s.isEmpty()) {
                    sets.add(s);
                }
            }
            if (sets.size() > 1) {
                partitions.get(idx).getSatConstraints().add(new Split(sets, c));
            }
        }
        return true;
    });
}
Also used : VM(org.btrplace.model.VM) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Split(org.btrplace.model.constraint.Split)

Example 4 with Split

use of org.btrplace.model.constraint.Split in project scheduler by btrplace.

the class SplitConverterTest method testViables.

@Test
public void testViables() throws JSONConverterException {
    Model mo = new DefaultModel();
    Collection<VM> s1 = Arrays.asList(mo.newVM(), mo.newVM());
    Collection<VM> s2 = Arrays.asList(mo.newVM(), mo.newVM());
    Collection<VM> s3 = Collections.singletonList(mo.newVM());
    Collection<Collection<VM>> vgrps = new HashSet<>(Arrays.asList(s1, s2, s3));
    Split d = new Split(vgrps, false);
    Split c = new Split(vgrps, true);
    ConstraintsConverter conv = new ConstraintsConverter();
    conv.register(new SplitConverter());
    Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(d)), d);
    Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(c)), c);
    System.out.println(conv.toJSON(d));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Collection(java.util.Collection) Split(org.btrplace.model.constraint.Split) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 5 with Split

use of org.btrplace.model.constraint.Split in project scheduler by btrplace.

the class CSplitTest method testContinuous.

// @Test
@Test(enabled = false)
public void testContinuous() 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, vm2).run(n3, vm3, vm4, vm5).run(n5, vm6, vm7, vm8);
    Collection<VM> g1 = Arrays.asList(vm1, vm2);
    Collection<VM> g2 = Arrays.asList(vm3, vm4, vm5);
    Collection<VM> g3 = Arrays.asList(vm6, vm7);
    Collection<Collection<VM>> grps = Arrays.asList(g1, g2, g3);
    Split s = new Split(grps);
    s.setContinuous(true);
    ChocoScheduler cra = new DefaultChocoScheduler();
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.add(s);
    // go away before the other arrive.
    for (VM v : map.getRunningVMs(n1)) {
        cstrs.add(new Fence(v, Collections.singleton(n3)));
    }
    // cra.setTimeLimit(2);
    ReconfigurationPlan p = cra.solve(mo, cstrs);
    Assert.assertNotNull(p);
    Assert.assertTrue(p.getSize() > 0);
}
Also used : SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Fence(org.btrplace.model.constraint.Fence) Split(org.btrplace.model.constraint.Split) Test(org.testng.annotations.Test)

Aggregations

Split (org.btrplace.model.constraint.Split)6 Test (org.testng.annotations.Test)5 Collection (java.util.Collection)2 DefaultModel (org.btrplace.model.DefaultModel)2 VM (org.btrplace.model.VM)2 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)2 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)2 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)1 Model (org.btrplace.model.Model)1 Fence (org.btrplace.model.constraint.Fence)1 MinMTTR (org.btrplace.model.constraint.MinMTTR)1 SatConstraint (org.btrplace.model.constraint.SatConstraint)1