Search in sources :

Example 21 with VM

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

the class CSerialize method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
    // Get the solver
    Model csp = rp.getModel();
    // Not enough VMs
    if (ser.getInvolvedVMs().size() < 2) {
        return true;
    }
    // Get all migrations involved
    for (VM vm : ser.getInvolvedVMs()) {
        VMTransition vt = rp.getVMAction(vm);
        if (vt instanceof RelocatableVM) {
            migrationList.add((RelocatableVM) vt);
        }
    }
    // Not enough migrations
    if (migrationList.size() < 2) {
        return true;
    }
    // Using a cumulative
    List<Task> tasks = new ArrayList<>();
    for (RelocatableVM mig : migrationList) {
        tasks.add(new Task(mig.getStart(), mig.getDuration(), mig.getEnd()));
    }
    IntVar[] heights = new IntVar[tasks.size()];
    Arrays.fill(heights, csp.intVar(1));
    csp.post(csp.cumulative(tasks.toArray(new Task[tasks.size()]), heights, csp.intVar(1), true));
    return true;
}
Also used : Task(org.chocosolver.solver.variables.Task) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) Model(org.chocosolver.solver.Model) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) IntVar(org.chocosolver.solver.variables.IntVar)

Example 22 with VM

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

the class CMinMTTR method placeVMs.

/*
     * Try to place the VMs associated on the actions in a random node while trying first to stay on the current node
     */
private void placeVMs(Parameters ps, List<AbstractStrategy<?>> strategies, List<VMTransition> actions, OnStableNodeFirst schedHeuristic, Map<IntVar, VM> map) {
    IntValueSelector rnd = new WorstFit(map, rp, new BiggestDimension());
    if (!useResources) {
        rnd = new RandomVMPlacement(rp, map, true, ps.getRandomSeed());
    }
    IntVar[] hosts = dSlices(actions).map(Slice::getHoster).filter(v -> !v.isInstantiated()).toArray(IntVar[]::new);
    if (hosts.length > 0) {
        strategies.add(new IntStrategy(hosts, new HostingVariableSelector(rp.getModel(), schedHeuristic), rnd));
    }
}
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) BiggestDimension(org.btrplace.scheduler.choco.constraint.mttr.load.BiggestDimension) IntStrategy(org.chocosolver.solver.search.strategy.strategy.IntStrategy) Slice(org.btrplace.scheduler.choco.Slice) IntVar(org.chocosolver.solver.variables.IntVar) IntValueSelector(org.chocosolver.solver.search.strategy.selectors.values.IntValueSelector)

Example 23 with VM

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

the class LinearToAResourceActionDuration method evaluate.

@Override
public int evaluate(Model mo, E e) {
    ShareableResource r = ShareableResource.get(mo, rc);
    if (r == null) {
        return -1;
    }
    int x;
    if (e instanceof VM) {
        x = r.getConsumption((VM) e);
    } else if (e instanceof Node) {
        x = r.getCapacity((Node) e);
    } else {
        return -1;
    }
    return (int) Math.round(coefficient * x + offset);
}
Also used : VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) ShareableResource(org.btrplace.model.view.ShareableResource)

Example 24 with VM

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

the class RelocatableVM method insertActions.

