}
/**
+ * 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.
* @param conf
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.
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;
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;
}
/**
+ * 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
*/