Browse Source

HUE-3450 [metadata] Refactor Navigator API for v3 support

Jenny Kim 9 years ago
parent
commit
30ccecd

+ 2 - 2
desktop/conf.dist/hue.ini

@@ -1418,8 +1418,8 @@
 
 
   [[navigator]]
   [[navigator]]
     # For tagging tables, files and getting lineage of data.
     # For tagging tables, files and getting lineage of data.
-    # Navigator API URL with version
-    ## api_url=http://localhost:7187/api/v2
+    # Navigator API URL (without version suffix)
+    ## api_url=http://localhost:7187/api
 
 
     # Navigator API HTTP authentication username and password
     # Navigator API HTTP authentication username and password
     # Override the desktop default username and password of the hue user used for authentications with other services.
     # Override the desktop default username and password of the hue user used for authentications with other services.

+ 2 - 2
desktop/conf/pseudo-distributed.ini.tmpl

@@ -1420,8 +1420,8 @@
 
 
   [[navigator]]
   [[navigator]]
     # For tagging tables, files and getting lineage of data.
     # For tagging tables, files and getting lineage of data.
-    # Navigator API URL with version
-    ## api_url=http://localhost:7187/api/v2
+    # Navigator API URL with version (without version suffix)
+    ## api_url=http://localhost:7187/api
 
 
     # Navigator API HTTP authentication username and password
     # Navigator API HTTP authentication username and password
     # Override the desktop default username and password of the hue user used for authentications with other services.
     # Override the desktop default username and password of the hue user used for authentications with other services.

+ 2 - 1
desktop/libs/metadata/src/metadata/conf.py

@@ -34,6 +34,7 @@ def get_auth_password():
     return password
     return password
   return DEFAULT_AUTH_PASSWORD.get()
   return DEFAULT_AUTH_PASSWORD.get()
 
 
+
 def get_optimizer_url():
 def get_optimizer_url():
   return OPTIMIZER.API_URL.get() and OPTIMIZER.API_URL.get().strip('/')
   return OPTIMIZER.API_URL.get() and OPTIMIZER.API_URL.get().strip('/')
 
 
