Skip to content

Commit 5cf8699

Browse files
authored
[HUDI-5027] Replace hardcoded hbase config keys with constant variables (#6946)
1 parent fa04e81 commit 5cf8699

2 files changed

Lines changed: 24 additions & 12 deletions

File tree

hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/index/hbase/SparkHoodieHBaseIndex.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@
8585

8686
import scala.Tuple2;
8787

88+
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION;
89+
import static org.apache.hadoop.hbase.HConstants.ZOOKEEPER_QUORUM;
90+
import static org.apache.hadoop.hbase.HConstants.ZOOKEEPER_ZNODE_PARENT;
91+
import static org.apache.hadoop.hbase.HConstants.ZOOKEEPER_CLIENT_PORT;
92+
import static org.apache.hadoop.hbase.security.SecurityConstants.MASTER_KRB_PRINCIPAL;
93+
import static org.apache.hadoop.hbase.security.SecurityConstants.REGIONSERVER_KRB_PRINCIPAL;
94+
import static org.apache.hadoop.hbase.security.User.HBASE_SECURITY_AUTHORIZATION_CONF_KEY;
95+
import static org.apache.hadoop.hbase.security.User.HBASE_SECURITY_CONF_KEY;
96+
8897
/**
8998
* Hoodie Index implementation backed by HBase.
9099
*/
@@ -145,22 +154,22 @@ public HBaseIndexQPSResourceAllocator createQPSResourceAllocator(HoodieWriteConf
145154
private Connection getHBaseConnection() {
146155
Configuration hbaseConfig = HBaseConfiguration.create();
147156
String quorum = config.getHbaseZkQuorum();
148-
hbaseConfig.set("hbase.zookeeper.quorum", quorum);
157+
hbaseConfig.set(ZOOKEEPER_QUORUM, quorum);
149158
String zkZnodeParent = config.getHBaseZkZnodeParent();
150159
if (zkZnodeParent != null) {
151-
hbaseConfig.set("zookeeper.znode.parent", zkZnodeParent);
160+
hbaseConfig.set(ZOOKEEPER_ZNODE_PARENT, zkZnodeParent);
152161
}
153162
String port = String.valueOf(config.getHbaseZkPort());
154-
hbaseConfig.set("hbase.zookeeper.property.clientPort", port);
163+
hbaseConfig.set(ZOOKEEPER_CLIENT_PORT, port);
155164

156165
try {
157166
String authentication = config.getHBaseIndexSecurityAuthentication();
158167
if (authentication.equals("kerberos")) {
159-
hbaseConfig.set("hbase.security.authentication", "kerberos");
160-
hbaseConfig.set("hadoop.security.authentication", "kerberos");
161-
hbaseConfig.set("hbase.security.authorization", "true");
162-
hbaseConfig.set("hbase.regionserver.kerberos.principal", config.getHBaseIndexRegionserverPrincipal());
163-
hbaseConfig.set("hbase.master.kerberos.principal", config.getHBaseIndexMasterPrincipal());
168+
hbaseConfig.set(HBASE_SECURITY_CONF_KEY, "kerberos");
169+
hbaseConfig.set(HADOOP_SECURITY_AUTHENTICATION, "kerberos");
170+
hbaseConfig.set(HBASE_SECURITY_AUTHORIZATION_CONF_KEY, "true");
171+
hbaseConfig.set(REGIONSERVER_KRB_PRINCIPAL, config.getHBaseIndexRegionserverPrincipal());
172+
hbaseConfig.set(MASTER_KRB_PRINCIPAL, config.getHBaseIndexMasterPrincipal());
164173

165174
String principal = config.getHBaseIndexKerberosUserPrincipal();
166175
String keytab = SparkFiles.get(config.getHBaseIndexKerberosUserKeytab());

hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/index/hbase/TestSparkHoodieHBaseIndex.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787
import static org.mockito.Mockito.times;
8888
import static org.mockito.Mockito.verify;
8989
import static org.mockito.Mockito.when;
90+
import static org.apache.hadoop.hbase.HConstants.ZOOKEEPER_CLIENT_PORT;
91+
import static org.apache.hadoop.hbase.HConstants.ZOOKEEPER_ZNODE_PARENT;
92+
import static org.apache.hadoop.hbase.HConstants.ZOOKEEPER_QUORUM;
9093

9194
/**
9295
* Note :: HBaseTestingUtility is really flaky with issues where the HbaseMiniCluster fails to shutdown across tests,
@@ -111,7 +114,7 @@ public class TestSparkHoodieHBaseIndex extends SparkClientFunctionalTestHarness
111114
public static void init() throws Exception {
112115
// Initialize HbaseMiniCluster
113116
hbaseConfig = HBaseConfiguration.create();
114-
hbaseConfig.set("zookeeper.znode.parent", "/hudi-hbase-test");
117+
hbaseConfig.set(ZOOKEEPER_ZNODE_PARENT, "/hudi-hbase-test");
115118

116119
utility = new HBaseTestingUtility(hbaseConfig);
117120
utility.startMiniCluster();
@@ -816,10 +819,10 @@ private HoodieWriteConfig.Builder getConfigBuilder(int hbaseIndexBatchSize, bool
816819
.forTable("test-trip-table")
817820
.withIndexConfig(HoodieIndexConfig.newBuilder().withIndexType(HoodieIndex.IndexType.HBASE)
818821
.withHBaseIndexConfig(new HoodieHBaseIndexConfig.Builder()
819-
.hbaseZkPort(Integer.parseInt(hbaseConfig.get("hbase.zookeeper.property.clientPort")))
822+
.hbaseZkPort(Integer.parseInt(hbaseConfig.get(ZOOKEEPER_CLIENT_PORT)))
820823
.hbaseIndexPutBatchSizeAutoCompute(true)
821-
.hbaseZkZnodeParent(hbaseConfig.get("zookeeper.znode.parent", ""))
822-
.hbaseZkQuorum(hbaseConfig.get("hbase.zookeeper.quorum")).hbaseTableName(TABLE_NAME)
824+
.hbaseZkZnodeParent(hbaseConfig.get(ZOOKEEPER_ZNODE_PARENT, ""))
825+
.hbaseZkQuorum(hbaseConfig.get(ZOOKEEPER_QUORUM)).hbaseTableName(TABLE_NAME)
823826
.hbaseIndexUpdatePartitionPath(updatePartitionPath)
824827
.hbaseIndexRollbackSync(rollbackSync)
825828
.hbaseIndexGetBatchSize(hbaseIndexBatchSize).build())

0 commit comments

Comments
 (0)