Search in sources :

Example 6 with Running

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

the class RunningSplitterTest method simpleTest.

@Test
public void simpleTest() {
    RunningSplitter splitter = new RunningSplitter();
    List<Instance> instances = new ArrayList<>();
    Model origin = new DefaultModel();
    Node n1 = origin.newNode();
    Node n2 = origin.newNode();
    VM vm1 = origin.newVM();
    VM vm2 = origin.newVM();
    VM vm3 = origin.newVM();
    VM vm4 = origin.newVM();
    /**
     * READY: vm1
     * n1 vm2
     * n2 (vm3) vm4
     */
    origin.getMapping().addOnlineNode(n1);
    origin.getMapping().addReadyVM(vm1);
    origin.getMapping().addRunningVM(vm2, n1);
    origin.getMapping().addOnlineNode(n2);
    origin.getMapping().addSleepingVM(vm3, n2);
    origin.getMapping().addRunningVM(vm4, n2);
    Model m0 = new DefaultModel();
    m0.newNode(n1.id());
    m0.newVM(vm1.id());
    m0.newVM(vm2.id());
    m0.getMapping().addOnlineNode(n1);
    m0.getMapping().addReadyVM(vm1);
    m0.getMapping().addRunningVM(vm2, n1);
    Model m1 = new DefaultModel();
    m1.newNode(n2.id());
    m1.newVM(vm3.id());
    m1.newVM(vm4.id());
    m1.getMapping().addOnlineNode(n2);
    m1.getMapping().addSleepingVM(vm3, n2);
    m1.getMapping().addRunningVM(vm4, n2);
    instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
    instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
    Set<VM> all = new HashSet<>(m0.getMapping().getAllVMs());
    all.addAll(m1.getMapping().getAllVMs());
    TIntIntHashMap index = Instances.makeVMIndex(instances);
    // Only VMs in m0
    Running single = new Running(vm1);
    Assert.assertTrue(splitter.split(single, null, instances, index, new TIntIntHashMap()));
    Assert.assertTrue(instances.get(0).getSatConstraints().contains(single));
    Assert.assertFalse(instances.get(1).getSatConstraints().contains(single));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) ArrayList(java.util.ArrayList) MinMTTR(org.btrplace.model.constraint.MinMTTR) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Running(org.btrplace.model.constraint.Running) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 7 with Running

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

the class VectorPackingTest method testSlotFilteringWithUniformVMs.

/**
 * 1GB free on every node and only 2GB VMs. We ask for booting a 2GB VM. No
 * solution detected immediately if the hosting capacity is capped to the
 * max number of VMs per node (100) as their sum will not exceed the
 * number of running VMs.
 */
@Test
public void testSlotFilteringWithUniformVMs() {
    int capa = 201;
    DefaultModel mo = new DefaultModel();
    Mapping map = mo.getMapping();
    ShareableResource mem = new ShareableResource("mem");
    ShareableResource cpu = new ShareableResource("cpu");
    ShareableResource ctrl = new ShareableResource("ctrl");
    mo.attach(mem);
    mo.attach(cpu);
    mo.attach(ctrl);
    Instance ii = new Instance(mo, new ArrayList<>(), new MinMigrations());
    for (int i = 0; i < 500; i++) {
        final Node no = mo.newNode();
        map.on(no);
        mem.setCapacity(no, capa);
        cpu.setCapacity(no, capa);
        ctrl.setCapacity(no, capa);
        // 1 left on every node.
        for (int j = 0; j < capa / 2; j++) {
            final VM vm = mo.newVM();
            map.run(no, vm);
            mem.setConsumption(vm, 2);
            cpu.setConsumption(vm, 2);
            ctrl.setConsumption(vm, 2);
        }
        final VM vm = mo.newVM();
        map.run(no, vm);
        mem.setConsumption(vm, 0);
        cpu.setConsumption(vm, 0);
        ctrl.setConsumption(vm, 0);
    }
    final VM p = mo.newVM();
    mem.setConsumption(p, 2);
    cpu.setConsumption(p, 2);
    ctrl.setConsumption(p, 2);
    map.addReadyVM(p);
    final ChocoScheduler sched = new DefaultChocoScheduler();
    ii.getSatConstraints().add(new Running(p));
    sched.doRepair(false);
    ReconfigurationPlan plan = sched.solve(ii);
    Assert.assertNull(plan);
    // The problem is stated during the initial propagation.
    SolvingStatistics stats = sched.getStatistics();
    Assert.assertEquals(0, stats.getMetrics().nodes());
    // With 0 size VMs, same conclusion.
    for (Node no : map.getOnlineNodes()) {
        final VM vm = mo.newVM();
        map.run(no, vm);
        mem.setConsumption(vm, 0);
        ctrl.setConsumption(vm, 0);
        cpu.setConsumption(vm, 0);
    }
    plan = sched.solve(ii);
    Assert.assertNull(plan);
    // The problem is stated during the initial propagation.
    stats = sched.getStatistics();
    Assert.assertEquals(0, stats.getMetrics().nodes());
    System.out.println(stats);
}
Also used : ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ShareableResource(org.btrplace.model.view.ShareableResource) Constraint(org.chocosolver.solver.constraints.Constraint) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Running(org.btrplace.model.constraint.Running) MinMigrations(org.btrplace.model.constraint.MinMigrations) SolvingStatistics(org.btrplace.scheduler.choco.runner.SolvingStatistics) Test(org.testng.annotations.Test)

