Search in sources :

Example 1 with SplitAmong

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

the class CSplitAmongTest method testContinuousWithGroupChange.

@Test
public void testContinuousWithGroupChange() 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, vm3).run(n2, vm2).run(n3, vm4, vm6).run(n4, vm5).run(n5, vm7);
    // Isolated VM not considered by the constraint
    map.addRunningVM(vm8, n1);
    Collection<VM> vg1 = new HashSet<>(Arrays.asList(vm1, vm2, vm3));
    Collection<VM> vg2 = new HashSet<>(Arrays.asList(vm4, vm5, vm6));
    Collection<Node> pg1 = new HashSet<>(Arrays.asList(n1, n2));
    Collection<Node> pg2 = new HashSet<>(Arrays.asList(n3, n4));
    Collection<Node> pg3 = new HashSet<>(Collections.singletonList(n5));
    Collection<Collection<VM>> vgs = new HashSet<>(Arrays.asList(vg1, vg2));
    Collection<Collection<Node>> pgs = new HashSet<>(Arrays.asList(pg1, pg2, pg3));
    List<SatConstraint> cstrs = new ArrayList<>();
    SplitAmong s = new SplitAmong(vgs, pgs);
    s.setContinuous(true);
    // Move group of VMs 1 to the group of nodes 2. Cannot work as
    // the among part of the constraint will be violated
    cstrs.add(s);
    for (VM v : vg1) {
        cstrs.add(new Fence(v, pg2));
    }
    ChocoScheduler cra = new DefaultChocoScheduler();
    Assert.assertNull(cra.solve(mo, cstrs));
}
Also used : SplitAmong(org.btrplace.model.constraint.SplitAmong) SatConstraint(org.btrplace.model.constraint.SatConstraint) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Fence(org.btrplace.model.constraint.Fence) Test(org.testng.annotations.Test)

Example 2 with SplitAmong

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

the class CSplitAmongTest method testDiscrete.

@Test
public void testDiscrete() 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, vm3).run(n2, vm2).run(n3, vm4, vm6).run(n4, vm5).run(n5, vm7);
    // Isolated VM not considered by the constraint
    map.addRunningVM(vm8, n1);
    Collection<VM> vg1 = new HashSet<>(Arrays.asList(vm1, vm2, vm3));
    Collection<VM> vg2 = new HashSet<>(Arrays.asList(vm4, vm5, vm6));
    Collection<VM> vg3 = new HashSet<>(Collections.singletonList(vm7));
    Collection<Node> pg1 = new HashSet<>(Arrays.asList(n1, n2));
    Collection<Node> pg2 = new HashSet<>(Arrays.asList(n3, n4));
    Collection<Node> pg3 = new HashSet<>(Collections.singletonList(n5));
    Collection<Collection<VM>> vgs = new HashSet<>(Arrays.asList(vg1, vg2, vg3));
    Collection<Collection<Node>> pgs = new HashSet<>(Arrays.asList(pg1, pg2, pg3));
    SplitAmong s = new SplitAmong(vgs, pgs);
    s.setContinuous(false);
    // vg1 and vg2 overlap on n2. The two groups are mis-placed
    map.addRunningVM(vm6, n2);
    ChocoScheduler cra = new DefaultChocoScheduler();
    ReconfigurationPlan p = cra.solve(mo, Collections.singleton(s));
    Assert.assertNotNull(p);
    Assert.assertTrue(p.getSize() > 0);
}
Also used : SplitAmong(org.btrplace.model.constraint.SplitAmong) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Test(org.testng.annotations.Test)

Example 3 with SplitAmong

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

