Search in sources :

Example 56 with ShareableResource

use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.

the class IssuesTest method testIssue5a.

/**
 * Another test related to issue #5.
 *
 * @throws org.btrplace.scheduler.SchedulerException
 */
@Test
public void testIssue5a() throws SchedulerException, ContradictionException {
    Model model = new DefaultModel();
    Node n1 = model.newNode();
    Node n2 = model.newNode();
    Node n3 = model.newNode();
    VM vm1 = model.newVM();
    VM vm2 = model.newVM();
    ShareableResource resources = new ShareableResource("vcpu", 1, 1);
    resources.setCapacity(n1, 2);
    resources.setCapacity(n2, 2);
    Mapping map = model.getMapping().on(n1, n2).off(n3).run(n1, vm1, vm2);
    model.attach(resources);
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(model).build();
    List<IntVar> VMsOnAllNodes = rp.getNbRunningVMs();
    int NUMBER_OF_NODE = map.getAllNodes().size();
    // Each element is the number of VMs on each node
    IntVar[] vmsOnInvolvedNodes = new IntVar[NUMBER_OF_NODE];
    BoolVar[] busy = new BoolVar[NUMBER_OF_NODE];
    rp.getEnd().updateUpperBound(10, Cause.Null);
    int i = 0;
    int maxVMs = rp.getSourceModel().getMapping().getAllVMs().size();
    for (Node n : map.getAllNodes()) {
        vmsOnInvolvedNodes[i] = rp.getModel().intVar("nVMs", -1, maxVMs, true);
        IntVar state = rp.getNodeAction(n).getState();
        // If the node is offline -> the temporary variable is -1, otherwise, it equals the number of VMs on that node
        Constraint elem = rp.getModel().element(vmsOnInvolvedNodes[i], new IntVar[] { rp.getModel().intVar(-1), VMsOnAllNodes.get(rp.getNode(n)) }, state, 0);
        rp.getModel().post(elem);
        // IF the node is online and hosting VMs -> busy = 1.
        busy[i] = rp.getModel().boolVar("busy" + n);
        ChocoUtils.postIfOnlyIf(rp, busy[i], rp.getModel().arithm(vmsOnInvolvedNodes[i], ">=", 1));
        i++;
    }
    // idle is equals the number of vmsOnInvolvedNodes with value 0. (The node without VM)
    IntVar idle = rp.getModel().intVar("Nidles", 0, NUMBER_OF_NODE, true);
    rp.getModel().post(rp.getModel().count(0, vmsOnInvolvedNodes, idle));
    // idle should be less than Amount for MaxSN (0, in this case)
    rp.getModel().post(rp.getModel().arithm(idle, "<=", 0));
    // Extract all the state of the involved nodes (all nodes in this case)
    IntVar[] states = new IntVar[NUMBER_OF_NODE];
    int j = 0;
    for (Node n : map.getAllNodes()) {
        states[j++] = rp.getNodeAction(n).getState();
    }
    // In case the number of VMs is inferior to the number of online nodes, some nodes have to shutdown
    // to satisfy the constraint. This could be express as:
    // The addition of the idle nodes and busy nodes should be equals the number of online nodes.
    IntVar sumStates = rp.getModel().intVar("sumStates", 0, 1000, true);
    rp.getModel().post(rp.getModel().sum(states, "=", sumStates));
    IntVar sumBusy = rp.getModel().intVar("sumBusy", 0, 1000, true);
    rp.getModel().post(rp.getModel().sum(states, "=", sumBusy));
    IntVar sumIB = rp.getModel().intVar("ib", 0, 1000, true);
    @SuppressWarnings("unused") Task task = new Task(sumBusy, idle, sumIB);
    // solver.eq(sumStates, sumIB));
    rp.getModel().post(rp.getModel().arithm(sumStates, "=", sumIB));
    ReconfigurationPlan plan = rp.solve(0, false);
    Assert.assertNotNull(plan);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Task(org.chocosolver.solver.variables.Task) OptConstraint(org.btrplace.model.constraint.OptConstraint) Constraint(org.chocosolver.solver.constraints.Constraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) Node(org.btrplace.model.Node) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Mapping(org.btrplace.model.Mapping) ShareableResource(org.btrplace.model.view.ShareableResource) IntVar(org.chocosolver.solver.variables.IntVar) OptConstraint(org.btrplace.model.constraint.OptConstraint) Constraint(org.chocosolver.solver.constraints.Constraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) BoolVar(org.chocosolver.solver.variables.BoolVar) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 57 with ShareableResource

use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.

the class SliceRcComparatorTest method testAscending.

@Test
public void testAscending() {
    List<Slice> l = makeSlices();
    ShareableResource rc = new ShareableResource("cpu");
    for (Slice s : l) {
        rc.setConsumption(s.getSubject(), rnd.nextInt(10));
    }
    SliceRcComparator cmp = new SliceRcComparator(rc, true);
    Collections.sort(l, cmp);
    for (int i = 0; i < l.size() - 1; i++) {
        VM u1 = l.get(i).getSubject();
        VM u2 = l.get(i + 1).getSubject();
        Assert.assertTrue(rc.getConsumption(u1) <= rc.getConsumption(u2));
    }
}
Also used : VM(org.btrplace.model.VM) ShareableResource(org.btrplace.model.view.ShareableResource) Test(org.testng.annotations.Test)

Example 58 with ShareableResource

use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.

the class Cons method eval.

@Override
public Integer eval(Context mo, Object... args) {
    String rc = (String) args[1];
    ShareableResource r = ShareableResource.get(mo.getModel(), rc);
    if (r == null) {
        throw new IllegalArgumentException("View '" + rc + "' is missing");
    }
    return r.getConsumption((VM) args[0]);
}
Also used : ShareableResource(org.btrplace.model.view.ShareableResource)

Example 59 with ShareableResource

use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.

the class ShareableResourceFuzzer method decorate.

@Override
public void decorate(ReconfigurationPlan p) {
    Model mo = p.getOrigin();
    ShareableResource rc = new ShareableResource(id);
    mo.attach(rc);
    Set<VM> toRun = p.getActions().stream().filter(a -> a instanceof RunningVMPlacement).map(a -> ((RunningVMPlacement) a).getVM()).collect(Collectors.toSet());
    // Initial consumption/capacity
    for (VM v : mo.getMapping().getAllVMs()) {
        int c = rnd.nextInt(maxCons - minCons + 1) + minCons;
        rc.setConsumption(v, c);
    }
    for (Node n : mo.getMapping().getAllNodes()) {
        int c = rnd.nextInt(maxCapa - minCapa + 1) + minCapa;
        rc.setCapacity(n, c);
    }
    // Composition issue
    for (VM v : toRun) {
        if (rnd.nextDouble() > variability) {
            continue;
        }
        int c = rnd.nextInt(maxCons - minCons + 1) + minCons;
        setDemand(p, rc, v, c);
    }
}
Also used : Model(org.btrplace.model.Model) VM(org.btrplace.model.VM) org.btrplace.plan.event(org.btrplace.plan.event) Node(org.btrplace.model.Node) ShareableResource(org.btrplace.model.view.ShareableResource) Set(java.util.Set) Random(java.util.Random) Collectors(java.util.stream.Collectors) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) ShareableResource(org.btrplace.model.view.ShareableResource)

