Search in sources :

Example 1 with HistoryEventType

use of org.apache.tez.dag.history.HistoryEventType in project tez by apache.

the class TestHistoryEventTimelineConversion method testHandlerExists.

@Test(timeout = 5000)
public void testHandlerExists() throws JSONException {
    for (HistoryEventType eventType : HistoryEventType.values()) {
        HistoryEvent event = null;
        switch(eventType) {
            case APP_LAUNCHED:
                event = new AppLaunchedEvent(applicationId, random.nextInt(), random.nextInt(), user, new Configuration(false), null);
                break;
            case AM_LAUNCHED:
                event = new AMLaunchedEvent(applicationAttemptId, random.nextInt(), random.nextInt(), user);
                break;
            case AM_STARTED:
                event = new AMStartedEvent(applicationAttemptId, random.nextInt(), user);
                break;
            case DAG_SUBMITTED:
                event = new DAGSubmittedEvent(tezDAGID, random.nextInt(), dagPlan, applicationAttemptId, null, user, null, containerLogs, null);
                break;
            case DAG_INITIALIZED:
                event = new DAGInitializedEvent(tezDAGID, random.nextInt(), user, dagPlan.getName(), null);
                break;
            case DAG_STARTED:
                event = new DAGStartedEvent(tezDAGID, random.nextInt(), user, dagPlan.getName());
                break;
            case DAG_FINISHED:
                event = new DAGFinishedEvent(tezDAGID, random.nextInt(), random.nextInt(), DAGState.ERROR, null, null, user, dagPlan.getName(), null, applicationAttemptId, dagPlan);
                break;
            case VERTEX_INITIALIZED:
                event = new VertexInitializedEvent(tezVertexID, "v1", random.nextInt(), random.nextInt(), random.nextInt(), "proc", null, null, null);
                break;
            case VERTEX_STARTED:
                event = new VertexStartedEvent(tezVertexID, random.nextInt(), random.nextInt());
                break;
            case VERTEX_CONFIGURE_DONE:
                event = new VertexConfigurationDoneEvent(tezVertexID, 0L, 1, null, null, null, true);
                break;
            case VERTEX_FINISHED:
                event = new VertexFinishedEvent(tezVertexID, "v1", 1, random.nextInt(), random.nextInt(), random.nextInt(), random.nextInt(), random.nextInt(), VertexState.ERROR, null, null, null, null, null);
                break;
            case TASK_STARTED:
                event = new TaskStartedEvent(tezTaskID, "v1", random.nextInt(), random.nextInt());
                break;
            case TASK_FINISHED:
                event = new TaskFinishedEvent(tezTaskID, "v1", random.nextInt(), random.nextInt(), tezTaskAttemptID, TaskState.FAILED, null, null, 0);
                break;
            case TASK_ATTEMPT_STARTED:
                event = new TaskAttemptStartedEvent(tezTaskAttemptID, "v1", random.nextInt(), containerId, nodeId, null, null, "nodeHttpAddress");
                break;
            case TASK_ATTEMPT_FINISHED:
                event = new TaskAttemptFinishedEvent(tezTaskAttemptID, "v1", random.nextInt(), random.nextInt(), TaskAttemptState.FAILED, TaskFailureType.NON_FATAL, TaskAttemptTerminationCause.OUTPUT_LOST, null, null, null, null, 0, null, 0, containerId, nodeId, null, null, "nodeHttpAddress");
                break;
            case CONTAINER_LAUNCHED:
                event = new ContainerLaunchedEvent(containerId, random.nextInt(), applicationAttemptId);
                break;
            case CONTAINER_STOPPED:
                event = new ContainerStoppedEvent(containerId, random.nextInt(), -1, applicationAttemptId);
                break;
            case DAG_COMMIT_STARTED:
                event = new DAGCommitStartedEvent();
                break;
            case VERTEX_COMMIT_STARTED:
                event = new VertexCommitStartedEvent();
                break;
            case VERTEX_GROUP_COMMIT_STARTED:
                event = new VertexGroupCommitStartedEvent();
                break;
            case VERTEX_GROUP_COMMIT_FINISHED:
                event = new VertexGroupCommitFinishedEvent();
                break;
            case DAG_RECOVERED:
                event = new DAGRecoveredEvent(applicationAttemptId, tezDAGID, dagPlan.getName(), user, random.nextLong(), containerLogs);
                break;
            case DAG_KILL_REQUEST:
                event = new DAGKillRequestEvent();
                break;
            default:
                Assert.fail("Unhandled event type " + eventType);
        }
        if (event == null || !event.isHistoryEvent()) {
            continue;
        }
        HistoryEventTimelineConversion.convertToTimelineEntities(event);
    }
}
Also used : DAGCommitStartedEvent(org.apache.tez.dag.history.events.DAGCommitStartedEvent) Configuration(org.apache.hadoop.conf.Configuration) VertexInitializedEvent(org.apache.tez.dag.history.events.VertexInitializedEvent) HistoryEventType(org.apache.tez.dag.history.HistoryEventType) DAGInitializedEvent(org.apache.tez.dag.history.events.DAGInitializedEvent) ContainerStoppedEvent(org.apache.tez.dag.history.events.ContainerStoppedEvent) DAGKillRequestEvent(org.apache.tez.dag.history.events.DAGKillRequestEvent) DAGStartedEvent(org.apache.tez.dag.history.events.DAGStartedEvent) VertexConfigurationDoneEvent(org.apache.tez.dag.history.events.VertexConfigurationDoneEvent) DAGRecoveredEvent(org.apache.tez.dag.history.events.DAGRecoveredEvent) TaskAttemptFinishedEvent(org.apache.tez.dag.history.events.TaskAttemptFinishedEvent) AMStartedEvent(org.apache.tez.dag.history.events.AMStartedEvent) VertexStartedEvent(org.apache.tez.dag.history.events.VertexStartedEvent) VertexGroupCommitStartedEvent(org.apache.tez.dag.history.events.VertexGroupCommitStartedEvent) HistoryEvent(org.apache.tez.dag.history.HistoryEvent) TaskStartedEvent(org.apache.tez.dag.history.events.TaskStartedEvent) TaskAttemptStartedEvent(org.apache.tez.dag.history.events.TaskAttemptStartedEvent) AppLaunchedEvent(org.apache.tez.dag.history.events.AppLaunchedEvent) TaskFinishedEvent(org.apache.tez.dag.history.events.TaskFinishedEvent) VertexGroupCommitFinishedEvent(org.apache.tez.dag.history.events.VertexGroupCommitFinishedEvent) AMLaunchedEvent(org.apache.tez.dag.history.events.AMLaunchedEvent) ContainerLaunchedEvent(org.apache.tez.dag.history.events.ContainerLaunchedEvent) DAGFinishedEvent(org.apache.tez.dag.history.events.DAGFinishedEvent) VertexFinishedEvent(org.apache.tez.dag.history.events.VertexFinishedEvent) DAGSubmittedEvent(org.apache.tez.dag.history.events.DAGSubmittedEvent) VertexCommitStartedEvent(org.apache.tez.dag.history.events.VertexCommitStartedEvent) Test(org.junit.Test)

