Search in sources :

Example 1 with AppInfo

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

the class WebServices method getApp.

public AppInfo getApp(HttpServletRequest req, HttpServletResponse res, String appId) {
    UserGroupInformation callerUGI = getUser(req);
    final ApplicationId id = parseApplicationId(appId);
    ApplicationReport app = null;
    try {
        if (callerUGI == null) {
            GetApplicationReportRequest request = GetApplicationReportRequest.newInstance(id);
            app = appBaseProt.getApplicationReport(request).getApplicationReport();
        } else {
            app = callerUGI.doAs(new PrivilegedExceptionAction<ApplicationReport>() {

                @Override
                public ApplicationReport run() throws Exception {
                    GetApplicationReportRequest request = GetApplicationReportRequest.newInstance(id);
                    return appBaseProt.getApplicationReport(request).getApplicationReport();
                }
            });
        }
    } catch (Exception e) {
        rewrapAndThrowException(e);
    }
    if (app == null) {
        throw new NotFoundException("app with id: " + appId + " not found");
    }
    return new AppInfo(app);
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) GetApplicationReportRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ForbiddenException(org.apache.hadoop.yarn.webapp.ForbiddenException) AuthorizationException(org.apache.hadoop.security.authorize.AuthorizationException) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) WebApplicationException(javax.ws.rs.WebApplicationException) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) AppInfo(org.apache.hadoop.yarn.server.webapp.dao.AppInfo)

Example 2 with AppInfo

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

the class RMAppsBlock method renderData.

@Override
protected void renderData(Block html) {
    TBODY<TABLE<Hamlet>> tbody = html.table("#apps").thead().tr().th(".id", "ID").th(".user", "User").th(".name", "Name").th(".type", "Application Type").th(".queue", "Queue").th(".priority", "Application Priority").th(".starttime", "StartTime").th(".finishtime", "FinishTime").th(".state", "State").th(".finalstatus", "FinalStatus").th(".runningcontainer", "Running Containers").th(".allocatedCpu", "Allocated CPU VCores").th(".allocatedMemory", "Allocated Memory MB").th(".queuePercentage", "% of Queue").th(".clusterPercentage", "% of Cluster").th(".progress", "Progress").th(".ui", "Tracking UI").th(".blacklisted", "Blacklisted Nodes")._()._().tbody();
    StringBuilder appsTableData = new StringBuilder("[\n");
    for (ApplicationReport appReport : appReports) {
        // hasn't filtering capability (YARN-1819).
        if (!reqAppStates.isEmpty() && !reqAppStates.contains(appReport.getYarnApplicationState())) {
            continue;
        }
        AppInfo app = new AppInfo(appReport);
        ApplicationAttemptId appAttemptId = ApplicationAttemptId.fromString(app.getCurrentAppAttemptId());
        String queuePercent = "N/A";
        String clusterPercent = "N/A";
        if (appReport.getApplicationResourceUsageReport() != null) {
            queuePercent = String.format("%.1f", appReport.getApplicationResourceUsageReport().getQueueUsagePercentage());
            clusterPercent = String.format("%.1f", appReport.getApplicationResourceUsageReport().getClusterUsagePercentage());
        }
        String blacklistedNodesCount = "N/A";
        RMAppAttempt appAttempt = rm.getRMContext().getRMApps().get(appAttemptId.getApplicationId()).getAppAttempts().get(appAttemptId);
        Set<String> nodes = null == appAttempt ? null : appAttempt.getBlacklistedNodes();
        if (nodes != null) {
            blacklistedNodesCount = String.valueOf(nodes.size());
        }
        String percent = StringUtils.format("%.1f", app.getProgress());
        appsTableData.append("[\"<a href='").append(url("app", app.getAppId())).append("'>").append(app.getAppId()).append("</a>\",\"").append(StringEscapeUtils.escapeJavaScript(StringEscapeUtils.escapeHtml(app.getUser()))).append("\",\"").append(StringEscapeUtils.escapeJavaScript(StringEscapeUtils.escapeHtml(app.getName()))).append("\",\"").append(StringEscapeUtils.escapeJavaScript(StringEscapeUtils.escapeHtml(app.getType()))).append("\",\"").append(StringEscapeUtils.escapeJavaScript(StringEscapeUtils.escapeHtml(app.getQueue()))).append("\",\"").append(String.valueOf(app.getPriority())).append("\",\"").append(app.getStartedTime()).append("\",\"").append(app.getFinishedTime()).append("\",\"").append(app.getAppState() == null ? UNAVAILABLE : app.getAppState()).append("\",\"").append(app.getFinalAppStatus()).append("\",\"").append(app.getRunningContainers() == -1 ? "N/A" : String.valueOf(app.getRunningContainers())).append("\",\"").append(app.getAllocatedCpuVcores() == -1 ? "N/A" : String.valueOf(app.getAllocatedCpuVcores())).append("\",\"").append(app.getAllocatedMemoryMB() == -1 ? "N/A" : String.valueOf(app.getAllocatedMemoryMB())).append("\",\"").append(queuePercent).append("\",\"").append(clusterPercent).append("\",\"").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>").append("\",\"<a ");
        String trackingURL = app.getTrackingUrl() == null || app.getTrackingUrl().equals(UNAVAILABLE) || app.getAppState() == YarnApplicationState.NEW ? null : app.getTrackingUrl();
        String trackingUI = app.getTrackingUrl() == null || app.getTrackingUrl().equals(UNAVAILABLE) || app.getAppState() == YarnApplicationState.NEW ? "Unassigned" : app.getAppState() == YarnApplicationState.FINISHED || app.getAppState() == YarnApplicationState.FAILED || app.getAppState() == YarnApplicationState.KILLED ? "History" : "ApplicationMaster";
        appsTableData.append(trackingURL == null ? "#" : "href='" + trackingURL).append("'>").append(trackingUI).append("</a>\",").append("\"").append(blacklistedNodesCount).append("\"],\n");
    }
    if (appsTableData.charAt(appsTableData.length() - 2) == ',') {
        appsTableData.delete(appsTableData.length() - 2, appsTableData.length() - 1);
    }
    appsTableData.append("]");
    html.script().$type("text/javascript")._("var appsTableData=" + appsTableData)._();
    tbody._()._();
}
Also used : TABLE(org.apache.hadoop.yarn.webapp.hamlet.Hamlet.TABLE) ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) RMAppAttempt(org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) AppInfo(org.apache.hadoop.yarn.server.webapp.dao.AppInfo)

