Search in sources :

Example 6 with ShareableResource

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

the class AllocateEventTest method testApply.

@Test
public void testApply() {
    AllocateEvent na = new AllocateEvent(vms.get(0), "foo", 3);
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    map.addOnlineNode(ns.get(0));
    map.addRunningVM(vms.get(0), ns.get(0));
    Assert.assertFalse(na.apply(mo));
    ShareableResource rc = new ShareableResource("foo");
    mo.attach(rc);
    Assert.assertTrue(na.apply(mo));
    Assert.assertEquals(3, rc.getConsumption(vms.get(0)));
}
Also used : ShareableResource(org.btrplace.model.view.ShareableResource) Test(org.testng.annotations.Test)

Example 7 with ShareableResource

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

the class LinearToAResourceActionDuration method evaluate.

@Override
public int evaluate(Model mo, E e) {
    ShareableResource r = ShareableResource.get(mo, rc);
    if (r == null) {
        return -1;
    }
    int x;
    if (e instanceof VM) {
        x = r.getConsumption((VM) e);
    } else if (e instanceof Node) {
        x = r.getCapacity((Node) e);
    } else {
        return -1;
    }
    return (int) Math.round(coefficient * x + offset);
}
Also used : VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) ShareableResource(org.btrplace.model.view.ShareableResource)

Example 8 with ShareableResource

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

the class IssuesTest method testIssue89.

@Test
public static void testIssue89() throws Exception {
    final Model model = new DefaultModel();
    final Mapping mapping = model.getMapping();
    final Node node0 = model.newNode(0);
    final int[] ids0 = { 1, 45, 43, 40, 39, 38, 82, 80, 79, 78, 30, 75, 18, 16, 15, 14, 60, 9, 55, 54, 50, 48 };
    final Node node1 = model.newNode(1);
    final int[] ids1 = { 84, 83, 81, 77, 73, 71, 64, 63, 62, 57, 53, 52, 47, 46, 44, 41, 34, 31, 28, 25, 13, 8, 6, 4, 3, 0 };
    final Node node2 = model.newNode(2);
    final int[] ids2 = { 21, 67, 42, 36, 35, 33, 76, 74, 23, 69, 68, 20, 61, 12, 11, 10, 5, 51 };
    final Node node3 = model.newNode(3);
    final int[] ids3 = { 2, 66, 86, 85, 37, 32, 29, 27, 26, 72, 24, 70, 22, 19, 65, 17, 59, 58, 56, 7, 49 };
    final ShareableResource cpu = new ShareableResource("cpu", 45, 1);
    final ShareableResource mem = new ShareableResource("mem", 90, 2);
    populateNodeVm(model, mapping, node0, ids0);
    populateNodeVm(model, mapping, node1, ids1);
    populateNodeVm(model, mapping, node2, ids2);
    populateNodeVm(model, mapping, node3, ids3);
    model.attach(cpu);
    model.attach(mem);
    final Collection<SatConstraint> satConstraints = new ArrayList<>();
    // We want to cause Node 3 to go offline to see how the VMs hosted on that
    // node will get rebalanced.
    satConstraints.add(new Offline(node3));
    final OptConstraint optConstraint = new MinMTTR();
    DefaultChocoScheduler scheduler = new DefaultChocoScheduler();
    scheduler.doOptimize(false);
    scheduler.doRepair(true);
    scheduler.setTimeLimit(60000);
    ReconfigurationPlan plan = scheduler.solve(model, satConstraints, optConstraint);
    System.out.println(scheduler.getStatistics());
    Assert.assertTrue(plan.isApplyable());
    satConstraints.clear();
    // This is somewhat similar to making Node 3 going offline by ensuring that
    // all VMs can no longer get hosted on that node.
    satConstraints.addAll(mapping.getAllVMs().stream().map(vm -> new Ban(vm, Collections.singletonList(node3))).collect(Collectors.toList()));
    scheduler = new DefaultChocoScheduler();
    scheduler.doOptimize(false);
    scheduler.doRepair(true);
    plan = scheduler.solve(model, satConstraints, optConstraint);
    Assert.assertTrue(plan.isApplyable());
}
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) MinMTTR(org.btrplace.model.constraint.MinMTTR) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) Offline(org.btrplace.model.constraint.Offline) Mapping(org.btrplace.model.Mapping) ShareableResource(org.btrplace.model.view.ShareableResource) Ban(org.btrplace.model.constraint.Ban) OptConstraint(org.btrplace.model.constraint.OptConstraint) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 9 with ShareableResource

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

the class IssuesTest method issue19.

@Test
public void issue19() {
    Model m = new DefaultModel();
    ShareableResource cpu = new ShareableResource("cpu", 4, 1);
    Node n = m.newNode();
    Node n2 = m.newNode();
    m.attach(cpu);
    Assert.assertEquals(cpu.sumCapacities(Arrays.asList(n, n2), true), 8);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) ShareableResource(org.btrplace.model.view.ShareableResource) Test(org.testng.annotations.Test)

Example 10 with ShareableResource

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

the class IssuesTest method issue72b.

@Test
public void issue72b() throws SchedulerException {
    Model mo = new DefaultModel();
    Mapping ma = mo.getMapping();
    ShareableResource rcCPU = new ShareableResource("cpu", 2, 0);
    mo.attach(rcCPU);
    List<Node> nodes = new ArrayList<>();
    for (int i = 0; i < 2; i++) {
        nodes.add(mo.newNode());
        ma.addOnlineNode(nodes.get(i));
    }
    for (int i = 0; i < 1; i++) {
        VM v = mo.newVM();
        ma.addRunningVM(v, nodes.get(0));
    }
    for (int i = 0; i < 2; i++) {
        VM v = mo.newVM();
        ma.addRunningVM(v, nodes.get(1));
    }
    DefaultParameters ps = new DefaultParameters();
    ReconfigurationPlan p = new DefaultChocoScheduler(ps).solve(mo, new ArrayList<>());
    Assert.assertNotNull(p);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) Mapping(org.btrplace.model.Mapping) ShareableResource(org.btrplace.model.view.ShareableResource) OptConstraint(org.btrplace.model.constraint.OptConstraint) Constraint(org.chocosolver.solver.constraints.Constraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) 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