Search in sources :

Example 1 with Spread

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

the class IssuesTest method testIssue86.

@Test
public void testIssue86() throws Exception {
    Model mo = new DefaultModel();
    mo.getMapping().addReadyVM(mo.newVM());
    mo.getMapping().addReadyVM(mo.newVM());
    mo.getMapping().addReadyVM(mo.newVM());
    mo.getMapping().addOnlineNode(mo.newNode());
    mo.getMapping().addOnlineNode(mo.newNode());
    mo.getMapping().addOnlineNode(mo.newNode());
    List<SatConstraint> cstrs = mo.getMapping().getAllVMs().stream().map(Running::new).collect(Collectors.toList());
    cstrs.add(new Spread(mo.getMapping().getAllVMs(), false));
    cstrs.addAll(mo.getMapping().getOnlineNodes().stream().map(n -> new RunningCapacity(n, 1)).collect(Collectors.toList()));
    Instance i = new Instance(mo, cstrs, new MinMTTR());
    ChocoScheduler s = new DefaultChocoScheduler();
    s.doOptimize(false);
    s.doRepair(false);
    ReconfigurationPlan p = s.solve(i.getModel(), i.getSatConstraints(), i.getOptConstraint());
    Assert.assertNotNull(p);
    Assert.assertEquals(3, p.getActions().size());
    s.doRepair(true);
    p = s.solve(i.getModel(), i.getSatConstraints(), i.getOptConstraint());
    Assert.assertNotNull(p);
    Assert.assertEquals(3, p.getActions().size());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Spread(org.btrplace.model.constraint.Spread) RunningCapacity(org.btrplace.model.constraint.RunningCapacity) Instance(org.btrplace.model.Instance) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) MinMTTR(org.btrplace.model.constraint.MinMTTR) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) Test(org.testng.annotations.Test)

Example 2 with Spread

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

the class IssuesTest method test16b.

/**
 * Unit test derived from Issue 16.
 *
 * @throws org.btrplace.scheduler.SchedulerException
 */
