/** * @param tableName a {@link TableName} object for exception identification. * @param request a {@link CreateTableRequest} object to send. * @throws java.io.IOException if any. */ protected ListenableFuture<Table> createTableAsync(final TableName tableName, CreateTableRequest request) throws IOException { ListenableFuture<Table> future = bigtableTableAdminClient.createTableAsync( request.toProto(bigtableInstanceName.toAdminInstanceName())); final SettableFuture<Table> settableFuture = SettableFuture.create(); Futures.addCallback(future, new FutureCallback<Table>() { @Override public void onSuccess(@Nullable Table result) { settableFuture.set(result); } @Override public void onFailure(Throwable t) { settableFuture.setException(convertToTableExistsException(tableName, t)); } }, MoreExecutors.directExecutor()); return settableFuture; }
/** * <p>modifyColumns.</p> * * @param tableName a {@link org.apache.hadoop.hbase.TableName} object. * @param modifications a {@link ModifyTableBuilder} object. */ private CompletableFuture<Void> modifyColumns(TableName tableName, ModifyTableBuilder modifications) { ModifyColumnFamiliesRequest request = modifications.build(); return bigtableTableAdminClient .modifyColumnFamilyAsync(request.toProto(bigtableInstanceName.toAdminInstanceName())) .thenApply(r -> null); }
/** * @param request a {@link CreateTableRequest} object to send. * @throws java.io.IOException if any. */ protected void createTable(TableName tableName, CreateTableRequest request) throws IOException { try { bigtableTableAdminClient.createTable( request.toProto(bigtableInstanceName.toAdminInstanceName())); } catch (Throwable throwable) { throw convertToTableExistsException(tableName, throwable); } }
/** * <p>modifyColumns.</p> * * @param tableName a {@link TableName} object for error messages. * @param columnName a {@link String} object for error messages * @param modificationType a {@link String} object for error messages * @param builder a {@link ModifyTableBuilder} object to send. * @throws java.io.IOException if any. */ protected Void modifyColumns(TableName tableName, String columnName, String modificationType, ModifyTableBuilder builder) throws IOException { ModifyColumnFamiliesRequest request = builder.build(); try { bigtableTableAdminClient.modifyColumnFamily( request.toProto(bigtableInstanceName.toAdminInstanceName())); return null; } catch (Throwable throwable) { throw new IOException( String.format( "Failed to %s column '%s' in table '%s'", modificationType, columnName, tableName.getNameAsString()), throwable); } }
/** {@inheritDoc} */ @Override public CompletableFuture<Void> createTable(TableDescriptor desc, byte[][] splitKeys) { // wraps exceptions in a CF (CompletableFuture). No null check here on desc to match Hbase impl if (desc.getTableName() == null) { return failedFuture(new IllegalArgumentException("TableName cannot be null")); } CreateTableRequest request = TableAdapter2x.adapt(desc, splitKeys); return bigtableTableAdminClient.createTableAsync( request.toProto(bigtableInstanceName.toAdminInstanceName())) .handle((resp, ex) -> { if (ex != null) { throw new CompletionException( AbstractBigtableAdmin.convertToTableExistsException(desc.getTableName(), ex)); } return null; }); }
/** {@inheritDoc} */ @Override public void modifyTable(TableName tableName, HTableDescriptor newDecriptor) throws IOException { if (isTableAvailable(tableName)) { try { ModifyColumnFamiliesRequest request = buildModifications(newDecriptor, getTableDescriptor(tableName)).build(); bigtableTableAdminClient.modifyColumnFamily( request.toProto(bigtableInstanceName.toAdminInstanceName())); } catch (Throwable throwable) { throw new IOException( String.format("Failed to modify table '%s'", tableName.getNameAsString()), throwable); } } else { throw new TableNotFoundException(tableName); } }