Search in sources :

Example 1 with Mapping

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

the class CSplitAmong method getMisPlacedVMs.

@Override
public Set<VM> getMisPlacedVMs(Instance i) {
    // contains the set of VMs hosted on a group id.
    @SuppressWarnings("unchecked") Collection<VM>[] usedGrp = new Set[cstr.getGroupsOfNodes().size()];
    Mapping map = i.getModel().getMapping();
    Set<VM> bad = new HashSet<>();
    for (Collection<VM> vms : cstr.getGroupsOfVMs()) {
        int grp = -1;
        for (VM vm : vms) {
            if (map.isRunning(vm)) {
                Node n = map.getVMLocation(vm);
                int g = getPGroup(n);
                if (g == -1) {
                    // The VM is on a node that belong to none of the given groups
                    bad.add(vm);
                } else if (grp == -1) {
                    grp = g;
                    usedGrp[g] = vms;
                } else if (g != grp) {
                    // The VMs spread over multiple group of nodes, the group of VMs is mis-placed
                    bad.addAll(vms);
                    if (usedGrp[g] != null) {
                        bad.addAll(usedGrp[g]);
                    }
                    bad.addAll(usedGrp[grp]);
                }
            }
        }
    }
    return bad;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Collection(java.util.Collection) Mapping(org.btrplace.model.Mapping) HashSet(java.util.HashSet)

Example 2 with Mapping

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

the class WorstFit method canStay.

/**
 * Check if a VM can stay on its current node.
 *
 * @param vm the VM
 * @return {@code true} iff the VM can stay
 */
private boolean canStay(VM vm) {
    Mapping m = rp.getSourceModel().getMapping();
    if (m.isRunning(vm)) {
        int curPos = rp.getNode(m.getVMLocation(vm));
        if (!rp.getVMAction(vm).getDSlice().getHoster().contains(curPos)) {
            return false;
        }
        IStateInt[] loads = load(curPos);
        return loadWith(curPos, loads, vm) <= 1.0;
    }
    return false;
}
Also used : IStateInt(org.chocosolver.memory.IStateInt) Mapping(org.btrplace.model.Mapping)

Example 3 with Mapping

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

the class CShareableResource method getMisPlacedVMs.

/**
 * {@inheritDoc}
 *
 * @param i the model to use to inspect the VMs.
 * @return the set of VMs that cannot have their associated {@link Preserve} constraint satisfy with regards
 * to a possible {@link Overbook} and single-node {@link ResourceCapacity} constraint.
 */
@Override
public Set<VM> getMisPlacedVMs(Instance i) {
    for (SatConstraint c : i.getSatConstraints()) {
        if (!(c instanceof ResourceRelated && ((ResourceRelated) c).getResource().equals(rc.getResourceIdentifier()))) {
            continue;
        }
        if (c instanceof Preserve) {
            VM v = c.getInvolvedVMs().iterator().next();
            wantedAmount.put(v, consumption(v, ((Preserve) c).getAmount()));
        } else if (c instanceof Overbook) {
            Node n = c.getInvolvedNodes().iterator().next();
            wantedRatios.put(n, ratio(n, ((Overbook) c).getRatio()));
        } else if (c instanceof ResourceCapacity && c.getInvolvedNodes().size() == 1) {
            Node n = c.getInvolvedNodes().iterator().next();
            wantedCapacity.put(n, capacity(n, ((ResourceCapacity) c).getAmount()));
        }
    }
    Mapping m = i.getModel().getMapping();
    Set<VM> candidates = new HashSet<>();
    for (Node n : m.getOnlineNodes()) {
        if (overloaded(m, n)) {
            candidates.addAll(m.getRunningVMs(n));
        }
    }
    return candidates;
}
Also used : ResourceCapacity(org.btrplace.model.constraint.ResourceCapacity) ResourceRelated(org.btrplace.model.view.ResourceRelated) SatConstraint(org.btrplace.model.constraint.SatConstraint) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Overbook(org.btrplace.model.constraint.Overbook) Node(org.btrplace.model.Node) Mapping(org.btrplace.model.Mapping) Preserve(org.btrplace.model.constraint.Preserve) HashSet(java.util.HashSet)

Example 4 with Mapping

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

the class DefaultChocoSchedulerTest method testGetStatisticsWithTimeout.

@Test(expectedExceptions = { SchedulerException.class })
public void testGetStatisticsWithTimeout() throws SchedulerException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    for (int i = 0; i < 1000; i++) {
        Node n = mo.newNode();
        map.addOnlineNode(n);
        for (int j = 0; j < 10; j++) {
            map.addReadyVM(mo.newVM());
        }
    }
    ChocoScheduler cra = new DefaultChocoScheduler();
    cra.setTimeLimit(1);
    try {
        System.err.println(cra.solve(mo, Running.newRunning(map.getAllVMs())));
    } catch (SchedulerException e) {
        SolvingStatistics stats = cra.getStatistics();
        Assert.assertNotNull(stats);
        System.out.println(stats);
        Assert.assertTrue(stats.getSolutions().isEmpty());
        Assert.assertEquals(stats.getInstance().getModel(), mo);
        throw e;
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) SchedulerException(org.btrplace.scheduler.SchedulerException) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Mapping(org.btrplace.model.Mapping) SolvingStatistics(org.btrplace.scheduler.choco.runner.SolvingStatistics) SatConstraint(org.btrplace.model.constraint.SatConstraint) Test(org.testng.annotations.Test)

Example 5 with Mapping

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

the class DefaultReconfigurationProblemTest method testVMCounting.

/**
 * Check the consistency between the variables counting the number of VMs on
 * each node, and the placement variable.
 *
 * @throws org.btrplace.scheduler.SchedulerException
 * @throws ContradictionException
 */
@Test
public void testVMCounting() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Node n3 = mo.newNode();
    Node n2 = mo.newNode();
    Mapping map = mo.getMapping();
    for (int i = 0; i < 7; i++) {
        VM v = mo.newVM();
        map.addReadyVM(v);
    }
    map.addOnlineNode(n3);
    map.addOnlineNode(n2);
    Parameters ps = new DefaultParameters();
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), map.getAllVMs(), new HashSet<>(), new HashSet<>()).build();
    // Restrict the capacity to 5 at most
    for (IntVar capa : rp.getNbRunningVMs()) {
        capa.updateUpperBound(5, Cause.Null);
    }
    new CMinMTTR().inject(ps, rp);
    ReconfigurationPlan p = rp.solve(-1, false);
    Assert.assertNotNull(p);
    // Check consistency between the counting and the hoster variables
    int[] counts = new int[map.getAllNodes().size()];
    for (Node n : map.getOnlineNodes()) {
        int nIdx = rp.getNode(n);
        counts[nIdx] = rp.getNbRunningVMs().get(nIdx).getValue();
    }
    for (VM vm : rp.getFutureRunningVMs()) {
        VMTransition vmo = rp.getVMActions().get(rp.getVM(vm));
        int on = vmo.getDSlice().getHoster().getValue();
        counts[on]--;
    }
    for (int count : counts) {
        Assert.assertEquals(count, 0);
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) 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) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

Mapping (org.btrplace.model.Mapping)83 Node (org.btrplace.model.Node)68 VM (org.btrplace.model.VM)62 Model (org.btrplace.model.Model)42 DefaultModel (org.btrplace.model.DefaultModel)39 Test (org.testng.annotations.Test)39 HashSet (java.util.HashSet)29 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)23 ShareableResource (org.btrplace.model.view.ShareableResource)16 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)16 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)15 ShutdownableNode (org.btrplace.scheduler.choco.transition.ShutdownableNode)15 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)15 IntVar (org.chocosolver.solver.variables.IntVar)15 SatConstraint (org.btrplace.model.constraint.SatConstraint)14 BootVM (org.btrplace.scheduler.choco.transition.BootVM)14 ForgeVM (org.btrplace.scheduler.choco.transition.ForgeVM)14 KillVM (org.btrplace.scheduler.choco.transition.KillVM)14 ResumeVM (org.btrplace.scheduler.choco.transition.ResumeVM)14 ShutdownVM (org.btrplace.scheduler.choco.transition.ShutdownVM)14