Example 2 with HistoryEventType

use of org.apache.tez.dag.history.HistoryEventType in project tez by apache.

the class ATSV15HistoryLoggingService method isValidEvent.

private boolean isValidEvent(DAGHistoryEvent event) {
    HistoryEventType eventType = event.getHistoryEvent().getEventType();
    TezDAGID dagId = event.getDagID();
    if (eventType.equals(HistoryEventType.DAG_SUBMITTED)) {
        DAGSubmittedEvent dagSubmittedEvent = (DAGSubmittedEvent) event.getHistoryEvent();
        String dagName = dagSubmittedEvent.getDAGName();
        if ((dagName != null && dagName.startsWith(TezConstants.TEZ_PREWARM_DAG_NAME_PREFIX)) || (!dagSubmittedEvent.isHistoryLoggingEnabled())) {
            // Skip recording pre-warm DAG events
            skippedDAGs.add(dagId);
            return false;
        }
    }
    if (eventType.equals(HistoryEventType.DAG_RECOVERED)) {
        DAGRecoveredEvent dagRecoveredEvent = (DAGRecoveredEvent) event.getHistoryEvent();
        if (!dagRecoveredEvent.isHistoryLoggingEnabled()) {
            skippedDAGs.add(dagRecoveredEvent.getDagID());
            return false;
        }
    }
    if (eventType.equals(HistoryEventType.DAG_FINISHED)) {
        // No more events should be seen after this point.
        if (skippedDAGs.remove(dagId)) {
            return false;
        }
    }
    if (dagId != null && skippedDAGs.contains(dagId)) {
        // Skip pre-warm DAGs
        return false;
    }
    return true;
}
Also used : TezDAGID(org.apache.tez.dag.records.TezDAGID) DAGRecoveredEvent(org.apache.tez.dag.history.events.DAGRecoveredEvent) HistoryEventType(org.apache.tez.dag.history.HistoryEventType) DAGSubmittedEvent(org.apache.tez.dag.history.events.DAGSubmittedEvent)

