2727import com .sun .jersey .api .client .WebResource ;
2828import com .sun .jersey .api .client .WebResource .Builder ;
2929import com .sun .jersey .api .client .filter .ClientFilter ;
30+ import com .sun .jersey .client .urlconnection .HttpURLConnectionFactory ;
31+ import com .sun .jersey .client .urlconnection .URLConnectionClientHandler ;
3032import java .io .File ;
3133import java .io .IOException ;
3234import java .io .InputStream ;
3335import java .io .PrintStream ;
3436import java .net .ConnectException ;
37+ import java .net .HttpURLConnection ;
3538import java .net .SocketException ;
3639import java .net .SocketTimeoutException ;
40+ import java .net .URL ;
3741import java .util .ArrayList ;
3842import java .util .Arrays ;
3943import java .util .Collection ;
6468import org .apache .hadoop .conf .Configuration ;
6569import org .apache .hadoop .conf .Configured ;
6670import org .apache .hadoop .security .UserGroupInformation ;
71+ import org .apache .hadoop .security .authentication .client .AuthenticatedURL ;
72+ import org .apache .hadoop .security .authentication .client .AuthenticationException ;
6773import org .apache .hadoop .util .Tool ;
6874import org .apache .hadoop .yarn .api .records .ApplicationAttemptReport ;
6975import org .apache .hadoop .yarn .api .records .ApplicationId ;
8187import org .apache .hadoop .yarn .logaggregation .LogCLIHelpers ;
8288import org .apache .hadoop .yarn .logaggregation .LogToolUtils ;
8389import org .apache .hadoop .yarn .server .metrics .AppAttemptMetricsConstants ;
84- import org .apache .hadoop .yarn .server .webapp .WebServiceClient ;
8590import org .apache .hadoop .yarn .util .Apps ;
8691import org .apache .hadoop .yarn .webapp .util .WebAppUtils ;
8792import org .apache .hadoop .yarn .webapp .util .YarnWebServiceUtils ;
@@ -117,7 +122,7 @@ public class LogsCLI extends Configured implements Tool {
117122
118123 private PrintStream outStream = System .out ;
119124 private YarnClient yarnClient = null ;
120- private Client client = null ;
125+ private Client webServiceClient = null ;
121126
122127 private static final int DEFAULT_MAX_RETRIES = 30 ;
123128 private static final long DEFAULT_RETRY_INTERVAL = 1000 ;
@@ -134,14 +139,28 @@ public class LogsCLI extends Configured implements Tool {
134139 @ Override
135140 public int run (String [] args ) throws Exception {
136141 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+ }));
138157 return runCommand (args );
139158 } finally {
140159 if (yarnClient != null ) {
141160 yarnClient .close ();
142161 }
143- if (client != null ) {
144- client .destroy ();
162+ if (webServiceClient != null ) {
163+ webServiceClient .destroy ();
145164 }
146165 }
147166 }
@@ -291,7 +310,7 @@ private int runCommand(String[] args) throws Exception {
291310 // Set up Retry WebService Client
292311 connectionRetry = new ClientConnectionRetry (maxRetries , retryInterval );
293312 ClientJerseyRetryFilter retryFilter = new ClientJerseyRetryFilter ();
294- client .addFilter (retryFilter );
313+ webServiceClient .addFilter (retryFilter );
295314
296315 LogCLIHelpers logCliHelper = new LogCLIHelpers ();
297316 logCliHelper .setConf (getConf ());
@@ -392,9 +411,7 @@ public static void main(String[] args) throws Exception {
392411 Configuration conf = new YarnConfiguration ();
393412 LogsCLI logDumper = new LogsCLI ();
394413 logDumper .setConf (conf );
395- WebServiceClient .initialize (conf );
396414 int exitCode = logDumper .run (args );
397- WebServiceClient .destroy ();
398415 System .exit (exitCode );
399416 }
400417
@@ -419,7 +436,7 @@ private List<JSONObject> getAMContainerInfoFromRM(
419436 List <JSONObject > amContainersList = new ArrayList <JSONObject >();
420437 ClientResponse response = null ;
421438 try {
422- Builder builder = client .resource (webAppAddress )
439+ Builder builder = webServiceClient .resource (webAppAddress )
423440 .path ("ws" ).path ("v1" ).path ("cluster" )
424441 .path ("apps" ).path (appId ).path ("appattempts" )
425442 .accept (MediaType .APPLICATION_JSON );
@@ -444,7 +461,7 @@ private List<JSONObject> getAMContainerInfoForAHSWebService(
444461 String webAppAddress =
445462 WebAppUtils .getHttpSchemePrefix (conf )
446463 + WebAppUtils .getAHSWebAppURLWithoutScheme (conf );
447- WebResource webResource = client .resource (webAppAddress );
464+ WebResource webResource = webServiceClient .resource (webAppAddress );
448465
449466 ClientResponse response =
450467 webResource .path ("ws" ).path ("v1" ).path ("applicationhistory" )
@@ -494,7 +511,7 @@ private List<Pair<ContainerLogFileInfo, String>> getContainerLogFiles(
494511 List <Pair <ContainerLogFileInfo , String >> logFileInfos
495512 = new ArrayList <>();
496513 try {
497- WebResource webResource = client
514+ WebResource webResource = webServiceClient
498515 .resource (WebAppUtils .getHttpSchemePrefix (conf ) + nodeHttpAddress );
499516 ClientResponse response =
500517 webResource .path ("ws" ).path ("v1" ).path ("node" ).path ("containers" )
@@ -582,7 +599,7 @@ public int printContainerLogsFromRunningApplication(Configuration conf,
582599 InputStream is = null ;
583600 try {
584601 ClientResponse response = getResponseFromNMWebService (conf ,
585- client , request , logFile );
602+ webServiceClient , request , logFile );
586603 if (response != null && response .getStatusInfo ().getStatusCode () ==
587604 ClientResponse .Status .OK .getStatusCode ()) {
588605 is = response .getEntityInputStream ();
@@ -794,7 +811,7 @@ protected ClientResponse getClientResponseFromTimelineReader(
794811 Configuration conf , String appId ) throws IOException {
795812 String webAppAddress = WebAppUtils .getHttpSchemePrefix (conf ) + WebAppUtils
796813 .getTimelineReaderWebAppURLWithoutScheme (conf );
797- WebResource webResource = client .resource (webAppAddress );
814+ WebResource webResource = webServiceClient .resource (webAppAddress );
798815
799816 ClientResponse response =
800817 webResource .path ("ws" ).path ("v2" ).path ("timeline" ).path ("clusters" )
0 commit comments