27
27
import com .sun .jersey .api .client .WebResource ;
28
28
import com .sun .jersey .api .client .WebResource .Builder ;
29
29
import com .sun .jersey .api .client .filter .ClientFilter ;
30
+ import com .sun .jersey .client .urlconnection .HttpURLConnectionFactory ;
31
+ import com .sun .jersey .client .urlconnection .URLConnectionClientHandler ;
30
32
import java .io .File ;
31
33
import java .io .IOException ;
32
34
import java .io .InputStream ;
33
35
import java .io .PrintStream ;
34
36
import java .net .ConnectException ;
37
+ import java .net .HttpURLConnection ;
35
38
import java .net .SocketException ;
36
39
import java .net .SocketTimeoutException ;
40
+ import java .net .URL ;
37
41
import java .util .ArrayList ;
38
42
import java .util .Arrays ;
39
43
import java .util .Collection ;
64
68
import org .apache .hadoop .conf .Configuration ;
65
69
import org .apache .hadoop .conf .Configured ;
66
70
import org .apache .hadoop .security .UserGroupInformation ;
71
+ import org .apache .hadoop .security .authentication .client .AuthenticatedURL ;
72
+ import org .apache .hadoop .security .authentication .client .AuthenticationException ;
67
73
import org .apache .hadoop .util .Tool ;
68
74
import org .apache .hadoop .yarn .api .records .ApplicationAttemptReport ;
69
75
import org .apache .hadoop .yarn .api .records .ApplicationId ;
81
87
import org .apache .hadoop .yarn .logaggregation .LogCLIHelpers ;
82
88
import org .apache .hadoop .yarn .logaggregation .LogToolUtils ;
83
89
import org .apache .hadoop .yarn .server .metrics .AppAttemptMetricsConstants ;
84
- import org .apache .hadoop .yarn .server .webapp .WebServiceClient ;
85
90
import org .apache .hadoop .yarn .util .Apps ;
86
91
import org .apache .hadoop .yarn .webapp .util .WebAppUtils ;
87
92
import org .apache .hadoop .yarn .webapp .util .YarnWebServiceUtils ;
@@ -117,7 +122,7 @@ public class LogsCLI extends Configured implements Tool {
117
122
118
123
private PrintStream outStream = System .out ;
119
124
private YarnClient yarnClient = null ;
120
- private Client client = null ;
125
+ private Client webServiceClient = null ;
121
126
122
127
private static final int DEFAULT_MAX_RETRIES = 30 ;
123
128
private static final long DEFAULT_RETRY_INTERVAL = 1000 ;
@@ -134,14 +139,28 @@ public class LogsCLI extends Configured implements Tool {
134
139
@ Override
135
140
public int run (String [] args ) throws Exception {
136
141
try {
137
- client = WebServiceClient .getWebServiceClient ().createClient ();
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
+ }));
138
157
return runCommand (args );
139
158
} finally {
140
159
if (yarnClient != null ) {
141
160
yarnClient .close ();
142
161
}
143
- if (client != null ) {
144
- client .destroy ();
162
+ if (webServiceClient != null ) {
163
+ webServiceClient .destroy ();
145
164
}
146
165
}
147
166
}
@@ -291,7 +310,7 @@ private int runCommand(String[] args) throws Exception {
291
310
// Set up Retry WebService Client
292
311
connectionRetry = new ClientConnectionRetry (maxRetries , retryInterval );
293
312
ClientJerseyRetryFilter retryFilter = new ClientJerseyRetryFilter ();
294
- client .addFilter (retryFilter );
313
+ webServiceClient .addFilter (retryFilter );
295
314
296
315
LogCLIHelpers logCliHelper = new LogCLIHelpers ();
297
316
logCliHelper .setConf (getConf ());
@@ -392,9 +411,7 @@ public static void main(String[] args) throws Exception {
392
411
Configuration conf = new YarnConfiguration ();
393
412
LogsCLI logDumper = new LogsCLI ();
394
413
logDumper .setConf (conf );
395
- WebServiceClient .initialize (conf );
396
414
int exitCode = logDumper .run (args );
397
- WebServiceClient .destroy ();
398
415
System .exit (exitCode );
399
416
}
400
417
@@ -419,7 +436,7 @@ private List<JSONObject> getAMContainerInfoFromRM(
419
436
List <JSONObject > amContainersList = new ArrayList <JSONObject >();
420
437
ClientResponse response = null ;
421
438
try {
422
- Builder builder = client .resource (webAppAddress )
439
+ Builder builder = webServiceClient .resource (webAppAddress )
423
440
.path ("ws" ).path ("v1" ).path ("cluster" )
424
441
.path ("apps" ).path (appId ).path ("appattempts" )
425
442
.accept (MediaType .APPLICATION_JSON );
@@ -444,7 +461,7 @@ private List<JSONObject> getAMContainerInfoForAHSWebService(
444
461
String webAppAddress =
445
462
WebAppUtils .getHttpSchemePrefix (conf )
446
463
+ WebAppUtils .getAHSWebAppURLWithoutScheme (conf );
447
- WebResource webResource = client .resource (webAppAddress );
464
+ WebResource webResource = webServiceClient .resource (webAppAddress );
448
465
449
466
ClientResponse response =
450
467
webResource .path ("ws" ).path ("v1" ).path ("applicationhistory" )
@@ -494,7 +511,7 @@ private List<Pair<ContainerLogFileInfo, String>> getContainerLogFiles(
494
511
List <Pair <ContainerLogFileInfo , String >> logFileInfos
495
512
= new ArrayList <>();
496
513
try {
497
- WebResource webResource = client
514
+ WebResource webResource = webServiceClient
498
515
.resource (WebAppUtils .getHttpSchemePrefix (conf ) + nodeHttpAddress );
499
516
ClientResponse response =
500
517
webResource .path ("ws" ).path ("v1" ).path ("node" ).path ("containers" )
@@ -582,7 +599,7 @@ public int printContainerLogsFromRunningApplication(Configuration conf,
582
599
InputStream is = null ;
583
600
try {
584
601
ClientResponse response = getResponseFromNMWebService (conf ,
585
- client , request , logFile );
602
+ webServiceClient , request , logFile );
586
603
if (response != null && response .getStatusInfo ().getStatusCode () ==
587
604
ClientResponse .Status .OK .getStatusCode ()) {
588
605
is = response .getEntityInputStream ();
@@ -794,7 +811,7 @@ protected ClientResponse getClientResponseFromTimelineReader(
794
811
Configuration conf , String appId ) throws IOException {
795
812
String webAppAddress = WebAppUtils .getHttpSchemePrefix (conf ) + WebAppUtils
796
813
.getTimelineReaderWebAppURLWithoutScheme (conf );
797
- WebResource webResource = client .resource (webAppAddress );
814
+ WebResource webResource = webServiceClient .resource (webAppAddress );
798
815
799
816
ClientResponse response =
800
817
webResource .path ("ws" ).path ("v2" ).path ("timeline" ).path ("clusters" )
0 commit comments