Search in sources :

Example 1 with MinMigrations

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

the class MinMigrationsConverterTest method test.

@Test
public void test() throws JSONConverterException {
    Model mo = new DefaultModel();
    ConstraintsConverter conv = new ConstraintsConverter();
    conv.register(new MinMigrationsConverter());
    MinMigrations m = new MinMigrations();
    Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(m)), m);
    System.out.println(conv.toJSON(m));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) MinMigrations(org.btrplace.model.constraint.MinMigrations) Test(org.testng.annotations.Test)

Example 2 with MinMigrations

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

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

the class CMinMigrationsTest method main.

public static void main(String[] args) {
    String root = "/Users/fabien.hermenier/Documents/BtrPlace/nutanix/instances";
    List<OptConstraint> objs = Arrays.asList(/*new MinMTTR(),*/
    new MinMigrations());
    boolean verbose = true;
    for (OptConstraint o : objs) {
        System.out.print(" " + o);
    }
    System.out.println();
    for (int idx = 1; idx <= 256; idx += 5) {
        String path = root + "/lazan/lazan-" + idx + ".json.gz";
        if (verbose) {
            System.out.println("--- " + idx + " --- ");
        } else {
            System.out.print(idx);
        }
        List<Long> res = new ArrayList<>();
        for (OptConstraint o : objs) {
            if (verbose) {
                System.out.println("\t" + o);
            }
            Instance i = JSON.readInstance(new File(path));
            if (Network.get(i.getModel()) != null) {
                i.getModel().detach(Network.get(i.getModel()));
            }
            i = new Instance(i.getModel(), i.getSatConstraints(), o);
            ChocoScheduler s = new DefaultChocoScheduler();
            s.doOptimize(false);
            s.setTimeLimit(30);
            s.doRepair(false);
            ReconfigurationPlan p = s.solve(i);
            Assert.assertNotNull(p);
            res.add(p.getActions().stream().filter(x -> x instanceof MigrateVM).mapToLong(x -> x.getEnd() - x.getStart()).sum());
            // res.add((long)s.getStatistics().lastSolution().getDuration());
            if (verbose) {
                System.out.println(s.getStatistics());
            // System.out.println(p);
            }
        }
        if (!verbose) {
            for (Long l : res) {
                System.out.print("\t" + l);
            }
            System.out.println();
        }
    }
}
Also used : Model(org.btrplace.model.Model) Arrays(java.util.Arrays) Node(org.btrplace.model.Node) OptConstraint(org.btrplace.model.constraint.OptConstraint) Spread(org.btrplace.model.constraint.Spread) Preserve(org.btrplace.model.constraint.Preserve) MigrateVM(org.btrplace.plan.event.MigrateVM) Test(org.testng.annotations.Test) DefaultModel(org.btrplace.model.DefaultModel) JSON(org.btrplace.json.JSON) File(java.io.File) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) VM(org.btrplace.model.VM) List(java.util.List) Assert(org.testng.Assert) ShareableResource(org.btrplace.model.view.ShareableResource) Instance(org.btrplace.model.Instance) MinMigrations(org.btrplace.model.constraint.MinMigrations) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Network(org.btrplace.model.view.network.Network) SatConstraint(org.btrplace.model.constraint.SatConstraint) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) Instance(org.btrplace.model.Instance) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) MigrateVM(org.btrplace.plan.event.MigrateVM) OptConstraint(org.btrplace.model.constraint.OptConstraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) OptConstraint(org.btrplace.model.constraint.OptConstraint) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) MinMigrations(org.btrplace.model.constraint.MinMigrations) File(java.io.File)

Example 4 with MinMigrations

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

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

the class CMinMigrationsTest method testWithFreeNodes.

/**
 * Issue #137.
 * ShutdownableNode.isOnline() is not instantiated at the end of the problem
 */
@Test
public void testWithFreeNodes() {
    Model mo = new DefaultModel();
    Node n0 = mo.newNode();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    VM v1 = mo.newVM();
    VM v2 = mo.newVM();
    DefaultChocoScheduler s = new DefaultChocoScheduler();
    mo.getMapping().on(n0, n1, n2).run(n0, v1, v2);
    Instance i = new Instance(mo, Arrays.asList(new Spread(mo.getMapping().getAllVMs(), false)), new MinMigrations());
    ReconfigurationPlan p = s.solve(i);
    Assert.assertNotNull(p);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Spread(org.btrplace.model.constraint.Spread) Instance(org.btrplace.model.Instance) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Node(org.btrplace.model.Node) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) MinMigrations(org.btrplace.model.constraint.MinMigrations) Test(org.testng.annotations.Test)

Aggregations

MinMigrations (org.btrplace.model.constraint.MinMigrations)8 Test (org.testng.annotations.Test)8 DefaultModel (org.btrplace.model.DefaultModel)6 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)6 Model (org.btrplace.model.Model)5 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)5 ArrayList (java.util.ArrayList)4 Instance (org.btrplace.model.Instance)4 Node (org.btrplace.model.Node)4 SatConstraint (org.btrplace.model.constraint.SatConstraint)4 ShareableResource (org.btrplace.model.view.ShareableResource)4 MigrateVM (org.btrplace.plan.event.MigrateVM)4 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)4 VM (org.btrplace.model.VM)3 File (java.io.File)2 List (java.util.List)2 OptConstraint (org.btrplace.model.constraint.OptConstraint)2 Preserve (org.btrplace.model.constraint.Preserve)2 Spread (org.btrplace.model.constraint.Spread)2 Constraint (org.chocosolver.solver.constraints.Constraint)2