Example 8 with Running

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

the class BootableNodeTest method testRequiredOnline.

@Test
public void testRequiredOnline() throws SchedulerException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    VM vm1 = mo.newVM();
    Node n1 = mo.newNode();
    map.addOfflineNode(n1);
    map.addReadyVM(vm1);
    ChocoScheduler s = new DefaultChocoScheduler();
    Parameters ps = s.getParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(BootNode.class, new ConstantActionDuration<>(5));
    dev.register(BootVM.class, new ConstantActionDuration<>(2));
    ReconfigurationPlan plan = s.solve(mo, Collections.singleton(new Running(vm1)));
    Assert.assertNotNull(plan);
    Assert.assertEquals(plan.getSize(), 2);
    for (Action a : plan.getActions()) {
        if (a instanceof BootNode) {
            Assert.assertEquals(a.getStart(), 0);
            Assert.assertEquals(a.getEnd(), 5);
        } else {
            Assert.assertEquals(a.getStart(), 5);
            Assert.assertEquals(a.getEnd(), 7);
        }
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Action(org.btrplace.plan.event.Action) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Parameters(org.btrplace.scheduler.choco.Parameters) BootNode(org.btrplace.plan.event.BootNode) Node(org.btrplace.model.Node) BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Mapping(org.btrplace.model.Mapping) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) BootVM(org.btrplace.plan.event.BootVM) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Running(org.btrplace.model.constraint.Running) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) Test(org.testng.annotations.Test)

Example 9 with Running

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

the class CSeqTest method testWithVMsWithNoTransitions.

@Test
public void testWithVMsWithNoTransitions() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    VM vm4 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    mo.getMapping().on(n1, n2).ready(vm1).run(n1, vm2, vm4).run(n2, vm3);
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.add(new Running(vm1));
    cstrs.add(new Running(vm2));
    cstrs.add(new Running(vm3));
    cstrs.add(new Ready(vm4));
    ChocoScheduler cra = new DefaultChocoScheduler();
    List<VM> seq = Arrays.asList(vm1, vm2, vm3, vm4);
    cstrs.add(new Seq(seq));
    ReconfigurationPlan plan = cra.solve(mo, cstrs);
    Assert.assertNotNull(plan);
// System.out.println(plan);
}
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) Ready(org.btrplace.model.constraint.Ready) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Running(org.btrplace.model.constraint.Running) Seq(org.btrplace.model.constraint.Seq) Test(org.testng.annotations.Test)

Example 10 with Running

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

the class CResourceCapacityTest method testCapacityEstimation.

/**
 * Test how CResourceCapacity notifies the view about the future capacity.
 */
@Test
public void testCapacityEstimation() {
    final Model mo = new DefaultModel();
    final Node n0 = mo.newNode();
    final Node n1 = mo.newNode();
    final VM vm = mo.newVM();
    final ShareableResource cpu = new ShareableResource("cpu");
    mo.attach(cpu);
    cpu.setCapacity(n0, 5).setCapacity(n1, 7);
    cpu.setConsumption(vm, 3);
    mo.getMapping().on(n0, n1).ready(vm);
    final List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.add(new Running(vm));
    final Instance i = new Instance(mo, cstrs, new MinMTTR());
    // Because of the worst-fit approach, the VM will go on n1 which has the
    // highest capacity.
    final ChocoScheduler sched = new DefaultChocoScheduler();
    ReconfigurationPlan res = sched.solve(i);
    Assert.assertEquals(n1, res.getResult().getMapping().getVMLocation(vm));
    // With a ResourceCapacity, we restrict n1 so that now n0 is the node
    // that will have the highest capacity. So the wort-fit approach inside
    // MinMTTR() should pick n0.
    i.getSatConstraints().add(new ResourceCapacity(n1, "cpu", 4));
    res = sched.solve(i);
    Assert.assertEquals(n0, res.getResult().getMapping().getVMLocation(vm));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) 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) ShareableResource(org.btrplace.model.view.ShareableResource) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) ResourceCapacity(org.btrplace.model.constraint.ResourceCapacity) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Running(org.btrplace.model.constraint.Running) Test(org.testng.annotations.Test)

Aggregations

Running (org.btrplace.model.constraint.Running)24 VM (org.btrplace.model.VM)20 Test (org.testng.annotations.Test)20 DefaultModel (org.btrplace.model.DefaultModel)17 Model (org.btrplace.model.Model)17 Node (org.btrplace.model.Node)17 SatConstraint (org.btrplace.model.constraint.SatConstraint)13 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)13 ArrayList (java.util.ArrayList)12 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)10 Instance (org.btrplace.model.Instance)8 MinMTTR (org.btrplace.model.constraint.MinMTTR)8 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)8 Mapping (org.btrplace.model.Mapping)7 ShareableResource (org.btrplace.model.view.ShareableResource)7 HashSet (java.util.HashSet)5 Ready (org.btrplace.model.constraint.Ready)5 Preserve (org.btrplace.model.constraint.Preserve)4 BootVM (org.btrplace.plan.event.BootVM)4 Fence (org.btrplace.model.constraint.Fence)3