HBASE-24719: Renaming invalid rsgroup throws NPE instead of proper error message (#2074)

Signed-off-by: Pankaj Kumar<pankajkumar@apache.org>
This commit is contained in:
Mohammad Arshad 2020-09-04 23:04:32 +05:30 committed by GitHub
parent c7b930a9e8
commit aac21aebec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -404,11 +404,14 @@ final class RSGroupInfoManagerImpl implements RSGroupInfoManager {
if (oldName.equals(RSGroupInfo.DEFAULT_GROUP)) {
throw new ConstraintException("Can't rename default rsgroup");
}
RSGroupInfo oldGroup = getRSGroup(oldName);
if (oldGroup == null) {
throw new ConstraintException("RSGroup " + oldName + " does not exist");
}
if (rsGroupMap.containsKey(newName)) {
throw new ConstraintException("Group already exists: " + newName);
}
RSGroupInfo oldGroup = getRSGroup(oldName);
Map<String,RSGroupInfo> newGroupMap = Maps.newHashMap(rsGroupMap);
newGroupMap.remove(oldName);
RSGroupInfo newGroup = new RSGroupInfo(newName,

View File

@ -558,6 +558,14 @@ public class TestRSGroupsAdmin1 extends TestRSGroupsBase {
assertNotNull(anotherGroup);
assertEquals(1, anotherGroup.getServers().size());
//Rename a non existing RSGroup
try {
rsGroupAdmin.renameRSGroup("nonExistingRSGroup", "newRSGroup1");
fail("ConstraintException was expected.");
} catch (ConstraintException e) {
assertTrue(e.getMessage().contains("does not exist"));
}
//Rename to existing group
try {
rsGroupAdmin.renameRSGroup(oldGroup.getName(), anotherRSGroupName);