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(); }
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; }
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; }
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); } }
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); } } }
// 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); } }
/** * @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; }
public boolean getIsSilent() { SessionState ss = SessionState.get(); // use the session or the one supplied in constructor return (ss != null) ? ss.getIsSilent() : isSilent; }
public PrintStream getChildErrStream() { SessionState ss = SessionState.get(); return ((ss != null) && (ss.childErr != null)) ? ss.childErr : System.err; }
public PrintStream getChildOutStream() { SessionState ss = SessionState.get(); return ((ss != null) && (ss.childOut != null)) ? ss.childOut : System.out; }
public PrintStream getInfoStream() { SessionState ss = SessionState.get(); return ((ss != null) && (ss.info != null)) ? ss.info : getErrStream(); }