slfan1989 commented on code in PR #5030: URL: https://github.com/apache/hadoop/pull/5030#discussion_r1000883075
########## hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/AppsBlock.java: ########## @@ -81,53 +154,57 @@ protected void render(Block html) { // Render the applications StringBuilder appsTableData = new StringBuilder("[\n"); - for (AppInfo app : apps.getApps()) { - try { - - String percent = String.format("%.1f", app.getProgress() * 100.0F); - String trackingURL = - app.getTrackingUrl() == null ? "#" : app.getTrackingUrl(); - // AppID numerical value parsed by parseHadoopID in yarn.dt.plugins.js - appsTableData.append("[\"") - .append("<a href='").append(trackingURL).append("'>") - .append(app.getAppId()).append("</a>\",\"") - .append(escape(app.getUser())).append("\",\"") - .append(escape(app.getName())).append("\",\"") - .append(escape(app.getApplicationType())).append("\",\"") - .append(escape(app.getQueue())).append("\",\"") - .append(String.valueOf(app.getPriority())).append("\",\"") - .append(app.getStartTime()).append("\",\"") - .append(app.getFinishTime()).append("\",\"") - .append(app.getState()).append("\",\"") - .append(app.getFinalStatus()).append("\",\"") - // Progress bar - .append("<br title='").append(percent).append("'> <div class='") - .append(C_PROGRESSBAR).append("' title='") - .append(join(percent, '%')).append("'> ").append("<div class='") - .append(C_PROGRESSBAR_VALUE).append("' style='") - .append(join("width:", percent, '%')).append("'> </div> </div>") - // History link - .append("\",\"<a href='").append(trackingURL).append("'>") - .append("History").append("</a>"); - appsTableData.append("\"],\n"); - - } catch (Exception e) { - LOG.info( - "Cannot add application {}: {}", app.getAppId(), e.getMessage()); + + if (appsInfo != null && CollectionUtils.isNotEmpty(appsInfo.getApps())) { + for (AppInfo app : appsInfo.getApps()) { + try { + + String percent = String.format("%.1f", app.getProgress() * 100.0F); + String trackingURL = + app.getTrackingUrl() == null ? "#" : app.getTrackingUrl(); + + // AppID numerical value parsed by parseHadoopID in yarn.dt.plugins.js + appsTableData.append("[\"") + .append("<a href='").append(trackingURL).append("'>") + .append(app.getAppId()).append("</a>\",\"") + .append(escape(app.getUser())).append("\",\"") + .append(escape(app.getName())).append("\",\"") + .append(escape(app.getApplicationType())).append("\",\"") + .append(escape(app.getQueue())).append("\",\"") + .append(app.getPriority()).append("\",\"") + .append(app.getStartTime()).append("\",\"") + .append(app.getFinishTime()).append("\",\"") + .append(app.getState()).append("\",\"") + .append(app.getFinalStatus()).append("\",\"") + // Progress bar + .append("<br title='").append(percent).append("'> <div class='") + .append(C_PROGRESSBAR).append("' title='") + .append(join(percent, '%')).append("'> ").append("<div class='") + .append(C_PROGRESSBAR_VALUE).append("' style='") + .append(join("width:", percent, '%')).append("'> </div> </div>") + // History link + .append("\",\"<a href='").append(trackingURL).append("'>") + .append("History").append("</a>"); + appsTableData.append("\"],\n"); + + } catch (Exception e) { + LOG.info("Cannot add application {}: {}", app.getAppId(), e.getMessage()); + } + } + + // The purpose of this part of the code is to remove redundant commas. Review Comment: Thanks for your suggestion, I will refactor this part of the code. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org