Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bigtable-hbase-2.x-hadoop incompatible with hbase-shaded-client 2.x #2773

Merged
merged 4 commits into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,13 @@
import io.grpc.Status;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.ClusterStatus;
import org.apache.hadoop.hbase.HBaseIOException;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HRegionInfo;
Expand Down Expand Up @@ -685,18 +682,6 @@ public void deleteColumn(final String tableName, final String columnName) throws
deleteColumn(TableName.valueOf(tableName), Bytes.toBytes(columnName));
}

/** {@inheritDoc} */
@Override
public ClusterStatus getClusterStatus() throws IOException {
return new ClusterStatus() {
@Override
public Collection<ServerName> getServers() {
// TODO(sduskis): Point the server name to options.getServerName()
return Collections.emptyList();
}
};
}

/** {@inheritDoc} */
@Override
public Configuration getConfiguration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

import com.google.api.core.InternalApi;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
import org.apache.hadoop.hbase.ClusterStatus;
import org.apache.hadoop.hbase.ProcedureInfo;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableExistsException;
Expand Down Expand Up @@ -258,4 +261,14 @@ public boolean[] setSplitOrMergeEnabled(boolean arg0, boolean arg1, MasterSwitch
throws IOException {
throw new UnsupportedOperationException("setSplitOrMergeEnabled"); // TODO
}

@Override
public ClusterStatus getClusterStatus() throws IOException {
return new ClusterStatus() {
@Override
public Collection<ServerName> getServers() {
return Collections.emptyList();
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.google.cloud.bigtable.hbase1_x;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import com.google.bigtable.admin.v2.BigtableTableAdminGrpc;
import com.google.bigtable.admin.v2.DropRowRangeRequest;
Expand All @@ -34,6 +35,7 @@
import java.net.ServerSocket;
import java.util.concurrent.ArrayBlockingQueue;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.ClusterStatus;
import org.apache.hadoop.hbase.TableName;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -129,4 +131,11 @@ public void onMessage(ReqT message) {
};
}
}

@Test
public void testGetClusterStatus() throws IOException {
// test to verify compatibility between 1x and 2x
ClusterStatus status = admin.getClusterStatus();
assertNotNull(status);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -32,6 +33,7 @@
import org.apache.hadoop.hbase.CacheEvictionStats;
import org.apache.hadoop.hbase.ClusterMetrics;
import org.apache.hadoop.hbase.ClusterMetrics.Option;
import org.apache.hadoop.hbase.ClusterStatus;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.NamespaceDescriptor;
Expand Down Expand Up @@ -833,4 +835,19 @@ public Future<Void> updateReplicationPeerConfigAsync(
String s, ReplicationPeerConfig replicationPeerConfig) {
throw new UnsupportedOperationException("updateReplicationPeerConfigAsync"); // TODO
}

@Override
public ClusterStatus getClusterStatus() throws IOException {
return new ClusterStatus(
"hbaseVersion",
"clusterid",
new HashMap(),
new ArrayList(),
null,
new ArrayList(),
new ArrayList(),
new String[0],
false,
-1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.hbase2_x;

import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertNull;
import static junit.framework.TestCase.assertTrue;
import static org.mockito.Mockito.mock;

import com.google.cloud.bigtable.hbase.wrappers.BigtableApi;
import java.io.IOException;
import org.apache.hadoop.hbase.ClusterStatus;
import org.apache.hadoop.hbase.client.AbstractBigtableConnection;
import org.junit.Test;
import org.mockito.Mockito;

public class BigtableAdminTest {

@Test
public void testGetClusterStatus() throws IOException {
// test to verify compatibility between 1x and 2x
AbstractBigtableConnection connectionMock = mock(AbstractBigtableConnection.class);
BigtableApi bigtableApi = mock(BigtableApi.class);
Mockito.doReturn(bigtableApi).when(connectionMock).getBigtableApi();
BigtableAdmin bigtableAdmin = new BigtableAdmin(connectionMock);

ClusterStatus status = bigtableAdmin.getClusterStatus();
assertNotNull(status);
assertEquals("hbaseVersion", status.getHBaseVersion());
assertEquals("clusterid", status.getClusterId());
assertTrue(status.getServersName().isEmpty());
assertTrue(status.getDeadServerNames().isEmpty());
assertNull(status.getMaster());
assertTrue(status.getBackupMasterNames().isEmpty());
assertTrue(status.getRegionStatesInTransition().isEmpty());
assertEquals(0, status.getMasterCoprocessors().length);
assertFalse(status.getBalancerOn());
assertEquals(-1, status.getMasterInfoPort());
}
}