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

HUE-4995 [oozie] Provide Email notification option at workflow submission

krish 9 жил өмнө
parent
commit
6fad03e

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

@@ -30,7 +30,6 @@ from django.core.urlresolvers import reverse
 from django.db.models import Q
 from django.utils.encoding import force_unicode
 from django.utils.translation import ugettext as _
-from django.contrib.auth.models import User
 
 from desktop.conf import USE_DEFAULT_CONFIGURATION
 from desktop.lib import django_mako
@@ -851,6 +850,18 @@ class Node():
       'workflow_mapping': workflow_mapping
     }
 
+    if mapping.get('email_checkbox'):
+      if self.data['type'] == KillAction.TYPE and not self.data['properties'].get('enableMail'):
+        self.data['properties']['enableMail'] = True
+        self.data['properties']['to'] = self.user.email
+        self.data['properties']['subject'] = _("${wf:name()} execution failure")
+        self.data['properties']['body'] = _("Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]")
+
+      if self.data['type'] == EndNode.TYPE:
+        self.data['properties']['enableMail'] = True
+        self.data['properties']['to'] = self.user.email
+        self.data['properties']['subject'] = _("${wf:name()} execution successful")
+
     return django_mako.render_to_string(self.get_template_name(), data)
 
   @property
@@ -916,6 +927,11 @@ def _upgrade_older_node(node):
     node['properties']['subject'] = ''
     node['properties']['body'] = ''
 
+  if node['type'] in ('end', 'end-widget') and 'to' not in node['properties']:
+    node['properties']['enableMail'] = False
+    node['properties']['to'] = ''
+    node['properties']['subject'] = ''
+
   if node['type'] == 'email-widget' and 'bcc' not in node['properties']:
     node['properties']['bcc'] = ''
     node['properties']['content_type'] = 'text/plain'

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 1 - 0
apps/oozie/src/oozie/models2_tests.py


+ 14 - 0
apps/oozie/src/oozie/templates/editor2/gen/workflow-end.xml.mako

@@ -15,4 +15,18 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 
+%if node['properties']['enableMail']:
+    <action name="${ node['name'] }">
+        <email xmlns="uri:oozie:email-action:0.2">
+            <to>${ node['properties']['to'] }</to>
+            <subject>${ node['properties']['subject'] }</subject>
+            <body></body>
+        </email>
+        <ok to="${ node['name'] }-kill"/>
+        <error to="${ node['name'] }-kill"/>
+    </action>
+
+    <end name="${ node['name'] }-kill"/>
+%else:
     <end name="${ node['name'] }"/>
+%endif

+ 15 - 0
apps/oozie/src/oozie/templates/editor2/submit_job_popup.mako

@@ -79,6 +79,21 @@
            <input type="checkbox" name="dryrun_checkbox" /> ${ _('Do a dryrun before submitting the job?') }
          </label>
       % endif
+      % if is_oozie_mail_enabled:
+        </br>
+        <label class="checkbox" style="display: inline-block; margin-top: 5px">
+          <input type="checkbox" name="email_checkbox"
+          % if not email_id:
+            disabled
+          % endif
+          />
+        % if email_id:
+          ${_('Email notification to ')}<a href="/useradmin/users/edit/${user.username}#step2" target="_blank"> ${email_id} </a>
+        % else:
+          ${_('Email not set in ')}<a href="/useradmin/users/edit/${user.username}#step2" target="_blank"> ${_('profile.')} </a>
+        % endif
+        </label>
+        %endif
       % if return_json:
         <input type="hidden" name="format" value="json">
       % endif

+ 10 - 1
apps/oozie/src/oozie/views/editor2.py

@@ -398,6 +398,7 @@ def _submit_workflow_helper(request, workflow, submit_action):
     if params_form.is_valid():
       mapping = dict([(param['name'], param['value']) for param in params_form.cleaned_data])
       mapping['dryrun'] = request.POST.get('dryrun_checkbox') == 'on'
+      mapping['email_checkbox'] = request.POST.get('email_checkbox') == 'on'
 
       try:
         job_id = _submit_workflow(request.user, request.fs, request.jt, workflow, mapping)
@@ -412,15 +413,23 @@ def _submit_workflow_helper(request, workflow, submit_action):
     initial_params = ParameterForm.get_initial_params(dict([(param['name'], param['value']) for param in parameters]))
     params_form = ParametersFormSet(initial=initial_params)
 
+
     popup = render('editor2/submit_job_popup.mako', request, {
                      'params_form': params_form,
                      'name': workflow.name,
                      'action': submit_action,
-                     'show_dryrun': True
+                     'show_dryrun': True,
+                     'email_id': request.user.email,
+                     'is_oozie_mail_enabled': _is_oozie_mail_enabled(request.user)
                    }, force_template=True).content
     return JsonResponse(popup, safe=False)
 
 
+def _is_oozie_mail_enabled(user):
+  api = get_oozie(user)
+  oozie_conf = api.get_configuration()
+  return oozie_conf.get('oozie.email.smtp.host') != 'localhost'
+
 def _submit_workflow(user, fs, jt, workflow, mapping):
   try:
     submission = Submission(user, workflow, fs, jt, mapping)

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

@@ -1331,6 +1331,12 @@ def config_validator(user):
   # Validate MYSQL storage engine of all tables
   res.extend(validate_database())
 
+  # Validate if oozie email server is active
+  from oozie.views.editor2 import _is_oozie_mail_enabled
+
+  if not _is_oozie_mail_enabled(user):
+    res.append(('OOZIE_EMAIL_SERVER', unicode(_('Email notifications is disabled for Workflows and Jobs as SMTP server is localhost.'))))
+
   return res
 
 def get_redaction_policy():

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно