Search in sources :

Example 21 with Parameters

use of org.btrplace.scheduler.choco.Parameters in project scheduler by btrplace.

the class CMinMTTR method injectPlacementHeuristic.

private void injectPlacementHeuristic(ReconfigurationProblem p, Parameters ps, IntVar cost) {
    List<CShareableResource> rcs = rp.getSourceModel().getViews().stream().filter(v -> v instanceof ShareableResource).map(v -> (CShareableResource) rp.getView(v.getIdentifier())).collect(Collectors.toList());
    useResources = !rcs.isEmpty();
    Model mo = p.getSourceModel();
    Mapping map = mo.getMapping();
    OnStableNodeFirst schedHeuristic = new OnStableNodeFirst(p);
    // Get the VMs to place
    Set<VM> onBadNodes = new HashSet<>(p.getManageableVMs());
    // Get the VMs that runs and have a pretty low chances to move
    Set<VM> onGoodNodes = map.getRunningVMs(map.getOnlineNodes());
    onGoodNodes.removeAll(onBadNodes);
    List<VMTransition> goodActions = p.getVMActions(onGoodNodes);
    List<VMTransition> badActions = p.getVMActions(onBadNodes);
    Solver s = p.getSolver();
    // Get the VMs to move for exclusion issue
    Set<VM> vmsToExclude = new HashSet<>(p.getManageableVMs());
    for (Iterator<VM> ite = vmsToExclude.iterator(); ite.hasNext(); ) {
        VM vm = ite.next();
        if (!(map.isRunning(vm) && p.getFutureRunningVMs().contains(vm))) {
            ite.remove();
        }
    }
    List<AbstractStrategy<?>> strategies = new ArrayList<>();
    Map<IntVar, VM> pla = VMPlacementUtils.makePlacementMap(p);
    if (!vmsToExclude.isEmpty()) {
        List<VMTransition> actions = new LinkedList<>();
        // Get all the involved slices
        for (VM vm : vmsToExclude) {
            if (p.getFutureRunningVMs().contains(vm)) {
                actions.add(p.getVMAction(vm));
            }
        }
        placeVMs(ps, strategies, actions, schedHeuristic, pla);
    }
    TObjectIntMap<VM> costs = CShareableResource.getWeights(rp, rcs);
    badActions.sort((v2, v1) -> costs.get(v1.getVM()) - costs.get(v2.getVM()));
    goodActions.sort((v2, v1) -> costs.get(v1.getVM()) - costs.get(v2.getVM()));
    placeVMs(ps, strategies, badActions, schedHeuristic, pla);
    placeVMs(ps, strategies, goodActions, schedHeuristic, pla);
    // Reinstantations. Try to reinstantiate first
    List<IntVar> migs = new ArrayList<>();
    for (VMTransition t : rp.getVMActions()) {
        if (t instanceof RelocatableVM) {
            migs.add(((RelocatableVM) t).getRelocationMethod());
        }
    }
    strategies.add(Search.intVarSearch(new FirstFail(rp.getModel()), new IntDomainMax(), migs.toArray(new IntVar[migs.size()])));
    if (!p.getNodeActions().isEmpty()) {
        // Boot some nodes if needed
        IntVar[] starts = p.getNodeActions().stream().map(Transition::getStart).toArray(IntVar[]::new);
        strategies.add(new IntStrategy(starts, new FirstFail(rp.getModel()), new IntDomainMin()));
    }
    // /SCHEDULING PROBLEM
    MovementGraph gr = new MovementGraph(rp);
    IntVar[] starts = dSlices(rp.getVMActions()).map(Slice::getStart).filter(v -> !v.isInstantiated()).toArray(IntVar[]::new);
    strategies.add(new IntStrategy(starts, new StartOnLeafNodes(rp, gr), new IntDomainMin()));
    strategies.add(new IntStrategy(schedHeuristic.getScope(), schedHeuristic, new IntDomainMin()));
    IntVar[] ends = rp.getVMActions().stream().map(Transition::getEnd).filter(v -> !v.isInstantiated()).toArray(IntVar[]::new);
    strategies.add(Search.intVarSearch(new MyInputOrder<>(s), new IntDomainMin(), ends));
    // At this stage only it matters to plug the cost constraints
    strategies.add(new IntStrategy(new IntVar[] { p.getEnd(), cost }, new MyInputOrder<>(s, this), new IntDomainMin()));
    s.setSearch(new StrategiesSequencer(s.getEnvironment(), strategies.toArray(new AbstractStrategy[strategies.size()])));
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) SchedulerException(org.btrplace.scheduler.SchedulerException) Transition(org.btrplace.scheduler.choco.transition.Transition) StrategiesSequencer(org.chocosolver.solver.search.strategy.strategy.StrategiesSequencer) Solver(org.chocosolver.solver.Solver) Search(org.chocosolver.solver.search.strategy.Search) CObjective(org.btrplace.scheduler.choco.constraint.CObjective) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) IntDomainMin(org.chocosolver.solver.search.strategy.selectors.values.IntDomainMin) TObjectIntMap(gnu.trove.map.TObjectIntMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) VM(org.btrplace.model.VM) FirstFail(org.chocosolver.solver.search.strategy.selectors.variables.FirstFail) Mapping(org.btrplace.model.Mapping) Map(java.util.Map) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) CShareableResource(org.btrplace.scheduler.choco.view.CShareableResource) LinkedList(java.util.LinkedList) Model(org.btrplace.model.Model) BiggestDimension(org.btrplace.scheduler.choco.constraint.mttr.load.BiggestDimension) Iterator(java.util.Iterator) Set(java.util.Set) Parameters(org.btrplace.scheduler.choco.Parameters) Collectors(java.util.stream.Collectors) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Objects(java.util.Objects) IntVar(org.chocosolver.solver.variables.IntVar) MinMTTR(org.btrplace.model.constraint.MinMTTR) List(java.util.List) Stream(java.util.stream.Stream) IntStrategy(org.chocosolver.solver.search.strategy.strategy.IntStrategy) ShareableResource(org.btrplace.model.view.ShareableResource) IntValueSelector(org.chocosolver.solver.search.strategy.selectors.values.IntValueSelector) Instance(org.btrplace.model.Instance) AbstractStrategy(org.chocosolver.solver.search.strategy.strategy.AbstractStrategy) IntDomainMax(org.chocosolver.solver.search.strategy.selectors.values.IntDomainMax) Collections(java.util.Collections) Solver(org.chocosolver.solver.Solver) ArrayList(java.util.ArrayList) Mapping(org.btrplace.model.Mapping) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) AbstractStrategy(org.chocosolver.solver.search.strategy.strategy.AbstractStrategy) CShareableResource(org.btrplace.scheduler.choco.view.CShareableResource) ShareableResource(org.btrplace.model.view.ShareableResource) IntVar(org.chocosolver.solver.variables.IntVar) IntStrategy(org.chocosolver.solver.search.strategy.strategy.IntStrategy) IntDomainMin(org.chocosolver.solver.search.strategy.selectors.values.IntDomainMin) FirstFail(org.chocosolver.solver.search.strategy.selectors.variables.FirstFail) CShareableResource(org.btrplace.scheduler.choco.view.CShareableResource) HashSet(java.util.HashSet) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) StrategiesSequencer(org.chocosolver.solver.search.strategy.strategy.StrategiesSequencer) LinkedList(java.util.LinkedList) Slice(org.btrplace.scheduler.choco.Slice) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) Transition(org.btrplace.scheduler.choco.transition.Transition) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) IntDomainMax(org.chocosolver.solver.search.strategy.selectors.values.IntDomainMax)

