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

HUE-5010 [oozie] Automatically refresh workflow parameters in a coordinator

Try to reuse older variables, so that we don't lose them in case of simple
renames.
Romain Rigaux 9 жил өмнө
parent
commit
9713b2f

+ 16 - 7
apps/oozie/src/oozie/static/oozie/js/coordinator-editor.ko.js

@@ -102,19 +102,27 @@ var Coordinator = function (vm, coordinator) {
       self.workflowParameters(data.parameters);
 
       // Remove Uncommon params
-      prev_variables = self.variables.slice();
+      var prev_variables = self.variables.slice();
+      var removed_variables = [];
       $.each(prev_variables, function (index, variable) {
-        if (data.parameters.filter(function(param) { return param['name'] == variable.workflow_variable() }).length == 0) {
+        if (data.parameters.filter(function(param) { return param['name'] == variable.workflow_variable(); }).length == 0) {
           self.variables.remove(variable);
+          removed_variables.push(variable);
         }
       });
 
-      // Append the new variables
+      // Append the new variables, reuse past variables in case of rename
       prev_variables = self.variables.slice();
       $.each(data.parameters, function (index, param) {
-        if (prev_variables.filter(function(variable) { return param['name'] == variable.workflow_variable() }).length == 0) {
-          self.addVariable();
-          self.variables()[self.variables().length - 1].workflow_variable(param['name']);
+        if (prev_variables.filter(function(variable) { return param['name'] == variable.workflow_variable(); }).length == 0) {
+          var newVar;
+          if (removed_variables.length > 0) {
+            newVar = removed_variables.shift();
+            self.variables.push(newVar);
+          } else {
+            newVar = self.addVariable();
+          }
+          newVar.workflow_variable(param['name']);
         }
       });
     }).fail(function (xhr, textStatus, errorThrown) {
@@ -171,6 +179,7 @@ var Coordinator = function (vm, coordinator) {
       }
     }
     self.variables.push(_koVar);
+    return _koVar;
   };
 }
 
@@ -239,7 +248,7 @@ var CoordinatorEditorViewModel = function (coordinator_json, credentials_json, w
             cb(data);
           }
           else {
-        	  $(document).trigger("info", data.message);
+            $(document).trigger("info", data.message);
           }
           if (window.location.search.indexOf("coordinator") == -1) {
             window.location.hash = '#coordinator=' + data.id;

+ 1 - 0
apps/oozie/src/oozie/templates/editor2/coordinator_editor.mako

@@ -148,6 +148,7 @@ ${ scheduler.import_sla_cron(coordinator_json) }
 
   viewModel.coordinator.properties.cron_advanced.valueHasMutated(); // Update jsCron enabled status
   viewModel.coordinator.tracker().markCurrentStateAsClean();
+  viewModel.coordinator.refreshParameters();
 
 
   var shareViewModel = initSharing("#documentShareModal");