Search in sources :

Example 1 with SubModel

use of org.btrplace.scheduler.runner.disjoint.model.SubModel 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 : Parameters(org.btrplace.scheduler.choco.Parameters) MinMTTR(org.btrplace.model.constraint.MinMTTR) SubModel(org.btrplace.scheduler.runner.disjoint.model.SubModel) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) SubModel(org.btrplace.scheduler.runner.disjoint.model.SubModel) Running(org.btrplace.model.constraint.Running) Test(org.testng.annotations.Test)

Example 2 with SubModel

use of org.btrplace.scheduler.runner.disjoint.model.SubModel in project scheduler by btrplace.

the class FixedNodeSetsPartitioning method split.

@Override
public List<Instance> split(Parameters ps, Instance i) throws SchedulerException {
    Model mo = i.getModel();
    SynchronizedElementBuilder eb = new SynchronizedElementBuilder(mo);
    List<Instance> parts = new ArrayList<>(partitions.size());
    // nb of VMs
    int nbVMs = i.getModel().getMapping().getNbVMs();
    int nbNodes = i.getModel().getMapping().getNbNodes();
    TIntIntHashMap vmPosition = new TIntIntHashMap(nbVMs);
    TIntIntHashMap nodePosition = new TIntIntHashMap(nbNodes);
    int partNumber = 0;
    Set<VM> toLaunch = getVMsToLaunch(i);
    for (Collection<Node> s : partitions) {
        SubModel partModel = new SubModel(mo, eb, s, new HashSet<>(toLaunch.size() / partitions.size()));
        parts.add(new Instance(partModel, new THashSet<>(), i.getOptConstraint()));
        // VM Index
        partModel.getMapping().fillVMIndex(vmPosition, partNumber);
        // Node index
        for (Node n : s) {
            nodePosition.put(n.id(), partNumber);
        }
        partNumber++;
    }
    // Round-robin placement for the VMs to launch
    int p = 0;
    for (VM v : toLaunch) {
        if (!parts.get(p).getModel().getMapping().addReadyVM(v)) {
            throw new SplitException(parts.get(p).getModel(), "Unable to dispatch the VM to launch '" + v + "'");
        }
        vmPosition.put(v.id(), p);
        p = (p + 1) % parts.size();
    }
    // Split the constraints
    for (SatConstraint cstr : i.getSatConstraints()) {
        if (!cstrMapper.split(cstr, i, parts, vmPosition, nodePosition)) {
            throw new SplitException(i.getModel(), "Unable to split " + cstr);
        }
    }
    return parts;
}
Also used : Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) ArrayList(java.util.ArrayList) SatConstraint(org.btrplace.model.constraint.SatConstraint) THashSet(gnu.trove.set.hash.THashSet) SubModel(org.btrplace.scheduler.runner.disjoint.model.SubModel) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) SubModel(org.btrplace.scheduler.runner.disjoint.model.SubModel) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) SynchronizedElementBuilder(org.btrplace.model.SynchronizedElementBuilder)

Example 3 with SubModel

use of org.btrplace.scheduler.runner.disjoint.model.SubModel 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(Collections.singletonList(n2)));
    plan = st.solve(p, i0);
    Assert.assertNull(plan);
    Assert.assertEquals(st.getStatistics().getSolutions().size(), 0);
}
Also used : Parameters(org.btrplace.scheduler.choco.Parameters) 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) SubModel(org.btrplace.scheduler.runner.disjoint.model.SubModel) Running(org.btrplace.model.constraint.Running) Test(org.testng.annotations.Test)

Aggregations

SubModel (org.btrplace.scheduler.runner.disjoint.model.SubModel)3 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 Test (org.testng.annotations.Test)2 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)1 THashSet (gnu.trove.set.hash.THashSet)1 ArrayList (java.util.ArrayList)1 Instance (org.btrplace.model.Instance)1 Model (org.btrplace.model.Model)1 Node (org.btrplace.model.Node)1 SynchronizedElementBuilder (org.btrplace.model.SynchronizedElementBuilder)1 VM (org.btrplace.model.VM)1 SatConstraint (org.btrplace.model.constraint.SatConstraint)1 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)1