Search in sources :

Example 51 with SatConstraint

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

the class NetworkAndMigrations method run.

@Override
public void run() {
    // New default model
    Model mo = new DefaultModel();
    Mapping ma = mo.getMapping();
    // Create and boot 2 source nodes and 1 destination node
    Node srcNode1 = mo.newNode();
    Node srcNode2 = mo.newNode();
    Node dstNode = mo.newNode();
    ma.addOnlineNode(srcNode1);
    ma.addOnlineNode(srcNode2);
    ma.addOnlineNode(dstNode);
    // Create 4 VMs and host 2 VMs on each source node
    VM vm0 = mo.newVM();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    ma.addRunningVM(vm0, srcNode1);
    ma.addRunningVM(vm1, srcNode1);
    ma.addRunningVM(vm2, srcNode2);
    ma.addRunningVM(vm3, srcNode2);
    // Set VM attributes 'memory used', 'hot dirty page size', 'hot dirty page duration' and 'cold dirty pages rate'
    // vm0 and vm3 are 'idle' VMs (with no special memory activity) but they still consume some memory
    // 2 GiB
    mo.getAttributes().put(vm0, "memUsed", 2000);
    // 2.2 GiB
    mo.getAttributes().put(vm3, "memUsed", 2200);
    // vm1 and vm2 consume memory and have a memory intensive workload equivalent to "stress --vm 1000 --bytes 50K"
    // 8 GiB
    mo.getAttributes().put(vm1, "memUsed", 8000);
    mo.getAttributes().put(vm1, "hotDirtySize", 56);
    mo.getAttributes().put(vm1, "hotDirtyDuration", 2);
    mo.getAttributes().put(vm1, "coldDirtyRate", 22.6);
    // 7.5 GiB
    mo.getAttributes().put(vm2, "memUsed", 7500);
    mo.getAttributes().put(vm2, "hotDirtySize", 56);
    mo.getAttributes().put(vm2, "hotDirtyDuration", 2);
    mo.getAttributes().put(vm2, "coldDirtyRate", 22.6);
    // Add placement constraints: we want to shutdown the source nodes to force VMs migration to destination nodes
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.add(new Offline(srcNode1));
    cstrs.add(new Offline(srcNode2));
    // Try to solve as is and show the computed plan
    ReconfigurationPlan p = new DefaultChocoScheduler().solve(mo, cstrs);
    System.out.println(p);
    // Set a default network view and try to solve again
    // connect nodes to a non-blocking switch using 1 Gbit/s links
    Network net = Network.createDefaultNetwork(mo);
    p = new DefaultChocoScheduler().solve(mo, cstrs);
    System.out.println(p);
    // Create and attach a custom network view and try to solve again
    mo.detach(net);
    net = new Network();
    // Connect the nodes through a main non-blocking switch
    // The source nodes are connected with 1Gbit/sec. links while the destination node has 10Gbit/sec. link.
    Switch swMain = net.newSwitch();
    net.connect(1000, swMain, srcNode1, srcNode2);
    net.connect(10000, swMain, dstNode);
    mo.attach(net);
    p = new DefaultChocoScheduler().solve(mo, cstrs);
    System.out.println(p);
    System.out.flush();
}
Also used : SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) Offline(org.btrplace.model.constraint.Offline) Switch(org.btrplace.model.view.network.Switch) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Network(org.btrplace.model.view.network.Network)

Example 52 with SatConstraint

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

the class CMaxOnlineTest method complexContinuousTest2.

@Test
public void complexContinuousTest2() throws SchedulerException {
    Model model = new DefaultModel();
    Node n1 = model.newNode(1);
    Node n2 = model.newNode(2);
    Node n3 = model.newNode(3);
    Node n4 = model.newNode(4);
    Node n5 = model.newNode(5);
    VM vm1 = model.newVM();
    VM vm2 = model.newVM();
    VM vm3 = model.newVM();
    VM vm4 = model.newVM();
    ShareableResource resources = new ShareableResource("cpu", 2, 1);
    resources.setCapacity(n1, 4);
    resources.setCapacity(n2, 8);
    resources.setConsumption(vm4, 2);
    Mapping map = model.getMapping().on(n1, n2, n3).off(n4, n5).run(n1, vm1, vm4).run(n2, vm2).run(n3, vm3);
    MappingUtils.fill(map, model.getMapping());
    model.attach(resources);
    MaxOnline maxOn = new MaxOnline(map.getAllNodes(), 4, true);
    MaxOnline maxOn2 = new MaxOnline(new HashSet<>(Arrays.asList(n2, n3, n4)), 2, true);
    List<SatConstraint> constraints = new ArrayList<>();
    constraints.add(maxOn);
    constraints.add(maxOn2);
    constraints.addAll(Online.newOnline(Arrays.asList(n4, n5)));
    ChocoScheduler cra = new DefaultChocoScheduler();
    cra.setTimeLimit(3);
    cra.setMaxEnd(10);
    cra.getMapper().mapConstraint(MaxOnline.class, CMaxOnline.class);
    ReconfigurationPlan plan = cra.solve(model, constraints);
    Assert.assertNotNull(plan);
    Assert.assertTrue(maxOn.isSatisfied(plan));
}
Also used : SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ShareableResource(org.btrplace.model.view.ShareableResource) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) MaxOnline(org.btrplace.model.constraint.MaxOnline) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Test(org.testng.annotations.Test)

Example 53 with SatConstraint

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

the class CNoDelayTest method testOk1.

@Test
public void testOk1() throws SchedulerException {
    Model model = new DefaultModel();
    Node n1 = model.newNode();
    Node n2 = model.newNode();
    Node n3 = model.newNode();
    VM vm1 = model.newVM();
    VM vm2 = model.newVM();
    VM vm3 = model.newVM();
    VM vm4 = model.newVM();
    ShareableResource resources = new ShareableResource("cpu", 4, 1);
    resources.setCapacity(n2, 3);
    resources.setConsumption(vm1, 4);
    Mapping map = model.getMapping().on(n1, n2, n3).run(n1, vm1).run(n2, vm2).run(n3, vm3).run(n3, vm4);
    MappingUtils.fill(map, model.getMapping());
    model.attach(resources);
    Ban b = new Ban(vm1, Collections.singleton(n1));
    NoDelay nd = new NoDelay(vm3);
    // 1 solution (priority to vm3): vm3 to n2 ; vm4 to n2 ; vm1 to n3
    List<SatConstraint> constraints = new ArrayList<>();
    constraints.add(nd);
    constraints.add(b);
    ChocoScheduler cra = new DefaultChocoScheduler();
    cra.getMapper().mapConstraint(MaxOnline.class, CMaxOnline.class);
    ReconfigurationPlan plan = cra.solve(model, constraints);
    Assert.assertNotNull(plan);
    Assert.assertTrue(nd.isSatisfied(plan));
}
Also used : SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) ShareableResource(org.btrplace.model.view.ShareableResource) Ban(org.btrplace.model.constraint.Ban) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) NoDelay(org.btrplace.model.constraint.NoDelay) Test(org.testng.annotations.Test)

Example 54 with SatConstraint

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

the class CNoDelayTest method testKo.

@Test
public void testKo() throws SchedulerException {
    Model model = new DefaultModel();
    Node n1 = model.newNode();
    Node n2 = model.newNode();
    Node n3 = model.newNode();
    VM vm1 = model.newVM();
    VM vm2 = model.newVM();
    VM vm3 = model.newVM();
    VM vm4 = model.newVM();
    ShareableResource resources = new ShareableResource("cpu", 4, 1);
    resources.setCapacity(n2, 3);
    resources.setConsumption(vm1, 4);
    Mapping map = model.getMapping().on(n1, n2, n3).run(n1, vm1).run(n2, vm2).run(n3, vm3).run(n3, vm4);
    MappingUtils.fill(map, model.getMapping());
    model.attach(resources);
    Ban b = new Ban(vm1, Collections.singleton(n1));
    NoDelay nd = new NoDelay(vm1);
    // No solution: unable to migrate vm1 at t=0
    List<SatConstraint> constraints = new ArrayList<>();
    constraints.add(nd);
    constraints.add(b);
    ChocoScheduler cra = new DefaultChocoScheduler();
    cra.getMapper().mapConstraint(MaxOnline.class, CMaxOnline.class);
    ReconfigurationPlan plan = cra.solve(model, constraints);
    Assert.assertNull(plan);
}
Also used : SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) ShareableResource(org.btrplace.model.view.ShareableResource) Ban(org.btrplace.model.constraint.Ban) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) NoDelay(org.btrplace.model.constraint.NoDelay) Test(org.testng.annotations.Test)

Example 55 with SatConstraint

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

the class CPreserveTest method testPreserveWithoutOverbook.

/*@Test
    public void testGetMisplaced() {
        Model mo = new DefaultModel();
        VM vm1 = mo.newVM();
        VM vm2 = mo.newVM();
        VM vm3 = mo.newVM();
        Node n1 = mo.newNode();
        Node n2 = mo.newNode();

        Mapping map = mo.getMapping().on(n1, n2).run(n1, vm1, vm2).run(n2, vm3).get();
        ShareableResource rc = new ShareableResource("cpu", 7, 7);
        rc.setConsumption(vm1, 3);
        rc.setConsumption(vm2, 3);
        rc.setConsumption(vm3, 5);

        Preserve p = new Preserve(vm1, "cpu", 5);

        mo.attach(rc);
        //Assert.assertEquals(SatConstraint.Sat.UNSATISFIED, p.isSatisfied(mo));

        CPreserve cp = new CPreserve(p);
        Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR());
        Set<VM> bads = cp.getMisPlacedVMs(i);
        Assert.assertEquals(1, bads.size());
        Assert.assertEquals(vm1, bads.iterator().next());
    }*/
/**
 * A preserve constraint asks for a minimum amount of resources but
 * their is no overbook ratio so, the default value of 1 is used
 * and vm1 or vm2 is moved to n2
 *
 * @throws org.btrplace.scheduler.SchedulerException
 */
@Test
public void testPreserveWithoutOverbook() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Mapping map = mo.getMapping().on(n1, n2).run(n1, vm1, vm2).run(n2, vm3);
    ShareableResource rc = new ShareableResource("cpu", 10, 10);
    rc.setCapacity(n1, 7);
    rc.setConsumption(vm1, 3);
    rc.setConsumption(vm2, 3);
    rc.setConsumption(vm3, 5);
    Preserve pr = new Preserve(vm2, "cpu", 5);
    ChocoScheduler cra = new DefaultChocoScheduler();
    mo.attach(rc);
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.addAll(Online.newOnline(map.getAllNodes()));
    cstrs.add(pr);
    ReconfigurationPlan p = cra.solve(mo, cstrs);
    Assert.assertNotNull(p);
}
Also used : SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) ShareableResource(org.btrplace.model.view.ShareableResource) Preserve(org.btrplace.model.constraint.Preserve) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Test(org.testng.annotations.Test)

Aggregations

SatConstraint (org.btrplace.model.constraint.SatConstraint)78 Test (org.testng.annotations.Test)54 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)43 ArrayList (java.util.ArrayList)39 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)38 DefaultModel (org.btrplace.model.DefaultModel)33 ShareableResource (org.btrplace.model.view.ShareableResource)30 VM (org.btrplace.model.VM)27 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)27 Node (org.btrplace.model.Node)23 Model (org.btrplace.model.Model)20 HashSet (java.util.HashSet)17 Fence (org.btrplace.model.constraint.Fence)16 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)14 Network (org.btrplace.model.view.network.Network)14 Offline (org.btrplace.model.constraint.Offline)13 Switch (org.btrplace.model.view.network.Switch)13 MigrateVM (org.btrplace.plan.event.MigrateVM)13 MinMTTRMig (org.btrplace.model.constraint.migration.MinMTTRMig)11 Preserve (org.btrplace.model.constraint.Preserve)9