Search in sources :

Example 56 with SatConstraint

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

the class CRootTest method testBasic.

@Test
public void testBasic() 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).ready(vm3);
    ChocoScheduler cra = new DefaultChocoScheduler();
    cra.doRepair(false);
    Root r1 = new Root(vm1);
    List<SatConstraint> l = new ArrayList<>();
    l.add(r1);
    l.addAll(Online.newOnline(map.getAllNodes()));
    ReconfigurationPlan p = cra.solve(mo, l);
    Assert.assertNotNull(p);
    Model res = p.getResult();
    Assert.assertEquals(n1, res.getMapping().getVMLocation(vm1));
}
Also used : DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) Root(org.btrplace.model.constraint.Root) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 57 with SatConstraint

use of org.btrplace.model.constraint.SatConstraint 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 58 with SatConstraint

use of org.btrplace.model.constraint.SatConstraint 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 59 with SatConstraint

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

the class CDeadlineTest method testOk.

@Test
public void testOk() throws SchedulerException {
    // 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(), srcNode2 = mo.newNode(), dstNode = mo.newNode();
    ma.addOnlineNode(srcNode1);
    ma.addOnlineNode(srcNode2);
    ma.addOnlineNode(dstNode);
    // Attach a network view
    Network net = new Network();
    mo.attach(net);
    // Connect the nodes through a main non-blocking switch
    // The destination node have twice the bandwidth of source nodes
    Switch swMain = net.newSwitch();
    net.connect(1000, swMain, srcNode1, srcNode2);
    net.connect(2000, swMain, dstNode);
    // Create and host 1 VM per source node
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    ma.addRunningVM(vm1, srcNode1);
    ma.addRunningVM(vm2, srcNode2);
    // Attach CPU and Mem resource views and assign nodes capacity and VMs consumption
    int mem_vm = 8, cpu_vm = 4, mem_src = 8, cpu_src = 4, mem_dst = 16, cpu_dst = 8;
    ShareableResource rcMem = new ShareableResource("mem", 0, 0), rcCPU = new ShareableResource("cpu", 0, 0);
    mo.attach(rcMem);
    mo.attach(rcCPU);
    // VMs
    rcMem.setConsumption(vm1, mem_vm).setConsumption(vm2, mem_vm);
    rcCPU.setConsumption(vm1, cpu_vm).setConsumption(vm2, cpu_vm);
    // Nodes
    rcMem.setCapacity(srcNode1, mem_src).setCapacity(srcNode2, mem_src).setCapacity(dstNode, mem_dst);
    rcCPU.setCapacity(srcNode1, cpu_src).setCapacity(srcNode2, cpu_src).setCapacity(dstNode, cpu_dst);
    // Set VM attributes 'memory used', 'hot dirty page size', 'hot dirty page duration' and 'cold dirty pages rate'
    int vm_mu = 6000, vm_mds = 46, vm_mdd = 2;
    double vm_cdr = 23.6;
    // vm1 is an 'idle' VM (with no special memory activity) but still consumes 6 GiB of memory
    mo.getAttributes().put(vm1, "memUsed", vm_mu);
    // vm2 consumes 6 GiB memory and has a memory intensive workload equivalent to "stress --vm 1000 --bytes 50K"
    // VM with a workload
    mo.getAttributes().put(vm2, "memUsed", vm_mu);
    mo.getAttributes().put(vm2, "hotDirtySize", vm_mds);
    mo.getAttributes().put(vm2, "hotDirtyDuration", vm_mdd);
    mo.getAttributes().put(vm2, "coldDirtyRate", vm_cdr);
    // Create constraints
    List<SatConstraint> cstrs = new ArrayList<>();
    // Placement constraints, we want to shutdown the source nodes to force the migration to destination nodes
    cstrs.add(new Offline(srcNode1));
    cstrs.add(new Offline(srcNode2));
    // SET A RELATIVE DEADLINE FOR THE MIGRATION OF VM2
    // 90s
    Deadline dead = new Deadline(vm2, "+00:01:30");
    cstrs.add(dead);
    // Solve it using the Min Max Time To Repair Migration scheduling oriented objective
    ReconfigurationPlan p = new DefaultChocoScheduler().solve(mo, cstrs, new MinMTTRMig());
    // It works because 30s is enough to fully migrate vm2
    Assert.assertNotNull(p);
    // Check if the deadline is respected
    Action mig1 = p.getActions().stream().filter(s -> s instanceof MigrateVM && ((MigrateVM) s).getVM().equals(vm1)).findAny().get();
    Assert.assertTrue(mig1.getEnd() <= 90);
    // TODO: use methods on DeadlineChecker to verify that the action terminates at time ?
    Assert.assertTrue(dead.isSatisfied(p));
}
Also used : Action(org.btrplace.plan.event.Action) SatConstraint(org.btrplace.model.constraint.SatConstraint) Deadline(org.btrplace.model.constraint.migration.Deadline) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) Offline(org.btrplace.model.constraint.Offline) MigrateVM(org.btrplace.plan.event.MigrateVM) ShareableResource(org.btrplace.model.view.ShareableResource) SatConstraint(org.btrplace.model.constraint.SatConstraint) MinMTTRMig(org.btrplace.model.constraint.migration.MinMTTRMig) Switch(org.btrplace.model.view.network.Switch) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Network(org.btrplace.model.view.network.Network) MigrateVM(org.btrplace.plan.event.MigrateVM) Test(org.testng.annotations.Test)

