@Override
  protected void render(Block html) {
    ContainerId containerId = verifyAndGetContainerId(html);
    NodeId nodeId = verifyAndGetNodeId(html);
    String appOwner = verifyAndGetAppOwner(html);
    if (containerId == null || nodeId == null || appOwner == null
        || appOwner.isEmpty()) {
      return;
    }
    
    ApplicationId applicationId =
        containerId.getApplicationAttemptId().getApplicationId();
    String logEntity = $(ENTITY_STRING);
    if (logEntity == null || logEntity.isEmpty()) {
      logEntity = containerId.toString();
    }

    if (!conf.getBoolean(YarnConfiguration.NM_LOG_AGGREGATION_ENABLED,
        YarnConfiguration.DEFAULT_NM_LOG_AGGREGATION_ENABLED)) {
      html.h1()
          ._("Aggregation is not enabled. Try the nodemanager at " + nodeId)
          ._();
      return;
    }
    
    Path remoteRootLogDir =
        new Path(conf.get(YarnConfiguration.NM_REMOTE_APP_LOG_DIR,
            YarnConfiguration.DEFAULT_NM_REMOTE_APP_LOG_DIR));
    AggregatedLogFormat.LogReader reader = null;
    try {
      reader =
          new AggregatedLogFormat.LogReader(conf,
              LogAggregationUtils.getRemoteNodeLogFileForApp(
                  remoteRootLogDir, applicationId, appOwner, nodeId,
                  LogAggregationUtils.getRemoteNodeLogDirSuffix(conf)));
    } catch (FileNotFoundException e) {
      // ACLs not available till the log file is opened.
      html.h1()
          ._("Logs not available for "
              + logEntity
              + ". Aggregation may not be complete, "
              + "Check back later or try the nodemanager at "
              + nodeId)._();
      return;
    } catch (IOException e) {
      html.h1()._("Error getting logs for " + logEntity)._();
      LOG.error("Error getting logs for " + logEntity, e);
      return;
    }

    String owner = null;
    Map<ApplicationAccessType, String> appAcls = null;
    try {
      owner = reader.getApplicationOwner();
      appAcls = reader.getApplicationAcls();
    } catch (IOException e) {
      html.h1()._("Error getting logs for " + logEntity)._();
      LOG.error("Error getting logs for " + logEntity, e);
      return;
    }
    ApplicationACLsManager aclsManager = new ApplicationACLsManager(conf);
    aclsManager.addApplication(applicationId, appAcls);

    String remoteUser = request().getRemoteUser();
    UserGroupInformation callerUGI = null;
    if (remoteUser != null) {
      callerUGI = UserGroupInformation.createRemoteUser(remoteUser);
    }
    if (callerUGI != null
        && !aclsManager.checkAccess(callerUGI, ApplicationAccessType.VIEW_APP,
            owner, applicationId)) {
      html.h1()
          ._("User [" + remoteUser
              + "] is not authorized to view the logs for " + logEntity)._();
      return;
    }

    DataInputStream valueStream;
    LogKey key = new LogKey();
    try {
      valueStream = reader.next(key);
      while (valueStream != null
          && !key.toString().equals(containerId.toString())) {
        valueStream = reader.next(key);
      }
      if (valueStream == null) {
        html.h1()._(
            "Logs not available for " + logEntity
                + ". Could be caused by the rentention policy")._();
        return;
      }
      writer().write("<pre>");
      AggregatedLogFormat.LogReader.readAcontainerLogs(valueStream, writer());
      writer().write("</pre>");
      return;
    } catch (IOException e) {
      html.h1()._("Error getting logs for " + logEntity)._();
      LOG.error("Error getting logs for " + logEntity, e);
      return;
    }
  }