Эх сурвалжийг харах

HUE-4252 [core] Handle 307 redirect from YARN upon standby failover

Don't enable allow_redirects by default, since it causes non-HA setups to fail.
Jenny Kim 9 жил өмнө
parent
commit
e5e7eba

+ 1 - 1
desktop/core/src/desktop/lib/rest/resource.py

@@ -122,7 +122,7 @@ class Resource(object):
 
     @return: A dictionary of the JSON result.
     """
-    return self.invoke("POST", relpath, params, data, self._make_headers(contenttype, headers), files)
+    return self.invoke("POST", relpath, params, data, self._make_headers(contenttype, headers), files, allow_redirects)
 
 
   def put(self, relpath=None, params=None, data=None, contenttype=None, allow_redirects=False):

+ 21 - 8
desktop/libs/hadoop/src/hadoop/yarn/resource_manager_api.py

@@ -25,7 +25,7 @@ from django.utils.translation import ugettext as _
 from desktop.conf import DEFAULT_USER
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.i18n import smart_str
-from desktop.lib.rest.http_client import HttpClient
+from desktop.lib.rest.http_client import HttpClient, RestException
 from desktop.lib.rest.resource import Resource
 
 from hadoop import cluster
@@ -140,7 +140,7 @@ class ResourceManagerApi(object):
 
     try:
       params = self._get_params()
-      return self._execute(self._root.put, 'cluster/apps/%(app_id)s/state' % {'app_id': app_id}, params=params, data=json.dumps(data), allow_redirects=True, contenttype=_JSON_CONTENT_TYPE)
+      return self._execute(self._root.put, 'cluster/apps/%(app_id)s/state' % {'app_id': app_id}, params=params, data=json.dumps(data), contenttype=_JSON_CONTENT_TYPE)
     finally:
       if token:
         self.cancel_token(token)
@@ -157,11 +157,24 @@ class ResourceManagerApi(object):
     return self._execute(self._root.delete, 'cluster/delegation-token', params=params, headers=headers)
 
   def _execute(self, function, *args, **kwargs):
-    response = function(*args, **kwargs)
-
-    # YARN-2605: Yarn does not use proper HTTP redirects when the standby RM has
-    # failed back to the master RM.
-    if isinstance(response, str) and response.startswith('This is standby RM. Redirecting to the current active RM'):
-      raise YarnFailoverOccurred(response)
+    response = None
+    try:
+      response = function(*args, **kwargs)
+    except RestException, e:
+      # YARN-2605: Yarn does not use proper HTTP redirects when the standby RM has
+      # failed back to the master RM.
+      if e.code == 307 and e.message.startswith('This is standby RM'):
+        LOG.info('Received YARN failover redirect response, attempting to resolve redirect.')
+        try:
+          kwargs.update({'allow_redirects': True})
+          response = function(*args, **kwargs)
+        except Exception, e:
+          if response:
+            raise YarnFailoverOccurred(response)
+          else:
+            raise PopupException(_('Failed to resolve YARN RM: %s') % e)
+      else:
+        raise PopupException(_('YARN RM returned a failed response: %s') % e)
 
     return response
+