diff --git a/bigtable-client-core-parent/bigtable-hbase-integration-tests-common/src/test/java/com/google/cloud/bigtable/hbase/test_env/BigtableEnv.java b/bigtable-client-core-parent/bigtable-hbase-integration-tests-common/src/test/java/com/google/cloud/bigtable/hbase/test_env/BigtableEnv.java
index 93b2442fe2..ffe9d89011 100644
--- a/bigtable-client-core-parent/bigtable-hbase-integration-tests-common/src/test/java/com/google/cloud/bigtable/hbase/test_env/BigtableEnv.java
+++ b/bigtable-client-core-parent/bigtable-hbase-integration-tests-common/src/test/java/com/google/cloud/bigtable/hbase/test_env/BigtableEnv.java
@@ -52,8 +52,7 @@ class BigtableEnv extends SharedTestEnv {
"google.bigtable.instance.id",
"google.bigtable.use.bulk.api",
"google.bigtable.use.plaintext.negotiation",
- "google.bigtable.snapshot.cluster.id",
- "google.bigtable.use.gcj.client");
+ "google.bigtable.snapshot.cluster.id");
@Override
protected void setup() throws IOException {
diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/BigtableOptionsFactory.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/BigtableOptionsFactory.java
index 624a07789f..e80fb7488d 100644
--- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/BigtableOptionsFactory.java
+++ b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/BigtableOptionsFactory.java
@@ -322,13 +322,6 @@ public class BigtableOptionsFactory {
/** Allow namespace methods to be no-ops */
public static final String BIGTABLE_NAMESPACE_WARNING_KEY = "google.bigtable.namespace.warnings";
- /**
- * A flag to decide which implementation to use for data & admin operation.
- *
- *
This will be removed after the transition to java-bigtable.
- */
- @BetaApi public static final String BIGTABLE_USE_GCJ_CLIENT = "google.bigtable.use.gcj.client";
-
/** Tracing cookie to send in the header with the requests */
@BetaApi("The API for setting tracing cookie is not yet stable and may change in the future")
public static final String BIGTABLE_TRACING_COOKIE = "google.bigtable.tracing.cookie.header";
diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/BigtableApi.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/BigtableApi.java
index 8289171c07..c62b030f38 100644
--- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/BigtableApi.java
+++ b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/BigtableApi.java
@@ -16,8 +16,6 @@
package com.google.cloud.bigtable.hbase.wrappers;
import com.google.api.core.InternalApi;
-import com.google.cloud.bigtable.hbase.wrappers.classic.BigtableClassicApi;
-import com.google.cloud.bigtable.hbase.wrappers.classic.BigtableHBaseClassicSettings;
import com.google.cloud.bigtable.hbase.wrappers.veneer.BigtableHBaseVeneerSettings;
import com.google.cloud.bigtable.hbase.wrappers.veneer.BigtableVeneerApi;
import java.io.IOException;
@@ -33,11 +31,7 @@ public abstract class BigtableApi implements AutoCloseable {
private final BigtableHBaseSettings hBaseSettings;
public static BigtableApi create(BigtableHBaseSettings settings) throws IOException {
- if (settings instanceof BigtableHBaseVeneerSettings) {
- return new BigtableVeneerApi((BigtableHBaseVeneerSettings) settings);
- } else {
- return new BigtableClassicApi((BigtableHBaseClassicSettings) settings);
- }
+ return new BigtableVeneerApi((BigtableHBaseVeneerSettings) settings);
}
protected BigtableApi(BigtableHBaseSettings hbaseSettings) {
diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/BigtableHBaseSettings.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/BigtableHBaseSettings.java
index f6c77814e1..78f28980d9 100644
--- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/BigtableHBaseSettings.java
+++ b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/BigtableHBaseSettings.java
@@ -15,7 +15,6 @@
*/
package com.google.cloud.bigtable.hbase.wrappers;
-import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.BIGTABLE_USE_GCJ_CLIENT;
import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.INSTANCE_ID_KEY;
import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.PROJECT_ID_KEY;
import static com.google.common.base.Strings.isNullOrEmpty;
@@ -23,7 +22,6 @@
import com.google.api.core.InternalApi;
import com.google.cloud.bigtable.hbase.BigtableOptionsFactory;
import com.google.cloud.bigtable.hbase.util.Logger;
-import com.google.cloud.bigtable.hbase.wrappers.classic.BigtableHBaseClassicSettings;
import com.google.cloud.bigtable.hbase.wrappers.veneer.BigtableHBaseVeneerSettings;
import com.google.common.base.Preconditions;
import java.io.IOException;
@@ -41,11 +39,7 @@ public abstract class BigtableHBaseSettings {
private final int ttlSecondsForBackup;
public static BigtableHBaseSettings create(Configuration configuration) throws IOException {
- if (configuration.getBoolean(BIGTABLE_USE_GCJ_CLIENT, true)) {
- return BigtableHBaseVeneerSettings.create(configuration);
- } else {
- return new BigtableHBaseClassicSettings(configuration);
- }
+ return BigtableHBaseVeneerSettings.create(configuration);
}
public BigtableHBaseSettings(Configuration configuration) {
diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/AdminClientClassicApi.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/AdminClientClassicApi.java
deleted file mode 100644
index f5d5fc0104..0000000000
--- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/AdminClientClassicApi.java
+++ /dev/null
@@ -1,322 +0,0 @@
-/*
- * Copyright 2020 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.cloud.bigtable.hbase.wrappers.classic;
-
-import com.google.api.core.ApiFuture;
-import com.google.api.core.InternalApi;
-import com.google.bigtable.admin.v2.DeleteBackupRequest;
-import com.google.bigtable.admin.v2.DeleteTableRequest;
-import com.google.bigtable.admin.v2.DropRowRangeRequest;
-import com.google.bigtable.admin.v2.GetTableRequest;
-import com.google.bigtable.admin.v2.ListBackupsRequest;
-import com.google.bigtable.admin.v2.ListBackupsResponse;
-import com.google.bigtable.admin.v2.ListClustersRequest;
-import com.google.bigtable.admin.v2.ListClustersResponse;
-import com.google.bigtable.admin.v2.ListTablesRequest;
-import com.google.bigtable.admin.v2.ListTablesResponse;
-import com.google.cloud.bigtable.admin.v2.internal.NameUtil;
-import com.google.cloud.bigtable.admin.v2.models.Backup;
-import com.google.cloud.bigtable.admin.v2.models.Cluster;
-import com.google.cloud.bigtable.admin.v2.models.CreateBackupRequest;
-import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest;
-import com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest;
-import com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest;
-import com.google.cloud.bigtable.admin.v2.models.RestoredTableResult;
-import com.google.cloud.bigtable.admin.v2.models.Table;
-import com.google.cloud.bigtable.grpc.BigtableClusterName;
-import com.google.cloud.bigtable.grpc.BigtableInstanceClient;
-import com.google.cloud.bigtable.grpc.BigtableInstanceName;
-import com.google.cloud.bigtable.grpc.BigtableSessionSharedThreadPools;
-import com.google.cloud.bigtable.grpc.BigtableTableAdminClient;
-import com.google.cloud.bigtable.hbase.wrappers.AdminClientWrapper;
-import com.google.cloud.bigtable.util.ApiFutureUtil;
-import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.longrunning.Operation;
-import com.google.protobuf.ByteString;
-import com.google.protobuf.Empty;
-import com.google.protobuf.InvalidProtocolBufferException;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-import javax.annotation.Nonnull;
-
-/** For internal use only - public for technical reasons. */
-@InternalApi("For internal usage only")
-public class AdminClientClassicApi implements AdminClientWrapper {
-
- private final BigtableTableAdminClient tableDelegate;
- private final BigtableInstanceClient instanceDelegate;
- private final BigtableInstanceName instanceName;
- private final ExecutorService batchThreadPool;
-
- AdminClientClassicApi(
- @Nonnull BigtableTableAdminClient tableDelegate,
- @Nonnull BigtableInstanceName instanceName,
- BigtableInstanceClient instanceDelegate) {
- this.tableDelegate = tableDelegate;
- this.instanceName = instanceName;
- this.batchThreadPool = BigtableSessionSharedThreadPools.getInstance().getBatchThreadPool();
- this.instanceDelegate = instanceDelegate;
- }
-
- @Override
- public ApiFuture
createTableAsync(CreateTableRequest request) {
- com.google.bigtable.admin.v2.CreateTableRequest requestProto =
- request.toProto(instanceName.getProjectId(), instanceName.getInstanceId());
-
- return ApiFutureUtil.transformAndAdapt(
- tableDelegate.createTableAsync(requestProto),
- new Function() {
- @Override
- public Table apply(com.google.bigtable.admin.v2.Table tableProto) {
- return Table.fromProto(tableProto);
- }
- });
- }
-
- @Override
- public ApiFuture getTableAsync(String tableId) {
- GetTableRequest requestProto =
- GetTableRequest.newBuilder().setName(instanceName.toTableNameStr(tableId)).build();
-
- return ApiFutureUtil.transformAndAdapt(
- tableDelegate.getTableAsync(requestProto),
- new Function() {
- @Override
- public Table apply(com.google.bigtable.admin.v2.Table tableProto) {
- return Table.fromProto(tableProto);
- }
- });
- }
-
- @Override
- public ApiFuture> listTablesAsync() {
- ListTablesRequest request =
- ListTablesRequest.newBuilder().setParent(instanceName.toString()).build();
- ListenableFuture response = tableDelegate.listTablesAsync(request);
-
- return ApiFutureUtil.transformAndAdapt(
- response,
- new Function>() {
- @Override
- public List apply(ListTablesResponse input) {
- ImmutableList.Builder tableIdsBuilder = ImmutableList.builder();
- for (com.google.bigtable.admin.v2.Table tableProto : input.getTablesList()) {
- tableIdsBuilder.add(instanceName.toTableId(tableProto.getName()));
- }
-
- return tableIdsBuilder.build();
- }
- });
- }
-
- @Override
- public ApiFuture deleteTableAsync(String tableId) {
- DeleteTableRequest request =
- DeleteTableRequest.newBuilder().setName(instanceName.toTableNameStr(tableId)).build();
-
- return ApiFutureUtil.transformAndAdapt(
- tableDelegate.deleteTableAsync(request),
- new Function() {
- @Override
- public Void apply(Empty empty) {
- return null;
- }
- });
- }
-
- @Override
- public ApiFuture modifyFamiliesAsync(ModifyColumnFamiliesRequest request) {
- com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest modifyColumnRequestProto =
- request.toProto(instanceName.getProjectId(), instanceName.getInstanceId());
-
- return ApiFutureUtil.transformAndAdapt(
- tableDelegate.modifyColumnFamilyAsync(modifyColumnRequestProto),
- new Function() {
- @Override
- public Table apply(com.google.bigtable.admin.v2.Table tableProto) {
- return Table.fromProto(tableProto);
- }
- });
- }
-
- @Override
- public ApiFuture dropRowRangeAsync(String tableId, ByteString rowKeyPrefix) {
- Preconditions.checkNotNull(rowKeyPrefix);
- DropRowRangeRequest protoRequest =
- DropRowRangeRequest.newBuilder()
- .setName(instanceName.toTableNameStr(tableId))
- .setDeleteAllDataFromTable(false)
- .setRowKeyPrefix(rowKeyPrefix)
- .build();
- return ApiFutureUtil.transformAndAdapt(
- tableDelegate.dropRowRangeAsync(protoRequest),
- new Function() {
- @Override
- public Void apply(Empty empty) {
- return null;
- }
- });
- }
-
- @Override
- public ApiFuture dropAllRowsAsync(String tableId) {
- DropRowRangeRequest protoRequest =
- DropRowRangeRequest.newBuilder()
- .setName(instanceName.toTableNameStr(tableId))
- .setDeleteAllDataFromTable(true)
- .build();
- return ApiFutureUtil.transformAndAdapt(
- tableDelegate.dropRowRangeAsync(protoRequest),
- new Function() {
- @Override
- public Void apply(Empty empty) {
- return null;
- }
- });
- }
-
- @Override
- public ApiFuture createBackupAsync(CreateBackupRequest request) {
- ListenableFuture backupAsync =
- tableDelegate.createBackupAsync(
- request.toProto(instanceName.getProjectId(), instanceName.getInstanceId()));
- Function function =
- new Function() {
- @Override
- public Backup apply(final Operation operation) {
- try {
- Future operationFuture =
- batchThreadPool.submit(
- new Callable() {
- @Override
- public Operation call() throws Exception {
- return tableDelegate.waitForOperation(operation);
- }
- });
-
- return Backup.fromProto(
- operationFuture
- .get()
- .getResponse()
- .unpack(com.google.bigtable.admin.v2.Backup.class));
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- throw new RuntimeException("Interrupted while waiting for operation to finish");
- } catch (ExecutionException | InvalidProtocolBufferException e) {
- throw new IllegalStateException(e);
- }
- }
- };
- return ApiFutureUtil.transformAndAdapt(backupAsync, function);
- }
-
- @Override
- public ApiFuture> listBackupsAsync(String clusterId) {
- BigtableClusterName clusterName = instanceName.toClusterName(clusterId);
- ListBackupsRequest request =
- ListBackupsRequest.newBuilder().setParent(clusterName.getClusterName()).build();
-
- // pagination is not required as page_size in the request is not set - everything will be
- // returned
- return ApiFutureUtil.transformAndAdapt(
- tableDelegate.listBackupsAsync(request),
- new Function>() {
- @Override
- public List apply(ListBackupsResponse response) {
- List backups = new ArrayList<>();
- for (com.google.bigtable.admin.v2.Backup backup : response.getBackupsList()) {
- backups.add(NameUtil.extractBackupIdFromBackupName(backup.getName()));
- }
- return backups;
- }
- });
- }
-
- @Override
- public ApiFuture deleteBackupAsync(String clusterId, String backupId) {
- BigtableClusterName clusterName = instanceName.toClusterName(clusterId);
- DeleteBackupRequest request =
- DeleteBackupRequest.newBuilder().setName(clusterName.toBackupName(backupId)).build();
- return ApiFutureUtil.transformAndAdapt(
- tableDelegate.deleteBackupAsync(request),
- new Function() {
- @Override
- public Void apply(Empty empty) {
- return null;
- }
- });
- }
-
- @Override
- public ApiFuture restoreTableAsync(RestoreTableRequest request) {
- return ApiFutureUtil.transformAndAdapt(
- tableDelegate.restoreTableAsync(
- request.toProto(instanceName.getProjectId(), instanceName.getInstanceId())),
- new Function() {
- @Override
- public RestoredTableResult apply(final Operation operation) {
- try {
- Future operationFuture =
- batchThreadPool.submit(
- new Callable() {
- @Override
- public Operation call() throws Exception {
- return tableDelegate.waitForOperation(operation);
- }
- });
-
- return new RestoredTableResult(
- Table.fromProto(
- operationFuture
- .get()
- .getResponse()
- .unpack(com.google.bigtable.admin.v2.Table.class)),
- operation
- .getMetadata()
- .unpack(com.google.bigtable.admin.v2.RestoreTableMetadata.class)
- .getOptimizeTableOperationName());
- } catch (IOException | InterruptedException | ExecutionException e) {
- throw new IllegalStateException(e);
- }
- }
- });
- }
-
- @Override
- public List listClusters(String instanceId) {
- ListClustersRequest request =
- ListClustersRequest.newBuilder().setParent(instanceName.getInstanceName()).build();
- ListClustersResponse listClustersResponse = instanceDelegate.listCluster(request);
- List protoList = listClustersResponse.getClustersList();
-
- List clusters = new ArrayList<>(protoList.size());
- for (com.google.bigtable.admin.v2.Cluster value : protoList) {
- clusters.add(Cluster.fromProto(value));
- }
- return clusters;
- }
-
- @Override
- public void close() {}
-}
diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BigtableClassicApi.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BigtableClassicApi.java
deleted file mode 100644
index a0e33d74f0..0000000000
--- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BigtableClassicApi.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright 2020 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.cloud.bigtable.hbase.wrappers.classic;
-
-import com.google.api.core.InternalApi;
-import com.google.cloud.bigtable.data.v2.internal.RequestContext;
-import com.google.cloud.bigtable.grpc.BigtableInstanceName;
-import com.google.cloud.bigtable.grpc.BigtableSession;
-import com.google.cloud.bigtable.hbase.wrappers.AdminClientWrapper;
-import com.google.cloud.bigtable.hbase.wrappers.BigtableApi;
-import com.google.cloud.bigtable.hbase.wrappers.BigtableHBaseSettings;
-import com.google.cloud.bigtable.hbase.wrappers.DataClientWrapper;
-import java.io.IOException;
-
-/** For internal use only - public for technical reasons. */
-@InternalApi("For internal usage only")
-public class BigtableClassicApi extends BigtableApi {
-
- private final BigtableSession bigtableSession;
- private final DataClientWrapper dataClientWrapper;
- private final AdminClientWrapper adminClientWrapper;
-
- public BigtableClassicApi(BigtableHBaseClassicSettings settings) throws IOException {
- this(settings, new BigtableSession(settings.getBigtableOptions()));
- }
-
- // This is a temporary constructor and will be removed once transition over new wrappers
- // are completed.
- public BigtableClassicApi(BigtableHBaseSettings settings, BigtableSession session)
- throws IOException {
- super(settings);
- this.bigtableSession = session;
-
- RequestContext requestContext =
- RequestContext.create(
- settings.getProjectId(),
- settings.getInstanceId(),
- session.getOptions().getAppProfileId());
- this.dataClientWrapper = new DataClientClassicApi(bigtableSession, requestContext);
-
- BigtableInstanceName instanceName =
- new BigtableInstanceName(settings.getProjectId(), settings.getInstanceId());
- this.adminClientWrapper =
- new AdminClientClassicApi(
- bigtableSession.getTableAdminClient(),
- instanceName,
- bigtableSession.getInstanceAdminClient());
- }
-
- @Override
- public AdminClientWrapper getAdminClient() {
- return adminClientWrapper;
- }
-
- @Override
- public DataClientWrapper getDataClient() {
- return dataClientWrapper;
- }
-
- @Override
- public void close() throws IOException {
- if (adminClientWrapper != null) {
- adminClientWrapper.close();
- }
- dataClientWrapper.close();
- bigtableSession.close();
- }
-}
diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BigtableHBaseClassicSettings.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BigtableHBaseClassicSettings.java
deleted file mode 100644
index 638345acf3..0000000000
--- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BigtableHBaseClassicSettings.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright 2020 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.cloud.bigtable.hbase.wrappers.classic;
-
-import com.google.api.core.InternalApi;
-import com.google.cloud.bigtable.config.BigtableOptions;
-import com.google.cloud.bigtable.hbase.BigtableOptionsFactory;
-import com.google.cloud.bigtable.hbase.wrappers.BigtableHBaseSettings;
-import java.io.IOException;
-import org.apache.hadoop.conf.Configuration;
-
-/** For internal use only - public for technical reasons. */
-@InternalApi("For internal usage only")
-public class BigtableHBaseClassicSettings extends BigtableHBaseSettings {
-
- private final BigtableOptions bigtableOptions;
-
- public BigtableHBaseClassicSettings(Configuration configuration) throws IOException {
- super(configuration);
- this.bigtableOptions = BigtableOptionsFactory.fromConfiguration(configuration);
- }
-
- @Override
- public String getDataHost() {
- return bigtableOptions.getDataHost();
- }
-
- @Override
- public String getAdminHost() {
- return bigtableOptions.getAdminHost();
- }
-
- @Override
- public int getPort() {
- return bigtableOptions.getPort();
- }
-
- @Override
- public int getBulkMaxRowCount() {
- return bigtableOptions.getBulkOptions().getBulkMaxRowKeyCount();
- }
-
- @Override
- public long getBatchingMaxRequestSize() {
- return bigtableOptions.getBulkOptions().getMaxMemory();
- }
-
- @Override
- public boolean isRetriesWithoutTimestampAllowed() {
- return bigtableOptions.getRetryOptions().allowRetriesWithoutTimestamp();
- }
-
- public BigtableOptions getBigtableOptions() {
- return bigtableOptions;
- }
-}
diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BulkMutationClassicApi.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BulkMutationClassicApi.java
deleted file mode 100644
index 5212e0c487..0000000000
--- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BulkMutationClassicApi.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2020 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.cloud.bigtable.hbase.wrappers.classic;
-
-import com.google.api.core.ApiFuture;
-import com.google.api.core.InternalApi;
-import com.google.bigtable.v2.MutateRowResponse;
-import com.google.cloud.bigtable.data.v2.models.RowMutationEntry;
-import com.google.cloud.bigtable.grpc.async.BulkMutation;
-import com.google.cloud.bigtable.hbase.wrappers.BulkMutationWrapper;
-import com.google.cloud.bigtable.util.ApiFutureUtil;
-import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
-import java.io.IOException;
-import javax.annotation.Nonnull;
-
-/** For internal use only - public for technical reasons. */
-@InternalApi("For internal usage only")
-public class BulkMutationClassicApi implements BulkMutationWrapper {
-
- private final BulkMutation delegate;
- private boolean isClosed = false;
-
- BulkMutationClassicApi(@Nonnull BulkMutation delegate) {
- this.delegate = delegate;
- }
-
- @Override
- public ApiFuture add(RowMutationEntry rowMutation) {
- Preconditions.checkState(!isClosed, "can't mutate when the bulk mutation is closed.");
- return ApiFutureUtil.transformAndAdapt(
- delegate.add(rowMutation.toProto()),
- new Function() {
- @Override
- public Void apply(MutateRowResponse response) {
- return null;
- }
- });
- }
-
- @Override
- public void sendUnsent() {
- delegate.sendUnsent();
- }
-
- @Override
- public void flush() throws InterruptedException {
- delegate.flush();
- }
-
- @Override
- public void close() throws IOException {
- isClosed = true;
- try {
- flush();
- } catch (InterruptedException interruptedException) {
- throw new IOException(interruptedException);
- }
- }
-}
diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BulkReadClassicApi.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BulkReadClassicApi.java
deleted file mode 100644
index 24e94abdf8..0000000000
--- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BulkReadClassicApi.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2020 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.cloud.bigtable.hbase.wrappers.classic;
-
-import com.google.api.core.ApiFunction;
-import com.google.api.core.ApiFuture;
-import com.google.api.core.ApiFutures;
-import com.google.api.core.InternalApi;
-import com.google.cloud.bigtable.data.v2.models.Filters;
-import com.google.cloud.bigtable.data.v2.models.Query;
-import com.google.cloud.bigtable.grpc.async.BulkRead;
-import com.google.cloud.bigtable.grpc.scanner.FlatRow;
-import com.google.cloud.bigtable.hbase.adapters.Adapters;
-import com.google.cloud.bigtable.hbase.wrappers.BulkReadWrapper;
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.MoreExecutors;
-import com.google.protobuf.ByteString;
-import javax.annotation.Nonnull;
-import org.apache.hadoop.hbase.client.Result;
-
-/** For internal use only - public for technical reasons. */
-@InternalApi("For internal usage only")
-public class BulkReadClassicApi implements BulkReadWrapper {
-
- private final BulkRead delegate;
- private final String tableId;
- private boolean isClosed = false;
-
- BulkReadClassicApi(@Nonnull BulkRead delegate, @Nonnull String tableId) {
- this.delegate = delegate;
- this.tableId = tableId;
- }
-
- @Override
- public void close() {
- isClosed = true;
- sendOutstanding();
- }
-
- @Override
- public ApiFuture add(ByteString rowKey, Filters.Filter filter) {
- Preconditions.checkState(!isClosed, "can't add request when the bulk read is closed.");
- Query query = Query.create(tableId).rowKey(rowKey);
- if (filter != null) {
- query.filter(filter);
- }
- return ApiFutures.transform(
- delegate.add(query),
- new ApiFunction() {
- @Override
- public Result apply(FlatRow flatRow) {
- return Adapters.FLAT_ROW_ADAPTER.adaptResponse(flatRow);
- }
- },
- MoreExecutors.directExecutor());
- }
-
- @Override
- public void sendOutstanding() {
- delegate.flush();
- }
-}
diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/DataClientClassicApi.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/DataClientClassicApi.java
deleted file mode 100644
index 33bd2c9e45..0000000000
--- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/DataClientClassicApi.java
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * Copyright 2020 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.cloud.bigtable.hbase.wrappers.classic;
-
-import com.google.api.core.ApiFunction;
-import com.google.api.core.ApiFuture;
-import com.google.api.core.ApiFutures;
-import com.google.api.core.InternalApi;
-import com.google.bigtable.v2.Cell;
-import com.google.bigtable.v2.CheckAndMutateRowRequest;
-import com.google.bigtable.v2.CheckAndMutateRowResponse;
-import com.google.bigtable.v2.Column;
-import com.google.bigtable.v2.Family;
-import com.google.bigtable.v2.MutateRowResponse;
-import com.google.bigtable.v2.ReadModifyWriteRowResponse;
-import com.google.bigtable.v2.Row;
-import com.google.bigtable.v2.SampleRowKeysRequest;
-import com.google.bigtable.v2.SampleRowKeysResponse;
-import com.google.cloud.bigtable.data.v2.internal.NameUtil;
-import com.google.cloud.bigtable.data.v2.internal.RequestContext;
-import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation;
-import com.google.cloud.bigtable.data.v2.models.Filters;
-import com.google.cloud.bigtable.data.v2.models.KeyOffset;
-import com.google.cloud.bigtable.data.v2.models.Query;
-import com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow;
-import com.google.cloud.bigtable.data.v2.models.RowMutation;
-import com.google.cloud.bigtable.grpc.BigtableDataClient;
-import com.google.cloud.bigtable.grpc.BigtableSession;
-import com.google.cloud.bigtable.grpc.BigtableTableName;
-import com.google.cloud.bigtable.grpc.scanner.FlatRow;
-import com.google.cloud.bigtable.grpc.scanner.ResultScanner;
-import com.google.cloud.bigtable.hbase.adapters.Adapters;
-import com.google.cloud.bigtable.hbase.adapters.read.RowCell;
-import com.google.cloud.bigtable.hbase.util.ByteStringer;
-import com.google.cloud.bigtable.hbase.util.TimestampConverter;
-import com.google.cloud.bigtable.hbase.wrappers.BulkMutationWrapper;
-import com.google.cloud.bigtable.hbase.wrappers.BulkReadWrapper;
-import com.google.cloud.bigtable.hbase.wrappers.DataClientWrapper;
-import com.google.cloud.bigtable.util.ApiFutureUtil;
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableList;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.MoreExecutors;
-import com.google.protobuf.ByteString;
-import io.grpc.stub.StreamObserver;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import javax.annotation.Nullable;
-import org.apache.hadoop.hbase.client.AbstractClientScanner;
-import org.apache.hadoop.hbase.client.Result;
-
-/** For internal use only - public for technical reasons. */
-@InternalApi("For internal usage only")
-public class DataClientClassicApi implements DataClientWrapper {
-
- private final BigtableSession session;
- private final BigtableDataClient delegate;
- private final RequestContext requestContext;
-
- DataClientClassicApi(BigtableSession session, RequestContext requestContext) {
- this.session = session;
- this.delegate = session.getDataClient();
- this.requestContext = requestContext;
- }
-
- @Override
- public BulkMutationWrapper createBulkMutation(String tableId) {
- BigtableTableName tableName =
- new BigtableTableName(
- NameUtil.formatTableName(
- requestContext.getProjectId(), requestContext.getInstanceId(), tableId));
- return new BulkMutationClassicApi(session.createBulkMutation(tableName));
- }
-
- @Override
- public BulkReadWrapper createBulkRead(String tableId) {
- BigtableTableName tableName =
- new BigtableTableName(
- NameUtil.formatTableName(
- requestContext.getProjectId(), requestContext.getInstanceId(), tableId));
- return new BulkReadClassicApi(session.createBulkRead(tableName), tableId);
- }
-
- @Override
- public ApiFuture mutateRowAsync(RowMutation rowMutation) {
- ListenableFuture response =
- delegate.mutateRowAsync(rowMutation.toProto(requestContext));
- return ApiFutureUtil.transformAndAdapt(
- response,
- new Function() {
- @Nullable
- @Override
- public Void apply(@Nullable MutateRowResponse mutateRowResponse) {
- return null;
- }
- });
- }
-
- @Override
- public ApiFuture readModifyWriteRowAsync(ReadModifyWriteRow readModifyWriteRow) {
- ListenableFuture response =
- delegate.readModifyWriteRowAsync(readModifyWriteRow.toProto(requestContext));
- return ApiFutureUtil.transformAndAdapt(
- response,
- new Function() {
- @Override
- public Result apply(ReadModifyWriteRowResponse response) {
- return transformRowToResult(response.getRow());
- }
- });
- }
-
- @Override
- public ApiFuture checkAndMutateRowAsync(ConditionalRowMutation conditionalRowMutation) {
- final CheckAndMutateRowRequest request = conditionalRowMutation.toProto(requestContext);
- final ListenableFuture response =
- delegate.checkAndMutateRowAsync(request);
- return ApiFutureUtil.transformAndAdapt(
- response,
- new Function() {
- @Override
- public Boolean apply(CheckAndMutateRowResponse checkAndMutateRowResponse) {
- return checkAndMutateRowResponse.getPredicateMatched();
- }
- });
- }
-
- @Override
- public ApiFuture> sampleRowKeysAsync(String tableId) {
- String fullTableName =
- NameUtil.formatTableName(
- requestContext.getProjectId(), requestContext.getInstanceId(), tableId);
- SampleRowKeysRequest requestProto =
- SampleRowKeysRequest.newBuilder().setTableName(fullTableName).build();
- ListenableFuture> responseProto =
- delegate.sampleRowKeysAsync(requestProto);
-
- return ApiFutureUtil.transformAndAdapt(
- responseProto,
- new Function, List>() {
- @Override
- public List apply(List rowKeysList) {
- ImmutableList.Builder keyOffsetBuilder = ImmutableList.builder();
- for (SampleRowKeysResponse rowKeys : rowKeysList) {
- keyOffsetBuilder.add(KeyOffset.create(rowKeys.getRowKey(), rowKeys.getOffsetBytes()));
- }
-
- return keyOffsetBuilder.build();
- }
- });
- }
-
- @Override
- public ApiFuture readRowAsync(String tableId, ByteString rowKey, Filters.Filter filter) {
- Query request = Query.create(tableId).rowKey(rowKey).limit(1L);
- if (filter != null) {
- request.filter(filter);
- }
-
- return ApiFutureUtil.transformAndAdapt(
- delegate.readFlatRowsAsync(request.toProto(requestContext)),
- new Function, Result>() {
- @Override
- public Result apply(List flatRows) {
- if (flatRows.isEmpty()) {
- return Result.EMPTY_RESULT;
- }
- return Adapters.FLAT_ROW_ADAPTER.adaptResponse(flatRows.get(0));
- }
- });
- }
-
- @Override
- public org.apache.hadoop.hbase.client.ResultScanner readRows(Query request) {
- final ResultScanner bigtableResultScanner =
- delegate.readFlatRows(request.toProto(requestContext));
-
- return new AbstractClientScanner() {
- @Override
- public Result next() throws IOException {
- FlatRow flatRow = bigtableResultScanner.next();
- if (flatRow == null) {
- // Null signals EOF.
- return null;
- }
- return Adapters.FLAT_ROW_ADAPTER.adaptResponse(flatRow);
- }
-
- @Override
- public void close() {
- try {
- bigtableResultScanner.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- // This is copied over form BigtableResultScannerAdapter.
- /**
- * This is an HBase concept that was added in HBase 1.0.2. It's not relevant for Cloud
- * Bigtable. It will not be called from the HBase code and should not be called by the user.
- */
- // Developers Note: Do not add @Override so that this can remain backwards compatible with
- // 1.0.1.
- public boolean renewLease() {
- throw new UnsupportedOperationException("renewLease");
- }
- };
- }
-
- @Override
- public ApiFuture> readRowsAsync(Query request) {
- return ApiFutures.transform(
- ApiFutureUtil.adapt(delegate.readFlatRowsAsync(request.toProto(requestContext))),
- new ApiFunction, List>() {
- @Override
- public List apply(List rows) {
- ImmutableList.Builder resultList = ImmutableList.builder();
- for (FlatRow flatRow : rows) {
- resultList.add(Adapters.FLAT_ROW_ADAPTER.adaptResponse(flatRow));
- }
- return resultList.build();
- }
- },
- MoreExecutors.directExecutor());
- }
-
- @Override
- public void readRowsAsync(Query request, final StreamObserver observer) {
- delegate.readFlatRows(
- request.toProto(requestContext),
- new StreamObserver() {
- @Override
- public void onNext(FlatRow flatRow) {
- observer.onNext(Adapters.FLAT_ROW_ADAPTER.adaptResponse(flatRow));
- }
-
- @Override
- public void onError(Throwable throwable) {
- observer.onError(throwable);
- }
-
- @Override
- public void onCompleted() {
- observer.onCompleted();
- }
- });
- }
-
- @Override
- public void close() throws IOException {
- session.close();
- }
-
- private static Result transformRowToResult(Row row) {
- List hbaseCells = new ArrayList<>();
- byte[] rowKeyBytes = ByteStringer.extract(row.getKey());
-
- for (Family family : row.getFamiliesList()) {
- byte[] familyBytes = ByteStringer.extract(family.getNameBytes());
-
- for (Column column : family.getColumnsList()) {
- byte[] qualifierBytes = ByteStringer.extract(column.getQualifier());
-
- for (Cell cell : column.getCellsList()) {
- hbaseCells.add(toRowCell(rowKeyBytes, familyBytes, qualifierBytes, cell));
- }
- }
- }
- return Result.create(hbaseCells);
- }
-
- private static RowCell toRowCell(byte[] rowKey, byte[] family, byte[] qualifier, Cell cell) {
- return new RowCell(
- rowKey,
- family,
- qualifier,
- TimestampConverter.bigtable2hbase(cell.getTimestampMicros()),
- ByteStringer.extract(cell.getValue()),
- cell.getLabelsList());
- }
-}
diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/veneer/metrics/MetricsApiTracerAdapter.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/veneer/metrics/MetricsApiTracerAdapter.java
index 8cdbf72192..f333893ed7 100644
--- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/veneer/metrics/MetricsApiTracerAdapter.java
+++ b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/veneer/metrics/MetricsApiTracerAdapter.java
@@ -16,8 +16,8 @@
package com.google.cloud.bigtable.hbase.wrappers.veneer.metrics;
import com.google.api.core.InternalApi;
-import com.google.api.gax.tracing.ApiTracer;
import com.google.api.gax.tracing.ApiTracerFactory.OperationType;
+import com.google.api.gax.tracing.BaseApiTracer;
import com.google.cloud.bigtable.metrics.BigtableClientMetrics;
import com.google.cloud.bigtable.metrics.BigtableClientMetrics.MetricLevel;
import com.google.cloud.bigtable.metrics.Counter;
@@ -35,7 +35,7 @@
* its lifecycle.
*/
@InternalApi
-public class MetricsApiTracerAdapter implements ApiTracer {
+public class MetricsApiTracerAdapter extends BaseApiTracer {
private final Timer firstResponseLatencyTimer =
BigtableClientMetrics.timer(MetricLevel.Info, "grpc.method.ReadRows.firstResponse.latency");
diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/org/apache/hadoop/hbase/client/AbstractBigtableConnection.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/org/apache/hadoop/hbase/client/AbstractBigtableConnection.java
index d17632cadc..df2c2a809f 100644
--- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/org/apache/hadoop/hbase/client/AbstractBigtableConnection.java
+++ b/bigtable-client-core-parent/bigtable-hbase/src/main/java/org/apache/hadoop/hbase/client/AbstractBigtableConnection.java
@@ -27,8 +27,6 @@
import com.google.cloud.bigtable.hbase.util.Logger;
import com.google.cloud.bigtable.hbase.wrappers.BigtableApi;
import com.google.cloud.bigtable.hbase.wrappers.BigtableHBaseSettings;
-import com.google.cloud.bigtable.hbase.wrappers.classic.BigtableHBaseClassicSettings;
-import com.google.cloud.bigtable.hbase.wrappers.veneer.BigtableHBaseVeneerSettings;
import com.google.common.base.MoreObjects;
import java.io.Closeable;
import java.io.IOException;
@@ -304,10 +302,7 @@ private void shutdownBatchPool() {
* @return a {@link com.google.cloud.bigtable.config.BigtableOptions} object.
*/
public BigtableOptions getOptions() {
- if (settings instanceof BigtableHBaseVeneerSettings) {
- throw new UnsupportedOperationException("veneer client does not support BigtableOptions");
- }
- return ((BigtableHBaseClassicSettings) settings).getBigtableOptions();
+ throw new UnsupportedOperationException("veneer client does not support BigtableOptions");
}
@Override
diff --git a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/classic/TestAdminClientClassicApi.java b/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/classic/TestAdminClientClassicApi.java
deleted file mode 100644
index 07acbd2c92..0000000000
--- a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/classic/TestAdminClientClassicApi.java
+++ /dev/null
@@ -1,282 +0,0 @@
-/*
- * Copyright 2020 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.cloud.bigtable.hbase.wrappers.classic;
-
-import static com.google.cloud.bigtable.admin.v2.models.GCRules.GCRULES;
-import static com.google.common.util.concurrent.Futures.immediateFuture;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import com.google.bigtable.admin.v2.*;
-import com.google.bigtable.admin.v2.Cluster;
-import com.google.bigtable.admin.v2.ColumnFamily;
-import com.google.bigtable.admin.v2.ListClustersResponse.Builder;
-import com.google.cloud.bigtable.admin.v2.internal.NameUtil;
-import com.google.cloud.bigtable.admin.v2.models.*;
-import com.google.cloud.bigtable.admin.v2.models.Backup;
-import com.google.cloud.bigtable.admin.v2.models.CreateBackupRequest;
-import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest;
-import com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest;
-import com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest;
-import com.google.cloud.bigtable.admin.v2.models.Table;
-import com.google.cloud.bigtable.grpc.BigtableClusterName;
-import com.google.cloud.bigtable.grpc.BigtableInstanceClient;
-import com.google.cloud.bigtable.grpc.BigtableInstanceName;
-import com.google.cloud.bigtable.grpc.BigtableTableAdminClient;
-import com.google.cloud.bigtable.hbase.wrappers.AdminClientWrapper;
-import com.google.common.collect.ImmutableList;
-import com.google.common.util.concurrent.Futures;
-import com.google.longrunning.Operation;
-import com.google.protobuf.Any;
-import com.google.protobuf.ByteString;
-import com.google.protobuf.Empty;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-import org.mockito.Mockito;
-import org.threeten.bp.Duration;
-
-@RunWith(JUnit4.class)
-public class TestAdminClientClassicApi {
-
- private static final String PROJECT_ID = "fake-project-id";
- private static final String INSTANCE_ID = "fake-instance-id";
- private static final BigtableInstanceName INSTANCE_NAME =
- new BigtableInstanceName(PROJECT_ID, INSTANCE_ID);
-
- private static final String TABLE_ID = "fake-Table-id";
- private static final String CLUSTER_ID = "fake-cluster-id";
- private static final String TABLE_NAME =
- NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID);
-
- private static final String COLUMN_FAMILY = "myColumnFamily";
- private static final String ROW_KEY_PREFIX = "row-key-val";
- private static final String UPDATE_FAMILY = "update-family";
- private static final String BACKUP_ID = "fake-backup-id";
- private static final BigtableClusterName CLUSTER_NAME = INSTANCE_NAME.toClusterName(CLUSTER_ID);
- private static final String BACKUP_NAME = CLUSTER_NAME.toBackupName(BACKUP_ID);
-
- private BigtableTableAdminClient tableDelegate;
- private BigtableInstanceClient instanceDelegate;
-
- private AdminClientWrapper adminClientWrapper;
-
- @Before
- public void setUp() {
- tableDelegate = Mockito.mock(BigtableTableAdminClient.class);
- instanceDelegate = Mockito.mock(BigtableInstanceClient.class);
- adminClientWrapper = new AdminClientClassicApi(tableDelegate, INSTANCE_NAME, instanceDelegate);
- }
-
- @Test
- public void testCreateTableAsync() throws Exception {
- CreateTableRequest request = CreateTableRequest.of(TABLE_ID);
-
- when(tableDelegate.createTableAsync(request.toProto(PROJECT_ID, INSTANCE_ID)))
- .thenReturn(immediateFuture(createTableData()));
-
- assertEquals(
- Table.fromProto(createTableData()), adminClientWrapper.createTableAsync(request).get());
- verify(tableDelegate).createTableAsync(request.toProto(PROJECT_ID, INSTANCE_ID));
- }
-
- @Test
- public void testGetTableAsync() throws Exception {
- GetTableRequest request = GetTableRequest.newBuilder().setName(TABLE_NAME).build();
- when(tableDelegate.getTableAsync(request)).thenReturn(immediateFuture(createTableData()));
-
- assertEquals(
- Table.fromProto(createTableData()), adminClientWrapper.getTableAsync(TABLE_ID).get());
- verify(tableDelegate).getTableAsync(request);
- }
-
- @Test
- public void testListTablesAsync() throws Exception {
- ImmutableList tableIdList =
- ImmutableList.of("test-table-1", "test-table-2", "test-table-3");
- ListTablesRequest request =
- ListTablesRequest.newBuilder().setParent(INSTANCE_NAME.toString()).build();
- ListTablesResponse.Builder builder = ListTablesResponse.newBuilder();
- builder.addTablesBuilder().setName(INSTANCE_NAME.toTableNameStr("test-table-1")).build();
- builder.addTablesBuilder().setName(INSTANCE_NAME.toTableNameStr("test-table-2")).build();
- builder.addTablesBuilder().setName(INSTANCE_NAME.toTableNameStr("test-table-3")).build();
- when(tableDelegate.listTablesAsync(request)).thenReturn(immediateFuture(builder.build()));
-
- assertEquals(tableIdList, adminClientWrapper.listTablesAsync().get());
- verify(tableDelegate).listTablesAsync(request);
- }
-
- @Test
- public void testDeleteTableAsync() throws ExecutionException, InterruptedException {
- DeleteTableRequest request = DeleteTableRequest.newBuilder().setName(TABLE_NAME).build();
- when(tableDelegate.deleteTableAsync(request))
- .thenReturn(immediateFuture(Empty.newBuilder().build()));
- adminClientWrapper.deleteTableAsync(TABLE_ID).get();
-
- verify(tableDelegate).deleteTableAsync(request);
- }
-
- @Test
- public void testModifyFamiliesAsync() throws Exception {
- ModifyColumnFamiliesRequest request =
- ModifyColumnFamiliesRequest.of(TABLE_ID)
- .addFamily(COLUMN_FAMILY, GCRULES.maxVersions(1))
- .updateFamily(UPDATE_FAMILY, GCRULES.maxAge(Duration.ofHours(100)));
-
- when(tableDelegate.modifyColumnFamilyAsync(request.toProto(PROJECT_ID, INSTANCE_ID)))
- .thenReturn(immediateFuture(createTableData()));
- Future response = adminClientWrapper.modifyFamiliesAsync(request);
-
- assertEquals(Table.fromProto(createTableData()), response.get());
- verify(tableDelegate).modifyColumnFamilyAsync(request.toProto(PROJECT_ID, INSTANCE_ID));
- }
-
- @Test
- public void dropRowRangeAsyncForDeleteByPrefix() throws ExecutionException, InterruptedException {
- ByteString rowKey = ByteString.copyFrom(new byte[] {0, -32, 122, 13});
- DropRowRangeRequest request =
- DropRowRangeRequest.newBuilder()
- .setName(TABLE_NAME)
- .setDeleteAllDataFromTable(false)
- .setRowKeyPrefix(rowKey)
- .build();
-
- when(tableDelegate.dropRowRangeAsync(request))
- .thenReturn(immediateFuture(Empty.newBuilder().build()));
- adminClientWrapper.dropRowRangeAsync(TABLE_ID, rowKey).get();
-
- verify(tableDelegate).dropRowRangeAsync(request);
- }
-
- @Test
- public void dropRowRangeAsyncForTruncate() throws ExecutionException, InterruptedException {
- DropRowRangeRequest request =
- DropRowRangeRequest.newBuilder()
- .setName(TABLE_NAME)
- .setDeleteAllDataFromTable(true)
- .build();
-
- when(tableDelegate.dropRowRangeAsync(request))
- .thenReturn(immediateFuture(Empty.newBuilder().build()));
- adminClientWrapper.dropAllRowsAsync(TABLE_ID).get();
-
- verify(tableDelegate).dropRowRangeAsync(request);
- }
-
- @Test
- public void listClusters() {
- ListClustersRequest request =
- ListClustersRequest.newBuilder().setParent(INSTANCE_NAME.getInstanceName()).build();
- Builder builder = ListClustersResponse.newBuilder();
- Cluster cluster = Cluster.newBuilder().setName(CLUSTER_ID).build();
- builder.addClusters(cluster);
- ListClustersResponse listClustersResponse = builder.build();
- when(instanceDelegate.listCluster(request)).thenReturn(listClustersResponse);
-
- List expected = new ArrayList<>();
- expected.add(com.google.cloud.bigtable.admin.v2.models.Cluster.fromProto(cluster));
-
- List actual =
- adminClientWrapper.listClusters(INSTANCE_ID);
- assertEquals(expected, actual);
- }
-
- @Test
- public void testCreateBackupAsync() throws Exception {
- CreateBackupRequest request =
- CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID).setSourceTableId(TABLE_NAME);
- com.google.bigtable.admin.v2.CreateBackupRequest requestProto =
- request.toProto(PROJECT_ID, INSTANCE_ID);
- Operation op =
- Operation.newBuilder()
- .setMetadata(Any.pack(CreateBackupMetadata.getDefaultInstance()))
- .setResponse(
- Any.pack(
- com.google.bigtable.admin.v2.Backup.newBuilder()
- .setName(BACKUP_NAME)
- .setSourceTable(TABLE_NAME)
- .build()))
- .build();
- when(tableDelegate.waitForOperation(op)).thenReturn(op);
- when(tableDelegate.createBackupAsync(requestProto)).thenReturn(Futures.immediateFuture(op));
- Future actualResponse = adminClientWrapper.createBackupAsync(request);
- assertEquals(BACKUP_ID, actualResponse.get().getId());
- verify(tableDelegate).createBackupAsync(requestProto);
- }
-
- @Test
- public void testListBackupsAsync() throws Exception {
- ListBackupsRequest request =
- ListBackupsRequest.newBuilder().setParent(CLUSTER_NAME.toString()).build();
- ListBackupsResponse response =
- ListBackupsResponse.newBuilder()
- .addBackups(
- com.google.bigtable.admin.v2.Backup.newBuilder()
- .setName(BACKUP_NAME)
- .setSourceTable(TABLE_NAME)
- .build())
- .build();
- when(tableDelegate.listBackupsAsync(request)).thenReturn(Futures.immediateFuture(response));
- Future> actualResponse = adminClientWrapper.listBackupsAsync(CLUSTER_ID);
- assertEquals(response.getBackupsCount(), actualResponse.get().size());
- verify(tableDelegate).listBackupsAsync(request);
- }
-
- @Test
- public void testDeleteBackupAsync() {
- DeleteBackupRequest request = DeleteBackupRequest.newBuilder().setName(BACKUP_NAME).build();
- when(tableDelegate.deleteBackupAsync(request))
- .thenReturn(Futures.immediateFuture(Empty.getDefaultInstance()));
- adminClientWrapper.deleteBackupAsync(CLUSTER_ID, BACKUP_ID);
- verify(tableDelegate).deleteBackupAsync(request);
- }
-
- @Test
- public void testRestoreTableAsync() throws Exception {
- RestoreTableRequest request =
- RestoreTableRequest.of(CLUSTER_ID, BACKUP_ID).setTableId(TABLE_ID);
- com.google.bigtable.admin.v2.RestoreTableRequest requestProto =
- request.toProto(PROJECT_ID, INSTANCE_ID);
- Operation op =
- Operation.newBuilder()
- .setMetadata(Any.pack(RestoreTableMetadata.newBuilder().setName(BACKUP_NAME).build()))
- .setResponse(
- Any.pack(
- com.google.bigtable.admin.v2.Table.newBuilder().setName(TABLE_NAME).build()))
- .build();
- when(tableDelegate.waitForOperation(op)).thenReturn(op);
- when(tableDelegate.restoreTableAsync(requestProto)).thenReturn(Futures.immediateFuture(op));
- Future actualResponse = adminClientWrapper.restoreTableAsync(request);
- assertEquals(TABLE_ID, actualResponse.get().getTable().getId());
- verify(tableDelegate).restoreTableAsync(requestProto);
- }
-
- private static com.google.bigtable.admin.v2.Table createTableData() {
- GCRules.GCRule gcRule = GCRULES.maxVersions(1);
- ColumnFamily columnFamily = ColumnFamily.newBuilder().setGcRule(gcRule.toProto()).build();
-
- return com.google.bigtable.admin.v2.Table.newBuilder()
- .setName(TABLE_NAME)
- .putColumnFamilies(COLUMN_FAMILY, columnFamily)
- .build();
- }
-}
diff --git a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/classic/TestBigtableClassicApi.java b/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/classic/TestBigtableClassicApi.java
deleted file mode 100644
index 57f009ed98..0000000000
--- a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/classic/TestBigtableClassicApi.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright 2020 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.cloud.bigtable.hbase.wrappers.classic;
-
-import static com.google.cloud.bigtable.admin.v2.internal.NameUtil.extractTableIdFromTableName;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-
-import com.google.bigtable.admin.v2.BigtableTableAdminGrpc;
-import com.google.bigtable.admin.v2.DeleteTableRequest;
-import com.google.bigtable.v2.BigtableGrpc;
-import com.google.bigtable.v2.ReadRowsRequest;
-import com.google.bigtable.v2.ReadRowsResponse;
-import com.google.cloud.bigtable.data.v2.models.Query;
-import com.google.cloud.bigtable.grpc.BigtableSession;
-import com.google.cloud.bigtable.hbase.BigtableOptionsFactory;
-import com.google.cloud.bigtable.hbase.wrappers.BigtableApi;
-import com.google.cloud.bigtable.hbase.wrappers.BigtableHBaseSettings;
-import com.google.cloud.bigtable.test.helper.TestServerBuilder;
-import com.google.common.collect.Queues;
-import com.google.protobuf.Empty;
-import io.grpc.Server;
-import io.grpc.stub.StreamObserver;
-import java.io.IOException;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.TimeUnit;
-import org.apache.hadoop.conf.Configuration;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-@RunWith(JUnit4.class)
-public class TestBigtableClassicApi {
-
- private static final String TEST_PROJECT_ID = "fake-project-id";
- private static final String TEST_INSTANCE_ID = "fake-instance-id";
- private static final String ROW_KEY = "test-row-key";
- private static final String TABLE_ID = "test-table-id";
-
- private static FakeDataService fakeDataService = new FakeDataService();
- private static FakeAdminService fakeAdminService = new FakeAdminService();
- private static Server server;
-
- private BigtableHBaseSettings bigtableHBaseSettings;
- private BigtableApi bigtableApi;
-
- @BeforeClass
- public static void setUpServer() throws IOException {
- server =
- TestServerBuilder.newInstance()
- .addService(fakeDataService)
- .addService(fakeAdminService)
- .buildAndStart();
- }
-
- @AfterClass
- public static void tearDownServer() throws InterruptedException {
- if (server != null) {
- server.shutdownNow();
- server.awaitTermination();
- }
- }
-
- @Before
- public void setUp() throws IOException {
- Configuration configuration = new Configuration(false);
- configuration.set(BigtableOptionsFactory.PROJECT_ID_KEY, TEST_PROJECT_ID);
- configuration.set(BigtableOptionsFactory.INSTANCE_ID_KEY, TEST_INSTANCE_ID);
- configuration.set(BigtableOptionsFactory.BIGTABLE_NULL_CREDENTIAL_ENABLE_KEY, "true");
- configuration.set(BigtableOptionsFactory.BIGTABLE_DATA_CHANNEL_COUNT_KEY, "1");
- configuration.set(
- BigtableOptionsFactory.BIGTABLE_EMULATOR_HOST_KEY, "localhost:" + server.getPort());
- configuration.setBoolean(BigtableOptionsFactory.BIGTABLE_USE_GCJ_CLIENT, false);
- bigtableHBaseSettings = BigtableHBaseClassicSettings.create(configuration);
- bigtableApi = BigtableApi.create(bigtableHBaseSettings);
- }
-
- @After
- public void tearDown() throws Exception {
- bigtableApi.close();
- }
-
- @Test
- public void testWithAlreadyBuildBigtableSession() throws Exception {
- BigtableHBaseClassicSettings settings = (BigtableHBaseClassicSettings) bigtableHBaseSettings;
-
- try (BigtableSession session = new BigtableSession(settings.getBigtableOptions());
- BigtableApi bigtableApi = new BigtableClassicApi(settings, session)) {
-
- assertSame(settings, bigtableApi.getBigtableHBaseSettings());
-
- bigtableApi.getAdminClient().deleteTableAsync(TABLE_ID).get();
- DeleteTableRequest deleteTableRequest = fakeAdminService.popLastRequest();
- assertEquals(TABLE_ID, extractTableIdFromTableName(deleteTableRequest.getName()));
-
- Query query = Query.create(TABLE_ID).rowKey(ROW_KEY);
- bigtableApi.getDataClient().readRowsAsync(query);
- ReadRowsRequest request = fakeDataService.popLastRequest();
- assertEquals(ROW_KEY, request.getRows().getRowKeys(0).toStringUtf8());
- }
- }
-
- @Test
- public void testAdminClient() throws Exception {
- assertTrue(bigtableApi.getAdminClient() instanceof AdminClientClassicApi);
-
- bigtableApi.getAdminClient().deleteTableAsync(TABLE_ID).get();
- DeleteTableRequest deleteTableRequest = fakeAdminService.popLastRequest();
- assertEquals(TABLE_ID, extractTableIdFromTableName(deleteTableRequest.getName()));
- }
-
- @Test
- public void testDataClient() throws Exception {
- assertTrue(bigtableApi.getDataClient() instanceof DataClientClassicApi);
-
- Query query = Query.create(TABLE_ID).rowKey(ROW_KEY);
- bigtableApi.getDataClient().readRowsAsync(query);
- ReadRowsRequest request = fakeDataService.popLastRequest();
- assertEquals(ROW_KEY, request.getRows().getRowKeys(0).toStringUtf8());
- }
-
- @Test
- public void testBigtableHBaseSettings() {
- assertSame(bigtableHBaseSettings, bigtableApi.getBigtableHBaseSettings());
- }
-
- private static class FakeDataService extends BigtableGrpc.BigtableImplBase {
- final BlockingQueue