Search in sources :

Example 96 with VM

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

the class InstanceSolverRunner method buildRP.

private ReconfigurationProblem buildRP() throws SchedulerException {
    // Build the RP. As VM state management is not possible
    // We extract VM-state related constraints first.
    // For other constraint, we just create the right choco constraint
    Set<VM> toRun = new HashSet<>();
    Set<VM> toForge = new HashSet<>();
    Set<VM> toKill = new HashSet<>();
    Set<VM> toSleep = new HashSet<>();
    cConstraints = new ArrayList<>();
    for (SatConstraint cstr : cstrs) {
        checkNodesExistence(origin, cstr.getInvolvedNodes());
        // (when they will be forged)
        if (!(cstrs instanceof Ready)) {
            checkUnknownVMsInMapping(origin, cstr.getInvolvedVMs());
        }
        if (cstr instanceof Running) {
            toRun.addAll(cstr.getInvolvedVMs());
        } else if (cstr instanceof Sleeping) {
            toSleep.addAll(cstr.getInvolvedVMs());
        } else if (cstr instanceof Ready) {
            checkUnknownVMsInMapping(origin, cstr.getInvolvedVMs());
            toForge.addAll(cstr.getInvolvedVMs());
        } else if (cstr instanceof Killed) {
            checkUnknownVMsInMapping(origin, cstr.getInvolvedVMs());
            toKill.addAll(cstr.getInvolvedVMs());
        }
        cConstraints.add(build(cstr));
    }
    cConstraints.add(build(obj));
    views = makeViews();
    DefaultReconfigurationProblemBuilder rpb = new DefaultReconfigurationProblemBuilder(origin).setNextVMsStates(toForge, toRun, toSleep, toKill).setParams(params);
    if (params.doRepair()) {
        Set<VM> toManage = new HashSet<>();
        cConstraints.forEach(c -> toManage.addAll(c.getMisPlacedVMs(instance)));
        views.forEach(v -> toManage.addAll(v.getMisPlacedVMs(instance)));
        rpb.setManageableVMs(toManage);
    }
    // The core views have been instantiated and available through rp.getViews()
    // Set the maximum duration
    ReconfigurationProblem p = rpb.build();
    try {
        p.getEnd().updateUpperBound(params.getMaxEnd(), Cause.Null);
    } catch (ContradictionException e) {
        p.getLogger().error("Unable to restrict the maximum plan duration to " + params.getMaxEnd(), e);
        return null;
    }
    return p;
}
Also used : Ready(org.btrplace.model.constraint.Ready) Sleeping(org.btrplace.model.constraint.Sleeping) ContradictionException(org.chocosolver.solver.exception.ContradictionException) VM(org.btrplace.model.VM) SatConstraint(org.btrplace.model.constraint.SatConstraint) Running(org.btrplace.model.constraint.Running) Killed(org.btrplace.model.constraint.Killed) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) HashSet(java.util.HashSet)

Example 97 with VM

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

the class CNetwork method beforeSolve.

