From ab2f8343a9810c9ec8b0920215a0897e7f671aba Mon Sep 17 00:00:00 2001 From: Nanda kumar Date: Tue, 3 Jul 2018 00:51:16 +0530 Subject: [PATCH] HDDS-206. Ozone shell command doesn't respect KSM port set in ozone-site.xml. Contributed by Shashikant Banerjee. --- .../ozone/client/OzoneClientFactory.java | 13 +++++----- .../org/apache/hadoop/ozone/KsmUtils.java | 24 ++++++++++++------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneClientFactory.java b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneClientFactory.java index dae94aa956..3085b0daa6 100644 --- a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneClientFactory.java +++ b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneClientFactory.java @@ -21,6 +21,7 @@ import com.google.common.base.Preconditions; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.ozone.KsmUtils; import org.apache.hadoop.ozone.client.protocol.ClientProtocol; import org.apache.hadoop.ozone.client.rest.RestClient; import org.apache.hadoop.ozone.client.rpc.RpcClient; @@ -37,10 +38,7 @@ .OZONE_CLIENT_PROTOCOL; import static org.apache.hadoop.ozone.ksm.KSMConfigKeys .OZONE_KSM_HTTP_ADDRESS_KEY; -import static org.apache.hadoop.ozone.ksm.KSMConfigKeys - .OZONE_KSM_HTTP_BIND_PORT_DEFAULT; import static org.apache.hadoop.ozone.ksm.KSMConfigKeys.OZONE_KSM_ADDRESS_KEY; -import static org.apache.hadoop.ozone.ksm.KSMConfigKeys.OZONE_KSM_PORT_DEFAULT; /** * Factory class to create different types of OzoneClients. @@ -108,8 +106,9 @@ public static OzoneClient getClient(Configuration config) */ public static OzoneClient getRpcClient(String ksmHost) throws IOException { - return getRpcClient(ksmHost, OZONE_KSM_PORT_DEFAULT, - new OzoneConfiguration()); + Configuration config = new OzoneConfiguration(); + int port = KsmUtils.getKsmRpcPort(config); + return getRpcClient(ksmHost, port, config); } /** @@ -185,7 +184,9 @@ public static OzoneClient getRpcClient(Configuration config) */ public static OzoneClient getRestClient(String ksmHost) throws IOException { - return getRestClient(ksmHost, OZONE_KSM_HTTP_BIND_PORT_DEFAULT); + Configuration config = new OzoneConfiguration(); + int port = KsmUtils.getKsmRestPort(config); + return getRestClient(ksmHost, port, config); } /** diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/KsmUtils.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/KsmUtils.java index ebada1c6e4..1025963aa8 100644 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/KsmUtils.java +++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/KsmUtils.java @@ -26,6 +26,8 @@ import static org.apache.hadoop.hdds.HddsUtils.getHostNameFromConfigKeys; import static org.apache.hadoop.hdds.HddsUtils.getPortNumberFromConfigKeys; import static org.apache.hadoop.ozone.ksm.KSMConfigKeys.OZONE_KSM_ADDRESS_KEY; +import static org.apache.hadoop.ozone.ksm.KSMConfigKeys.OZONE_KSM_HTTP_ADDRESS_KEY; +import static org.apache.hadoop.ozone.ksm.KSMConfigKeys.OZONE_KSM_HTTP_BIND_PORT_DEFAULT; import static org.apache.hadoop.ozone.ksm.KSMConfigKeys .OZONE_KSM_BIND_HOST_DEFAULT; import static org.apache.hadoop.ozone.ksm.KSMConfigKeys.OZONE_KSM_PORT_DEFAULT; @@ -49,13 +51,9 @@ public static InetSocketAddress getKsmAddress( final Optional host = getHostNameFromConfigKeys(conf, OZONE_KSM_ADDRESS_KEY); - // If no port number is specified then we'll just try the defaultBindPort. - final Optional port = getPortNumberFromConfigKeys(conf, - OZONE_KSM_ADDRESS_KEY); - return NetUtils.createSocketAddr( host.or(OZONE_KSM_BIND_HOST_DEFAULT) + ":" + - port.or(OZONE_KSM_PORT_DEFAULT)); + getKsmRpcPort(conf)); } /** @@ -76,12 +74,22 @@ public static InetSocketAddress getKsmAddressForClients( " details on configuring Ozone."); } + return NetUtils.createSocketAddr( + host.get() + ":" + getKsmRpcPort(conf)); + } + + public static int getKsmRpcPort(Configuration conf) { // If no port number is specified then we'll just try the defaultBindPort. final Optional port = getPortNumberFromConfigKeys(conf, OZONE_KSM_ADDRESS_KEY); - - return NetUtils.createSocketAddr( - host.get() + ":" + port.or(OZONE_KSM_PORT_DEFAULT)); + return port.or(OZONE_KSM_PORT_DEFAULT); } + public static int getKsmRestPort(Configuration conf) { + // If no port number is specified then we'll just try the default + // HTTP BindPort. + final Optional port = + getPortNumberFromConfigKeys(conf, OZONE_KSM_HTTP_ADDRESS_KEY); + return port.or(OZONE_KSM_HTTP_BIND_PORT_DEFAULT); + } }