HDDS-1096. OzoneManager#loadOMHAConfigs should use default ports in case port is not defined. Contributed by Hanisha Koneru.

This commit is contained in:
Márton Elek 2019-02-14 14:02:16 +01:00
parent dfe0f42835
commit 7a57974f1f
3 changed files with 90 additions and 1 deletions

View File

@ -79,6 +79,24 @@ public final class OmUtils {
getOmRpcPort(conf);
}
/**
* Retrieve the socket address that is used by OM as specified by the confKey.
* Return null if the specified conf key is not set.
* @param conf configuration
* @param confKey configuration key to lookup address from
* @return Target InetSocketAddress for the OM RPC server.
*/
public static String getOmRpcAddress(Configuration conf, String confKey) {
final Optional<String> host = getHostNameFromConfigKeys(conf, confKey);
if (host.isPresent()) {
return host.get() + ":" + getOmRpcPort(conf, confKey);
} else {
// The specified confKey is not set
return null;
}
}
/**
* Retrieve the socket address that should be used by clients to connect
* to OM.
@ -108,6 +126,19 @@ public final class OmUtils {
return port.orElse(OZONE_OM_PORT_DEFAULT);
}
/**
* Retrieve the port that is used by OM as specified by the confKey.
* Return default port if port is not specified in the confKey.
* @param conf configuration
* @param confKey configuration key to lookup address from
* @return Port on which OM RPC server will listen on
*/
public static int getOmRpcPort(Configuration conf, String confKey) {
// If no port number is specified then we'll just try the defaultBindPort.
final Optional<Integer> port = getPortNumberFromConfigKeys(conf, confKey);
return port.orElse(OZONE_OM_PORT_DEFAULT);
}
public static int getOmRestPort(Configuration conf) {
// If no port number is specified then we'll just try the default
// HTTP BindPort.

View File

@ -20,6 +20,7 @@ package org.apache.hadoop.ozone.om;
import org.apache.hadoop.hdds.HddsConfigKeys;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.ozone.MiniOzoneCluster;
import org.apache.hadoop.ozone.OmUtils;
import org.apache.hadoop.ozone.OzoneConfigKeys;
@ -34,6 +35,7 @@ import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
@ -94,6 +96,57 @@ public class TestOzoneManagerConfiguration {
cluster.waitForClusterToBeReady();
}
/**
* Test that if no OM address is specified, then the OM rpc server
* is started on localhost.
*/
@Test
public void testNoConfiguredOMAddress() throws Exception {
startCluster();
om = cluster.getOzoneManager();
Assert.assertTrue(NetUtils.isLocalAddress(
om.getOmRpcServerAddr().getAddress()));
}
/**
* Test that if only the hostname is specified for om address, then the
* default port is used.
*/
@Test
public void testDefaultPortIfNotSpecified() throws Exception {
String omNode1Id = "omNode1";
String omNode2Id = "omNode2";
String omNodesKeyValue = omNode1Id + "," + omNode2Id;
conf.set(OMConfigKeys.OZONE_OM_NODES_KEY, omNodesKeyValue);
String omNode1RpcAddrKey = getOMAddrKeyWithSuffix(null, omNode1Id);
String omNode2RpcAddrKey = getOMAddrKeyWithSuffix(null, omNode2Id);
conf.set(omNode1RpcAddrKey, "0.0.0.0");
conf.set(omNode2RpcAddrKey, "122.0.0.122");
// Set omNode1 as the current node. omNode1 address does not have a port
// number specified. So the default port should be taken.
conf.set(OMConfigKeys.OZONE_OM_NODE_ID_KEY, omNode1Id);
startCluster();
om = cluster.getOzoneManager();
Assert.assertEquals("0.0.0.0",
om.getOmRpcServerAddr().getHostName());
Assert.assertEquals(OMConfigKeys.OZONE_OM_PORT_DEFAULT,
om.getOmRpcServerAddr().getPort());
// Verify that the 2nd OMs address stored in the current OM also has the
// default port as the port is not specified
InetSocketAddress omNode2Addr = om.getPeerNodes().get(0).getRpcAddress();
Assert.assertEquals("122.0.0.122", omNode2Addr.getHostString());
Assert.assertEquals(OMConfigKeys.OZONE_OM_PORT_DEFAULT,
omNode2Addr.getPort());
}
/**
* Test a single node OM service (default setting for MiniOzoneCluster).
* @throws Exception

View File

@ -360,7 +360,7 @@ public final class OzoneManager extends ServiceRuntimeInfoImpl
}
String rpcAddrKey = OmUtils.addKeySuffixes(OZONE_OM_ADDRESS_KEY,
serviceId, nodeId);
String rpcAddrStr = conf.get(rpcAddrKey);
String rpcAddrStr = OmUtils.getOmRpcAddress(conf, rpcAddrKey);
if (rpcAddrStr == null) {
continue;
}
@ -2407,4 +2407,9 @@ public final class OzoneManager extends ServiceRuntimeInfoImpl
public String getOMServiceId() {
return omNodeDetails.getOMServiceId();
}
@VisibleForTesting
public List<OMNodeDetails> getPeerNodes() {
return peerNodes;
}
}