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

Fix credential pruning and start/stop log messages

This commit is contained in:
Nick O'Leary 2015-02-24 22:02:39 +00:00
parent fbb45a8961
commit f3880b7601
3 changed files with 29 additions and 48 deletions

View File

@ -301,7 +301,6 @@ Flow.prototype.start = function() {
if (this.missingTypes.length > 0) { if (this.missingTypes.length > 0) {
throw new Error("missing types"); throw new Error("missing types");
} }
events.emit("nodes-starting"); events.emit("nodes-starting");
for (var id in this.nodes) { for (var id in this.nodes) {
@ -435,7 +434,13 @@ Flow.prototype.applyConfig = function(config,type) {
} }
var flow = this; var flow = this;
if (type != "full") {
log.info("Stopping modified "+type);
}
return this.stop(activeNodesToStop).then(function() { return this.stop(activeNodesToStop).then(function() {
if (type != "full") {
log.info("Stopped modified "+type);
}
flow.parseConfig(config); flow.parseConfig(config);
for (var i=0;i<nodesToRewire.length;i++) { for (var i=0;i<nodesToRewire.length;i++) {
var node = flow.activeNodes[nodesToRewire[i]]; var node = flow.activeNodes[nodesToRewire[i]];
@ -443,7 +448,13 @@ Flow.prototype.applyConfig = function(config,type) {
node.updateWires(flow.allNodes[node.id].wires); node.updateWires(flow.allNodes[node.id].wires);
} }
} }
if (type != "full") {
log.info("Starting modified "+type);
}
flow.start(); flow.start();
if (type != "full") {
log.info("Started modified "+type);
}
}) })
} }

View File

@ -190,6 +190,7 @@ module.exports = {
} }
} }
credentialCache[nodeID] = savedCredentials; credentialCache[nodeID] = savedCredentials;
delete node.credentials;
} }
}, },

View File

@ -75,45 +75,6 @@ var flowNodes = module.exports = {
activeFlow.eachNode(cb); activeFlow.eachNode(cb);
}, },
/**
* Stops all active nodes and clears the active set
* @return a promise for the stopping of all active nodes
*/
//clear: function(nodesToStop) {
// var stopList;
// if (nodesToStop == null) {
// stopList = Object.keys(nodes);
// } else {
// stopList = Object.keys(nodesToStop);
// }
// console.log(stopList);
// return when.promise(function(resolve) {
// events.emit("nodes-stopping");
// var promises = [];
// console.log("running nodes:",Object.keys(nodes).length);
// for (var i=0;i<stopList.length;i++) {
// var node = nodes[stopList[i]];
// if (node) {
// try {
// var p = node.close();
// if (p) {
// promises.push(p);
// }
// } catch(err) {
// node.error(err);
// }
// delete nodes[stopList[i]];
// delete activeConfigNodes[stopList[i]];
// }
// }
// console.log("running nodes:",Object.keys(nodes).length);
// when.settle(promises).then(function() {
// events.emit("nodes-stopped");
// resolve();
// });
// });
//},
/** /**
* @return the active configuration * @return the active configuration
*/ */
@ -135,7 +96,12 @@ var flowNodes = module.exports = {
var credentialSavePromise = null; var credentialSavePromise = null;
config.forEach(function(node) {
// Clone config and extract credentials prior to saving
// Original config needs to retain credentials so that flow.applyConfig
// knows which nodes have had changes.
var cleanConfig = clone(config);
cleanConfig.forEach(function(node) {
if (node.credentials) { if (node.credentials) {
credentials.extract(node); credentials.extract(node);
credentialsChanged = true; credentialsChanged = true;
@ -148,22 +114,22 @@ var flowNodes = module.exports = {
credentialSavePromise = when.resolve(); credentialSavePromise = when.resolve();
} }
if (type=="full") { if (type=="full") {
return credentialSavePromise return credentialSavePromise
.then(function() { return storage.saveFlows(config);}) .then(function() { return storage.saveFlows(cleanConfig);})
.then(function() { return flowNodes.stopFlows(); }) .then(function() { return flowNodes.stopFlows(); })
.then(function() { activeFlow = new Flow(config); flowNodes.startFlows();}); .then(function() { activeFlow = new Flow(config); flowNodes.startFlows();});
} else { } else {
return credentialSavePromise return credentialSavePromise
.then(function() { return storage.saveFlows(config);}) .then(function() { return storage.saveFlows(cleanConfig);})
.then(function() { return activeFlow.applyConfig(config,type); }); .then(function() { return activeFlow.applyConfig(config,type); });
} }
}, },
startFlows: function() { startFlows: function() {
log.info("Starting flows"); log.info("Starting flows");
try { try {
activeFlow.start(); activeFlow.start();
log.info("Started flows");
} catch(err) { } catch(err) {
var missingTypes = activeFlow.getMissingTypes(); var missingTypes = activeFlow.getMissingTypes();
if (missingTypes.length > 0) { if (missingTypes.length > 0) {
@ -177,7 +143,10 @@ var flowNodes = module.exports = {
}, },
stopFlows: function() { stopFlows: function() {
log.info("Stopping flows"); log.info("Stopping flows");
return activeFlow.stop(); return activeFlow.stop().then(function() {
log.info("Stopped flows");
return;
});
} }
}; };