Search in sources :

Example 1 with ApplicationAttemptHistoryData

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

the class TestMemoryApplicationHistoryStore method testReadWriteApplicationAttemptHistory.

@Test
public void testReadWriteApplicationAttemptHistory() throws Exception {
    // Out of order
    ApplicationId appId = ApplicationId.newInstance(0, 1);
    ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1);
    try {
        writeApplicationAttemptFinishData(appAttemptId);
        Assert.fail();
    } catch (IOException e) {
        Assert.assertTrue(e.getMessage().contains("is stored before the start information"));
    }
    // Normal
    int numAppAttempts = 5;
    writeApplicationStartData(appId);
    for (int i = 1; i <= numAppAttempts; ++i) {
        appAttemptId = ApplicationAttemptId.newInstance(appId, i);
        writeApplicationAttemptStartData(appAttemptId);
        writeApplicationAttemptFinishData(appAttemptId);
    }
    Assert.assertEquals(numAppAttempts, store.getApplicationAttempts(appId).size());
    for (int i = 1; i <= numAppAttempts; ++i) {
        appAttemptId = ApplicationAttemptId.newInstance(appId, i);
        ApplicationAttemptHistoryData data = store.getApplicationAttempt(appAttemptId);
        Assert.assertNotNull(data);
        Assert.assertEquals(appAttemptId.toString(), data.getHost());
        Assert.assertEquals(appAttemptId.toString(), data.getDiagnosticsInfo());
    }
    writeApplicationFinishData(appId);
    // Write again
    appAttemptId = ApplicationAttemptId.newInstance(appId, 1);
    try {
        writeApplicationAttemptStartData(appAttemptId);
        Assert.fail();
    } catch (IOException e) {
        Assert.assertTrue(e.getMessage().contains("is already stored"));
    }
    try {
        writeApplicationAttemptFinishData(appAttemptId);
        Assert.fail();
    } catch (IOException e) {
        Assert.assertTrue(e.getMessage().contains("is already stored"));
    }
}
Also used : ApplicationAttemptHistoryData(org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationAttemptHistoryData) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) IOException(java.io.IOException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Test(org.junit.Test)

Example 2 with ApplicationAttemptHistoryData

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

the class FileSystemApplicationHistoryStore method getApplicationAttempts.

@Override
public Map<ApplicationAttemptId, ApplicationAttemptHistoryData> getApplicationAttempts(ApplicationId appId) throws IOException {
    Map<ApplicationAttemptId, ApplicationAttemptHistoryData> historyDataMap = new HashMap<ApplicationAttemptId, ApplicationAttemptHistoryData>();
    HistoryFileReader hfReader = getHistoryFileReader(appId);
    try {
        while (hfReader.hasNext()) {
            HistoryFileReader.Entry entry = hfReader.next();
            if (entry.key.id.startsWith(ConverterUtils.APPLICATION_ATTEMPT_PREFIX)) {
                ApplicationAttemptId appAttemptId = ApplicationAttemptId.fromString(entry.key.id);
                if (appAttemptId.getApplicationId().equals(appId)) {
                    ApplicationAttemptHistoryData historyData = historyDataMap.get(appAttemptId);
                    if (historyData == null) {
                        historyData = ApplicationAttemptHistoryData.newInstance(appAttemptId, null, -1, null, null, null, FinalApplicationStatus.UNDEFINED, null);
                        historyDataMap.put(appAttemptId, historyData);
                    }
                    if (entry.key.suffix.equals(START_DATA_SUFFIX)) {
                        mergeApplicationAttemptHistoryData(historyData, parseApplicationAttemptStartData(entry.value));
                    } else if (entry.key.suffix.equals(FINISH_DATA_SUFFIX)) {
                        mergeApplicationAttemptHistoryData(historyData, parseApplicationAttemptFinishData(entry.value));
                    }
                }
            }
        }
        LOG.info("Completed reading history information of all application" + " attempts of application " + appId);
    } catch (IOException e) {
        LOG.info("Error when reading history information of some application" + " attempts of application " + appId);
    } finally {
        hfReader.close();
    }
    return historyDataMap;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ApplicationAttemptHistoryData(org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationAttemptHistoryData) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) IOException(java.io.IOException)

Example 3 with ApplicationAttemptHistoryData

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

the class FileSystemApplicationHistoryStore method getApplicationAttempt.

@Override
public ApplicationAttemptHistoryData getApplicationAttempt(ApplicationAttemptId appAttemptId) throws IOException {
    HistoryFileReader hfReader = getHistoryFileReader(appAttemptId.getApplicationId());
    try {
        boolean readStartData = false;
        boolean readFinishData = false;
        ApplicationAttemptHistoryData historyData = ApplicationAttemptHistoryData.newInstance(appAttemptId, null, -1, null, null, null, FinalApplicationStatus.UNDEFINED, null);
        while ((!readStartData || !readFinishData) && hfReader.hasNext()) {
            HistoryFileReader.Entry entry = hfReader.next();
            if (entry.key.id.equals(appAttemptId.toString())) {
                if (entry.key.suffix.equals(START_DATA_SUFFIX)) {
                    ApplicationAttemptStartData startData = parseApplicationAttemptStartData(entry.value);
                    mergeApplicationAttemptHistoryData(historyData, startData);
                    readStartData = true;
                } else if (entry.key.suffix.equals(FINISH_DATA_SUFFIX)) {
                    ApplicationAttemptFinishData finishData = parseApplicationAttemptFinishData(entry.value);
                    mergeApplicationAttemptHistoryData(historyData, finishData);
                    readFinishData = true;
                }
            }
        }
        if (!readStartData && !readFinishData) {
            return null;
        }
        if (!readStartData) {
            LOG.warn("Start information is missing for application attempt " + appAttemptId);
        }
        if (!readFinishData) {
            LOG.warn("Finish information is missing for application attempt " + appAttemptId);
        }
        LOG.info("Completed reading history information of application attempt " + appAttemptId);
        return historyData;
    } catch (IOException e) {
        LOG.error("Error when reading history file of application attempt" + appAttemptId, e);
        throw e;
    } finally {
        hfReader.close();
    }
}
Also used : ApplicationAttemptStartData(org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationAttemptStartData) ApplicationAttemptHistoryData(org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationAttemptHistoryData) ApplicationAttemptFinishData(org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationAttemptFinishData) IOException(java.io.IOException)

Example 4 with ApplicationAttemptHistoryData

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

the class ApplicationHistoryManagerImpl method getLastAttempt.

private ApplicationAttemptHistoryData getLastAttempt(ApplicationId appId) throws IOException {
    Map<ApplicationAttemptId, ApplicationAttemptHistoryData> attempts = historyStore.getApplicationAttempts(appId);
    ApplicationAttemptId prevMaxAttemptId = null;
    for (ApplicationAttemptId attemptId : attempts.keySet()) {
        if (prevMaxAttemptId == null) {
            prevMaxAttemptId = attemptId;
        } else {
            if (prevMaxAttemptId.getAttemptId() < attemptId.getAttemptId()) {
                prevMaxAttemptId = attemptId;
            }
        }
    }
    return attempts.get(prevMaxAttemptId);
}
Also used : ApplicationAttemptHistoryData(org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationAttemptHistoryData) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId)

