Search in sources :

Example 26 with DefaultModel

use of org.btrplace.model.DefaultModel in project scheduler by btrplace.

the class MaxOnlineSplitterTest method testSplit.

@Test
public void testSplit() throws SchedulerException {
    MaxOnlineSplitter splitter = new MaxOnlineSplitter();
    Model mo = new DefaultModel();
    Node[] ns = new Node[10];
    for (int i = 0; i < ns.length; i++) {
        Node n = mo.newNode();
        mo.getMapping().addOnlineNode(n);
        ns[i] = n;
    }
    FixedNodeSetsPartitioning cut = new FixedSizePartitioning(5);
    Instance origin = new Instance(mo, Collections.emptyList(), new MinMTTR());
    List<Instance> instances = cut.split(new DefaultParameters(), origin);
    TIntIntHashMap vmIndex = Instances.makeVMIndex(instances);
    TIntIntHashMap nodeIndex = Instances.makeNodeIndex(instances);
    MaxOnline m1 = new MaxOnline(new HashSet<>(Arrays.asList(ns[0], ns[1], ns[2], ns[3], ns[4])), 3);
    // This one is valid as m1 stay in the first partition
    Assert.assertTrue(splitter.split(m1, origin, instances, vmIndex, nodeIndex));
    boolean found = false;
    for (Instance i : instances) {
        if (i.getSatConstraints().contains(m1)) {
            if (found) {
                Assert.fail(m1 + " is already in a partition");
            }
            found = true;
        }
    }
    // Invalid, the constraint is over 2 partitions
    MaxOnline m2 = new MaxOnline(new HashSet<>(Arrays.asList(ns[0], ns[1], ns[5])), 3);
    Assert.assertFalse(splitter.split(m2, origin, instances, vmIndex, nodeIndex));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) MinMTTR(org.btrplace.model.constraint.MinMTTR) FixedNodeSetsPartitioning(org.btrplace.scheduler.runner.disjoint.FixedNodeSetsPartitioning) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) MaxOnline(org.btrplace.model.constraint.MaxOnline) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) FixedSizePartitioning(org.btrplace.scheduler.runner.disjoint.FixedSizePartitioning) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) Test(org.testng.annotations.Test)

Example 27 with DefaultModel

use of org.btrplace.model.DefaultModel in project scheduler by btrplace.

the class OnlineSplitterTest method simpleTest.

@Test
public void simpleTest() {
    OnlineSplitter splitter = new OnlineSplitter();
    List<Instance> instances = new ArrayList<>();
    Model m0 = new DefaultModel();
    Node n = m0.newNode();
    m0.getMapping().addOnlineNode(n);
    m0.getMapping().addOnlineNode(m0.newNode(1));
    Model m1 = new DefaultModel();
    m1.getMapping().addOnlineNode(m1.newNode(2));
    m1.getMapping().addOnlineNode(m1.newNode(3));
    instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
    instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
    Set<Node> all = new HashSet<>(m0.getMapping().getAllNodes());
    all.addAll(m1.getMapping().getAllNodes());
    TIntIntHashMap nodeIndex = Instances.makeNodeIndex(instances);
    // Only nodes in m0
    Online oSimple = new Online(n);
    Assert.assertTrue(splitter.split(oSimple, null, instances, new TIntIntHashMap(), nodeIndex));
    Assert.assertTrue(instances.get(0).getSatConstraints().contains(oSimple));
    Assert.assertFalse(instances.get(1).getSatConstraints().contains(oSimple));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) 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) Online(org.btrplace.model.constraint.Online) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 28 with DefaultModel

use of org.btrplace.model.DefaultModel in project scheduler by btrplace.

the class OverbookSplitterTest method simpleTest.

