Beispiel #1
0
  /**
   * set current session to existing session object if a thread is running multiple sessions - it
   * must call this method with the new session object when switching from one session to another.
   */
  public static SessionState start(SessionState startSs) {
    setCurrentSessionState(startSs);

    if (startSs.hiveHist == null) {
      if (startSs.getConf().getBoolVar(HiveConf.ConfVars.HIVE_SESSION_HISTORY_ENABLED)) {
        startSs.hiveHist = new HiveHistoryImpl(startSs);
      } else {
        // Hive history is disabled, create a no-op proxy
        startSs.hiveHist = HiveHistoryProxyHandler.getNoOpHiveHistoryProxy();
      }
    }

    // Get the following out of the way when you start the session these take a
    // while and should be done when we start up.
    try {
      // Hive object instance should be created with a copy of the conf object. If the conf is
      // shared with SessionState, other parts of the code might update the config, but
      // Hive.get(HiveConf) would not recognize the case when it needs refreshing
      Hive.get(new HiveConf(startSs.conf)).getMSC();
      UserGroupInformation sessionUGI = Utils.getUGI();
      FileSystem.get(startSs.conf);

      // Create scratch dirs for this session
      startSs.createSessionDirs(sessionUGI.getShortUserName());

      // Set temp file containing results to be sent to HiveClient
      if (startSs.getTmpOutputFile() == null) {
        try {
          startSs.setTmpOutputFile(createTempFile(startSs.getConf()));
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

    } catch (Exception e) {
      // Catch-all due to some exec time dependencies on session state
      // that would cause ClassNoFoundException otherwise
      throw new RuntimeException(e);
    }

    if (HiveConf.getVar(startSs.getConf(), HiveConf.ConfVars.HIVE_EXECUTION_ENGINE).equals("tez")
        && (startSs.isHiveServerQuery == false)) {
      try {
        if (startSs.tezSessionState == null) {
          startSs.tezSessionState = new TezSessionState(startSs.getSessionId());
        }
        if (!startSs.tezSessionState.isOpen()) {
          startSs.tezSessionState.open(startSs.conf); // should use conf on session start-up
        }
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    } else {
      LOG.info("No Tez session required at this point. hive.execution.engine=mr.");
    }
    return startSs;
  }
Beispiel #2
0
 public static Path getTempTableSpace(Configuration conf) {
   SessionState ss = SessionState.get();
   if (ss == null) {
     String tempTablePathString = conf.get(TMP_TABLE_SPACE_KEY);
     Preconditions.checkNotNull(
         tempTablePathString, "Conf temp table path expected to be non-null");
     return new Path(tempTablePathString);
   }
   return ss.getTempTableSpace();
 }
Beispiel #3
0
  static void validateFiles(List<String> newFiles) throws IllegalArgumentException {
    SessionState ss = SessionState.get();
    Configuration conf = (ss == null) ? new Configuration() : ss.getConf();

    for (String newFile : newFiles) {
      try {
        if (Utilities.realFile(newFile, conf) == null) {
          String message = newFile + " does not exist";
          throw new IllegalArgumentException(message);
        }
      } catch (IOException e) {
        String message = "Unable to validate " + newFile;
        throw new IllegalArgumentException(message, e);
      }
    }
  }
Beispiel #4
0
 public static Path getLocalSessionPath(Configuration conf) {
   SessionState ss = SessionState.get();
   if (ss == null) {
     String localPathString = conf.get(LOCAL_SESSION_PATH_KEY);
     Preconditions.checkNotNull(
         localPathString, "Conf local session path expected to be non-null");
     return new Path(localPathString);
   }
   Preconditions.checkNotNull(ss.localSessionPath, "Local session path expected to be non-null");
   return ss.localSessionPath;
 }
  @Override
  void postStateChange(
      final SessionState oldState, final SessionState newState, final Exception error) {
    // Make sure this doesn't get overwritten.
    String id = testAccountId;

    super.postStateChange(oldState, newState, error);

    if (newState.isClosed() && id != null && mode == Mode.PRIVATE) {
      deleteTestAccount(id, getAppAccessToken());
    }
  }
Beispiel #6
0
 public static Path getHDFSSessionPath(Configuration conf) {
   SessionState ss = SessionState.get();
   if (ss == null) {
     String sessionPathString = conf.get(HDFS_SESSION_PATH_KEY);
     Preconditions.checkNotNull(
         sessionPathString, "Conf non-local session path expected to be non-null");
     return new Path(sessionPathString);
   }
   Preconditions.checkNotNull(
       ss.hdfsSessionPath, "Non-local session path expected to be non-null");
   return ss.hdfsSessionPath;
 }
Beispiel #7
0
 static void registerJars(List<String> newJars) throws IllegalArgumentException {
   LogHelper console = getConsole();
   try {
     ClassLoader loader = Thread.currentThread().getContextClassLoader();
     ClassLoader newLoader = Utilities.addToClassPath(loader, newJars.toArray(new String[0]));
     Thread.currentThread().setContextClassLoader(newLoader);
     SessionState.get().getConf().setClassLoader(newLoader);
     console.printInfo("Added " + newJars + " to class path");
   } catch (Exception e) {
     String message = "Unable to register " + newJars;
     throw new IllegalArgumentException(message, e);
   }
 }
Beispiel #8
0
  // reloading the jars under the path specified in hive.reloadable.aux.jars.path property
  public void reloadAuxJars() throws IOException {
    final Set<String> reloadedAuxJars = new HashSet<String>();

    final String renewableJarPath = conf.getVar(ConfVars.HIVERELOADABLEJARS);
    // do nothing if this property is not specified or empty
    if (renewableJarPath == null || renewableJarPath.isEmpty()) {
      return;
    }

    Set<String> jarPaths = Utilities.getJarFilesByPath(renewableJarPath);

    // load jars under the hive.reloadable.aux.jars.path
    if (!jarPaths.isEmpty()) {
      reloadedAuxJars.addAll(jarPaths);
    }

    // remove the previous renewable jars
    try {
      if (preReloadableAuxJars != null && !preReloadableAuxJars.isEmpty()) {
        Utilities.removeFromClassPath(preReloadableAuxJars.toArray(new String[0]));
      }
    } catch (Exception e) {
      String msg = "Fail to remove the reloaded jars loaded last time: " + e;
      throw new IOException(msg, e);
    }

    try {
      if (reloadedAuxJars != null && !reloadedAuxJars.isEmpty()) {
        URLClassLoader currentCLoader =
            (URLClassLoader) SessionState.get().getConf().getClassLoader();
        currentCLoader =
            (URLClassLoader)
                Utilities.addToClassPath(currentCLoader, reloadedAuxJars.toArray(new String[0]));
        conf.setClassLoader(currentCLoader);
        Thread.currentThread().setContextClassLoader(currentCLoader);
      }
      preReloadableAuxJars.clear();
      preReloadableAuxJars.addAll(reloadedAuxJars);
    } catch (Exception e) {
      String msg =
          "Fail to add jars from the path specified in hive.reloadable.aux.jars.path property: "
              + e;
      throw new IOException(msg, e);
    }
  }
Beispiel #9
0
 /**
  * @return username from current SessionState authenticator. username will be null if there is no
  *     current SessionState object or authenticator is null.
  */
 public static String getUserFromAuthenticator() {
   if (SessionState.get() != null && SessionState.get().getAuthenticator() != null) {
     return SessionState.get().getAuthenticator().getUserName();
   }
   return null;
 }
Beispiel #10
0
 public boolean getIsSilent() {
   SessionState ss = SessionState.get();
   // use the session or the one supplied in constructor
   return (ss != null) ? ss.getIsSilent() : isSilent;
 }
Beispiel #11
0
 public PrintStream getChildErrStream() {
   SessionState ss = SessionState.get();
   return ((ss != null) && (ss.childErr != null)) ? ss.childErr : System.err;
 }
Beispiel #12
0
 public PrintStream getChildOutStream() {
   SessionState ss = SessionState.get();
   return ((ss != null) && (ss.childOut != null)) ? ss.childOut : System.out;
 }
Beispiel #13
0
 public PrintStream getInfoStream() {
   SessionState ss = SessionState.get();
   return ((ss != null) && (ss.info != null)) ? ss.info : getErrStream();
 }
Beispiel #14
0
 /** Sets the given session state in the thread local var for sessions. */
 public static void setCurrentSessionState(SessionState startSs) {
   tss.set(startSs);
   Thread.currentThread().setContextClassLoader(startSs.getConf().getClassLoader());
 }