DAGClient submit(DAG dag, Ref<TezSessionState> sessionStateRef) throws Exception {
    perfLogger.perfLogBegin(CLASS_NAME, PerfLogger.TEZ_SUBMIT_DAG);
    DAGClient dagClient = null;
    TezSessionState sessionState = sessionStateRef.value;
    try {
      try {
        // ready to start execution on the cluster
        dagClient = submitInternal(dag, sessionState);
      } catch (SessionNotRunning nr) {
        console.printInfo("Tez session was closed. Reopening...");
        sessionStateRef.value = sessionState = getNewTezSessionOnError(sessionState);
        console.printInfo("Session re-established.");
        dagClient = submitInternal(dag, sessionState);
      }
    } catch (Exception e) {
      if (this.isShutdown) {
        // Incase of taskShutdown, no need to retry
        sessionDestroyOrReturnToPool(sessionStateRef, sessionState);
        throw e;
      }
      // In case of any other exception, retry. If this also fails, report original error and exit.
      try {
        console.printInfo("Dag submit failed due to " + e.getMessage() + " stack trace: "
            + Arrays.toString(e.getStackTrace()) + " retrying...");
        sessionStateRef.value = sessionState = getNewTezSessionOnError(sessionState);
        dagClient = submitInternal(dag, sessionState);
      } catch (Exception retryException) {
        // we failed to submit after retrying.
        // If this is a non-pool session, destroy it.
        // Otherwise move it to sessionPool, reopen will retry.
        sessionDestroyOrReturnToPool(sessionStateRef, sessionState);
        throw retryException;
      }
    }

    perfLogger.perfLogEnd(CLASS_NAME, PerfLogger.TEZ_SUBMIT_DAG);
    return new SyncDagClient(dagClient);
  }
Ensures that the Tez Session is open and the AM has all necessary jars configured.
ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezTask.java