Search in sources :

Example 16 with Instance

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

the class CMinMigrationsTest method main.

public static void main(String[] args) {
    String root = "/Users/fabien.hermenier/Documents/BtrPlace/nutanix/instances";
    List<OptConstraint> objs = Arrays.asList(/*new MinMTTR(),*/
    new MinMigrations());
    boolean verbose = true;
    for (OptConstraint o : objs) {
        System.out.print(" " + o);
    }
    System.out.println();
    for (int idx = 1; idx <= 256; idx += 5) {
        String path = root + "/lazan/lazan-" + idx + ".json.gz";
        if (verbose) {
            System.out.println("--- " + idx + " --- ");
        } else {
            System.out.print(idx);
        }
        List<Long> res = new ArrayList<>();
        for (OptConstraint o : objs) {
            if (verbose) {
                System.out.println("\t" + o);
            }
            Instance i = JSON.readInstance(new File(path));
            if (Network.get(i.getModel()) != null) {
                i.getModel().detach(Network.get(i.getModel()));
            }
            i = new Instance(i.getModel(), i.getSatConstraints(), o);
            ChocoScheduler s = new DefaultChocoScheduler();
            s.doOptimize(false);
            s.setTimeLimit(30);
            s.doRepair(false);
            ReconfigurationPlan p = s.solve(i);
            Assert.assertNotNull(p);
            res.add(p.getActions().stream().filter(x -> x instanceof MigrateVM).mapToLong(x -> x.getEnd() - x.getStart()).sum());
            // res.add((long)s.getStatistics().lastSolution().getDuration());
            if (verbose) {
                System.out.println(s.getStatistics());
            // System.out.println(p);
            }
        }
        if (!verbose) {
            for (Long l : res) {
                System.out.print("\t" + l);
            }
            System.out.println();
        }
    }
}
Also used : Model(org.btrplace.model.Model) Arrays(java.util.Arrays) Node(org.btrplace.model.Node) OptConstraint(org.btrplace.model.constraint.OptConstraint) Spread(org.btrplace.model.constraint.Spread) Preserve(org.btrplace.model.constraint.Preserve) MigrateVM(org.btrplace.plan.event.MigrateVM) Test(org.testng.annotations.Test) DefaultModel(org.btrplace.model.DefaultModel) JSON(org.btrplace.json.JSON) File(java.io.File) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) VM(org.btrplace.model.VM) List(java.util.List) Assert(org.testng.Assert) ShareableResource(org.btrplace.model.view.ShareableResource) Instance(org.btrplace.model.Instance) MinMigrations(org.btrplace.model.constraint.MinMigrations) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Network(org.btrplace.model.view.network.Network) SatConstraint(org.btrplace.model.constraint.SatConstraint) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) Instance(org.btrplace.model.Instance) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) MigrateVM(org.btrplace.plan.event.MigrateVM) OptConstraint(org.btrplace.model.constraint.OptConstraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) OptConstraint(org.btrplace.model.constraint.OptConstraint) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) MinMigrations(org.btrplace.model.constraint.MinMigrations) File(java.io.File)

Example 17 with Instance

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

the class DefaultChocoScheduler method solve.

@Override
public ReconfigurationPlan solve(Instance i) throws SchedulerException {
    Model mo = i.getModel();
    Collection<SatConstraint> cstrs = i.getSatConstraints();
    // If a network view is attached, ensure that all the migrations' destination node are defined
    Network net = Network.get(mo);
    stages = null;
    if (net != null) {
        // The network view is useless to take placement decisions
        mo.detach(net);
        // Solve a first time using placement oriented MinMTTR optimisation constraint
        ReconfigurationPlan p = runner.solve(params, i);
        stages = new StagedSolvingStatistics(runner.getStatistics());
        if (p == null) {
            return null;
        }
        // Add Fence constraints for each destination node chosen
        List<SatConstraint> newCstrs = p.getActions().stream().filter(a -> a instanceof MigrateVM).map(a -> new Fence(((MigrateVM) a).getVM(), Collections.singleton(((MigrateVM) a).getDestinationNode()))).collect(Collectors.toList());
        Model result = p.getResult();
        if (result == null) {
            throw new InconsistentSolutionException(mo, p, "The plan cannot be applied");
        }
        // Add Root constraints to all staying VMs
        newCstrs.addAll(mo.getMapping().getRunningVMs().stream().filter(v -> p.getOrigin().getMapping().getVMLocation(v).id() == result.getMapping().getVMLocation(v).id()).map(Root::new).collect(Collectors.toList()));
        // Add the old constraints
        newCstrs.addAll(cstrs);
        // Re-attach the network view
        mo.attach(net);
        // New timeout value = elapsed time - initial timeout value
        Parameters ps = new DefaultParameters(params);
        if (ps.getTimeLimit() > 0) {
            // in seconds
            double timeout = params.getTimeLimit() - runner.getStatistics().getMetrics().timeCount() / 1000;
            ps.setTimeLimit((int) timeout);
        }
        return runner.solve(ps, new Instance(mo, newCstrs, i.getOptConstraint()));
    }
    // Solve and return the computed plan
    return runner.solve(params, new Instance(mo, cstrs, i.getOptConstraint()));
}
Also used : ChocoView(org.btrplace.scheduler.choco.view.ChocoView) Root(org.btrplace.model.constraint.Root) SchedulerException(org.btrplace.scheduler.SchedulerException) MigrateVM(org.btrplace.plan.event.MigrateVM) SolvingStatistics(org.btrplace.scheduler.choco.runner.SolvingStatistics) Fence(org.btrplace.model.constraint.Fence) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) SingleRunner(org.btrplace.scheduler.choco.runner.single.SingleRunner) BiConsumer(java.util.function.BiConsumer) ChocoMapper(org.btrplace.scheduler.choco.constraint.ChocoMapper) SatConstraint(org.btrplace.model.constraint.SatConstraint) Model(org.btrplace.model.Model) StagedSolvingStatistics(org.btrplace.scheduler.choco.runner.StagedSolvingStatistics) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) Collection(java.util.Collection) TransitionFactory(org.btrplace.scheduler.choco.transition.TransitionFactory) Collectors(java.util.stream.Collectors) MinMTTR(org.btrplace.model.constraint.MinMTTR) InconsistentSolutionException(org.btrplace.scheduler.InconsistentSolutionException) List(java.util.List) Instance(org.btrplace.model.Instance) InstanceSolver(org.btrplace.scheduler.choco.runner.InstanceSolver) Collections(java.util.Collections) Network(org.btrplace.model.view.network.Network) Settings(org.chocosolver.solver.Settings) InconsistentSolutionException(org.btrplace.scheduler.InconsistentSolutionException) Root(org.btrplace.model.constraint.Root) Instance(org.btrplace.model.Instance) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) StagedSolvingStatistics(org.btrplace.scheduler.choco.runner.StagedSolvingStatistics) Network(org.btrplace.model.view.network.Network) Model(org.btrplace.model.Model) Fence(org.btrplace.model.constraint.Fence)

