protected override void Render(HtmlBlock.Block html) { string redirectUrl = $(RedirectUrl); if (redirectUrl != null && redirectUrl.Equals("false")) { html.H1("Failed while trying to construct the redirect url to the log" + " server. Log Server url may not be configured" ); } //Intentional fallthrough. ContainerId containerId; try { containerId = ConverterUtils.ToContainerId($(YarnWebParams.ContainerId)); } catch (ArgumentException) { html.H1("Invalid container ID: " + $(YarnWebParams.ContainerId)); return; } try { if ($(ContainerLogType).IsEmpty()) { IList <FilePath> logFiles = ContainerLogsUtils.GetContainerLogDirs(containerId, Request ().GetRemoteUser(), nmContext); PrintLogFileDirectory(html, logFiles); } else { FilePath logFile = ContainerLogsUtils.GetContainerLogFile(containerId, $(ContainerLogType ), Request().GetRemoteUser(), nmContext); PrintLogFile(html, logFile); } }
protected internal override void Render(HtmlBlock.Block html) { ContainerId containerId = VerifyAndGetContainerId(html); NodeId nodeId = VerifyAndGetNodeId(html); string appOwner = VerifyAndGetAppOwner(html); AggregatedLogsBlock.LogLimits logLimits = VerifyAndGetLogLimits(html); if (containerId == null || nodeId == null || appOwner == null || appOwner.IsEmpty () || logLimits == null) { return; } ApplicationId applicationId = containerId.GetApplicationAttemptId().GetApplicationId (); string logEntity = $(YarnWebParams.EntityString); if (logEntity == null || logEntity.IsEmpty()) { logEntity = containerId.ToString(); } if (!conf.GetBoolean(YarnConfiguration.LogAggregationEnabled, YarnConfiguration.DefaultLogAggregationEnabled )) { html.H1().("Aggregation is not enabled. Try the nodemanager at " + nodeId).(); return; } Path remoteRootLogDir = new Path(conf.Get(YarnConfiguration.NmRemoteAppLogDir, YarnConfiguration .DefaultNmRemoteAppLogDir)); Path remoteAppDir = LogAggregationUtils.GetRemoteAppLogDir(remoteRootLogDir, applicationId , appOwner, LogAggregationUtils.GetRemoteNodeLogDirSuffix(conf)); RemoteIterator <FileStatus> nodeFiles; try { Path qualifiedLogDir = FileContext.GetFileContext(conf).MakeQualified(remoteAppDir ); nodeFiles = FileContext.GetFileContext(qualifiedLogDir.ToUri(), conf).ListStatus( remoteAppDir); } catch (FileNotFoundException) { html.H1().("Logs not available for " + logEntity + ". Aggregation may not be complete, " + "Check back later or try the nodemanager at " + nodeId).(); return; } catch (Exception) { html.H1().("Error getting logs at " + nodeId).(); return; } bool foundLog = false; string desiredLogType = $(YarnWebParams.ContainerLogType); try { while (nodeFiles.HasNext()) { AggregatedLogFormat.LogReader reader = null; try { FileStatus thisNodeFile = nodeFiles.Next(); if (!thisNodeFile.GetPath().GetName().Contains(LogAggregationUtils.GetNodeString( nodeId)) || thisNodeFile.GetPath().GetName().EndsWith(LogAggregationUtils.TmpFileSuffix )) { continue; } long logUploadedTime = thisNodeFile.GetModificationTime(); reader = new AggregatedLogFormat.LogReader(conf, thisNodeFile.GetPath()); string owner = null; IDictionary <ApplicationAccessType, string> appAcls = null; try { owner = reader.GetApplicationOwner(); appAcls = reader.GetApplicationAcls(); } catch (IOException e) { Log.Error("Error getting logs for " + logEntity, e); continue; } 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 .ViewApp, owner, applicationId)) { html.H1().("User [" + remoteUser + "] is not authorized to view the logs for " + logEntity + " in log file [" + thisNodeFile.GetPath().GetName() + "]").(); Log.Error("User [" + remoteUser + "] is not authorized to view the logs for " + logEntity ); continue; } AggregatedLogFormat.ContainerLogsReader logReader = reader.GetContainerLogsReader (containerId); if (logReader == null) { continue; } foundLog = ReadContainerLogs(html, logReader, logLimits, desiredLogType, logUploadedTime ); } catch (IOException ex) { Log.Error("Error getting logs for " + logEntity, ex); continue; } finally { if (reader != null) { reader.Close(); } } } if (!foundLog) { if (desiredLogType.IsEmpty()) { html.H1("No logs available for container " + containerId.ToString()); } else { html.H1("Unable to locate '" + desiredLogType + "' log for container " + containerId .ToString()); } } } catch (IOException e) { html.H1().("Error getting logs for " + logEntity).(); Log.Error("Error getting logs for " + logEntity, e); } }