Search in sources :

Example 31 with MinMTTR

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

the class SingleRunnerStatisticsTest method testInstantiate.

@Test
public void testInstantiate() {
    Parameters ps = new DefaultParameters();
    Model mo = new DefaultModel();
    long st = System.currentTimeMillis();
    List<SatConstraint> cstrs = new ArrayList<>();
    Instance i = new Instance(mo, cstrs, new MinMTTR());
    SingleRunnerStatistics stats = new SingleRunnerStatistics(ps, i, st);
    Assert.assertEquals(stats.getStart(), st);
    Assert.assertEquals(stats.getCoreBuildDuration(), -1);
    Assert.assertEquals(stats.getSpecializationDuration(), -1);
    Assert.assertEquals(stats.getInstance(), i);
    Assert.assertEquals(stats.getNbManagedVMs(), -1);
    Assert.assertEquals(stats.getParameters(), ps);
    Assert.assertEquals(stats.getSolutions().size(), 0);
    Assert.assertEquals(stats.completed(), false);
    Assert.assertEquals(stats.getMetrics(), null);
    stats.setCoreBuildDuration(12);
    stats.setSpecialisationDuration(17);
    stats.setNbManagedVMs(18);
    stats.setCompleted(true);
    Assert.assertEquals(stats.getCoreBuildDuration(), 12);
    Assert.assertEquals(stats.getSpecializationDuration(), 17);
    Assert.assertEquals(stats.getNbManagedVMs(), 18);
    Assert.assertEquals(stats.completed(), true);
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
    SolutionStatistics sol = new SolutionStatistics(new Metrics(), plan);
    stats.addSolution(sol);
    Assert.assertEquals(stats.getSolutions().size(), 1);
    Assert.assertEquals(stats.getSolutions().get(0), sol);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Instance(org.btrplace.model.Instance) SatConstraint(org.btrplace.model.constraint.SatConstraint) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) SolutionStatistics(org.btrplace.scheduler.choco.runner.SolutionStatistics) ArrayList(java.util.ArrayList) MinMTTR(org.btrplace.model.constraint.MinMTTR) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) Metrics(org.btrplace.scheduler.choco.runner.Metrics) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 32 with MinMTTR

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

the class DefaultChocoSchedulerTest method testOnSolutionHook.

@Test
public void testOnSolutionHook() {
    ChocoScheduler cra = new DefaultChocoScheduler();
    Model mo = new DefaultModel();
    VM vm = mo.newVM();
    Node node = mo.newNode();
    mo.getMapping().on(node).run(node, vm);
    Instance i = new Instance(mo, Running.newRunning(vm), new MinMTTR());
    List<ReconfigurationPlan> onSolutions = new ArrayList<>();
    cra.addSolutionListener((rp, plan) -> onSolutions.add(plan));
    Assert.assertEquals(1, cra.solutionListeners().size());
    ReconfigurationPlan plan = cra.solve(i);
    Assert.assertEquals(1, onSolutions.size());
    Assert.assertEquals(plan, onSolutions.get(0));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) 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) MinMTTR(org.btrplace.model.constraint.MinMTTR) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 33 with MinMTTR

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

the class CBanTest method testGetMisPlaced.

/**
 * Test getMisPlaced() in various situations.
 */
@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();
    Node n4 = mo.newNode();
    Node n5 = mo.newNode();
    mo.getMapping().on(n1, n2, n3, n4, n5).run(n1, vm1, vm2).run(n2, vm3).run(n3, vm4).sleep(n4, vm5);
    Set<Node> ns = new HashSet<>(Arrays.asList(n3, n4));
    CBan c = new CBan(new Ban(vm1, ns));
    Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR());
    Assert.assertTrue(c.getMisPlacedVMs(i).isEmpty());
    ns.add(mo.newNode());
    Assert.assertTrue(c.getMisPlacedVMs(i).isEmpty());
    ns.add(n1);
    Set<VM> bad = c.getMisPlacedVMs(i);
    Assert.assertEquals(1, bad.size());
    Assert.assertTrue(bad.contains(vm1));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) MinMTTR(org.btrplace.model.constraint.MinMTTR) Ban(org.btrplace.model.constraint.Ban) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 34 with MinMTTR

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

the class CGatherTest method testGetMisplaced.

@Test
public void testGetMisplaced() {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Mapping map = mo.getMapping().ready(vm1).on(n1, n2).run(n2, vm2);
    Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR());
    Gather g = new Gather(map.getAllVMs());
    CGather c = new CGather(g);
    Assert.assertTrue(c.getMisPlacedVMs(i).isEmpty());
    map.addRunningVM(vm1, n2);
    Assert.assertTrue(c.getMisPlacedVMs(i).isEmpty());
    map.addRunningVM(vm1, n1);
    Assert.assertEquals(c.getMisPlacedVMs(i), map.getAllVMs());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) MinMTTR(org.btrplace.model.constraint.MinMTTR) Mapping(org.btrplace.model.Mapping) Gather(org.btrplace.model.constraint.Gather) Test(org.testng.annotations.Test)

Example 35 with MinMTTR

use of org.btrplace.model.constraint.MinMTTR 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)

Aggregations

MinMTTR (org.btrplace.model.constraint.MinMTTR)47 Model (org.btrplace.model.Model)42 Instance (org.btrplace.model.Instance)41 Test (org.testng.annotations.Test)41 DefaultModel (org.btrplace.model.DefaultModel)40 Node (org.btrplace.model.Node)33 VM (org.btrplace.model.VM)33 ArrayList (java.util.ArrayList)22 HashSet (java.util.HashSet)22 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)15 SatConstraint (org.btrplace.model.constraint.SatConstraint)10 Mapping (org.btrplace.model.Mapping)9 Running (org.btrplace.model.constraint.Running)8 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)8 Collection (java.util.Collection)6 Offline (org.btrplace.model.constraint.Offline)5 ShareableResource (org.btrplace.model.view.ShareableResource)5 Spread (org.btrplace.model.constraint.Spread)4 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)4 Ban (org.btrplace.model.constraint.Ban)3