Search in sources :

Example 1 with ContainerHistoryData

use of org.apache.hadoop.yarn.server.applicationhistoryservice.records.ContainerHistoryData in project hadoop by apache.

the class FileSystemApplicationHistoryStore method getContainers.

@Override
public Map<ContainerId, ContainerHistoryData> getContainers(ApplicationAttemptId appAttemptId) throws IOException {
    Map<ContainerId, ContainerHistoryData> historyDataMap = new HashMap<ContainerId, ContainerHistoryData>();
    HistoryFileReader hfReader = getHistoryFileReader(appAttemptId.getApplicationId());
    try {
        while (hfReader.hasNext()) {
            HistoryFileReader.Entry entry = hfReader.next();
            if (entry.key.id.startsWith(ConverterUtils.CONTAINER_PREFIX)) {
                ContainerId containerId = ContainerId.fromString(entry.key.id);
                if (containerId.getApplicationAttemptId().equals(appAttemptId)) {
                    ContainerHistoryData historyData = historyDataMap.get(containerId);
                    if (historyData == null) {
                        historyData = ContainerHistoryData.newInstance(containerId, null, null, null, Long.MIN_VALUE, Long.MAX_VALUE, null, Integer.MAX_VALUE, null);
                        historyDataMap.put(containerId, historyData);
                    }
                    if (entry.key.suffix.equals(START_DATA_SUFFIX)) {
                        mergeContainerHistoryData(historyData, parseContainerStartData(entry.value));
                    } else if (entry.key.suffix.equals(FINISH_DATA_SUFFIX)) {
                        mergeContainerHistoryData(historyData, parseContainerFinishData(entry.value));
                    }
                }
            }
        }
        LOG.info("Completed reading history information of all containers" + " of application attempt " + appAttemptId);
    } catch (IOException e) {
        LOG.info("Error when reading history information of some containers" + " of application attempt " + appAttemptId);
    } finally {
        hfReader.close();
    }
    return historyDataMap;
}
Also used : ContainerHistoryData(org.apache.hadoop.yarn.server.applicationhistoryservice.records.ContainerHistoryData) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) IOException(java.io.IOException)

Example 2 with ContainerHistoryData

use of org.apache.hadoop.yarn.server.applicationhistoryservice.records.ContainerHistoryData in project hadoop by apache.

the class FileSystemApplicationHistoryStore method getContainer.

@Override
public ContainerHistoryData getContainer(ContainerId containerId) throws IOException {
    HistoryFileReader hfReader = getHistoryFileReader(containerId.getApplicationAttemptId().getApplicationId());
    try {
        boolean readStartData = false;
        boolean readFinishData = false;
        ContainerHistoryData historyData = ContainerHistoryData.newInstance(containerId, null, null, null, Long.MIN_VALUE, Long.MAX_VALUE, null, Integer.MAX_VALUE, null);
        while ((!readStartData || !readFinishData) && hfReader.hasNext()) {
            HistoryFileReader.Entry entry = hfReader.next();
            if (entry.key.id.equals(containerId.toString())) {
                if (entry.key.suffix.equals(START_DATA_SUFFIX)) {
                    ContainerStartData startData = parseContainerStartData(entry.value);
                    mergeContainerHistoryData(historyData, startData);
                    readStartData = true;
                } else if (entry.key.suffix.equals(FINISH_DATA_SUFFIX)) {
                    ContainerFinishData finishData = parseContainerFinishData(entry.value);
                    mergeContainerHistoryData(historyData, finishData);
                    readFinishData = true;
                }
            }
        }
        if (!readStartData && !readFinishData) {
            return null;
        }
        if (!readStartData) {
            LOG.warn("Start information is missing for container " + containerId);
        }
        if (!readFinishData) {
            LOG.warn("Finish information is missing for container " + containerId);
        }
        LOG.info("Completed reading history information of container " + containerId);
        return historyData;
    } catch (IOException e) {
        LOG.error("Error when reading history file of container " + containerId, e);
        throw e;
    } finally {
        hfReader.close();
    }
}
Also used : ContainerStartData(org.apache.hadoop.yarn.server.applicationhistoryservice.records.ContainerStartData) ContainerHistoryData(org.apache.hadoop.yarn.server.applicationhistoryservice.records.ContainerHistoryData) IOException(java.io.IOException) ContainerFinishData(org.apache.hadoop.yarn.server.applicationhistoryservice.records.ContainerFinishData)

