Search in sources :

Example 36 with ShareableResource

use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.

the class CResourceCapacityTest method testDiscreteSolvable.

/*@Test
    public void testSingleGetMisplaced() {
        Model mo = new DefaultModel();
        VM vm2 = mo.newVM();
        VM vm3 = mo.newVM();
        Node n2 = mo.newNode();
        Mapping map = mo.getMapping().on(n2).run(n2, vm2, vm3);

        org.btrplace.model.view.ShareableResource rc = new ShareableResource("cpu", 5, 5);
        rc.setConsumption(vm2, 3);
        rc.setConsumption(vm3, 1);

        mo.attach(rc);

        Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR());
        ResourceCapacity s = new ResourceCapacity(n2, "cpu", 4);
        CResourceCapacity cs = new CResourceCapacity(s);
        Assert.assertTrue(cs.getMisPlacedVMs(i).isEmpty());
        rc.setConsumption(vm3, 2);
        Assert.assertEquals(cs.getMisPlacedVMs(i), map.getRunningVMs(n2));
    }*/
@Test
public void testDiscreteSolvable() 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();
    mo.getMapping().on(n1, n2).run(n1, vm1, vm2);
    ShareableResource rc = new ShareableResource("cpu", 5, 5);
    rc.setConsumption(vm1, 3);
    rc.setConsumption(vm2, 1);
    rc.setConsumption(vm3, 1);
    mo.attach(rc);
    ResourceCapacity s = new ResourceCapacity(n1, "cpu", 4);
    ChocoScheduler cra = new DefaultChocoScheduler();
    ReconfigurationPlan p = cra.solve(mo, Arrays.asList(s, new Preserve(vm2, "cpu", 3)));
    Assert.assertNotNull(p);
    Assert.assertEquals(p.getSize(), 1);
// System.out.println(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) ShareableResource(org.btrplace.model.view.ShareableResource) Test(org.testng.annotations.Test)

Example 37 with ShareableResource

use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.

the class CDeadlineTest method testKo.

@Test
public void testKo() 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 with 1 Gbit/s links
    Switch swMain = net.newSwitch();
    net.connect(1000, swMain, srcNode1, srcNode2);
    net.connect(1000, 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 TOO SHORT DEADLINE FOR THE MIGRATION OF VM2
    // 30s
    Deadline dead = new Deadline(vm2, "+00:00:30");
    cstrs.add(dead);
    // Try to solve it using the Min Max Time To Repair Migration scheduling oriented objective
    ReconfigurationPlan p = new DefaultChocoScheduler().solve(mo, cstrs, new MinMTTRMig());
    Assert.assertNull(p);
}
Also used : 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) 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 38 with ShareableResource

use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.

the class CMinMigrationsTest method simpleTest.

@Test
public void simpleTest() {
    Model mo = new DefaultModel();
    Node n0 = mo.newNode();
    Node n1 = mo.newNode();
    VM vm0 = mo.newVM();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    mo.getMapping().on(n0, n1).run(n0, vm0, vm1, vm2);
    ShareableResource mem = new ShareableResource("mem", 5, 1);
    // cpu dimension to create the violation
    ShareableResource cpu = new ShareableResource("cpu", 5, 1);
    // VM0 as the big VM
    mem.setConsumption(vm0, 3);
    mo.attach(cpu);
    mo.attach(mem);
    List<SatConstraint> cstrs = new ArrayList<>();
    // The 3 VMs no longer feet on n0
    cstrs.add(new Preserve(vm0, "cpu", 5));
    ChocoScheduler s = new DefaultChocoScheduler();
    s.doOptimize(true);
    ReconfigurationPlan p = s.solve(mo, cstrs, new MinMigrations());
    System.out.println(s.getStatistics());
    System.out.println(p);
    // VM0 to n1
    Assert.assertEquals(p.getActions().size(), 1);
    // VM0 to n1
    Assert.assertEquals(p.getResult().getMapping().getVMLocation(vm0), n1);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) 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) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) MinMigrations(org.btrplace.model.constraint.MinMigrations) Test(org.testng.annotations.Test)