@Override
public boolean beforeSolve(ReconfigurationProblem rp) throws SchedulerException {
    Model mo = rp.getSourceModel();
    Attributes attrs = mo.getAttributes();
    // Pre-compute duration and bandwidth for each VM migration
    for (VMTransition migration : rp.getVMActions()) {
        if (!(migration instanceof RelocatableVM)) {
            continue;
        }
        // Get vars from migration
        VM vm = migration.getVM();
        IntVar bandwidth = ((RelocatableVM) migration).getBandwidth();
        IntVar duration = migration.getDuration();
        Node src = rp.getSourceModel().getMapping().getVMLocation(vm);
        // Try to get the destination node
        Node dst;
        if (!migration.getDSlice().getHoster().isInstantiated()) {
            throw new SchedulerModelingException(null, "Destination node for VM '" + vm + "' should be known !");
        }
        if (!mo.getAttributes().isSet(vm, "memUsed")) {
            throw new SchedulerModelingException(null, "Unable to retrieve 'memUsed' attribute for the vm '" + vm + "'");
        }
        dst = rp.getNode(migration.getDSlice().getHoster().getValue());
        if (src.equals(dst)) {
            try {
                ((RelocatableVM) migration).getBandwidth().instantiateTo(0, Cause.Null);
                continue;
            } catch (ContradictionException e) {
                rp.getLogger().error("Contradiction exception when trying to instantiate bandwidth and " + " duration variables for " + vm + " migration", e);
                return false;
            }
        }
        // Get attribute vars
        int memUsed = attrs.get(vm, "memUsed", -1);
        // Get VM memory activity attributes if defined, otherwise set an idle workload on the VM
        // Minimal observed value on idle VM
        double hotDirtySize = attrs.get(vm, "hotDirtySize", 5.0);
        // Minimal observed value on idle VM
        double hotDirtyDuration = attrs.get(vm, "hotDirtyDuration", 2.0);
        double coldDirtyRate = attrs.get(vm, "coldDirtyRate", 0.0);
        // Get the maximal bandwidth available on the migration path
        int maxBW = net.getRouting().getMaxBW(src, dst);
        // Compute the duration related to each enumerated bandwidth
        double durationMin;
        double durationColdPages;
        double durationHotPages;
        double durationTotal;
        // Cheat a bit, real is less than theoretical (8->9)
        double bandwidthOctet = maxBW / 9.0;
        // Estimate the duration for the current bandwidth
        durationMin = memUsed / bandwidthOctet;
        if (durationMin > hotDirtyDuration) {
            durationColdPages = (hotDirtySize + (durationMin - hotDirtyDuration) * coldDirtyRate) / (bandwidthOctet - coldDirtyRate);
            durationHotPages = (hotDirtySize / bandwidthOctet * ((hotDirtySize / hotDirtyDuration) / (bandwidthOctet - (hotDirtySize / hotDirtyDuration))));
            durationTotal = durationMin + durationColdPages + durationHotPages;
        } else {
            durationTotal = durationMin + (((hotDirtySize / hotDirtyDuration) * durationMin) / (bandwidthOctet - (hotDirtySize / hotDirtyDuration)));
        }
        // Instantiate the computed bandwidth and duration
        try {
            // prevent from a 0 duration when the memory usage is very low
            int dd = (int) Math.max(1, Math.round(durationTotal));
            duration.instantiateTo(dd, Cause.Null);
            bandwidth.instantiateTo(maxBW, Cause.Null);
        } catch (ContradictionException e) {
            rp.getLogger().error("Contradiction exception when trying to instantiate bandwidth and " + " duration variables for " + vm + " migration: ", e);
            return false;
        }
    }
    // Add links and switches constraints
    addLinkConstraints(rp);
    addSwitchConstraints(rp);
    return true;
}
Also used : ContradictionException(org.chocosolver.solver.exception.ContradictionException) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) Attributes(org.btrplace.model.Attributes) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) IntVar(org.chocosolver.solver.variables.IntVar) SchedulerModelingException(org.btrplace.scheduler.SchedulerModelingException)

Example 98 with VM

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

the class CNetwork method addSwitchConstraints.

/**
 * Add the cumulative constraints for each blocking switch (having limited capacity)
 *
 * @param rp the reconfiguration problem
 */
