Skip to content

Commit d4eda5f

Browse files
committed
Fix the log content can't be got from Spark 2.2 cluster YarnUI issue
Signed-off-by: Wei Zhang <[email protected]>
1 parent aa826d7 commit d4eda5f

File tree

1 file changed

+23
-6
lines changed
  • Utils/hdinsight-node-common/src/com/microsoft/azure/hdinsight/spark/jobs

1 file changed

+23
-6
lines changed

Utils/hdinsight-node-common/src/com/microsoft/azure/hdinsight/spark/jobs/JobUtils.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import com.gargoylesoftware.htmlunit.BrowserVersion;
2525
import com.gargoylesoftware.htmlunit.Cache;
26+
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
2627
import com.gargoylesoftware.htmlunit.WebClient;
2728
import com.gargoylesoftware.htmlunit.html.*;
2829
import 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

Comments
 (0)