@@ -108,7 +109,7 @@ NAVIGATOR = ConfigSection(
   members=dict(
   members=dict(
     API_URL=Config(
     API_URL=Config(
       key='api_url',
       key='api_url',
-      help=_t('Base URL to Navigator API (e.g. - http://localhost:7187/api/v2)'),
+      help=_t('Base URL to Navigator API (e.g. - http://localhost:7187/api)'),
       default=None),
       default=None),
     AUTH_USERNAME=Config(
     AUTH_USERNAME=Config(
       key="auth_username",
       key="auth_username",

+ 1 - 1
desktop/libs/metadata/src/metadata/navigator_api.py

@@ -25,7 +25,7 @@ from django.views.decorators.http import require_POST
 from desktop.lib.django_util import JsonResponse
 from desktop.lib.django_util import JsonResponse
 from desktop.lib.i18n import force_unicode
 from desktop.lib.i18n import force_unicode
 
 
-from metadata.navigator import NavigatorApi, is_navigator_enabled
+from metadata.navigator_client import NavigatorApi, is_navigator_enabled
 
 
 LOG = logging.getLogger(__name__)
 LOG = logging.getLogger(__name__)
 
 

+ 9 - 8
desktop/libs/metadata/src/metadata/navigator_client.py

@@ -26,6 +26,7 @@ from metadata.conf import NAVIGATOR
 
 
 
 
 LOG = logging.getLogger(__name__)
 LOG = logging.getLogger(__name__)
+VERSION = 'v3'
 
 
 
 
 def is_navigator_enabled():
 def is_navigator_enabled():
@@ -38,11 +39,11 @@ class NavigatorApiException(Exception):
 
 
 class NavigatorApi(object):
 class NavigatorApi(object):
   """
   """
-  http://cloudera.github.io/navigator/apidocs/v2/index.html
+  http://cloudera.github.io/navigator/apidocs/v3/index.html
   """
   """
 
 
   def __init__(self, api_url=None, user=None, password=None):
   def __init__(self, api_url=None, user=None, password=None):
-    self._api_url = (api_url or NAVIGATOR.API_URL.get()).strip('/')
+    self._api_url = '%s/%s' % ((api_url or NAVIGATOR.API_URL.get()).strip('/'), VERSION)
     self._username = user or NAVIGATOR.AUTH_USERNAME.get()
     self._username = user or NAVIGATOR.AUTH_USERNAME.get()
     self._password = password or NAVIGATOR.AUTH_PASSWORD.get()
     self._password = password or NAVIGATOR.AUTH_PASSWORD.get()
 
 
@@ -56,8 +57,8 @@ class NavigatorApi(object):
 
 
   def find_entity(self, source_type, type, name, **filters):
   def find_entity(self, source_type, type, name, **filters):
     """
     """
-    GET /api/v2/entities?query=((sourceType:<source_type>)AND(type:<type>)AND(originalName:<name>))
-    http://cloudera.github.io/navigator/apidocs/v2/path__v2_entities.html
+    GET /api/v3/entities?query=((sourceType:<source_type>)AND(type:<type>)AND(originalName:<name>))
+    http://cloudera.github.io/navigator/apidocs/v3/path__v3_entities.html
     """
     """
     try:
     try:
       params = self.__params
       params = self.__params
@@ -95,8 +96,8 @@ class NavigatorApi(object):
 
 
   def get_entity(self, entity_id):
   def get_entity(self, entity_id):
     """
     """
-    GET /api/v2/entities/:id
-    http://cloudera.github.io/navigator/apidocs/v2/path__v2_entities_-id-.html
+    GET /api/v3/entities/:id
+    http://cloudera.github.io/navigator/apidocs/v3/path__v3_entities_-id-.html
     """
     """
     try:
     try:
       return self._root.get('entities/%s' % entity_id, headers=self.__headers, params=self.__params)
       return self._root.get('entities/%s' % entity_id, headers=self.__headers, params=self.__params)
@@ -108,8 +109,8 @@ class NavigatorApi(object):
 
 
   def update_entity(self, entity_id, **metadata):
   def update_entity(self, entity_id, **metadata):
     """
     """
-    PUT /api/v2/entities/:id
-    http://cloudera.github.io/navigator/apidocs/v2/path__v2_entities_-id-.html
+    PUT /api/v3/entities/:id
+    http://cloudera.github.io/navigator/apidocs/v3/path__v3_entities_-id-.html
     """
     """
     try:
     try:
       # TODO: Check permissions of entity
       # TODO: Check permissions of entity

+ 1 - 0
desktop/libs/metadata/src/metadata/navigator_tests.py

@@ -105,6 +105,7 @@ class TestNavigatorApi(object):
     resp = self.client.post(reverse('metadata:delete_properties'), self._format_json_body({'id': entity_id, 'keys': ['hue']}))
     resp = self.client.post(reverse('metadata:delete_properties'), self._format_json_body({'id': entity_id, 'keys': ['hue']}))
     json_resp = json.loads(resp.content)
     json_resp = json.loads(resp.content)
     assert_equal(0, json_resp['status'], json_resp)
     assert_equal(0, json_resp['status'], json_resp)
+    del props['hue']
     assert_equal(entity['properties'], json_resp['entity']['properties'])
     assert_equal(entity['properties'], json_resp['entity']['properties'])
 
 
 
 

+ 2 - 1
desktop/libs/metadata/src/metadata/urls.py

@@ -17,6 +17,7 @@
 
 
 from django.conf.urls import patterns, url
 from django.conf.urls import patterns, url
 
 
+
 # Navigator API
 # Navigator API
 urlpatterns = patterns('metadata.navigator_api',
 urlpatterns = patterns('metadata.navigator_api',
   url(r'^api/navigator/find_entity/?$', 'find_entity', name='find_entity'),
   url(r'^api/navigator/find_entity/?$', 'find_entity', name='find_entity'),
@@ -29,7 +30,7 @@ urlpatterns = patterns('metadata.navigator_api',
 
 
 
 
 # Optimizer API
 # Optimizer API
-urlpatterns = patterns('metadata.optimizer_api',
+urlpatterns += patterns('metadata.optimizer_api',
   url(r'^api/optimizer_api/top_tables/?$', 'top_tables', name='top_tables'),
   url(r'^api/optimizer_api/top_tables/?$', 'top_tables', name='top_tables'),
   url(r'^api/optimizer_api/table_details/?$', 'table_details', name='table_details'),
   url(r'^api/optimizer_api/table_details/?$', 'table_details', name='table_details'),
   url(r'^api/optimizer_api/query_compatibility/?$', 'query_compatibility', name='query_compatibility'),
   url(r'^api/optimizer_api/query_compatibility/?$', 'query_compatibility', name='query_compatibility'),