Search in sources :

Example 66 with ShareableResource

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

the class CShareableResourceTest method testInitiallyUnsatisfied.

@Test
public void testInitiallyUnsatisfied() throws SchedulerException {
    Model mo = new DefaultModel();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    ShareableResource rc = new ShareableResource("cpu", 1, 1);
    VM v1 = mo.newVM();
    VM v2 = mo.newVM();
    mo.getMapping().addOnlineNode(n1);
    mo.getMapping().addOnlineNode(n2);
    mo.getMapping().addRunningVM(v1, n1);
    mo.getMapping().addRunningVM(v2, n1);
    mo.attach(rc);
    ChocoScheduler s = new DefaultChocoScheduler();
    try {
        Assert.assertNull(s.solve(mo, new ArrayList<>()));
        Assert.fail("Should have thrown an exception");
    } catch (@SuppressWarnings("unused") SchedulerException e) {
        Assert.assertEquals(s.getStatistics().getMetrics().backtracks(), 0);
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) SchedulerException(org.btrplace.scheduler.SchedulerException) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) ArrayList(java.util.ArrayList) ShareableResource(org.btrplace.model.view.ShareableResource) Test(org.testng.annotations.Test)

Example 67 with ShareableResource

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

the class CShareableResourceTest method testMisplaced.

@Test
public void testMisplaced() throws SchedulerException {
    Model mo = new DefaultModel();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    ShareableResource rc = new ShareableResource("cpu", 10, 1);
    VM v1 = mo.newVM();
    VM v2 = mo.newVM();
    mo.getMapping().addOnlineNode(n1);
    mo.getMapping().addOnlineNode(n2);
    mo.getMapping().addRunningVM(v1, n1);
    mo.getMapping().addRunningVM(v2, n1);
    mo.attach(rc);
    List<SatConstraint> l = new ArrayList<>();
    l.addAll(Preserve.newPreserve(mo.getMapping().getAllVMs(), "cpu", 5));
    ChocoScheduler s = new DefaultChocoScheduler();
    s.doRepair(true);
    ReconfigurationPlan p = s.solve(mo, l);
    Assert.assertEquals(s.getStatistics().getNbManagedVMs(), 0);
    Assert.assertNotNull(p);
    Assert.assertEquals(p.getResult().getMapping(), mo.getMapping());
    Assert.assertEquals(p.getSize(), 2);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) ArrayList(java.util.ArrayList) ShareableResource(org.btrplace.model.view.ShareableResource) Test(org.testng.annotations.Test)

Example 68 with ShareableResource

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

the class GettingStarted method makeModel.

/**
 * Make a model with 4 online nodes, 6 VMs (5 running, 1 ready).
 * Declare 2 resources.
 */
private Model makeModel() {
    Model model = new DefaultModel();
    Mapping map = model.getMapping();
    // Create 4 online nodes
    for (int i = 0; i < 4; i++) {
        Node n = model.newNode();
        nodes.add(n);
        map.addOnlineNode(n);
    }
    // Create 6 VMs: vm0..vm5
    for (int i = 0; i < 6; i++) {
        VM v = model.newVM();
        vms.add(v);
    }
    // vm2,vm1,vm0,vm3,vm5 are running on the nodes
    map.addRunningVM(vms.get(2), nodes.get(0));
    map.addRunningVM(vms.get(1), nodes.get(1));
    map.addRunningVM(vms.get(0), nodes.get(2));
    map.addRunningVM(vms.get(3), nodes.get(2));
    map.addRunningVM(vms.get(5), nodes.get(3));
    // vm4 is ready to be running on a node.
    map.addReadyVM(vms.get(4));
    // Declare a view to specify the "cpu" physical capacity of the nodes
    // and the virtual consumption of the VMs.
    // By default, nodes have 8 "cpu" resources
    ShareableResource rcCPU = new ShareableResource("cpu", 8, 0);
    rcCPU.setConsumption(vms.get(0), 2);
    rcCPU.setConsumption(vms.get(1), 3);
    rcCPU.setConsumption(vms.get(2), 4);
    rcCPU.setConsumption(vms.get(3), 3);
    rcCPU.setConsumption(vms.get(5), 5);
    // By default, nodes have 7 "mem" resources
    ShareableResource rcMem = new ShareableResource("mem", 7, 0);
    rcMem.setConsumption(vms.get(0), 2);
    rcMem.setConsumption(vms.get(1), 2);
    rcMem.setConsumption(vms.get(2), 4);
    rcMem.setConsumption(vms.get(3), 3);
    rcMem.setConsumption(vms.get(5), 4);
    // Attach the resources
    model.attach(rcCPU);
    model.attach(rcMem);
    return model;
}
Also used : ShareableResource(org.btrplace.model.view.ShareableResource) org.btrplace.model.constraint(org.btrplace.model.constraint)

Example 69 with ShareableResource

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

the class SolverTuning method makeModel.

/**
 * A default model with 500 nodes hosting 3000 VMs.
 * 6 VMs per node
 * Each node has a 10GB network interface and 32 GB RAM
 * Each VM consumes 1GB Bandwidth and between 1 to 5 GB RAM
 */
private Model makeModel() {
    Model mo = new DefaultModel();
    Mapping mapping = mo.getMapping();
    int nbNodes = 300;
    int nbVMs = 6 * nbNodes;
    // Memory usage/consumption in GB
    ShareableResource rcMem = new ShareableResource("mem");
    // A resource representing the bandwidth usage/consumption of the elements in GB
    ShareableResource rcBW = new ShareableResource("bandwidth");
    nodes = new ArrayList<>(nbNodes);
    for (int i = 0; i < nbNodes; i++) {
        Node n = mo.newNode();
        nodes.add(n);
        mapping.addOnlineNode(n);
        // Each node provides a 10GB bandwidth and 32 GB RAM to its VMs
        rcBW.setCapacity(n, 10);
        rcMem.setCapacity(n, 32);
    }
    for (int i = 0; i < nbVMs; i++) {
        VM vm = mo.newVM();
        // Basic balancing through a round-robin: 6 VMs per node
        mapping.addRunningVM(vm, nodes.get(i % nodes.size()));
        // Each VM uses currently a 1GB bandwidth and 1,2 or 3 GB RAM
        rcBW.setConsumption(vm, 1);
        rcMem.setConsumption(vm, i % 5 + 1);
    }
    mo.attach(rcBW);
    mo.attach(rcMem);
    return mo;
}
Also used : MigrateVM(org.btrplace.plan.event.MigrateVM) ShareableResource(org.btrplace.model.view.ShareableResource) SatConstraint(org.btrplace.model.constraint.SatConstraint)

Example 70 with ShareableResource

use of org.btrplace.model.view.ShareableResource 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)

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