Selaa lähdekoodia

HUE-2942 [core] Unify app examples

Separates install user from owners and checks against list of valid sample document owners
Jenny Kim 10 vuotta sitten
vanhempi
commit
71be43abd2

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1 - 1
apps/oozie/src/oozie/fixtures/initial_oozie_examples.json


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1 - 1
apps/search/src/search/fixtures/initial_search_examples.json


+ 2 - 2
apps/search/src/search/management/commands/search_setup.py

@@ -20,7 +20,7 @@ import logging
 from django.core import management
 from django.core.management.base import NoArgsCommand
 
-from desktop.models import Document, Document2, SAMPLE_USERNAME
+from desktop.models import Document, Document2, SAMPLE_USER_OWNERS
 from useradmin.models import install_sample_user
 
 
@@ -30,7 +30,7 @@ LOG = logging.getLogger(__name__)
 class Command(NoArgsCommand):
   def handle_noargs(self, **options):
 
-    if not Document2.objects.filter(type='search-dashboard', owner__username=SAMPLE_USERNAME).exists():
+    if not Document2.objects.filter(type='search-dashboard', owner__username__in=SAMPLE_USER_OWNERS).exists():
       install_sample_user()
 
       management.call_command('loaddata', 'initial_search_examples.json', verbosity=2)

+ 2 - 2
apps/search/src/search/search_controller.py

@@ -20,7 +20,7 @@ import logging
 
 from django.db.models import Q
 
-from desktop.models import Document2, Document, SAMPLE_USERNAME
+from desktop.models import Document2, Document, SAMPLE_USER_OWNERS
 from libsolr.api import SolrApi
 
 from search.conf import SOLR_URL
@@ -42,7 +42,7 @@ class SearchController(object):
 
   def get_shared_search_collections(self):
     # Those are the ones appearing in the menu
-    docs = Document.objects.filter(Q(owner=self.user) | Q(owner__username=SAMPLE_USERNAME), extra='search-dashboard')
+    docs = Document.objects.filter(Q(owner=self.user) | Q(owner__username__in=SAMPLE_USER_OWNERS), extra='search-dashboard')
 
     return [d.content_object for d in docs.order_by('-id')]
 

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1 - 1
apps/spark/src/spark/fixtures/initial_spark_examples.json


+ 2 - 2
apps/spark/src/spark/management/commands/spark_setup.py

@@ -23,7 +23,7 @@ from django.contrib.auth.models import User
 from django.core import management
 from django.core.management.base import BaseCommand
 
-from desktop.models import Document, Document2, SAMPLE_USERNAME
+from desktop.models import Document, Document2, SAMPLE_USER_OWNERS
 from useradmin.models import install_sample_user
 
 
@@ -40,7 +40,7 @@ class Command(BaseCommand):
     else:
       user = options['user']
 
-    if not Document2.objects.filter(type='notebook', owner__username=SAMPLE_USERNAME).exists():
+    if not Document2.objects.filter(type='notebook', owner__username__in=SAMPLE_USER_OWNERS).exists():
       install_sample_user()
 
       management.call_command('loaddata', 'apps/spark/src/spark/fixtures/initial_spark_examples.json', verbosity=2)

+ 22 - 8
apps/useradmin/src/useradmin/models.py

@@ -59,7 +59,7 @@ from django.utils.translation import ugettext_lazy as _t
 
 from desktop import appmanager
 from desktop.lib.exceptions_renderable import PopupException
-from desktop.models import SAMPLE_USERNAME
+from desktop.models import SAMPLE_USER_INSTALL
 from hadoop import cluster
 
 import useradmin.conf
@@ -295,19 +295,33 @@ def install_sample_user():
   """
   Setup the de-activated sample user with a certain id. Do not create a user profile.
   """
-
-  user, created = auth_models.User.objects.get_or_create(
-      username=SAMPLE_USERNAME,
+  user = None
+  try:
+    user = auth_models.User.objects.get(id=1100713)
+    LOG.info('Sample user found: %s' % user.username)
+  except auth_models.User.DoesNotExist:
+    user, created = auth_models.User.objects.get_or_create(
+      username=SAMPLE_USER_INSTALL,
       password='!',
       is_active=False,
       is_superuser=False,
       id=1100713,
       pk=1100713)
 
-  if created:
-    LOG.info('Installed a user called "%s"' % (SAMPLE_USERNAME,))
+    if created:
+      LOG.info('Installed a user called "%s"' % SAMPLE_USER_INSTALL)
+  except Exception, ex:
+    LOG.exception('Failed to get or create sample user')
 
-    fs = cluster.get_hdfs()
-    fs.do_as_user(SAMPLE_USERNAME, fs.create_home_dir)
+  fs = cluster.get_hdfs()
+  # If home directory doesn't exist for sample user, create it
+  try:
+    if not fs.do_as_user(SAMPLE_USER_INSTALL, fs.get_home_dir):
+      fs.do_as_user(SAMPLE_USER_INSTALL, fs.create_home_dir)
+      LOG.info('Created home directory for user: %s' % SAMPLE_USER_INSTALL)
+    else:
+      LOG.info('Home directory already exists for user: %s' % SAMPLE_USER_INSTALL)
+  except Exception, ex:
+    LOG.exception('Failed to create home directory for user %s: %s' % (SAMPLE_USER_INSTALL, str(ex)))
 
   return user

+ 3 - 2
desktop/core/src/desktop/models.py

@@ -39,7 +39,8 @@ from desktop.lib.exceptions_renderable import PopupException
 LOG = logging.getLogger(__name__)
 
 
-SAMPLE_USERNAME = 'sample'
+SAMPLE_USER_INSTALL = 'hue'
+SAMPLE_USER_OWNERS = ['hue', 'sample']
 
 
 class UserPreferences(models.Model):
@@ -363,7 +364,7 @@ class DocumentManager(models.Manager):
       # Make sure all the sample user documents are shared.
       try:
         with transaction.atomic():
-          for doc in Document.objects.filter(owner__username=SAMPLE_USERNAME):
+          for doc in Document.objects.filter(owner__username__in=SAMPLE_USER_OWNERS):
             doc.share_to_default()
 
             tag = DocumentTag.objects.get_example_tag(user=doc.owner)

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä