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 @Override 435 public Future<Void> reopenTableRegionsAsync(TableName tableName) throws IOException { 436 return admin.reopenTableRegionsAsync(tableName); 437 } 438 439 @Override 440 public Future<Void> reopenTableRegionsAsync(TableName tableName, List<RegionInfo> regions) 441 throws IOException { 442 return admin.reopenTableRegionsAsync(tableName, regions); 443 } 444 445 public void shutdown() throws IOException { 446 admin.shutdown(); 447 } 448 449 public void stopMaster() throws IOException { 450 admin.stopMaster(); 451 } 452 453 public boolean isMasterInMaintenanceMode() throws IOException { 454 return admin.isMasterInMaintenanceMode(); 455 } 456 457 public void stopRegionServer(String hostnamePort) throws IOException { 458 admin.stopRegionServer(hostnamePort); 459 } 460 461 public ClusterMetrics getClusterMetrics(EnumSet<Option> options) throws IOException { 462 return admin.getClusterMetrics(options); 463 } 464 465 public List<RegionMetrics> getRegionMetrics(ServerName serverName) throws IOException { 466 return admin.getRegionMetrics(serverName); 467 } 468 469 public List<RegionMetrics> getRegionMetrics(ServerName serverName, TableName tableName) 470 throws IOException { 471 return admin.getRegionMetrics(serverName, tableName); 472 } 473 474 public Configuration getConfiguration() { 475 return admin.getConfiguration(); 476 } 477 478 public Future<Void> createNamespaceAsync(NamespaceDescriptor descriptor) throws IOException { 479 return admin.createNamespaceAsync(descriptor); 480 } 481 482 public Future<Void> modifyNamespaceAsync(NamespaceDescriptor descriptor) throws IOException { 483 return admin.modifyNamespaceAsync(descriptor); 484 } 485 486 public Future<Void> deleteNamespaceAsync(String name) throws IOException { 487 return admin.deleteNamespaceAsync(name); 488 } 489 490 public NamespaceDescriptor getNamespaceDescriptor(String name) 491 throws NamespaceNotFoundException, IOException { 492 return admin.getNamespaceDescriptor(name); 493 } 494 495 public String[] listNamespaces() throws IOException { 496 return admin.listNamespaces(); 497 } 498 499 public NamespaceDescriptor[] listNamespaceDescriptors() throws IOException { 500 return admin.listNamespaceDescriptors(); 501 } 502 503 public List<TableDescriptor> listTableDescriptorsByNamespace(byte[] name) throws IOException { 504 return admin.listTableDescriptorsByNamespace(name); 505 } 506 507 public TableName[] listTableNamesByNamespace(String name) throws IOException { 508 return admin.listTableNamesByNamespace(name); 509 } 510 511 public List<RegionInfo> getRegions(TableName tableName) throws IOException { 512 return admin.getRegions(tableName); 513 } 514 515 public void close() { 516 admin.close(); 517 } 518 519 public List<TableDescriptor> listTableDescriptors(List<TableName> tableNames) throws IOException { 520 return admin.listTableDescriptors(tableNames); 521 } 522 523 public Future<Boolean> abortProcedureAsync(long procId, boolean mayInterruptIfRunning) 524 throws IOException { 525 return admin.abortProcedureAsync(procId, mayInterruptIfRunning); 526 } 527 528 public String getProcedures() throws IOException { 529 return admin.getProcedures(); 530 } 531 532 public String getLocks() throws IOException { 533 return admin.getLocks(); 534 } 535 536 public void rollWALWriter(ServerName serverName) throws IOException, FailedLogCloseException { 537 admin.rollWALWriter(serverName); 538 } 539 540 @Override 541 public Map<ServerName, Long> rollAllWALWriters() throws IOException { 542 return admin.rollAllWALWriters(); 543 } 544 545 public CompactionState getCompactionState(TableName tableName) throws IOException { 546 return admin.getCompactionState(tableName); 547 } 548 549 public CompactionState getCompactionState(TableName tableName, CompactType compactType) 550 throws IOException { 551 return admin.getCompactionState(tableName, compactType); 552 } 553 554 public CompactionState getCompactionStateForRegion(byte[] regionName) throws IOException { 555 return admin.getCompactionStateForRegion(regionName); 556 } 557 558 public long getLastMajorCompactionTimestamp(TableName tableName) throws IOException { 559 return admin.getLastMajorCompactionTimestamp(tableName); 560 } 561 562 public long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException { 563 return admin.getLastMajorCompactionTimestampForRegion(regionName); 564 } 565 566 public void snapshot(SnapshotDescription snapshot) 567 throws IOException, SnapshotCreationException, IllegalArgumentException { 568 admin.snapshot(snapshot); 569 } 570 571 public Future<Void> snapshotAsync(SnapshotDescription snapshot) 572 throws IOException, SnapshotCreationException { 573 return admin.snapshotAsync(snapshot); 574 } 575 576 public boolean isSnapshotFinished(SnapshotDescription snapshot) 577 throws IOException, HBaseSnapshotException, UnknownSnapshotException { 578 return admin.isSnapshotFinished(snapshot); 579 } 580 581 public void restoreSnapshot(String snapshotName) throws IOException, RestoreSnapshotException { 582 admin.restoreSnapshot(snapshotName); 583 } 584 585 public void restoreSnapshot(String snapshotName, boolean takeFailSafeSnapshot, boolean restoreAcl) 586 throws IOException, RestoreSnapshotException { 587 admin.restoreSnapshot(snapshotName, takeFailSafeSnapshot, restoreAcl); 588 } 589 590 public Future<Void> cloneSnapshotAsync(String snapshotName, TableName tableName, 591 boolean restoreAcl, String customSFT) 592 throws IOException, TableExistsException, RestoreSnapshotException { 593 return admin.cloneSnapshotAsync(snapshotName, tableName, restoreAcl, customSFT); 594 } 595 596 public void execProcedure(String signature, String instance, Map<String, String> props) 597 throws IOException { 598 admin.execProcedure(signature, instance, props); 599 } 600 601 public byte[] execProcedureWithReturn(String signature, String instance, 602 Map<String, String> props) throws IOException { 603 return admin.execProcedureWithReturn(signature, instance, props); 604 } 605 606 public boolean isProcedureFinished(String signature, String instance, Map<String, String> props) 607 throws IOException { 608 return admin.isProcedureFinished(signature, instance, props); 609 } 610 611 public List<SnapshotDescription> listSnapshots() throws IOException { 612 return admin.listSnapshots(); 613 } 614 615 public List<SnapshotDescription> listSnapshots(Pattern pattern) throws IOException { 616 return admin.listSnapshots(pattern); 617 } 618 619 public List<SnapshotDescription> listTableSnapshots(Pattern tableNamePattern, 620 Pattern snapshotNamePattern) throws IOException { 621 return admin.listTableSnapshots(tableNamePattern, snapshotNamePattern); 622 } 623 624 public void deleteSnapshot(String snapshotName) throws IOException { 625 admin.deleteSnapshot(snapshotName); 626 } 627 628 public void deleteSnapshots(Pattern pattern) throws IOException { 629 admin.deleteSnapshots(pattern); 630 } 631 632 public void deleteTableSnapshots(Pattern tableNamePattern, Pattern snapshotNamePattern) 633 throws IOException { 634 admin.deleteTableSnapshots(tableNamePattern, snapshotNamePattern); 635 } 636 637 public void setQuota(QuotaSettings quota) throws IOException { 638 admin.setQuota(quota); 639 } 640 641 public List<QuotaSettings> getQuota(QuotaFilter filter) throws IOException { 642 return admin.getQuota(filter); 643 } 644 645 public CoprocessorRpcChannel coprocessorService() { 646 return admin.coprocessorService(); 647 } 648 649 public CoprocessorRpcChannel coprocessorService(ServerName serverName) { 650 return admin.coprocessorService(serverName); 651 } 652 653 public void updateConfiguration(ServerName server) throws IOException { 654 admin.updateConfiguration(server); 655 } 656 657 public void updateConfiguration() throws IOException { 658 admin.updateConfiguration(); 659 } 660 661 public void updateConfiguration(String groupName) throws IOException { 662 admin.updateConfiguration(groupName); 663 } 664 665 public List<SecurityCapability> getSecurityCapabilities() throws IOException { 666 return admin.getSecurityCapabilities(); 667 } 668 669 public boolean splitSwitch(boolean enabled, boolean synchronous) throws IOException { 670 return admin.splitSwitch(enabled, synchronous); 671 } 672 673 public boolean mergeSwitch(boolean enabled, boolean synchronous) throws IOException { 674 return admin.mergeSwitch(enabled, synchronous); 675 } 676 677 public boolean isSplitEnabled() throws IOException { 678 return admin.isSplitEnabled(); 679 } 680 681 public boolean isMergeEnabled() throws IOException { 682 return admin.isMergeEnabled(); 683 } 684 685 public Future<Void> addReplicationPeerAsync(String peerId, ReplicationPeerConfig peerConfig, 686 boolean enabled) throws IOException { 687 return admin.addReplicationPeerAsync(peerId, peerConfig, enabled); 688 } 689 690 public Future<Void> removeReplicationPeerAsync(String peerId) throws IOException { 691 return admin.removeReplicationPeerAsync(peerId); 692 } 693 694 public Future<Void> enableReplicationPeerAsync(String peerId) throws IOException { 695 return admin.enableReplicationPeerAsync(peerId); 696 } 697 698 public Future<Void> disableReplicationPeerAsync(String peerId) throws IOException { 699 return admin.disableReplicationPeerAsync(peerId); 700 } 701 702 public ReplicationPeerConfig getReplicationPeerConfig(String peerId) throws IOException { 703 return admin.getReplicationPeerConfig(peerId); 704 } 705 706 public Future<Void> updateReplicationPeerConfigAsync(String peerId, 707 ReplicationPeerConfig peerConfig) throws IOException { 708 return admin.updateReplicationPeerConfigAsync(peerId, peerConfig); 709 } 710 711 public List<ReplicationPeerDescription> listReplicationPeers() throws IOException { 712 return admin.listReplicationPeers(); 713 } 714 715 public List<ReplicationPeerDescription> listReplicationPeers(Pattern pattern) throws IOException { 716 return admin.listReplicationPeers(pattern); 717 } 718 719 public Future<Void> transitReplicationPeerSyncReplicationStateAsync(String peerId, 720 SyncReplicationState state) throws IOException { 721 return admin.transitReplicationPeerSyncReplicationStateAsync(peerId, state); 722 } 723 724 @Override 725 public boolean isReplicationPeerEnabled(String peerId) throws IOException { 726 return admin.isReplicationPeerEnabled(peerId); 727 } 728 729 public void decommissionRegionServers(List<ServerName> servers, boolean offload) 730 throws IOException { 731 admin.decommissionRegionServers(servers, offload); 732 } 733 734 public List<ServerName> listDecommissionedRegionServers() throws IOException { 735 return admin.listDecommissionedRegionServers(); 736 } 737 738 public void recommissionRegionServer(ServerName server, List<byte[]> encodedRegionNames) 739 throws IOException { 740 admin.recommissionRegionServer(server, encodedRegionNames); 741 } 742 743 public List<TableCFs> listReplicatedTableCFs() throws IOException { 744 return admin.listReplicatedTableCFs(); 745 } 746 747 public void enableTableReplication(TableName tableName) throws IOException { 748 admin.enableTableReplication(tableName); 749 } 750 751 public void disableTableReplication(TableName tableName) throws IOException { 752 admin.disableTableReplication(tableName); 753 } 754 755 public void clearCompactionQueues(ServerName serverName, Set<String> queues) 756 throws IOException, InterruptedException { 757 admin.clearCompactionQueues(serverName, queues); 758 } 759 760 public List<ServerName> clearDeadServers(List<ServerName> servers) throws IOException { 761 return admin.clearDeadServers(servers); 762 } 763 764 public void cloneTableSchema(TableName tableName, TableName newTableName, boolean preserveSplits) 765 throws IOException { 766 admin.cloneTableSchema(tableName, newTableName, preserveSplits); 767 } 768 769 public boolean switchRpcThrottle(boolean enable) throws IOException { 770 return admin.switchRpcThrottle(enable); 771 } 772 773 public boolean isRpcThrottleEnabled() throws IOException { 774 return admin.isRpcThrottleEnabled(); 775 } 776 777 public boolean exceedThrottleQuotaSwitch(boolean enable) throws IOException { 778 return admin.exceedThrottleQuotaSwitch(enable); 779 } 780 781 public Map<TableName, Long> getSpaceQuotaTableSizes() throws IOException { 782 return admin.getSpaceQuotaTableSizes(); 783 } 784 785 public Map<TableName, ? extends SpaceQuotaSnapshotView> 786 getRegionServerSpaceQuotaSnapshots(ServerName serverName) throws IOException { 787 return admin.getRegionServerSpaceQuotaSnapshots(serverName); 788 } 789 790 public SpaceQuotaSnapshotView getCurrentSpaceQuotaSnapshot(String namespace) throws IOException { 791 return admin.getCurrentSpaceQuotaSnapshot(namespace); 792 } 793 794 public SpaceQuotaSnapshotView getCurrentSpaceQuotaSnapshot(TableName tableName) 795 throws IOException { 796 return admin.getCurrentSpaceQuotaSnapshot(tableName); 797 } 798 799 public void grant(UserPermission userPermission, boolean mergeExistingPermissions) 800 throws IOException { 801 admin.grant(userPermission, mergeExistingPermissions); 802 } 803 804 public void revoke(UserPermission userPermission) throws IOException { 805 admin.revoke(userPermission); 806 } 807 808 public List<UserPermission> 809 getUserPermissions(GetUserPermissionsRequest getUserPermissionsRequest) throws IOException { 810 return admin.getUserPermissions(getUserPermissionsRequest); 811 } 812 813 public List<Boolean> hasUserPermissions(String userName, List<Permission> permissions) 814 throws IOException { 815 return admin.hasUserPermissions(userName, permissions); 816 } 817 818 public boolean snapshotCleanupSwitch(boolean on, boolean synchronous) throws IOException { 819 return admin.snapshotCleanupSwitch(on, synchronous); 820 } 821 822 public boolean isSnapshotCleanupEnabled() throws IOException { 823 return admin.isSnapshotCleanupEnabled(); 824 } 825 826 public void addRSGroup(String groupName) throws IOException { 827 admin.addRSGroup(groupName); 828 verify(); 829 } 830 831 public RSGroupInfo getRSGroup(String groupName) throws IOException { 832 return admin.getRSGroup(groupName); 833 } 834 835 public RSGroupInfo getRSGroup(Address hostPort) throws IOException { 836 return admin.getRSGroup(hostPort); 837 } 838 839 public RSGroupInfo getRSGroup(TableName tableName) throws IOException { 840 return admin.getRSGroup(tableName); 841 } 842 843 public List<RSGroupInfo> listRSGroups() throws IOException { 844 return admin.listRSGroups(); 845 } 846 847 @Override 848 public List<TableName> listTablesInRSGroup(String groupName) throws IOException { 849 return admin.listTablesInRSGroup(groupName); 850 } 851 852 @Override 853 public Pair<List<String>, List<TableName>> 854 getConfiguredNamespacesAndTablesInRSGroup(String groupName) throws IOException { 855 return admin.getConfiguredNamespacesAndTablesInRSGroup(groupName); 856 } 857 858 public void removeRSGroup(String groupName) throws IOException { 859 admin.removeRSGroup(groupName); 860 verify(); 861 } 862 863 public void removeServersFromRSGroup(Set<Address> servers) throws IOException { 864 admin.removeServersFromRSGroup(servers); 865 verify(); 866 } 867 868 public void moveServersToRSGroup(Set<Address> servers, String targetGroup) throws IOException { 869 admin.moveServersToRSGroup(servers, targetGroup); 870 verify(); 871 } 872 873 public void setRSGroup(Set<TableName> tables, String groupName) throws IOException { 874 admin.setRSGroup(tables, groupName); 875 verify(); 876 } 877 878 public BalanceResponse balanceRSGroup(String groupName, BalanceRequest request) 879 throws IOException { 880 return admin.balanceRSGroup(groupName, request); 881 } 882 883 @Override 884 public void renameRSGroup(String oldName, String newName) throws IOException { 885 admin.renameRSGroup(oldName, newName); 886 verify(); 887 } 888 889 @Override 890 public void updateRSGroupConfig(String groupName, Map<String, String> configuration) 891 throws IOException { 892 admin.updateRSGroupConfig(groupName, configuration); 893 verify(); 894 } 895 896 @Override 897 public List<LogEntry> getLogEntries(Set<ServerName> serverNames, String logType, 898 ServerType serverType, int limit, Map<String, Object> filterParams) throws IOException { 899 return admin.getLogEntries(serverNames, logType, serverType, limit, filterParams); 900 } 901 902 private void verify() throws IOException { 903 Map<String, RSGroupInfo> groupMap = Maps.newHashMap(); 904 Set<RSGroupInfo> zList = Sets.newHashSet(); 905 List<TableDescriptor> tds = new ArrayList<>(); 906 try (Admin admin = conn.getAdmin()) { 907 tds.addAll(admin.listTableDescriptors()); 908 tds.addAll(admin.listTableDescriptorsByNamespace(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME)); 909 } 910 SortedSet<Address> lives = Sets.newTreeSet(); 911 for (ServerName sn : conn.getAdmin().getClusterMetrics().getLiveServerMetrics().keySet()) { 912 lives.add(sn.getAddress()); 913 } 914 for (ServerName sn : conn.getAdmin().listDecommissionedRegionServers()) { 915 lives.remove(sn.getAddress()); 916 } 917 try (Table table = conn.getTable(RSGroupInfoManagerImpl.RSGROUP_TABLE_NAME); 918 ResultScanner scanner = table.getScanner(new Scan())) { 919 for (;;) { 920 Result result = scanner.next(); 921 if (result == null) { 922 break; 923 } 924 RSGroupProtos.RSGroupInfo proto = RSGroupProtos.RSGroupInfo.parseFrom(result.getValue( 925 RSGroupInfoManagerImpl.META_FAMILY_BYTES, RSGroupInfoManagerImpl.META_QUALIFIER_BYTES)); 926 RSGroupInfo rsGroupInfo = ProtobufUtil.toGroupInfo(proto); 927 groupMap.put(proto.getName(), RSGroupUtil.fillTables(rsGroupInfo, tds)); 928 for (Address address : rsGroupInfo.getServers()) { 929 lives.remove(address); 930 } 931 } 932 } 933 SortedSet<TableName> tables = Sets.newTreeSet(); 934 for (TableDescriptor td : conn.getAdmin().listTableDescriptors(Pattern.compile(".*"), true)) { 935 String groupName = td.getRegionServerGroup().orElse(RSGroupInfo.DEFAULT_GROUP); 936 if (groupName.equals(RSGroupInfo.DEFAULT_GROUP)) { 937 tables.add(td.getTableName()); 938 } 939 } 940 941 groupMap.put(RSGroupInfo.DEFAULT_GROUP, 942 new RSGroupInfo(RSGroupInfo.DEFAULT_GROUP, lives, tables)); 943 assertEquals(Sets.newHashSet(groupMap.values()), Sets.newHashSet(admin.listRSGroups())); 944 try { 945 String groupBasePath = ZNodePaths.joinZNode(zkw.getZNodePaths().baseZNode, "rsgroup"); 946 for (String znode : ZKUtil.listChildrenNoWatch(zkw, groupBasePath)) { 947 byte[] data = ZKUtil.getData(zkw, ZNodePaths.joinZNode(groupBasePath, znode)); 948 if (data.length > 0) { 949 ProtobufUtil.expectPBMagicPrefix(data); 950 ByteArrayInputStream bis = 951 new ByteArrayInputStream(data, ProtobufUtil.lengthOfPBMagic(), data.length); 952 RSGroupInfo rsGroupInfo = 953 ProtobufUtil.toGroupInfo(RSGroupProtos.RSGroupInfo.parseFrom(bis)); 954 zList.add(RSGroupUtil.fillTables(rsGroupInfo, tds)); 955 } 956 } 957 groupMap.remove(RSGroupInfo.DEFAULT_GROUP); 958 assertEquals(zList.size(), groupMap.size()); 959 for (RSGroupInfo rsGroupInfo : zList) { 960 assertTrue(groupMap.get(rsGroupInfo.getName()).equals(rsGroupInfo)); 961 } 962 } catch (KeeperException e) { 963 throw new IOException("ZK verification failed", e); 964 } catch (DeserializationException e) { 965 throw new IOException("ZK verification failed", e); 966 } catch (InterruptedException e) { 967 throw new IOException("ZK verification failed", e); 968 } 969 } 970 971 @Override 972 public List<Boolean> clearSlowLogResponses(Set<ServerName> serverNames) throws IOException { 973 return admin.clearSlowLogResponses(serverNames); 974 } 975 976 @Override 977 public Future<Void> modifyColumnFamilyStoreFileTrackerAsync(TableName tableName, byte[] family, 978 String dstSFT) throws IOException { 979 return admin.modifyColumnFamilyStoreFileTrackerAsync(tableName, family, dstSFT); 980 } 981 982 @Override 983 public Future<Void> modifyTableStoreFileTrackerAsync(TableName tableName, String dstSFT) 984 throws IOException { 985 return admin.modifyTableStoreFileTrackerAsync(tableName, dstSFT); 986 } 987 988 @Override 989 public void flushMasterStore() throws IOException { 990 admin.flushMasterStore(); 991 } 992 993 @Override 994 public List<String> getCachedFilesList(ServerName serverName) throws IOException { 995 return admin.getCachedFilesList(serverName); 996 } 997 998 @Override 999 public void restoreBackupSystemTable(String snapshotName) throws IOException { 1000 admin.restoreBackupSystemTable(snapshotName); 1001 } 1002 1003 @Override 1004 public boolean replicationPeerModificationSwitch(boolean on, boolean drainProcedures) 1005 throws IOException { 1006 return admin.replicationPeerModificationSwitch(on, drainProcedures); 1007 } 1008 1009 @Override 1010 public boolean isReplicationPeerModificationEnabled() throws IOException { 1011 return admin.isReplicationPeerModificationEnabled(); 1012 } 1013}