Skip to content

Commit 99cd757

Browse files
committed
YARN-9801. SchedConfCli does not work wiwith https mode. Contributed by Prabhu Joseph
1 parent 425a6c8 commit 99cd757

File tree

1 file changed

+58
-4
lines changed
  • hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli

1 file changed

+58
-4
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/SchedConfCLI.java

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.sun.jersey.api.client.ClientResponse;
2424
import com.sun.jersey.api.client.WebResource;
2525
import com.sun.jersey.api.client.WebResource.Builder;
26+
import com.sun.jersey.client.urlconnection.HttpURLConnectionFactory;
27+
import com.sun.jersey.client.urlconnection.URLConnectionClientHandler;
2628
import org.apache.commons.cli.CommandLine;
2729
import org.apache.commons.cli.GnuParser;
2830
import org.apache.commons.cli.MissingArgumentException;
@@ -31,6 +33,8 @@
3133
import org.apache.hadoop.classification.InterfaceStability.Unstable;
3234
import org.apache.hadoop.conf.Configuration;
3335
import org.apache.hadoop.conf.Configured;
36+
import org.apache.hadoop.security.authentication.client.AuthenticatedURL;
37+
import org.apache.hadoop.security.ssl.SSLFactory;
3438
import org.apache.hadoop.security.UserGroupInformation;
3539
import org.apache.hadoop.util.Tool;
3640
import org.apache.hadoop.yarn.conf.YarnConfiguration;
@@ -41,6 +45,9 @@
4145

4246
import javax.ws.rs.core.MediaType;
4347
import javax.ws.rs.core.Response.Status;
48+
import java.io.IOException;
49+
import java.net.HttpURLConnection;
50+
import java.net.URL;
4451
import java.util.ArrayList;
4552
import java.util.Arrays;
4653
import java.util.HashMap;
@@ -156,7 +163,12 @@ public int run(String[] args) throws Exception {
156163
@VisibleForTesting
157164
int formatSchedulerConf(String webAppAddress, WebResource resource)
158165
throws Exception {
159-
Client webServiceClient = Client.create();
166+
Configuration conf = getConf();
167+
SSLFactory clientSslFactory = null;
168+
if (YarnConfiguration.useHttps(conf)) {
169+
clientSslFactory = new SSLFactory(SSLFactory.Mode.CLIENT, conf);
170+
}
171+
Client webServiceClient = createWebServiceClient(clientSslFactory);
160172
ClientResponse response = null;
161173
resource = (resource != null) ? resource :
162174
webServiceClient.resource(webAppAddress);
@@ -194,14 +206,24 @@ int formatSchedulerConf(String webAppAddress, WebResource resource)
194206
if (response != null) {
195207
response.close();
196208
}
197-
webServiceClient.destroy();
209+
if (webServiceClient != null) {
210+
webServiceClient.destroy();
211+
}
212+
if (clientSslFactory != null) {
213+
clientSslFactory.destroy();
214+
}
198215
}
199216
}
200217

201218
@VisibleForTesting
202219
int updateSchedulerConfOnRMNode(String webAppAddress,
203220
SchedConfUpdateInfo updateInfo) throws Exception {
204-
Client webServiceClient = Client.create();
221+
Configuration conf = getConf();
222+
SSLFactory clientSslFactory = null;
223+
if (YarnConfiguration.useHttps(conf)) {
224+
clientSslFactory = new SSLFactory(SSLFactory.Mode.CLIENT, conf);
225+
}
226+
Client webServiceClient = createWebServiceClient(clientSslFactory);
205227
ClientResponse response = null;
206228
WebResource resource = webServiceClient.resource(webAppAddress);
207229

@@ -236,10 +258,42 @@ int updateSchedulerConfOnRMNode(String webAppAddress,
236258
if (response != null) {
237259
response.close();
238260
}
239-
webServiceClient.destroy();
261+
if (webServiceClient != null) {
262+
webServiceClient.destroy();
263+
}
264+
if (clientSslFactory != null) {
265+
clientSslFactory.destroy();
266+
}
240267
}
241268
}
242269

270+
private Client createWebServiceClient(SSLFactory clientSslFactory) {
271+
Client webServiceClient = new Client(new URLConnectionClientHandler(
272+
new HttpURLConnectionFactory() {
273+
@Override
274+
public HttpURLConnection getHttpURLConnection(URL url)
275+
throws IOException {
276+
AuthenticatedURL.Token token = new AuthenticatedURL.Token();
277+
AuthenticatedURL aUrl;
278+
HttpURLConnection conn = null;
279+
try {
280+
if (clientSslFactory != null) {
281+
clientSslFactory.init();
282+
aUrl = new AuthenticatedURL(null, clientSslFactory);
283+
} else {
284+
aUrl = new AuthenticatedURL();
285+
}
286+
conn = aUrl.openConnection(url, token);
287+
} catch (Exception e) {
288+
throw new IOException(e);
289+
}
290+
return conn;
291+
}
292+
}));
293+
webServiceClient.setChunkedEncodingSize(null);
294+
return webServiceClient;
295+
}
296+
243297

244298
@VisibleForTesting
245299
void addQueues(String args, SchedConfUpdateInfo updateInfo) {

0 commit comments

Comments
 (0)