AnsweredAssumed Answered

Unable to getQueues after enabling PAM and switching user?

Question asked by harinder on Feb 17, 2015
Hi, i am unable to get the queues from the cluster when is relogin with PAM with some other user and try to get the queue. Following is my program:-


        import org.apache.hadoop.conf.Configuration;
        import org.apache.hadoop.mapred.JobClient;
        import org.apache.hadoop.mapred.JobQueueInfo;
        public class Test {
         public static void main(String[] args)
          loginWithPAM(args[0], args[1]);
          loginWithPAM(args[2], args[3]);
         private static void printQueuesForUser(String username)
          UserGroupInformation ugi = UserGroupInformation.createRemoteUser(username);
          JobQueueInfo[] jcInfo = null;
          try {
           System.out.println("getUserName "+ugi.getUserName());
           System.out.println("getCurrentUser "+ugi.getCurrentUser().toString());
           System.out.println("getLoginUser "+ugi.getLoginUser().toString());
           jcInfo = ugi.doAs(new PrivilegedExceptionAction<JobQueueInfo[]>() {
            public JobQueueInfo[] run() throws Exception {
             JobClient jc = new JobClient(new Configuration());
             JobQueueInfo[] jcInfo=jc.getQueues();
             return jcInfo;
          } catch (Exception e) {  
          for(JobQueueInfo info : jcInfo){
         private static void loginWithPAM(String username,String password){
          String command="maprlogin password -user "+username;// command to login with PAM
          Process process = null;
          try {  
           process = Runtime.getRuntime().exec(command); // execute command
           OutputStream out=process.getOutputStream();
           out.write(password.getBytes());// write password to output stream
           // check for errors
           BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
           String line;
           while ((line = errorReader.readLine()) != null)
            // Add logging here once logger is implemented in the agent
          catch (Exception e) {

What i am doing is i am passing the username and password for two users like root pass mapr pass.
This prints the queues for the first user only and not for the 2nd user. It returns null at the second attempt(i.e jcInfo is null).  When i change it to mapr pass root pass it prints for mapr and not root.

I am launching the program like hadoop jar **`hadoop jar queue.jar mapr pass root pass`**
It only prints the queues for the first user and not the second one. Can someone please explain what am i doing wrong here.

This is the output of my program:

    getUserName mapr
    getCurrentUser mapr (auth:CUSTOM)
    getLoginUser mapr (auth:CUSTOM)
    15/02/18 11:48:15 INFO client.RMProxy: Connecting to ResourceManager at ****/
    getUserName root
    getCurrentUser mapr (auth:CUSTOM)
    getLoginUser mapr (auth:CUSTOM)
    15/02/18 11:48:17 INFO client.RMProxy: Connecting to ResourceManager at ****/
    15/02/18 11:48:17 INFO fs.MapRFileSystem: User mapr is impersonating user root
    Exception in thread "main" java.lang.NullPointerException
            at com.test.q.Test.printQueuesForUser(
            at com.test.q.Test.main(
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(
            at java.lang.reflect.Method.invoke(
            at org.apache.hadoop.util.RunJar.main(