Skip to content

Commit 7836bc4

Browse files
Prabhu JosephPrabhu Joseph
authored andcommitted
YARN-9606. Set sslfactory for AuthenticatedURL() while creating LogsCLI#webServiceClient.
Contributed by Bilwa S T. Reviewed by Brahma Reddy Battula.
1 parent 6ce295b commit 7836bc4

File tree

3 files changed

+76
-100
lines changed

3 files changed

+76
-100
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@
119119
<dependency>
120120
<groupId>org.apache.hadoop</groupId>
121121
<artifactId>hadoop-yarn-server-common</artifactId>
122-
<scope>test</scope>
123122
</dependency>
124123
<!-- 'mvn dependency:analyze' fails to detect use of this dependency -->
125124
<dependency>

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

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,13 @@
2727
import com.sun.jersey.api.client.WebResource;
2828
import com.sun.jersey.api.client.WebResource.Builder;
2929
import com.sun.jersey.api.client.filter.ClientFilter;
30-
import com.sun.jersey.client.urlconnection.HttpURLConnectionFactory;
31-
import com.sun.jersey.client.urlconnection.URLConnectionClientHandler;
3230
import java.io.File;
3331
import java.io.IOException;
3432
import java.io.InputStream;
3533
import java.io.PrintStream;
3634
import java.net.ConnectException;
37-
import java.net.HttpURLConnection;
3835
import java.net.SocketException;
3936
import java.net.SocketTimeoutException;
40-
import java.net.URL;
4137
import java.util.ArrayList;
4238
import java.util.Arrays;
4339
import java.util.Collection;
@@ -68,8 +64,6 @@
6864
import org.apache.hadoop.conf.Configuration;
6965
import org.apache.hadoop.conf.Configured;
7066
import org.apache.hadoop.security.UserGroupInformation;
71-
import org.apache.hadoop.security.authentication.client.AuthenticatedURL;
72-
import org.apache.hadoop.security.authentication.client.AuthenticationException;
7367
import org.apache.hadoop.util.Tool;
7468
import org.apache.hadoop.yarn.api.records.ApplicationAttemptReport;
7569
import org.apache.hadoop.yarn.api.records.ApplicationId;
@@ -87,6 +81,7 @@
8781
import org.apache.hadoop.yarn.logaggregation.LogCLIHelpers;
8882
import org.apache.hadoop.yarn.logaggregation.LogToolUtils;
8983
import org.apache.hadoop.yarn.server.metrics.AppAttemptMetricsConstants;
84+
import org.apache.hadoop.yarn.server.webapp.WebServiceClient;
9085
import org.apache.hadoop.yarn.util.Apps;
9186
import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
9287
import org.apache.hadoop.yarn.webapp.util.YarnWebServiceUtils;
@@ -122,7 +117,7 @@ public class LogsCLI extends Configured implements Tool {
122117

123118
private PrintStream outStream = System.out;
124119
private YarnClient yarnClient = null;
125-
private Client webServiceClient = null;
120+
private Client client = null;
126121

127122
private static final int DEFAULT_MAX_RETRIES = 30;
128123
private static final long DEFAULT_RETRY_INTERVAL = 1000;
@@ -139,28 +134,14 @@ public class LogsCLI extends Configured implements Tool {
139134
@Override
140135
public int run(String[] args) throws Exception {
141136
try {
142-
webServiceClient = new Client(new URLConnectionClientHandler(
143-
new HttpURLConnectionFactory() {
144-
@Override
145-
public HttpURLConnection getHttpURLConnection(URL url)
146-
throws IOException {
147-
AuthenticatedURL.Token token = new AuthenticatedURL.Token();
148-
HttpURLConnection conn = null;
149-
try {
150-
conn = new AuthenticatedURL().openConnection(url, token);
151-
} catch (AuthenticationException e) {
152-
throw new IOException(e);
153-
}
154-
return conn;
155-
}
156-
}));
137+
client = WebServiceClient.getWebServiceClient().createClient();
157138
return runCommand(args);
158139
} finally {
159140
if (yarnClient != null) {
160141
yarnClient.close();
161142
}
162-
if (webServiceClient != null) {
163-
webServiceClient.destroy();
143+
if (client != null) {
144+
client.destroy();
164145
}
165146
}
166147
}
@@ -310,7 +291,7 @@ private int runCommand(String[] args) throws Exception {
310291
// Set up Retry WebService Client
311292
connectionRetry = new ClientConnectionRetry(maxRetries, retryInterval);
312293
ClientJerseyRetryFilter retryFilter = new ClientJerseyRetryFilter();
313-
webServiceClient.addFilter(retryFilter);
294+
client.addFilter(retryFilter);
314295

315296
LogCLIHelpers logCliHelper = new LogCLIHelpers();
316297
logCliHelper.setConf(getConf());
@@ -411,7 +392,9 @@ public static void main(String[] args) throws Exception {
411392
Configuration conf = new YarnConfiguration();
412393
LogsCLI logDumper = new LogsCLI();
413394
logDumper.setConf(conf);
395+
WebServiceClient.initialize(conf);
414396
int exitCode = logDumper.run(args);
397+
WebServiceClient.destroy();
415398
System.exit(exitCode);
416399
}
417400

@@ -436,7 +419,7 @@ private List<JSONObject> getAMContainerInfoFromRM(
436419
List<JSONObject> amContainersList = new ArrayList<JSONObject>();
437420
ClientResponse response = null;
438421
try {
439-
Builder builder = webServiceClient.resource(webAppAddress)
422+
Builder builder = client.resource(webAppAddress)
440423
.path("ws").path("v1").path("cluster")
441424
.path("apps").path(appId).path("appattempts")
442425
.accept(MediaType.APPLICATION_JSON);
@@ -461,7 +444,7 @@ private List<JSONObject> getAMContainerInfoForAHSWebService(
461444
String webAppAddress =
462445
WebAppUtils.getHttpSchemePrefix(conf)
463446
+ WebAppUtils.getAHSWebAppURLWithoutScheme(conf);
464-
WebResource webResource = webServiceClient.resource(webAppAddress);
447+
WebResource webResource = client.resource(webAppAddress);
465448

466449
ClientResponse response =
467450
webResource.path("ws").path("v1").path("applicationhistory")
@@ -511,7 +494,7 @@ private List<Pair<ContainerLogFileInfo, String>> getContainerLogFiles(
511494
List<Pair<ContainerLogFileInfo, String>> logFileInfos
512495
= new ArrayList<>();
513496
try {
514-
WebResource webResource = webServiceClient
497+
WebResource webResource = client
515498
.resource(WebAppUtils.getHttpSchemePrefix(conf) + nodeHttpAddress);
516499
ClientResponse response =
517500
webResource.path("ws").path("v1").path("node").path("containers")
@@ -599,7 +582,7 @@ public int printContainerLogsFromRunningApplication(Configuration conf,
599582
InputStream is = null;
600583
try {
601584
ClientResponse response = getResponseFromNMWebService(conf,
602-
webServiceClient, request, logFile);
585+
client, request, logFile);
603586
if (response != null && response.getStatusInfo().getStatusCode() ==
604587
ClientResponse.Status.OK.getStatusCode()) {
605588
is = response.getEntityInputStream();
@@ -811,7 +794,7 @@ protected ClientResponse getClientResponseFromTimelineReader(
811794
Configuration conf, String appId) throws IOException {
812795
String webAppAddress = WebAppUtils.getHttpSchemePrefix(conf) + WebAppUtils
813796
.getTimelineReaderWebAppURLWithoutScheme(conf);
814-
WebResource webResource = webServiceClient.resource(webAppAddress);
797+
WebResource webResource = client.resource(webAppAddress);
815798

816799
ClientResponse response =
817800
webResource.path("ws").path("v2").path("timeline").path("clusters")

0 commit comments

Comments
 (0)