Example 3 with AppInfo

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

the class AHSWebServices method getLogs.

//TODO: YARN-4993: Refactory ContainersLogsBlock, AggregatedLogsBlock and
//      container log webservice introduced in AHS to minimize
//      the duplication.
@GET
@Path("/containerlogs/{containerid}/{filename}")
@Produces({ MediaType.TEXT_PLAIN + "; " + JettyUtils.UTF_8 })
@Public
@Unstable
public Response getLogs(@Context HttpServletRequest req, @Context HttpServletResponse res, @PathParam(YarnWebServiceParams.CONTAINER_ID) String containerIdStr, @PathParam(YarnWebServiceParams.CONTAINER_LOG_FILE_NAME) String filename, @QueryParam(YarnWebServiceParams.RESPONSE_CONTENT_FORMAT) String format, @QueryParam(YarnWebServiceParams.RESPONSE_CONTENT_SIZE) String size, @QueryParam(YarnWebServiceParams.NM_ID) String nmId, @QueryParam(YarnWebServiceParams.REDIRECTED_FROM_NODE) @DefaultValue("false") boolean redirected_from_node) {
    init(res);
    ContainerId containerId;
    try {
        containerId = ContainerId.fromString(containerIdStr);
    } catch (IllegalArgumentException ex) {
        return createBadResponse(Status.NOT_FOUND, "Invalid ContainerId: " + containerIdStr);
    }
    final long length = parseLongParam(size);
    ApplicationId appId = containerId.getApplicationAttemptId().getApplicationId();
    AppInfo appInfo;
    try {
        appInfo = super.getApp(req, res, appId.toString());
    } catch (Exception ex) {
        // directly find logs from HDFS.
        return sendStreamOutputResponse(appId, null, null, containerIdStr, filename, format, length, false);
    }
    String appOwner = appInfo.getUser();
    if (isFinishedState(appInfo.getAppState())) {
        // directly find logs from HDFS.
        return sendStreamOutputResponse(appId, appOwner, null, containerIdStr, filename, format, length, false);
    }
    if (isRunningState(appInfo.getAppState())) {
        String nodeHttpAddress = null;
        if (nmId != null && !nmId.isEmpty()) {
            try {
                nodeHttpAddress = getNMWebAddressFromRM(conf, nmId);
            } catch (Exception ex) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug(ex.getMessage());
                }
            }
        }
        if (nodeHttpAddress == null || nodeHttpAddress.isEmpty()) {
            ContainerInfo containerInfo;
            try {
                containerInfo = super.getContainer(req, res, appId.toString(), containerId.getApplicationAttemptId().toString(), containerId.toString());
            } catch (Exception ex) {
                // output the aggregated logs
                return sendStreamOutputResponse(appId, appOwner, null, containerIdStr, filename, format, length, true);
            }
            nodeHttpAddress = containerInfo.getNodeHttpAddress();
            // request back. Simply output the aggregated logs.
            if (nodeHttpAddress == null || nodeHttpAddress.isEmpty() || redirected_from_node) {
                // output the aggregated logs
                return sendStreamOutputResponse(appId, appOwner, null, containerIdStr, filename, format, length, true);
            }
        }
        String uri = "/" + containerId.toString() + "/logs/" + filename;
        String resURI = JOINER.join(getAbsoluteNMWebAddress(nodeHttpAddress), NM_DOWNLOAD_URI_STR, uri);
        String query = req.getQueryString();
        if (query != null && !query.isEmpty()) {
            resURI += "?" + query;
        }
        ResponseBuilder response = Response.status(HttpServletResponse.SC_TEMPORARY_REDIRECT);
        response.header("Location", resURI);
        return response.build();
    } else {
        return createBadResponse(Status.NOT_FOUND, "The application is not at Running or Finished State.");
    }
}
Also used : ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ContainerInfo(org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) 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) AppInfo(org.apache.hadoop.yarn.server.webapp.dao.AppInfo) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Unstable(org.apache.hadoop.classification.InterfaceStability.Unstable) Public(org.apache.hadoop.classification.InterfaceAudience.Public)

