فهرست منبع

HUE-3973 [core] Add a global flag to enable/disable the new configuration system

Jenny Kim 9 سال پیش
والد
کامیت
74040cb

+ 4 - 1
apps/oozie/src/oozie/models2.py

@@ -29,6 +29,7 @@ from django.core.urlresolvers import reverse
 from django.utils.encoding import force_unicode
 from django.utils.translation import ugettext as _
 
+from desktop.conf import USE_DEFAULT_CONFIGURATION
 from desktop.lib import django_mako
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.i18n import smart_str
@@ -284,7 +285,9 @@ class Workflow(Job):
     if not properties:
       config = None
       if user is not None:
-        config = DefaultConfiguration.objects.get_configuration_for_user(app=WorkflowConfiguration.APP_NAME, user=user)
+        config = None
+        if USE_DEFAULT_CONFIGURATION.get():
+          config = DefaultConfiguration.objects.get_configuration_for_user(app=WorkflowConfiguration.APP_NAME, user=user)
 
       if config is not None:
         properties = config.properties_dict

+ 56 - 49
apps/oozie/src/oozie/tests2.py

@@ -25,6 +25,7 @@ from django.db.models import Q
 
 from nose.tools import assert_true, assert_false, assert_equal, assert_not_equal
 
+from desktop.conf import USE_DEFAULT_CONFIGURATION
 from desktop.lib.django_test_util import make_logged_in_client
 from desktop.lib.test_utils import add_permission, add_to_group, grant_access, remove_from_group
 from desktop.models import DefaultConfiguration, Document, Document2
@@ -433,46 +434,49 @@ LIMIT $limit"""))
 
 
   def test_workflow_properties(self):
-    # Test that a new workflow will be initialized with default properties if no saved configs exist
-    wf = Workflow(user=self.user)
-    data = json.loads(wf.data)
-    assert_equal(data['workflow']['properties'], Workflow.get_workflow_properties_for_user(self.user))
-
-    # Setup a test Default configuration, NOTE: this is an invalid format for testing only
-    properties = [
-      {
-        'multiple': False,
-        'value': '/user/test/oozie',
-        'nice_name': 'Workspace',
-        'key': 'deployment_dir',
-        'help_text': 'Specify the deployment directory.',
-        'type': 'hdfs-file'
-      }, {
-        'multiple': True,
-        'value': [
+    reset = USE_DEFAULT_CONFIGURATION.set_for_testing(True)
+
+    try:
+      # Test that a new workflow will be initialized with default properties if no saved configs exist
+      wf = Workflow(user=self.user)
+      data = json.loads(wf.data)
+      assert_equal(data['workflow']['properties'], Workflow.get_workflow_properties_for_user(self.user))
+
+      # Setup a test Default configuration, NOTE: this is an invalid format for testing only
+      properties = [
+        {
+          'multiple': False,
+          'value': '/user/test/oozie',
+          'nice_name': 'Workspace',
+          'key': 'deployment_dir',
+          'help_text': 'Specify the deployment directory.',
+          'type': 'hdfs-file'
+        }, {
+          'multiple': True,
+          'value': [
             {
               'value': 'test',
               'key': 'mapred.queue.name'
             }
-        ],
-        'nice_name': 'Hadoop Properties',
-        'key': 'properties',
-        'help_text': 'Hadoop configuration properties.',
-        'type': 'settings'
-      }
-    ]
-    config = DefaultConfiguration(app=WorkflowConfiguration.APP_NAME, properties=json.dumps(properties), is_default=True)
-    config.save()
-    wf_props = config.properties_dict
-    wf_props.update({'wf1_id': None, 'description': ''})
-
-    # Test that a new workflow will be initialized with Default saved config if it exists
-    wf = Workflow(user=self.user)
-    data = json.loads(wf.data)
-    assert_equal(data['workflow']['properties'], wf_props)
-
-    # Test that a new workflow will be initialized with Group saved config if it exists
-    properties = [
+          ],
+          'nice_name': 'Hadoop Properties',
+          'key': 'properties',
+          'help_text': 'Hadoop configuration properties.',
+          'type': 'settings'
+        }
+      ]
+      config = DefaultConfiguration(app=WorkflowConfiguration.APP_NAME, properties=json.dumps(properties), is_default=True)
+      config.save()
+      wf_props = config.properties_dict
+      wf_props.update({'wf1_id': None, 'description': ''})
+
+      # Test that a new workflow will be initialized with Default saved config if it exists
+      wf = Workflow(user=self.user)
+      data = json.loads(wf.data)
+      assert_equal(data['workflow']['properties'], wf_props)
+
+      # Test that a new workflow will be initialized with Group saved config if it exists
+      properties = [
         {
             'multiple': True,
             'value': [
@@ -490,19 +494,22 @@ LIMIT $limit"""))
             'help_text': 'Hadoop configuration properties.',
             'type': 'settings'
         }
