Search in sources :

Example 1 with GetContainersRequest

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

the class TestClientRMService method testGetContainers.

@Test
public void testGetContainers() throws YarnException, IOException {
    ClientRMService rmService = createRMService();
    RecordFactory recordFactory = RecordFactoryProvider.getRecordFactory(null);
    GetContainersRequest request = recordFactory.newRecordInstance(GetContainersRequest.class);
    ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(ApplicationId.newInstance(123456, 1), 1);
    ContainerId containerId = ContainerId.newContainerId(attemptId, 1);
    request.setApplicationAttemptId(attemptId);
    try {
        GetContainersResponse response = rmService.getContainers(request);
        Assert.assertEquals(containerId, response.getContainerList().get(0).getContainerId());
    } catch (ApplicationNotFoundException ex) {
        Assert.fail(ex.getMessage());
    }
}
Also used : RecordFactory(org.apache.hadoop.yarn.factories.RecordFactory) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) GetContainersResponse(org.apache.hadoop.yarn.api.protocolrecords.GetContainersResponse) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) GetContainersRequest(org.apache.hadoop.yarn.api.protocolrecords.GetContainersRequest) Test(org.junit.Test)

Example 2 with GetContainersRequest

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

the class TestApplicationHistoryClientService method testContainers.

@Test
public void testContainers() throws IOException, YarnException {
    ApplicationId appId = ApplicationId.newInstance(0, 1);
    ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1);
    ContainerId containerId = ContainerId.newContainerId(appAttemptId, 1);
    ContainerId containerId1 = ContainerId.newContainerId(appAttemptId, 2);
    GetContainersRequest request = GetContainersRequest.newInstance(appAttemptId);
    GetContainersResponse response = clientService.getContainers(request);
    List<ContainerReport> containers = response.getContainerList();
    Assert.assertNotNull(containers);
    Assert.assertEquals(containerId, containers.get(0).getContainerId());
    Assert.assertEquals(containerId1, containers.get(1).getContainerId());
}
Also used : ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) GetContainersResponse(org.apache.hadoop.yarn.api.protocolrecords.GetContainersResponse) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) GetContainersRequest(org.apache.hadoop.yarn.api.protocolrecords.GetContainersRequest) Test(org.junit.Test)

Example 3 with GetContainersRequest

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

the class AppAttemptBlock method render.

@Override
protected void render(Block html) {
    String attemptid = $(APPLICATION_ATTEMPT_ID);
    if (attemptid.isEmpty()) {
        puts("Bad request: requires application attempt ID");
        return;
    }
    try {
        appAttemptId = ApplicationAttemptId.fromString(attemptid);
    } catch (IllegalArgumentException e) {
        puts("Invalid application attempt ID: " + attemptid);
        return;
    }
    UserGroupInformation callerUGI = getCallerUGI();
    ApplicationAttemptReport appAttemptReport;
    try {
        final GetApplicationAttemptReportRequest request = GetApplicationAttemptReportRequest.newInstance(appAttemptId);
        if (callerUGI == null) {
            appAttemptReport = appBaseProt.getApplicationAttemptReport(request).getApplicationAttemptReport();
        } else {
            appAttemptReport = callerUGI.doAs(new PrivilegedExceptionAction<ApplicationAttemptReport>() {

                @Override
                public ApplicationAttemptReport run() throws Exception {
                    return appBaseProt.getApplicationAttemptReport(request).getApplicationAttemptReport();
                }
            });
        }
    } catch (Exception e) {
        String message = "Failed to read the application attempt " + appAttemptId + ".";
        LOG.error(message, e);
        html.p()._(message)._();
        return;
    }
    if (appAttemptReport == null) {
        puts("Application Attempt not found: " + attemptid);
        return;
    }
    boolean exceptionWhenGetContainerReports = false;
    Collection<ContainerReport> containers = null;
    try {
        final GetContainersRequest request = GetContainersRequest.newInstance(appAttemptId);
        if (callerUGI == null) {
            containers = appBaseProt.getContainers(request).getContainerList();
        } else {
            containers = callerUGI.doAs(new PrivilegedExceptionAction<Collection<ContainerReport>>() {

                @Override
                public Collection<ContainerReport> run() throws Exception {
                    return appBaseProt.getContainers(request).getContainerList();
                }
            });
        }
    } catch (RuntimeException e) {
        // have this block to suppress the findbugs warning
        exceptionWhenGetContainerReports = true;
    } catch (Exception e) {
        exceptionWhenGetContainerReports = true;
    }
    AppAttemptInfo appAttempt = new AppAttemptInfo(appAttemptReport);
    setTitle(join("Application Attempt ", attemptid));
    String node = "N/A";
    if (appAttempt.getHost() != null && appAttempt.getRpcPort() >= 0 && appAttempt.getRpcPort() < 65536) {
        node = appAttempt.getHost() + ":" + appAttempt.getRpcPort();
    }
    generateOverview(appAttemptReport, containers, appAttempt, node);
    if (exceptionWhenGetContainerReports) {
        html.p()._("Sorry, Failed to get containers for application attempt" + attemptid + ".")._();
        return;
    }
    createAttemptHeadRoomTable(html);
    html._(InfoBlock.class);
    createTablesForAttemptMetrics(html);
    // Container Table
    TBODY<TABLE<Hamlet>> tbody = html.table("#containers").thead().tr().th(".id", "Container ID").th(".node", "Node").th(".exitstatus", "Container Exit Status").th(".logs", "Logs")._()._().tbody();
    StringBuilder containersTableData = new StringBuilder("[\n");
    for (ContainerReport containerReport : containers) {
        ContainerInfo container = new ContainerInfo(containerReport);
        containersTableData.append("[\"<a href='").append(url("container", container.getContainerId())).append("'>").append(container.getContainerId()).append("</a>\",\"<a ").append(container.getNodeHttpAddress() == null ? "#" : "href='" + container.getNodeHttpAddress()).append("'>").append(container.getNodeHttpAddress() == null ? "N/A" : StringEscapeUtils.escapeJavaScript(StringEscapeUtils.escapeHtml(container.getNodeHttpAddress()))).append("</a>\",\"").append(container.getContainerExitStatus()).append("\",\"<a href='").append(container.getLogUrl() == null ? "#" : container.getLogUrl()).append("'>").append(container.getLogUrl() == null ? "N/A" : "Logs").append("</a>\"],\n");
    }
    if (containersTableData.charAt(containersTableData.length() - 2) == ',') {
        containersTableData.delete(containersTableData.length() - 2, containersTableData.length() - 1);
    }
    containersTableData.append("]");
    html.script().$type("text/javascript")._("var containersTableData=" + containersTableData)._();
    tbody._()._();
}
Also used : AppAttemptInfo(org.apache.hadoop.yarn.server.webapp.dao.AppAttemptInfo) ApplicationAttemptReport(org.apache.hadoop.yarn.api.records.ApplicationAttemptReport) GetApplicationAttemptReportRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportRequest) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) TABLE(org.apache.hadoop.yarn.webapp.hamlet.Hamlet.TABLE) ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) ContainerInfo(org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo) GetContainersRequest(org.apache.hadoop.yarn.api.protocolrecords.GetContainersRequest) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 4 with GetContainersRequest

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

