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 ;
3230import java .io .File ;
3331import java .io .IOException ;
3432import java .io .InputStream ;
3533import java .io .PrintStream ;
3634import java .net .ConnectException ;
37- import java .net .HttpURLConnection ;
3835import java .net .SocketException ;
3936import java .net .SocketTimeoutException ;
40- import java .net .URL ;
4137import java .util .ArrayList ;
4238import java .util .Arrays ;
4339import java .util .Collection ;
6864import org .apache .hadoop .conf .Configuration ;
6965import org .apache .hadoop .conf .Configured ;
7066import org .apache .hadoop .security .UserGroupInformation ;
71- import org .apache .hadoop .security .authentication .client .AuthenticatedURL ;
72- import org .apache .hadoop .security .authentication .client .AuthenticationException ;
7367import org .apache .hadoop .util .Tool ;
7468import org .apache .hadoop .yarn .api .records .ApplicationAttemptReport ;
7569import org .apache .hadoop .yarn .api .records .ApplicationId ;
8781import org .apache .hadoop .yarn .logaggregation .LogCLIHelpers ;
8882import org .apache .hadoop .yarn .logaggregation .LogToolUtils ;
8983import org .apache .hadoop .yarn .server .metrics .AppAttemptMetricsConstants ;
84+ import org .apache .hadoop .yarn .server .webapp .WebServiceClient ;
9085import org .apache .hadoop .yarn .util .Apps ;
9186import org .apache .hadoop .yarn .webapp .util .WebAppUtils ;
9287import 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