@Test public void testGetMisplaced() { Model mo = new DefaultModel(); VM vm1 = mo.newVM(); VM vm2 = mo.newVM(); VM vm3 = mo.newVM(); VM vm4 = mo.newVM(); VM vm5 = mo.newVM(); VM vm6 = mo.newVM(); VM vm7 = mo.newVM(); VM vm8 = mo.newVM(); Node n1 = mo.newNode(); Node n2 = mo.newNode(); Node n3 = mo.newNode(); Node n4 = mo.newNode(); Node n5 = mo.newNode(); Mapping map = mo.getMapping().on(n1, n2, n3, n4, n5) .run(n1, vm1, vm2) .run(n2, vm3) .run(n3, vm4, vm5) .run(n4, vm6) .run(n5, vm7, vm8); Collection<VM> g1 = Arrays.asList(vm1, vm2); Collection<VM> g2 = new HashSet<>(Arrays.asList(vm3, vm4, vm5)); Collection<VM> g3 = new HashSet<>(Arrays.asList(vm6, vm7)); Collection<Collection<VM>> grps = Arrays.asList(g1, g2, g3); Split s = new Split(grps); CSplit cs = new CSplit(s); Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR()); Assert.assertTrue(cs.getMisPlacedVMs(i).isEmpty()); map.addRunningVM(vm5, n1); Set<VM> bad = cs.getMisPlacedVMs(i); Assert.assertEquals(bad.size(), 3); Assert.assertTrue(bad.contains(vm1) && bad.contains(vm2) && bad.contains(vm5)); map.addRunningVM(vm6, n3); bad = cs.getMisPlacedVMs(i); Assert.assertTrue(bad.contains(vm4) && bad.contains(vm5) && bad.contains(vm6)); }
@Override public Set<VM> getMisPlacedVMs(Instance i) { Mapping map = i.getModel().getMapping(); List<Collection<VM>> groups = new ArrayList<>(cstr.getSets()); Set<VM> bad = new HashSet<>(); for (Collection<VM> grp : groups) { for (VM vm : grp) { if (map.isRunning(vm)) { Node n = map.getVMLocation(vm); Set<VM> allOnN = map.getRunningVMs(n); for (VM vmOnN : allOnN) { if (inOtherGroup(groups, grp, vmOnN)) { bad.add(vm); bad.add(vmOnN); } } } } } return bad; }
CSplit implements ChocoConstraint { @Override public Set<VM> getMisPlacedVMs(Instance i) { Mapping map = i.getModel().getMapping(); List<Collection<VM>> groups = new ArrayList<>(cstr.getSets()); Set<VM> bad = new HashSet<>(); for (Collection<VM> grp : groups) { for (VM vm : grp) { if (map.isRunning(vm)) { Node n = map.getVMLocation(vm); Set<VM> allOnN = map.getRunningVMs(n); for (VM vmOnN : allOnN) { if (inOtherGroup(groups, grp, vmOnN)) { bad.add(vm); bad.add(vmOnN); } } } } } return bad; } }
CSplit implements ChocoConstraint { @Override public Set<VM> getMisPlacedVMs(Instance i) { Mapping map = i.getModel().getMapping(); List<Collection<VM>> groups = new ArrayList<>(cstr.getSets()); Set<VM> bad = new HashSet<>(); for (Collection<VM> grp : groups) { for (VM vm : grp) { if (map.isRunning(vm)) { Node n = map.getVMLocation(vm); Set<VM> allOnN = map.getRunningVMs(n); for (VM vmOnN : allOnN) { if (inOtherGroup(groups, grp, vmOnN)) { bad.add(vm); bad.add(vmOnN); } } } } } return bad; } CSplit(Split s); }
CSplit implements ChocoConstraint { @Override public Set<VM> getMisPlacedVMs(Instance i) { Mapping map = i.getModel().getMapping(); List<Collection<VM>> groups = new ArrayList<>(cstr.getSets()); Set<VM> bad = new HashSet<>(); for (Collection<VM> grp : groups) { for (VM vm : grp) { if (map.isRunning(vm)) { Node n = map.getVMLocation(vm); Set<VM> allOnN = map.getRunningVMs(n); for (VM vmOnN : allOnN) { if (inOtherGroup(groups, grp, vmOnN)) { bad.add(vm); bad.add(vmOnN); } } } } } return bad; } CSplit(Split s); @Override boolean inject(Parameters ps, ReconfigurationProblem rp); @Override Set<VM> getMisPlacedVMs(Instance i); @Override String toString(); }
CSplit implements ChocoConstraint { @Override public Set<VM> getMisPlacedVMs(Instance i) { Mapping map = i.getModel().getMapping(); List<Collection<VM>> groups = new ArrayList<>(cstr.getSets()); Set<VM> bad = new HashSet<>(); for (Collection<VM> grp : groups) { for (VM vm : grp) { if (map.isRunning(vm)) { Node n = map.getVMLocation(vm); Set<VM> allOnN = map.getRunningVMs(n); for (VM vmOnN : allOnN) { if (inOtherGroup(groups, grp, vmOnN)) { bad.add(vm); bad.add(vmOnN); } } } } } return bad; } CSplit(Split s); @Override boolean inject(Parameters ps, ReconfigurationProblem rp); @Override Set<VM> getMisPlacedVMs(Instance i); @Override String toString();  }