Search in sources :

Example 26 with VMTransition

use of org.btrplace.scheduler.choco.transition.VMTransition 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 27 with VMTransition

use of org.btrplace.scheduler.choco.transition.VMTransition 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 28 with VMTransition

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

Example 29 with VMTransition

use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.

the class DefaultCumulatives method symmetryBreakingForStayingVMs.

/**
 * Symmetry breaking for VMs that stay running, on the same node.
 *
 * @return {@code true} iff the symmetry breaking does not lead to a problem without solutions
 */
private boolean symmetryBreakingForStayingVMs(ReconfigurationProblem rp) {
    for (VM vm : rp.getFutureRunningVMs()) {
        VMTransition a = rp.getVMAction(vm);
        Slice dSlice = a.getDSlice();
        Slice cSlice = a.getCSlice();
        if (dSlice != null && cSlice != null) {
            BoolVar stay = ((KeepRunningVM) a).isStaying();
            Boolean ret = strictlyDecreasingOrUnchanged(vm);
            if (Boolean.TRUE.equals(ret) && !zeroDuration(rp, stay, cSlice)) {
                return false;
            // Else, the resource usage is decreasing, so
            // we set the cSlice duration to 0 to directly reduces the resource allocation
            } else if (Boolean.FALSE.equals(ret) && !zeroDuration(rp, stay, dSlice)) {
                // (the allocation will be performed at the end of the reconfiguration process)
                return false;
            }
        }
    }
    return true;
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) KeepRunningVM(org.btrplace.scheduler.choco.transition.KeepRunningVM) VM(org.btrplace.model.VM) KeepRunningVM(org.btrplace.scheduler.choco.transition.KeepRunningVM) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) BoolVar(org.chocosolver.solver.variables.BoolVar)

Example 30 with VMTransition

use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.

the class DefaultReconfigurationProblemTest method testMinimize.

/**
 * Test a minimization problem: use the minimum number of nodes.
 *
 * @throws org.btrplace.scheduler.SchedulerException
 */
@Test
public void testMinimize() throws SchedulerException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    for (int i = 0; i < 10; i++) {
        Node n = mo.newNode();
        VM vm = mo.newVM();
        map.addOnlineNode(n);
        map.addRunningVM(vm, n);
    }
    Parameters ps = new DefaultParameters();
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
    Solver s = rp.getSolver();
    IntVar nbNodes = rp.getModel().intVar("nbNodes", 1, map.getAllNodes().size(), true);
    Stream<Slice> dSlices = rp.getVMActions().stream().filter(t -> t.getDSlice() != null).map(VMTransition::getDSlice);
    IntVar[] hosters = dSlices.map(Slice::getHoster).toArray(IntVar[]::new);
    rp.getModel().post(rp.getModel().atMostNValues(hosters, nbNodes, true));
    rp.setObjective(true, nbNodes);
    ReconfigurationPlan plan = rp.solve(-1, true);
    Assert.assertNotNull(plan);
    Assert.assertEquals(s.getMeasures().getSolutionCount(), 1);
    Mapping dst = plan.getResult().getMapping();
    Assert.assertEquals(usedNodes(dst), 1);
}
Also used : ShutdownableNode(org.btrplace.scheduler.choco.transition.ShutdownableNode) ChocoView(org.btrplace.scheduler.choco.view.ChocoView) Arrays(java.util.Arrays) SchedulerException(org.btrplace.scheduler.SchedulerException) SuspendVM(org.btrplace.scheduler.choco.transition.SuspendVM) Node(org.btrplace.model.Node) ModelView(org.btrplace.model.view.ModelView) UnstatableProblemException(org.btrplace.scheduler.UnstatableProblemException) NodeTransition(org.btrplace.scheduler.choco.transition.NodeTransition) ContradictionException(org.chocosolver.solver.exception.ContradictionException) Test(org.testng.annotations.Test) Solver(org.chocosolver.solver.Solver) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) HashSet(java.util.HashSet) VM(org.btrplace.model.VM) BootableNode(org.btrplace.scheduler.choco.transition.BootableNode) Assert(org.testng.Assert) Mapping(org.btrplace.model.Mapping) StayAwayVM(org.btrplace.scheduler.choco.transition.StayAwayVM) Model(org.btrplace.model.Model) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) ResumeVM(org.btrplace.scheduler.choco.transition.ResumeVM) Set(java.util.Set) DefaultModel(org.btrplace.model.DefaultModel) Cause(org.chocosolver.solver.Cause) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) IntVar(org.chocosolver.solver.variables.IntVar) Stream(java.util.stream.Stream) KillVM(org.btrplace.scheduler.choco.transition.KillVM) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) BootVM(org.btrplace.scheduler.choco.transition.BootVM) ForgeVM(org.btrplace.scheduler.choco.transition.ForgeVM) ShutdownVM(org.btrplace.scheduler.choco.transition.ShutdownVM) ShareableResource(org.btrplace.model.view.ShareableResource) Solution(org.chocosolver.solver.Solution) Collections(java.util.Collections) DefaultModel(org.btrplace.model.DefaultModel) Solver(org.chocosolver.solver.Solver) ShutdownableNode(org.btrplace.scheduler.choco.transition.ShutdownableNode) Node(org.btrplace.model.Node) BootableNode(org.btrplace.scheduler.choco.transition.BootableNode) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Mapping(org.btrplace.model.Mapping) IntVar(org.chocosolver.solver.variables.IntVar) SuspendVM(org.btrplace.scheduler.choco.transition.SuspendVM) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) StayAwayVM(org.btrplace.scheduler.choco.transition.StayAwayVM) ResumeVM(org.btrplace.scheduler.choco.transition.ResumeVM) KillVM(org.btrplace.scheduler.choco.transition.KillVM) BootVM(org.btrplace.scheduler.choco.transition.BootVM) ForgeVM(org.btrplace.scheduler.choco.transition.ForgeVM) ShutdownVM(org.btrplace.scheduler.choco.transition.ShutdownVM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Aggregations

VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)41 VM (org.btrplace.model.VM)34 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)23 Node (org.btrplace.model.Node)22 IntVar (org.chocosolver.solver.variables.IntVar)22 ArrayList (java.util.ArrayList)18 Model (org.btrplace.model.Model)17 HashSet (java.util.HashSet)16 Mapping (org.btrplace.model.Mapping)16 Slice (org.btrplace.scheduler.choco.Slice)16 DefaultModel (org.btrplace.model.DefaultModel)12 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)12 ShutdownableNode (org.btrplace.scheduler.choco.transition.ShutdownableNode)12 StayAwayVM (org.btrplace.scheduler.choco.transition.StayAwayVM)12 Test (org.testng.annotations.Test)12 BootVM (org.btrplace.scheduler.choco.transition.BootVM)11 ForgeVM (org.btrplace.scheduler.choco.transition.ForgeVM)11 KillVM (org.btrplace.scheduler.choco.transition.KillVM)11 ResumeVM (org.btrplace.scheduler.choco.transition.ResumeVM)11 ShutdownVM (org.btrplace.scheduler.choco.transition.ShutdownVM)11