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 flush(TableName tableName, byte[] columnFamily) throws IOException {
249    get(admin.flush(tableName, columnFamily));
250  }
251
252  @Override
253  public void flushRegion(byte[] regionName) throws IOException {
254    get(admin.flushRegion(regionName));
255  }
256
257  @Override
258  public void flushRegion(byte[] regionName, byte[] columnFamily) throws IOException {
259    get(admin.flushRegion(regionName, columnFamily));
260  }
261
262  @Override
263  public void flushRegionServer(ServerName serverName) throws IOException {
264    get(admin.flushRegionServer(serverName));
265  }
266
267  @Override
268  public void compact(TableName tableName) throws IOException {
269    get(admin.compact(tableName));
270  }
271
272  @Override
273  public void compactRegion(byte[] regionName) throws IOException {
274    get(admin.compactRegion(regionName));
275  }
276
277  @Override
278  public void compact(TableName tableName, byte[] columnFamily) throws IOException {
279    get(admin.compact(tableName, columnFamily));
280  }
281
282  @Override
283  public void compactRegion(byte[] regionName, byte[] columnFamily) throws IOException {
284    get(admin.compactRegion(regionName, columnFamily));
285  }
286
287  @Override
288  public void compact(TableName tableName, CompactType compactType)
289      throws IOException, InterruptedException {
290    get(admin.compact(tableName, compactType));
291  }
292
293  @Override
294  public void compact(TableName tableName, byte[] columnFamily, CompactType compactType)
295      throws IOException, InterruptedException {
296    get(admin.compact(tableName, columnFamily, compactType));
297  }
298
299  @Override
300  public void majorCompact(TableName tableName) throws IOException {
301    get(admin.majorCompact(tableName));
302  }
303
304  @Override
305  public void majorCompactRegion(byte[] regionName) throws IOException {
306    get(admin.majorCompactRegion(regionName));
307  }
308
309  @Override
310  public void majorCompact(TableName tableName, byte[] columnFamily) throws IOException {
311    get(admin.majorCompact(tableName, columnFamily));
312  }
313
314  @Override
315  public void majorCompactRegion(byte[] regionName, byte[] columnFamily) throws IOException {
316    get(admin.majorCompactRegion(regionName, columnFamily));
317  }
318
319  @Override
320  public void majorCompact(TableName tableName, CompactType compactType)
321      throws IOException, InterruptedException {
322    get(admin.majorCompact(tableName, compactType));
323  }
324
325  @Override
326  public void majorCompact(TableName tableName, byte[] columnFamily, CompactType compactType)
327      throws IOException, InterruptedException {
328    get(admin.majorCompact(tableName, columnFamily, compactType));
329  }
330
331  @Override
332  public Map<ServerName, Boolean> compactionSwitch(boolean switchState,
333      List<String> serverNamesList) throws IOException {
334    return get(admin.compactionSwitch(switchState, serverNamesList));
335  }
336
337  @Override
338  public void compactRegionServer(ServerName serverName) throws IOException {
339    get(admin.compactRegionServer(serverName));
340  }
341
342  @Override
343  public void majorCompactRegionServer(ServerName serverName) throws IOException {
344    get(admin.majorCompactRegionServer(serverName));
345  }
346
347  @Override
348  public void move(byte[] encodedRegionName) throws IOException {
349    get(admin.move(encodedRegionName));
350  }
351
352  @Override
353  public void move(byte[] encodedRegionName, ServerName destServerName) throws IOException {
354    get(admin.move(encodedRegionName, destServerName));
355  }
356
357  @Override
358  public void assign(byte[] regionName) throws IOException {
359    get(admin.assign(regionName));
360  }
361
362  @Override
363  public void unassign(byte[] regionName) throws IOException {
364    get(admin.unassign(regionName));
365  }
366
367  @Override
368  public void offline(byte[] regionName) throws IOException {
369    get(admin.offline(regionName));
370  }
371
372  @Override
373  public boolean balancerSwitch(boolean onOrOff, boolean synchronous) throws IOException {
374    return get(admin.balancerSwitch(onOrOff, synchronous));
375  }
376
377  @Override
378  public boolean balance() throws IOException {
379    return get(admin.balance());
380  }
381
382  @Override
383  public boolean balance(boolean force) throws IOException {
384    return get(admin.balance(force));
385  }
386
387  @Override
388  public boolean isBalancerEnabled() throws IOException {
389    return get(admin.isBalancerEnabled());
390  }
391
392  @Override
393  public CacheEvictionStats clearBlockCache(TableName tableName) throws IOException {
394    return get(admin.clearBlockCache(tableName));
395  }
396
397  @Override
398  public boolean normalize(NormalizeTableFilterParams ntfp) throws IOException {
399    return get(admin.normalize(ntfp));
400  }
401
402  @Override
403  public boolean isNormalizerEnabled() throws IOException {
404    return get(admin.isNormalizerEnabled());
405  }
406
407  @Override
408  public boolean normalizerSwitch(boolean on) throws IOException {
409    return get(admin.normalizerSwitch(on));
410  }
411
412  @Override
413  public boolean catalogJanitorSwitch(boolean onOrOff) throws IOException {
414    return get(admin.catalogJanitorSwitch(onOrOff));
415  }
416
417  @Override
418  public int runCatalogJanitor() throws IOException {
419    return get(admin.runCatalogJanitor());
420  }
421
422  @Override
423  public boolean isCatalogJanitorEnabled() throws IOException {
424    return get(admin.isCatalogJanitorEnabled());
425  }
426
427  @Override
428  public boolean cleanerChoreSwitch(boolean onOrOff) throws IOException {
429    return get(admin.cleanerChoreSwitch(onOrOff));
430  }
431
432  @Override
433  public boolean runCleanerChore() throws IOException {
434    return get(admin.runCleanerChore());
435  }
436
437  @Override
438  public boolean isCleanerChoreEnabled() throws IOException {
439    return get(admin.isCleanerChoreEnabled());
440  }
441
442  @Override
443  public Future<Void> mergeRegionsAsync(byte[][] nameOfRegionsToMerge, boolean forcible)
444      throws IOException {
445    return admin.mergeRegions(Arrays.asList(nameOfRegionsToMerge), forcible);
446  }
447
448  @Override
449  public void split(TableName tableName) throws IOException {
450    get(admin.split(tableName));
451  }
452
453  @Override
454  public void split(TableName tableName, byte[] splitPoint) throws IOException {
455    get(admin.split(tableName, splitPoint));
456  }
457
458  @Override
459  public Future<Void> splitRegionAsync(byte[] regionName) throws IOException {
460    return admin.splitRegion(regionName);
461  }
462
463  @Override
464  public Future<Void> splitRegionAsync(byte[] regionName, byte[] splitPoint) throws IOException {
465    return admin.splitRegion(regionName, splitPoint);
466  }
467
468  @Override
469  public Future<Void> modifyTableAsync(TableDescriptor td) throws IOException {
470    return admin.modifyTable(td);
471  }
472
473  @Override
474  public void shutdown() throws IOException {
475    get(admin.shutdown());
476  }
477
478  @Override
479  public void stopMaster() throws IOException {
480    get(admin.stopMaster());
481  }
482
483  @Override
484  public boolean isMasterInMaintenanceMode() throws IOException {
485    return get(admin.isMasterInMaintenanceMode());
486  }
487
488  @Override
489  public void stopRegionServer(String hostnamePort) throws IOException {
490    get(admin.stopRegionServer(ServerName.valueOf(hostnamePort, 0)));
491  }
492
493  @Override
494  public ClusterMetrics getClusterMetrics(EnumSet<Option> options) throws IOException {
495    return get(admin.getClusterMetrics(options));
496  }
497
498  @Override
499  public List<RegionMetrics> getRegionMetrics(ServerName serverName) throws IOException {
500    return get(admin.getRegionMetrics(serverName));
501  }
502
503  @Override
504  public List<RegionMetrics> getRegionMetrics(ServerName serverName, TableName tableName)
505      throws IOException {
506    return get(admin.getRegionMetrics(serverName, tableName));
507  }
508
509  @Override
510  public Configuration getConfiguration() {
511    return conn.getConfiguration();
512  }
513
514  @Override
515  public Future<Void> createNamespaceAsync(NamespaceDescriptor descriptor) throws IOException {
516    return admin.createNamespace(descriptor);
517  }
518
519  @Override
520  public Future<Void> modifyNamespaceAsync(NamespaceDescriptor descriptor) throws IOException {
521    return admin.modifyNamespace(descriptor);
522  }
523
524  @Override
525  public Future<Void> deleteNamespaceAsync(String name) throws IOException {
526    return admin.deleteNamespace(name);
527  }
528
529  @Override
530  public NamespaceDescriptor getNamespaceDescriptor(String name)
531      throws NamespaceNotFoundException, IOException {
532    return get(admin.getNamespaceDescriptor(name));
533  }
534
535  @Override
536  public String[] listNamespaces() throws IOException {
537    return get(admin.listNamespaces()).toArray(new String[0]);
538  }
539
540  @Override
541  public NamespaceDescriptor[] listNamespaceDescriptors() throws IOException {
542    return get(admin.listNamespaceDescriptors()).toArray(new NamespaceDescriptor[0]);
543  }
544
545  @Override
546  public List<TableDescriptor> listTableDescriptorsByNamespace(byte[] name) throws IOException {
547    return get(admin.listTableDescriptorsByNamespace(Bytes.toString(name)));
548  }
549
550  @Override
551  public TableName[] listTableNamesByNamespace(String name) throws IOException {
552    return get(admin.listTableNamesByNamespace(name)).toArray(new TableName[0]);
553  }
554
555  @Override
556  public List<RegionInfo> getRegions(TableName tableName) throws IOException {
557    return get(admin.getRegions(tableName));
558  }
559
560  @Override
561  public void close() {
562    // do nothing, AsyncAdmin is not a Closeable.
563  }
564
565  @Override
566  public List<TableDescriptor> listTableDescriptors(List<TableName> tableNames) throws IOException {
567    return get(admin.listTableDescriptors(tableNames));
568  }
569
570  @Override
571  public Future<Boolean> abortProcedureAsync(long procId, boolean mayInterruptIfRunning)
572      throws IOException {
573    return admin.abortProcedure(procId, mayInterruptIfRunning);
574  }
575
576  @Override
577  public String getProcedures() throws IOException {
578    return get(admin.getProcedures());
579  }
580
581  @Override
582  public String getLocks() throws IOException {
583    return get(admin.getLocks());
584  }
585
586  @Override
587  public void rollWALWriter(ServerName serverName) throws IOException, FailedLogCloseException {
588    get(admin.rollWALWriter(serverName));
589  }
590
591  @Override
592  public CompactionState getCompactionState(TableName tableName) throws IOException {
593    return get(admin.getCompactionState(tableName));
594  }
595
596  @Override
597  public CompactionState getCompactionState(TableName tableName, CompactType compactType)
598      throws IOException {
599    return get(admin.getCompactionState(tableName, compactType));
600  }
601
602  @Override
603  public CompactionState getCompactionStateForRegion(byte[] regionName) throws IOException {
604    return get(admin.getCompactionStateForRegion(regionName));
605  }
606
607  @Override
608  public long getLastMajorCompactionTimestamp(TableName tableName) throws IOException {
609    return get(admin.getLastMajorCompactionTimestamp(tableName)).orElse(0L);
610  }
611
612  @Override
613  public long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException {
614    return get(admin.getLastMajorCompactionTimestampForRegion(regionName)).orElse(0L);
615  }
616
617  @Override
618  public void snapshot(SnapshotDescription snapshot)
619      throws IOException, SnapshotCreationException, IllegalArgumentException {
620    get(admin.snapshot(snapshot));
621  }
622
623  @Override
624  public Future<Void> snapshotAsync(SnapshotDescription snapshot)
625      throws IOException, SnapshotCreationException {
626    return admin.snapshot(snapshot);
627  }
628
629  @Override
630  public boolean isSnapshotFinished(SnapshotDescription snapshot)
631      throws IOException, HBaseSnapshotException, UnknownSnapshotException {
632    return get(admin.isSnapshotFinished(snapshot));
633  }
634
635  @Override
636  public void restoreSnapshot(String snapshotName) throws IOException, RestoreSnapshotException {
637    get(admin.restoreSnapshot(snapshotName));
638  }
639
640  @Override
641  public void restoreSnapshot(String snapshotName, boolean takeFailSafeSnapshot, boolean restoreAcl)
642      throws IOException, RestoreSnapshotException {
643    get(admin.restoreSnapshot(snapshotName, takeFailSafeSnapshot, restoreAcl));
644  }
645
646  @Override
647  public Future<Void> cloneSnapshotAsync(String snapshotName, TableName tableName,
648      boolean restoreAcl) throws IOException, TableExistsException, RestoreSnapshotException {
649    return admin.cloneSnapshot(snapshotName, tableName, restoreAcl);
650  }
651
652  @Override
653  public void execProcedure(String signature, String instance, Map<String, String> props)
654      throws IOException {
655    get(admin.execProcedure(signature, instance, props));
656  }
657
658  @Override
659  public byte[] execProcedureWithReturn(String signature, String instance,
660      Map<String, String> props) throws IOException {
661    return get(admin.execProcedureWithReturn(signature, instance, props));
662  }
663
664  @Override
665  public boolean isProcedureFinished(String signature, String instance, Map<String, String> props)
666      throws IOException {
667    return get(admin.isProcedureFinished(signature, instance, props));
668  }
669
670  @Override
671  public List<SnapshotDescription> listSnapshots() throws IOException {
672    return get(admin.listSnapshots());
673  }
674
675  @Override
676  public List<SnapshotDescription> listSnapshots(Pattern pattern) throws IOException {
677    return get(admin.listSnapshots(pattern));
678  }
679
680  @Override
681  public List<SnapshotDescription> listTableSnapshots(Pattern tableNamePattern,
682      Pattern snapshotNamePattern) throws IOException {
683    return get(admin.listTableSnapshots(tableNamePattern, snapshotNamePattern));
684  }
685
686  @Override
687  public void deleteSnapshot(String snapshotName) throws IOException {
688    get(admin.deleteSnapshot(snapshotName));
689  }
690
691  @Override
692  public void deleteSnapshots(Pattern pattern) throws IOException {
693    get(admin.deleteSnapshots(pattern));
694  }
695
696  @Override
697  public void deleteTableSnapshots(Pattern tableNamePattern, Pattern snapshotNamePattern)
698      throws IOException {
699    get(admin.deleteTableSnapshots(tableNamePattern, snapshotNamePattern));
700  }
701
702  @Override
703  public void setQuota(QuotaSettings quota) throws IOException {
704    get(admin.setQuota(quota));
705  }
706
707  @Override
708  public List<QuotaSettings> getQuota(QuotaFilter filter) throws IOException {
709    return get(admin.getQuota(filter));
710  }
711
712  @SuppressWarnings("deprecation")
713  private static final class SyncCoprocessorRpcChannelOverAsync implements CoprocessorRpcChannel {
714
715    private final RpcChannel delegate;
716
717    public SyncCoprocessorRpcChannelOverAsync(RpcChannel delegate) {
718      this.delegate = delegate;
719    }
720
721    @Override
722    public void callMethod(MethodDescriptor method, RpcController controller, Message request,
723        Message responsePrototype, RpcCallback<Message> done) {
724      ClientCoprocessorRpcController c = new ClientCoprocessorRpcController();
725      CoprocessorBlockingRpcCallback<Message> callback = new CoprocessorBlockingRpcCallback<>();
726      delegate.callMethod(method, c, request, responsePrototype, callback);
727      Message ret;
728      try {
729        ret = callback.get();
730      } catch (IOException e) {
731        setCoprocessorError(controller, e);
732        return;
733      }
734      if (c.failed()) {
735        setCoprocessorError(controller, c.getFailed());
736      }
737      done.run(ret);
738    }
739
740    @Override
741    public Message callBlockingMethod(MethodDescriptor method, RpcController controller,
742        Message request, Message responsePrototype) throws ServiceException {
743      ClientCoprocessorRpcController c = new ClientCoprocessorRpcController();
744      CoprocessorBlockingRpcCallback<Message> done = new CoprocessorBlockingRpcCallback<>();
745      callMethod(method, c, request, responsePrototype, done);
746      Message ret;
747      try {
748        ret = done.get();
749      } catch (IOException e) {
750        throw new ServiceException(e);
751      }
752      if (c.failed()) {
753        setCoprocessorError(controller, c.getFailed());
754        throw new ServiceException(c.getFailed());
755      }
756      return ret;
757    }
758  }
759
760  @SuppressWarnings("deprecation")
761  @Override
762  public CoprocessorRpcChannel coprocessorService() {
763    return new SyncCoprocessorRpcChannelOverAsync(
764      new MasterCoprocessorRpcChannelImpl(admin.<Message> newMasterCaller()));
765  }
766
767  @SuppressWarnings("deprecation")
768  @Override
769  public CoprocessorRpcChannel coprocessorService(ServerName serverName) {
770    return new SyncCoprocessorRpcChannelOverAsync(new RegionServerCoprocessorRpcChannelImpl(
771      admin.<Message> newServerCaller().serverName(serverName)));
772  }
773
774  @Override
775  public void updateConfiguration(ServerName server) throws IOException {
776    get(admin.updateConfiguration(server));
777  }
778
779  @Override
780  public void updateConfiguration() throws IOException {
781    get(admin.updateConfiguration());
782  }
783
784  @Override
785  public List<SecurityCapability> getSecurityCapabilities() throws IOException {
786    return get(admin.getSecurityCapabilities());
787  }
788
789  @Override
790  public boolean splitSwitch(boolean enabled, boolean synchronous) throws IOException {
791    return get(admin.splitSwitch(enabled, synchronous));
792  }
793
794  @Override
795  public boolean mergeSwitch(boolean enabled, boolean synchronous) throws IOException {
796    return get(admin.mergeSwitch(enabled, synchronous));
797  }
798
799  @Override
800  public boolean isSplitEnabled() throws IOException {
801    return get(admin.isSplitEnabled());
802  }
803
804  @Override
805  public boolean isMergeEnabled() throws IOException {
806    return get(admin.isMergeEnabled());
807  }
808
809  @Override
810  public Future<Void> addReplicationPeerAsync(String peerId, ReplicationPeerConfig peerConfig,
811      boolean enabled) throws IOException {
812    return admin.addReplicationPeer(peerId, peerConfig, enabled);
813  }
814
815  @Override
816  public Future<Void> removeReplicationPeerAsync(String peerId) throws IOException {
817    return admin.removeReplicationPeer(peerId);
818  }
819
820  @Override
821  public Future<Void> enableReplicationPeerAsync(String peerId) throws IOException {
822    return admin.enableReplicationPeer(peerId);
823  }
824
825  @Override
826  public Future<Void> disableReplicationPeerAsync(String peerId) throws IOException {
827    return admin.disableReplicationPeer(peerId);
828  }
829
830  @Override
831  public ReplicationPeerConfig getReplicationPeerConfig(String peerId) throws IOException {
832    return get(admin.getReplicationPeerConfig(peerId));
833  }
834
835  @Override
836  public Future<Void> updateReplicationPeerConfigAsync(String peerId,
837      ReplicationPeerConfig peerConfig) throws IOException {
838    return admin.updateReplicationPeerConfig(peerId, peerConfig);
839  }
840
841  @Override
842  public List<ReplicationPeerDescription> listReplicationPeers() throws IOException {
843    return get(admin.listReplicationPeers());
844  }
845
846  @Override
847  public List<ReplicationPeerDescription> listReplicationPeers(Pattern pattern) throws IOException {
848    return get(admin.listReplicationPeers(pattern));
849  }
850
851  @Override
852  public Future<Void> transitReplicationPeerSyncReplicationStateAsync(String peerId,
853      SyncReplicationState state) throws IOException {
854    return admin.transitReplicationPeerSyncReplicationState(peerId, state);
855  }
856
857  @Override
858  public void decommissionRegionServers(List<ServerName> servers, boolean offload)
859      throws IOException {
860    get(admin.decommissionRegionServers(servers, offload));
861  }
862
863  @Override
864  public List<ServerName> listDecommissionedRegionServers() throws IOException {
865    return get(admin.listDecommissionedRegionServers());
866  }
867
868  @Override
869  public void recommissionRegionServer(ServerName server, List<byte[]> encodedRegionNames)
870      throws IOException {
871    get(admin.recommissionRegionServer(server, encodedRegionNames));
872  }
873
874  @Override
875  public List<TableCFs> listReplicatedTableCFs() throws IOException {
876    return get(admin.listReplicatedTableCFs());
877  }
878
879  @Override
880  public void enableTableReplication(TableName tableName) throws IOException {
881    get(admin.enableTableReplication(tableName));
882  }
883
884  @Override
885  public void disableTableReplication(TableName tableName) throws IOException {
886    get(admin.disableTableReplication(tableName));
887  }
888
889  @Override
890  public void clearCompactionQueues(ServerName serverName, Set<String> queues)
891      throws IOException, InterruptedException {
892    get(admin.clearCompactionQueues(serverName, queues));
893  }
894
895  @Override
896  public List<ServerName> clearDeadServers(List<ServerName> servers) throws IOException {
897    return get(admin.clearDeadServers(servers));
898  }
899
900  @Override
901  public void cloneTableSchema(TableName tableName, TableName newTableName, boolean preserveSplits)
902      throws IOException {
903    get(admin.cloneTableSchema(tableName, newTableName, preserveSplits));
904  }
905
906  @Override
907  public boolean switchRpcThrottle(boolean enable) throws IOException {
908    return get(admin.switchRpcThrottle(enable));
909  }
910
911  @Override
912  public boolean isRpcThrottleEnabled() throws IOException {
913    return get(admin.isRpcThrottleEnabled());
914  }
915
916  @Override
917  public boolean exceedThrottleQuotaSwitch(boolean enable) throws IOException {
918    return get(admin.exceedThrottleQuotaSwitch(enable));
919  }
920
921  @Override
922  public Map<TableName, Long> getSpaceQuotaTableSizes() throws IOException {
923    return get(admin.getSpaceQuotaTableSizes());
924  }
925
926  @Override
927  public Map<TableName, ? extends SpaceQuotaSnapshotView> getRegionServerSpaceQuotaSnapshots(
928      ServerName serverName) throws IOException {
929    return get(admin.getRegionServerSpaceQuotaSnapshots(serverName));
930  }
931
932  @Override
933  public SpaceQuotaSnapshotView getCurrentSpaceQuotaSnapshot(String namespace) throws IOException {
934    return get(admin.getCurrentSpaceQuotaSnapshot(namespace));
935  }
936
937  @Override
938  public SpaceQuotaSnapshotView getCurrentSpaceQuotaSnapshot(TableName tableName)
939      throws IOException {
940    return get(admin.getCurrentSpaceQuotaSnapshot(tableName));
941  }
942
943  @Override
944  public void grant(UserPermission userPermission, boolean mergeExistingPermissions)
945      throws IOException {
946    get(admin.grant(userPermission, mergeExistingPermissions));
947  }
948
949  @Override
950  public void revoke(UserPermission userPermission) throws IOException {
951    get(admin.revoke(userPermission));
952  }
953
954  @Override
955  public List<UserPermission> getUserPermissions(
956      GetUserPermissionsRequest getUserPermissionsRequest) throws IOException {
957    return get(admin.getUserPermissions(getUserPermissionsRequest));
958  }
959
960  @Override
961  public List<Boolean> hasUserPermissions(String userName, List<Permission> permissions)
962      throws IOException {
963    return get(admin.hasUserPermissions(userName, permissions));
964  }
965
966  @Override
967  public boolean snapshotCleanupSwitch(final boolean on, final boolean synchronous)
968      throws IOException {
969    return get(admin.snapshotCleanupSwitch(on, synchronous));
970  }
971
972  @Override
973  public boolean isSnapshotCleanupEnabled() throws IOException {
974    return get(admin.isSnapshotCleanupEnabled());
975  }
976
977  @Override
978  public List<Boolean> clearSlowLogResponses(final Set<ServerName> serverNames)
979      throws IOException {
980    return get(admin.clearSlowLogResponses(serverNames));
981  }
982
983  @Override
984  public RSGroupInfo getRSGroup(String groupName) throws IOException {
985    return get(admin.getRSGroup(groupName));
986  }
987
988  @Override
989  public void moveServersToRSGroup(Set<Address> servers, String groupName) throws IOException {
990    get(admin.moveServersToRSGroup(servers, groupName));
991  }
992
993  @Override
994  public void addRSGroup(String groupName) throws IOException {
995    get(admin.addRSGroup(groupName));
996  }
997
998  @Override
999  public void removeRSGroup(String groupName) throws IOException {
1000    get(admin.removeRSGroup(groupName));
1001  }
1002
1003  @Override
1004  public boolean balanceRSGroup(String groupName) throws IOException {
1005    return get(admin.balanceRSGroup(groupName));
1006  }
1007
1008  @Override
1009  public List<RSGroupInfo> listRSGroups() throws IOException {
1010    return get(admin.listRSGroups());
1011  }
1012
1013  @Override
1014  public List<TableName> listTablesInRSGroup(String groupName) throws IOException {
1015    return get(admin.listTablesInRSGroup(groupName));
1016  }
1017
1018  @Override
1019  public Pair<List<String>, List<TableName>>
1020    getConfiguredNamespacesAndTablesInRSGroup(String groupName) throws IOException {
1021    return get(admin.getConfiguredNamespacesAndTablesInRSGroup(groupName));
1022  }
1023
1024  @Override
1025  public RSGroupInfo getRSGroup(Address hostPort) throws IOException {
1026    return get(admin.getRSGroup(hostPort));
1027  }
1028
1029  @Override
1030  public void removeServersFromRSGroup(Set<Address> servers) throws IOException {
1031    get(admin.removeServersFromRSGroup(servers));
1032  }
1033
1034  @Override
1035  public RSGroupInfo getRSGroup(TableName tableName) throws IOException {
1036    return get(admin.getRSGroup(tableName));
1037  }
1038
1039  @Override
1040  public void setRSGroup(Set<TableName> tables, String groupName) throws IOException {
1041    get(admin.setRSGroup(tables, groupName));
1042  }
1043
1044  @Override
1045  public void renameRSGroup(String oldName, String newName) throws IOException {
1046    get(admin.renameRSGroup(oldName, newName));
1047  }
1048
1049  @Override
1050  public void updateRSGroupConfig(String groupName, Map<String, String> configuration)
1051      throws IOException {
1052    get(admin.updateRSGroupConfig(groupName, configuration));
1053  }
1054
1055  @Override
1056  public List<LogEntry> getLogEntries(Set<ServerName> serverNames, String logType,
1057      ServerType serverType, int limit, Map<String, Object> filterParams)
1058      throws IOException {
1059    return get(admin.getLogEntries(serverNames, logType, serverType, limit, filterParams));
1060  }
1061}