Search in sources :

Example 6 with GetContainerReportRequest

use of org.apache.hadoop.yarn.api.protocolrecords.GetContainerReportRequest in project hadoop by apache.

the class WebServices method getContainer.

public ContainerInfo getContainer(HttpServletRequest req, HttpServletResponse res, String appId, String appAttemptId, String containerId) {
    UserGroupInformation callerUGI = getUser(req);
    ApplicationId aid = parseApplicationId(appId);
    ApplicationAttemptId aaid = parseApplicationAttemptId(appAttemptId);
    final ContainerId cid = parseContainerId(containerId);
    validateIds(aid, aaid, cid);
    ContainerReport container = null;
    try {
        if (callerUGI == null) {
            GetContainerReportRequest request = GetContainerReportRequest.newInstance(cid);
            container = appBaseProt.getContainerReport(request).getContainerReport();
        } else {
            container = callerUGI.doAs(new PrivilegedExceptionAction<ContainerReport>() {

                @Override
                public ContainerReport run() throws Exception {
                    GetContainerReportRequest request = GetContainerReportRequest.newInstance(cid);
                    return appBaseProt.getContainerReport(request).getContainerReport();
                }
            });
        }
    } catch (Exception e) {
        rewrapAndThrowException(e);
    }
    if (container == null) {
        throw new NotFoundException("container with id: " + containerId + " not found");
    }
    return new ContainerInfo(container);
}
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) 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) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) 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) GetContainerReportRequest(org.apache.hadoop.yarn.api.protocolrecords.GetContainerReportRequest)

Example 7 with GetContainerReportRequest

use of org.apache.hadoop.yarn.api.protocolrecords.GetContainerReportRequest in project hadoop by apache.

the class TestApplicationHistoryClientService method testContainerNotFound.

@Test
public void testContainerNotFound() throws IOException, YarnException {
    ApplicationId appId = ApplicationId.newInstance(0, 1);
    ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1);
    ContainerId containerId = ContainerId.newContainerId(appAttemptId, MAX_APPS + 1);
    GetContainerReportRequest request = GetContainerReportRequest.newInstance(containerId);
    try {
        @SuppressWarnings("unused") GetContainerReportResponse response = clientService.getContainerReport(request);
    } catch (ContainerNotFoundException e) {
        //This exception is expected
        Assert.assertTrue(e.getMessage().contains("doesn't exist in the timeline store"));
    } catch (Exception e) {
        Assert.fail("Undesired exception caught");
    }
}
Also used : ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) GetContainerReportResponse(org.apache.hadoop.yarn.api.protocolrecords.GetContainerReportResponse) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) GetContainerReportRequest(org.apache.hadoop.yarn.api.protocolrecords.GetContainerReportRequest) Test(org.junit.Test)

Example 8 with GetContainerReportRequest

use of org.apache.hadoop.yarn.api.protocolrecords.GetContainerReportRequest 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)

Aggregations

GetContainerReportRequest (org.apache.hadoop.yarn.api.protocolrecords.GetContainerReportRequest)8 GetContainerReportResponse (org.apache.hadoop.yarn.api.protocolrecords.GetContainerReportResponse)5 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)5 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)4 ContainerReport (org.apache.hadoop.yarn.api.records.ContainerReport)4 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)3 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)3 ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)3 ContainerNotFoundException (org.apache.hadoop.yarn.exceptions.ContainerNotFoundException)3 ContainerInfo (org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo)3 Test (org.junit.Test)3 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)2 ApplicationAttemptNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException)2 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)2 IOException (java.io.IOException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 AuthenticationException (org.apache.hadoop.security.authentication.client.AuthenticationException)1 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)1 ApplicationAttemptReport (org.apache.hadoop.yarn.api.records.ApplicationAttemptReport)1