@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(); Node n1 = mo.newNode(); Node n2 = mo.newNode(); Node n3 = mo.newNode(); Mapping m = mo.getMapping().on(n1, n2, n3) .run(n1, vm1, vm2, vm3).run(n2, vm4).ready(vm5); ShareableResource rc = new ShareableResource("cpu", 5, 5); rc.setConsumption(vm1, 2); rc.setConsumption(vm2, 3); rc.setConsumption(vm3, 3); rc.setConsumption(vm4, 1); rc.setConsumption(vm5, 5); mo.attach(rc); ResourceCapacity c = new ResourceCapacity(m.getAllNodes(), "cpu", 10); CResourceCapacity cc = new CResourceCapacity(c); Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR()); Assert.assertTrue(cc.getMisPlacedVMs(i).isEmpty()); m.addRunningVM(vm5, n3); Assert.assertEquals(cc.getMisPlacedVMs(i), m.getAllVMs()); }
@Override public Set<VM> getMisPlacedVMs(Instance i) { if (cstr.getInvolvedNodes().size() <= 1) { 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; }
CResourceCapacity implements ChocoConstraint { @Override public Set<VM> getMisPlacedVMs(Instance i) { if (cstr.getInvolvedNodes().size() <= 1) { 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; } }
CResourceCapacity implements ChocoConstraint { @Override public Set<VM> getMisPlacedVMs(Instance i) { if (cstr.getInvolvedNodes().size() <= 1) { 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; } CResourceCapacity(ResourceCapacity c); }
CResourceCapacity implements ChocoConstraint { @Override public Set<VM> getMisPlacedVMs(Instance i) { if (cstr.getInvolvedNodes().size() <= 1) { 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; } CResourceCapacity(ResourceCapacity c); @Override boolean inject(Parameters ps, ReconfigurationProblem rp); @Override Set<VM> getMisPlacedVMs(Instance i); @Override String toString(); }
CResourceCapacity implements ChocoConstraint { @Override public Set<VM> getMisPlacedVMs(Instance i) { if (cstr.getInvolvedNodes().size() <= 1) { 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; } CResourceCapacity(ResourceCapacity c); @Override boolean inject(Parameters ps, ReconfigurationProblem rp); @Override Set<VM> getMisPlacedVMs(Instance i); @Override String toString();  }