Search in sources :

Example 6 with Preserve

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

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

the class PreserveBuilderTest method testGoodSignatures.

@Test(dataProvider = "goodPreserves")
public void testGoodSignatures(String str, int nbVMs, String rcId, int a) throws Exception {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    Set<SatConstraint> cstrs = b.build("namespace test; VM[1..10] : tiny;\n@N[1..20] : defaultNode;\n" + str).getConstraints();
    Assert.assertEquals(cstrs.size(), nbVMs);
    Set<VM> vms = new HashSet<>();
    for (SatConstraint x : cstrs) {
        Assert.assertTrue(x instanceof Preserve);
        Assert.assertTrue(vms.addAll(x.getInvolvedVMs()));
        Assert.assertEquals(x.isContinuous(), false);
        Assert.assertEquals(((Preserve) x).getResource(), rcId);
        Assert.assertEquals(((Preserve) x).getAmount(), a);
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) SatConstraint(org.btrplace.model.constraint.SatConstraint) VM(org.btrplace.model.VM) ScriptBuilder(org.btrplace.btrpsl.ScriptBuilder) Preserve(org.btrplace.model.constraint.Preserve) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 8 with Preserve

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

the class DefaultChocoSchedulerTest method testNonHomogeneousIncrease.

/**
 * Issue #14
 *
 * @throws org.btrplace.scheduler.SchedulerException
 */
@Test
public void testNonHomogeneousIncrease() throws SchedulerException {
    ShareableResource cpu = new ShareableResource("cpu");
    ShareableResource mem = new ShareableResource("mem");
    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();
    cpu.setCapacity(n1, 10);
    mem.setCapacity(n1, 10);
    cpu.setCapacity(n2, 10);
    mem.setCapacity(n2, 10);
    cpu.setConsumption(vm1, 5);
    mem.setConsumption(vm1, 4);
    cpu.setConsumption(vm2, 3);
    mem.setConsumption(vm2, 8);
    cpu.setConsumption(vm3, 5);
    cpu.setConsumption(vm3, 4);
    cpu.setConsumption(vm4, 4);
    cpu.setConsumption(vm4, 5);
    // vm1 requires more cpu resources, but fewer mem resources
    Preserve pCPU = new Preserve(vm1, "cpu", 7);
    Preserve pMem = new Preserve(vm1, "mem", 2);
    mo.getMapping().on(n1, n2).run(n1, vm1).run(n2, vm3, vm4).ready(vm2);
    mo.attach(cpu);
    mo.attach(mem);
    ChocoScheduler cra = new DefaultChocoScheduler();
    cra.setMaxEnd(5);
    ReconfigurationPlan p = cra.solve(mo, Arrays.asList(pCPU, pMem, new Online(n1), new Running(vm2), new Ready(vm3)));
    Assert.assertNotNull(p);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Ready(org.btrplace.model.constraint.Ready) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Running(org.btrplace.model.constraint.Running) ShareableResource(org.btrplace.model.view.ShareableResource) Online(org.btrplace.model.constraint.Online) Preserve(org.btrplace.model.constraint.Preserve) Test(org.testng.annotations.Test)

Example 9 with Preserve

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

the class PreserveConverterTest method testViables.

@Test
public void testViables() throws JSONConverterException {
    Model mo = new DefaultModel();
    ConstraintsConverter conv = new ConstraintsConverter();
    conv.register(new PreserveConverter());
    Preserve d = new Preserve(mo.newVM(), "cpu", 5);
    Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(d)), d);
    System.out.println(conv.toJSON(d));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Preserve(org.btrplace.model.constraint.Preserve) Test(org.testng.annotations.Test)

Example 10 with Preserve

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

the class SolverTuning method run.

@Override
@SuppressWarnings("squid:S1166")
public void run() {
    // Make a default model with 500 nodes hosting 3,000 VMs
    Model model = makeModel();
    Set<SatConstraint> constraints = new HashSet<>();
    // We allow memory over-commitment with a overbooking ratio of 50%
    // i.e. 1MB physical RAM for 1.5MB virtual RAM
    constraints.addAll(Overbook.newOverbooks(model.getMapping().getAllNodes(), "mem", 1.5));
    /**
     * On 10 nodes, 4 of the 6 hosted VMs ask now for a 4GB bandwidth
     */
    for (int i = 0; i < 5; i++) {
        Node n = nodes.get(i);
        Set<VM> vmsOnN = model.getMapping().getRunningVMs(n);
        Iterator<VM> ite = vmsOnN.iterator();
        for (int j = 0; ite.hasNext() && j < 4; j++) {
            VM v = ite.next();
            constraints.add(new Preserve(v, "bandwidth", 4));
        }
    }
    ChocoScheduler cra = new DefaultChocoScheduler();
    // Customize the estimated duration of actions
    cra.getDurationEvaluators().register(MigrateVM.class, new LinearToAResourceActionDuration<VM>("mem", 1, 3));
    // We want the best possible solution, computed in up to 5 sec.
    cra.doOptimize(true);
    cra.setTimeLimit(5);
    // We solve without the repair mode
    cra.doRepair(false);
    try {
        solve(cra, model, constraints);
    } catch (@SuppressWarnings("unused") SchedulerException ex) {
    // Just in case the testing environment is not performant enough
    // It does not matter that much if there is no enough time to get a solution here
    }
    // Re-solve using the repair mode to check for the improvement
    cra.doRepair(true);
    solve(cra, model, constraints);
}
Also used : SchedulerException(org.btrplace.scheduler.SchedulerException) SatConstraint(org.btrplace.model.constraint.SatConstraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) 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)

Aggregations

Preserve (org.btrplace.model.constraint.Preserve)12 Test (org.testng.annotations.Test)10 DefaultModel (org.btrplace.model.DefaultModel)9 VM (org.btrplace.model.VM)9 SatConstraint (org.btrplace.model.constraint.SatConstraint)9 Model (org.btrplace.model.Model)8 ArrayList (java.util.ArrayList)7 Node (org.btrplace.model.Node)7 ShareableResource (org.btrplace.model.view.ShareableResource)7 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)7 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)7 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)7 MigrateVM (org.btrplace.plan.event.MigrateVM)5 Mapping (org.btrplace.model.Mapping)4 HashSet (java.util.HashSet)3 Overbook (org.btrplace.model.constraint.Overbook)2 SchedulerException (org.btrplace.scheduler.SchedulerException)2 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)1 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)1 Instance (org.btrplace.model.Instance)1