Search in sources :

Example 1 with ContainerLogMeta

use of org.apache.hadoop.yarn.logaggregation.ContainerLogMeta 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)

Example 2 with ContainerLogMeta

use of org.apache.hadoop.yarn.logaggregation.ContainerLogMeta in project hadoop by apache.

the class AHSWebServices method getContainerLogMeta.

private Response getContainerLogMeta(ApplicationId appId, String appOwner, final String nodeId, final String containerIdStr, boolean emptyLocalContainerLogMeta) {
    try {
        List<ContainerLogMeta> containerLogMeta = LogToolUtils.getContainerLogMetaFromRemoteFS(conf, appId, containerIdStr, nodeId, appOwner);
        if (containerLogMeta.isEmpty()) {
            throw new NotFoundException("Can not get log meta for container: " + containerIdStr);
        }
        List<ContainerLogsInfo> containersLogsInfo = new ArrayList<>();
        for (ContainerLogMeta meta : containerLogMeta) {
            ContainerLogsInfo logInfo = new ContainerLogsInfo(meta, ContainerLogAggregationType.AGGREGATED);
            containersLogsInfo.add(logInfo);
        }
        if (emptyLocalContainerLogMeta) {
            ContainerLogMeta emptyMeta = new ContainerLogMeta(containerIdStr, "N/A");
            ContainerLogsInfo empty = new ContainerLogsInfo(emptyMeta, ContainerLogAggregationType.LOCAL);
            containersLogsInfo.add(empty);
        }
        GenericEntity<List<ContainerLogsInfo>> meta = new GenericEntity<List<ContainerLogsInfo>>(containersLogsInfo) {
        };
        ResponseBuilder response = 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.
        response.header("X-Content-Type-Options", "nosniff");
        return response.build();
    } catch (Exception ex) {
        throw new WebApplicationException(ex);
    }
}
Also used : ContainerLogsInfo(org.apache.hadoop.yarn.server.webapp.dao.ContainerLogsInfo) WebApplicationException(javax.ws.rs.WebApplicationException) GenericEntity(javax.ws.rs.core.GenericEntity) ContainerLogMeta(org.apache.hadoop.yarn.logaggregation.ContainerLogMeta) ArrayList(java.util.ArrayList) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) List(java.util.List) ArrayList(java.util.ArrayList) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) WebApplicationException(javax.ws.rs.WebApplicationException) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException)

Aggregations

IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 GenericEntity (javax.ws.rs.core.GenericEntity)2 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)2 ContainerLogMeta (org.apache.hadoop.yarn.logaggregation.ContainerLogMeta)2 ContainerLogsInfo (org.apache.hadoop.yarn.server.webapp.dao.ContainerLogsInfo)2 BadRequestException (org.apache.hadoop.yarn.webapp.BadRequestException)2 NotFoundException (org.apache.hadoop.yarn.webapp.NotFoundException)2 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)1 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)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 Application (org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application)1 NMContainerLogsInfo (org.apache.hadoop.yarn.server.nodemanager.webapp.dao.NMContainerLogsInfo)1