2323
2424import com .gargoylesoftware .htmlunit .BrowserVersion ;
2525import com .gargoylesoftware .htmlunit .Cache ;
26+ import com .gargoylesoftware .htmlunit .FailingHttpStatusCodeException ;
2627import com .gargoylesoftware .htmlunit .WebClient ;
2728import com .gargoylesoftware .htmlunit .html .*;
2829import com .google .gson .Gson ;
@@ -247,10 +248,12 @@ public static String getInformationFromYarnLogDom(final CredentialsProvider cred
247248 HTTP_WEB_CLIENT .setCredentialsProvider (credentialsProvider );
248249 }
249250
251+ URI url = null ;
252+
250253 try {
251- URI url = new URI (baseUrl + "/" ).resolve (
254+ url = new URI (baseUrl + "/" ).resolve (
252255 String .format ("%s?start=%d" , type , start ) +
253- (size <= 0 ? "" : String .format ("&&end=%d" , start + size )));
256+ (size <= 0 ? "" : String .format ("&&end=%d" , start + size )));
254257 HtmlPage htmlPage = HTTP_WEB_CLIENT .getPage (url .toString ());
255258
256259 Iterator <DomElement > iterator = htmlPage .getElementById ("navcell" ).getNextElementSibling ().getChildElements ().iterator ();
@@ -274,18 +277,32 @@ public static String getInformationFromYarnLogDom(final CredentialsProvider cred
274277 .ifPresent (logType ::set );
275278 } else if (node instanceof HtmlPreformattedText ) {
276279 // In running, no log type paragraph in page
277- String typ = Optional .ofNullable (logType .get ()).orElse (type );
278280
279- // Only get the first <pre>...</pre>
280- if (! logTypeMap . containsKey ( typ )) {
281- logTypeMap .put (typ , Optional .ofNullable (node .getFirstChild ())
281+ if ( logType . get () != null ) {
282+ // Only get the first <pre>...</pre>
283+ logTypeMap .put (logType . get () , Optional .ofNullable (node .getFirstChild ())
282284 .map (DomNode ::getTextContent )
283285 .orElse ("" ));
286+
287+ logType .set (null );
284288 }
285289 }
286290 }
287291
288292 return logTypeMap .getOrDefault (type , "" );
293+ } catch (FailingHttpStatusCodeException httpError ) {
294+ // If the URL is wrong, will get 200 response with content:
295+ // Unable to locate 'xxx' log for container
296+ // OR
297+ // Logs not available for <user>. Aggregation may not be complete, Check back later or try the nodemanager at...
298+ // OR
299+ // Cannot get container logs without ...
300+ //
301+ // if fetching Yarn log hits the gap between the job running and stop, will get the status 403
302+ // the log is moving to job history server, just wait and retry.
303+ if (httpError .getStatusCode () != HttpStatus .SC_FORBIDDEN ) {
304+ LOGGER .warn ("The GET request to " + url + " responded error: " + httpError .getMessage ());
305+ }
289306 } catch (URISyntaxException e ) {
290307 LOGGER .error ("baseUrl has syntax error: " + baseUrl );
291308 } catch (Exception e ) {
0 commit comments