private boolean taskTerminated(TezTaskAttemptID taskAttemptID, boolean isKilled,
                               TaskFailureType taskFailureType, Throwable t, String diagnostics,
                               EventMetaData srcMeta) throws IOException, TezException {
      // Ensure only one final event is ever sent.
      if (!finalEventQueued.getAndSet(true)) {
        List<TezEvent> tezEvents = new ArrayList<>();
        if (diagnostics == null) {
          diagnostics = ExceptionUtils.getStackTrace(t);
        } else {
          diagnostics = diagnostics + ":" + ExceptionUtils.getStackTrace(t);
        }

        if (isKilled) {
          tezEvents.add(new TezEvent(new TaskAttemptKilledEvent(diagnostics),
              srcMeta == null ? updateEventMetadata : srcMeta));
        } else {
          tezEvents.add(new TezEvent(new TaskAttemptFailedEvent(diagnostics,
              taskFailureType),
              srcMeta == null ? updateEventMetadata : srcMeta));
        }
        try {
          tezEvents.add(new TezEvent(
              getStatusUpdateEvent(true, true), updateEventMetadata));
        } catch (Exception e) {
          // Counter may exceed limitation
          LOG.warn("Error when get constructing TaskStatusUpdateEvent. Not sending it out");
        }
        if (LOG.isDebugEnabled()) {
          LOG.debug(
              "Invoking OOB heartbeat for failed/killed attempt: {}, isTaskDone={}, isKilled={}",
              taskAttemptID, task.isTaskDone(), isKilled);
        }
        completionListener.fragmentCompleting(fragmentRequestId,
            isKilled ? SchedulerFragmentCompletingListener.State.KILLED :
                SchedulerFragmentCompletingListener.State.FAILED);
        return !heartbeat(tezEvents).shouldDie;
      } else {
        LOG.warn("A final task state event has already been sent. Not sending again");
        return askedToDie.get();
      }

    }
Sends out final events for task failure.
@param taskAttemptID
@param isKilled
@param taskFailureType
@param t
@param diagnostics
@param srcMeta
@return
@throws IOException
          indicates an RPC communication failure.
@throws TezException
          indicates an exception somewhere in the AM.
llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/LlapTaskReporter.java