@Test public void testGetMisplaced() { Model mo = new DefaultModel(); VM vm1 = mo.newVM(); VM vm2 = mo.newVM(); VM vm3 = mo.newVM(); Node n1 = mo.newNode(); Node n2 = mo.newNode(); Mapping map = mo.getMapping().on(n1, n2) .run(n1, vm1, vm3) .run(n2, vm2); Set<VM> vms = new HashSet<>(Arrays.asList(vm1, vm2)); Spread s = new Spread(vms); CSpread cs = new CSpread(s); Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR()); Assert.assertTrue(cs.getMisPlacedVMs(i).isEmpty()); vms.add(vm3); Assert.assertEquals(map.getRunningVMs(n1), cs.getMisPlacedVMs(i)); }
@Override public Set<VM> getMisPlacedVMs(Instance i) { Map<Node, Set<VM>> spots = new HashMap<>(); Set<VM> bad = new HashSet<>(); Mapping map = i.getModel().getMapping(); for (VM vm : cstr.getInvolvedVMs()) { Node h = map.getVMLocation(vm); if (map.isRunning(vm)) { if (!spots.containsKey(h)) { spots.put(h, new HashSet<>()); } spots.get(h).add(vm); } } for (Map.Entry<Node, Set<VM>> e : spots.entrySet()) { if (e.getValue().size() > 1) { bad.addAll(e.getValue()); } } return bad; }
CSpread implements ChocoConstraint { @Override public Set<VM> getMisPlacedVMs(Instance i) { Map<Node, Set<VM>> spots = new HashMap<>(); Set<VM> bad = new HashSet<>(); Mapping map = i.getModel().getMapping(); for (VM vm : cstr.getInvolvedVMs()) { Node h = map.getVMLocation(vm); if (map.isRunning(vm)) { if (!spots.containsKey(h)) { spots.put(h, new HashSet<>()); } spots.get(h).add(vm); } } for (Map.Entry<Node, Set<VM>> e : spots.entrySet()) { if (e.getValue().size() > 1) { bad.addAll(e.getValue()); } } return bad; } }
CSpread implements ChocoConstraint { @Override public Set<VM> getMisPlacedVMs(Instance i) { Map<Node, Set<VM>> spots = new HashMap<>(); Set<VM> bad = new HashSet<>(); Mapping map = i.getModel().getMapping(); for (VM vm : cstr.getInvolvedVMs()) { Node h = map.getVMLocation(vm); if (map.isRunning(vm)) { if (!spots.containsKey(h)) { spots.put(h, new HashSet<>()); } spots.get(h).add(vm); } } for (Map.Entry<Node, Set<VM>> e : spots.entrySet()) { if (e.getValue().size() > 1) { bad.addAll(e.getValue()); } } return bad; } CSpread(Spread s); }
CSpread implements ChocoConstraint { @Override public Set<VM> getMisPlacedVMs(Instance i) { Map<Node, Set<VM>> spots = new HashMap<>(); Set<VM> bad = new HashSet<>(); Mapping map = i.getModel().getMapping(); for (VM vm : cstr.getInvolvedVMs()) { Node h = map.getVMLocation(vm); if (map.isRunning(vm)) { if (!spots.containsKey(h)) { spots.put(h, new HashSet<>()); } spots.get(h).add(vm); } } for (Map.Entry<Node, Set<VM>> e : spots.entrySet()) { if (e.getValue().size() > 1) { bad.addAll(e.getValue()); } } return bad; } CSpread(Spread s); @Override boolean inject(Parameters ps, ReconfigurationProblem rp); @Override Set<VM> getMisPlacedVMs(Instance i); @Override String toString(); }
CSpread implements ChocoConstraint { @Override public Set<VM> getMisPlacedVMs(Instance i) { Map<Node, Set<VM>> spots = new HashMap<>(); Set<VM> bad = new HashSet<>(); Mapping map = i.getModel().getMapping(); for (VM vm : cstr.getInvolvedVMs()) { Node h = map.getVMLocation(vm); if (map.isRunning(vm)) { if (!spots.containsKey(h)) { spots.put(h, new HashSet<>()); } spots.get(h).add(vm); } } for (Map.Entry<Node, Set<VM>> e : spots.entrySet()) { if (e.getValue().size() > 1) { bad.addAll(e.getValue()); } } return bad; } CSpread(Spread s); @Override boolean inject(Parameters ps, ReconfigurationProblem rp); @Override Set<VM> getMisPlacedVMs(Instance i); @Override String toString();  }