Partial deploy with missing node type breaks deploy

This commit is contained in:
Nick O'Leary 2015-03-13 13:15:20 +00:00
parent 4078212089
commit af20f3df64
2 changed files with 56 additions and 40 deletions

View File

@ -253,6 +253,7 @@ function Flow(config) {
this.activeNodes = {}; this.activeNodes = {};
this.subflowInstanceNodes = {}; this.subflowInstanceNodes = {};
this.catchNodeMap = {};
this.started = false; this.started = false;
this.parseConfig(config); this.parseConfig(config);
@ -273,8 +274,6 @@ Flow.prototype.parseConfig = function(config) {
this.configNodes = {}; this.configNodes = {};
this.catchNodeMap = null;
var unknownTypes = {}; var unknownTypes = {};
for (i=0;i<this.config.length;i++) { for (i=0;i<this.config.length;i++) {
@ -352,7 +351,16 @@ Flow.prototype.parseConfig = function(config) {
this.missingTypes = Object.keys(unknownTypes); this.missingTypes = Object.keys(unknownTypes);
} }
Flow.prototype.start = function() { 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);
}
}
}
this.started = true; this.started = true;
if (this.missingTypes.length > 0) { if (this.missingTypes.length > 0) {
throw new Error("missing types"); throw new Error("missing types");
@ -402,8 +410,14 @@ Flow.prototype.start = function() {
events.emit("nodes-started"); events.emit("nodes-started");
} }
Flow.prototype.stop = function(nodeList) { Flow.prototype.stop = function(configDiff) {
nodeList = nodeList || Object.keys(this.activeNodes); var nodeList;
if (configDiff) {
nodeList = configDiff.stop;
} else {
nodeList = Object.keys(this.activeNodes);
}
var flow = this; var flow = this;
return when.promise(function(resolve) { return when.promise(function(resolve) {
events.emit("nodes-stopping"); events.emit("nodes-stopping");
@ -481,15 +495,12 @@ Flow.prototype.applyConfig = function(config,type) {
//} //}
var nodesToStop = []; var nodesToStop = [];
var nodesToCreate = [];
nodesToRewire = diff.wiringChanged; nodesToRewire = diff.wiringChanged;
if (type == "nodes") { if (type == "nodes") {
nodesToStop = diff.deleted.concat(diff.changed); nodesToStop = diff.deleted.concat(diff.changed);
nodesToCreate = diff.changed;
} else if (type == "flows") { } else if (type == "flows") {
nodesToStop = diff.deleted.concat(diff.changed).concat(diff.linked); nodesToStop = diff.deleted.concat(diff.changed).concat(diff.linked);
nodesToCreate = diff.changed.concat(diff.linked);
} }
for (var i=0;i<nodesToStop.length;i++) { for (var i=0;i<nodesToStop.length;i++) {
@ -504,29 +515,12 @@ Flow.prototype.applyConfig = function(config,type) {
activeNodesToStop = Object.keys(this.activeNodes); activeNodesToStop = Object.keys(this.activeNodes);
} }
var flow = this; return {
if (type != "full") { type: type,
log.info("Stopping modified "+type); stop: activeNodesToStop,
rewire: nodesToRewire,
config: config
} }
return this.stop(activeNodesToStop).then(function() {
if (type != "full") {
log.info("Stopped modified "+type);
}
flow.parseConfig(config);
for (var i=0;i<nodesToRewire.length;i++) {
var node = flow.activeNodes[nodesToRewire[i]];
if (node) {
node.updateWires(flow.allNodes[node.id].wires);
}
}
if (type != "full") {
log.info("Starting modified "+type);
}
flow.start();
if (type != "full") {
log.info("Started modified "+type);
}
})
} }
Flow.prototype.diffFlow = function(config) { Flow.prototype.diffFlow = function(config) {

View File

@ -122,14 +122,28 @@ var flowNodes = module.exports = {
} else { } else {
return credentialSavePromise return credentialSavePromise
.then(function() { return storage.saveFlows(cleanConfig);}) .then(function() { return storage.saveFlows(cleanConfig);})
.then(function() { return activeFlow.applyConfig(config,type); }); .then(function() {
var configDiff = activeFlow.applyConfig(config,type);
return flowNodes.stopFlows(configDiff).then(function() {
activeFlow.parseConfig(config);
flowNodes.startFlows(configDiff);
});
});
} }
}, },
startFlows: function() { startFlows: function(configDiff) {
if (configDiff) {
log.info("Starting modified "+configDiff.type);
} else {
log.info("Starting flows"); log.info("Starting flows");
}
try { try {
activeFlow.start(); activeFlow.start(configDiff);
if (configDiff) {
log.info("Started modified "+configDiff.type);
} else {
log.info("Started flows"); log.info("Started flows");
}
} catch(err) { } catch(err) {
var missingTypes = activeFlow.getMissingTypes(); var missingTypes = activeFlow.getMissingTypes();
if (missingTypes.length > 0) { if (missingTypes.length > 0) {
@ -140,11 +154,19 @@ var flowNodes = module.exports = {
} }
} }
}, },
stopFlows: function() { stopFlows: function(configDiff) {
if (configDiff) {
log.info("Stopping modified "+configDiff.type);
} else {
log.info("Stopping flows"); log.info("Stopping flows");
}
if (activeFlow) { if (activeFlow) {
return activeFlow.stop().then(function() { return activeFlow.stop(configDiff).then(function() {
if (configDiff) {
log.info("Stopped modified "+configDiff.type);
} else {
log.info("Stopped flows"); log.info("Stopped flows");
}
return; return;
}); });
} else { } else {