Example 3 with HistoryEventType

use of org.apache.tez.dag.history.HistoryEventType in project tez by apache.

the class TestHistoryEventJsonConversion method testHandlerExists.

@Test(timeout = 5000)
public void testHandlerExists() throws JSONException {
    for (HistoryEventType eventType : HistoryEventType.values()) {
        HistoryEvent event = null;
        switch(eventType) {
            case APP_LAUNCHED:
                event = new AppLaunchedEvent(applicationId, random.nextInt(), random.nextInt(), user, new Configuration(false), null);
                break;
            case AM_LAUNCHED:
                event = new AMLaunchedEvent(applicationAttemptId, random.nextInt(), random.nextInt(), user);
                break;
            case AM_STARTED:
                event = new AMStartedEvent(applicationAttemptId, random.nextInt(), user);
                break;
            case DAG_SUBMITTED:
                event = new DAGSubmittedEvent(tezDAGID, random.nextInt(), dagPlan, applicationAttemptId, null, user, null, null, "Q_" + eventType.name());
                break;
            case DAG_INITIALIZED:
                event = new DAGInitializedEvent(tezDAGID, random.nextInt(), user, dagPlan.getName(), null);
                break;
            case DAG_STARTED:
                event = new DAGStartedEvent(tezDAGID, random.nextInt(), user, dagPlan.getName());
                break;
            case DAG_FINISHED:
                event = new DAGFinishedEvent(tezDAGID, random.nextInt(), random.nextInt(), DAGState.ERROR, null, null, user, dagPlan.getName(), null, applicationAttemptId, dagPlan);
                break;
            case VERTEX_INITIALIZED:
                event = new VertexInitializedEvent(tezVertexID, "v1", random.nextInt(), random.nextInt(), random.nextInt(), "proc", null, null, null);
                break;
            case VERTEX_STARTED:
                event = new VertexStartedEvent(tezVertexID, random.nextInt(), random.nextInt());
                break;
            case VERTEX_CONFIGURE_DONE:
                event = new VertexConfigurationDoneEvent(tezVertexID, 0L, 1, null, null, null, true);
                break;
            case VERTEX_FINISHED:
                event = new VertexFinishedEvent(tezVertexID, "v1", 1, random.nextInt(), random.nextInt(), random.nextInt(), random.nextInt(), random.nextInt(), VertexState.ERROR, null, null, null, null, null);
                break;
            case TASK_STARTED:
                event = new TaskStartedEvent(tezTaskID, "v1", random.nextInt(), random.nextInt());
                break;
            case TASK_FINISHED:
                event = new TaskFinishedEvent(tezTaskID, "v1", random.nextInt(), random.nextInt(), tezTaskAttemptID, TaskState.FAILED, null, null, 0);
                break;
            case TASK_ATTEMPT_STARTED:
                event = new TaskAttemptStartedEvent(tezTaskAttemptID, "v1", random.nextInt(), containerId, nodeId, null, null, "nodeHttpAddress");
                break;
            case TASK_ATTEMPT_FINISHED:
                event = new TaskAttemptFinishedEvent(tezTaskAttemptID, "v1", random.nextInt(), random.nextInt(), TaskAttemptState.KILLED, null, TaskAttemptTerminationCause.TERMINATED_BY_CLIENT, null, null, null, null, 0, null, 0, containerId, nodeId, null, null, "nodeHttpAddress");
                break;
            case CONTAINER_LAUNCHED:
                event = new ContainerLaunchedEvent(containerId, random.nextInt(), applicationAttemptId);
                break;
            case CONTAINER_STOPPED:
                event = new ContainerStoppedEvent(containerId, random.nextInt(), -1, applicationAttemptId);
                break;
            case DAG_COMMIT_STARTED:
                event = new DAGCommitStartedEvent();
                break;
            case VERTEX_COMMIT_STARTED:
                event = new VertexCommitStartedEvent();
                break;
            case VERTEX_GROUP_COMMIT_STARTED:
                event = new VertexGroupCommitStartedEvent();
                break;
            case VERTEX_GROUP_COMMIT_FINISHED:
                event = new VertexGroupCommitFinishedEvent();
                break;
            case DAG_RECOVERED:
                event = new DAGRecoveredEvent(applicationAttemptId, tezDAGID, dagPlan.getName(), user, 1l, null);
                break;
            case DAG_KILL_REQUEST:
                event = new DAGKillRequestEvent();
                break;
            default:
                Assert.fail("Unhandled event type " + eventType);
        }
        if (event == null || !event.isHistoryEvent()) {
            continue;
        }
        JSONObject json = HistoryEventJsonConversion.convertToJson(event);
        if (eventType == HistoryEventType.DAG_SUBMITTED) {
            try {
                Assert.assertEquals("Q_" + eventType.name(), json.getJSONObject(ATSConstants.OTHER_INFO).getString(ATSConstants.DAG_QUEUE_NAME));
                Assert.assertEquals("Q_" + eventType.name(), json.getJSONObject(ATSConstants.PRIMARY_FILTERS).getString(ATSConstants.DAG_QUEUE_NAME));
            } catch (JSONException ex) {
                Assert.fail("Exception: " + ex.getMessage() + " for type: " + eventType);
            }
        }
    }
}
Also used : DAGCommitStartedEvent(org.apache.tez.dag.history.events.DAGCommitStartedEvent) Configuration(org.apache.hadoop.conf.Configuration) VertexInitializedEvent(org.apache.tez.dag.history.events.VertexInitializedEvent) HistoryEventType(org.apache.tez.dag.history.HistoryEventType) DAGInitializedEvent(org.apache.tez.dag.history.events.DAGInitializedEvent) ContainerStoppedEvent(org.apache.tez.dag.history.events.ContainerStoppedEvent) DAGKillRequestEvent(org.apache.tez.dag.history.events.DAGKillRequestEvent) DAGStartedEvent(org.apache.tez.dag.history.events.DAGStartedEvent) VertexConfigurationDoneEvent(org.apache.tez.dag.history.events.VertexConfigurationDoneEvent) DAGRecoveredEvent(org.apache.tez.dag.history.events.DAGRecoveredEvent) TaskAttemptFinishedEvent(org.apache.tez.dag.history.events.TaskAttemptFinishedEvent) AMStartedEvent(org.apache.tez.dag.history.events.AMStartedEvent) VertexStartedEvent(org.apache.tez.dag.history.events.VertexStartedEvent) VertexGroupCommitStartedEvent(org.apache.tez.dag.history.events.VertexGroupCommitStartedEvent) JSONException(org.codehaus.jettison.json.JSONException) HistoryEvent(org.apache.tez.dag.history.HistoryEvent) TaskStartedEvent(org.apache.tez.dag.history.events.TaskStartedEvent) TaskAttemptStartedEvent(org.apache.tez.dag.history.events.TaskAttemptStartedEvent) AppLaunchedEvent(org.apache.tez.dag.history.events.AppLaunchedEvent) TaskFinishedEvent(org.apache.tez.dag.history.events.TaskFinishedEvent) JSONObject(org.codehaus.jettison.json.JSONObject) VertexGroupCommitFinishedEvent(org.apache.tez.dag.history.events.VertexGroupCommitFinishedEvent) AMLaunchedEvent(org.apache.tez.dag.history.events.AMLaunchedEvent) ContainerLaunchedEvent(org.apache.tez.dag.history.events.ContainerLaunchedEvent) DAGFinishedEvent(org.apache.tez.dag.history.events.DAGFinishedEvent) VertexFinishedEvent(org.apache.tez.dag.history.events.VertexFinishedEvent) DAGSubmittedEvent(org.apache.tez.dag.history.events.DAGSubmittedEvent) VertexCommitStartedEvent(org.apache.tez.dag.history.events.VertexCommitStartedEvent) Test(org.junit.Test)

