Browse Source

Fixed issue where not having the configuration for ABFS doesn't allow Hue to start (#964)

HUE-8978 [abfs] Allow scheme to vary. (#964)
travisle22 6 năm trước cách đây
mục cha
commit
f6a60c9097

+ 21 - 7
desktop/libs/azure/src/azure/abfs/__init__.py

@@ -30,7 +30,7 @@ from azure.conf import get_default_abfs_fs
 LOG = logging.getLogger(__name__)
 LOG = logging.getLogger(__name__)
 
 
 ABFS_PATH_RE = re.compile('^/*[aA][bB][fF][sS]{1,2}://([$a-z0-9](?!.*--)[-a-z0-9]{1,61}[a-z0-9])(/(.*?)/?)?$')
 ABFS_PATH_RE = re.compile('^/*[aA][bB][fF][sS]{1,2}://([$a-z0-9](?!.*--)[-a-z0-9]{1,61}[a-z0-9])(/(.*?)/?)?$')
-ABFS_PATH_FULL = re.compile('^/*[aA][bB][fF][sS]{1,2}://([$a-z0-9](?!.*--)[-a-z0-9]{1,61}[a-z0-9])@[^.]*?\.dfs\.core\.windows\.net(/(.*?)/?)?$')#bug here
+ABFS_PATH_FULL = re.compile('^/*[aA][bB][fF][sS]{1,2}://(([$a-z0-9](?!.*--)[-a-z0-9]{1,61}[a-z0-9])@[^.]*?\.dfs\.core\.windows\.net)(/(.*?)/?)?$')#bug here
 ABFS_ROOT_S = 'abfss://'
 ABFS_ROOT_S = 'abfss://'
 ABFS_ROOT = 'abfs://'
 ABFS_ROOT = 'abfs://'
 ABFSACCOUNT_NAME = re.compile('^/*[aA][bB][fF][sS]{1,2}://[$a-z0-9](?!.*--)[-a-z0-9]{1,61}[a-z0-9](@.*?)$')
 ABFSACCOUNT_NAME = re.compile('^/*[aA][bB][fF][sS]{1,2}://[$a-z0-9](?!.*--)[-a-z0-9]{1,61}[a-z0-9](@.*?)$')
@@ -41,13 +41,21 @@ def parse_uri(uri):
   Raises ValueError if invalid ABFS URI is passed.
   Raises ValueError if invalid ABFS URI is passed.
   """
   """
   match = ABFS_PATH_RE.match(uri)
   match = ABFS_PATH_RE.match(uri)
-  if not match:
+  direct_name = ''
+  base_direct_name = ''
+  file_system = ''
+  if match:
+    direct_name = match.group(3) or ''
+    base_direct_name = match.group(2) or ''
+    file_system = match.group(1)
+  else:
     match = ABFS_PATH_FULL.match(uri)
     match = ABFS_PATH_FULL.match(uri)
     if not match:
     if not match:
       raise ValueError("Invalid ABFS URI: %s" % uri)
       raise ValueError("Invalid ABFS URI: %s" % uri)
-  direct_name = match.group(3) or ''
-  base_direct_name = match.group(2) or ''
-  return match.group(1), direct_name, base_direct_name
+    direct_name = match.group(4) or ''
+    base_direct_name = match.group(3) or ''
+    file_system = match.group(2)
+  return file_system, direct_name, base_direct_name
 
 
 def is_root(uri):
 def is_root(uri):
   """
   """
@@ -96,7 +104,7 @@ def parent_path(path):
   Returns the parent of the specified folder
   Returns the parent of the specified folder
   """
   """
   if is_root(path):
   if is_root(path):
-    return "abfs://"
+    return path
   filesystem, directory_name, other = parse_uri(path)
   filesystem, directory_name, other = parse_uri(path)
   parent = None
   parent = None
   if directory_name == "":
   if directory_name == "":
@@ -129,10 +137,16 @@ def join(first,*complist):
   return joined
   return joined
 
 
 
 
-def abfspath(path, fs_defaultfs = get_default_abfs_fs()):
+def abfspath(path, fs_defaultfs = None):
   """
   """
   Converts a path to a path that the ABFS driver can use
   Converts a path to a path that the ABFS driver can use
   """
   """
+  if fs_defaultfs is None:
+    try:
+      fs_defaultfs = get_default_abfs_fs()
+    except:
+      LOG.warn("Configuration for ABFS is not set, may run into errors")
+      return path
   filesystem, dir_name = ("","")
   filesystem, dir_name = ("","")
   try:
   try:
     filesystem, dir_name = parse_uri(path)[:2]
     filesystem, dir_name = parse_uri(path)[:2]

+ 11 - 7
desktop/libs/azure/src/azure/abfs/abfs.py

@@ -144,7 +144,7 @@ class ABFS(object):
     Returns the ABFFStat object
     Returns the ABFFStat object
     """
     """
     if ABFS.isroot(path):
     if ABFS.isroot(path):
-      return ABFSStat.for_root()
+      return ABFSStat.for_root(path)
     file_system, dir_name = Init_ABFS.parse_uri(path)[:2]
     file_system, dir_name = Init_ABFS.parse_uri(path)[:2]
     if dir_name == '':
     if dir_name == '':
       LOG.debug("Path being called is a Filesystem")
       LOG.debug("Path being called is a Filesystem")
@@ -161,6 +161,9 @@ class ABFS(object):
       return self.listfilesystems_stats(params=None, **kwargs)
       return self.listfilesystems_stats(params=None, **kwargs)
     dir_stats = []
     dir_stats = []
     file_system, directory_name = Init_ABFS.parse_uri(path)[:2]
     file_system, directory_name = Init_ABFS.parse_uri(path)[:2]
+    root = Init_ABFS.ABFS_ROOT
+    if path.lower().startswith(Init_ABFS.ABFS_ROOT_S):
+      root = Init_ABFS.ABFS_ROOT_S
     if params is None:
     if params is None:
       params = {}
       params = {}
     if 'recursive' not in params:
     if 'recursive' not in params:
@@ -171,10 +174,10 @@ class ABFS(object):
     res = self._root._invoke("GET", file_system, params, headers=self._getheaders(), **kwargs)
     res = self._root._invoke("GET", file_system, params, headers=self._getheaders(), **kwargs)
     resp = self._root._format_response(res)
     resp = self._root._format_response(res)
     for x in resp['paths']:
     for x in resp['paths']:
-      dir_stats.append(ABFSStat.for_directory(res.headers, x, Init_ABFS.ABFS_ROOT +file_system + "/" + x['name']))
+      dir_stats.append(ABFSStat.for_directory(res.headers, x, root + file_system + "/" + x['name']))
     return dir_stats
     return dir_stats
   
   
-  def listfilesystems_stats(self, params=None, **kwargs):
+  def listfilesystems_stats(self, root = Init_ABFS.ABFS_ROOT, params=None, **kwargs):
     """
     """
     Lists the stats inside the File Systems, No functionality for params
     Lists the stats inside the File Systems, No functionality for params
     """
     """
@@ -184,8 +187,9 @@ class ABFS(object):
     params["resource"] = "account"
     params["resource"] = "account"
     res = self._root._invoke("GET", params=params, headers=self._getheaders() )
     res = self._root._invoke("GET", params=params, headers=self._getheaders() )
     resp = self._root._format_response(res)
     resp = self._root._format_response(res)
+    LOG.debug("%s" % root)
     for x in resp['filesystems']:
     for x in resp['filesystems']:
-      stats.append(ABFSStat.for_filesystems(res.headers, x))
+      stats.append(ABFSStat.for_filesystems(res.headers, x, root))
     return stats
     return stats
   
   
   def _stats(self, schemeless_path, params=None, **kwargs):
   def _stats(self, schemeless_path, params=None, **kwargs):
@@ -217,16 +221,16 @@ class ABFS(object):
     """
     """
     if ABFS.isroot(path):
     if ABFS.isroot(path):
       LOG.warn("Path being called is a Filesystem")
       LOG.warn("Path being called is a Filesystem")
-      return self.listfilesystems(params, **kwargs)
+      return self.listfilesystems(params = params, **kwargs)
     listofDir = self.listdir_stats(path, params)
     listofDir = self.listdir_stats(path, params)
     return [x.name for x in listofDir]
     return [x.name for x in listofDir]
   
   
   
   
-  def listfilesystems(self, params=None, **kwargs):
+  def listfilesystems(self, root = Init_ABFS.ABFS_ROOT,params=None, **kwargs):
     """
     """
     Lists the names of the File Systems, limited arguements  
     Lists the names of the File Systems, limited arguements  
     """
     """
-    listofFileSystems = self.listfilesystems_stats(params)
+    listofFileSystems = self.listfilesystems_stats(root = root, params = params)
     return [x.name for x in listofFileSystems]
     return [x.name for x in listofFileSystems]
   
   
   # Find or alter information about the URI path
   # Find or alter information about the URI path

+ 4 - 4
desktop/libs/azure/src/azure/abfs/abfsstats.py

@@ -61,12 +61,12 @@ class ABFSStat(object):
     return False
     return False
   
   
   @classmethod
   @classmethod
-  def for_root(cls):
-    return cls(True, 0, 0, 0, 'abfs://')
+  def for_root(cls,path):
+    return cls(True, 0, 0, 0, path)
   
   
   @classmethod
   @classmethod
-  def for_filesystems(cls,headers,resp):
-    return cls(True, headers['date'], resp['lastModified'], 0, 'abfs://' + resp['name'])
+  def for_filesystems(cls,headers,resp, scheme):
+    return cls(True, headers['date'], resp['lastModified'], 0, scheme + resp['name'])
 
 
   @classmethod
   @classmethod
   def for_directory(cls,headers,resp, path):
   def for_directory(cls,headers,resp, path):