Search in sources :

Example 1 with Lonely

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

the class CLonelyTest method testFeasibleContinuous.

/**
 * vm3 needs to go to n2 . vm1, vm2, vm3 must be lonely. n2 is occupied by "other" VMs, so
 * they have to go away before receiving vm3
 *
 * @throws org.btrplace.scheduler.SchedulerException
 */
@Test
public void testFeasibleContinuous() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    VM vm4 = mo.newVM();
    VM vm5 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Node n3 = mo.newNode();
    mo.getMapping().on(n1, n2, n3).run(n1, vm1, vm2, vm3).run(n2, vm4, vm5);
    Set<VM> mine = new HashSet<>(Arrays.asList(vm1, vm2, vm3));
    ChocoScheduler cra = new DefaultChocoScheduler();
    Lonely l = new Lonely(mine);
    l.setContinuous(true);
    Set<SatConstraint> cstrs = new HashSet<>();
    cstrs.add(l);
    cstrs.add(new Fence(vm3, Collections.singleton(n2)));
    ReconfigurationPlan plan = cra.solve(mo, cstrs);
    Assert.assertNotNull(plan);
}
Also used : Lonely(org.btrplace.model.constraint.Lonely) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Fence(org.btrplace.model.constraint.Fence) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with Lonely

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

the class LonelyConverterTest method testViables.

@Test
public void testViables() throws JSONConverterException {
    Model mo = new DefaultModel();
    ConstraintsConverter conv = new ConstraintsConverter();
    conv.register(new LonelyConverter());
    Lonely d = new Lonely(new HashSet<>(Arrays.asList(mo.newVM(), mo.newVM())), false);
    Lonely c = new Lonely(new HashSet<>(Arrays.asList(mo.newVM(), mo.newVM())), true);
    Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(d)), d);
    Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(c)), c);
    System.out.println(conv.toJSON(d));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Lonely(org.btrplace.model.constraint.Lonely) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 3 with Lonely

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

the class CLonelyTest method testFeasibleDiscrete.

@Test
public void testFeasibleDiscrete() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    VM vm4 = mo.newVM();
    VM vm5 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Node n3 = mo.newNode();
    mo.getMapping().on(n1, n2, n3).run(n1, vm1, vm2).run(n2, vm3, vm4, vm5);
    Set<VM> mine = new HashSet<>(Arrays.asList(vm1, vm2, vm3));
    ChocoScheduler cra = new DefaultChocoScheduler();
    Lonely l = new Lonely(mine);
    l.setContinuous(false);
    ReconfigurationPlan plan = cra.solve(mo, Collections.singleton(l));
    Assert.assertNotNull(plan);
// System.out.println(plan);
// Assert.assertEquals(l.isSatisfied(plan.getResult()), SatConstraint.Sat.SATISFIED);
}
Also used : DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Lonely(org.btrplace.model.constraint.Lonely) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 4 with Lonely

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

the class CLonelyTest method testGetMisplaced.

@Test
public void testGetMisplaced() {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    VM vm4 = mo.newVM();
    VM vm5 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Node n3 = mo.newNode();
    Mapping map = mo.getMapping().on(n1, n2, n3).run(n1, vm1, vm2, vm3).run(n2, vm4, vm5);
    Set<VM> mine = new HashSet<>(Arrays.asList(vm1, vm2, vm3));
    CLonely c = new CLonely(new Lonely(mine));
    Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR());
    Assert.assertTrue(c.getMisPlacedVMs(i).isEmpty());
    map.addRunningVM(vm2, n2);
    Assert.assertEquals(c.getMisPlacedVMs(i), map.getRunningVMs(n2));
}
Also used : Lonely(org.btrplace.model.constraint.Lonely) MinMTTR(org.btrplace.model.constraint.MinMTTR) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 5 with Lonely

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

the class LonelyBuilderTest method testGoodSignatures.

@Test(dataProvider = "goodLonelys")
public void testGoodSignatures(String str, int nbVMs, boolean c) throws Exception {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    Lonely x = (Lonely) b.build("namespace test; VM[1..10] : tiny;\n" + str).getConstraints().iterator().next();
    Assert.assertEquals(x.getInvolvedVMs().size(), nbVMs);
    Assert.assertEquals(x.isContinuous(), c);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Lonely(org.btrplace.model.constraint.Lonely) ScriptBuilder(org.btrplace.btrpsl.ScriptBuilder) Test(org.testng.annotations.Test)

Aggregations

Lonely (org.btrplace.model.constraint.Lonely)6 Test (org.testng.annotations.Test)6 HashSet (java.util.HashSet)4 DefaultModel (org.btrplace.model.DefaultModel)3 Model (org.btrplace.model.Model)2 MinMTTR (org.btrplace.model.constraint.MinMTTR)2 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)2 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)2 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)2 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)1 ArrayList (java.util.ArrayList)1 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)1 Instance (org.btrplace.model.Instance)1 VM (org.btrplace.model.VM)1 Fence (org.btrplace.model.constraint.Fence)1 SatConstraint (org.btrplace.model.constraint.SatConstraint)1