Example 18 with Instance

use of org.btrplace.model.Instance 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(Arrays.asList(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 19 with Instance

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

the class IssuesTest method computable.

/**
 * A helper to check that an instance has a solution.
 *
 * @param file the serialised instance. Must be in 'src/test/resources/'
 */
private static void computable(String file) {
    Instance i = JSON.readInstance(new File("src/test/resources/" + file));
    ChocoScheduler s = new DefaultChocoScheduler();
    ReconfigurationPlan p = s.solve(i);
    System.out.println(s.getStatistics());
    Assert.assertNotNull(p);
    System.out.println(p.getSize() + " action(s)");
}
Also used : Instance(org.btrplace.model.Instance) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) File(java.io.File)

Example 20 with Instance

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

the class IssuesTest method issue72.

@Test
public void issue72() throws Exception {
    String input = "{\"model\":{\"mapping\":{\"readyVMs\":[],\"onlineNodes\":{\"0\":{\"sleepingVMs\":[],\"runningVMs\":[9,8,7,6,5,4,3,2,1,0]},\"1\":{\"sleepingVMs\":[],\"runningVMs\":[19,18,17,16,15,14,13,12,11,10]}},\"offlineNodes\":[]},\"attributes\":{\"nodes\":{},\"vms\":{}},\"views\":[{\"defConsumption\":0,\"nodes\":{\"0\":32768,\"1\":32768},\"rcId\":\"mem\",\"id\":\"shareableResource\",\"defCapacity\":8192,\"vms\":{\"11\":1024,\"12\":1024,\"13\":1024,\"14\":1024,\"15\":1024,\"16\":1024,\"17\":1024,\"18\":1024,\"19\":1024,\"0\":1024,\"1\":1024,\"2\":1024,\"3\":1024,\"4\":1024,\"5\":1024,\"6\":1024,\"7\":1024,\"8\":1024,\"9\":1024,\"10\":1024}},{\"defConsumption\":0,\"nodes\":{\"0\":700,\"1\":700},\"rcId\":\"cpu\",\"id\":\"shareableResource\",\"defCapacity\":8000,\"vms\":{\"11\":0,\"12\":0,\"13\":0,\"14\":0,\"15\":0,\"16\":70,\"17\":0,\"18\":60,\"19\":0,\"0\":100,\"1\":0,\"2\":0,\"3\":0,\"4\":0,\"5\":0,\"6\":0,\"7\":0,\"8\":90,\"9\":0,\"10\":0}}]},\"constraints\":[],\"objective\":{\"id\":\"minimizeMTTR\"}}";
    Instance i = JSON.readInstance(new StringReader(input));
    ChocoScheduler s = new DefaultChocoScheduler();
    s.setTimeLimit(-1);
    i.getModel().detach(ShareableResource.get(i.getModel(), "mem"));
    i.getModel().detach(ShareableResource.get(i.getModel(), "cpu"));
    List<SatConstraint> cstrs = new ArrayList<>();
    ReconfigurationPlan p = s.solve(i.getModel(), cstrs, i.getOptConstraint());
    Assert.assertTrue(p.getActions().isEmpty());
}
Also used : Instance(org.btrplace.model.Instance) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

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