@Test public void testMoveServersFromDefaultGroup() throws Exception { rsGroupAdmin.addRSGroup("foo"); RSGroupInfo fooGroup = rsGroupAdmin.getRSGroupInfo("foo"); assertEquals(0, fooGroup.getServers().size()); RSGroupInfo defaultGroup = rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP); rsGroupAdmin.moveServers(defaultGroup.getServers(), fooGroup.getName()); fail(RSGroupAdminServer.KEEP_ONE_SERVER_IN_DEFAULT_ERROR_MESSAGE); } catch (ConstraintException ex) { LOG.info("moving server " + serverInDefaultGroup + " from group default to group " + fooGroup.getName()); rsGroupAdmin.moveServers(Sets.newHashSet(serverInDefaultGroup), fooGroup.getName()); fooGroup = rsGroupAdmin.getRSGroupInfo("foo"); LOG.info("moving servers " + fooGroup.getServers() + " to group default"); rsGroupAdmin.moveServers(fooGroup.getServers(), RSGroupInfo.DEFAULT_GROUP); fooGroup = rsGroupAdmin.getRSGroupInfo("foo"); assertEquals(0, fooGroup.getServers().size()); rsGroupAdmin.removeRSGroup(fooGroup.getName()); Assert.assertEquals(null, rsGroupAdmin.getRSGroupInfo(fooGroup.getName()));
@Test public void testBogusArgs() throws Exception { assertNull(rsGroupAdmin.getRSGroupInfoOfTable(TableName.valueOf("nonexistent"))); assertNull(rsGroupAdmin.getRSGroupOfServer(Address.fromParts("bogus", 123))); assertNull(rsGroupAdmin.getRSGroupInfo("bogus")); rsGroupAdmin.removeRSGroup("bogus"); fail("Expected removing bogus group to fail"); } catch (ConstraintException ex) { rsGroupAdmin.moveTables(Sets.newHashSet(TableName.valueOf("bogustable")), "bogus"); fail("Expected move with bogus group to fail"); } catch (ConstraintException | TableNotFoundException ex) { rsGroupAdmin.moveServers(Sets.newHashSet(Address.fromParts("bogus", 123)), "bogus"); fail("Expected move with bogus group to fail"); } catch (ConstraintException ex) { rsGroupAdmin.balanceRSGroup("bogus"); admin.balancerSwitch(false, true); fail("Expected move with bogus group to fail");
public void deleteGroups() throws IOException { RSGroupAdmin groupAdmin = new RSGroupAdminClient(TEST_UTIL.getConnection()); for(RSGroupInfo group: groupAdmin.listRSGroups()) { if(!group.getName().equals(RSGroupInfo.DEFAULT_GROUP)) { groupAdmin.moveTables(group.getTables(), RSGroupInfo.DEFAULT_GROUP); groupAdmin.moveServers(group.getServers(), RSGroupInfo.DEFAULT_GROUP); groupAdmin.removeRSGroup(group.getName()); } } }
public void removeGroup(String groupName) throws IOException { RSGroupInfo groupInfo = rsGroupAdmin.getRSGroupInfo(groupName); rsGroupAdmin.moveTables(groupInfo.getTables(), RSGroupInfo.DEFAULT_GROUP); rsGroupAdmin.moveServers(groupInfo.getServers(), RSGroupInfo.DEFAULT_GROUP); rsGroupAdmin.removeRSGroup(groupName); }
public RSGroupInfo addGroup(String groupName, int serverCount) throws IOException, InterruptedException { RSGroupInfo defaultInfo = rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP); rsGroupAdmin.addRSGroup(groupName); Set<Address> set = new HashSet<>(); for(Address server: defaultInfo.getServers()) { if(set.size() == serverCount) { break; } set.add(server); } rsGroupAdmin.moveServers(set, groupName); RSGroupInfo result = rsGroupAdmin.getRSGroupInfo(groupName); return result; }
RSGroupInfo tableGrpA = rsGroupAdmin.getRSGroupInfoOfTable(tableNameA); assertTrue(tableGrpA.getName().equals(RSGroupInfo.DEFAULT_GROUP)); RSGroupInfo tableGrpB = rsGroupAdmin.getRSGroupInfoOfTable(tableNameB); assertTrue(tableGrpB.getName().equals(RSGroupInfo.DEFAULT_GROUP)); rsGroupAdmin.moveTables(Sets.newHashSet(tableNameA, tableNameB), newGroup.getName()); rsGroupAdmin.getRSGroupInfoOfTable(tableNameA).getName()); rsGroupAdmin.getRSGroupInfoOfTable(tableNameB).getName()); rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getTables(); assertFalse(DefaultTables.contains(tableNameA)); assertFalse(DefaultTables.contains(tableNameB)); Set<TableName> newGroupTables = rsGroupAdmin.getRSGroupInfo(newGroupName).getTables(); assertTrue(newGroupTables.contains(tableNameA)); assertTrue(newGroupTables.contains(tableNameB));
.getLiveServerMetrics().keySet()) { if (!newGroup.containsServer(server.getAddress()) && !rsGroupAdmin.getRSGroupInfo("master").containsServer(server.getAddress())) { targetServer = server; break; LOG.debug("Print group info : " + rsGroupAdmin.listRSGroups()); int oldDefaultGroupServerSize = rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getServers().size(); int oldDefaultGroupTableSize = rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getTables().size(); rsGroupAdmin.moveServersAndTables(Sets.newHashSet(Address.fromString("foo:9999")), Sets.newHashSet(tableName), newGroup.getName()); fail("Bogus servers shouldn't have been successfully moved."); rsGroupAdmin.moveServersAndTables(Sets.newHashSet(targetServer.getAddress()), Sets.newHashSet(tableName), RSGroupInfo.DEFAULT_GROUP); fail("servers shouldn't have been successfully moved."); rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getServers().size()); Assert.assertEquals(oldDefaultGroupTableSize, rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getTables().size()); Assert.assertEquals(1, rsGroupAdmin.getRSGroupInfo(newGroup.getName()).getServers().size()); Assert.assertEquals(0, rsGroupAdmin.getRSGroupInfo(newGroup.getName()).getTables().size()); rsGroupAdmin.moveServersAndTables(Sets.newHashSet(targetServer.getAddress()), Sets.newHashSet(tableName), newGroup.getName());
String newGroup = "my_group"; RSGroupAdmin groupAdmin = new RSGroupAdminClient(TEST_UTIL.getConnection()); groupAdmin.addRSGroup(newGroup); if (master.getAssignmentManager().getRegionStates().getRegionAssignments() .containsValue(failoverRS.getServerName())) { groupAdmin.moveServers(Sets.newHashSet(groupRS.getServerName().getAddress()), newGroup); TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() { @Override groupAdmin.moveTables(Sets.newHashSet(RSGroupInfoManager.RSGROUP_TABLE_NAME), newGroup); LOG.info("Waiting for move table..."); TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
@Test public void testNonExistentTableMove() throws Exception { TableName tableName = TableName.valueOf(tablePrefix + name.getMethodName()); RSGroupInfo tableGrp = rsGroupAdmin.getRSGroupInfoOfTable(tableName); assertNull(tableGrp); // test if table exists already. boolean exist = admin.tableExists(tableName); assertFalse(exist); LOG.info("Moving table " + tableName + " to " + RSGroupInfo.DEFAULT_GROUP); try { rsGroupAdmin.moveTables(Sets.newHashSet(tableName), RSGroupInfo.DEFAULT_GROUP); fail("Table " + tableName + " shouldn't have been successfully moved."); } catch (IOException ex) { assertTrue(ex instanceof TableNotFoundException); } try { rsGroupAdmin.moveServersAndTables(Sets.newHashSet(Address.fromParts("bogus", 123)), Sets.newHashSet(tableName), RSGroupInfo.DEFAULT_GROUP); fail("Table " + tableName + " shouldn't have been successfully moved."); } catch (IOException ex) { assertTrue(ex instanceof TableNotFoundException); } // verify group change assertNull(rsGroupAdmin.getRSGroupInfoOfTable(tableName)); }
@Test public void testDisabledTableMove() throws Exception { final byte[] familyNameBytes = Bytes.toBytes("f"); String newGroupName = getGroupName(name.getMethodName()); final RSGroupInfo newGroup = addGroup(newGroupName, 2); TEST_UTIL.createMultiRegionTable(tableName, familyNameBytes, 5); TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() { @Override public boolean evaluate() throws Exception { List<String> regions = getTableRegionMap().get(tableName); if (regions == null) { return false; } return getTableRegionMap().get(tableName).size() >= 5; } }); RSGroupInfo tableGrp = rsGroupAdmin.getRSGroupInfoOfTable(tableName); assertTrue(tableGrp.getName().equals(RSGroupInfo.DEFAULT_GROUP)); // test disable table admin.disableTable(tableName); // change table's group LOG.info("Moving table " + tableName + " to " + newGroup.getName()); rsGroupAdmin.moveTables(Sets.newHashSet(tableName), newGroup.getName()); // verify group change Assert.assertEquals(newGroup.getName(), rsGroupAdmin.getRSGroupInfoOfTable(tableName).getName()); }
rsGroupAdmin.addRSGroup("master"); ServerName masterServerName = ((MiniHBaseCluster)cluster).getMaster().getServerName(); rsGroupAdmin.moveServers(Sets.newHashSet(masterServerName.getAddress()), "master"); } catch (Exception ex) { LOG.warn("Got this on setup, FYI", ex);
String groupName = tablePrefix + "_foo"; LOG.info("testNamespaceConstraint"); rsGroupAdmin.addRSGroup(groupName); assertTrue(observer.preAddRSGroupCalled); assertTrue(observer.postAddRSGroupCalled); rsGroupAdmin.removeRSGroup(groupName); fail("Expected a constraint exception"); } catch (IOException ex) { .addConfiguration(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP, groupName).build()); String anotherGroup = tablePrefix + "_anotherGroup"; rsGroupAdmin.addRSGroup(anotherGroup); rsGroupAdmin.removeRSGroup(groupName); assertTrue(observer.preRemoveRSGroupCalled); assertTrue(observer.postRemoveRSGroupCalled);
Set<Address> newServers = Sets.newHashSet(); newServers .add(rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getServers().iterator().next()); rsGroupAdmin.moveServers(newServers, appInfo.getName());
rsGroupAdmin.removeServers(Sets.newHashSet(targetServer.getAddress())); fail("Online servers shouldn't have been successfully removed."); } catch (IOException ex) { rsGroupAdmin.removeServers(Sets.newHashSet(targetServer.getAddress())); fail("Dead servers shouldn't have been successfully removed."); } catch (IOException ex) { rsGroupAdmin.removeServers(Sets.newHashSet(targetServer.getAddress())); Set<Address> newGroupServers = rsGroupAdmin.getRSGroupInfo(newGroup.getName()).getServers(); assertFalse(newGroupServers.contains(targetServer.getAddress())); assertEquals(2, newGroupServers.size());
@Override public RSGroupInfo getRSGroupInfo(String groupName) throws IOException { return wrapped.getRSGroupInfo(groupName); }
@Override public boolean balanceRSGroup(String groupName) throws IOException { return wrapped.balanceRSGroup(groupName); }
@Override public List<RSGroupInfo> listRSGroups() throws IOException { return wrapped.listRSGroups(); }
@Override public void addRSGroup(String groupName) throws IOException { wrapped.addRSGroup(groupName); verify(); }
@Override public void moveServers(Set<Address> servers, String targetGroup) throws IOException { wrapped.moveServers(servers, targetGroup); verify(); }
@Override public RSGroupInfo getRSGroupOfServer(Address hostPort) throws IOException { return wrapped.getRSGroupOfServer(hostPort); }