Эх сурвалжийг харах

HUE-6292 [oozie] Properly prompt for parameters in document actions

Romain Rigaux 8 жил өмнө
parent
commit
41529347ad

+ 10 - 7
apps/oozie/src/oozie/models2.py

@@ -42,6 +42,7 @@ from desktop.models import DefaultConfiguration, Document2, Document
 from hadoop.fs.hadoopfs import Hdfs
 from hadoop.fs.exceptions import WebHdfsException
 
+from liboozie.conf import SECURITY_ENABLED
 from liboozie.oozie_api import get_oozie
 from liboozie.submission2 import Submission
 from liboozie.submission2 import create_directories
@@ -390,10 +391,12 @@ class Workflow(Job):
           if param['value'] and '=' in param['value']:
             name, val = param['value'].split('=', 1)
             parameters[name] = val
+        extra = find_parameters(node, fields=['key_tab_path', 'user_principal'])
       else:
         extra = node.find_parameters()
-        if extra:
-          parameters.update(dict([(param, '') for param in list(extra)]))
+
+      if extra:
+        parameters.update(dict([(param, '') for param in list(extra)]))
 
     return parameters
 
@@ -1386,14 +1389,14 @@ class ImpalaAction(HiveServer2Action):
   FIELDS['key_tab_path'] = {
       'name': 'key_tab_path',
       'label': _('Keytab path'),
-      'value': '',
+      'value': '${key_tab_path}' if SECURITY_ENABLED.get() else '',
       'help_text': _('Path to the keytab to use when on a secure cluster, e.g. /user/joe/joe.keytab.'),
       'type': ''
   }
   FIELDS['user_principal'] = {
       'name': 'user_principal',
       'label': _('User principal'),
-      'value': 'joe@PROD.EDH',
+      'value': '${user_principal}' if SECURITY_ENABLED.get() else '',
       'help_text': _('Name of the principal to use in the kinit, e.g.: kinit -k -t /home/joe/joe.keytab joe@PROD.EDH.'),
       'type': ''
   }
@@ -2246,20 +2249,20 @@ class ImpalaDocumentAction(HiveDocumentAction):
       'name': 'impalad_host',
       'label': _('Impalad hostname'),
       'value': "",
-      'help_text': _('e.g. impalad-001.cluster.com. The hostname of the Impalad to send the query to.'),
+      'help_text': _('e.g. impalad-001.cluster.com (optional)'),
       'type': ''
   }
   FIELDS['key_tab_path'] = {
       'name': 'key_tab_path',
       'label': _('Keytab path'),
-      'value': '',
+      'value': '${key_tab_path}' if SECURITY_ENABLED.get() else '',
       'help_text': _('Path to the keytab to use when on a secure cluster, e.g. /user/joe/joe.keytab.'),
       'type': ''
   }
   FIELDS['user_principal'] = {
       'name': 'user_principal',
       'label': _('User principal'),
-      'value': 'joe@PROD.EDH',
+      'value': '${user_principal}' if SECURITY_ENABLED.get() else '',
       'help_text': _('Name of the principal to use in the kinit, e.g.: kinit -k -t /home/joe/joe.keytab joe@PROD.EDH.'),
       'type': ''
   }

+ 3 - 3
apps/oozie/src/oozie/templates/editor2/common_workflow.mako

@@ -1146,17 +1146,17 @@
       </ul>
       <div class="tab-content">
         <div class="tab-pane active" data-bind="attr: { id: 'properties-' + id() }">
-          <!-- ko if: $root.workflow_properties.jdbc_url -->
+          <!-- ko if: typeof properties.jdbc_url != 'undefined' -->
           <span data-bind="text: $root.workflow_properties.jdbc_url.label"></span>
           <input type="text" data-bind="value: properties.jdbc_url, attr: { placeholder: $root.workflow_properties.jdbc_url.help_text }" />
           <br/>
           <!-- /ko -->
-          <!-- ko if: $root.workflow_properties.password -->
+          <!-- ko if: typeof properties.password != 'undefined' -->
           <span data-bind="text: $root.workflow_properties.password.label"></span>
           <input type="text" data-bind="value: properties.password, attr: { placeholder: $root.workflow_properties.password.help_text }" />
           <br/>
           <!-- /ko -->
-          <!-- ko if: $root.workflow_properties.impalad_host -->
+          <!-- ko if: typeof properties.impalad_host != 'undefined' -->
           <span data-bind="text: $root.workflow_properties.impalad_host.label"></span>
           <input type="text" data-bind="value: properties.impalad_host, attr: { placeholder: $root.workflow_properties.impalad_host.help_text }" />
           <br/>

+ 4 - 1
desktop/libs/liboozie/src/liboozie/submission2.py

@@ -20,6 +20,8 @@ import logging
 import os
 import time
 
+from string import Template
+
 from django.utils.functional import wraps
 from django.utils.translation import ugettext as _
 
@@ -211,6 +213,7 @@ class Submission(object):
             if action.data['properties'].get('uuid'):
               notebook = Notebook(document=Document2.objects.get_by_uuid(user=self.user, uuid=action.data['properties']['uuid']))
               statements = notebook.get_str()
+              statements = Template(statements).safe_substitute(**self.properties)
               script_name = action.data['name'] + '.sql'
               self._create_file(deployment_dir, script_name, statements)
           else:
@@ -218,7 +221,7 @@ class Submission(object):
 
           if self.api.security_enabled:
             kinit = 'kinit -k -t *.keytab %(user_principal)s' % {
-              'user_principal': action.data['properties'].get('user_principal')
+              'user_principal': self.properties.get('user_principal', action.data['properties'].get('user_principal'))
             }
           else:
             kinit = ''