Skip to content

Commit 1792c60

Browse files
authored
fix: bigtable-hbase-2.x-hadoop incompatible with hbase-shaded-client 2.x (#2773)
* fix: bigtable-hbase-2.x-hadoop incompatible with hbase-shaded-client 2.x * test: unit tests for BigtableAdmin.getClusterStatus() * fix: bigtable-hbase-2.x-hadoop incompatible with hbase-shaded-client 2.x * fix: copyright header
1 parent 5340db5 commit 1792c60

5 files changed

Lines changed: 94 additions & 15 deletions

File tree

bigtable-client-core-parent/bigtable-hbase/src/main/java/org/apache/hadoop/hbase/client/AbstractBigtableAdmin.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,13 @@
4141
import io.grpc.Status;
4242
import java.io.IOException;
4343
import java.util.ArrayList;
44-
import java.util.Collection;
45-
import java.util.Collections;
4644
import java.util.LinkedList;
4745
import java.util.List;
4846
import java.util.Map;
4947
import java.util.Set;
5048
import java.util.regex.Pattern;
5149
import javax.annotation.Nullable;
5250
import org.apache.hadoop.conf.Configuration;
53-
import org.apache.hadoop.hbase.ClusterStatus;
5451
import org.apache.hadoop.hbase.HBaseIOException;
5552
import org.apache.hadoop.hbase.HColumnDescriptor;
5653
import org.apache.hadoop.hbase.HRegionInfo;
@@ -685,18 +682,6 @@ public void deleteColumn(final String tableName, final String columnName) throws
685682
deleteColumn(TableName.valueOf(tableName), Bytes.toBytes(columnName));
686683
}
687684

688-
/** {@inheritDoc} */
689-
@Override
690-
public ClusterStatus getClusterStatus() throws IOException {
691-
return new ClusterStatus() {
692-
@Override
693-
public Collection<ServerName> getServers() {
694-
// TODO(sduskis): Point the server name to options.getServerName()
695-
return Collections.emptyList();
696-
}
697-
};
698-
}
699-
700685
/** {@inheritDoc} */
701686
@Override
702687
public Configuration getConfiguration() {

bigtable-hbase-1.x-parent/bigtable-hbase-1.x/src/main/java/com/google/cloud/bigtable/hbase1_x/BigtableAdmin.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717

1818
import com.google.api.core.InternalApi;
1919
import java.io.IOException;
20+
import java.util.Collection;
21+
import java.util.Collections;
2022
import java.util.List;
2123
import java.util.concurrent.Future;
2224
import java.util.regex.Pattern;
25+
import org.apache.hadoop.hbase.ClusterStatus;
2326
import org.apache.hadoop.hbase.ProcedureInfo;
2427
import org.apache.hadoop.hbase.ServerName;
2528
import org.apache.hadoop.hbase.TableExistsException;
@@ -258,4 +261,14 @@ public boolean[] setSplitOrMergeEnabled(boolean arg0, boolean arg1, MasterSwitch
258261
throws IOException {
259262
throw new UnsupportedOperationException("setSplitOrMergeEnabled"); // TODO
260263
}
264+
265+
@Override
266+
public ClusterStatus getClusterStatus() throws IOException {
267+
return new ClusterStatus() {
268+
@Override
269+
public Collection<ServerName> getServers() {
270+
return Collections.emptyList();
271+
}
272+
};
273+
}
261274
}

bigtable-hbase-1.x-parent/bigtable-hbase-1.x/src/test/java/com/google/cloud/bigtable/hbase1_x/TestBigtableAdmin.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.google.cloud.bigtable.hbase1_x;
1717

1818
import static org.junit.Assert.assertEquals;
19+
import static org.junit.Assert.assertNotNull;
1920

2021
import com.google.bigtable.admin.v2.BigtableTableAdminGrpc;
2122
import com.google.bigtable.admin.v2.DropRowRangeRequest;
@@ -34,6 +35,7 @@
3435
import java.net.ServerSocket;
3536
import java.util.concurrent.ArrayBlockingQueue;
3637
import org.apache.hadoop.conf.Configuration;
38+
import org.apache.hadoop.hbase.ClusterStatus;
3739
import org.apache.hadoop.hbase.TableName;
3840
import org.junit.After;
3941
import org.junit.Before;
@@ -129,4 +131,11 @@ public void onMessage(ReqT message) {
129131
};
130132
}
131133
}
134+
135+
@Test
136+
public void testGetClusterStatus() throws IOException {
137+
// test to verify compatibility between 1x and 2x
138+
ClusterStatus status = admin.getClusterStatus();
139+
assertNotNull(status);
140+
}
132141
}

