Search in sources :

Example 76 with ChocoScheduler

use of org.btrplace.scheduler.choco.ChocoScheduler in project scheduler by btrplace.

the class CSplitAmongTest method testDiscreteWithGroupChange.

@Test
public void testDiscreteWithGroupChange() 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(false);
    // Move group of VMs 1 to the group of nodes 2. This is allowed
    // group of VMs 2 will move to another group of node so at the end, the constraint should be satisfied
    cstrs.add(s);
    for (VM v : vg1) {
        cstrs.add(new Fence(v, pg2));
    }
    ChocoScheduler cra = new DefaultChocoScheduler();
    ReconfigurationPlan plan = cra.solve(mo, cstrs);
    Assert.assertNotNull(plan);
}
Also used : SplitAmong(org.btrplace.model.constraint.SplitAmong) 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) Test(org.testng.annotations.Test)

Example 77 with ChocoScheduler

use of org.btrplace.scheduler.choco.ChocoScheduler 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)

Example 78 with ChocoScheduler

use of org.btrplace.scheduler.choco.ChocoScheduler in project scheduler by btrplace.

the class CSpreadTest method testSeparateWithContinuous.

/**
 * 2 VMs are already hosted on a same node, check
 * if separation is working in continuous mode
 */
@Test
public void testSeparateWithContinuous() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    mo.getMapping().on(n1, n2).run(n1, vm1, vm2);
    List<SatConstraint> cstr = new ArrayList<>();
    ChocoScheduler cra = new DefaultChocoScheduler();
    Spread s = new Spread(mo.getMapping().getAllVMs());
    s.setContinuous(true);
    cstr.add(s);
    cstr.addAll(Online.newOnline(mo.getMapping().getAllNodes()));
    cstr.add(new Fence(vm1, Collections.singleton(n2)));
    ReconfigurationPlan p = cra.solve(mo, cstr);
    Assert.assertNull(p);
}
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) Test(org.testng.annotations.Test)

Example 79 with ChocoScheduler

use of org.btrplace.scheduler.choco.ChocoScheduler in project scheduler by btrplace.

the class CSpreadTest method testContinuous.

@Test
public void testContinuous() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Node n3 = mo.newNode();
    mo.getMapping().on(n1, n2, n3).run(n1, vm1).run(n2, vm2);
    List<SatConstraint> cstr = new ArrayList<>();
    ChocoScheduler cra = new DefaultChocoScheduler();
    cstr.add(new Spread(mo.getMapping().getAllVMs(), true));
    cstr.addAll(Online.newOnline(mo.getMapping().getAllNodes()));
    cstr.add(new Fence(vm1, Collections.singleton(n2)));
    ReconfigurationPlan p = cra.solve(mo, cstr);
    Assert.assertNotNull(p);
    System.err.println(p);
    Mapping res = p.getResult().getMapping();
    Assert.assertEquals(2, p.getSize());
    Assert.assertNotSame(res.getVMLocation(vm1), res.getVMLocation(vm2));
}
Also used : 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 80 with ChocoScheduler

use of org.btrplace.scheduler.choco.ChocoScheduler in project scheduler by btrplace.

the class CMinMigrationsTest method testNtnx.

@Test
public void testNtnx() {
    String root = "src/test/resources/min-migrations.json";
    Instance i = JSON.readInstance(new File(root));
    i = new Instance(i.getModel(), i.getSatConstraints(), new MinMigrations());
    ChocoScheduler s = new DefaultChocoScheduler();
    s.doOptimize(true);
    ReconfigurationPlan p = s.solve(i);
    Assert.assertNotNull(p);
    System.out.println(s.getStatistics());
    System.out.println(p);
    Assert.assertEquals(p.getActions().stream().filter(x -> x instanceof MigrateVM).count(), 1);
    Assert.assertEquals(3, p.getDuration());
}
Also used : DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) Instance(org.btrplace.model.Instance) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) MinMigrations(org.btrplace.model.constraint.MinMigrations) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)82 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)82 Test (org.testng.annotations.Test)76 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)73 ShareableResource (org.btrplace.model.view.ShareableResource)30 SatConstraint (org.btrplace.model.constraint.SatConstraint)28 ArrayList (java.util.ArrayList)25 DefaultModel (org.btrplace.model.DefaultModel)17 Model (org.btrplace.model.Model)17 Node (org.btrplace.model.Node)17 VM (org.btrplace.model.VM)16 BootVM (org.btrplace.plan.event.BootVM)12 ShutdownVM (org.btrplace.plan.event.ShutdownVM)12 MigrateVM (org.btrplace.plan.event.MigrateVM)10 Fence (org.btrplace.model.constraint.Fence)9 Preserve (org.btrplace.model.constraint.Preserve)8 org.btrplace.model.constraint (org.btrplace.model.constraint)7 MaxOnline (org.btrplace.model.constraint.MaxOnline)6 org.btrplace.model (org.btrplace.model)5 SchedulerException (org.btrplace.scheduler.SchedulerException)5