private void addSwitchConstraints(ReconfigurationProblem rp) {
    // Switches capacity limitation
    List<Task> tasksList = new ArrayList<>();
    List<IntVar> heightsList = new ArrayList<>();
    for (Switch sw : net.getSwitches()) {
        // Only if the capacity is limited
        if (sw.getCapacity() != Integer.MAX_VALUE) {
            for (VM vm : rp.getVMs()) {
                VMTransition a = rp.getVMAction(vm);
                if (a != null && a instanceof RelocatableVM) {
                    if (a.getDSlice().getHoster().isInstantiated()) {
                        if (a.getCSlice().getHoster().getValue() != a.getDSlice().getHoster().getValue()) {
                            Node src = source.getMapping().getVMLocation(vm);
                            Node dst = rp.getNode(a.getDSlice().getHoster().getValue());
                            if (!Collections.disjoint(net.getConnectedLinks(sw), net.getRouting().getPath(src, dst))) {
                                tasksList.add(new Task(a.getStart(), a.getDuration(), a.getEnd()));
                                heightsList.add(((RelocatableVM) a).getBandwidth());
                            }
                        }
                    }
                }
            }
            if (!tasksList.isEmpty()) {
                // Post the cumulative constraint for the current switch
                csp.post(csp.cumulative(tasksList.toArray(new Task[tasksList.size()]), heightsList.toArray(new IntVar[heightsList.size()]), csp.intVar(sw.getCapacity()), true));
                tasksList.clear();
                heightsList.clear();
            }
        }
    }
}
Also used : Task(org.chocosolver.solver.variables.Task) Switch(org.btrplace.model.view.network.Switch) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) ArrayList(java.util.ArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) IntVar(org.chocosolver.solver.variables.IntVar)

Example 99 with VM

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

the class CNetwork method addLinkConstraints.

/**
 * Add the cumulative constraints for each link.
 *
 * Full-duplex links are considered, two cumulative constraints are defined per link by looking at
 * the migration direction for each link on the migration path.
 *
 * @param rp the reconfiguration problem
 */
private void addLinkConstraints(ReconfigurationProblem rp) {
    // Links limitation
    List<Task> tasksListUp = new ArrayList<>();
    List<Task> tasksListDown = new ArrayList<>();
    List<IntVar> heightsListUp = new ArrayList<>();
    List<IntVar> heightsListDown = new ArrayList<>();
    for (Link l : net.getLinks()) {
        for (VM vm : rp.getVMs()) {
            VMTransition a = rp.getVMAction(vm);
            if (a instanceof RelocatableVM && !a.getDSlice().getHoster().isInstantiatedTo(a.getCSlice().getHoster().getValue())) {
                Node src = source.getMapping().getVMLocation(vm);
                Node dst = rp.getNode(a.getDSlice().getHoster().getValue());
                List<Link> path = net.getRouting().getPath(src, dst);
                // Check first if the link is on migration path
                if (path.contains(l)) {
                    // Get link direction
                    LinkDirection linkDirection = net.getRouting().getLinkDirection(src, dst, l);
                    // UpLink
                    if (linkDirection == LinkDirection.UPLINK) {
                        tasksListUp.add(((RelocatableVM) a).getMigrationTask());
                        heightsListUp.add(((RelocatableVM) a).getBandwidth());
                    } else // DownLink
                    {
                        tasksListDown.add(((RelocatableVM) a).getMigrationTask());
                        heightsListDown.add(((RelocatableVM) a).getBandwidth());
                    }
                }
            }
        }
        if (!tasksListUp.isEmpty()) {
            // Post the cumulative constraint for the current UpLink
            csp.post(csp.cumulative(tasksListUp.toArray(new Task[tasksListUp.size()]), heightsListUp.toArray(new IntVar[heightsListUp.size()]), csp.intVar(l.getCapacity()), true));
            tasksListUp.clear();
            heightsListUp.clear();
        }
        if (!tasksListDown.isEmpty()) {
            // Post the cumulative constraint for the current DownLink
            csp.post(csp.cumulative(tasksListDown.toArray(new Task[tasksListDown.size()]), heightsListDown.toArray(new IntVar[heightsListDown.size()]), csp.intVar(l.getCapacity()), true));
            tasksListDown.clear();
            heightsListDown.clear();
        }
    }
}
Also used : Task(org.chocosolver.solver.variables.Task) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) ArrayList(java.util.ArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) LinkDirection(org.btrplace.model.view.network.Routing.LinkDirection) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) IntVar(org.chocosolver.solver.variables.IntVar) Link(org.btrplace.model.view.network.Link)

Example 100 with VM

use of org.btrplace.model.VM 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)

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