Bläddra i källkod

[HUE-6055] Need http_client for navigator

Since navigator api communicate on http and it needs to clear the cookies. In secure cluster clearing cookies will cause service interruption. Seperated navigator's http_client.

Tested on:
http://ranade-511-1.gce.cloudera.com:7180/
Prakash Ranade 8 år sedan
förälder
incheckning
86c94b7

+ 59 - 0
desktop/core/src/desktop/lib/rest/unsecure_http_client.py

@@ -0,0 +1,59 @@
+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+import requests
+import threading
+
+from desktop import conf
+
+from desktop.lib.rest.http_client import HttpClient, RestException
+
+__docformat__ = "epytext"
+
+LOG = logging.getLogger(__name__)
+
+CACHE_UNSECURE_SESSION = None
+CACHE_UNSECURE_SESSION_LOCK = threading.Lock()
+
+def get_unsecure_httponly_request_session():
+  global CACHE_UNSECURE_SESSION
+  if CACHE_UNSECURE_SESSION is None:
+    CACHE_UNSECURE_SESSION_LOCK.acquire()
+    try:
+      if CACHE_UNSECURE_SESSION is None:
+        CACHE_UNSECURE_SESSION = requests.Session()
+        CACHE_UNSECURE_SESSION.mount('http://', requests.adapters.HTTPAdapter(pool_connections=conf.CHERRYPY_SERVER_THREADS.get(), pool_maxsize=conf.CHERRYPY_SERVER_THREADS.get()))
+    finally:
+      CACHE_UNSECURE_SESSION_LOCK.release()
+  return CACHE_UNSECURE_SESSION
+
+class UnsecureHttpClient(HttpClient):
+  """
+  HTTP Client that should not be used with Kerberos in order to keep the pool separate from the kerberized one.
+
+  This allow to have a pool of HTTP client with Kerberos authentication and another one without, in case the components are not all secure or all unsecure.
+  """
+  def __init__(self, base_url, exc_class=None, logger=None):
+    """
+    @param base_url: The base url to the API.
+    @param exc_class: An exception class to handle non-200 results.
+    """
+    self._base_url = base_url.rstrip('/')
+    self._exc_class = exc_class or RestException
+    self._logger = logger or LOG
+    self._session = get_unsecure_httponly_request_session()
+    self._cookies = None

+ 4 - 3
desktop/libs/metadata/src/metadata/navigator_client.py

@@ -27,8 +27,8 @@ from django.utils.translation import ugettext as _
 
 from desktop.lib.i18n import smart_unicode
 from desktop.lib.rest import resource
-from desktop.lib.rest.http_client import HttpClient, RestException
-
+from desktop.lib.rest.unsecure_http_client import UnsecureHttpClient
+from desktop.lib.rest.http_client import RestException
 
 from hadoop.conf import HDFS_CLUSTERS
 from libsentry.conf import PRIVILEGE_CHECKER_CACHING
@@ -110,7 +110,8 @@ class NavigatorApi(object):
     self._password = get_navigator_auth_password()
 
     self.user = user
-    self._client = HttpClient(self._api_url, logger=LOG)
+    # Navigator does not support Kerberos authentication while other components usually requires it
+    self._client = UnsecureHttpClient(self._api_url, logger=LOG)
     self._client.set_basic_auth(self._username, self._password)
     self._root = resource.Resource(self._client, urlencode=False) # For search_entities_interactive