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;
}
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;
}
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);
}
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;
}
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);
}
Aggregations