use of org.btrplace.model.Node in project scheduler by btrplace.
the class Decommissionning method run.
@Override
public void run() {
int ratio = 1;
int nbPCPUs = 4;
int nbNodes = 2;
// The current DC
Model mo = new DefaultModel();
for (int i = 0; i < nbNodes; i++) {
Node n = mo.newNode();
mo.getMapping().addOnlineNode(n);
// 4 VMs per node
for (int j = 0; j < ratio * nbPCPUs; j++) {
VM v = mo.newVM();
mo.getMapping().addRunningVM(v, n);
}
}
// Resource allocation
ShareableResource rc = new ShareableResource("cpu", 8, 1);
mo.attach(rc);
// The new DC
for (int i = 0; i < nbNodes; i++) {
Node n = mo.newNode();
mo.getMapping().addOfflineNode(n);
rc.setCapacity(n, 10);
}
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Offline.newOffline(mo.getMapping().getOnlineNodes()));
MaxOnline m = new MaxOnline(mo.getMapping().getAllNodes(), nbNodes + 1, true);
cstrs.add(m);
ChocoScheduler cra = new DefaultChocoScheduler();
cra.setMaxEnd(3);
cra.setVerbosity(1);
ReconfigurationPlan p = cra.solve(mo, cstrs);
System.out.println(p);
System.out.println(cra.getStatistics());
}
use of org.btrplace.model.Node in project scheduler by btrplace.
the class JSONs method nodesFromJSON.
/**
* Convert an array of VM identifiers to a set of VMs.
* This operation uses a cache of previously converted set of nodes.
* @param mo the associated model to browse
* @param a the json array
* @return the set of nodes
*/
public static List<Node> nodesFromJSON(Model mo, JSONArray a) throws JSONConverterException {
String json = a.toJSONString();
List<Node> s = nodesCache.get(json);
if (s != null) {
return s;
}
s = new ArrayList<>(a.size());
for (Object o : a) {
s.add(getNode(mo, (int) o));
}
nodesCache.put(json, s);
return s;
}
use of org.btrplace.model.Node in project scheduler by btrplace.
the class ReconfigurationPlanFuzzer method setInitialState.
private void setInitialState(ReconfigurationPlan p, VM v) {
Mapping map = p.getOrigin().getMapping();
Set<Node> onlines = map.getOnlineNodes();
if (onlines.isEmpty()) {
map.addReadyVM(v);
return;
}
// CDF to consider the distribution
int n = rnd.nextInt(srcReadyVMs + srcRunningVMs + srcSleepingVMs);
if (n < srcReadyVMs) {
map.addReadyVM(v);
} else if (n < srcReadyVMs + srcRunningVMs) {
map.addRunningVM(v, pick(onlines));
} else {
map.addSleepingVM(v, pick(onlines));
}
}
use of org.btrplace.model.Node in project scheduler by btrplace.
the class ReconfigurationSimulator method visit.
@Override
public Object visit(KillVM a) {
if (start) {
co.getMapping().state(a.getVM(), VMStateType.Type.TERMINATED);
return null;
}
Node n = a.getNode();
if (n != null) {
co.getMapping().unhost(n, a.getVM());
co.getMapping().desactivate(a.getVM());
co.getMapping().state(a.getVM(), VMStateType.Type.TERMINATED);
}
return null;
}
use of org.btrplace.model.Node in project scheduler by btrplace.
the class FixedSizePartitioning method randomPartitions.
private List<Collection<Node>> randomPartitions(long seed, Mapping map) {
Random rnd = new Random(seed);
List<Node> unselectedNodes = new ArrayList<>(map.getNbNodes());
unselectedNodes.addAll(map.getOnlineNodes());
unselectedNodes.addAll(map.getOfflineNodes());
List<Collection<Node>> partOfNodes = new ArrayList<>();
Set<Node> curPartition = new HashSet<>(partSize);
partOfNodes.add(curPartition);
while (!unselectedNodes.isEmpty()) {
Node n = unselectedNodes.remove(rnd.nextInt(unselectedNodes.size()));
if (curPartition.size() == partSize) {
curPartition = new HashSet<>(partSize);
partOfNodes.add(curPartition);
}
curPartition.add(n);
}
return partOfNodes;
}
Aggregations