@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, vm3) .run(n2, vm2) .run(n3, vm4, vm6) .run(n4, vm5) .run(n5, vm7); map.addRunningVM(vm8, n1); Collection<VM> vg1 = new HashSet<>(Arrays.asList(vm1, vm2, vm3)); Collection<VM> vg2 = new HashSet<>(Arrays.asList(vm4, vm5, vm6)); Collection<VM> vg3 = new HashSet<>(Collections.singletonList(vm7)); Collection<Node> pg1 = new HashSet<>(Arrays.asList(n1, n2)); Collection<Node> pg2 = new HashSet<>(Arrays.asList(n3, n4)); Collection<Node> pg3 = new HashSet<>(Collections.singletonList(n5)); Collection<Collection<VM>> vgs = new HashSet<>(Arrays.asList(vg1, vg2, vg3)); Collection<Collection<Node>> pgs = new HashSet<>(Arrays.asList(pg1, pg2, pg3)); SplitAmong s = new SplitAmong(vgs, pgs); CSplitAmong cs = new CSplitAmong(s); Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR()); Assert.assertTrue(cs.getMisPlacedVMs(i).isEmpty()); map.remove(vm7); map.addRunningVM(vm6, n5); Assert.assertEquals(cs.getMisPlacedVMs(i), vg2); map.addRunningVM(vm7, n5); map.addRunningVM(vm6, n2); Assert.assertTrue(cs.getMisPlacedVMs(i).containsAll(vg1)); Assert.assertTrue(cs.getMisPlacedVMs(i).containsAll(vg2)); Assert.assertEquals(cs.getMisPlacedVMs(i).size(), vg1.size() + vg2.size()); }
@Override public Set<VM> getMisPlacedVMs(Instance i) { @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) { bad.add(vm); } else if (grp == -1) { grp = g; usedGrp[g] = vms; } else if (g != grp) { bad.addAll(vms); if (usedGrp[g] != null) { bad.addAll(usedGrp[g]); } bad.addAll(usedGrp[grp]); } } } } return bad; }
CSplitAmong implements ChocoConstraint { @Override public Set<VM> getMisPlacedVMs(Instance i) { @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) { bad.add(vm); } else if (grp == -1) { grp = g; usedGrp[g] = vms; } else if (g != grp) { bad.addAll(vms); if (usedGrp[g] != null) { bad.addAll(usedGrp[g]); } bad.addAll(usedGrp[grp]); } } } } return bad; } }
CSplitAmong implements ChocoConstraint { @Override public Set<VM> getMisPlacedVMs(Instance i) { @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) { bad.add(vm); } else if (grp == -1) { grp = g; usedGrp[g] = vms; } else if (g != grp) { bad.addAll(vms); if (usedGrp[g] != null) { bad.addAll(usedGrp[g]); } bad.addAll(usedGrp[grp]); } } } } return bad; } CSplitAmong(SplitAmong s); }
CSplitAmong implements ChocoConstraint { @Override public Set<VM> getMisPlacedVMs(Instance i) { @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) { bad.add(vm); } else if (grp == -1) { grp = g; usedGrp[g] = vms; } else if (g != grp) { bad.addAll(vms); if (usedGrp[g] != null) { bad.addAll(usedGrp[g]); } bad.addAll(usedGrp[grp]); } } } } return bad; } CSplitAmong(SplitAmong s); @Override boolean inject(Parameters ps, ReconfigurationProblem rp); int getPGroup(Node n); @Override Set<VM> getMisPlacedVMs(Instance i); @Override String toString(); }
CSplitAmong implements ChocoConstraint { @Override public Set<VM> getMisPlacedVMs(Instance i) { @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) { bad.add(vm); } else if (grp == -1) { grp = g; usedGrp[g] = vms; } else if (g != grp) { bad.addAll(vms); if (usedGrp[g] != null) { bad.addAll(usedGrp[g]); } bad.addAll(usedGrp[grp]); } } } } return bad; } CSplitAmong(SplitAmong s); @Override boolean inject(Parameters ps, ReconfigurationProblem rp); int getPGroup(Node n); @Override Set<VM> getMisPlacedVMs(Instance i); @Override String toString();  }