Index: src/test/java/org/apache/hadoop/hbase/regionserver/TestMasterSettingRegionServerAddress.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/regionserver/TestMasterSettingRegionServerAddress.java (revision 0) +++ src/test/java/org/apache/hadoop/hbase/regionserver/TestMasterSettingRegionServerAddress.java (revision 0) @@ -0,0 +1,100 @@ +/** + * Copyright 2011 The Apache Software Foundation + * + * 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 + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.hadoop.hbase.regionserver; + +import java.io.IOException; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.HMsg; +import org.apache.hadoop.hbase.HRegionInfo; +import org.apache.hadoop.hbase.HServerAddress; +import org.apache.hadoop.hbase.HServerInfo; +import org.apache.hadoop.hbase.master.HMaster; +import org.apache.hadoop.io.MapWritable; +import org.apache.zookeeper.KeeperException; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + + +public class TestMasterSettingRegionServerAddress { + private static final Log LOG = + LogFactory.getLog(TestMasterSettingRegionServerAddress.class); + private static final HBaseTestingUtility TESTING_UTIL = + new HBaseTestingUtility(); + private static final String WHAT_TO_USE_INSTEAD = "example.org:10000"; + + @BeforeClass public static void beforeClass() throws Exception { + TESTING_UTIL.startMiniZKCluster(); + } + + @AfterClass public static void afterClass() throws IOException { + TESTING_UTIL.shutdownMiniZKCluster(); + } + + static class TestHMaster extends HMaster { + public TestHMaster(final Configuration c) + throws IOException, KeeperException, InterruptedException { + super(c); + } + + @Override + public HMsg[] regionServerReport(HServerInfo serverInfo, HMsg[] msgs, + HRegionInfo[] mostLoadedRegions) + throws IOException { + LOG.info("Heartbeat: " + serverInfo.getServerName()); + Assert.assertEquals(WHAT_TO_USE_INSTEAD, serverInfo.getHostnamePort()); + return super.regionServerReport(serverInfo, msgs, mostLoadedRegions); + } + + @Override + public MapWritable regionServerStartup(HServerInfo serverInfo, + long serverCurrentTime) + throws IOException {/* + MapWritable mw = + super.regionServerStartup(serverInfo, serverCurrentTime); + HServerAddress hsa = + (HServerAddress)mw.get(HConstants.HBASE_REGIONSERVER_ADDRESS); + HServerAddress instead = new HServerAddress(WHAT_TO_USE_INSTEAD); + LOG.info("reportForDuty returning " + hsa.toString() + + " but changed to " + instead.toString()); + mw.put(HConstants.HBASE_REGIONSERVER_ADDRESS, instead); + return mw; + */ + return null; + } + } + + @Test public void testDifferentAddress() + throws IOException, KeeperException, InterruptedException { + HMaster master = new TestHMaster(TESTING_UTIL.getConfiguration()); + master.start(); + while(!master.isMasterRunning()) Thread.sleep(100); + HRegionServer hrs = new HRegionServer(TESTING_UTIL.getConfiguration()); + Thread t = new Thread(hrs); + t.start(); + while(!master.isInitialized()) Thread.sleep(100); + } +} Index: src/main/java/org/apache/hadoop/hbase/HConstants.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/HConstants.java (revision 1057488) +++ src/main/java/org/apache/hadoop/hbase/HConstants.java (working copy) @@ -21,6 +21,7 @@ import org.apache.hadoop.hbase.ipc.HRegionInterface; import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.io.Text; /** * HConstants holds a bunch of HBase-related constants @@ -364,6 +365,9 @@ public static final String HBASE_MASTER_LOGCLEANER_PLUGINS = "hbase.master.logcleaner.plugins"; + public static final Text HBASE_REGIONSERVER_ADDRESS = + new Text("hbase.regionserver.address"); + private HConstants() { // Can't be instantiated with this ctor. } Index: src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (revision 1057488) +++ src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (working copy) @@ -839,13 +839,14 @@ * * @param c Extra configuration. */ - protected void handleReportForDutyResponse(final MapWritable c) throws IOException { + protected void handleReportForDutyResponse(final MapWritable c) + throws IOException { try { for (Map.Entry e : c.entrySet()) { String key = e.getKey().toString(); // Use the address the master passed us - if (key.equals("hbase.regionserver.address")) { + if (key.equals(HConstants.HBASE_REGIONSERVER_ADDRESS.toString())) { HServerAddress hsa = (HServerAddress) e.getValue(); LOG.info("Master passed us address to use. Was=" + this.serverInfo.getServerAddress() + ", Now=" + hsa.toString()); Index: src/main/java/org/apache/hadoop/hbase/master/HMaster.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/master/HMaster.java (revision 1057488) +++ src/main/java/org/apache/hadoop/hbase/master/HMaster.java (working copy) @@ -618,8 +618,7 @@ this.serverManager.regionServerStartup(serverInfo, serverCurrentTime); // Send back some config info MapWritable mw = createConfigurationSubset(); - mw.put(new Text("hbase.regionserver.address"), - serverInfo.getServerAddress()); + mw.put(HConstants.HBASE_REGIONSERVER_ADDRESS, serverInfo.getServerAddress()); return mw; }