Search in sources :

Example 61 with Node

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

the class Instances method makeVMIndex.

/**
 * Make an index revealing the position of each VM in a collection
 * of disjoint instances
 *
 * @param instances the collection to browse. Instances are supposed to be disjoint
 * @return the index of every VM. Format {@code VM#id() -> position}
 */
public static TIntIntHashMap makeVMIndex(Collection<Instance> instances) {
    TIntIntHashMap index = new TIntIntHashMap();
    int p = 0;
    for (Instance i : instances) {
        Mapping m = i.getModel().getMapping();
        for (Node n : m.getOnlineNodes()) {
            for (VM v : m.getRunningVMs(n)) {
                index.put(v.id(), p);
            }
            for (VM v : m.getSleepingVMs(n)) {
                index.put(v.id(), p);
            }
        }
        for (VM v : m.getReadyVMs()) {
            index.put(v.id(), p);
        }
        p++;
    }
    return index;
}
Also used : Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) Mapping(org.btrplace.model.Mapping) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap)

Example 62 with Node

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

the class Instances method makeNodeIndex.

/**
 * Make an index revealing the position of each node in a collection
 * of disjoint instances
 *
 * @param instances the collection to browse. Instances are supposed to be disjoint
 * @return the index of every node. Format {@code Node#id() -> position}
 */
public static TIntIntHashMap makeNodeIndex(Collection<Instance> instances) {
    TIntIntHashMap index = new TIntIntHashMap();
    int p = 0;
    for (Instance i : instances) {
        Mapping m = i.getModel().getMapping();
        for (Node n : m.getOfflineNodes()) {
            index.put(n.id(), p);
        }
        for (Node n : m.getOnlineNodes()) {
            index.put(n.id(), p);
        }
        p++;
    }
    return index;
}
Also used : Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) Mapping(org.btrplace.model.Mapping) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap)

Example 63 with Node

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

the class OfflineSplitter method split.

@Override
public boolean split(Offline cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
    Node n = cstr.getInvolvedNodes().iterator().next();
    int i = nodePosition.get(n.id());
    return partitions.get(i).getSatConstraints().add(cstr);
}
Also used : Node(org.btrplace.model.Node)

Example 64 with Node

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

the class NetworkConverter method physicalElementToJSON.

/**
 * Convert a PhysicalElement to a JSON object.
 *
 * @param pe the physical element to convert
 * @return  the JSON object
 * @throws IllegalArgumentException if the physical element is not supported
 */
public JSONObject physicalElementToJSON(PhysicalElement pe) {
    JSONObject o = new JSONObject();
    if (pe instanceof Node) {
        o.put("type", NODE_LABEL);
        o.put("id", ((Node) pe).id());
    } else if (pe instanceof Switch) {
        o.put("type", SWITCH_LABEL);
        o.put("id", ((Switch) pe).id());
    } else {
        throw new IllegalArgumentException("Unsupported physical element '" + pe.getClass().toString() + "'");
    }
    return o;
}
Also used : JSONObject(net.minidev.json.JSONObject) Switch(org.btrplace.model.view.network.Switch) Node(org.btrplace.model.Node) JSONs.requiredNode(org.btrplace.json.JSONs.requiredNode)

Example 65 with Node

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

the class CQuarantineTest method testWithNoSolution2.

/**
 * A VM try to leave the quarantine zone.
 *
 * @throws org.btrplace.scheduler.SchedulerException
 */
@Test
public void testWithNoSolution2() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    VM vm4 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Node n3 = mo.newNode();
    mo.getMapping().on(n1, n2, n3).run(n1, vm1).run(n2, vm2, vm3).run(n3, vm4);
    Quarantine q = new Quarantine(n2);
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.add(q);
    cstrs.add(new Fence(vm1, Collections.singleton(n2)));
    ChocoScheduler cra = new DefaultChocoScheduler();
    ReconfigurationPlan p = cra.solve(mo, cstrs);
    Assert.assertNull(p);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Quarantine(org.btrplace.model.constraint.Quarantine) ArrayList(java.util.ArrayList) Fence(org.btrplace.model.constraint.Fence) Test(org.testng.annotations.Test)

Aggregations

Node (org.btrplace.model.Node)188 VM (org.btrplace.model.VM)110 Model (org.btrplace.model.Model)92 DefaultModel (org.btrplace.model.DefaultModel)91 Test (org.testng.annotations.Test)85 Mapping (org.btrplace.model.Mapping)68 HashSet (java.util.HashSet)48 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)43 SatConstraint (org.btrplace.model.constraint.SatConstraint)35 ArrayList (java.util.ArrayList)34 IntVar (org.chocosolver.solver.variables.IntVar)29 ShareableResource (org.btrplace.model.view.ShareableResource)28 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)23 MigrateVM (org.btrplace.plan.event.MigrateVM)22 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)19 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)19 ShutdownableNode (org.btrplace.scheduler.choco.transition.ShutdownableNode)19 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)18 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)16 BootVM (org.btrplace.scheduler.choco.transition.BootVM)16