Example 5 with GetContainersRequest

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

the class YarnClientImpl method getContainers.

@Override
public List<ContainerReport> getContainers(ApplicationAttemptId applicationAttemptId) throws YarnException, IOException {
    List<ContainerReport> containersForAttempt = new ArrayList<ContainerReport>();
    boolean appNotFoundInRM = false;
    try {
        GetContainersRequest request = Records.newRecord(GetContainersRequest.class);
        request.setApplicationAttemptId(applicationAttemptId);
        GetContainersResponse response = rmClient.getContainers(request);
        containersForAttempt.addAll(response.getContainerList());
    } catch (YarnException e) {
        if (e.getClass() != ApplicationNotFoundException.class || !historyServiceEnabled) {
            // need to check with history service else throw exception.
            throw e;
        }
        appNotFoundInRM = true;
    }
    if (historyServiceEnabled) {
        // Check with AHS even if found in RM because to capture info of finished
        // containers also
        List<ContainerReport> containersListFromAHS = null;
        try {
            containersListFromAHS = historyClient.getContainers(applicationAttemptId);
        } catch (IOException e) {
            // is disabled hence app not found exception is possible
            if (appNotFoundInRM) {
                // app not found in bothM and RM then propagate the exception.
                throw e;
            }
        }
        if (null != containersListFromAHS && containersListFromAHS.size() > 0) {
            // remove duplicates
            Set<ContainerId> containerIdsToBeKeptFromAHS = new HashSet<ContainerId>();
            Iterator<ContainerReport> tmpItr = containersListFromAHS.iterator();
            while (tmpItr.hasNext()) {
                containerIdsToBeKeptFromAHS.add(tmpItr.next().getContainerId());
            }
            Iterator<ContainerReport> rmContainers = containersForAttempt.iterator();
            while (rmContainers.hasNext()) {
                ContainerReport tmp = rmContainers.next();
                containerIdsToBeKeptFromAHS.remove(tmp.getContainerId());
            // Remove containers from AHS as container from RM will have latest
            // information
            }
            if (containerIdsToBeKeptFromAHS.size() > 0 && containersListFromAHS.size() != containerIdsToBeKeptFromAHS.size()) {
                Iterator<ContainerReport> containersFromHS = containersListFromAHS.iterator();
                while (containersFromHS.hasNext()) {
                    ContainerReport containerReport = containersFromHS.next();
                    if (containerIdsToBeKeptFromAHS.contains(containerReport.getContainerId())) {
                        containersForAttempt.add(containerReport);
                    }
                }
            } else if (containersListFromAHS.size() == containerIdsToBeKeptFromAHS.size()) {
                containersForAttempt.addAll(containersListFromAHS);
            }
        }
    }
    return containersForAttempt;
}
Also used : ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ArrayList(java.util.ArrayList) GetContainersResponse(org.apache.hadoop.yarn.api.protocolrecords.GetContainersResponse) IOException(java.io.IOException) GetContainersRequest(org.apache.hadoop.yarn.api.protocolrecords.GetContainersRequest) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) HashSet(java.util.HashSet)

Aggregations

GetContainersRequest (org.apache.hadoop.yarn.api.protocolrecords.GetContainersRequest)6 GetContainersResponse (org.apache.hadoop.yarn.api.protocolrecords.GetContainersResponse)4 ContainerReport (org.apache.hadoop.yarn.api.records.ContainerReport)4 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)3 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)3 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)2 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)2 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)2 ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)2 ContainerInfo (org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)1 GetApplicationAttemptReportRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportRequest)1 ApplicationAttemptReport (org.apache.hadoop.yarn.api.records.ApplicationAttemptReport)1 ApplicationAttemptNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException)1