001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.rsgroup;
019
020import static org.junit.Assert.assertEquals;
021import static org.junit.Assert.assertTrue;
022
023import java.io.ByteArrayInputStream;
024import java.io.Closeable;
025import java.io.IOException;
026import java.util.ArrayList;
027import java.util.EnumSet;
028import java.util.List;
029import java.util.Map;
030import java.util.Set;
031import java.util.SortedSet;
032import java.util.concurrent.Future;
033import java.util.regex.Pattern;
034import org.apache.hadoop.conf.Configuration;
035import org.apache.hadoop.hbase.CacheEvictionStats;
036import org.apache.hadoop.hbase.ClusterMetrics;
037import org.apache.hadoop.hbase.ClusterMetrics.Option;
038import org.apache.hadoop.hbase.NamespaceDescriptor;
039import org.apache.hadoop.hbase.NamespaceNotFoundException;
040import org.apache.hadoop.hbase.RegionMetrics;
041import org.apache.hadoop.hbase.ServerName;
042import org.apache.hadoop.hbase.TableExistsException;
043import org.apache.hadoop.hbase.TableName;
044import org.apache.hadoop.hbase.TableNotFoundException;
045import org.apache.hadoop.hbase.client.Admin;
046import org.apache.hadoop.hbase.client.BalanceRequest;
047import org.apache.hadoop.hbase.client.BalanceResponse;
048import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
049import org.apache.hadoop.hbase.client.CompactType;
050import org.apache.hadoop.hbase.client.CompactionState;
051import org.apache.hadoop.hbase.client.Connection;
052import org.apache.hadoop.hbase.client.ConnectionFactory;
053import org.apache.hadoop.hbase.client.LogEntry;
054import org.apache.hadoop.hbase.client.NormalizeTableFilterParams;
055import org.apache.hadoop.hbase.client.RegionInfo;
056import org.apache.hadoop.hbase.client.Result;
057import org.apache.hadoop.hbase.client.ResultScanner;
058import org.apache.hadoop.hbase.client.Scan;
059import org.apache.hadoop.hbase.client.ServerType;
060import org.apache.hadoop.hbase.client.SnapshotDescription;
061import org.apache.hadoop.hbase.client.Table;
062import org.apache.hadoop.hbase.client.TableDescriptor;
063import org.apache.hadoop.hbase.client.replication.TableCFs;
064import org.apache.hadoop.hbase.client.security.SecurityCapability;
065import org.apache.hadoop.hbase.exceptions.DeserializationException;
066import org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel;
067import org.apache.hadoop.hbase.net.Address;
068import org.apache.hadoop.hbase.quotas.QuotaFilter;
069import org.apache.hadoop.hbase.quotas.QuotaSettings;
070import org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshotView;
071import org.apache.hadoop.hbase.regionserver.wal.FailedLogCloseException;
072import org.apache.hadoop.hbase.replication.ReplicationPeerConfig;
073import org.apache.hadoop.hbase.replication.ReplicationPeerDescription;
074import org.apache.hadoop.hbase.replication.SyncReplicationState;
075import org.apache.hadoop.hbase.security.access.GetUserPermissionsRequest;
076import org.apache.hadoop.hbase.security.access.Permission;
077import org.apache.hadoop.hbase.security.access.UserPermission;
078import org.apache.hadoop.hbase.snapshot.HBaseSnapshotException;
079import org.apache.hadoop.hbase.snapshot.RestoreSnapshotException;
080import org.apache.hadoop.hbase.snapshot.SnapshotCreationException;
081import org.apache.hadoop.hbase.snapshot.UnknownSnapshotException;
082import org.apache.hadoop.hbase.util.Pair;
083import org.apache.hadoop.hbase.zookeeper.ZKUtil;
084import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
085import org.apache.hadoop.hbase.zookeeper.ZNodePaths;
086import org.apache.yetus.audience.InterfaceAudience;
087import org.apache.zookeeper.KeeperException;
088
089import org.apache.hbase.thirdparty.com.google.common.collect.Maps;
090import org.apache.hbase.thirdparty.com.google.common.collect.Sets;
091
092import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
093import org.apache.hadoop.hbase.shaded.protobuf.generated.RSGroupProtos;
094
095@InterfaceAudience.Private
096public class VerifyingRSGroupAdmin implements Admin, Closeable {
097
098  private final Connection conn;
099
100  private final Admin admin;
101
102  private final ZKWatcher zkw;
103
104  public VerifyingRSGroupAdmin(Configuration conf) throws IOException {
105    conn = ConnectionFactory.createConnection(conf);
106    admin = conn.getAdmin();
107    zkw = new ZKWatcher(conf, this.getClass().getSimpleName(), null);
108  }
109
110  public int getOperationTimeout() {
111    return admin.getOperationTimeout();
112  }
113
114  public int getSyncWaitTimeout() {
115    return admin.getSyncWaitTimeout();
116  }
117
118  public void abort(String why, Throwable e) {
119    admin.abort(why, e);
120  }
121
122  public boolean isAborted() {
123    return admin.isAborted();
124  }
125
126  public Connection getConnection() {
127    return admin.getConnection();
128  }
129
130  public boolean tableExists(TableName tableName) throws IOException {
131    return admin.tableExists(tableName);
132  }
133
134  public List<TableDescriptor> listTableDescriptors() throws IOException {
135    return admin.listTableDescriptors();
136  }
137
138  public List<TableDescriptor> listTableDescriptors(boolean includeSysTables) throws IOException {
139    return admin.listTableDescriptors(includeSysTables);
140  }
141
142  public List<TableDescriptor> listTableDescriptors(Pattern pattern, boolean includeSysTables)
143    throws IOException {
144    return admin.listTableDescriptors(pattern, includeSysTables);
145  }
146
147  @Override
148  public List<TableDescriptor> listTableDescriptorsByState(boolean isEnabled) throws IOException {
149    return admin.listTableDescriptorsByState(isEnabled);
150  }
151
152  public TableName[] listTableNames() throws IOException {
153    return admin.listTableNames();
154  }
155
156  public TableName[] listTableNames(Pattern pattern, boolean includeSysTables) throws IOException {
157    return admin.listTableNames(pattern, includeSysTables);
158  }
159
160  @Override
161  public List<TableName> listTableNamesByState(boolean isEnabled) throws IOException {
162    return admin.listTableNamesByState(isEnabled);
163  }
164
165  public TableDescriptor getDescriptor(TableName tableName)
166    throws TableNotFoundException, IOException {
167    return admin.getDescriptor(tableName);
168  }
169
170  public void createTable(TableDescriptor desc, byte[] startKey, byte[] endKey, int numRegions)
171    throws IOException {
172    admin.createTable(desc, startKey, endKey, numRegions);
173  }
174
175  public Future<Void> createTableAsync(TableDescriptor desc) throws IOException {
176    return admin.createTableAsync(desc);
177  }
178
179  public Future<Void> createTableAsync(TableDescriptor desc, byte[][] splitKeys)
180    throws IOException {
181    return admin.createTableAsync(desc, splitKeys);
182  }
183
184  public Future<Void> deleteTableAsync(TableName tableName) throws IOException {
185    return admin.deleteTableAsync(tableName);
186  }
187
188  public Future<Void> truncateTableAsync(TableName tableName, boolean preserveSplits)
189    throws IOException {
190    return admin.truncateTableAsync(tableName, preserveSplits);
191  }
192
193  public Future<Void> enableTableAsync(TableName tableName) throws IOException {
194    return admin.enableTableAsync(tableName);
195  }
196
197  public Future<Void> disableTableAsync(TableName tableName) throws IOException {
198    return admin.disableTableAsync(tableName);
199  }
200
201  public boolean isTableEnabled(TableName tableName) throws IOException {
202    return admin.isTableEnabled(tableName);
203  }
204
205  public boolean isTableDisabled(TableName tableName) throws IOException {
206    return admin.isTableDisabled(tableName);
207  }
208
209  public boolean isTableAvailable(TableName tableName) throws IOException {
210    return admin.isTableAvailable(tableName);
211  }
212
213  public Future<Void> addColumnFamilyAsync(TableName tableName, ColumnFamilyDescriptor columnFamily)
214    throws IOException {
215    return admin.addColumnFamilyAsync(tableName, columnFamily);
216  }
217
218  public Future<Void> deleteColumnFamilyAsync(TableName tableName, byte[] columnFamily)
219    throws IOException {
220    return admin.deleteColumnFamilyAsync(tableName, columnFamily);
221  }
222
223  public Future<Void> modifyColumnFamilyAsync(TableName tableName,
224    ColumnFamilyDescriptor columnFamily) throws IOException {
225    return admin.modifyColumnFamilyAsync(tableName, columnFamily);
226  }
227
228  public List<RegionInfo> getRegions(ServerName serverName) throws IOException {
229    return admin.getRegions(serverName);
230  }
231
232  public void flush(TableName tableName) throws IOException {
233    admin.flush(tableName);
234  }
235
236  public void flush(TableName tableName, byte[] columnFamily) throws IOException {
237    admin.flush(tableName, columnFamily);
238  }
239
240  public void flush(TableName tableName, List<byte[]> columnFamilies) throws IOException {
241    admin.flush(tableName, columnFamilies);
242  }
243
244  public void flushRegion(byte[] regionName) throws IOException {
245    admin.flushRegion(regionName);
246  }
247
248  public void flushRegion(byte[] regionName, byte[] columnFamily) throws IOException {
249    admin.flushRegion(regionName, columnFamily);
250  }
251
252  public void flushRegionServer(ServerName serverName) throws IOException {
253    admin.flushRegionServer(serverName);
254  }
255
256  public void compact(TableName tableName) throws IOException {
257    admin.compact(tableName);
258  }
259
260  public void compactRegion(byte[] regionName) throws IOException {
261    admin.compactRegion(regionName);
262  }
263
264  public void compact(TableName tableName, byte[] columnFamily) throws IOException {
265    admin.compact(tableName, columnFamily);
266  }
267
268  public void compactRegion(byte[] regionName, byte[] columnFamily) throws IOException {
269    admin.compactRegion(regionName, columnFamily);
270  }
271
272  public void compact(TableName tableName, CompactType compactType)
273    throws IOException, InterruptedException {
274    admin.compact(tableName, compactType);
275  }
276
277  public void compact(TableName tableName, byte[] columnFamily, CompactType compactType)
278    throws IOException, InterruptedException {
279    admin.compact(tableName, columnFamily, compactType);
280  }
281
282  public void majorCompact(TableName tableName) throws IOException {
283    admin.majorCompact(tableName);
284  }
285
286  public void majorCompactRegion(byte[] regionName) throws IOException {
287    admin.majorCompactRegion(regionName);
288  }
289
290  public void majorCompact(TableName tableName, byte[] columnFamily) throws IOException {
291    admin.majorCompact(tableName, columnFamily);
292  }
293
294  public void majorCompactRegion(byte[] regionName, byte[] columnFamily) throws IOException {
295    admin.majorCompactRegion(regionName, columnFamily);
296  }
297
298  public void majorCompact(TableName tableName, CompactType compactType)
299    throws IOException, InterruptedException {
300    admin.majorCompact(tableName, compactType);
301  }
302
303  public void majorCompact(TableName tableName, byte[] columnFamily, CompactType compactType)
304    throws IOException, InterruptedException {
305    admin.majorCompact(tableName, columnFamily, compactType);
306  }
307
308  public Map<ServerName, Boolean> compactionSwitch(boolean switchState,
309    List<String> serverNamesList) throws IOException {
310    return admin.compactionSwitch(switchState, serverNamesList);
311  }
312
313  public void compactRegionServer(ServerName serverName) throws IOException {
314    admin.compactRegionServer(serverName);
315  }
316
317  public void majorCompactRegionServer(ServerName serverName) throws IOException {
318    admin.majorCompactRegionServer(serverName);
319  }
320
321  public void move(byte[] encodedRegionName) throws IOException {
322    admin.move(encodedRegionName);
323  }
324
325  public void move(byte[] encodedRegionName, ServerName destServerName) throws IOException {
326    admin.move(encodedRegionName, destServerName);
327  }
328
329  public void assign(byte[] regionName) throws IOException {
330    admin.assign(regionName);
331  }
332
333  public void unassign(byte[] regionName) throws IOException {
334    admin.unassign(regionName);
335  }
336
337  public void offline(byte[] regionName) throws IOException {
338    admin.offline(regionName);
339  }
340
341  public boolean balancerSwitch(boolean onOrOff, boolean synchronous) throws IOException {
342    return admin.balancerSwitch(onOrOff, synchronous);
343  }
344
345  public BalanceResponse balance(BalanceRequest request) throws IOException {
346    return admin.balance(request);
347  }
348
349  public boolean isBalancerEnabled() throws IOException {
350    return admin.isBalancerEnabled();
351  }
352
353  public CacheEvictionStats clearBlockCache(TableName tableName) throws IOException {
354    return admin.clearBlockCache(tableName);
355  }
356
357  @Override
358  public boolean normalize(NormalizeTableFilterParams ntfp) throws IOException {
359    return admin.normalize(ntfp);
360  }
361
362  public boolean isNormalizerEnabled() throws IOException {
363    return admin.isNormalizerEnabled();
364  }
365
366  public boolean normalizerSwitch(boolean on) throws IOException {
367    return admin.normalizerSwitch(on);
368  }
369
370  public boolean catalogJanitorSwitch(boolean onOrOff) throws IOException {
371    return admin.catalogJanitorSwitch(onOrOff);
372  }
373
374  public int runCatalogJanitor() throws IOException {
375    return admin.runCatalogJanitor();
376  }
377
378  public boolean isCatalogJanitorEnabled() throws IOException {
379    return admin.isCatalogJanitorEnabled();
380  }
381
382  public boolean cleanerChoreSwitch(boolean onOrOff) throws IOException {
383    return admin.cleanerChoreSwitch(onOrOff);
384  }
385
386  public boolean runCleanerChore() throws IOException {
387    return admin.runCleanerChore();
388  }
389
390  public boolean isCleanerChoreEnabled() throws IOException {
391    return admin.isCleanerChoreEnabled();
392  }
393
394  public Future<Void> mergeRegionsAsync(byte[][] nameofRegionsToMerge, boolean forcible)
395    throws IOException {
396    return admin.mergeRegionsAsync(nameofRegionsToMerge, forcible);
397  }
398
399  public void split(TableName tableName) throws IOException {
400    admin.split(tableName);
401  }
402
403  public void split(TableName tableName, byte[] splitPoint) throws IOException {
404    admin.split(tableName, splitPoint);
405  }
406
407  public Future<Void> splitRegionAsync(byte[] regionName) throws IOException {
408    return admin.splitRegionAsync(regionName);
409  }
410
411  public Future<Void> splitRegionAsync(byte[] regionName, byte[] splitPoint) throws IOException {
412    return admin.splitRegionAsync(regionName, splitPoint);
413  }
414
415  @Override
416  public void truncateRegion(byte[] regionName) throws IOException {
417    admin.truncateRegion(regionName);
418  }
419
420  @Override
421  public Future<Void> truncateRegionAsync(byte[] regionName) throws IOException {
422    return admin.truncateRegionAsync(regionName);
423  }
424
425  public Future<Void> modifyTableAsync(TableDescriptor td) throws IOException {
426    return modifyTableAsync(td, true);
427  }
428
429  public Future<Void> modifyTableAsync(TableDescriptor td, boolean reopenRegions)
430    throws IOException {
431    return admin.modifyTableAsync(td, reopenRegions);
432  }
433
434  public void shutdown() throws IOException {
435    admin.shutdown();
436  }
437
438  public void stopMaster() throws IOException {
439    admin.stopMaster();
440  }
441
442  public boolean isMasterInMaintenanceMode() throws IOException {
443    return admin.isMasterInMaintenanceMode();
444  }
445
446  public void stopRegionServer(String hostnamePort) throws IOException {
447    admin.stopRegionServer(hostnamePort);
448  }
449
450  public ClusterMetrics getClusterMetrics(EnumSet<Option> options) throws IOException {
451    return admin.getClusterMetrics(options);
452  }
453
454  public List<RegionMetrics> getRegionMetrics(ServerName serverName) throws IOException {
455    return admin.getRegionMetrics(serverName);
456  }
457
458  public List<RegionMetrics> getRegionMetrics(ServerName serverName, TableName tableName)
459    throws IOException {
460    return admin.getRegionMetrics(serverName, tableName);
461  }
462
463  public Configuration getConfiguration() {
464    return admin.getConfiguration();
465  }
466
467  public Future<Void> createNamespaceAsync(NamespaceDescriptor descriptor) throws IOException {
468    return admin.createNamespaceAsync(descriptor);
469  }
470
471  public Future<Void> modifyNamespaceAsync(NamespaceDescriptor descriptor) throws IOException {
472    return admin.modifyNamespaceAsync(descriptor);
473  }
474
475  public Future<Void> deleteNamespaceAsync(String name) throws IOException {
476    return admin.deleteNamespaceAsync(name);
477  }
478
479  public NamespaceDescriptor getNamespaceDescriptor(String name)
480    throws NamespaceNotFoundException, IOException {
481    return admin.getNamespaceDescriptor(name);
482  }
483
484  public String[] listNamespaces() throws IOException {
485    return admin.listNamespaces();
486  }
487
488  public NamespaceDescriptor[] listNamespaceDescriptors() throws IOException {
489    return admin.listNamespaceDescriptors();
490  }
491
492  public List<TableDescriptor> listTableDescriptorsByNamespace(byte[] name) throws IOException {
493    return admin.listTableDescriptorsByNamespace(name);
494  }
495
496  public TableName[] listTableNamesByNamespace(String name) throws IOException {
497    return admin.listTableNamesByNamespace(name);
498  }
499
500  public List<RegionInfo> getRegions(TableName tableName) throws IOException {
501    return admin.getRegions(tableName);
502  }
503
504  public void close() {
505    admin.close();
506  }
507
508  public List<TableDescriptor> listTableDescriptors(List<TableName> tableNames) throws IOException {
509    return admin.listTableDescriptors(tableNames);
510  }
511
512  public Future<Boolean> abortProcedureAsync(long procId, boolean mayInterruptIfRunning)
513    throws IOException {
514    return admin.abortProcedureAsync(procId, mayInterruptIfRunning);
515  }
516
517  public String getProcedures() throws IOException {
518    return admin.getProcedures();
519  }
520
521  public String getLocks() throws IOException {
522    return admin.getLocks();
523  }
524
525  public void rollWALWriter(ServerName serverName) throws IOException, FailedLogCloseException {
526    admin.rollWALWriter(serverName);
527  }
528
529  public CompactionState getCompactionState(TableName tableName) throws IOException {
530    return admin.getCompactionState(tableName);
531  }
532
533  public CompactionState getCompactionState(TableName tableName, CompactType compactType)
534    throws IOException {
535    return admin.getCompactionState(tableName, compactType);
536  }
537
538  public CompactionState getCompactionStateForRegion(byte[] regionName) throws IOException {
539    return admin.getCompactionStateForRegion(regionName);
540  }
541
542  public long getLastMajorCompactionTimestamp(TableName tableName) throws IOException {
543    return admin.getLastMajorCompactionTimestamp(tableName);
544  }
545
546  public long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException {
547    return admin.getLastMajorCompactionTimestampForRegion(regionName);
548  }
549
550  public void snapshot(SnapshotDescription snapshot)
551    throws IOException, SnapshotCreationException, IllegalArgumentException {
552    admin.snapshot(snapshot);
553  }
554
555  public Future<Void> snapshotAsync(SnapshotDescription snapshot)
556    throws IOException, SnapshotCreationException {
557    return admin.snapshotAsync(snapshot);
558  }
559
560  public boolean isSnapshotFinished(SnapshotDescription snapshot)
561    throws IOException, HBaseSnapshotException, UnknownSnapshotException {
562    return admin.isSnapshotFinished(snapshot);
563  }
564
565  public void restoreSnapshot(String snapshotName) throws IOException, RestoreSnapshotException {
566    admin.restoreSnapshot(snapshotName);
567  }
568
569  public void restoreSnapshot(String snapshotName, boolean takeFailSafeSnapshot, boolean restoreAcl)
570    throws IOException, RestoreSnapshotException {
571    admin.restoreSnapshot(snapshotName, takeFailSafeSnapshot, restoreAcl);
572  }
573
574  public Future<Void> cloneSnapshotAsync(String snapshotName, TableName tableName,
575    boolean restoreAcl, String customSFT)
576    throws IOException, TableExistsException, RestoreSnapshotException {
577    return admin.cloneSnapshotAsync(snapshotName, tableName, restoreAcl, customSFT);
578  }
579
580  public void execProcedure(String signature, String instance, Map<String, String> props)
581    throws IOException {
582    admin.execProcedure(signature, instance, props);
583  }
584
585  public byte[] execProcedureWithReturn(String signature, String instance,
586    Map<String, String> props) throws IOException {
587    return admin.execProcedureWithReturn(signature, instance, props);
588  }
589
590  public boolean isProcedureFinished(String signature, String instance, Map<String, String> props)
591    throws IOException {
592    return admin.isProcedureFinished(signature, instance, props);
593  }
594
595  public List<SnapshotDescription> listSnapshots() throws IOException {
596    return admin.listSnapshots();
597  }
598
599  public List<SnapshotDescription> listSnapshots(Pattern pattern) throws IOException {
600    return admin.listSnapshots(pattern);
601  }
602
603  public List<SnapshotDescription> listTableSnapshots(Pattern tableNamePattern,
604    Pattern snapshotNamePattern) throws IOException {
605    return admin.listTableSnapshots(tableNamePattern, snapshotNamePattern);
606  }
607
608  public void deleteSnapshot(String snapshotName) throws IOException {
609    admin.deleteSnapshot(snapshotName);
610  }
611
612  public void deleteSnapshots(Pattern pattern) throws IOException {
613    admin.deleteSnapshots(pattern);
614  }
615
616  public void deleteTableSnapshots(Pattern tableNamePattern, Pattern snapshotNamePattern)
617    throws IOException {
618    admin.deleteTableSnapshots(tableNamePattern, snapshotNamePattern);
619  }
620
621  public void setQuota(QuotaSettings quota) throws IOException {
622    admin.setQuota(quota);
623  }
624
625  public List<QuotaSettings> getQuota(QuotaFilter filter) throws IOException {
626    return admin.getQuota(filter);
627  }
628
629  public CoprocessorRpcChannel coprocessorService() {
630    return admin.coprocessorService();
631  }
632
633  public CoprocessorRpcChannel coprocessorService(ServerName serverName) {
634    return admin.coprocessorService(serverName);
635  }
636
637  public void updateConfiguration(ServerName server) throws IOException {
638    admin.updateConfiguration(server);
639  }
640
641  public void updateConfiguration() throws IOException {
642    admin.updateConfiguration();
643  }
644
645  public void updateConfiguration(String groupName) throws IOException {
646    admin.updateConfiguration(groupName);
647  }
648
649  public List<SecurityCapability> getSecurityCapabilities() throws IOException {
650    return admin.getSecurityCapabilities();
651  }
652
653  public boolean splitSwitch(boolean enabled, boolean synchronous) throws IOException {
654    return admin.splitSwitch(enabled, synchronous);
655  }
656
657  public boolean mergeSwitch(boolean enabled, boolean synchronous) throws IOException {
658    return admin.mergeSwitch(enabled, synchronous);
659  }
660
661  public boolean isSplitEnabled() throws IOException {
662    return admin.isSplitEnabled();
663  }
664
665  public boolean isMergeEnabled() throws IOException {
666    return admin.isMergeEnabled();
667  }
668
669  public Future<Void> addReplicationPeerAsync(String peerId, ReplicationPeerConfig peerConfig,
670    boolean enabled) throws IOException {
671    return admin.addReplicationPeerAsync(peerId, peerConfig, enabled);
672  }
673
674  public Future<Void> removeReplicationPeerAsync(String peerId) throws IOException {
675    return admin.removeReplicationPeerAsync(peerId);
676  }
677
678  public Future<Void> enableReplicationPeerAsync(String peerId) throws IOException {
679    return admin.enableReplicationPeerAsync(peerId);
680  }
681
682  public Future<Void> disableReplicationPeerAsync(String peerId) throws IOException {
683    return admin.disableReplicationPeerAsync(peerId);
684  }
685
686  public ReplicationPeerConfig getReplicationPeerConfig(String peerId) throws IOException {
687    return admin.getReplicationPeerConfig(peerId);
688  }
689
690  public Future<Void> updateReplicationPeerConfigAsync(String peerId,
691    ReplicationPeerConfig peerConfig) throws IOException {
692    return admin.updateReplicationPeerConfigAsync(peerId, peerConfig);
693  }
694
695  public List<ReplicationPeerDescription> listReplicationPeers() throws IOException {
696    return admin.listReplicationPeers();
697  }
698
699  public List<ReplicationPeerDescription> listReplicationPeers(Pattern pattern) throws IOException {
700    return admin.listReplicationPeers(pattern);
701  }
702
703  public Future<Void> transitReplicationPeerSyncReplicationStateAsync(String peerId,
704    SyncReplicationState state) throws IOException {
705    return admin.transitReplicationPeerSyncReplicationStateAsync(peerId, state);
706  }
707
708  @Override
709  public boolean isReplicationPeerEnabled(String peerId) throws IOException {
710    return admin.isReplicationPeerEnabled(peerId);
711  }
712
713  public void decommissionRegionServers(List<ServerName> servers, boolean offload)
714    throws IOException {
715    admin.decommissionRegionServers(servers, offload);
716  }
717
718  public List<ServerName> listDecommissionedRegionServers() throws IOException {
719    return admin.listDecommissionedRegionServers();
720  }
721
722  public void recommissionRegionServer(ServerName server, List<byte[]> encodedRegionNames)
723    throws IOException {
724    admin.recommissionRegionServer(server, encodedRegionNames);
725  }
726
727  public List<TableCFs> listReplicatedTableCFs() throws IOException {
728    return admin.listReplicatedTableCFs();
729  }
730
731  public void enableTableReplication(TableName tableName) throws IOException {
732    admin.enableTableReplication(tableName);
733  }
734
735  public void disableTableReplication(TableName tableName) throws IOException {
736    admin.disableTableReplication(tableName);
737  }
738
739  public void clearCompactionQueues(ServerName serverName, Set<String> queues)
740    throws IOException, InterruptedException {
741    admin.clearCompactionQueues(serverName, queues);
742  }
743
744  public List<ServerName> clearDeadServers(List<ServerName> servers) throws IOException {
745    return admin.clearDeadServers(servers);
746  }
747
748  public void cloneTableSchema(TableName tableName, TableName newTableName, boolean preserveSplits)
749    throws IOException {
750    admin.cloneTableSchema(tableName, newTableName, preserveSplits);
751  }
752
753  public boolean switchRpcThrottle(boolean enable) throws IOException {
754    return admin.switchRpcThrottle(enable);
755  }
756
757  public boolean isRpcThrottleEnabled() throws IOException {
758    return admin.isRpcThrottleEnabled();
759  }
760
761  public boolean exceedThrottleQuotaSwitch(boolean enable) throws IOException {
762    return admin.exceedThrottleQuotaSwitch(enable);
763  }
764
765  public Map<TableName, Long> getSpaceQuotaTableSizes() throws IOException {
766    return admin.getSpaceQuotaTableSizes();
767  }
768
769  public Map<TableName, ? extends SpaceQuotaSnapshotView>
770    getRegionServerSpaceQuotaSnapshots(ServerName serverName) throws IOException {
771    return admin.getRegionServerSpaceQuotaSnapshots(serverName);
772  }
773
774  public SpaceQuotaSnapshotView getCurrentSpaceQuotaSnapshot(String namespace) throws IOException {
775    return admin.getCurrentSpaceQuotaSnapshot(namespace);
776  }
777
778  public SpaceQuotaSnapshotView getCurrentSpaceQuotaSnapshot(TableName tableName)
779    throws IOException {
780    return admin.getCurrentSpaceQuotaSnapshot(tableName);
781  }
782
783  public void grant(UserPermission userPermission, boolean mergeExistingPermissions)
784    throws IOException {
785    admin.grant(userPermission, mergeExistingPermissions);
786  }
787
788  public void revoke(UserPermission userPermission) throws IOException {
789    admin.revoke(userPermission);
790  }
791
792  public List<UserPermission>
793    getUserPermissions(GetUserPermissionsRequest getUserPermissionsRequest) throws IOException {
794    return admin.getUserPermissions(getUserPermissionsRequest);
795  }
796
797  public List<Boolean> hasUserPermissions(String userName, List<Permission> permissions)
798    throws IOException {
799    return admin.hasUserPermissions(userName, permissions);
800  }
801
802  public boolean snapshotCleanupSwitch(boolean on, boolean synchronous) throws IOException {
803    return admin.snapshotCleanupSwitch(on, synchronous);
804  }
805
806  public boolean isSnapshotCleanupEnabled() throws IOException {
807    return admin.isSnapshotCleanupEnabled();
808  }
809
810  public void addRSGroup(String groupName) throws IOException {
811    admin.addRSGroup(groupName);
812    verify();
813  }
814
815  public RSGroupInfo getRSGroup(String groupName) throws IOException {
816    return admin.getRSGroup(groupName);
817  }
818
819  public RSGroupInfo getRSGroup(Address hostPort) throws IOException {
820    return admin.getRSGroup(hostPort);
821  }
822
823  public RSGroupInfo getRSGroup(TableName tableName) throws IOException {
824    return admin.getRSGroup(tableName);
825  }
826
827  public List<RSGroupInfo> listRSGroups() throws IOException {
828    return admin.listRSGroups();
829  }
830
831  @Override
832  public List<TableName> listTablesInRSGroup(String groupName) throws IOException {
833    return admin.listTablesInRSGroup(groupName);
834  }
835
836  @Override
837  public Pair<List<String>, List<TableName>>
838    getConfiguredNamespacesAndTablesInRSGroup(String groupName) throws IOException {
839    return admin.getConfiguredNamespacesAndTablesInRSGroup(groupName);
840  }
841
842  public void removeRSGroup(String groupName) throws IOException {
843    admin.removeRSGroup(groupName);
844    verify();
845  }
846
847  public void removeServersFromRSGroup(Set<Address> servers) throws IOException {
848    admin.removeServersFromRSGroup(servers);
849    verify();
850  }
851
852  public void moveServersToRSGroup(Set<Address> servers, String targetGroup) throws IOException {
853    admin.moveServersToRSGroup(servers, targetGroup);
854    verify();
855  }
856
857  public void setRSGroup(Set<TableName> tables, String groupName) throws IOException {
858    admin.setRSGroup(tables, groupName);
859    verify();
860  }
861
862  public BalanceResponse balanceRSGroup(String groupName, BalanceRequest request)
863    throws IOException {
864    return admin.balanceRSGroup(groupName, request);
865  }
866
867  @Override
868  public void renameRSGroup(String oldName, String newName) throws IOException {
869    admin.renameRSGroup(oldName, newName);
870    verify();
871  }
872
873  @Override
874  public void updateRSGroupConfig(String groupName, Map<String, String> configuration)
875    throws IOException {
876    admin.updateRSGroupConfig(groupName, configuration);
877    verify();
878  }
879
880  @Override
881  public List<LogEntry> getLogEntries(Set<ServerName> serverNames, String logType,
882    ServerType serverType, int limit, Map<String, Object> filterParams) throws IOException {
883    return admin.getLogEntries(serverNames, logType, serverType, limit, filterParams);
884  }
885
886  private void verify() throws IOException {
887    Map<String, RSGroupInfo> groupMap = Maps.newHashMap();
888    Set<RSGroupInfo> zList = Sets.newHashSet();
889    List<TableDescriptor> tds = new ArrayList<>();
890    try (Admin admin = conn.getAdmin()) {
891      tds.addAll(admin.listTableDescriptors());
892      tds.addAll(admin.listTableDescriptorsByNamespace(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME));
893    }
894    SortedSet<Address> lives = Sets.newTreeSet();
895    for (ServerName sn : conn.getAdmin().getClusterMetrics().getLiveServerMetrics().keySet()) {
896      lives.add(sn.getAddress());
897    }
898    for (ServerName sn : conn.getAdmin().listDecommissionedRegionServers()) {
899      lives.remove(sn.getAddress());
900    }
901    try (Table table = conn.getTable(RSGroupInfoManagerImpl.RSGROUP_TABLE_NAME);
902      ResultScanner scanner = table.getScanner(new Scan())) {
903      for (;;) {
904        Result result = scanner.next();
905        if (result == null) {
906          break;
907        }
908        RSGroupProtos.RSGroupInfo proto = RSGroupProtos.RSGroupInfo.parseFrom(result.getValue(
909          RSGroupInfoManagerImpl.META_FAMILY_BYTES, RSGroupInfoManagerImpl.META_QUALIFIER_BYTES));
910        RSGroupInfo rsGroupInfo = ProtobufUtil.toGroupInfo(proto);
911        groupMap.put(proto.getName(), RSGroupUtil.fillTables(rsGroupInfo, tds));
912        for (Address address : rsGroupInfo.getServers()) {
913          lives.remove(address);
914        }
915      }
916    }
917    SortedSet<TableName> tables = Sets.newTreeSet();
918    for (TableDescriptor td : conn.getAdmin().listTableDescriptors(Pattern.compile(".*"), true)) {
919      String groupName = td.getRegionServerGroup().orElse(RSGroupInfo.DEFAULT_GROUP);
920      if (groupName.equals(RSGroupInfo.DEFAULT_GROUP)) {
921        tables.add(td.getTableName());
922      }
923    }
924
925    groupMap.put(RSGroupInfo.DEFAULT_GROUP,
926      new RSGroupInfo(RSGroupInfo.DEFAULT_GROUP, lives, tables));
927    assertEquals(Sets.newHashSet(groupMap.values()), Sets.newHashSet(admin.listRSGroups()));
928    try {
929      String groupBasePath = ZNodePaths.joinZNode(zkw.getZNodePaths().baseZNode, "rsgroup");
930      for (String znode : ZKUtil.listChildrenNoWatch(zkw, groupBasePath)) {
931        byte[] data = ZKUtil.getData(zkw, ZNodePaths.joinZNode(groupBasePath, znode));
932        if (data.length > 0) {
933          ProtobufUtil.expectPBMagicPrefix(data);
934          ByteArrayInputStream bis =
935            new ByteArrayInputStream(data, ProtobufUtil.lengthOfPBMagic(), data.length);
936          RSGroupInfo rsGroupInfo =
937            ProtobufUtil.toGroupInfo(RSGroupProtos.RSGroupInfo.parseFrom(bis));
938          zList.add(RSGroupUtil.fillTables(rsGroupInfo, tds));
939        }
940      }
941      groupMap.remove(RSGroupInfo.DEFAULT_GROUP);
942      assertEquals(zList.size(), groupMap.size());
943      for (RSGroupInfo rsGroupInfo : zList) {
944        assertTrue(groupMap.get(rsGroupInfo.getName()).equals(rsGroupInfo));
945      }
946    } catch (KeeperException e) {
947      throw new IOException("ZK verification failed", e);
948    } catch (DeserializationException e) {
949      throw new IOException("ZK verification failed", e);
950    } catch (InterruptedException e) {
951      throw new IOException("ZK verification failed", e);
952    }
953  }
954
955  @Override
956  public List<Boolean> clearSlowLogResponses(Set<ServerName> serverNames) throws IOException {
957    return admin.clearSlowLogResponses(serverNames);
958  }
959
960  @Override
961  public Future<Void> modifyColumnFamilyStoreFileTrackerAsync(TableName tableName, byte[] family,
962    String dstSFT) throws IOException {
963    return admin.modifyColumnFamilyStoreFileTrackerAsync(tableName, family, dstSFT);
964  }
965
966  @Override
967  public Future<Void> modifyTableStoreFileTrackerAsync(TableName tableName, String dstSFT)
968    throws IOException {
969    return admin.modifyTableStoreFileTrackerAsync(tableName, dstSFT);
970  }
971
972  @Override
973  public void flushMasterStore() throws IOException {
974    admin.flushMasterStore();
975  }
976
977  @Override
978  public List<String> getCachedFilesList(ServerName serverName) throws IOException {
979    return admin.getCachedFilesList(serverName);
980  }
981
982  @Override
983  public boolean replicationPeerModificationSwitch(boolean on, boolean drainProcedures)
984    throws IOException {
985    return admin.replicationPeerModificationSwitch(on, drainProcedures);
986  }
987
988  @Override
989  public boolean isReplicationPeerModificationEnabled() throws IOException {
990    return admin.isReplicationPeerModificationEnabled();
991  }
992}