public static String getHadoopUser ( ) { try { Class < ? > ugiClass = Class . forName ( "org.apache.hadoop.security.UserGroupInformation" , false , EnvironmentInformation . class . getClassLoader ( ) ) ; Method currentUserMethod = ugiClass . getMethod ( "getCurrentUser" ) ; Method shortUserNameMethod = ugiClass . getMethod ( "getShortUserName" ) ; Object ugi = currentUserMethod . invoke ( null ) ; return ( String ) shortUserNameMethod . invoke ( ugi ) ; } catch ( ClassNotFoundException e ) { return "<no hadoop dependency found>" ; } catch ( LinkageError e ) { // hadoop classes are not in the classpath LOG . debug ( "Cannot determine user/group information using Hadoop utils. " + "Hadoop classes not loaded or compatible" , e ) ; } catch ( Throwable t ) { // some other error occurred that we should log and make known LOG . warn ( "Error while accessing user/group information via Hadoop utils." , t ) ; } return UNKNOWN ; }
Gets the name of the user that is running the JVM .