mirror of
https://github.com/ctripcorp/zeus.git
synced 2024-09-22 00:26:05 +08:00
fix up path validation
This commit is contained in:
parent
f26d94b355
commit
0939b5db56
|
@ -32,7 +32,7 @@ public class DefaultGroupValidator implements GroupValidator {
|
|||
throw new ValidationException("Group with null value cannot be persisted.");
|
||||
}
|
||||
if (!validateGroupSlbs(group))
|
||||
throw new ValidationException("Virtual server cannot be found.");
|
||||
throw new ValidationException("Virtual server has invalid data.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,14 +65,13 @@ public class DefaultGroupValidator implements GroupValidator {
|
|||
groupPaths.add(vs.getId() + gs.getPath());
|
||||
}
|
||||
for (Long virtualServerId : virtualServerIds) {
|
||||
Set<String> paths = new HashSet<>();
|
||||
for (GroupSlb groupSlb : slbRepository.listGroupSlbsByVirtualServer(virtualServerId)) {
|
||||
if (groupSlb.getGroupId().equals(group.getId()))
|
||||
continue;
|
||||
if (paths.contains(groupSlb.getPath()))
|
||||
if (groupPaths.contains(virtualServerId + groupSlb.getPath()))
|
||||
return false;
|
||||
else
|
||||
paths.add(groupSlb.getPath());
|
||||
groupPaths.add(virtualServerId + groupSlb.getPath());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -200,9 +200,21 @@ public class ValidationTest extends AbstractSpringTest {
|
|||
}
|
||||
|
||||
group = new Group().setName("testDuplicatePath").setAppId("000000")
|
||||
.addGroupSlb(new GroupSlb().setSlbId(1L).setPath("/test").setVirtualServer(slb.getVirtualServers().get(0)))
|
||||
.addGroupSlb(new GroupSlb().setSlbId(1L).setPath("/test1").setVirtualServer(slb.getVirtualServers().get(0)));
|
||||
.addGroupSlb(new GroupSlb().setSlbId(1L).setPath("/test").setVirtualServer(slb.getVirtualServers().get(0)));
|
||||
groupRepository.add(group);
|
||||
|
||||
group = new Group().setName("testDuplicatePath1").setAppId("000000")
|
||||
.addGroupSlb(new GroupSlb().setSlbId(1L).setPath("/test").setVirtualServer(slb.getVirtualServers().get(0)));
|
||||
try {
|
||||
groupRepository.add(group);
|
||||
Assert.assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
Assert.assertTrue(e instanceof ValidationException);
|
||||
System.out.println("Expected cause: duplicate path was found; real cause: " + e.getMessage());
|
||||
}
|
||||
|
||||
group = groupRepository.get("testDuplicatePath");
|
||||
groupRepository.update(group);
|
||||
}
|
||||
|
||||
private Slb prepareSlb() throws Exception {
|
||||
|
|
Loading…
Reference in a new issue