diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java index ce482ed022e7..af4796057ce5 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java @@ -171,6 +171,11 @@ public enum OperationStatusCode { /** Configuration key for master web API port */ public static final String MASTER_INFO_PORT = "hbase.master.info.port"; + /** Configuration key for the list of master host:ports **/ + public static final String MASTER_ADDRS_KEY = "hbase.master.addrs"; + + public static final String MASTER_ADDRS_DEFAULT = "localhost:" + DEFAULT_MASTER_PORT; + /** Parameter name for the master type being backup (waits for primary to go inactive). */ public static final String MASTER_TYPE_BACKUP = "hbase.master.backup"; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java index d3e62dc39001..1fdd464a2484 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java @@ -173,6 +173,14 @@ public LocalHBaseCluster(final Configuration conf, final int noMasters, for (int i = 0; i < noMasters; i++) { addMaster(new Configuration(conf), i); } + + // Populate the master address host ports in the config. This is needed if a master based + // registry is configured for client metadata services (HBASE-18095) + List masterHostPorts = new ArrayList<>(); + getMasters().forEach(masterThread -> + masterHostPorts.add(masterThread.getMaster().getServerName().getAddress().toString())); + conf.set(HConstants.MASTER_ADDRS_KEY, String.join(",", masterHostPorts)); + // Start the HRegionServers. this.regionServerClass = (Class)conf.getClass(HConstants.REGION_SERVER_IMPL, @@ -220,7 +228,7 @@ public JVMClusterUtil.MasterThread addMaster() throws IOException { } public JVMClusterUtil.MasterThread addMaster(Configuration c, final int index) - throws IOException { + throws IOException { // Create each master with its own Configuration instance so each has // its Connection instance rather than share (see HBASE_INSTANCES down in // the guts of ConnectionManager. diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java index 76a23706c53f..b2a616a25af8 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -447,10 +447,14 @@ public void testOverridingOfDefaultPorts() throws Exception { HBaseTestingUtility htu = new HBaseTestingUtility(defaultConfig); try { MiniHBaseCluster defaultCluster = htu.startMiniCluster(); + final String masterHostPort = + defaultCluster.getMaster().getServerName().getAddress().toString(); assertNotEquals(HConstants.DEFAULT_MASTER_INFOPORT, defaultCluster.getConfiguration().getInt(HConstants.MASTER_INFO_PORT, 0)); assertNotEquals(HConstants.DEFAULT_REGIONSERVER_INFOPORT, defaultCluster.getConfiguration().getInt(HConstants.REGIONSERVER_INFO_PORT, 0)); + assertEquals(masterHostPort, + defaultCluster.getConfiguration().get(HConstants.MASTER_ADDRS_KEY)); } finally { htu.shutdownMiniCluster(); } @@ -464,10 +468,14 @@ public void testOverridingOfDefaultPorts() throws Exception { htu = new HBaseTestingUtility(altConfig); try { MiniHBaseCluster customCluster = htu.startMiniCluster(); + final String masterHostPort = + customCluster.getMaster().getServerName().getAddress().toString(); assertEquals(nonDefaultMasterInfoPort, - customCluster.getConfiguration().getInt(HConstants.MASTER_INFO_PORT, 0)); + customCluster.getConfiguration().getInt(HConstants.MASTER_INFO_PORT, 0)); assertEquals(nonDefaultRegionServerPort, customCluster.getConfiguration().getInt(HConstants.REGIONSERVER_INFO_PORT, 0)); + assertEquals(masterHostPort, + customCluster.getConfiguration().get(HConstants.MASTER_ADDRS_KEY)); } finally { htu.shutdownMiniCluster(); }