浏览代码

HUE-8758 [connector] API to install data examples

Romain 5 年之前
父节点
当前提交
8d17cfafc1

+ 4 - 3
apps/about/src/about/templates/admin_wizard.mako

@@ -317,10 +317,11 @@ ${ layout.menubar(section='quick_start') }
     self.isInstallingSample = ko.observable(false);
 
     self.installConnectorDataExample = function(data, event) {
-      var sampleUrl = data.dialect == 'hive' ? "${ url('beeswax:install_examples') }" : "${ url('impala:install_examples') }";
-
       self.isInstallingSample(true);
-      $.post(sampleUrl, function(data) {
+
+      $.post("${ url('notebook:install_examples') }", {
+          dialect: data.dialect
+        }, function(data) {
         if (data.status == 0) {
           $(document).trigger('info','${ _("Examples refreshed") }');
           if ($(button).data("is-connector")) {

+ 2 - 2
apps/beeswax/src/beeswax/management/commands/beeswax_install_examples.py

@@ -90,7 +90,7 @@ class Command(BaseCommand):
 
   def _install_tables(self, django_user, app_name, db_name, tables):
     data_dir = beeswax.conf.LOCAL_EXAMPLES_DATA_DIR.get()
-    table_file = file(os.path.join(data_dir, tables))
+    table_file = open(os.path.join(data_dir, tables))
     table_list = json.load(table_file)
     table_file.close()
 
@@ -102,7 +102,7 @@ class Command(BaseCommand):
         raise InstallException(_('Could not install table: %s') % ex)
 
   def _install_queries(self, django_user, app_name):
-    design_file = file(os.path.join(beeswax.conf.LOCAL_EXAMPLES_DATA_DIR.get(), 'designs.json'))
+    design_file = open(os.path.join(beeswax.conf.LOCAL_EXAMPLES_DATA_DIR.get(), 'designs.json'))
     design_list = json.load(design_file)
     design_file.close()
 

+ 1 - 1
apps/useradmin/src/useradmin/models.py

@@ -335,7 +335,7 @@ def install_sample_user(django_user=None):
     else:
       user_attributes = lookup.copy()
       if ENABLE_ORGANIZATIONS.get():
-        user_attributes['organization'] = get_organization(user=django_user)
+        user_attributes['organization'] = get_organization(email=django_username)
       user_attributes.update({
         'password': '!',
         'is_active': False,

+ 3 - 1
desktop/libs/hadoop/src/hadoop/cluster.py

@@ -62,7 +62,9 @@ def rm_ha(funct):
 def get_hdfs(identifier="default", user=None):
   global FS_CACHE
   get_all_hdfs()
-  return FS_CACHE[list(FS_CACHE.keys())[0]] if has_connectors() else FS_CACHE[identifier]
+  if has_connectors():
+    identifier = list(FS_CACHE.keys())[0] if FS_CACHE.keys() else None
+  return FS_CACHE.get(identifier)
 
 
 def get_defaultfs():

+ 5 - 2
desktop/libs/notebook/src/notebook/views.py

@@ -376,8 +376,11 @@ def install_examples(request):
 
   if request.method == 'POST':
     try:
-      Command().handle(user=request.user)
-      response['status'] = 0
+      if request.POST.get('dialect') == 'hive':
+        pass
+      else:
+        Command().handle(user=request.user)
+        response['status'] = 0
     except Exception as err:
       LOG.exception(err)
       response['message'] = str(err)