use of org.btrplace.model.VM in project scheduler by btrplace.
the class KilledSplitterTest method simpleTest.
@Test
public void simpleTest() {
KilledSplitter splitter = new KilledSplitter();
List<Instance> instances = new ArrayList<>();
Model m0 = new DefaultModel();
VM v = m0.newVM(1);
m0.getMapping().addReadyVM(v);
m0.getMapping().addRunningVM(m0.newVM(2), m0.newNode(1));
Model m1 = new DefaultModel();
m1.getMapping().addReadyVM(m1.newVM(3));
m1.getMapping().addSleepingVM(m1.newVM(4), m1.newNode(2));
m1.getMapping().addRunningVM(m1.newVM(5), m1.newNode(3));
instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
TIntIntHashMap index = Instances.makeVMIndex(instances);
Set<VM> all = new HashSet<>(m0.getMapping().getAllVMs());
all.addAll(m1.getMapping().getAllVMs());
// Only VMs in m0
Killed single = new Killed(v);
Assert.assertTrue(splitter.split(single, null, instances, index, new TIntIntHashMap()));
Assert.assertTrue(instances.get(0).getSatConstraints().contains(single));
Assert.assertFalse(instances.get(1).getSatConstraints().contains(single));
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class CSplitAmong method getMisPlacedVMs.
@Override
public Set<VM> getMisPlacedVMs(Instance i) {
// contains the set of VMs hosted on a group id.
@SuppressWarnings("unchecked") Collection<VM>[] usedGrp = new Set[cstr.getGroupsOfNodes().size()];
Mapping map = i.getModel().getMapping();
Set<VM> bad = new HashSet<>();
for (Collection<VM> vms : cstr.getGroupsOfVMs()) {
int grp = -1;
for (VM vm : vms) {
if (map.isRunning(vm)) {
Node n = map.getVMLocation(vm);
int g = getPGroup(n);
if (g == -1) {
// The VM is on a node that belong to none of the given groups
bad.add(vm);
} else if (grp == -1) {
grp = g;
usedGrp[g] = vms;
} else if (g != grp) {
// The VMs spread over multiple group of nodes, the group of VMs is mis-placed
bad.addAll(vms);
if (usedGrp[g] != null) {
bad.addAll(usedGrp[g]);
}
bad.addAll(usedGrp[grp]);
}
}
}
}
return bad;
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class CSpread method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) {
if (cstr.isContinuous()) {
Set<Node> usedNodes = new HashSet<>();
for (VM vm : cstr.getInvolvedVMs()) {
Node node = rp.getSourceModel().getMapping().getVMLocation(vm);
if (node != null && !usedNodes.add(node)) {
rp.getLogger().error("Constraint {} is not satisfied initially", cstr);
// System.out.println(rp.getSourceModel().getMapping());
return false;
}
}
}
List<IntVar> running = placementVariables(rp);
Model csp = rp.getModel();
if (running.isEmpty()) {
return true;
}
// The lazy spread implementation for the placement
csp.post(csp.allDifferent(running.toArray(new IntVar[running.size()]), "AC"));
if (cstr.isContinuous()) {
List<VM> vms = new ArrayList<>(cstr.getInvolvedVMs());
for (int i = 0; i < vms.size(); i++) {
VM vm = vms.get(i);
VMTransition aI = rp.getVMAction(vm);
for (int j = 0; j < i; j++) {
VM vmJ = vms.get(j);
VMTransition aJ = rp.getVMAction(vmJ);
disallowOverlap(rp, aI, aJ);
}
}
}
return true;
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class CSpread method placementVariables.
private List<IntVar> placementVariables(ReconfigurationProblem rp) {
List<IntVar> running = new ArrayList<>();
for (VM vmId : cstr.getInvolvedVMs()) {
if (rp.getFutureRunningVMs().contains(vmId)) {
VMTransition a = rp.getVMAction(vmId);
Slice d = a.getDSlice();
if (d != null) {
running.add(d.getHoster());
}
}
}
return running;
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class CMinMigrations method placeVMs.
/*
* Try to place the VMs associated on the actions in a random node while trying first to stay on the current node
*/
private void placeVMs(Parameters ps, List<AbstractStrategy<?>> strategies, List<VMTransition> actions, OnStableNodeFirst schedHeuristic, Map<IntVar, VM> map) {
IntValueSelector rnd = new WorstFit(map, rp, new BiggestDimension());
if (!useResources) {
rnd = new RandomVMPlacement(rp, map, true, ps.getRandomSeed());
}
IntVar[] hosts = dSlices(actions).map(Slice::getHoster).filter(v -> !v.isInstantiated()).toArray(IntVar[]::new);
if (hosts.length > 0) {
strategies.add(new IntStrategy(hosts, new HostingVariableSelector(rp.getModel(), schedHeuristic), rnd));
}
}
Aggregations