Search in sources :

Example 1 with GetContainersResponse

use of org.apache.hadoop.yarn.api.protocolrecords.GetContainersResponse 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 2 with GetContainersResponse

use of org.apache.hadoop.yarn.api.protocolrecords.GetContainersResponse 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 3 with GetContainersResponse

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

Example 4 with GetContainersResponse

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

the class AHSClientImpl method getContainers.

@Override
public List<ContainerReport> getContainers(ApplicationAttemptId applicationAttemptId) throws YarnException, IOException {
    GetContainersRequest request = GetContainersRequest.newInstance(applicationAttemptId);
    GetContainersResponse response = ahsClient.getContainers(request);
    return response.getContainerList();
}
Also used : GetContainersResponse(org.apache.hadoop.yarn.api.protocolrecords.GetContainersResponse) GetContainersRequest(org.apache.hadoop.yarn.api.protocolrecords.GetContainersRequest)

Example 5 with GetContainersResponse

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

the class ClientRMService method getContainers.

/*
   * (non-Javadoc)
   * 
   * we're going to fix the issue of showing non-running containers of the
   * running application in YARN-1794"
   */
@Override
public GetContainersResponse getContainers(GetContainersRequest request) throws YarnException, IOException {
    ApplicationAttemptId appAttemptId = request.getApplicationAttemptId();
    ApplicationId appId = appAttemptId.getApplicationId();
    UserGroupInformation callerUGI;
    try {
        callerUGI = UserGroupInformation.getCurrentUser();
    } catch (IOException ie) {
        LOG.info("Error getting UGI ", ie);
        throw RPCUtil.getRemoteException(ie);
    }
    RMApp application = this.rmContext.getRMApps().get(appId);
    if (application == null) {
        // ApplicationNotFoundException and let client to handle.
        throw new ApplicationNotFoundException("Application with id '" + appId + "' doesn't exist in RM. Please check that the job submission " + "was successful.");
    }
    boolean allowAccess = checkAccess(callerUGI, application.getUser(), ApplicationAccessType.VIEW_APP, application);
    GetContainersResponse response = null;
    if (allowAccess) {
        RMAppAttempt appAttempt = application.getAppAttempts().get(appAttemptId);
        if (appAttempt == null) {
            throw new ApplicationAttemptNotFoundException("ApplicationAttempt with id '" + appAttemptId + "' doesn't exist in RM.");
        }
        Collection<RMContainer> rmContainers = Collections.emptyList();
        SchedulerAppReport schedulerAppReport = this.rmContext.getScheduler().getSchedulerAppInfo(appAttemptId);
        if (schedulerAppReport != null) {
            rmContainers = schedulerAppReport.getLiveContainers();
        }
        List<ContainerReport> listContainers = new ArrayList<ContainerReport>();
        for (RMContainer rmContainer : rmContainers) {
            listContainers.add(rmContainer.createContainerReport());
        }
        response = GetContainersResponse.newInstance(listContainers);
    } else {
        throw new YarnException("User " + callerUGI.getShortUserName() + " does not have privilege to see this application " + appId);
    }
    return response;
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) RMAppAttempt(org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt) ArrayList(java.util.ArrayList) GetContainersResponse(org.apache.hadoop.yarn.api.protocolrecords.GetContainersResponse) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) IOException(java.io.IOException) RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) SchedulerAppReport(org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerAppReport) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Aggregations

GetContainersResponse (org.apache.hadoop.yarn.api.protocolrecords.GetContainersResponse)5 GetContainersRequest (org.apache.hadoop.yarn.api.protocolrecords.GetContainersRequest)4 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)3 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)3 ContainerReport (org.apache.hadoop.yarn.api.records.ContainerReport)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)2 ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)2 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)2 Test (org.junit.Test)2 HashSet (java.util.HashSet)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 ApplicationAttemptNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException)1 RecordFactory (org.apache.hadoop.yarn.factories.RecordFactory)1 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)1 RMAppAttempt (org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt)1 RMContainer (org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer)1 SchedulerAppReport (org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerAppReport)1