1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Partial deploy with missing type breaks flow diff

Another refactor of Flow lifecycle.
 - diffFlow made a private static function
 - applyConfig now diffConfig - which returns a diff object that
   can be passed to .stop/.start to be properly applied
This commit is contained in:
Nick O'Leary 2015-03-13 17:54:58 +00:00
parent af20f3df64
commit f77dd06e65
3 changed files with 844 additions and 370 deletions

View File

@ -160,7 +160,7 @@ function createSubflow(sf,sfn,subflows) {
if (!node._originalWires) { if (!node._originalWires) {
node._originalWires = clone(node.wires); node._originalWires = clone(node.wires);
} }
node.wires[wires[j].port] = node.wires[wires[j].port].concat(sfn.wires[i]); node.wires[wires[j].port] = (node.wires[wires[j].port]||[]).concat(sfn.wires[i]);
} }
} }
} }
@ -353,10 +353,10 @@ Flow.prototype.parseConfig = function(config) {
Flow.prototype.start = function(configDiff) { Flow.prototype.start = function(configDiff) {
if (configDiff) { if (configDiff) {
for (var i=0;i<configDiff.rewire.length;i++) { for (var j=0;j<configDiff.rewire.length;j++) {
var node = flow.activeNodes[configDiff.rewire[i]]; var rewireNode = this.activeNodes[configDiff.rewire[j]];
if (node) { if (rewireNode) {
node.updateWires(flow.allNodes[node.id].wires); rewireNode.updateWires(this.allNodes[rewireNode.id].wires);
} }
} }
} }
@ -479,14 +479,13 @@ Flow.prototype.eachNode = function(callback) {
} }
} }
Flow.prototype.applyConfig = function(config,type) { Flow.prototype.diffConfig = function(config,type) {
var activeNodesToStop = []; var activeNodesToStop = [];
var nodesToRewire = []; var nodesToRewire = [];
if (type && type!="full") { if (type && type!="full") {
var diff = this.diffFlow(config); var diff = diffFlow(this,config);
//console.log(diff);
//var diff = { //var diff = {
// deleted:[] // deleted:[]
// changed:[] // changed:[]
@ -523,8 +522,11 @@ Flow.prototype.applyConfig = function(config,type) {
} }
} }
Flow.prototype.diffFlow = function(config) { function diffFlow(flow,config) {
var flow = this;
//if (!flow.started) {
// throw new Error("Cannot diff an unstarted flow");
//}
var flowNodes = {}; var flowNodes = {};
var changedNodes = {}; var changedNodes = {};
var deletedNodes = {}; var deletedNodes = {};
@ -579,14 +581,14 @@ Flow.prototype.diffFlow = function(config) {
} }
}); });
this.config.forEach(function(node) { flow.config.forEach(function(node) {
if (!flowNodes[node.id] && node.type != "tab") { if (!flowNodes[node.id] && node.type != "tab") {
deletedNodes[node.id] = node; deletedNodes[node.id] = node;
} }
buildNodeLinks(activeLinks,node,flow.allNodes); buildNodeLinks(activeLinks,node,flow.allNodes);
}); });
this.config.forEach(function(node) { flow.config.forEach(function(node) {
for (var prop in node) { for (var prop in node) {
if (node.hasOwnProperty(prop) && prop != "z" && prop != "id" && prop != "wires") { if (node.hasOwnProperty(prop) && prop != "z" && prop != "id" && prop != "wires") {
// This node has a property that references a changed node // This node has a property that references a changed node

View File

@ -123,7 +123,7 @@ var flowNodes = module.exports = {
return credentialSavePromise return credentialSavePromise
.then(function() { return storage.saveFlows(cleanConfig);}) .then(function() { return storage.saveFlows(cleanConfig);})
.then(function() { .then(function() {
var configDiff = activeFlow.applyConfig(config,type); var configDiff = activeFlow.diffConfig(config,type);
return flowNodes.stopFlows(configDiff).then(function() { return flowNodes.stopFlows(configDiff).then(function() {
activeFlow.parseConfig(config); activeFlow.parseConfig(config);
flowNodes.startFlows(configDiff); flowNodes.startFlows(configDiff);

File diff suppressed because it is too large Load Diff