use of gnu.trove.set.hash.THashSet in project scheduler by btrplace.
the class FixedNodeSetsPartitioning method split.
@Override
public List<Instance> split(Parameters ps, Instance i) throws SchedulerException {
Model mo = i.getModel();
SynchronizedElementBuilder eb = new SynchronizedElementBuilder(mo);
List<Instance> parts = new ArrayList<>(partitions.size());
// nb of VMs
int nbVMs = i.getModel().getMapping().getNbVMs();
int nbNodes = i.getModel().getMapping().getNbNodes();
TIntIntHashMap vmPosition = new TIntIntHashMap(nbVMs);
TIntIntHashMap nodePosition = new TIntIntHashMap(nbNodes);
int partNumber = 0;
Set<VM> toLaunch = getVMsToLaunch(i);
for (Collection<Node> s : partitions) {
SubModel partModel = new SubModel(mo, eb, s, new HashSet<>(toLaunch.size() / partitions.size()));
parts.add(new Instance(partModel, new THashSet<>(), i.getOptConstraint()));
// VM Index
partModel.getMapping().fillVMIndex(vmPosition, partNumber);
// Node index
for (Node n : s) {
nodePosition.put(n.id(), partNumber);
}
partNumber++;
}
// Round-robin placement for the VMs to launch
int p = 0;
for (VM v : toLaunch) {
if (!parts.get(p).getModel().getMapping().addReadyVM(v)) {
throw new SplitException(parts.get(p).getModel(), "Unable to dispatch the VM to launch '" + v + "'");
}
vmPosition.put(v.id(), p);
p = (p + 1) % parts.size();
}
// Split the constraints
for (SatConstraint cstr : i.getSatConstraints()) {
if (!cstrMapper.split(cstr, i, parts, vmPosition, nodePosition)) {
throw new SplitException(i.getModel(), "Unable to split " + cstr);
}
}
return parts;
}
use of gnu.trove.set.hash.THashSet in project scheduler by btrplace.
the class FixedNodeSetsPartitioning method getVMsToLaunch.
private Set<VM> getVMsToLaunch(Instance i) {
Mapping m = i.getModel().getMapping();
Set<VM> toLaunch = new THashSet<>();
for (SatConstraint cstr : i.getSatConstraints()) {
// Extract the VMs to launch
if (cstr instanceof Running) {
for (VM v : cstr.getInvolvedVMs()) {
if (m.isReady(v)) {
m.remove(v);
toLaunch.add(v);
}
}
}
}
return toLaunch;
}
Aggregations