Example 60 with SatConstraint

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

the class CPrecedenceTest method testOk.

@Test
public void testOk() throws SchedulerException {
    // 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(), srcNode2 = mo.newNode(), dstNode = mo.newNode();
    ma.addOnlineNode(srcNode1);
    ma.addOnlineNode(srcNode2);
    ma.addOnlineNode(dstNode);
    // Attach a network view
    Network net = new Network();
    mo.attach(net);
    // Connect the nodes through a main non-blocking switch
    // The destination node have twice the bandwidth of source nodes
    Switch swMain = net.newSwitch();
    net.connect(1000, swMain, srcNode1, srcNode2);
    net.connect(2000, swMain, dstNode);
    // Create and host 1 VM per source node
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    ma.addRunningVM(vm1, srcNode1);
    ma.addRunningVM(vm2, srcNode2);
    // Attach CPU and Mem resource views and assign nodes capacity and VMs consumption
    int mem_vm = 8, cpu_vm = 4, mem_src = 8, cpu_src = 4, mem_dst = 16, cpu_dst = 8;
    ShareableResource rcMem = new ShareableResource("mem", 0, 0), rcCPU = new ShareableResource("cpu", 0, 0);
    mo.attach(rcMem);
    mo.attach(rcCPU);
    // VMs
    rcMem.setConsumption(vm1, mem_vm).setConsumption(vm2, mem_vm);
    rcCPU.setConsumption(vm1, cpu_vm).setConsumption(vm2, cpu_vm);
    // Nodes
    rcMem.setCapacity(srcNode1, mem_src).setCapacity(srcNode2, mem_src).setCapacity(dstNode, mem_dst);
    rcCPU.setCapacity(srcNode1, cpu_src).setCapacity(srcNode2, cpu_src).setCapacity(dstNode, cpu_dst);
    // Set VM attributes 'memory used', 'hot dirty page size', 'hot dirty page duration' and 'cold dirty pages rate'
    int vm_mu = 6000, vm_mds = 46, vm_mdd = 2;
    double vm_cdr = 23.6;
    // vm1 is an 'idle' VM (with no special memory activity) but still consumes 6 GiB of memory
    mo.getAttributes().put(vm1, "memUsed", vm_mu);
    // vm2 consumes 6 GiB memory and has a memory intensive workload equivalent to "stress --vm 1000 --bytes 50K"
    // VM with a workload
    mo.getAttributes().put(vm2, "memUsed", vm_mu);
    mo.getAttributes().put(vm2, "hotDirtySize", vm_mds);
    mo.getAttributes().put(vm2, "hotDirtyDuration", vm_mdd);
    mo.getAttributes().put(vm2, "coldDirtyRate", vm_cdr);
    // Create constraints
    List<SatConstraint> cstrs = new ArrayList<>();
    // Placement constraints, we want to shutdown the source nodes to force the migration to destination nodes
    cstrs.add(new Offline(srcNode1));
    cstrs.add(new Offline(srcNode2));
    // MIGRATE VM2 BEFORE VM1
    Precedence prec = new Precedence(vm2, vm1);
    cstrs.add(prec);
    // Solve it using the Min Max Time To Repair Migration scheduling oriented objective
    ReconfigurationPlan p = new DefaultChocoScheduler().solve(mo, cstrs, new MinMTTRMig());
    Assert.assertNotNull(p);
    // Check if the precedence constraint is respected
    Action mig1 = p.getActions().stream().filter(s -> s instanceof MigrateVM && ((MigrateVM) s).getVM().equals(vm1)).findAny().get();
    Action mig2 = p.getActions().stream().filter(s -> s instanceof MigrateVM && ((MigrateVM) s).getVM().equals(vm2)).findAny().get();
    Assert.assertTrue(mig1.getStart() >= mig2.getEnd());
    // TODO: use methods on PrecedenceChecker to verify that the migrations are in the expected order ?
    Assert.assertTrue(prec.isSatisfied(p));
}
Also used : Action(org.btrplace.plan.event.Action) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) Offline(org.btrplace.model.constraint.Offline) MigrateVM(org.btrplace.plan.event.MigrateVM) ShareableResource(org.btrplace.model.view.ShareableResource) SatConstraint(org.btrplace.model.constraint.SatConstraint) MinMTTRMig(org.btrplace.model.constraint.migration.MinMTTRMig) Switch(org.btrplace.model.view.network.Switch) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Network(org.btrplace.model.view.network.Network) MigrateVM(org.btrplace.plan.event.MigrateVM) Precedence(org.btrplace.model.constraint.migration.Precedence) 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