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 java.io.BufferedReader;
        import java.io.InputStreamReader;
        import java.io.OutputStream;
        import java.security.PrivilegedExceptionAction;
        
        import org.apache.hadoop.conf.Configuration;
        import org.apache.hadoop.mapred.JobClient;
        import org.apache.hadoop.mapred.JobQueueInfo;
        import org.apache.hadoop.security.UserGroupInformation;
        
        public class Test {
        
         public static void main(String[] args)
         {
          loginWithPAM(args[0], args[1]);
          printQueuesForUser(args[0]);
        
        
          loginWithPAM(args[2], args[3]);
          printQueuesForUser(args[2]);
        
         }
        
        
         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[]>() {
        
            @Override
            public JobQueueInfo[] run() throws Exception {
             JobClient jc = new JobClient(new Configuration());
             JobQueueInfo[] jcInfo=jc.getQueues();
             return jcInfo;
            }
           });
          } catch (Exception e) {  
           e.printStackTrace(); 
          }
        
        
          for(JobQueueInfo info : jcInfo){
        
           System.out.println(info.getQueueName());
          }
        
         }
        
         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
           out.flush();
           out.close();
        
           // 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
            System.out.println(line);
           }
        
           errorReader.close();  
        
           process.waitFor();
        
          }
          catch (Exception e) {
           e.printStackTrace();
          }
        
         }
        }



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 ****/127.0.0.1:8032
    root.default
    root.mapr
    root.root
    getUserName root
    getCurrentUser mapr (auth:CUSTOM)
    getLoginUser mapr (auth:CUSTOM)
    15/02/18 11:48:17 INFO client.RMProxy: Connecting to ResourceManager at ****/127.0.0.1:8032
    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(Test.java:52)
            at com.test.q.Test.main(Test.java:22)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.apache.hadoop.util.RunJar.main(RunJar.java:212)


Outcomes