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.client;
019
020import static org.apache.hadoop.hbase.client.ConnectionUtils.setCoprocessorError;
021import static org.apache.hadoop.hbase.util.FutureUtils.get;
022
023import java.io.IOException;
024import java.util.Arrays;
025import java.util.EnumSet;
026import java.util.List;
027import java.util.Map;
028import java.util.Set;
029import java.util.concurrent.Future;
030import java.util.regex.Pattern;
031import org.apache.hadoop.conf.Configuration;
032import org.apache.hadoop.hbase.CacheEvictionStats;
033import org.apache.hadoop.hbase.ClusterMetrics;
034import org.apache.hadoop.hbase.ClusterMetrics.Option;
035import org.apache.hadoop.hbase.HConstants;
036import org.apache.hadoop.hbase.NamespaceDescriptor;
037import org.apache.hadoop.hbase.NamespaceNotFoundException;
038import org.apache.hadoop.hbase.RegionMetrics;
039import org.apache.hadoop.hbase.ServerName;
040import org.apache.hadoop.hbase.TableExistsException;
041import org.apache.hadoop.hbase.TableName;
042import org.apache.hadoop.hbase.TableNotFoundException;
043import org.apache.hadoop.hbase.client.replication.TableCFs;
044import org.apache.hadoop.hbase.client.security.SecurityCapability;
045import org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel;
046import org.apache.hadoop.hbase.net.Address;
047import org.apache.hadoop.hbase.quotas.QuotaFilter;
048import org.apache.hadoop.hbase.quotas.QuotaSettings;
049import org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshotView;
050import org.apache.hadoop.hbase.regionserver.wal.FailedLogCloseException;
051import org.apache.hadoop.hbase.replication.ReplicationPeerConfig;
052import org.apache.hadoop.hbase.replication.ReplicationPeerDescription;
053import org.apache.hadoop.hbase.replication.SyncReplicationState;
054import org.apache.hadoop.hbase.rsgroup.RSGroupInfo;
055import org.apache.hadoop.hbase.security.access.GetUserPermissionsRequest;
056import org.apache.hadoop.hbase.security.access.Permission;
057import org.apache.hadoop.hbase.security.access.UserPermission;
058import org.apache.hadoop.hbase.snapshot.HBaseSnapshotException;
059import org.apache.hadoop.hbase.snapshot.RestoreSnapshotException;
060import org.apache.hadoop.hbase.snapshot.SnapshotCreationException;
061import org.apache.hadoop.hbase.snapshot.UnknownSnapshotException;
062import org.apache.hadoop.hbase.util.Bytes;
063import org.apache.hadoop.hbase.util.Pair;
064import org.apache.yetus.audience.InterfaceAudience;
065import org.slf4j.Logger;
066import org.slf4j.LoggerFactory;
067
068import org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.MethodDescriptor;
069import org.apache.hbase.thirdparty.com.google.protobuf.Message;
070import org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback;
071import org.apache.hbase.thirdparty.com.google.protobuf.RpcChannel;
072import org.apache.hbase.thirdparty.com.google.protobuf.RpcController;
073import org.apache.hbase.thirdparty.com.google.protobuf.ServiceException;
074
075/**
076 * The {@link Admin} implementation which is based on an {@link AsyncAdmin}.
077 */
078@InterfaceAudience.Private
079class AdminOverAsyncAdmin implements Admin {
080
081  private static final Logger LOG = LoggerFactory.getLogger(AdminOverAsyncAdmin.class);
082
083  private volatile boolean aborted = false;
084
085  private final Connection conn;
086
087  private final RawAsyncHBaseAdmin admin;
088
089  private final int operationTimeout;
090
091  private final int syncWaitTimeout;
092
093  public AdminOverAsyncAdmin(Connection conn, RawAsyncHBaseAdmin admin) {
094    this.conn = conn;
095    this.admin = admin;
096    this.operationTimeout = conn.getConfiguration().getInt(
097      HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT);
098    this.syncWaitTimeout =
099      conn.getConfiguration().getInt("hbase.client.sync.wait.timeout.msec", 10 * 60000); // 10min
100  }
101
102  @Override
103  public int getOperationTimeout() {
104    return operationTimeout;
105  }
106
107  @Override
108  public int getSyncWaitTimeout() {
109    return syncWaitTimeout;
110  }
111
112  @Override
113  public void abort(String why, Throwable e) {
114    LOG.warn("Aborting becasue of {}", why, e);
115    this.aborted = true;
116  }
117
118  @Override
119  public boolean isAborted() {
120    return aborted;
121  }
122
123  @Override
124  public Connection getConnection() {
125    return conn;
126  }
127
128  @Override
129  public boolean tableExists(TableName tableName) throws IOException {
130    return get(admin.tableExists(tableName));
131  }
132
133  @Override
134  public List<TableDescriptor> listTableDescriptors() throws IOException {
135    return get(admin.listTableDescriptors());
136  }
137
138  @Override
139  public List<TableDescriptor> listTableDescriptors(boolean includeSysTables)
140      throws IOException {
141    return get(admin.listTableDescriptors(includeSysTables));
142  }
143
144  @Override
145  public List<TableDescriptor> listTableDescriptors(Pattern pattern, boolean includeSysTables)
146      throws IOException {
147    return get(admin.listTableDescriptors(pattern, includeSysTables));
148  }
149
150  @Override
151  public TableName[] listTableNames() throws IOException {
152    return get(admin.listTableNames()).toArray(new TableName[0]);
153  }
154
155  @Override
156  public TableName[] listTableNames(Pattern pattern, boolean includeSysTables) throws IOException {
157    return get(admin.listTableNames(pattern, includeSysTables)).toArray(new TableName[0]);
158  }
159
160  @Override
161  public TableDescriptor getDescriptor(TableName tableName)
162      throws TableNotFoundException, IOException {
163    return get(admin.getDescriptor(tableName));
164  }
165
166  @Override
167  public void createTable(TableDescriptor desc, byte[] startKey, byte[] endKey, int numRegions)
168      throws IOException {
169    get(admin.createTable(desc, startKey, endKey, numRegions));
170  }
171
172  @Override
173  public Future<Void> createTableAsync(TableDescriptor desc) throws IOException {
174    return admin.createTable(desc);
175  }
176
177  @Override
178  public Future<Void> createTableAsync(TableDescriptor desc, byte[][] splitKeys)
179      throws IOException {
180    return admin.createTable(desc, splitKeys);
181  }
182
183  @Override
184  public Future<Void> deleteTableAsync(TableName tableName) throws IOException {
185    return admin.deleteTable(tableName);
186  }
187
188  @Override
189  public Future<Void> truncateTableAsync(TableName tableName, boolean preserveSplits)
190      throws IOException {
191    return admin.truncateTable(tableName, preserveSplits);
192  }
193
194  @Override
195  public Future<Void> enableTableAsync(TableName tableName) throws IOException {
196    return admin.enableTable(tableName);
197  }
198
199  @Override
200  public Future<Void> disableTableAsync(TableName tableName) throws IOException {
201    return admin.disableTable(tableName);
202  }
203
204  @Override
205  public boolean isTableEnabled(TableName tableName) throws IOException {
206    return get(admin.isTableEnabled(tableName));
207  }
208
209  @Override
210  public boolean isTableDisabled(TableName tableName) throws IOException {
211    return get(admin.isTableDisabled(tableName));
212  }
213
214  @Override
215  public boolean isTableAvailable(TableName tableName) throws IOException {
216    return get(admin.isTableAvailable(tableName));
217  }
218
219  @Override
220  public Future<Void> addColumnFamilyAsync(TableName tableName, ColumnFamilyDescriptor columnFamily)
221      throws IOException {
222    return admin.addColumnFamily(tableName, columnFamily);
223  }
224
225  @Override
226  public Future<Void> deleteColumnFamilyAsync(TableName tableName, byte[] columnFamily)
227      throws IOException {
228    return admin.deleteColumnFamily(tableName, columnFamily);
229  }
230
231  @Override
232  public Future<Void> modifyColumnFamilyAsync(TableName tableName,
233      ColumnFamilyDescriptor columnFamily) throws IOException {
234    return admin.modifyColumnFamily(tableName, columnFamily);
235  }
236
237  @Override
238  public List<RegionInfo> getRegions(ServerName serverName) throws IOException {
239    return get(admin.getRegions(serverName));
240  }
241
242  @Override
243  public void flush(TableName tableName) throws IOException {
244    get(admin.flush(tableName));
245  }
246
247  @Override
248  public void flushRegion(byte[] regionName) throws IOException {
249    get(admin.flushRegion(regionName));
250  }
251
252  @Override
253  public void flushRegion(byte[] regionName, byte[] columnFamily) throws IOException {
254    get(admin.flushRegion(regionName, columnFamily));
255  }
256
257  @Override
258  public void flushRegionServer(ServerName serverName) throws IOException {
259    get(admin.flushRegionServer(serverName));
260  }
261
262  @Override
263  public void compact(TableName tableName) throws IOException {
264    get(admin.compact(tableName));
265  }
266
267  @Override
268  public void compactRegion(byte[] regionName) throws IOException {
269    get(admin.compactRegion(regionName));
270  }
271
272  @Override
273  public void compact(TableName tableName, byte[] columnFamily) throws IOException {
274    get(admin.compact(tableName, columnFamily));
275  }
276
277  @Override
278  public void compactRegion(byte[] regionName, byte[] columnFamily) throws IOException {
279    get(admin.compactRegion(regionName, columnFamily));
280  }
281
282  @Override
283  public void compact(TableName tableName, CompactType compactType)
284      throws IOException, InterruptedException {
285    get(admin.compact(tableName, compactType));
286  }
287
288  @Override
289  public void compact(TableName tableName, byte[] columnFamily, CompactType compactType)
290      throws IOException, InterruptedException {
291    get(admin.compact(tableName, columnFamily, compactType));
292  }
293
294  @Override
295  public void majorCompact(TableName tableName) throws IOException {
296    get(admin.majorCompact(tableName));
297  }
298
299  @Override
300  public void majorCompactRegion(byte[] regionName) throws IOException {
301    get(admin.majorCompactRegion(regionName));
302  }
303
304  @Override
305  public void majorCompact(TableName tableName, byte[] columnFamily) throws IOException {
306    get(admin.majorCompact(tableName, columnFamily));
307  }
308
309  @Override
310  public void majorCompactRegion(byte[] regionName, byte[] columnFamily) throws IOException {
311    get(admin.majorCompactRegion(regionName, columnFamily));
312  }
313
314  @Override
315  public void majorCompact(TableName tableName, CompactType compactType)
316      throws IOException, InterruptedException {
317    get(admin.majorCompact(tableName, compactType));
318  }
319
320  @Override
321  public void majorCompact(TableName tableName, byte[] columnFamily, CompactType compactType)
322      throws IOException, InterruptedException {
323    get(admin.majorCompact(tableName, columnFamily, compactType));
324  }
325
326  @Override
327  public Map<ServerName, Boolean> compactionSwitch(boolean switchState,
328      List<String> serverNamesList) throws IOException {
329    return get(admin.compactionSwitch(switchState, serverNamesList));
330  }
331
332  @Override
333  public void compactRegionServer(ServerName serverName) throws IOException {
334    get(admin.compactRegionServer(serverName));
335  }
336
337  @Override
338  public void majorCompactRegionServer(ServerName serverName) throws IOException {
339    get(admin.majorCompactRegionServer(serverName));
340  }
341
342  @Override
343  public void move(byte[] encodedRegionName) throws IOException {
344    get(admin.move(encodedRegionName));
345  }
346
347  @Override
348  public void move(byte[] encodedRegionName, ServerName destServerName) throws IOException {
349    get(admin.move(encodedRegionName, destServerName));
350  }
351
352  @Override
353  public void assign(byte[] regionName) throws IOException {
354    get(admin.assign(regionName));
355  }
356
357  @Override
358  public void unassign(byte[] regionName, boolean force) throws IOException {
359    get(admin.unassign(regionName, force));
360  }
361
362  @Override
363  public void offline(byte[] regionName) throws IOException {
364    get(admin.offline(regionName));
365  }
366
367  @Override
368  public boolean balancerSwitch(boolean onOrOff, boolean synchronous) throws IOException {
369    return get(admin.balancerSwitch(onOrOff, synchronous));
370  }
371
372  @Override
373  public boolean balance() throws IOException {
374    return get(admin.balance());
375  }
376
377  @Override
378  public boolean balance(boolean force) throws IOException {
379    return get(admin.balance(force));
380  }
381
382  @Override
383  public boolean isBalancerEnabled() throws IOException {
384    return get(admin.isBalancerEnabled());
385  }
386
387  @Override
388  public CacheEvictionStats clearBlockCache(TableName tableName) throws IOException {
389    return get(admin.clearBlockCache(tableName));
390  }
391
392  @Override
393  public boolean normalize() throws IOException {
394    return get(admin.normalize());
395  }
396
397  @Override
398  public boolean isNormalizerEnabled() throws IOException {
399    return get(admin.isNormalizerEnabled());
400  }
401
402  @Override
403  public boolean normalizerSwitch(boolean on) throws IOException {
404    return get(admin.normalizerSwitch(on));
405  }
406
407  @Override
408  public boolean catalogJanitorSwitch(boolean onOrOff) throws IOException {
409    return get(admin.catalogJanitorSwitch(onOrOff));
410  }
411
412  @Override
413  public int runCatalogJanitor() throws IOException {
414    return get(admin.runCatalogJanitor());
415  }
416
417  @Override
418  public boolean isCatalogJanitorEnabled() throws IOException {
419    return get(admin.isCatalogJanitorEnabled());
420  }
421
422  @Override
423  public boolean cleanerChoreSwitch(boolean onOrOff) throws IOException {
424    return get(admin.cleanerChoreSwitch(onOrOff));
425  }
426
427  @Override
428  public boolean runCleanerChore() throws IOException {
429    return get(admin.runCleanerChore());
430  }
431
432  @Override
433  public boolean isCleanerChoreEnabled() throws IOException {
434    return get(admin.isCleanerChoreEnabled());
435  }
436
437  @Override
438  public Future<Void> mergeRegionsAsync(byte[][] nameOfRegionsToMerge, boolean forcible)
439      throws IOException {
440    return admin.mergeRegions(Arrays.asList(nameOfRegionsToMerge), forcible);
441  }
442
443  @Override
444  public void split(TableName tableName) throws IOException {
445    get(admin.split(tableName));
446  }
447
448  @Override
449  public void split(TableName tableName, byte[] splitPoint) throws IOException {
450    get(admin.split(tableName, splitPoint));
451  }
452
453  @Override
454  public Future<Void> splitRegionAsync(byte[] regionName) throws IOException {
455    return admin.splitRegion(regionName);
456  }
457
458  @Override
459  public Future<Void> splitRegionAsync(byte[] regionName, byte[] splitPoint) throws IOException {
460    return admin.splitRegion(regionName, splitPoint);
461  }
462
463  @Override
464  public Future<Void> modifyTableAsync(TableDescriptor td) throws IOException {
465    return admin.modifyTable(td);
466  }
467
468  @Override
469  public void shutdown() throws IOException {
470    get(admin.shutdown());
471  }
472
473  @Override
474  public void stopMaster() throws IOException {
475    get(admin.stopMaster());
476  }
477
478  @Override
479  public boolean isMasterInMaintenanceMode() throws IOException {
480    return get(admin.isMasterInMaintenanceMode());
481  }
482
483  @Override
484  public void stopRegionServer(String hostnamePort) throws IOException {
485    get(admin.stopRegionServer(ServerName.valueOf(hostnamePort, 0)));
486  }
487
488  @Override
489  public ClusterMetrics getClusterMetrics(EnumSet<Option> options) throws IOException {
490    return get(admin.getClusterMetrics(options));
491  }
492
493  @Override
494  public List<RegionMetrics> getRegionMetrics(ServerName serverName) throws IOException {
495    return get(admin.getRegionMetrics(serverName));
496  }
497
498  @Override
499  public List<RegionMetrics> getRegionMetrics(ServerName serverName, TableName tableName)
500      throws IOException {
501    return get(admin.getRegionMetrics(serverName, tableName));
502  }
503
504  @Override
505  public Configuration getConfiguration() {
506    return conn.getConfiguration();
507  }
508
509  @Override
510  public Future<Void> createNamespaceAsync(NamespaceDescriptor descriptor) throws IOException {
511    return admin.createNamespace(descriptor);
512  }
513
514  @Override
515  public Future<Void> modifyNamespaceAsync(NamespaceDescriptor descriptor) throws IOException {
516    return admin.modifyNamespace(descriptor);
517  }
518
519  @Override
520  public Future<Void> deleteNamespaceAsync(String name) throws IOException {
521    return admin.deleteNamespace(name);
522  }
523
524  @Override
525  public NamespaceDescriptor getNamespaceDescriptor(String name)
526      throws NamespaceNotFoundException, IOException {
527    return get(admin.getNamespaceDescriptor(name));
528  }
529
530  @Override
531  public String[] listNamespaces() throws IOException {
532    return get(admin.listNamespaces()).toArray(new String[0]);
533  }
534
535  @Override
536  public NamespaceDescriptor[] listNamespaceDescriptors() throws IOException {
537    return get(admin.listNamespaceDescriptors()).toArray(new NamespaceDescriptor[0]);
538  }
539
540  @Override
541  public List<TableDescriptor> listTableDescriptorsByNamespace(byte[] name) throws IOException {
542    return get(admin.listTableDescriptorsByNamespace(Bytes.toString(name)));
543  }
544
545  @Override
546  public TableName[] listTableNamesByNamespace(String name) throws IOException {
547    return get(admin.listTableNamesByNamespace(name)).toArray(new TableName[0]);
548  }
549
550  @Override
551  public List<RegionInfo> getRegions(TableName tableName) throws IOException {
552    return get(admin.getRegions(tableName));
553  }
554
555  @Override
556  public void close() {
557    // do nothing, AsyncAdmin is not a Closeable.
558  }
559
560  @Override
561  public List<TableDescriptor> listTableDescriptors(List<TableName> tableNames) throws IOException {
562    return get(admin.listTableDescriptors(tableNames));
563  }
564
565  @Override
566  public Future<Boolean> abortProcedureAsync(long procId, boolean mayInterruptIfRunning)
567      throws IOException {
568    return admin.abortProcedure(procId, mayInterruptIfRunning);
569  }
570
571  @Override
572  public String getProcedures() throws IOException {
573    return get(admin.getProcedures());
574  }
575
576  @Override
577  public String getLocks() throws IOException {
578    return get(admin.getLocks());
579  }
580
581  @Override
582  public void rollWALWriter(ServerName serverName) throws IOException, FailedLogCloseException {
583    get(admin.rollWALWriter(serverName));
584  }
585
586  @Override
587  public CompactionState getCompactionState(TableName tableName) throws IOException {
588    return get(admin.getCompactionState(tableName));
589  }
590
591  @Override
592  public CompactionState getCompactionState(TableName tableName, CompactType compactType)
593      throws IOException {
594    return get(admin.getCompactionState(tableName, compactType));
595  }
596
597  @Override
598  public CompactionState getCompactionStateForRegion(byte[] regionName) throws IOException {
599    return get(admin.getCompactionStateForRegion(regionName));
600  }
601
602  @Override
603  public long getLastMajorCompactionTimestamp(TableName tableName) throws IOException {
604    return get(admin.getLastMajorCompactionTimestamp(tableName)).orElse(0L);
605  }
606
607  @Override
608  public long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException {
609    return get(admin.getLastMajorCompactionTimestampForRegion(regionName)).orElse(0L);
610  }
611
612  @Override
613  public void snapshot(SnapshotDescription snapshot)
614      throws IOException, SnapshotCreationException, IllegalArgumentException {
615    get(admin.snapshot(snapshot));
616  }
617
618  @Override
619  public Future<Void> snapshotAsync(SnapshotDescription snapshot)
620      throws IOException, SnapshotCreationException {
621    return admin.snapshot(snapshot);
622  }
623
624  @Override
625  public boolean isSnapshotFinished(SnapshotDescription snapshot)
626      throws IOException, HBaseSnapshotException, UnknownSnapshotException {
627    return get(admin.isSnapshotFinished(snapshot));
628  }
629
630  @Override
631  public void restoreSnapshot(String snapshotName) throws IOException, RestoreSnapshotException {
632    get(admin.restoreSnapshot(snapshotName));
633  }
634
635  @Override
636  public void restoreSnapshot(String snapshotName, boolean takeFailSafeSnapshot, boolean restoreAcl)
637      throws IOException, RestoreSnapshotException {
638    get(admin.restoreSnapshot(snapshotName, takeFailSafeSnapshot, restoreAcl));
639  }
640
641  @Override
642  public Future<Void> cloneSnapshotAsync(String snapshotName, TableName tableName,
643      boolean restoreAcl) throws IOException, TableExistsException, RestoreSnapshotException {
644    return admin.cloneSnapshot(snapshotName, tableName, restoreAcl);
645  }
646
647  @Override
648  public void execProcedure(String signature, String instance, Map<String, String> props)
649      throws IOException {
650    get(admin.execProcedure(signature, instance, props));
651  }
652
653  @Override
654  public byte[] execProcedureWithReturn(String signature, String instance,
655      Map<String, String> props) throws IOException {
656    return get(admin.execProcedureWithReturn(signature, instance, props));
657  }
658
659  @Override
660  public boolean isProcedureFinished(String signature, String instance, Map<String, String> props)
661      throws IOException {
662    return get(admin.isProcedureFinished(signature, instance, props));
663  }
664
665  @Override
666  public List<SnapshotDescription> listSnapshots() throws IOException {
667    return get(admin.listSnapshots());
668  }
669
670  @Override
671  public List<SnapshotDescription> listSnapshots(Pattern pattern) throws IOException {
672    return get(admin.listSnapshots(pattern));
673  }
674
675  @Override
676  public List<SnapshotDescription> listTableSnapshots(Pattern tableNamePattern,
677      Pattern snapshotNamePattern) throws IOException {
678    return get(admin.listTableSnapshots(tableNamePattern, snapshotNamePattern));
679  }
680
681  @Override
682  public void deleteSnapshot(String snapshotName) throws IOException {
683    get(admin.deleteSnapshot(snapshotName));
684  }
685
686  @Override
687  public void deleteSnapshots(Pattern pattern) throws IOException {
688    get(admin.deleteSnapshots(pattern));
689  }
690
691  @Override
692  public void deleteTableSnapshots(Pattern tableNamePattern, Pattern snapshotNamePattern)
693      throws IOException {
694    get(admin.deleteTableSnapshots(tableNamePattern, snapshotNamePattern));
695  }
696
697  @Override
698  public void setQuota(QuotaSettings quota) throws IOException {
699    get(admin.setQuota(quota));
700  }
701
702  @Override
703  public List<QuotaSettings> getQuota(QuotaFilter filter) throws IOException {
704    return get(admin.getQuota(filter));
705  }
706
707  @SuppressWarnings("deprecation")
708  private static final class SyncCoprocessorRpcChannelOverAsync implements CoprocessorRpcChannel {
709
710    private final RpcChannel delegate;
711
712    public SyncCoprocessorRpcChannelOverAsync(RpcChannel delegate) {
713      this.delegate = delegate;
714    }
715
716    @Override
717    public void callMethod(MethodDescriptor method, RpcController controller, Message request,
718        Message responsePrototype, RpcCallback<Message> done) {
719      ClientCoprocessorRpcController c = new ClientCoprocessorRpcController();
720      CoprocessorBlockingRpcCallback<Message> callback = new CoprocessorBlockingRpcCallback<>();
721      delegate.callMethod(method, c, request, responsePrototype, callback);
722      Message ret;
723      try {
724        ret = callback.get();
725      } catch (IOException e) {
726        setCoprocessorError(controller, e);
727        return;
728      }
729      if (c.failed()) {
730        setCoprocessorError(controller, c.getFailed());
731      }
732      done.run(ret);
733    }
734
735    @Override
736    public Message callBlockingMethod(MethodDescriptor method, RpcController controller,
737        Message request, Message responsePrototype) throws ServiceException {
738      ClientCoprocessorRpcController c = new ClientCoprocessorRpcController();
739      CoprocessorBlockingRpcCallback<Message> done = new CoprocessorBlockingRpcCallback<>();
740      callMethod(method, c, request, responsePrototype, done);
741      Message ret;
742      try {
743        ret = done.get();
744      } catch (IOException e) {
745        throw new ServiceException(e);
746      }
747      if (c.failed()) {
748        setCoprocessorError(controller, c.getFailed());
749        throw new ServiceException(c.getFailed());
750      }
751      return ret;
752    }
753  }
754
755  @SuppressWarnings("deprecation")
756  @Override
757  public CoprocessorRpcChannel coprocessorService() {
758    return new SyncCoprocessorRpcChannelOverAsync(
759      new MasterCoprocessorRpcChannelImpl(admin.<Message> newMasterCaller()));
760  }
761
762  @SuppressWarnings("deprecation")
763  @Override
764  public CoprocessorRpcChannel coprocessorService(ServerName serverName) {
765    return new SyncCoprocessorRpcChannelOverAsync(new RegionServerCoprocessorRpcChannelImpl(
766      admin.<Message> newServerCaller().serverName(serverName)));
767  }
768
769  @Override
770  public void updateConfiguration(ServerName server) throws IOException {
771    get(admin.updateConfiguration(server));
772  }
773
774  @Override
775  public void updateConfiguration() throws IOException {
776    get(admin.updateConfiguration());
777  }
778
779  @Override
780  public List<SecurityCapability> getSecurityCapabilities() throws IOException {
781    return get(admin.getSecurityCapabilities());
782  }
783
784  @Override
785  public boolean splitSwitch(boolean enabled, boolean synchronous) throws IOException {
786    return get(admin.splitSwitch(enabled, synchronous));
787  }
788
789  @Override
790  public boolean mergeSwitch(boolean enabled, boolean synchronous) throws IOException {
791    return get(admin.mergeSwitch(enabled, synchronous));
792  }
793
794  @Override
795  public boolean isSplitEnabled() throws IOException {
796    return get(admin.isSplitEnabled());
797  }
798
799  @Override
800  public boolean isMergeEnabled() throws IOException {
801    return get(admin.isMergeEnabled());
802  }
803
804  @Override
805  public Future<Void> addReplicationPeerAsync(String peerId, ReplicationPeerConfig peerConfig,
806      boolean enabled) throws IOException {
807    return admin.addReplicationPeer(peerId, peerConfig, enabled);
808  }
809
810  @Override
811  public Future<Void> removeReplicationPeerAsync(String peerId) throws IOException {
812    return admin.removeReplicationPeer(peerId);
813  }
814
815  @Override
816  public Future<Void> enableReplicationPeerAsync(String peerId) throws IOException {
817    return admin.enableReplicationPeer(peerId);
818  }
819
820  @Override
821  public Future<Void> disableReplicationPeerAsync(String peerId) throws IOException {
822    return admin.disableReplicationPeer(peerId);
823  }
824
825  @Override
826  public ReplicationPeerConfig getReplicationPeerConfig(String peerId) throws IOException {
827    return get(admin.getReplicationPeerConfig(peerId));
828  }
829
830  @Override
831  public Future<Void> updateReplicationPeerConfigAsync(String peerId,
832      ReplicationPeerConfig peerConfig) throws IOException {
833    return admin.updateReplicationPeerConfig(peerId, peerConfig);
834  }
835
836  @Override
837  public List<ReplicationPeerDescription> listReplicationPeers() throws IOException {
838    return get(admin.listReplicationPeers());
839  }
840
841  @Override
842  public List<ReplicationPeerDescription> listReplicationPeers(Pattern pattern) throws IOException {
843    return get(admin.listReplicationPeers(pattern));
844  }
845
846  @Override
847  public Future<Void> transitReplicationPeerSyncReplicationStateAsync(String peerId,
848      SyncReplicationState state) throws IOException {
849    return admin.transitReplicationPeerSyncReplicationState(peerId, state);
850  }
851
852  @Override
853  public void decommissionRegionServers(List<ServerName> servers, boolean offload)
854      throws IOException {
855    get(admin.decommissionRegionServers(servers, offload));
856  }
857
858  @Override
859  public List<ServerName> listDecommissionedRegionServers() throws IOException {
860    return get(admin.listDecommissionedRegionServers());
861  }
862
863  @Override
864  public void recommissionRegionServer(ServerName server, List<byte[]> encodedRegionNames)
865      throws IOException {
866    get(admin.recommissionRegionServer(server, encodedRegionNames));
867  }
868
869  @Override
870  public List<TableCFs> listReplicatedTableCFs() throws IOException {
871    return get(admin.listReplicatedTableCFs());
872  }
873
874  @Override
875  public void enableTableReplication(TableName tableName) throws IOException {
876    get(admin.enableTableReplication(tableName));
877  }
878
879  @Override
880  public void disableTableReplication(TableName tableName) throws IOException {
881    get(admin.disableTableReplication(tableName));
882  }
883
884  @Override
885  public void clearCompactionQueues(ServerName serverName, Set<String> queues)
886      throws IOException, InterruptedException {
887    get(admin.clearCompactionQueues(serverName, queues));
888  }
889
890  @Override
891  public List<ServerName> clearDeadServers(List<ServerName> servers) throws IOException {
892    return get(admin.clearDeadServers(servers));
893  }
894
895  @Override
896  public void cloneTableSchema(TableName tableName, TableName newTableName, boolean preserveSplits)
897      throws IOException {
898    get(admin.cloneTableSchema(tableName, newTableName, preserveSplits));
899  }
900
901  @Override
902  public boolean switchRpcThrottle(boolean enable) throws IOException {
903    return get(admin.switchRpcThrottle(enable));
904  }
905
906  @Override
907  public boolean isRpcThrottleEnabled() throws IOException {
908    return get(admin.isRpcThrottleEnabled());
909  }
910
911  @Override
912  public boolean exceedThrottleQuotaSwitch(boolean enable) throws IOException {
913    return get(admin.exceedThrottleQuotaSwitch(enable));
914  }
915
916  @Override
917  public Map<TableName, Long> getSpaceQuotaTableSizes() throws IOException {
918    return get(admin.getSpaceQuotaTableSizes());
919  }
920
921  @Override
922  public Map<TableName, ? extends SpaceQuotaSnapshotView> getRegionServerSpaceQuotaSnapshots(
923      ServerName serverName) throws IOException {
924    return get(admin.getRegionServerSpaceQuotaSnapshots(serverName));
925  }
926
927  @Override
928  public SpaceQuotaSnapshotView getCurrentSpaceQuotaSnapshot(String namespace) throws IOException {
929    return get(admin.getCurrentSpaceQuotaSnapshot(namespace));
930  }
931
932  @Override
933  public SpaceQuotaSnapshotView getCurrentSpaceQuotaSnapshot(TableName tableName)
934      throws IOException {
935    return get(admin.getCurrentSpaceQuotaSnapshot(tableName));
936  }
937
938  @Override
939  public void grant(UserPermission userPermission, boolean mergeExistingPermissions)
940      throws IOException {
941    get(admin.grant(userPermission, mergeExistingPermissions));
942  }
943
944  @Override
945  public void revoke(UserPermission userPermission) throws IOException {
946    get(admin.revoke(userPermission));
947  }
948
949  @Override
950  public List<UserPermission> getUserPermissions(
951      GetUserPermissionsRequest getUserPermissionsRequest) throws IOException {
952    return get(admin.getUserPermissions(getUserPermissionsRequest));
953  }
954
955  @Override
956  public List<Boolean> hasUserPermissions(String userName, List<Permission> permissions)
957      throws IOException {
958    return get(admin.hasUserPermissions(userName, permissions));
959  }
960
961  @Override
962  public boolean snapshotCleanupSwitch(final boolean on, final boolean synchronous)
963      throws IOException {
964    return get(admin.snapshotCleanupSwitch(on, synchronous));
965  }
966
967  @Override
968  public boolean isSnapshotCleanupEnabled() throws IOException {
969    return get(admin.isSnapshotCleanupEnabled());
970  }
971
972  @Override
973  public List<OnlineLogRecord> getSlowLogResponses(final Set<ServerName> serverNames,
974      final LogQueryFilter logQueryFilter) throws IOException {
975    return get(admin.getSlowLogResponses(serverNames, logQueryFilter));
976  }
977
978  @Override
979  public List<Boolean> clearSlowLogResponses(final Set<ServerName> serverNames)
980      throws IOException {
981    return get(admin.clearSlowLogResponses(serverNames));
982  }
983
984  @Override
985  public RSGroupInfo getRSGroup(String groupName) throws IOException {
986    return get(admin.getRSGroup(groupName));
987  }
988
989  @Override
990  public void moveServersToRSGroup(Set<Address> servers, String groupName) throws IOException {
991    get(admin.moveServersToRSGroup(servers, groupName));
992  }
993
994  @Override
995  public void addRSGroup(String groupName) throws IOException {
996    get(admin.addRSGroup(groupName));
997  }
998
999  @Override
1000  public void removeRSGroup(String groupName) throws IOException {
1001    get(admin.removeRSGroup(groupName));
1002  }
1003
1004  @Override
1005  public boolean balanceRSGroup(String groupName) throws IOException {
1006    return get(admin.balanceRSGroup(groupName));
1007  }
1008
1009  @Override
1010  public List<RSGroupInfo> listRSGroups() throws IOException {
1011    return get(admin.listRSGroups());
1012  }
1013
1014  @Override
1015  public List<TableName> listTablesInRSGroup(String groupName) throws IOException {
1016    return get(admin.listTablesInRSGroup(groupName));
1017  }
1018
1019  @Override
1020  public Pair<List<String>, List<TableName>>
1021    getConfiguredNamespacesAndTablesInRSGroup(String groupName) throws IOException {
1022    return get(admin.getConfiguredNamespacesAndTablesInRSGroup(groupName));
1023  }
1024
1025  @Override
1026  public RSGroupInfo getRSGroup(Address hostPort) throws IOException {
1027    return get(admin.getRSGroup(hostPort));
1028  }
1029
1030  @Override
1031  public void removeServersFromRSGroup(Set<Address> servers) throws IOException {
1032    get(admin.removeServersFromRSGroup(servers));
1033  }
1034
1035  @Override
1036  public RSGroupInfo getRSGroup(TableName tableName) throws IOException {
1037    return get(admin.getRSGroup(tableName));
1038  }
1039
1040  @Override
1041  public void setRSGroup(Set<TableName> tables, String groupName) throws IOException {
1042    get(admin.setRSGroup(tables, groupName));
1043  }
1044
1045  @Override
1046  public void renameRSGroup(String oldName, String newName) throws IOException {
1047    get(admin.renameRSGroup(oldName, newName));
1048  }
1049
1050  @Override
1051  public void updateRSGroupConfig(String groupName, Map<String, String> configuration)
1052      throws IOException {
1053    get(admin.updateRSGroupConfig(groupName, configuration));
1054  }
1055}