@Test
public void simpleTest() {
    OverbookSplitter splitter = new OverbookSplitter();
    List<Instance> instances = new ArrayList<>();
    Model m0 = new DefaultModel();
    Node n = m0.newNode(0);
    m0.getMapping().addOnlineNode(n);
    m0.getMapping().addOnlineNode(m0.newNode(1));
    Model m1 = new DefaultModel();
    m1.getMapping().addOnlineNode(m1.newNode(2));
    m1.getMapping().addOnlineNode(m1.newNode(3));
    instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
    instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
    Set<Node> all = new HashSet<>(m0.getMapping().getAllNodes());
    all.addAll(m1.getMapping().getAllNodes());
    TIntIntHashMap nodeIndex = Instances.makeNodeIndex(instances);
    // Only nodes in m0
    Overbook oSimple = new Overbook(n, "cpu", 2);
    Assert.assertTrue(splitter.split(oSimple, null, instances, new TIntIntHashMap(), nodeIndex));
    Assert.assertTrue(instances.get(0).getSatConstraints().contains(oSimple));
    Assert.assertFalse(instances.get(1).getSatConstraints().contains(oSimple));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) Overbook(org.btrplace.model.constraint.Overbook) 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) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 29 with DefaultModel

use of org.btrplace.model.DefaultModel in project scheduler by btrplace.

the class DefaultChocoSchedulerTest method testWithUnknownVMs.

