Search in sources :

Example 6 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)

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