-    ]
-    config = DefaultConfiguration.objects.create(app=WorkflowConfiguration.APP_NAME,
-      properties=json.dumps(properties),
-      is_default=False)
-    config.groups.add(self.user.groups.first())
-    config.save()
-    wf_props = config.properties_dict
-    wf_props.update({'wf1_id': None, 'description': ''})
-
-    # Test that a new workflow will be initialized with Default saved config if it exists
-    wf = Workflow(user=self.user)
-    data = json.loads(wf.data)
-    assert_equal(data['workflow']['properties'], wf_props)
+      ]
+      config = DefaultConfiguration.objects.create(app=WorkflowConfiguration.APP_NAME,
+        properties=json.dumps(properties),
+        is_default=False)
+      config.groups.add(self.user.groups.first())
+      config.save()
+      wf_props = config.properties_dict
+      wf_props.update({'wf1_id': None, 'description': ''})
+
+      # Test that a new workflow will be initialized with Default saved config if it exists
+      wf = Workflow(user=self.user)
+      data = json.loads(wf.data)
+      assert_equal(data['workflow']['properties'], wf_props)
+    finally:
+      reset()
+
 
 class TestExternalWorkflowGraph(object):
 

+ 3 - 0
desktop/conf.dist/hue.ini

@@ -143,6 +143,9 @@
   # Choose whether to show the new SQL editor.
   ## use_new_editor=true
 
+  # Enable saved default configurations for Hive, Impala, Spark, and Oozie.
+  ## use_default_configurations=false
+
   # The directory where to store the auditing logs. Auditing is disable if the value is empty.
   # e.g. /var/log/hue/audit.log
   ## audit_event_log_dir=

+ 3 - 0
desktop/conf/pseudo-distributed.ini.tmpl

@@ -147,6 +147,9 @@
   # Choose whether to show the new SQL editor.
   ## use_new_editor=true
 
+  # Enable saved default configurations for Hive, Impala, Spark, and Oozie.
+  ## use_default_configurations=false
+
   # The directory where to store the auditing logs. Auditing is disable if the value is empty.
   # e.g. /var/log/hue/audit.log
   ## audit_event_log_dir=

+ 7 - 0
desktop/core/src/desktop/conf.py

@@ -1092,6 +1092,13 @@ USE_NEW_EDITOR = Config( # To remove in Hue 4
   help=_('Choose whether to show the new SQL editor.')
 )
 
+USE_DEFAULT_CONFIGURATION = Config(
+  key='use_default_configuration',
+  default=False,
+  type=coerce_bool,
+  help=_('Enable saved default configurations for Hive, Impala, Spark, and Oozie.')
+)
+
 def validate_ldap(user, config):
   res = []
 

+ 6 - 1
desktop/libs/notebook/src/notebook/connectors/hiveserver2.py

@@ -23,6 +23,7 @@ import StringIO
 from django.core.urlresolvers import reverse
 from django.utils.translation import ugettext as _
 
+from desktop.conf import USE_DEFAULT_CONFIGURATION
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.i18n import force_unicode
 from desktop.models import DefaultConfiguration
@@ -145,7 +146,11 @@ class HS2Api(Api):
       session = dbms.get(self.user, query_server=get_query_server_config(name=lang)).open_session(self.user)
 
     if not properties:
-      config = DefaultConfiguration.objects.get_configuration_for_user(app=lang, user=self.user)
+
+      config = None
+      if USE_DEFAULT_CONFIGURATION.get():
+        config = DefaultConfiguration.objects.get_configuration_for_user(app=lang, user=self.user)
+
       if config is not None:
         properties = config.properties_list
       else:

+ 5 - 1
desktop/libs/notebook/src/notebook/connectors/spark_shell.py

@@ -21,6 +21,7 @@ import time
 
 from django.utils.translation import ugettext as _
 
+from desktop.conf import USE_DEFAULT_CONFIGURATION
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.i18n import force_unicode
 from desktop.lib.rest.http_client import RestException
@@ -144,7 +145,10 @@ class SparkApi(Api):
 
   def create_session(self, lang='scala', properties=None):
     if not properties:
-      config = DefaultConfiguration.objects.get_configuration_for_user(app='spark', user=self.user)
+      config = None
+      if USE_DEFAULT_CONFIGURATION.get():
+        config = DefaultConfiguration.objects.get_configuration_for_user(app='spark', user=self.user)
+
       if config is not None:
         properties = config.properties_list
       else: