浏览代码

[sqoop] Fix connection error handling

Abraham Elmahrek 12 年之前
父节点
当前提交
0b15066
共有 3 个文件被更改,包括 24 次插入3 次删除
  1. 2 1
      apps/sqoop/src/sqoop/api/exception.py
  2. 16 0
      apps/sqoop/src/sqoop/templates/app.mako
  3. 6 2
      apps/sqoop/static/js/sqoop.js

+ 2 - 1
apps/sqoop/src/sqoop/api/exception.py

@@ -40,5 +40,6 @@ def handle_rest_exception(e, msg):
     LOG.error(smart_str(e.message))
     return {
       'status': 1,
-      'errors': [msg]
+      'errors': [msg],
+      'exception': str(e)
     }

+ 16 - 0
apps/sqoop/src/sqoop/templates/app.mako

@@ -330,6 +330,8 @@ ${ commonheader(None, "sqoop", user) | n,unicode }
 
 <script type="text/html" id="job-editor-begin">
 <fieldset>
+  <div data-bind="template: {'name': 'job-editor-form-error', 'data': {'name': ko.observable('connection')}}" class=""></div>
+
   <div class="control-group">
     <label class="control-label">${ _('Name') }</label>
     <div class="controls">
@@ -714,6 +716,19 @@ function handle_form_errors(e, node, options, data) {
   }
 }
 
+function connection_missing_error(e, node) {
+  // Resets save and run btns
+  reset_save_buttons();
+  viewModel.errors({
+    'connection': [{
+      'status': 'UNACCEPTABLE',
+      'message': '${_("Please specify a connection.")}'
+    }]
+  });
+  viewModel.warnings({});
+  routie('job/edit/wizard/job-editor-begin');
+}
+
 $(document).on('connection_error.jobs', function(e, name, options, jqXHR) {
   $('#sqoop-error .message').text("${ _('Cannot connect to sqoop server.') }");
   routie('error');
@@ -744,6 +759,7 @@ $(document).one('load_fail.job', function() {
 });
 
 $(document).on('save_fail.job', handle_form_errors);
+$(document).on('connection_missing.job', connection_missing_error);
 $(document).on('save_fail.connection', handle_form_errors);
 $(document).on('delete_fail.job', handle_form_errors);
 

+ 6 - 2
apps/sqoop/static/js/sqoop.js

@@ -306,8 +306,12 @@ var viewModel = new (function() {
   self.saveJob = function() {
     var job = self.job();
     if (job) {
-      job.connector_id(self.connector().id());
-      job.connection_id(self.connection().id());
+      if (!self.connection()) {
+        $(document).trigger('connection_missing.job', [self, null, {}]);
+        return;
+      }
+      job.connector_id((self.connector()) ? self.connector().id() : null);
+      job.connection_id((self.connection()) ? self.connection().id() : null);
       job.save();
     }
   };