the class CSplitAmongTest 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, vm3).run(n2, vm2).run(n3, vm4, vm6).run(n4, vm5).run(n5, vm7);
    // Isolated VM not considered by the constraint
    map.addRunningVM(vm8, n1);
    Collection<VM> vg1 = new HashSet<>(Arrays.asList(vm1, vm2, vm3));
    Collection<VM> vg2 = new HashSet<>(Arrays.asList(vm4, vm5, vm6));
    Collection<VM> vg3 = new HashSet<>(Collections.singletonList(vm7));
    Collection<Node> pg1 = new HashSet<>(Arrays.asList(n1, n2));
    Collection<Node> pg2 = new HashSet<>(Arrays.asList(n3, n4));
    Collection<Node> pg3 = new HashSet<>(Collections.singletonList(n5));
    Collection<Collection<VM>> vgs = new HashSet<>(Arrays.asList(vg1, vg2, vg3));
    Collection<Collection<Node>> pgs = new HashSet<>(Arrays.asList(pg1, pg2, pg3));
    SplitAmong s = new SplitAmong(vgs, pgs);
    CSplitAmong cs = new CSplitAmong(s);
    Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR());
    Assert.assertTrue(cs.getMisPlacedVMs(i).isEmpty());
    map.remove(vm7);
    map.addRunningVM(vm6, n5);
    // vg2 is on 2 group of nodes, the whole group is mis-placed
    Assert.assertEquals(cs.getMisPlacedVMs(i), vg2);
    map.addRunningVM(vm7, n5);
    // vg1 and vg2 overlap on n1. The two groups are mis-placed
    map.addRunningVM(vm6, n2);
    Assert.assertTrue(cs.getMisPlacedVMs(i).containsAll(vg1));
    Assert.assertTrue(cs.getMisPlacedVMs(i).containsAll(vg2));
    Assert.assertEquals(cs.getMisPlacedVMs(i).size(), vg1.size() + vg2.size());
}
Also used : SplitAmong(org.btrplace.model.constraint.SplitAmong) MinMTTR(org.btrplace.model.constraint.MinMTTR) Test(org.testng.annotations.Test)

Example 4 with SplitAmong

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

the class SplitAmongBuilderTest method testGoodSignatures.

@Test(dataProvider = "goodSplitAmongs")
public void testGoodSignatures(String str, int nbVGrp, int nbVMs, int nbPGrp, int nbNodes) throws Exception {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    SplitAmong x = (SplitAmong) b.build("namespace test; VM[1..10] : tiny;\n@N[1..20] : defaultNode;\n" + str).getConstraints().iterator().next();
    Assert.assertEquals(x.getGroupsOfVMs().size(), nbVGrp);
    Assert.assertEquals(x.getInvolvedVMs().size(), nbVMs);
    Assert.assertEquals(x.getGroupsOfNodes().size(), nbPGrp);
    Assert.assertEquals(x.getInvolvedNodes().size(), nbNodes);
    Assert.assertEquals(x.isContinuous(), !str.startsWith(">>"));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) SplitAmong(org.btrplace.model.constraint.SplitAmong) ScriptBuilder(org.btrplace.btrpsl.ScriptBuilder) Test(org.testng.annotations.Test)

Example 5 with SplitAmong

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

the class SplitAmongConverterTest method testViables.

@Test
public void testViables() throws JSONConverterException {
    Model mo = new DefaultModel();
    Collection<VM> s1 = Arrays.asList(mo.newVM(), mo.newVM(), mo.newVM());
    Collection<VM> s2 = Arrays.asList(mo.newVM(), mo.newVM(), mo.newVM());
    Collection<VM> s3 = Arrays.asList(mo.newVM(), mo.newVM());
    Collection<Collection<VM>> vgrps = new HashSet<>(Arrays.asList(s1, s2, s3));
    Collection<Node> p1 = Arrays.asList(mo.newNode(), mo.newNode());
    Collection<Node> p2 = Arrays.asList(mo.newNode(), mo.newNode());
    Collection<Node> p3 = Collections.singletonList(mo.newNode());
    Collection<Collection<Node>> pgrps = new HashSet<>(Arrays.asList(p1, p2, p3));
    SplitAmong d = new SplitAmong(vgrps, pgrps, false);
    SplitAmong c = new SplitAmong(vgrps, pgrps, true);
    ConstraintsConverter conv = new ConstraintsConverter();
    conv.register(new SplitAmongConverter());
    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) SplitAmong(org.btrplace.model.constraint.SplitAmong) Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Collection(java.util.Collection) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

SplitAmong (org.btrplace.model.constraint.SplitAmong)7 Test (org.testng.annotations.Test)7 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)4 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)4 DefaultModel (org.btrplace.model.DefaultModel)2 Fence (org.btrplace.model.constraint.Fence)2 SatConstraint (org.btrplace.model.constraint.SatConstraint)2 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)1 Model (org.btrplace.model.Model)1 Node (org.btrplace.model.Node)1 VM (org.btrplace.model.VM)1 MinMTTR (org.btrplace.model.constraint.MinMTTR)1