Example 4 with HistoryEventType

use of org.apache.tez.dag.history.HistoryEventType in project tez by apache.

the class RecoveryService method handleRecoveryEvent.

@VisibleForTesting
protected void handleRecoveryEvent(DAGHistoryEvent event) throws IOException {
    HistoryEventType eventType = event.getHistoryEvent().getEventType();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Handling recovery event of type " + event.getHistoryEvent().getEventType());
    }
    TezDAGID dagID = event.getDagID();
    if (completedDAGs.contains(dagID)) {
        // no need to recover completed DAGs
        if (LOG.isDebugEnabled()) {
            LOG.debug("Skipping Recovery Event as DAG completed" + ", dagId=" + dagID + ", completed=" + completedDAGs.contains(dagID) + ", skipped=" + skippedDAGs.contains(dagID) + ", eventType=" + eventType);
        }
        return;
    }
    if (!outputStreamMap.containsKey(dagID)) {
        Path dagFilePath = TezCommonUtils.getDAGRecoveryPath(recoveryPath, dagID.toString());
        FSDataOutputStream outputStream;
        if (recoveryDirFS.exists(dagFilePath)) {
            createFatalErrorFlagDir();
            return;
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Opening DAG recovery file in create mode" + ", filePath=" + dagFilePath);
            }
            outputStream = recoveryDirFS.create(dagFilePath, false, bufferSize);
        }
        outputStreamMap.put(dagID, outputStream);
    }
    FSDataOutputStream outputStream = outputStreamMap.get(dagID);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Writing recovery event to output stream" + ", dagId=" + dagID + ", eventType=" + eventType);
    }
    ++unflushedEventsCount;
    outputStream.writeInt(event.getHistoryEvent().getEventType().ordinal());
    event.getHistoryEvent().toProtoStream(outputStream);
    if (!EnumSet.of(HistoryEventType.DAG_SUBMITTED, HistoryEventType.DAG_FINISHED).contains(eventType)) {
        maybeFlush(outputStream);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) TezDAGID(org.apache.tez.dag.records.TezDAGID) HistoryEventType(org.apache.tez.dag.history.HistoryEventType) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with HistoryEventType