Example 4 with AppInfo

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

the class AppsBlock method renderData.

protected void renderData(Block html) {
    TBODY<TABLE<Hamlet>> tbody = html.table("#apps").thead().tr().th(".id", "ID").th(".user", "User").th(".name", "Name").th(".type", "Application Type").th(".queue", "Queue").th(".priority", "Application Priority").th(".starttime", "StartTime").th(".finishtime", "FinishTime").th(".state", "State").th(".finalstatus", "FinalStatus").th(".progress", "Progress").th(".ui", "Tracking UI")._()._().tbody();
    StringBuilder appsTableData = new StringBuilder("[\n");
    for (ApplicationReport appReport : appReports) {
        // hasn't filtering capability (YARN-1819).
        if (!reqAppStates.isEmpty() && !reqAppStates.contains(appReport.getYarnApplicationState())) {
            continue;
        }
        AppInfo app = new AppInfo(appReport);
        String percent = StringUtils.format("%.1f", app.getProgress());
        appsTableData.append("[\"<a href='").append(url("app", app.getAppId())).append("'>").append(app.getAppId()).append("</a>\",\"").append(StringEscapeUtils.escapeJavaScript(StringEscapeUtils.escapeHtml(app.getUser()))).append("\",\"").append(StringEscapeUtils.escapeJavaScript(StringEscapeUtils.escapeHtml(app.getName()))).append("\",\"").append(StringEscapeUtils.escapeJavaScript(StringEscapeUtils.escapeHtml(app.getType()))).append("\",\"").append(StringEscapeUtils.escapeJavaScript(StringEscapeUtils.escapeHtml(app.getQueue()))).append("\",\"").append(String.valueOf(app.getPriority())).append("\",\"").append(app.getStartedTime()).append("\",\"").append(app.getFinishedTime()).append("\",\"").append(app.getAppState() == null ? UNAVAILABLE : app.getAppState()).append("\",\"").append(app.getFinalAppStatus()).append("\",\"").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>").append("\",\"<a ");
        String trackingURL = app.getTrackingUrl() == null || app.getTrackingUrl().equals(UNAVAILABLE) ? null : app.getTrackingUrl();
        String trackingUI = app.getTrackingUrl() == null || app.getTrackingUrl().equals(UNAVAILABLE) ? "Unassigned" : app.getAppState() == YarnApplicationState.FINISHED || app.getAppState() == YarnApplicationState.FAILED || app.getAppState() == YarnApplicationState.KILLED ? "History" : "ApplicationMaster";
        appsTableData.append(trackingURL == null ? "#" : "href='" + trackingURL).append("'>").append(trackingUI).append("</a>\"],\n");
    }
    if (appsTableData.charAt(appsTableData.length() - 2) == ',') {
        appsTableData.delete(appsTableData.length() - 2, appsTableData.length() - 1);
    }
    appsTableData.append("]");
    html.script().$type("text/javascript")._("var appsTableData=" + appsTableData)._();
    tbody._()._();
}
Also used : TABLE(org.apache.hadoop.yarn.webapp.hamlet.Hamlet.TABLE) ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) AppInfo(org.apache.hadoop.yarn.server.webapp.dao.AppInfo)

