From 6939d98476c6a8a091ae9130229fe3bc2790d927 Mon Sep 17 00:00:00 2001 From: Prabhu Joseph Date: Thu, 29 Aug 2019 18:36:56 +0530 Subject: [PATCH] YARN-9801. Support Https RM Url from SchedConfCli. --- .../hadoop/yarn/client/cli/SchedConfCLI.java | 51 +++++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/SchedConfCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/SchedConfCLI.java index be54553..a3852ff 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/SchedConfCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/SchedConfCLI.java @@ -22,6 +22,8 @@ import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource.Builder; +import com.sun.jersey.client.urlconnection.HttpURLConnectionFactory; +import com.sun.jersey.client.urlconnection.URLConnectionClientHandler; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.GnuParser; import org.apache.commons.cli.MissingArgumentException; @@ -30,6 +32,9 @@ import org.apache.hadoop.classification.InterfaceStability.Unstable; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; +import org.apache.hadoop.security.authentication.client.AuthenticatedURL; +import org.apache.hadoop.security.authentication.client.AuthenticationException; +import org.apache.hadoop.security.ssl.SSLFactory; import org.apache.hadoop.util.Tool; import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.webapp.dao.QueueConfigInfo; @@ -39,6 +44,9 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response.Status; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -137,9 +145,43 @@ public int run(String[] args) throws Exception { this::updateSchedulerConfOnRMNode, updateInfo); } + + private Client createWebServiceClient(SSLFactory clientSslFactory) { + Client webServiceClient = new Client(new URLConnectionClientHandler( + new HttpURLConnectionFactory() { + @Override + public HttpURLConnection getHttpURLConnection(URL url) + throws IOException { + AuthenticatedURL.Token token = new AuthenticatedURL.Token(); + AuthenticatedURL aUrl; + HttpURLConnection conn = null; + try { + if (clientSslFactory != null) { + clientSslFactory.init(); + aUrl = new AuthenticatedURL(null, clientSslFactory); + } else { + aUrl = new AuthenticatedURL(); + } + conn = aUrl.openConnection(url, token); + } catch (Exception e) { + throw new IOException(e); + } + return conn; + } + })); + webServiceClient.setChunkedEncodingSize(null); + return webServiceClient; + } + + private int updateSchedulerConfOnRMNode(String webAppAddress, SchedConfUpdateInfo updateInfo) throws Exception { - Client webServiceClient = Client.create(); + Configuration conf = getConf(); + SSLFactory clientSslFactory = null; + if (YarnConfiguration.useHttps(conf)) { + clientSslFactory = new SSLFactory(SSLFactory.Mode.CLIENT, conf); + } + Client webServiceClient = createWebServiceClient(clientSslFactory); ClientResponse response = null; try { Builder builder = webServiceClient.resource(webAppAddress) @@ -164,7 +206,12 @@ private int updateSchedulerConfOnRMNode(String webAppAddress, if (response != null) { response.close(); } - webServiceClient.destroy(); + if (webServiceClient != null) { + webServiceClient.destroy(); + } + if (clientSslFactory != null) { + clientSslFactory.destroy(); + } } } -- 2.7.4 (Apple Git-66)