@Test
public void test16b() throws SchedulerException {
    Model model = new DefaultModel();
    Node n1 = model.newNode();
    Node n2 = model.newNode();
    Node n3 = model.newNode();
    Node n4 = model.newNode();
    VM vm1 = model.newVM();
    VM vm2 = model.newVM();
    VM vm3 = model.newVM();
    VM vm4 = model.newVM();
    VM vm5 = model.newVM();
    VM vm6 = model.newVM();
    model.getMapping().on(n1, n2, n3, n4).run(n1, vm1, vm2).run(n2, vm3, vm4).run(n3, vm5, vm6);
    Set<SatConstraint> ctrsC = new HashSet<>();
    Set<VM> vms1 = new HashSet<>(Arrays.asList(vm1, vm3, vm5));
    Set<VM> vms2 = new HashSet<>(Arrays.asList(vm2, vm4, vm6));
    ctrsC.add(new Spread(vms1));
    ctrsC.add(new Spread(vms2));
    ctrsC.add(new Fence(vm3, Collections.singleton(n1)));
    Offline off = new Offline(n2);
    ctrsC.add(off);
    ChocoScheduler cra = new DefaultChocoScheduler();
    ReconfigurationPlan dp = cra.solve(model, ctrsC);
    Assert.assertNotNull(dp);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Offline(org.btrplace.model.constraint.Offline) Spread(org.btrplace.model.constraint.Spread) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Fence(org.btrplace.model.constraint.Fence) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 3 with Spread

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

the class Bench method makeApp.

private static int makeApp(Instance i, int remainder, List<Collection<Node>> edges) {
    int curMax = Math.min(remainder, 30);
    if (remainder - 30 < 6) {
        curMax = remainder / 2;
    } else {
        curMax = Math.min(curMax, rnd.nextInt(30 - 6) + 6);
    }
    // at least 2 VMs, at most max - 4 (2 per tiers)
    int nbT1 = curMax == 6 ? 2 : rnd.nextInt(curMax - 4 - 2) + 2;
    curMax -= nbT1;
    int nbT2 = curMax == 4 ? 2 : rnd.nextInt(curMax - 2 - 2) + 2;
    int nbT3 = curMax - nbT2;
    int nbVMs = nbT1 + nbT2 + nbT3;
    Model mo = i.getModel();
    Set<VM> t1 = makeVMSet(mo, nbT1);
    Set<VM> t2 = makeVMSet(mo, nbT2);
    Set<VM> t3 = makeVMSet(mo, nbT3);
    // Make the constraints
    i.getSatConstraints().add(new Spread(t1, true));
    i.getSatConstraints().add(new Spread(t2, true));
    i.getSatConstraints().add(new Spread(t3, true));
    i.getSatConstraints().add(new Among(t3, edges, false));
    // Place the VMs
    // Pick a random edge, and place every VMs on it
    int myEdge = rnd.nextInt(edges.size());
    Collection<Node> nodes = edges.get(myEdge);
    Node n = nodes.iterator().next();
    t1.stream().map(v -> mo.getMapping().addRunningVM(v, n));
    t2.stream().map(v -> mo.getMapping().addRunningVM(v, n));
    t3.stream().map(v -> mo.getMapping().addRunningVM(v, n));
    return nbVMs;
}
Also used : Spread(org.btrplace.model.constraint.Spread) Among(org.btrplace.model.constraint.Among)

Example 4 with Spread

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

the class ChocoMapperTest method testMap.

@Test(dependsOnMethods = { "testInstantiate" })
public void testMap() {
    Model mo = new DefaultModel();
    ChocoMapper map = ChocoMapper.newBundle();
    Spread s = new Spread(Collections.singleton(mo.newVM()));
    ChocoConstraint c = map.get(s);
    Assert.assertTrue(c.getClass().equals(CSpread.class));
    map.unMapConstraint(Spread.class);
    map.mapConstraint(Spread.class, CSpread.class);
    c = map.get(s);
    Assert.assertTrue(c.getClass().equals(CSpread.class));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Spread(org.btrplace.model.constraint.Spread) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 5 with Spread

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

the class CMinMigrationsTest method testWithFreeNodes.

/**
 * Issue #137.
 * ShutdownableNode.isOnline() is not instantiated at the end of the problem
 */
@Test
public void testWithFreeNodes() {
    Model mo = new DefaultModel();
    Node n0 = mo.newNode();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    VM v1 = mo.newVM();
    VM v2 = mo.newVM();
    DefaultChocoScheduler s = new DefaultChocoScheduler();
    mo.getMapping().on(n0, n1, n2).run(n0, v1, v2);
    Instance i = new Instance(mo, Arrays.asList(new Spread(mo.getMapping().getAllVMs(), false)), new MinMigrations());
    ReconfigurationPlan p = s.solve(i);
    Assert.assertNotNull(p);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Spread(org.btrplace.model.constraint.Spread) Instance(org.btrplace.model.Instance) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Node(org.btrplace.model.Node) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) MinMigrations(org.btrplace.model.constraint.MinMigrations) Test(org.testng.annotations.Test)

Aggregations

Spread (org.btrplace.model.constraint.Spread)9 Test (org.testng.annotations.Test)7 DefaultModel (org.btrplace.model.DefaultModel)6 Model (org.btrplace.model.Model)5 HashSet (java.util.HashSet)3 VM (org.btrplace.model.VM)3 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)3 Instance (org.btrplace.model.Instance)2 Node (org.btrplace.model.Node)2 MinMTTR (org.btrplace.model.constraint.MinMTTR)2 SatConstraint (org.btrplace.model.constraint.SatConstraint)2 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)1 Among (org.btrplace.model.constraint.Among)1 Fence (org.btrplace.model.constraint.Fence)1 MinMigrations (org.btrplace.model.constraint.MinMigrations)1 Offline (org.btrplace.model.constraint.Offline)1 RunningCapacity (org.btrplace.model.constraint.RunningCapacity)1