Search in sources :

Example 11 with Slice

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

the class CMinMigrations 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()));
        // Fix the duration. The side effect will be that states will be fixed as well
        // with the objective to not do un-necessary actions
        IntVar[] durations = p.getNodeActions().stream().map(Transition::getDuration).toArray(IntVar[]::new);
        strategies.add(new IntStrategy(durations, new FirstFail(rp.getModel()), new IntDomainMin()));
    }
    postCostConstraints();
    // /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) OnStableNodeFirst(org.btrplace.scheduler.choco.constraint.mttr.OnStableNodeFirst) 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) WorstFit(org.btrplace.scheduler.choco.constraint.mttr.WorstFit) Map(java.util.Map) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) StartOnLeafNodes(org.btrplace.scheduler.choco.constraint.mttr.StartOnLeafNodes) CShareableResource(org.btrplace.scheduler.choco.view.CShareableResource) MinMigrations(org.btrplace.model.constraint.MinMigrations) LinkedList(java.util.LinkedList) RandomVMPlacement(org.btrplace.scheduler.choco.constraint.mttr.RandomVMPlacement) Model(org.btrplace.model.Model) BiggestDimension(org.btrplace.scheduler.choco.constraint.mttr.load.BiggestDimension) Iterator(java.util.Iterator) MovementGraph(org.btrplace.scheduler.choco.constraint.mttr.MovementGraph) HostingVariableSelector(org.btrplace.scheduler.choco.constraint.mttr.HostingVariableSelector) Set(java.util.Set) MyInputOrder(org.btrplace.scheduler.choco.constraint.mttr.MyInputOrder) Parameters(org.btrplace.scheduler.choco.Parameters) Collectors(java.util.stream.Collectors) VMPlacementUtils(org.btrplace.scheduler.choco.constraint.mttr.VMPlacementUtils) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Objects(java.util.Objects) IntVar(org.chocosolver.solver.variables.IntVar) 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) MyInputOrder(org.btrplace.scheduler.choco.constraint.mttr.MyInputOrder) 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) StartOnLeafNodes(org.btrplace.scheduler.choco.constraint.mttr.StartOnLeafNodes) 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) MovementGraph(org.btrplace.scheduler.choco.constraint.mttr.MovementGraph) 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) OnStableNodeFirst(org.btrplace.scheduler.choco.constraint.mttr.OnStableNodeFirst) IntDomainMax(org.chocosolver.solver.search.strategy.selectors.values.IntDomainMax)

Example 12 with Slice

use of org.btrplace.scheduler.choco.Slice 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 13 with Slice

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

the class CShareableResource method linkVirtualToPhysicalUsage.

private boolean linkVirtualToPhysicalUsage() throws SchedulerException {
    int min = Integer.MAX_VALUE;
    // Number of VMs with a 0 usage
    int nbZeroes = 0;
    for (int vId = 0; vId < vmAllocation.size(); vId++) {
        int alloc = vmAllocation.get(vId);
        if (alloc > 0) {
            min = Math.min(alloc, min);
        } else {
            nbZeroes++;
        }
    }
    for (int nIdx = 0; nIdx < ratios.size(); nIdx++) {
        if (!linkVirtualToPhysicalUsage(nIdx)) {
            return false;
        }
        if (!capHosting(nIdx, min, nbZeroes)) {
            return false;
        }
    }
    // The slice scheduling constraint that is necessary
    TIntArrayList cUse = new TIntArrayList();
    List<IntVar> dUse = new ArrayList<>();
    for (VMTransition a : rp.getVMActions()) {
        VM vm = a.getVM();
        Slice c = a.getCSlice();
        Slice d = a.getDSlice();
        if (c != null) {
            cUse.add(getSourceResource().getConsumption(vm));
        }
        if (d != null) {
            int m = getVMAllocation(rp.getVM(vm));
            dUse.add(rp.fixed(m, "vmAllocation('", getResourceIdentifier(), "', '", vm, "'"));
        }
    }
    Cumulatives v = (Cumulatives) rp.getView(Cumulatives.VIEW_ID);
    v.addDim(virtRcUsage, cUse.toArray(), dUse.toArray(new IntVar[dUse.size()]));
    checkInitialSatisfaction();
    return true;
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) IntVar(org.chocosolver.solver.variables.IntVar) SatConstraint(org.btrplace.model.constraint.SatConstraint) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 14 with Slice

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

the class CShareableResource method insertActions.