Example 3 with ContainerHistoryData

use of org.apache.hadoop.yarn.server.applicationhistoryservice.records.ContainerHistoryData in project hadoop by apache.

the class ApplicationHistoryManagerImpl method getContainers.

@Override
public Map<ContainerId, ContainerReport> getContainers(ApplicationAttemptId appAttemptId) throws IOException {
    ApplicationReport app = getApplication(appAttemptId.getApplicationId());
    Map<ContainerId, ContainerHistoryData> histData = historyStore.getContainers(appAttemptId);
    HashMap<ContainerId, ContainerReport> containersReport = new HashMap<ContainerId, ContainerReport>();
    for (Entry<ContainerId, ContainerHistoryData> entry : histData.entrySet()) {
        containersReport.put(entry.getKey(), convertToContainerReport(entry.getValue(), app == null ? null : app.getUser()));
    }
    return containersReport;
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) ContainerHistoryData(org.apache.hadoop.yarn.server.applicationhistoryservice.records.ContainerHistoryData) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) HashMap(java.util.HashMap) ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport)

Example 4 with ContainerHistoryData

use of org.apache.hadoop.yarn.server.applicationhistoryservice.records.ContainerHistoryData in project hadoop by apache.

the class MemoryApplicationHistoryStore method containerFinished.

@Override
public void containerFinished(ContainerFinishData containerFinish) throws IOException {
    ConcurrentMap<ContainerId, ContainerHistoryData> subMap = getSubMap(containerFinish.getContainerId().getApplicationAttemptId());
    ContainerHistoryData data = subMap.get(containerFinish.getContainerId());
    if (data == null) {
        throw new IOException("The finish information of container " + containerFinish.getContainerId() + " is stored before" + " the start information.");
    }
    // the finish information is already recorded
    if (data.getContainerState() != null) {
        throw new IOException("The finish information of container " + containerFinish.getContainerId() + " is already stored.");
    }
    data.setFinishTime(containerFinish.getFinishTime());
    data.setDiagnosticsInfo(containerFinish.getDiagnosticsInfo());
    data.setContainerExitStatus(containerFinish.getContainerExitStatus());
    data.setContainerState(containerFinish.getContainerState());
}
Also used : ContainerHistoryData(org.apache.hadoop.yarn.server.applicationhistoryservice.records.ContainerHistoryData) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) IOException(java.io.IOException)

Example 5 with ContainerHistoryData

use of org.apache.hadoop.yarn.server.applicationhistoryservice.records.ContainerHistoryData in project hadoop by apache.

the class MemoryApplicationHistoryStore method containerStarted.

@Override
public void containerStarted(ContainerStartData containerStart) throws IOException {
    ConcurrentMap<ContainerId, ContainerHistoryData> subMap = getSubMap(containerStart.getContainerId().getApplicationAttemptId());
    ContainerHistoryData oldData = subMap.putIfAbsent(containerStart.getContainerId(), ContainerHistoryData.newInstance(containerStart.getContainerId(), containerStart.getAllocatedResource(), containerStart.getAssignedNode(), containerStart.getPriority(), containerStart.getStartTime(), Long.MAX_VALUE, null, Integer.MAX_VALUE, null));
    if (oldData != null) {
        throw new IOException("The start information of container " + containerStart.getContainerId() + " is already stored.");
    }
}
Also used : ContainerHistoryData(org.apache.hadoop.yarn.server.applicationhistoryservice.records.ContainerHistoryData) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) IOException(java.io.IOException)

Aggregations

ContainerHistoryData (org.apache.hadoop.yarn.server.applicationhistoryservice.records.ContainerHistoryData)8 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)2 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)2 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)2 Test (org.junit.Test)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)1 ContainerReport (org.apache.hadoop.yarn.api.records.ContainerReport)1 ApplicationAttemptHistoryData (org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationAttemptHistoryData)1 ApplicationHistoryData (org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationHistoryData)1 ContainerFinishData (org.apache.hadoop.yarn.server.applicationhistoryservice.records.ContainerFinishData)1 ContainerStartData (org.apache.hadoop.yarn.server.applicationhistoryservice.records.ContainerStartData)1 RMContainer (org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer)1