Example 60 with ShareableResource

use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.

the class ShareableResourceConverter method fromJSON.

@Override
public ShareableResource fromJSON(Model mo, JSONObject o) throws JSONConverterException {
    checkKeys(o, "vms", NODES_LABEL, DEFAULT_CAPACITY, DEFAULT_CONSUMPTION, ModelViewConverter.IDENTIFIER);
    String id = requiredString(o, ModelViewConverter.IDENTIFIER);
    if (!id.equals(getJSONId())) {
        return null;
    }
    String rcId = requiredString(o, "rcId");
    int defConsumption = requiredInt(o, DEFAULT_CONSUMPTION);
    int defCapacity = requiredInt(o, DEFAULT_CAPACITY);
    ShareableResource rc = new ShareableResource(rcId, defCapacity, defConsumption);
    parseVMs(mo, rc, o.get("vms"));
    parseNodes(mo, rc, o.get(NODES_LABEL));
    return rc;
}
Also used : JSONs.requiredString(org.btrplace.json.JSONs.requiredString) ShareableResource(org.btrplace.model.view.ShareableResource)

Aggregations

ShareableResource (org.btrplace.model.view.ShareableResource)86 Test (org.testng.annotations.Test)61 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)47 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)41 SatConstraint (org.btrplace.model.constraint.SatConstraint)32 ArrayList (java.util.ArrayList)31 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)29 VM (org.btrplace.model.VM)27 Model (org.btrplace.model.Model)25 Node (org.btrplace.model.Node)25 DefaultModel (org.btrplace.model.DefaultModel)22 MigrateVM (org.btrplace.plan.event.MigrateVM)16 Mapping (org.btrplace.model.Mapping)13 Network (org.btrplace.model.view.network.Network)12 Switch (org.btrplace.model.view.network.Switch)12 Offline (org.btrplace.model.constraint.Offline)11 MinMTTRMig (org.btrplace.model.constraint.migration.MinMTTRMig)10 SchedulerException (org.btrplace.scheduler.SchedulerException)10 Fence (org.btrplace.model.constraint.Fence)7 Preserve (org.btrplace.model.constraint.Preserve)7