use of org.apache.tez.dag.history.HistoryEventType in project tez by apache.

the class RecoveryService method handle.

public void handle(DAGHistoryEvent event) throws IOException {
    if (stopped.get()) {
        LOG.warn("Igoring event as service stopped, eventType" + event.getHistoryEvent().getEventType());
        return;
    }
    HistoryEventType eventType = event.getHistoryEvent().getEventType();
    if (recoveryFatalErrorOccurred.get()) {
        return;
    }
    if (!started.get()) {
        LOG.warn("Adding event of type " + eventType + " to queue as service not started");
        addToEventQueue(event);
        return;
    }
    TezDAGID dagId = event.getDagID();
    if (eventType.equals(HistoryEventType.DAG_SUBMITTED)) {
        DAGSubmittedEvent dagSubmittedEvent = (DAGSubmittedEvent) event.getHistoryEvent();
        String dagName = dagSubmittedEvent.getDAGName();
        if (dagName != null && dagName.startsWith(TezConstants.TEZ_PREWARM_DAG_NAME_PREFIX)) {
            // Skip recording pre-warm DAG events
            skippedDAGs.add(dagId);
            return;
        }
    }
    if (dagId == null || skippedDAGs.contains(dagId)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Skipping event for DAG" + ", eventType=" + eventType + ", dagId=" + (dagId == null ? "null" : dagId.toString()) + ", isSkippedDAG=" + (dagId == null ? "null" : skippedDAGs.contains(dagId)));
        }
        return;
    }
    if (event.getHistoryEvent() instanceof SummaryEvent) {
        synchronized (lock) {
            if (stopped.get()) {
                LOG.warn("Igoring event as service stopped, eventType" + event.getHistoryEvent().getEventType());
                return;
            }
            try {
                SummaryEvent summaryEvent = (SummaryEvent) event.getHistoryEvent();
                handleSummaryEvent(dagId, eventType, summaryEvent);
                if (summaryEvent.writeToRecoveryImmediately()) {
                    handleRecoveryEvent(event);
                    // outputStream may already be closed and removed
                    if (outputStreamMap.containsKey(event.getDagID())) {
                        doFlush(outputStreamMap.get(event.getDagID()), appContext.getClock().getTime());
                    }
                } else {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Queueing Non-immediate Summary/Recovery event of type" + eventType.name());
                    }
                    addToEventQueue(event);
                }
                if (eventType.equals(HistoryEventType.DAG_FINISHED)) {
                    LOG.info("DAG completed" + ", dagId=" + event.getDagID() + ", queueSize=" + eventQueue.size());
                    completedDAGs.add(dagId);
                    if (outputStreamMap.containsKey(dagId)) {
                        try {
                            outputStreamMap.get(dagId).close();
                            outputStreamMap.remove(dagId);
                        } catch (IOException ioe) {
                            LOG.warn("Error when trying to flush/close recovery file for" + " dag, dagId=" + event.getDagID());
                        }
                    }
                }
            } catch (IOException ioe) {
                LOG.error("Error handling summary event" + ", eventType=" + event.getHistoryEvent().getEventType(), ioe);
                createFatalErrorFlagDir();
                if (eventType.equals(HistoryEventType.DAG_SUBMITTED)) {
                    // Throw error to tell client that dag submission failed
                    throw ioe;
                }
            }
        }
    } else {
        // All other events just get queued
        if (LOG.isDebugEnabled()) {
            LOG.debug("Queueing Non-Summary Recovery event of type " + eventType.name());
        }
        addToEventQueue(event);
    }
}
Also used : TezDAGID(org.apache.tez.dag.records.TezDAGID) SummaryEvent(org.apache.tez.dag.history.SummaryEvent) HistoryEventType(org.apache.tez.dag.history.HistoryEventType) IOException(java.io.IOException) DAGSubmittedEvent(org.apache.tez.dag.history.events.DAGSubmittedEvent)