Example 22 with Parameters

use of org.btrplace.scheduler.choco.Parameters 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)

Example 23 with Parameters

use of org.btrplace.scheduler.choco.Parameters in project scheduler by btrplace.

the class SingleRunnerStatisticsTest method testInstantiate.

@Test
public void testInstantiate() {
    Parameters ps = new DefaultParameters();
    Model mo = new DefaultModel();
    long st = System.currentTimeMillis();
    List<SatConstraint> cstrs = new ArrayList<>();
    Instance i = new Instance(mo, cstrs, new MinMTTR());
    SingleRunnerStatistics stats = new SingleRunnerStatistics(ps, i, st);
    Assert.assertEquals(stats.getStart(), st);
    Assert.assertEquals(stats.getCoreBuildDuration(), -1);
    Assert.assertEquals(stats.getSpecializationDuration(), -1);
    Assert.assertEquals(stats.getInstance(), i);
    Assert.assertEquals(stats.getNbManagedVMs(), -1);
    Assert.assertEquals(stats.getParameters(), ps);
    Assert.assertEquals(stats.getSolutions().size(), 0);
    Assert.assertEquals(stats.completed(), false);
    Assert.assertEquals(stats.getMetrics(), null);
    stats.setCoreBuildDuration(12);
    stats.setSpecialisationDuration(17);
    stats.setNbManagedVMs(18);
    stats.setCompleted(true);
    Assert.assertEquals(stats.getCoreBuildDuration(), 12);
    Assert.assertEquals(stats.getSpecializationDuration(), 17);
    Assert.assertEquals(stats.getNbManagedVMs(), 18);
    Assert.assertEquals(stats.completed(), true);
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
    SolutionStatistics sol = new SolutionStatistics(new Metrics(), plan);
    stats.addSolution(sol);
    Assert.assertEquals(stats.getSolutions().size(), 1);
    Assert.assertEquals(stats.getSolutions().get(0), sol);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Instance(org.btrplace.model.Instance) SatConstraint(org.btrplace.model.constraint.SatConstraint) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) SolutionStatistics(org.btrplace.scheduler.choco.runner.SolutionStatistics) ArrayList(java.util.ArrayList) MinMTTR(org.btrplace.model.constraint.MinMTTR) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) Metrics(org.btrplace.scheduler.choco.runner.Metrics) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 24 with Parameters

