Search in sources :

Example 16 with ContainerReport

use of org.apache.hadoop.yarn.api.records.ContainerReport in project samza by apache.

the class YarnJobValidationTool method validateContainerCount.

public int validateContainerCount(ApplicationAttemptId attemptId) throws Exception {
    int runningContainerCount = 0;
    for (ContainerReport containerReport : this.client.getContainers(attemptId)) {
        if (containerReport.getContainerState() == ContainerState.RUNNING) {
            ++runningContainerCount;
        }
    }
    // expected containers to be the configured job containers plus the AppMaster container
    int containerExpected = this.config.getContainerCount() + 1;
    if (runningContainerCount == containerExpected) {
        log.info("Container count matches. " + runningContainerCount + " containers are running.");
        return runningContainerCount;
    } else {
        throw new SamzaException("Container count does not match. " + runningContainerCount + " containers are running, while " + containerExpected + " is expected.");
    }
}
Also used : ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) SamzaException(org.apache.samza.SamzaException)

Example 17 with ContainerReport

use of org.apache.hadoop.yarn.api.records.ContainerReport in project samza by apache.

the class TestYarnJobValidationTool method testValidateContainerCount.

@Test
public void testValidateContainerCount() throws Exception {
    List<ContainerReport> containerReports = new ArrayList<>();
    for (int i = 0; i <= containerCount; i++) {
        ContainerReport report = mock(ContainerReport.class);
        when(report.getContainerState()).thenReturn(ContainerState.RUNNING);
        containerReports.add(report);
    }
    when(client.getContainers(attemptId)).thenReturn(containerReports);
    assertTrue(tool.validateContainerCount(attemptId) == (containerCount + 1));
    containerReports.remove(0);
    exception.expect(SamzaException.class);
    tool.validateContainerCount(attemptId);
}
Also used : ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 18 with ContainerReport

use of org.apache.hadoop.yarn.api.records.ContainerReport 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 19 with ContainerReport

use of org.apache.hadoop.yarn.api.records.ContainerReport in project hadoop by apache.

the class LogsCLI method getContainerReportsFromRunningApplication.

private List<ContainerReport> getContainerReportsFromRunningApplication(ContainerLogsRequest options) throws YarnException, IOException {
    List<ContainerReport> reports = new ArrayList<ContainerReport>();
    List<ApplicationAttemptReport> attempts = yarnClient.getApplicationAttempts(options.getAppId());
    Map<ContainerId, ContainerReport> containerMap = new TreeMap<ContainerId, ContainerReport>();
    for (ApplicationAttemptReport attempt : attempts) {
        List<ContainerReport> containers = yarnClient.getContainers(attempt.getApplicationAttemptId());
        for (ContainerReport container : containers) {
            if (!containerMap.containsKey(container.getContainerId())) {
                containerMap.put(container.getContainerId(), container);
            }
        }
    }
    reports.addAll(containerMap.values());
    return reports;
}
Also used : ApplicationAttemptReport(org.apache.hadoop.yarn.api.records.ApplicationAttemptReport) ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap)

Example 20 with ContainerReport

use of org.apache.hadoop.yarn.api.records.ContainerReport in project hadoop by apache.

the class LogsCLI method getContainersLogRequestForRunningApplication.

private List<ContainerLogsRequest> getContainersLogRequestForRunningApplication(ContainerLogsRequest options) throws YarnException, IOException {
    List<ContainerLogsRequest> newOptionsList = new ArrayList<ContainerLogsRequest>();
    List<ContainerReport> reports = getContainerReportsFromRunningApplication(options);
    for (ContainerReport container : reports) {
        ContainerLogsRequest newOptions = new ContainerLogsRequest(options);
        newOptions.setContainerId(container.getContainerId().toString());
        newOptions.setNodeId(container.getAssignedNode().toString());
        String httpAddress = container.getNodeHttpAddress();
        if (httpAddress != null && !httpAddress.isEmpty()) {
            newOptions.setNodeHttpAddress(httpAddress.replaceFirst(WebAppUtils.getHttpSchemePrefix(getConf()), ""));
        }
        newOptions.setContainerState(container.getContainerState());
        newOptionsList.add(newOptions);
    }
    return newOptionsList;
}
Also used : ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) ArrayList(java.util.ArrayList) ContainerLogsRequest(org.apache.hadoop.yarn.logaggregation.ContainerLogsRequest)

Aggregations

ContainerReport (org.apache.hadoop.yarn.api.records.ContainerReport)36 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)16 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)16 Test (org.junit.Test)16 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)14 ArrayList (java.util.ArrayList)9 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)8 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)8 Configuration (org.apache.hadoop.conf.Configuration)7 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)5 ApplicationAttemptReport (org.apache.hadoop.yarn.api.records.ApplicationAttemptReport)5 YarnClient (org.apache.hadoop.yarn.client.api.YarnClient)5 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)5 ContainerInfo (org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo)5 PrintWriter (java.io.PrintWriter)4 GetContainersRequest (org.apache.hadoop.yarn.api.protocolrecords.GetContainersRequest)4 ApplicationAttemptNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException)4 ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)4 ContainerNotFoundException (org.apache.hadoop.yarn.exceptions.ContainerNotFoundException)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3