소스 검색

[oozie] Add specific error message when Oozie is not running

Same for JobSub.
Adding a test.
No test for JobSub as we have HUE-896.
Cleaning trailing spaces and prints.
Romain Rigaux 13 년 전
부모
커밋
ec9c8ca33e

+ 4 - 2
apps/jobsub/src/jobsub/views.py

@@ -275,8 +275,10 @@ def submit_design(request, design_id):
     submission = submit.Submission(design_obj, request.fs)
     jobid = submission.run()
   except RestException, ex:
-    raise PopupException(_("Error submitting design %(id)s") % {'id': design_id},
-                         detail=ex.message)
+    detail = ex.message
+    if 'urlopen error' in ex.message:
+      detail = '%s: %s' % (_('The Oozie server is not running'), detail)
+    raise PopupException(_("Error submitting design %(id)s") % {'id': design_id}, detail=detail)
   # Save the submission record
   job_record = models.JobHistory(owner=request.user,
                                  job_id=jobid,

+ 8 - 8
apps/oozie/src/oozie/migrations/0009_auto__add_decision.py

@@ -5,22 +5,22 @@ from south.v2 import SchemaMigration
 from django.db import models
 
 class Migration(SchemaMigration):
-    
+
     def forwards(self, orm):
-        
+
         # Adding model 'Decision'
         db.create_table('oozie_decision', (
             ('node_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['oozie.Node'], unique=True, primary_key=True)),
         ))
         db.send_create_signal('oozie', ['Decision'])
-    
-    
+
+
     def backwards(self, orm):
-        
+
         # Deleting model 'Decision'
         db.delete_table('oozie_decision')
-    
-    
+
+
     models = {
         'auth.group': {
             'Meta': {'object_name': 'Group'},
@@ -266,5 +266,5 @@ class Migration(SchemaMigration):
             'start': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'start_workflow'", 'blank': 'True', 'null': 'True', 'to': "orm['oozie.Start']"})
         }
     }
-    
+
     complete_apps = ['oozie']

+ 1 - 1
apps/oozie/src/oozie/templates/editor/action_utils.mako

@@ -186,7 +186,7 @@
 
     </form>
   </div>
-% if template: 
+% if template:
   </script>
 % endif
 </%def>

+ 1 - 1
apps/oozie/src/oozie/templates/editor/control_utils.mako

@@ -148,7 +148,7 @@
     </form>
   </div>
 
-% if template: 
+% if template:
   </script>
 % endif
 </%def>

+ 16 - 1
apps/oozie/src/oozie/tests.py

@@ -14,11 +14,11 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
 try:
   import json
 except ImportError:
   import simplejson as json
-import copy
 import logging
 import re
 
@@ -32,6 +32,7 @@ from desktop.lib.test_utils import grant_access, add_permission
 from jobsub.management.commands import jobsub_setup
 from jobsub.models import OozieDesign
 from liboozie import oozie_api
+from liboozie.conf import OOZIE_URL
 from liboozie.oozie_api_test import OozieServerProvider
 from liboozie.types import WorkflowList, Workflow as OozieWorkflow, Coordinator as OozieCoordinator,\
   CoordinatorList, WorkflowAction
@@ -1115,6 +1116,20 @@ class TestOozieSubmissions(OozieBase):
     assert_equal('SUCCEEDED', job.status)
 
 
+class TestDashboardNoMocking:
+
+  def test_oozie_not_running_message(self):
+    c = make_logged_in_client(is_superuser=False)
+    grant_access("test", "test", "oozie")
+
+    finish = OOZIE_URL.set_for_testing('http://not_localhost:11000/bad')
+    try:
+      response = c.get(reverse('oozie:list_oozie_workflows'))
+      assert_true('The Oozie server is not running' in response.content, response.content)
+    finally:
+      finish()
+
+
 class TestDashboard(OozieMockBase):
 
   def test_manage_workflow_dashboard(self):

+ 1 - 1
apps/oozie/src/oozie/utils.py

@@ -38,7 +38,7 @@ def workflow_to_dict(workflow):
 
   for index, node in enumerate(node_list):
     nodes[index]['child_links'] = [model_to_dict(link) for link in node.get_all_children_links()]
-  
+
   workflow_dict['nodes'] = nodes
 
   return workflow_dict

+ 3 - 3
apps/oozie/src/oozie/views/api.py

@@ -137,7 +137,7 @@ def update_workflow_nodes(workflow, json_nodes, id_map):
             setattr(node, key, json.dumps(json_node[key]))
         else:
           setattr(node, key, json_node[key])
-    
+
     node.workflow = workflow
     node.save()
 
@@ -176,7 +176,7 @@ def workflow_save(request, workflow):
   for json_node in json_nodes:
     child_links = json_node['child_links']
     Link.objects.filter(parent=nodes[index]).delete()
-    
+
     for child_link in child_links:
       link = Link()
       link.id = getattr(child_link, 'id', None)
@@ -209,7 +209,7 @@ def _workflow(request, workflow):
 
   for index in range(0, len(node_list)):
     nodes[index]['child_links'] = [model_to_dict(link) for link in node_list[index].get_all_children_links()]
-  
+
   workflow_dict['nodes'] = nodes
 
   response['status'] = 0

+ 4 - 1
apps/oozie/src/oozie/views/dashboard.py

@@ -77,7 +77,10 @@ def show_oozie_error(view_func):
     try:
       return view_func(request, *args, **kwargs)
     except RestException, ex:
-      raise PopupException(_('Sorry, an error with Oozie happened.'), detail=ex._headers.get('oozie-error-message', ex))
+      detail = ex._headers.get('oozie-error-message', ex)
+      if 'urlopen error' in str(detail):
+        detail = '%s: %s' % (_('The Oozie server is not running'), detail)
+      raise PopupException(_('Sorry, an error with Oozie happened.'), detail=detail)
   return wraps(view_func)(decorate)
 
 

+ 4 - 2
apps/oozie/src/oozie/views/editor.py

@@ -193,8 +193,10 @@ def _submit_workflow(request, workflow, mapping):
     History.objects.create_from_submission(submission)
     return job_id
   except RestException, ex:
-    raise PopupException(_("Error submitting workflow %s") % (workflow,),
-                         detail=ex._headers.get('oozie-error-message', ex))
+    detail = ex._headers.get('oozie-error-message', ex)
+    if 'urlopen error' in str(detail):
+      detail = '%s: %s' % (_('The Oozie server is not running'), detail)
+    raise PopupException(_("Error submitting workflow %s") % (workflow,), detail=detail)
 
   request.info(_('Workflow submitted'))
   return redirect(reverse('oozie:list_oozie_workflow', kwargs={'job_id': job_id}))

+ 5 - 4
desktop/libs/liboozie/src/liboozie/oozie_api_test.py

@@ -31,7 +31,6 @@ from liboozie.oozie_api import get_oozie
 from liboozie.conf import OOZIE_URL
 
 
-_oozie_running = False
 _oozie_lock = threading.Lock()
 
 LOG = logging.getLogger(__name__)
@@ -45,6 +44,7 @@ class OozieServerProvider(object):
   OOZIE_HOME = get_run_root('ext/oozie/oozie')
 
   requires_hadoop = True
+  is_oozie_running = False
 
   @classmethod
   def setup_class(cls):
@@ -109,11 +109,11 @@ class OozieServerProvider(object):
 
   @classmethod
   def _get_shared_oozie_server(cls):
-    global _oozie_running
     callback = lambda: None
 
     _oozie_lock.acquire()
-    if not _oozie_running:
+
+    if not OozieServerProvider.is_oozie_running:
       LOG.info('\nStarting a Mini Oozie. Requires "tools/jenkins/jenkins.sh" to be previously ran.\n')
       LOG.info('See https://issues.cloudera.org/browse/HUE-861\n')
 
@@ -156,7 +156,8 @@ class OozieServerProvider(object):
       if not started:
         raise Exception("Oozie server took too long to come up.")
 
-      _oozie_running = True
+      OozieServerProvider.is_oozie_running = True
+
       def shutdown():
         for f in finish:
           f()