/*@Test
    public void testGetStatistics() throws SchedulerException {
        Model mo = new DefaultModel();
        Mapping map = mo.getMapping();
        for (int i = 0; i < 10; i++) {
            Node n = mo.newNode();
            map.addOnlineNode(n);
            map.addRunningVM(mo.newVM(), n);
        }
        ChocoScheduler cra = new DefaultChocoScheduler();
        cra.doOptimize(true);
        cra.setTimeLimit(0);

        Assert.assertNull(cra.getStatistics());

        OptConstraint o = new OptConstraint() {
            @Override
            public String id() {
                return "foo";
            }
        };

        ChocoConstraint co =  new ChocoMapperTest.MockCConstraint() {

            public ChocoMapperTest.MockCConstraint(OptConstraint f) {}
            @Override
            public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
                return false;
            }

            @Override
            public Set<VM> getMisPlacedVMs(Model m) {
                return Collections.emptySet();
            }
        };
        cra.getMapper().register(o.getClass(), co.getClass());

        ReconfigurationPlan p = cra.solve(mo, Collections.<SatConstraint>emptyList(), o);
        Mapping res = p.getResult().getMapping();
        int nbRunning = 0;
        for (Node n : res.getOnlineNodes()) {
            if (!res.getRunningVMs(n).isEmpty()) {
                nbRunning++;
            }
        }
        Assert.assertEquals(nbRunning, 1);
        SolvingStatistics st = cra.getStatistics();
        Assert.assertEquals(st.getSolutions().get(0).getOptValue(), 1);
        Assert.assertEquals(st.getSolutions().size(), 1);
    }
*/
/*    @Test
    public void testSolvableRepair() throws SchedulerException {
        Model mo = new DefaultModel();
        final VM vm1 = mo.newVM();
        final VM vm2 = mo.newVM();
        final 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();

        mo.on(n1, n2, n3).run(n1, vm1, vm4).run(n2, vm2).run(n3, vm3, vm5).get();

        //A satisfied constraint
        Fence c1 = new Fence(vm1, new HashSet<>(Arrays.asList(n1, n2)));

        //A constraint that is not satisfied. vm2 is misplaced
        Fence c2 = new Fence(vm2, new HashSet<>(Arrays.asList(n1, n3)));

        Set<SatConstraint> cstrs = new HashSet<SatConstraint>(Arrays.asList(c1, c2));
        mo = new DefaultModel();
        mo.on(n1, n2, n3).run(n1, vm1, vm4).run(n2, vm2).run(n3, vm3, vm5).get();
        ChocoScheduler cra = new DefaultChocoScheduler();
        OptConstraint o = new OptConstraint() {
            @Override
            public String id() {
                return "foo";
            }
        };

        ChocoConstraint co = new ChocoConstraint() {
            @Override
            public Set<VM> getMisPlacedVMs(Model m) {
                return new HashSet<>(Arrays.asList(vm2, vm3));
            }
        };
        cra.getMapper().register(o.getClass(), co.getClass());
        cra.doRepair(true);
        cra.doOptimize(false);

        //Solve a problem with the repair mode
        Assert.assertNotNull(cra.solve(mo, cstrs, o));
        SolvingStatistics st = cra.getStatistics();
        System.out.println(st);
        Assert.assertEquals(st.getNbManagedVMs(), 2); //vm2, vm3.
    }
*/
@Test(expectedExceptions = { SchedulerException.class })
public void testWithUnknownVMs() throws SchedulerException {
    Model mo = new DefaultModel();
    final VM vm1 = mo.newVM();
    final VM vm2 = mo.newVM();
    final VM vm3 = mo.newVM();
    VM vm4 = mo.newVM();
    VM vm5 = mo.newVM();
    VM vm6 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Node n3 = mo.newNode();
    Node n4 = mo.newNode();
    mo.getMapping().on(n1, n2, n3).run(n1, vm1, vm4).run(n2, vm2).run(n3, vm3, vm5);
    SatConstraint cstr = mock(SatConstraint.class);
    when(cstr.getInvolvedVMs()).thenReturn(Arrays.asList(vm1, vm2, vm6));
    when(cstr.getInvolvedNodes()).thenReturn(Arrays.asList(n1, n4));
    ChocoScheduler cra = new DefaultChocoScheduler();
    cra.solve(mo, Collections.singleton(cstr));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 30 with DefaultModel

use of org.btrplace.model.DefaultModel in project scheduler by btrplace.

the class DefaultChocoSchedulerTest method testGetStatisticsWithTimeout.

@Test(expectedExceptions = { SchedulerException.class })
public void testGetStatisticsWithTimeout() throws SchedulerException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    for (int i = 0; i < 1000; i++) {
        Node n = mo.newNode();
        map.addOnlineNode(n);
        for (int j = 0; j < 10; j++) {
            map.addReadyVM(mo.newVM());
        }
    }
    ChocoScheduler cra = new DefaultChocoScheduler();
    cra.setTimeLimit(1);
    try {
        System.err.println(cra.solve(mo, Running.newRunning(map.getAllVMs())));
    } catch (SchedulerException e) {
        SolvingStatistics stats = cra.getStatistics();
        Assert.assertNotNull(stats);
        System.out.println(stats);
        Assert.assertTrue(stats.getSolutions().isEmpty());
        Assert.assertEquals(stats.getInstance().getModel(), mo);
        throw e;
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) SchedulerException(org.btrplace.scheduler.SchedulerException) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Mapping(org.btrplace.model.Mapping) SolvingStatistics(org.btrplace.scheduler.choco.runner.SolvingStatistics) SatConstraint(org.btrplace.model.constraint.SatConstraint) Test(org.testng.annotations.Test)

Aggregations

DefaultModel (org.btrplace.model.DefaultModel)201 Test (org.testng.annotations.Test)177 Model (org.btrplace.model.Model)157 Node (org.btrplace.model.Node)91 VM (org.btrplace.model.VM)91 HashSet (java.util.HashSet)48 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)43 SatConstraint (org.btrplace.model.constraint.SatConstraint)40 Mapping (org.btrplace.model.Mapping)39 ArrayList (java.util.ArrayList)26 ShareableResource (org.btrplace.model.view.ShareableResource)24 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)22 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)18 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)17 ShutdownableNode (org.btrplace.scheduler.choco.transition.ShutdownableNode)17 MigrateVM (org.btrplace.plan.event.MigrateVM)16 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)16 BootVM (org.btrplace.scheduler.choco.transition.BootVM)16 ForgeVM (org.btrplace.scheduler.choco.transition.ForgeVM)16 KillVM (org.btrplace.scheduler.choco.transition.KillVM)16