20
20
import static org .junit .Assert .assertTrue ;
21
21
22
22
import java .io .IOException ;
23
+ import java .util .ArrayList ;
23
24
import java .util .EnumSet ;
24
25
import java .util .HashSet ;
25
26
import java .util .LinkedList ;
37
38
import org .apache .hadoop .hbase .HConstants ;
38
39
import org .apache .hadoop .hbase .MiniHBaseCluster ;
39
40
import org .apache .hadoop .hbase .NamespaceDescriptor ;
40
- import org .apache .hadoop .hbase .RegionMetrics ;
41
- import org .apache .hadoop .hbase .ServerMetrics ;
42
41
import org .apache .hadoop .hbase .ServerName ;
43
42
import org .apache .hadoop .hbase .TableName ;
44
43
import org .apache .hadoop .hbase .Waiter ;
55
54
import org .apache .hadoop .hbase .master .ServerManager ;
56
55
import org .apache .hadoop .hbase .master .snapshot .SnapshotManager ;
57
56
import org .apache .hadoop .hbase .net .Address ;
58
- import org .apache .hadoop .hbase .util .Bytes ;
59
57
import org .junit .Rule ;
60
58
import org .junit .rules .TestName ;
61
59
import org .slf4j .Logger ;
@@ -185,7 +183,7 @@ public boolean evaluate() throws Exception {
185
183
});
186
184
}
187
185
188
- public RSGroupInfo addGroup (String groupName , int serverCount )
186
+ protected RSGroupInfo addGroup (String groupName , int serverCount )
189
187
throws IOException , InterruptedException {
190
188
RSGroupInfo defaultInfo = rsGroupAdmin .getRSGroupInfo (RSGroupInfo .DEFAULT_GROUP );
191
189
rsGroupAdmin .addRSGroup (groupName );
@@ -201,29 +199,29 @@ public RSGroupInfo addGroup(String groupName, int serverCount)
201
199
return result ;
202
200
}
203
201
204
- public void removeGroup (String groupName ) throws IOException {
202
+ protected void removeGroup (String groupName ) throws IOException {
205
203
RSGroupInfo groupInfo = rsGroupAdmin .getRSGroupInfo (groupName );
206
204
rsGroupAdmin .moveTables (groupInfo .getTables (), RSGroupInfo .DEFAULT_GROUP );
207
205
rsGroupAdmin .moveServers (groupInfo .getServers (), RSGroupInfo .DEFAULT_GROUP );
208
206
rsGroupAdmin .removeRSGroup (groupName );
209
207
}
210
208
211
- public void deleteTableIfNecessary () throws IOException {
209
+ protected void deleteTableIfNecessary () throws IOException {
212
210
for (TableDescriptor desc : TEST_UTIL .getAdmin ()
213
211
.listTableDescriptors (Pattern .compile (tablePrefix + ".*" ))) {
214
212
TEST_UTIL .deleteTable (desc .getTableName ());
215
213
}
216
214
}
217
215
218
- public void deleteNamespaceIfNecessary () throws IOException {
216
+ protected void deleteNamespaceIfNecessary () throws IOException {
219
217
for (NamespaceDescriptor desc : TEST_UTIL .getAdmin ().listNamespaceDescriptors ()) {
220
218
if (desc .getName ().startsWith (tablePrefix )) {
221
219
admin .deleteNamespace (desc .getName ());
222
220
}
223
221
}
224
222
}
225
223
226
- public void deleteGroups () throws IOException {
224
+ protected void deleteGroups () throws IOException {
227
225
RSGroupAdmin groupAdmin = new RSGroupAdminClient (TEST_UTIL .getConnection ());
228
226
for (RSGroupInfo group : groupAdmin .listRSGroups ()) {
229
227
if (!group .getName ().equals (RSGroupInfo .DEFAULT_GROUP )) {
@@ -234,7 +232,7 @@ public void deleteGroups() throws IOException {
234
232
}
235
233
}
236
234
237
- public Map <TableName , List <String >> getTableRegionMap () throws IOException {
235
+ protected Map <TableName , List <String >> getTableRegionMap () throws IOException {
238
236
Map <TableName , List <String >> map = Maps .newTreeMap ();
239
237
Map <TableName , Map <ServerName , List <String >>> tableServerRegionMap
240
238
= getTableServerRegionMap ();
@@ -249,35 +247,24 @@ public Map<TableName, List<String>> getTableRegionMap() throws IOException {
249
247
return map ;
250
248
}
251
249
252
- public Map <TableName , Map <ServerName , List <String >>> getTableServerRegionMap ()
253
- throws IOException {
250
+ protected Map <TableName , Map <ServerName , List <String >>> getTableServerRegionMap ()
251
+ throws IOException {
254
252
Map <TableName , Map <ServerName , List <String >>> map = Maps .newTreeMap ();
255
- ClusterMetrics status = TEST_UTIL .getHBaseClusterInterface ().getClusterMetrics ();
256
- for (Map .Entry <ServerName , ServerMetrics > entry : status .getLiveServerMetrics ().entrySet ()) {
257
- ServerName serverName = entry .getKey ();
258
- for (RegionMetrics rl : entry .getValue ().getRegionMetrics ().values ()) {
259
- TableName tableName = null ;
260
- try {
261
- tableName = RegionInfo .getTable (rl .getRegionName ());
262
- } catch (IllegalArgumentException e ) {
263
- LOG .warn ("Failed parse a table name from regionname=" +
264
- Bytes .toStringBinary (rl .getRegionName ()));
265
- continue ;
266
- }
267
- if (!map .containsKey (tableName )) {
268
- map .put (tableName , new TreeMap <>());
269
- }
270
- if (!map .get (tableName ).containsKey (serverName )) {
271
- map .get (tableName ).put (serverName , new LinkedList <>());
272
- }
273
- map .get (tableName ).get (serverName ).add (rl .getNameAsString ());
253
+ Admin admin = TEST_UTIL .getAdmin ();
254
+ ClusterMetrics metrics =
255
+ admin .getClusterMetrics (EnumSet .of (ClusterMetrics .Option .SERVERS_NAME ));
256
+ for (ServerName serverName : metrics .getServersName ()) {
257
+ for (RegionInfo region : admin .getRegions (serverName )) {
258
+ TableName tableName = region .getTable ();
259
+ map .computeIfAbsent (tableName , k -> new TreeMap <>())
260
+ .computeIfAbsent (serverName , k -> new ArrayList <>()).add (region .getRegionNameAsString ());
274
261
}
275
262
}
276
263
return map ;
277
264
}
278
265
279
266
// return the real number of region servers, excluding the master embedded region server in 2.0+
280
- public int getNumServers () throws IOException {
267
+ protected int getNumServers () throws IOException {
281
268
ClusterMetrics status =
282
269
admin .getClusterMetrics (EnumSet .of (Option .MASTER , Option .LIVE_SERVERS ));
283
270
ServerName masterName = status .getMasterName ();
@@ -290,7 +277,7 @@ public int getNumServers() throws IOException {
290
277
return count ;
291
278
}
292
279
293
- public String getGroupName (String baseName ) {
280
+ protected String getGroupName (String baseName ) {
294
281
return groupPrefix + "_" + baseName + "_" + rand .nextInt (Integer .MAX_VALUE );
295
282
}
296
283
0 commit comments