Search in sources :

Example 6 with ContainerInfo

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

the class ContainerBlock method render.

@Override
protected void render(Block html) {
    String containerid = $(CONTAINER_ID);
    if (containerid.isEmpty()) {
        puts("Bad request: requires container ID");
        return;
    }
    ContainerId containerId = null;
    try {
        containerId = ContainerId.fromString(containerid);
    } catch (IllegalArgumentException e) {
        puts("Invalid container ID: " + containerid);
        return;
    }
    UserGroupInformation callerUGI = getCallerUGI();
    ContainerReport containerReport = null;
    try {
        final GetContainerReportRequest request = GetContainerReportRequest.newInstance(containerId);
        if (callerUGI == null) {
            containerReport = appBaseProt.getContainerReport(request).getContainerReport();
        } else {
            containerReport = callerUGI.doAs(new PrivilegedExceptionAction<ContainerReport>() {

                @Override
                public ContainerReport run() throws Exception {
                    return appBaseProt.getContainerReport(request).getContainerReport();
                }
            });
        }
    } catch (Exception e) {
        String message = "Failed to read the container " + containerid + ".";
        LOG.error(message, e);
        html.p()._(message)._();
        return;
    }
    if (containerReport == null) {
        puts("Container not found: " + containerid);
        return;
    }
    ContainerInfo container = new ContainerInfo(containerReport);
    setTitle(join("Container ", containerid));
    info("Container Overview")._("Container State:", container.getContainerState() == null ? UNAVAILABLE : container.getContainerState())._("Exit Status:", container.getContainerExitStatus())._("Node:", container.getNodeHttpAddress() == null ? "#" : container.getNodeHttpAddress(), container.getNodeHttpAddress() == null ? "N/A" : container.getNodeHttpAddress())._("Priority:", container.getPriority())._("Started:", Times.format(container.getStartedTime()))._("Elapsed:", StringUtils.formatTime(Times.elapsed(container.getStartedTime(), container.getFinishedTime())))._("Resource:", container.getAllocatedMB() + " Memory, " + container.getAllocatedVCores() + " VCores")._("Logs:", container.getLogUrl() == null ? "#" : container.getLogUrl(), container.getLogUrl() == null ? "N/A" : "Logs")._("Diagnostics:", container.getDiagnosticsInfo() == null ? "" : container.getDiagnosticsInfo());
    html._(InfoBlock.class);
}
Also used : ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) ContainerInfo(org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) GetContainerReportRequest(org.apache.hadoop.yarn.api.protocolrecords.GetContainerReportRequest)

Example 7 with ContainerInfo

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

the class WebServices method getContainers.

public ContainersInfo getContainers(HttpServletRequest req, HttpServletResponse res, String appId, String appAttemptId) {
    UserGroupInformation callerUGI = getUser(req);
    ApplicationId aid = parseApplicationId(appId);
    final ApplicationAttemptId aaid = parseApplicationAttemptId(appAttemptId);
    validateIds(aid, aaid, null);
    Collection<ContainerReport> containerReports = null;
    try {
        if (callerUGI == null) {
            GetContainersRequest request = GetContainersRequest.newInstance(aaid);
            containerReports = appBaseProt.getContainers(request).getContainerList();
        } else {
            containerReports = callerUGI.doAs(new PrivilegedExceptionAction<Collection<ContainerReport>>() {

                @Override
                public Collection<ContainerReport> run() throws Exception {
                    GetContainersRequest request = GetContainersRequest.newInstance(aaid);
                    return appBaseProt.getContainers(request).getContainerList();
                }
            });
        }
    } catch (Exception e) {
        rewrapAndThrowException(e);
    }
    ContainersInfo containersInfo = new ContainersInfo();
    if (containerReports == null) {
        return containersInfo;
    }
    for (ContainerReport containerReport : containerReports) {
        ContainerInfo containerInfo = new ContainerInfo(containerReport);
        containersInfo.add(containerInfo);
    }
    return containersInfo;
}
Also used : ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) ContainerInfo(org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ContainersInfo(org.apache.hadoop.yarn.server.webapp.dao.ContainersInfo) GetContainersRequest(org.apache.hadoop.yarn.api.protocolrecords.GetContainersRequest) 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)

Aggregations

ContainerInfo (org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo)7 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)5 ContainerReport (org.apache.hadoop.yarn.api.records.ContainerReport)5 WebApplicationException (javax.ws.rs.WebApplicationException)4 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)4 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)4 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)4 BadRequestException (org.apache.hadoop.yarn.webapp.BadRequestException)4 NotFoundException (org.apache.hadoop.yarn.webapp.NotFoundException)4 GetContainerReportRequest (org.apache.hadoop.yarn.api.protocolrecords.GetContainerReportRequest)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