@Override
public boolean insertActions(Solution s, ReconfigurationPlan plan) {
    DurationEvaluators dev = rp.getDurationEvaluators();
    // Only if the VM doesn't stay
    if (s.getIntVal(cSlice.getHoster()) != (s.getIntVal(dSlice.getHoster()))) {
        Action a;
        Node dst = rp.getNode(s.getIntVal(dSlice.getHoster()));
        // Migration
        if (s.getIntVal(doReinstantiation) == 0) {
            int st = s.getIntVal(getStart());
            int ed = s.getIntVal(getEnd());
            if (getBandwidth() != null) {
                a = new MigrateVM(vm, src, dst, st, ed, s.getIntVal(getBandwidth()));
            } else {
                a = new MigrateVM(vm, src, dst, st, ed);
            }
            plan.add(a);
        // Re-instantiation
        } else {
            VM newVM = rp.cloneVM(vm);
            if (newVM == null) {
                rp.getLogger().error("Unable to get a new int to plan the re-instantiate of VM {}", vm);
                return false;
            }
            org.btrplace.plan.event.ForgeVM fvm = new org.btrplace.plan.event.ForgeVM(newVM, s.getIntVal(dSlice.getStart()) - dev.evaluate(rp.getSourceModel(), org.btrplace.plan.event.ForgeVM.class, vm), s.getIntVal(dSlice.getStart()));
            // forge the new VM from a template
            plan.add(fvm);
            // Boot the new VM
            int endForging = fvm.getEnd();
            org.btrplace.plan.event.BootVM boot = new org.btrplace.plan.event.BootVM(newVM, dst, endForging, endForging + dev.evaluate(rp.getSourceModel(), org.btrplace.plan.event.BootVM.class, newVM));
            boot.addEvent(Action.Hook.PRE, new SubstitutedVMEvent(vm, newVM));
            return plan.add(boot) && plan.add(new org.btrplace.plan.event.ShutdownVM(vm, src, boot.getEnd(), s.getIntVal(cSlice.getEnd())));
        }
    }
    return true;
}
Also used : Action(org.btrplace.plan.event.Action) Node(org.btrplace.model.Node) MigrateVM(org.btrplace.plan.event.MigrateVM) SubstitutedVMEvent(org.btrplace.plan.event.SubstitutedVMEvent) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators)

Example 25 with VM

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

the class CShareableResource method beforeSolve.

/**
 * Set the resource usage for each of the VM.
 * If the LB is < 0 , the previous consumption is used to maintain the resource usage.
 * Otherwise, the usage is set to the variable lower bound.
 *
 * @return false if an operation leads to a problem without solution
 */
@Override
public boolean beforeSolve(ReconfigurationProblem p) throws SchedulerException {
    for (VM vm : source.getMapping().getAllVMs()) {
        int vmId = p.getVM(vm);
        int v = getVMAllocation(vmId);
        if (v < 0) {
            int prevUsage = rc.getConsumption(vm);
            minVMAllocation(vmId, prevUsage);
        }
    }
    ChocoView v = rp.getView(Packing.VIEW_ID);
    if (v == null) {
        throw SchedulerModelingException.missingView(rp.getSourceModel(), Packing.VIEW_ID);
    }
    IntVar[] host = new IntVar[p.getFutureRunningVMs().size()];
    int[] demand = new int[host.length];
    int i = 0;
    for (VM vm : p.getFutureRunningVMs()) {
        host[i] = rp.getVMAction(vm).getDSlice().getHoster();
        demand[i] = getVMAllocation(p.getVM(vm));
        i++;
    }
    ((Packing) v).addDim(rc.getResourceIdentifier(), virtRcUsage, demand, host);
    return linkVirtualToPhysicalUsage();
}
Also used : MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) IntVar(org.chocosolver.solver.variables.IntVar) SatConstraint(org.btrplace.model.constraint.SatConstraint)

Aggregations

VM (org.btrplace.model.VM)192 Node (org.btrplace.model.Node)110 Model (org.btrplace.model.Model)92 DefaultModel (org.btrplace.model.DefaultModel)91 Test (org.testng.annotations.Test)91 Mapping (org.btrplace.model.Mapping)64 HashSet (java.util.HashSet)58 ArrayList (java.util.ArrayList)43 SatConstraint (org.btrplace.model.constraint.SatConstraint)40 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)39 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)35 IntVar (org.chocosolver.solver.variables.IntVar)35 ShareableResource (org.btrplace.model.view.ShareableResource)32 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)27 MigrateVM (org.btrplace.plan.event.MigrateVM)25 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)17 StayAwayVM (org.btrplace.scheduler.choco.transition.StayAwayVM)17 Slice (org.btrplace.scheduler.choco.Slice)16 BootVM (org.btrplace.scheduler.choco.transition.BootVM)16 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)16