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:
parent
c7b930a9e8
commit
aac21aebec
|
@ -404,11 +404,14 @@ final class RSGroupInfoManagerImpl implements RSGroupInfoManager {
|
||||||
if (oldName.equals(RSGroupInfo.DEFAULT_GROUP)) {
|
if (oldName.equals(RSGroupInfo.DEFAULT_GROUP)) {
|
||||||
throw new ConstraintException("Can't rename default rsgroup");
|
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)) {
|
if (rsGroupMap.containsKey(newName)) {
|
||||||
throw new ConstraintException("Group already exists: " + newName);
|
throw new ConstraintException("Group already exists: " + newName);
|
||||||
}
|
}
|
||||||
|
|
||||||
RSGroupInfo oldGroup = getRSGroup(oldName);
|
|
||||||
Map<String,RSGroupInfo> newGroupMap = Maps.newHashMap(rsGroupMap);
|
Map<String,RSGroupInfo> newGroupMap = Maps.newHashMap(rsGroupMap);
|
||||||
newGroupMap.remove(oldName);
|
newGroupMap.remove(oldName);
|
||||||
RSGroupInfo newGroup = new RSGroupInfo(newName,
|
RSGroupInfo newGroup = new RSGroupInfo(newName,
|
||||||
|
|
|
@ -558,6 +558,14 @@ public class TestRSGroupsAdmin1 extends TestRSGroupsBase {
|
||||||
assertNotNull(anotherGroup);
|
assertNotNull(anotherGroup);
|
||||||
assertEquals(1, anotherGroup.getServers().size());
|
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
|
//Rename to existing group
|
||||||
try {
|
try {
|
||||||
rsGroupAdmin.renameRSGroup(oldGroup.getName(), anotherRSGroupName);
|
rsGroupAdmin.renameRSGroup(oldGroup.getName(), anotherRSGroupName);
|
||||||
|
|
Loading…
Reference in New Issue