Browse Source

[webhdfs] Make DEFAULT_USER an attribute of the filesystem object

Also changed the DEFAULT_USER to `hue', which is the user running Hue
(most of the time).
bc Wong 13 years ago
parent
commit
e816a71173

+ 1 - 2
desktop/libs/hadoop/src/hadoop/fs/upload.py

@@ -32,7 +32,6 @@ import time
 from django.core.files.uploadhandler import \
 from django.core.files.uploadhandler import \
     FileUploadHandler, StopFutureHandlers, StopUpload
     FileUploadHandler, StopFutureHandlers, StopUpload
 import hadoop.cluster
 import hadoop.cluster
-import hadoop.fs.webhdfs
 
 
 UPLOAD_SUBDIR = 'hue-uploads'
 UPLOAD_SUBDIR = 'hue-uploads'
 LOG = logging.getLogger(__name__)
 LOG = logging.getLogger(__name__)
@@ -62,7 +61,7 @@ class HDFStemporaryUploadedFile(object):
     # We want to set the user to be the superuser. But any operation
     # We want to set the user to be the superuser. But any operation
     # in the fs needs a username, including the retrieval of the superuser.
     # in the fs needs a username, including the retrieval of the superuser.
     # So we first set it to the DEFAULT_USER to break this chicken-&-egg.
     # So we first set it to the DEFAULT_USER to break this chicken-&-egg.
-    self._fs.setuser(hadoop.fs.webhdfs.DEFAULT_USER)
+    self._fs.setuser(self._fs.DEFAULT_USER)
     self._fs.setuser(self._fs.superuser)
     self._fs.setuser(self._fs.superuser)
 
 
     self._path = self._fs.mktemp(
     self._path = self._fs.mktemp(

+ 6 - 2
desktop/libs/hadoop/src/hadoop/fs/webhdfs.py

@@ -32,7 +32,6 @@ from hadoop.fs.exceptions import WebHdfsException
 from hadoop.fs.webhdfs_types import WebHdfsStat, WebHdfsContentSummary
 from hadoop.fs.webhdfs_types import WebHdfsStat, WebHdfsContentSummary
 
 
 DEFAULT_HDFS_SUPERUSER = 'hdfs'
 DEFAULT_HDFS_SUPERUSER = 'hdfs'
-DEFAULT_USER = 'hue_webui'
 
 
 # The number of bytes to read if not specified
 # The number of bytes to read if not specified
 DEFAULT_READ_SIZE = 1024*1024 # 1MB
 DEFAULT_READ_SIZE = 1024*1024 # 1MB
@@ -43,6 +42,8 @@ class WebHdfs(Hdfs):
   """
   """
   WebHdfs implements the filesystem interface via the WebHDFS rest protocol.
   WebHdfs implements the filesystem interface via the WebHDFS rest protocol.
   """
   """
+  DEFAULT_USER = 'hue'        # This should be the user running Hue
+
   def __init__(self, url,
   def __init__(self, url,
                hdfs_superuser=None,
                hdfs_superuser=None,
                security_enabled=False,
                security_enabled=False,
@@ -57,7 +58,7 @@ class WebHdfs(Hdfs):
 
 
     # To store user info
     # To store user info
     self._thread_local = threading.local()
     self._thread_local = threading.local()
-    self.setuser(DEFAULT_USER)
+    self._thread_local.user = WebHdfs.DEFAULT_USER
 
 
     LOG.debug("Initializing Hadoop WebHdfs: %s (security: %s, superuser: %s)" %
     LOG.debug("Initializing Hadoop WebHdfs: %s (security: %s, superuser: %s)" %
               (self._url, self._security_enabled, self._superuser))
               (self._url, self._security_enabled, self._superuser))
@@ -100,7 +101,10 @@ class WebHdfs(Hdfs):
     return { "user.name" : self._thread_local.user }
     return { "user.name" : self._thread_local.user }
 
 
   def setuser(self, user):
   def setuser(self, user):
+    """Set a new user. Return the current user."""
+    curr = self._thread_local.user
     self._thread_local.user = user
     self._thread_local.user = user
+    return curr
 
 
 
 
   def listdir_stats(self, path, glob=None):
   def listdir_stats(self, path, glob=None):