use of org.btrplace.scheduler.choco.Parameters in project scheduler by btrplace.

the class BootVMTest method testBasics.

/**
 * Just boot a VM on a  node.
 */
@Test
public void testBasics() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    final VM vm1 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    map.addOnlineNode(n1);
    map.addOnlineNode(n2);
    map.addReadyVM(vm1);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(org.btrplace.plan.event.BootVM.class, new ConstantActionDuration<>(5));
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), map.getAllVMs(), new HashSet<>(), new HashSet<>()).build();
    rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
    rp.getNodeActions().get(1).getState().instantiateTo(1, Cause.Null);
    BootVM m = (BootVM) rp.getVMActions().get(0);
    Assert.assertEquals(vm1, m.getVM());
    Assert.assertNull(m.getCSlice());
    Assert.assertTrue(m.getDuration().isInstantiatedTo(5));
    Assert.assertTrue(m.getState().isInstantiatedTo(1));
    Assert.assertFalse(m.getDSlice().getHoster().isInstantiated());
    Assert.assertFalse(m.getDSlice().getStart().isInstantiated());
    Assert.assertFalse(m.getDSlice().getEnd().isInstantiated());
    new CMinMTTR().inject(ps, rp);
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    org.btrplace.plan.event.BootVM a = (org.btrplace.plan.event.BootVM) p.getActions().iterator().next();
    Node dest = rp.getNode(m.getDSlice().getHoster().getValue());
    Assert.assertEquals(vm1, a.getVM());
    Assert.assertEquals(dest, a.getDestinationNode());
    Assert.assertEquals(5, a.getEnd() - a.getStart());
}
Also used : Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 25 with Parameters

use of org.btrplace.scheduler.choco.Parameters in project scheduler by btrplace.

the class ForgeVMTest method testWithoutTemplate.

@Test(expectedExceptions = { SchedulerException.class })
public void testWithoutTemplate() throws SchedulerException {
    Model mo = new DefaultModel();
    final VM vm1 = mo.newVM();
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(org.btrplace.plan.event.ForgeVM.class, new ConstantActionDuration<>(7));
    new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(Collections.singleton(vm1), Collections.emptySet(), Collections.emptySet(), Collections.emptySet()).build();
}
Also used : Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) Test(org.testng.annotations.Test)

Aggregations

Parameters (org.btrplace.scheduler.choco.Parameters)36 ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)31 Test (org.testng.annotations.Test)31 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)29 DefaultReconfigurationProblemBuilder (org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder)28 DurationEvaluators (org.btrplace.scheduler.choco.duration.DurationEvaluators)28 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)27 CMinMTTR (org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR)14 HashSet (java.util.HashSet)13 Model (org.btrplace.model.Model)12 Mapping (org.btrplace.model.Mapping)11 VM (org.btrplace.model.VM)11 ShutdownNode (org.btrplace.plan.event.ShutdownNode)10 BootNode (org.btrplace.plan.event.BootNode)9 DefaultModel (org.btrplace.model.DefaultModel)8 Action (org.btrplace.plan.event.Action)8 Node (org.btrplace.model.Node)7 MigrateVM (org.btrplace.plan.event.MigrateVM)7 ArrayList (java.util.ArrayList)5 Instance (org.btrplace.model.Instance)5