Exemplo n.º 1
0
        /// <exception cref="System.IO.IOException"/>
        private int GetGroups(string[] usernames)
        {
            // Get groups users belongs to
            if (usernames.Length == 0)
            {
                usernames = new string[] { UserGroupInformation.GetCurrentUser().GetUserName() };
            }
            // Get the current configuration
            Configuration conf    = GetConf();
            IPEndPoint    address = conf.GetSocketAddr(JHAdminConfig.JhsAdminAddress, JHAdminConfig
                                                       .DefaultJhsAdminAddress, JHAdminConfig.DefaultJhsAdminPort);
            GetUserMappingsProtocol getUserMappingProtocol = HSProxies.CreateProxy <GetUserMappingsProtocol
                                                                                    >(conf, address, UserGroupInformation.GetCurrentUser());

            foreach (string username in usernames)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(username + " :");
                foreach (string group in getUserMappingProtocol.GetGroupsForUser(username))
                {
                    sb.Append(" ");
                    sb.Append(group);
                }
                System.Console.Out.WriteLine(sb);
            }
            return(0);
        }
 /// <exception cref="Com.Google.Protobuf.ServiceException"/>
 public virtual GetUserMappingsProtocolProtos.GetGroupsForUserResponseProto GetGroupsForUser
     (RpcController controller, GetUserMappingsProtocolProtos.GetGroupsForUserRequestProto
     request)
 {
     string[] groups;
     try
     {
         groups = impl.GetGroupsForUser(request.GetUser());
     }
     catch (IOException e)
     {
         throw new ServiceException(e);
     }
     GetUserMappingsProtocolProtos.GetGroupsForUserResponseProto.Builder builder = GetUserMappingsProtocolProtos.GetGroupsForUserResponseProto
                                                                                   .NewBuilder();
     foreach (string g in groups)
     {
         builder.AddGroups(g);
     }
     return((GetUserMappingsProtocolProtos.GetGroupsForUserResponseProto)builder.Build
                ());
 }