Example 5 with ApplicationAttemptHistoryData

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

the class ApplicationHistoryManagerImpl method convertToApplicationReport.

private ApplicationReport convertToApplicationReport(ApplicationHistoryData appHistory) throws IOException {
    ApplicationAttemptId currentApplicationAttemptId = null;
    String trackingUrl = UNAVAILABLE;
    String host = UNAVAILABLE;
    int rpcPort = -1;
    ApplicationAttemptHistoryData lastAttempt = getLastAttempt(appHistory.getApplicationId());
    if (lastAttempt != null) {
        currentApplicationAttemptId = lastAttempt.getApplicationAttemptId();
        trackingUrl = lastAttempt.getTrackingURL();
        host = lastAttempt.getHost();
        rpcPort = lastAttempt.getRPCPort();
    }
    return ApplicationReport.newInstance(appHistory.getApplicationId(), currentApplicationAttemptId, appHistory.getUser(), appHistory.getQueue(), appHistory.getApplicationName(), host, rpcPort, null, appHistory.getYarnApplicationState(), appHistory.getDiagnosticsInfo(), trackingUrl, appHistory.getStartTime(), appHistory.getFinishTime(), appHistory.getFinalApplicationStatus(), null, "", 100, appHistory.getApplicationType(), null);
}
Also used : ApplicationAttemptHistoryData(org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationAttemptHistoryData) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId)

Aggregations

ApplicationAttemptHistoryData (org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationAttemptHistoryData)9 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)7 IOException (java.io.IOException)5 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)1 ApplicationAttemptFinishData (org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationAttemptFinishData)1 ApplicationAttemptStartData (org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationAttemptStartData)1 ApplicationHistoryData (org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationHistoryData)1 ContainerHistoryData (org.apache.hadoop.yarn.server.applicationhistoryservice.records.ContainerHistoryData)1 RMAppAttempt (org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt)1