Example 5 with AppInfo

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

the class AHSWebServices method getContainerLogsInfo.

// TODO: YARN-6080: Create WebServiceUtils to have common functions used in
//       RMWebService, NMWebService and AHSWebService.
/**
   * Returns log file's name as well as current file size for a container.
   *
   * @param req
   *    HttpServletRequest
   * @param res
   *    HttpServletResponse
   * @param containerIdStr
   *    The container ID
   * @param nmId
   *    The Node Manager NodeId
   * @param redirected_from_node
   *    Whether this is a redirected request from NM
   * @return
   *    The log file's name and current file size
   */
@GET
@Path("/containers/{containerid}/logs")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getContainerLogsInfo(@Context HttpServletRequest req, @Context HttpServletResponse res, @PathParam(YarnWebServiceParams.CONTAINER_ID) String containerIdStr, @QueryParam(YarnWebServiceParams.NM_ID) String nmId, @QueryParam(YarnWebServiceParams.REDIRECTED_FROM_NODE) @DefaultValue("false") boolean redirected_from_node) {
    ContainerId containerId = null;
    init(res);
    try {
        containerId = ContainerId.fromString(containerIdStr);
    } catch (IllegalArgumentException e) {
        throw new BadRequestException("invalid container id, " + containerIdStr);
    }
    ApplicationId appId = containerId.getApplicationAttemptId().getApplicationId();
    AppInfo appInfo;
    try {
        appInfo = super.getApp(req, res, appId.toString());
    } catch (Exception ex) {
        // directly find logs from HDFS.
        return getContainerLogMeta(appId, null, null, containerIdStr, false);
    }
    // from HDFS.
    if (isFinishedState(appInfo.getAppState())) {
        return getContainerLogMeta(appId, null, null, containerIdStr, false);
    }
    if (isRunningState(appInfo.getAppState())) {
        String appOwner = appInfo.getUser();
        String nodeHttpAddress = null;
        if (nmId != null && !nmId.isEmpty()) {
            try {
                nodeHttpAddress = getNMWebAddressFromRM(conf, nmId);
            } catch (Exception ex) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug(ex.getMessage());
                }
            }
        }
        if (nodeHttpAddress == null || nodeHttpAddress.isEmpty()) {
            ContainerInfo containerInfo;
            try {
                containerInfo = super.getContainer(req, res, appId.toString(), containerId.getApplicationAttemptId().toString(), containerId.toString());
            } catch (Exception ex) {
                // It will also return empty log meta for the local logs.
                return getContainerLogMeta(appId, appOwner, null, containerIdStr, true);
            }
            nodeHttpAddress = containerInfo.getNodeHttpAddress();
            // re-directing the request
            if (nodeHttpAddress == null || nodeHttpAddress.isEmpty() || redirected_from_node) {
                // re-direct the request back. Simply output the aggregated log meta.
                return getContainerLogMeta(appId, appOwner, null, containerIdStr, true);
            }
        }
        String uri = "/" + containerId.toString() + "/logs";
        String resURI = JOINER.join(getAbsoluteNMWebAddress(nodeHttpAddress), NM_DOWNLOAD_URI_STR, uri);
        String query = req.getQueryString();
        if (query != null && !query.isEmpty()) {
            resURI += "?" + query;
        }
        ResponseBuilder response = Response.status(HttpServletResponse.SC_TEMPORARY_REDIRECT);
        response.header("Location", resURI);
        return response.build();
    } else {
        throw new NotFoundException("The application is not at Running or Finished State.");
    }
}
Also used : ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ContainerInfo(org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) 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) AppInfo(org.apache.hadoop.yarn.server.webapp.dao.AppInfo) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

AppInfo (org.apache.hadoop.yarn.server.webapp.dao.AppInfo)7 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)5 WebApplicationException (javax.ws.rs.WebApplicationException)4 BadRequestException (org.apache.hadoop.yarn.webapp.BadRequestException)4 NotFoundException (org.apache.hadoop.yarn.webapp.NotFoundException)4 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)3 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)3 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)3 ContainerNotFoundException (org.apache.hadoop.yarn.exceptions.ContainerNotFoundException)3 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)2 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)2 IOException (java.io.IOException)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)2 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)2 GetApplicationReportRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest)2 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)2