use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class CAmong method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
int nextGrp = -1;
int curGrp = -1;
List<Collection<Node>> groups = new ArrayList<>();
groups.addAll(cstr.getGroupsOfNodes());
Set<VM> running = new HashSet<>();
Mapping src = rp.getSourceModel().getMapping();
for (VM vm : cstr.getInvolvedVMs()) {
if (rp.getFutureRunningVMs().contains(vm)) {
// The VM will be running
running.add(vm);
IntVar vAssign = rp.getVMAction(vm).getDSlice().getHoster();
// If one of the VM is already placed, no need for the constraint, the group will be known
if (vAssign.isInstantiated()) {
// Get the group of nodes that match the selected node
int g = getGroup(rp.getNode(vAssign.getValue()), groups);
if (errorReported(rp, vm, nextGrp, g)) {
return false;
}
nextGrp = g;
}
}
if (cstr.isContinuous() && src.isRunning(vm)) {
// The VM is already running, so we get its current group
Node curNode = src.getVMLocation(vm);
int g = getGroup(curNode, groups);
if (errorReported(rp, vm, curGrp, g)) {
return false;
}
curGrp = g;
}
}
if (cstr.isContinuous() && curGrp != -1) {
return restrictGroup(ps, rp, running, groups, curGrp);
} else if (groups.size() == 1) {
return restrictGroup(ps, rp, running, groups, 0);
}
return restrictGroup(ps, rp, running, groups, nextGrp);
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class CGather method continuousColocation.
/*
* Check for the already running VMs and force co-location if any.
*/
private boolean continuousColocation(ReconfigurationProblem rp, List<Slice> dSlices) {
Set<VM> alreadyRunning = new HashSet<>();
Mapping map = rp.getSourceModel().getMapping();
Node loc = null;
for (VM vm : cstr.getInvolvedVMs()) {
if (map.isRunning(vm)) {
alreadyRunning.add(vm);
Node node = map.getVMLocation(vm);
if (loc == null) {
loc = node;
} else if (!loc.equals(node)) {
rp.getLogger().error("Some VMs in '{}' are already running but not co-located", cstr.getInvolvedVMs());
return false;
}
}
}
if (loc != null) {
if (cstr.getInvolvedVMs().size() == 1 && dSlices.size() == 1) {
// The VM may migrate, we don't care as it is alone.
return true;
}
return placeDSlices(rp, dSlices, rp.getNode(loc));
}
return true;
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class CLonely method continuousRestriction.
private static void continuousRestriction(ReconfigurationProblem rp, Collection<VM> vms, Set<VM> otherVMs) {
// Get the position of all the others c-slices and their associated end moment
TIntArrayList otherPos = new TIntArrayList();
TIntArrayList minePos = new TIntArrayList();
List<IntVar> otherEnds = new ArrayList<>();
List<IntVar> mineEnds = new ArrayList<>();
Mapping map = rp.getSourceModel().getMapping();
for (Node n : map.getOnlineNodes()) {
for (VM vm : map.getRunningVMs(n)) {
if (!vms.contains(vm)) {
otherPos.add(rp.getNode(map.getVMLocation(vm)));
VMTransition a = rp.getVMAction(vm);
otherEnds.add(a.getCSlice().getEnd());
} else {
minePos.add(rp.getNode(map.getVMLocation(vm)));
VMTransition a = rp.getVMAction(vm);
mineEnds.add(a.getCSlice().getEnd());
}
}
}
for (VM vm : vms) {
VMTransition a = rp.getVMAction(vm);
Precedences p = new Precedences(a.getDSlice().getHoster(), a.getDSlice().getStart(), otherPos.toArray(), otherEnds.toArray(new IntVar[otherEnds.size()]));
rp.getModel().post(p);
}
// TODO: The following reveals a model problem. Too many constraints!!
for (VM vm : otherVMs) {
VMTransition a = rp.getVMAction(vm);
Precedences p = new Precedences(a.getDSlice().getHoster(), a.getDSlice().getStart(), minePos.toArray(), mineEnds.toArray(new IntVar[mineEnds.size()]));
rp.getModel().post(p);
}
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class CLonely method getMisPlacedVMs.
@Override
public Set<VM> getMisPlacedVMs(Instance i) {
Set<VM> bad = new HashSet<>();
Set<Node> hosts = new HashSet<>();
Collection<VM> vms = cstr.getInvolvedVMs();
Mapping map = i.getModel().getMapping();
for (VM vm : vms) {
if (map.isRunning(vm)) {
hosts.add(map.getVMLocation(vm));
}
}
for (Node n : hosts) {
// is a bad node. All the hosted VMs are candidate for relocation. Not optimal, but safe
for (VM vm : map.getRunningVMs(n)) {
if (!vms.contains(vm)) {
bad.addAll(map.getRunningVMs(n));
break;
}
}
}
return bad;
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class CResourceCapacity method getMisPlacedVMs.
@Override
public Set<VM> getMisPlacedVMs(Instance i) {
if (cstr.getInvolvedNodes().size() <= 1) {
// If there is only a single node, we delegate this work to CShareableResource.
return Collections.emptySet();
}
Mapping map = i.getModel().getMapping();
ShareableResource rc = ShareableResource.get(i.getModel(), cstr.getResource());
if (rc == null) {
return map.getRunningVMs(cstr.getInvolvedNodes());
}
Set<VM> bad = new HashSet<>();
int remainder = cstr.getAmount();
for (Node n : cstr.getInvolvedNodes()) {
for (VM v : map.getRunningVMs(n)) {
remainder -= rc.getConsumption(v);
if (remainder < 0) {
for (Node n2 : cstr.getInvolvedNodes()) {
bad.addAll(map.getRunningVMs(n2));
}
return bad;
}
}
}
return bad;
}
Aggregations