Aggregations

HistoryEventType (org.apache.tez.dag.history.HistoryEventType)9 DAGSubmittedEvent (org.apache.tez.dag.history.events.DAGSubmittedEvent)7 TezDAGID (org.apache.tez.dag.records.TezDAGID)6 HistoryEvent (org.apache.tez.dag.history.HistoryEvent)5 DAGRecoveredEvent (org.apache.tez.dag.history.events.DAGRecoveredEvent)4 TaskAttemptFinishedEvent (org.apache.tez.dag.history.events.TaskAttemptFinishedEvent)4 TaskAttemptStartedEvent (org.apache.tez.dag.history.events.TaskAttemptStartedEvent)4 TaskFinishedEvent (org.apache.tez.dag.history.events.TaskFinishedEvent)4 TaskStartedEvent (org.apache.tez.dag.history.events.TaskStartedEvent)4 VertexConfigurationDoneEvent (org.apache.tez.dag.history.events.VertexConfigurationDoneEvent)4 VertexFinishedEvent (org.apache.tez.dag.history.events.VertexFinishedEvent)4 VertexInitializedEvent (org.apache.tez.dag.history.events.VertexInitializedEvent)4 VertexStartedEvent (org.apache.tez.dag.history.events.VertexStartedEvent)4 IOException (java.io.IOException)3 AMLaunchedEvent (org.apache.tez.dag.history.events.AMLaunchedEvent)3 AMStartedEvent (org.apache.tez.dag.history.events.AMStartedEvent)3 ContainerLaunchedEvent (org.apache.tez.dag.history.events.ContainerLaunchedEvent)3 ContainerStoppedEvent (org.apache.tez.dag.history.events.ContainerStoppedEvent)3 DAGCommitStartedEvent (org.apache.tez.dag.history.events.DAGCommitStartedEvent)3 DAGFinishedEvent (org.apache.tez.dag.history.events.DAGFinishedEvent)3