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) {
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) {
if (configDiff) {
for (var i=0;i<configDiff.rewire.length;i++) {
var node = flow.activeNodes[configDiff.rewire[i]];
if (node) {
node.updateWires(flow.allNodes[node.id].wires);
for (var j=0;j<configDiff.rewire.length;j++) {
var rewireNode = this.activeNodes[configDiff.rewire[j]];
if (rewireNode) {
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 nodesToRewire = [];
if (type && type!="full") {
var diff = this.diffFlow(config);
//console.log(diff);
var diff = diffFlow(this,config);
//var diff = {
// deleted:[]
// changed:[]
@ -523,8 +522,11 @@ Flow.prototype.applyConfig = function(config,type) {
}
}
Flow.prototype.diffFlow = function(config) {
var flow = this;
function diffFlow(flow,config) {
//if (!flow.started) {
// throw new Error("Cannot diff an unstarted flow");
//}
var flowNodes = {};
var changedNodes = {};
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") {
deletedNodes[node.id] = node;
}
buildNodeLinks(activeLinks,node,flow.allNodes);
});
this.config.forEach(function(node) {
flow.config.forEach(function(node) {
for (var prop in node) {
if (node.hasOwnProperty(prop) && prop != "z" && prop != "id" && prop != "wires") {
// This node has a property that references a changed node

View File

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

File diff suppressed because it is too large Load Diff