bigtable-hbase-2.x-parent/bigtable-hbase-2.x/src/main/java/com/google/cloud/bigtable/hbase2_x/BigtableAdmin.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.ArrayList;
2323
import java.util.Arrays;
2424
import java.util.EnumSet;
25+
import java.util.HashMap;
2526
import java.util.List;
2627
import java.util.Map;
2728
import java.util.Set;
@@ -32,6 +33,7 @@
3233
import org.apache.hadoop.hbase.CacheEvictionStats;
3334
import org.apache.hadoop.hbase.ClusterMetrics;
3435
import org.apache.hadoop.hbase.ClusterMetrics.Option;
36+
import org.apache.hadoop.hbase.ClusterStatus;
3537
import org.apache.hadoop.hbase.HRegionInfo;
3638
import org.apache.hadoop.hbase.HTableDescriptor;
3739
import org.apache.hadoop.hbase.NamespaceDescriptor;
@@ -833,4 +835,19 @@ public Future<Void> updateReplicationPeerConfigAsync(
833835
String s, ReplicationPeerConfig replicationPeerConfig) {
834836
throw new UnsupportedOperationException("updateReplicationPeerConfigAsync"); // TODO
835837
}
838+
839+
@Override
840+
public ClusterStatus getClusterStatus() throws IOException {
841+
return new ClusterStatus(
842+
"hbaseVersion",
843+
"clusterid",
844+
new HashMap(),
845+
new ArrayList(),
846+
null,
847+
new ArrayList(),
848+
new ArrayList(),
849+
new String[0],
850+
false,
851+
-1);
852+
}
836853
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.cloud.bigtable.hbase2_x;
17+
18+
import static junit.framework.TestCase.assertEquals;
19+
import static junit.framework.TestCase.assertFalse;
20+
import static junit.framework.TestCase.assertNotNull;
21+
import static junit.framework.TestCase.assertNull;
22+
import static junit.framework.TestCase.assertTrue;
23+
import static org.mockito.Mockito.mock;
24+
25+
import com.google.cloud.bigtable.hbase.wrappers.BigtableApi;
26+
import java.io.IOException;
27+
import org.apache.hadoop.hbase.ClusterStatus;
28+
import org.apache.hadoop.hbase.client.AbstractBigtableConnection;
29+
import org.junit.Test;
30+
import org.mockito.Mockito;
31+
32+
public class BigtableAdminTest {
33+
34+
@Test
35+
public void testGetClusterStatus() throws IOException {
36+
// test to verify compatibility between 1x and 2x
37+
AbstractBigtableConnection connectionMock = mock(AbstractBigtableConnection.class);
38+
BigtableApi bigtableApi = mock(BigtableApi.class);
39+
Mockito.doReturn(bigtableApi).when(connectionMock).getBigtableApi();
40+
BigtableAdmin bigtableAdmin = new BigtableAdmin(connectionMock);
41+
42+
ClusterStatus status = bigtableAdmin.getClusterStatus();
43+
assertNotNull(status);
44+
assertEquals("hbaseVersion", status.getHBaseVersion());
45+
assertEquals("clusterid", status.getClusterId());
46+
assertTrue(status.getServersName().isEmpty());
47+
assertTrue(status.getDeadServerNames().isEmpty());
48+
assertNull(status.getMaster());
49+
assertTrue(status.getBackupMasterNames().isEmpty());
50+
assertTrue(status.getRegionStatesInTransition().isEmpty());
51+
assertEquals(0, status.getMasterCoprocessors().length);
52+
assertFalse(status.getBalancerOn());
53+
assertEquals(-1, status.getMasterInfoPort());
54+
}
55+
}

0 commit comments

Comments
 (0)