Search in sources :

Example 1 with DefaultElementBuilder

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

the class StaticPartitioningTest method testSolvingIncorrectPartitioning.

@Test(expectedExceptions = { SchedulerException.class })
public void testSolvingIncorrectPartitioning() throws SchedulerException {
    SynchronizedElementBuilder eb = new SynchronizedElementBuilder(new DefaultElementBuilder());
    Model origin = new DefaultModel(eb);
    Node n1 = origin.newNode();
    Node n2 = origin.newNode();
    VM vm1 = origin.newVM();
    VM vm2 = origin.newVM();
    /*
         * 2 nodes among 2 instances, 2 VMs to boot on the nodes
         */
    origin.getMapping().addOnlineNode(n1);
    origin.getMapping().addOfflineNode(n2);
    origin.getMapping().addReadyVM(vm1);
    origin.getMapping().addReadyVM(vm2);
    Model s1 = new SubModel(origin, eb, Collections.singletonList(n1), Collections.singleton(vm1));
    Model s2 = new SubModel(origin, eb, Collections.singletonList(n2), Collections.singleton(vm2));
    Instance i0 = new Instance(origin, new MinMTTR());
    final Instance i1 = new Instance(s1, Running.newRunning(Collections.singletonList(vm1)), new MinMTTR());
    final Instance i2 = new Instance(s2, new MinMTTR());
    // Error, vm1 is in s1, not s2
    i2.getSatConstraints().add(new Running(vm1));
    StaticPartitioning st = new StaticPartitioning() {

        @Override
        public List<Instance> split(Parameters ps, Instance i) throws SchedulerException {
            return Arrays.asList(i1, i2);
        }
    };
    Parameters p = new DefaultChocoScheduler();
    st.solve(p, i0);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Parameters(org.btrplace.scheduler.choco.Parameters) Instance(org.btrplace.model.Instance) DefaultElementBuilder(org.btrplace.model.DefaultElementBuilder) Node(org.btrplace.model.Node) MinMTTR(org.btrplace.model.constraint.MinMTTR) SubModel(org.btrplace.scheduler.runner.disjoint.model.SubModel) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) SubModel(org.btrplace.scheduler.runner.disjoint.model.SubModel) DefaultModel(org.btrplace.model.DefaultModel) Running(org.btrplace.model.constraint.Running) SynchronizedElementBuilder(org.btrplace.model.SynchronizedElementBuilder) Test(org.testng.annotations.Test)

Example 2 with DefaultElementBuilder

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

the class StaticPartitioningTest method testParallelSolve.

@Test
public void testParallelSolve() throws SchedulerException {
    SynchronizedElementBuilder eb = new SynchronizedElementBuilder(new DefaultElementBuilder());
    Model origin = new DefaultModel(eb);
    Node n1 = origin.newNode();
    Node n2 = origin.newNode();
    VM vm1 = origin.newVM();
    VM vm2 = origin.newVM();
    /*
         * 2 nodes among 2 instances, 2 VMs to boot on the nodes
         */
    origin.getMapping().addOnlineNode(n1);
    origin.getMapping().addOfflineNode(n2);
    origin.getMapping().addReadyVM(vm1);
    origin.getMapping().addReadyVM(vm2);
    Model s1 = new SubModel(origin, eb, Collections.singletonList(n1), Collections.singleton(vm1));
    Model s2 = new SubModel(origin, eb, Collections.singletonList(n2), Collections.singleton(vm2));
    Instance i0 = new Instance(origin, new MinMTTR());
    final Instance i1 = new Instance(s1, Running.newRunning(Collections.singletonList(vm1)), new MinMTTR());
    final Instance i2 = new Instance(s2, new MinMTTR());
    i2.getSatConstraints().add(new Running(vm2));
    StaticPartitioning st = new StaticPartitioning() {

        @Override
        public List<Instance> split(Parameters ps, Instance i) throws SchedulerException {
            return Arrays.asList(i1, i2);
        }
    };
    Parameters p = new DefaultChocoScheduler();
    ReconfigurationPlan plan = st.solve(p, i0);
    Assert.assertNotNull(plan);
    Model dst = plan.getResult();
    Assert.assertEquals(dst.getMapping().getOnlineNodes().size(), 2);
    Assert.assertEquals(dst.getMapping().getRunningVMs().size(), 2);
    // Now, there is no solution for i2. the resulting plan should be null
    i2.getSatConstraints().addAll(Offline.newOffline(n2));
    plan = st.solve(p, i0);
    Assert.assertNull(plan);
    Assert.assertEquals(st.getStatistics().getSolutions().size(), 0);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Parameters(org.btrplace.scheduler.choco.Parameters) Instance(org.btrplace.model.Instance) DefaultElementBuilder(org.btrplace.model.DefaultElementBuilder) Node(org.btrplace.model.Node) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) MinMTTR(org.btrplace.model.constraint.MinMTTR) SubModel(org.btrplace.scheduler.runner.disjoint.model.SubModel) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) SubModel(org.btrplace.scheduler.runner.disjoint.model.SubModel) DefaultModel(org.btrplace.model.DefaultModel) Running(org.btrplace.model.constraint.Running) SynchronizedElementBuilder(org.btrplace.model.SynchronizedElementBuilder) Test(org.testng.annotations.Test)

Aggregations

DefaultElementBuilder (org.btrplace.model.DefaultElementBuilder)2 DefaultModel (org.btrplace.model.DefaultModel)2 Instance (org.btrplace.model.Instance)2 Model (org.btrplace.model.Model)2 Node (org.btrplace.model.Node)2 SynchronizedElementBuilder (org.btrplace.model.SynchronizedElementBuilder)2 VM (org.btrplace.model.VM)2 MinMTTR (org.btrplace.model.constraint.MinMTTR)2 Running (org.btrplace.model.constraint.Running)2 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)2 Parameters (org.btrplace.scheduler.choco.Parameters)2 SubModel (org.btrplace.scheduler.runner.disjoint.model.SubModel)2 Test (org.testng.annotations.Test)2 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)1