@Override
public boolean insertActions(ReconfigurationProblem r, Solution s, ReconfigurationPlan p) {
    Mapping srcMapping = r.getSourceModel().getMapping();
    // Encache the VM -> Action to ease the event injection.
    Map<VM, Action> actions = new HashMap<>();
    p.getActions().stream().filter(RunningVMPlacement.class::isInstance).map(a -> (RunningVMPlacement) a).forEach(a -> actions.put(destVM(a.getVM()), (Action) a));
    for (VM vm : r.getFutureRunningVMs()) {
        Slice dSlice = r.getVMAction(vm).getDSlice();
        Node destNode = r.getNode(s.getIntVal(dSlice.getHoster()));
        if (srcMapping.isRunning(vm) && destNode.equals(srcMapping.getVMLocation(vm))) {
            // Was running and stay on the same node
            // Check if the VM has been cloned
            // TODO: might be too late depending on the symmetry breaking on the actions schedule
            insertAllocateAction(p, vm, destNode, s.getIntVal(dSlice.getStart()));
        } else {
            VM dVM = destVM(vm);
            Action a = actions.get(dVM);
            if (a instanceof MigrateVM) {
                // For a migrated VM, we allocate once the migration over
                insertAllocateEvent(a, Action.Hook.POST, dVM);
            } else {
                // Resume or Boot VM
                // As the VM was not running, we pre-allocate
                insertAllocateEvent(a, Action.Hook.PRE, dVM);
            }
        }
    }
    return true;
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) Arrays(java.util.Arrays) SchedulerException(org.btrplace.scheduler.SchedulerException) TIntArrayList(gnu.trove.list.array.TIntArrayList) Node(org.btrplace.model.Node) Preserve(org.btrplace.model.constraint.Preserve) Overbook(org.btrplace.model.constraint.Overbook) TDoubleList(gnu.trove.list.TDoubleList) ContradictionException(org.chocosolver.solver.exception.ContradictionException) MigrateVM(org.btrplace.plan.event.MigrateVM) HashMap(java.util.HashMap) RoundedUpDivision(org.btrplace.scheduler.choco.extensions.RoundedUpDivision) TObjectIntMap(gnu.trove.map.TObjectIntMap) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) TObjectDoubleHashMap(gnu.trove.map.hash.TObjectDoubleHashMap) HashSet(java.util.HashSet) TObjectDoubleMap(gnu.trove.map.TObjectDoubleMap) VM(org.btrplace.model.VM) SchedulerModelingException(org.btrplace.scheduler.SchedulerModelingException) Mapping(org.btrplace.model.Mapping) Map(java.util.Map) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) SatConstraint(org.btrplace.model.constraint.SatConstraint) Model(org.btrplace.model.Model) TIntList(gnu.trove.list.TIntList) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) Set(java.util.Set) Cause(org.chocosolver.solver.Cause) Parameters(org.btrplace.scheduler.choco.Parameters) AllocateEvent(org.btrplace.plan.event.AllocateEvent) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) IntVar(org.chocosolver.solver.variables.IntVar) List(java.util.List) TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) RunningVMPlacement(org.btrplace.plan.event.RunningVMPlacement) ResourceRelated(org.btrplace.model.view.ResourceRelated) Allocate(org.btrplace.plan.event.Allocate) ShareableResource(org.btrplace.model.view.ShareableResource) Solution(org.chocosolver.solver.Solution) Instance(org.btrplace.model.Instance) ResourceCapacity(org.btrplace.model.constraint.ResourceCapacity) Action(org.btrplace.plan.event.Action) Collections(java.util.Collections) Action(org.btrplace.plan.event.Action) RunningVMPlacement(org.btrplace.plan.event.RunningVMPlacement) HashMap(java.util.HashMap) TObjectDoubleHashMap(gnu.trove.map.hash.TObjectDoubleHashMap) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) Slice(org.btrplace.scheduler.choco.Slice) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Mapping(org.btrplace.model.Mapping) MigrateVM(org.btrplace.plan.event.MigrateVM)

Example 15 with Slice

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

the class CShareableResource method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem p) throws SchedulerException {
    this.rp = p;
    this.references = new HashMap<>();
    this.clones = new HashMap<>();
    csp = p.getModel();
    this.source = p.getSourceModel();
    List<Node> nodes = p.getNodes();
    phyRcUsage = new ArrayList<>(nodes.size());
    virtRcUsage = new ArrayList<>(nodes.size());
    this.ratios = new TDoubleArrayList(nodes.size());
    id = ShareableResource.VIEW_ID_BASE + rc.getResourceIdentifier();
    for (Node nId : p.getNodes()) {
        phyRcUsage.add(csp.intVar(p.makeVarLabel("phyRcUsage('", rc.getResourceIdentifier(), "', '", nId, "')"), 0, rc.getCapacity(nId), true));
        virtRcUsage.add(csp.intVar(p.makeVarLabel("virtRcUsage('", rc.getResourceIdentifier(), "', '", nId, "')"), 0, Integer.MAX_VALUE / 100, true));
        ratios.add(UNCHECKED_RATIO);
    }
    phyRcUsage = Collections.unmodifiableList(phyRcUsage);
    virtRcUsage = Collections.unmodifiableList(virtRcUsage);
    // Bin packing for the node vmAllocation
    vmAllocation = new TIntArrayList();
    for (VM vmId : p.getVMs()) {
        VMTransition a = p.getVMAction(vmId);
        Slice slice = a.getDSlice();
        if (slice == null) {
            // The VMs will not be running, so its consumption is set to 0
            vmAllocation.add(0);
        } else {
            // We don't know about the next VM usage for the moment, -1 is used by default to allow to detect an
            // non-updated value.
            vmAllocation.add(-1);
        }
    }
    return true;
}
Also used : TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) Slice(org.btrplace.scheduler.choco.Slice) Node(org.btrplace.model.Node) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Aggregations

Slice (org.btrplace.scheduler.choco.Slice)22 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)17 VM (org.btrplace.model.VM)16 ArrayList (java.util.ArrayList)12 IntVar (org.chocosolver.solver.variables.IntVar)11 Node (org.btrplace.model.Node)8 List (java.util.List)6 TIntArrayList (gnu.trove.list.array.TIntArrayList)5 TObjectIntMap (gnu.trove.map.TObjectIntMap)5 Collections (java.util.Collections)5 HashSet (java.util.HashSet)5 Map (java.util.Map)5 Objects (java.util.Objects)5 Set (java.util.Set)5 Instance (org.btrplace.model.Instance)5 Mapping (org.btrplace.model.Mapping)5 Model (org.btrplace.model.Model)5 ShareableResource (org.btrplace.model.view.ShareableResource)5 SchedulerException (org.btrplace.scheduler.SchedulerException)5 Parameters (org.btrplace.scheduler.choco.Parameters)5