public TezClient getSession() {
    if (session == null && sessionFuture != null) {
      if (!sessionFuture.isDone()) {
        console.printInfo("Waiting for Tez session and AM to be ready...");
      }
      try {
        session = sessionFuture.get();
      } catch (InterruptedException e) {
        console.printInfo("Interrupted while waiting for the session");
        Thread.currentThread().interrupt();
        return null;
      } catch (ExecutionException e) {
        console.printInfo("Failed to get session");
        throw new RuntimeException(e);
      } catch (CancellationException e) {
        console.printInfo("Cancelled while waiting for the session");
        return null;
      }
    }
    return session;
  }
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