Example 39 with ShareableResource

use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.

the class LinearToAResourceDurationTest method testSimple.

@Test
public void testSimple() {
    ShareableResource rc = new ShareableResource("foo", 0, 0);
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    mo.attach(rc);
    rc.setConsumption(vm1, 3);
    LinearToAResourceActionDuration<VM> d = new LinearToAResourceActionDuration<>("foo", 3);
    System.out.println(d.toString());
    Assert.assertEquals(d.getCoefficient(), 3.0);
    Assert.assertEquals(d.getOffset(), 0.0);
    Assert.assertEquals(d.getResourceId(), "foo");
    Assert.assertEquals(d.evaluate(mo, vm1), 9);
    Assert.assertEquals(d.evaluate(mo, vm2), 0);
    d = new LinearToAResourceActionDuration<>("foo", 3, 4);
    Assert.assertEquals(d.evaluate(mo, vm1), 13);
    Assert.assertEquals(d.evaluate(mo, vm3), 4);
    d = new LinearToAResourceActionDuration<>("bar", 3, 4);
    Assert.assertEquals(d.evaluate(mo, vm3), -1);
    d.setCoefficient(5);
    d.setOffset(12);
    d.setResourceId("bar");
    Assert.assertEquals(d.getCoefficient(), 5.0);
    Assert.assertEquals(d.getOffset(), 12.0);
    Assert.assertEquals(d.getResourceId(), "bar");
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) ShareableResource(org.btrplace.model.view.ShareableResource) Test(org.testng.annotations.Test)

Example 40 with ShareableResource

use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.

the class CResourceCapacity method getMisPlacedVMs.

@Override
public Set<VM> getMisPlacedVMs(Instance i) {
    if (cstr.getInvolvedNodes().size() <= 1) {
        // If there is only a single node, we delegate this work to CShareableResource.
        return Collections.emptySet();
    }
    Mapping map = i.getModel().getMapping();
    ShareableResource rc = ShareableResource.get(i.getModel(), cstr.getResource());
    if (rc == null) {
        return map.getRunningVMs(cstr.getInvolvedNodes());
    }
    Set<VM> bad = new HashSet<>();
    int remainder = cstr.getAmount();
    for (Node n : cstr.getInvolvedNodes()) {
        for (VM v : map.getRunningVMs(n)) {
            remainder -= rc.getConsumption(v);
            if (remainder < 0) {
                for (Node n2 : cstr.getInvolvedNodes()) {
                    bad.addAll(map.getRunningVMs(n2));
                }
                return bad;
            }
        }
    }
    return bad;
}
Also used : VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Mapping(org.btrplace.model.Mapping) CShareableResource(org.btrplace.scheduler.choco.view.CShareableResource) ShareableResource(org.btrplace.model.view.ShareableResource) HashSet(java.util.HashSet)

Aggregations

ShareableResource (org.btrplace.model.view.ShareableResource)86 Test (org.testng.annotations.Test)61 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)47 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)41 SatConstraint (org.btrplace.model.constraint.SatConstraint)32 ArrayList (java.util.ArrayList)31 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)29 VM (org.btrplace.model.VM)27 Model (org.btrplace.model.Model)25 Node (org.btrplace.model.Node)25 DefaultModel (org.btrplace.model.DefaultModel)22 MigrateVM (org.btrplace.plan.event.MigrateVM)16 Mapping (org.btrplace.model.Mapping)13 Network (org.btrplace.model.view.network.Network)12 Switch (org.btrplace.model.view.network.Switch)12 Offline (org.btrplace.model.constraint.Offline)11 MinMTTRMig (org.btrplace.model.constraint.migration.MinMTTRMig)10 SchedulerException (org.btrplace.scheduler.SchedulerException)10 Fence (org.btrplace.model.constraint.Fence)7 Preserve (org.btrplace.model.constraint.Preserve)7