Search in sources :

Example 1 with NMContainerLogsInfo

use of org.apache.hadoop.yarn.server.nodemanager.webapp.dao.NMContainerLogsInfo in project hadoop by apache.

the class NMWebServices method getContainerLogsInfo.

/**
   * Returns log file's name as well as current file size for a container.
   *
   * @param hsr
   *    HttpServletRequest
   * @param res
   *    HttpServletResponse
   * @param containerIdStr
   *    The container ID
   * @return
   *    The log file's name and current file size
   */
@GET
@Path("/containers/{containerid}/logs")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
public Response getContainerLogsInfo(@javax.ws.rs.core.Context HttpServletRequest hsr, @javax.ws.rs.core.Context HttpServletResponse res, @PathParam(YarnWebServiceParams.CONTAINER_ID) String containerIdStr) {
    ContainerId containerId = null;
    init();
    try {
        containerId = ContainerId.fromString(containerIdStr);
    } catch (IllegalArgumentException ex) {
        throw new BadRequestException("invalid container id, " + containerIdStr);
    }
    try {
        List<ContainerLogsInfo> containersLogsInfo = new ArrayList<>();
        containersLogsInfo.add(new NMContainerLogsInfo(this.nmContext, containerId, hsr.getRemoteUser(), ContainerLogAggregationType.LOCAL));
        // check whether we have aggregated logs in RemoteFS. If exists, show the
        // the log meta for the aggregated logs as well.
        ApplicationId appId = containerId.getApplicationAttemptId().getApplicationId();
        Application app = this.nmContext.getApplications().get(appId);
        String appOwner = app == null ? null : app.getUser();
        try {
            List<ContainerLogMeta> containerLogMeta = LogToolUtils.getContainerLogMetaFromRemoteFS(this.nmContext.getConf(), appId, containerIdStr, this.nmContext.getNodeId().toString(), appOwner);
            if (!containerLogMeta.isEmpty()) {
                for (ContainerLogMeta logMeta : containerLogMeta) {
                    containersLogsInfo.add(new ContainerLogsInfo(logMeta, ContainerLogAggregationType.AGGREGATED));
                }
            }
        } catch (IOException ex) {
            // Skip it and do nothing
            if (LOG.isDebugEnabled()) {
                LOG.debug(ex.getMessage());
            }
        }
        GenericEntity<List<ContainerLogsInfo>> meta = new GenericEntity<List<ContainerLogsInfo>>(containersLogsInfo) {
        };
        ResponseBuilder resp = Response.ok(meta);
        // Sending the X-Content-Type-Options response header with the value
        // nosniff will prevent Internet Explorer from MIME-sniffing a response
        // away from the declared content-type.
        resp.header("X-Content-Type-Options", "nosniff");
        return resp.build();
    } catch (Exception ex) {
        if (redirectWSUrl == null || redirectWSUrl.isEmpty()) {
            throw new WebApplicationException(ex);
        }
        // redirect the request to the configured log server
        String redirectURI = "/containers/" + containerIdStr + "/logs";
        return createRedirectResponse(hsr, redirectWSUrl, redirectURI);
    }
}
Also used : NMContainerLogsInfo(org.apache.hadoop.yarn.server.nodemanager.webapp.dao.NMContainerLogsInfo) ContainerLogsInfo(org.apache.hadoop.yarn.server.webapp.dao.ContainerLogsInfo) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) ContainerLogMeta(org.apache.hadoop.yarn.logaggregation.ContainerLogMeta) IOException(java.io.IOException) WebApplicationException(javax.ws.rs.WebApplicationException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) IOException(java.io.IOException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) GenericEntity(javax.ws.rs.core.GenericEntity) NMContainerLogsInfo(org.apache.hadoop.yarn.server.nodemanager.webapp.dao.NMContainerLogsInfo) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) List(java.util.List) ArrayList(java.util.ArrayList) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Application(org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 GenericEntity (javax.ws.rs.core.GenericEntity)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)1 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)1 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)1 ContainerLogMeta (org.apache.hadoop.yarn.logaggregation.ContainerLogMeta)1 Application (org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application)1 NMContainerLogsInfo (org.apache.hadoop.yarn.server.nodemanager.webapp.dao.NMContainerLogsInfo)1 ContainerLogsInfo (org.apache.hadoop.yarn.server.webapp.dao.ContainerLogsInfo)1 BadRequestException (org.apache.hadoop.yarn.webapp.BadRequestException)1 NotFoundException (org.apache.hadoop.yarn.webapp.NotFoundException)1