void close(boolean keepDagFilesDir) throws Exception {
    console = null;
    appJarLr = null;

    try {
      if (session != null) {
        LOG.info("Closing Tez Session");
        closeClient(session);
        session = null;
      } else if (sessionFuture != null) {
        sessionFuture.cancel(true);
        TezClient asyncSession = null;
        try {
          asyncSession = sessionFuture.get(); // In case it was done and noone looked at it.
        } catch (ExecutionException | CancellationException e) {
          // ignore
        } catch (InterruptedException e) {
          Thread.currentThread().interrupt();
          // ignore
        }
        sessionFuture = null;
        if (asyncSession != null) {
          LOG.info("Closing Tez Session");
          closeClient(asyncSession);
        }
      }
    } finally {
      try {
        cleanupScratchDir();
      } finally {
        if (!keepDagFilesDir) {
          cleanupDagResources();
        }
      }
    }
  }
Close a tez session. Will cleanup any tez/am related resources. After closing a session no
further DAGs can be executed against it. Only called by session management classes; some
sessions should not simply be closed by users - e.g. pool sessions need to be restarted.

@param keepDagFilesDir
         whether or not to remove the scratch dir at the same time.
@throws Exception
ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezSessionState.java