Search in sources :

Example 1 with Instance

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

the class KilledSplitterTest method simpleTest.

@Test
public void simpleTest() {
    KilledSplitter splitter = new KilledSplitter();
    List<Instance> instances = new ArrayList<>();
    Model m0 = new DefaultModel();
    VM v = m0.newVM(1);
    m0.getMapping().addReadyVM(v);
    m0.getMapping().addRunningVM(m0.newVM(2), m0.newNode(1));
    Model m1 = new DefaultModel();
    m1.getMapping().addReadyVM(m1.newVM(3));
    m1.getMapping().addSleepingVM(m1.newVM(4), m1.newNode(2));
    m1.getMapping().addRunningVM(m1.newVM(5), m1.newNode(3));
    instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
    instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
    TIntIntHashMap index = Instances.makeVMIndex(instances);
    Set<VM> all = new HashSet<>(m0.getMapping().getAllVMs());
    all.addAll(m1.getMapping().getAllVMs());
    // Only VMs in m0
    Killed single = new Killed(v);
    Assert.assertTrue(splitter.split(single, null, instances, index, new TIntIntHashMap()));
    Assert.assertTrue(instances.get(0).getSatConstraints().contains(single));
    Assert.assertFalse(instances.get(1).getSatConstraints().contains(single));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) VM(org.btrplace.model.VM) ArrayList(java.util.ArrayList) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) MinMTTR(org.btrplace.model.constraint.MinMTTR) Killed(org.btrplace.model.constraint.Killed) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with Instance

use of org.btrplace.model.Instance 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 3 with Instance

use of org.btrplace.model.Instance 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 4 with Instance

use of org.btrplace.model.Instance 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 5 with Instance

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

the class InstanceSolverRunner method call.

@Override
// for the LifeCycleViolationException
@SuppressWarnings("squid:S1166")
public SolvingStatistics call() throws SchedulerException {
    stats = new SingleRunnerStatistics(params, instance, System.currentTimeMillis());
    rp = null;
    // Build the core problem
    long d = -System.currentTimeMillis();
    try {
        rp = buildRP();
    } catch (@SuppressWarnings("unused") LifeCycleViolationException ex) {
        // If there is a violation of the cycle it is not a bug that should be propagated
        // it it just indicating there is no solution
        stats.setCompleted(true);
        stats.setMetrics(new Metrics());
        return stats;
    } finally {
        d += System.currentTimeMillis();
        stats.setCoreBuildDuration(d);
    }
    stats.setNbManagedVMs(rp.getManageableVMs().size());
    // Customize the core problem
    d = -System.currentTimeMillis();
    if (!specialise()) {
        d += System.currentTimeMillis();
        stats.setSpecialisationDuration(d);
        stats.setCompleted(true);
        return getStatistics();
    }
    d += System.currentTimeMillis();
    stats.setSpecialisationDuration(d);
    // statistics
    stats.setMetrics(new Metrics(rp.getSolver().getMeasures()));
    rp.getLogger().debug(stats.toString());
    // The solution monitor to store the measures at each solution
    rp.getSolver().plugMonitor((IMonitorSolution) () -> {
        Solution solution = new Solution(rp.getModel());
        solution.record();
        ReconfigurationPlan plan = rp.buildReconfigurationPlan(solution, origin);
        views.forEach(v -> v.insertActions(rp, solution, plan));
        MeasuresRecorder m = rp.getSolver().getMeasures();
        SolutionStatistics st = new SolutionStatistics(new Metrics(m), plan);
        IntVar o = rp.getObjective();
        if (o != null) {
            st.setObjective(solution.getIntVal(o));
        }
        stats.addSolution(st);
        params.solutionListeners().forEach(c -> c.accept(rp, plan));
    });
    setVerbosity();
    // The actual solving process
    rp.solve(params.getTimeLimit(), params.doOptimize());
    return getStatistics();
}
Also used : LifeCycleViolationException(org.btrplace.scheduler.choco.LifeCycleViolationException) ChocoView(org.btrplace.scheduler.choco.view.ChocoView) Ready(org.btrplace.model.constraint.Ready) MeasuresRecorder(org.chocosolver.solver.search.measure.MeasuresRecorder) SchedulerException(org.btrplace.scheduler.SchedulerException) Node(org.btrplace.model.Node) OptConstraint(org.btrplace.model.constraint.OptConstraint) ContradictionException(org.chocosolver.solver.exception.ContradictionException) Callable(java.util.concurrent.Callable) SolvingStatistics(org.btrplace.scheduler.choco.runner.SolvingStatistics) CObjective(org.btrplace.scheduler.choco.constraint.CObjective) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) VM(org.btrplace.model.VM) Running(org.btrplace.model.constraint.Running) SchedulerModelingException(org.btrplace.scheduler.SchedulerModelingException) Measures(org.chocosolver.solver.search.measure.Measures) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) IMonitorSolution(org.chocosolver.solver.search.loop.monitors.IMonitorSolution) SearchState(org.chocosolver.solver.search.SearchState) ChocoMapper(org.btrplace.scheduler.choco.constraint.ChocoMapper) SatConstraint(org.btrplace.model.constraint.SatConstraint) Model(org.btrplace.model.Model) Sleeping(org.btrplace.model.constraint.Sleeping) Constraint(org.btrplace.model.constraint.Constraint) Collection(java.util.Collection) SolutionStatistics(org.btrplace.scheduler.choco.runner.SolutionStatistics) Set(java.util.Set) ChocoConstraint(org.btrplace.scheduler.choco.constraint.ChocoConstraint) Cause(org.chocosolver.solver.Cause) Parameters(org.btrplace.scheduler.choco.Parameters) IntVar(org.chocosolver.solver.variables.IntVar) List(java.util.List) Killed(org.btrplace.model.constraint.Killed) Metrics(org.btrplace.scheduler.choco.runner.Metrics) ChocoViews(org.btrplace.scheduler.choco.view.ChocoViews) Solution(org.chocosolver.solver.Solution) Optional(java.util.Optional) Instance(org.btrplace.model.Instance) Metrics(org.btrplace.scheduler.choco.runner.Metrics) LifeCycleViolationException(org.btrplace.scheduler.choco.LifeCycleViolationException) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) SolutionStatistics(org.btrplace.scheduler.choco.runner.SolutionStatistics) IntVar(org.chocosolver.solver.variables.IntVar) IMonitorSolution(org.chocosolver.solver.search.loop.monitors.IMonitorSolution) Solution(org.chocosolver.solver.Solution) MeasuresRecorder(org.chocosolver.solver.search.measure.MeasuresRecorder)

Aggregations

Instance (org.btrplace.model.Instance)34 Test (org.testng.annotations.Test)24 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)20 Model (org.btrplace.model.Model)19 ArrayList (java.util.ArrayList)17 DefaultModel (org.btrplace.model.DefaultModel)14 MinMTTR (org.btrplace.model.constraint.MinMTTR)13 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)12 Node (org.btrplace.model.Node)12 VM (org.btrplace.model.VM)12 StringReader (java.io.StringReader)10 HashSet (java.util.HashSet)10 SatConstraint (org.btrplace.model.constraint.SatConstraint)8 List (java.util.List)5 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)5 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)4 File (java.io.File)3 MinMigrations (org.btrplace.model.constraint.MinMigrations)3 Spread (org.btrplace.model.constraint.Spread)3 MigrateVM (org.btrplace.plan.event.MigrateVM)3