Search in sources :

Example 11 with Preserve

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

the class CPreserveTest method testPreserveWithoutOverbook.

/*@Test
    public void testGetMisplaced() {
        Model mo = new DefaultModel();
        VM vm1 = mo.newVM();
        VM vm2 = mo.newVM();
        VM vm3 = mo.newVM();
        Node n1 = mo.newNode();
        Node n2 = mo.newNode();

        Mapping map = mo.getMapping().on(n1, n2).run(n1, vm1, vm2).run(n2, vm3).get();
        ShareableResource rc = new ShareableResource("cpu", 7, 7);
        rc.setConsumption(vm1, 3);
        rc.setConsumption(vm2, 3);
        rc.setConsumption(vm3, 5);

        Preserve p = new Preserve(vm1, "cpu", 5);

        mo.attach(rc);
        //Assert.assertEquals(SatConstraint.Sat.UNSATISFIED, p.isSatisfied(mo));

        CPreserve cp = new CPreserve(p);
        Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR());
        Set<VM> bads = cp.getMisPlacedVMs(i);
        Assert.assertEquals(1, bads.size());
        Assert.assertEquals(vm1, bads.iterator().next());
    }*/
/**
 * A preserve constraint asks for a minimum amount of resources but
 * their is no overbook ratio so, the default value of 1 is used
 * and vm1 or vm2 is moved to n2
 *
 * @throws org.btrplace.scheduler.SchedulerException
 */
@Test
public void testPreserveWithoutOverbook() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Mapping map = mo.getMapping().on(n1, n2).run(n1, vm1, vm2).run(n2, vm3);
    ShareableResource rc = new ShareableResource("cpu", 10, 10);
    rc.setCapacity(n1, 7);
    rc.setConsumption(vm1, 3);
    rc.setConsumption(vm2, 3);
    rc.setConsumption(vm3, 5);
    Preserve pr = new Preserve(vm2, "cpu", 5);
    ChocoScheduler cra = new DefaultChocoScheduler();
    mo.attach(rc);
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.addAll(Online.newOnline(map.getAllNodes()));
    cstrs.add(pr);
    ReconfigurationPlan p = cra.solve(mo, cstrs);
    Assert.assertNotNull(p);
}
Also used : 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) Test(org.testng.annotations.Test)

Example 12 with Preserve

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

the class PreserveSplitterTest method simpleTest.

@Test
public void simpleTest() {
    PreserveSplitter splitter = new PreserveSplitter();
    List<Instance> instances = new ArrayList<>();
    Model m0 = new DefaultModel();
    VM v = m0.newVM(1);
    m0.getMapping().addReadyVM(v);
    m0.getMapping().addRunningVM(m0.newVM(2), m0.newNode(1));
    Model m1 = new DefaultModel();
    m1.getMapping().addReadyVM(m1.newVM(3));
    m1.getMapping().addSleepingVM(m1.newVM(4), m1.newNode(2));
    m1.getMapping().addRunningVM(m1.newVM(5), m1.newNode(3));
    instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
    instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
    TIntIntHashMap index = Instances.makeVMIndex(instances);
    Set<VM> all = new HashSet<>(m0.getMapping().getAllVMs());
    all.addAll(m1.getMapping().getAllVMs());
    // Only VMs in m0
    Preserve single = new Preserve(v, "foo", 3);
    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) VM(org.btrplace.model.VM) ArrayList(java.util.ArrayList) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) MinMTTR(org.btrplace.model.constraint.MinMTTR) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) Preserve(org.btrplace.model.constraint.Preserve) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

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