Add dynamic node api

Closes #322
- nodes modules can be installed/removed dynamically at runtime
- nodes can be enabled/disabled
- onpaletteadd/onpaletteremove api added to node definitions
- initial implementation of nr-cli
This commit is contained in:
Nick O'Leary
2014-08-28 00:35:07 +01:00
parent 00cb8d5bce
commit da61fe12d0
24 changed files with 1540 additions and 381 deletions

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2013 IBM Corp.
* Copyright 2013, 2014 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
var when = require('when');
var storageModule;
var settingsAvailable;
function moduleSelector(aSettings) {
var toReturn;
@@ -38,48 +39,64 @@ function is_malicious(path) {
}
var storageModuleInterface = {
init : function(settings) {
init: function(settings) {
try {
storageModule = moduleSelector(settings);
settingsAvailable = storageModule.hasOwnProperty("getSettings") && storageModule.hasOwnProperty("saveSettings");
} catch (e) {
return when.reject(e);
}
return storageModule.init(settings);
},
getFlows : function() {
getFlows: function() {
return storageModule.getFlows();
},
saveFlows : function(flows) {
saveFlows: function(flows) {
return storageModule.saveFlows(flows);
},
getCredentials : function() {
getCredentials: function() {
return storageModule.getCredentials();
},
saveCredentials : function(credentials) {
saveCredentials: function(credentials) {
return storageModule.saveCredentials(credentials);
},
getAllFlows : function() {
getSettings: function() {
if (settingsAvailable) {
return storageModule.getSettings();
} else {
return when.resolve(null);
}
},
saveSettings: function(settings) {
if (settingsAvailable) {
return storageModule.saveSettings(settings);
} else {
return when.resolve();
}
},
/* Library Functions */
getAllFlows: function() {
return storageModule.getAllFlows();
},
getFlow : function(fn) {
getFlow: function(fn) {
if (is_malicious(fn)) {
return when.reject(new Error('forbidden flow name'));
}
return storageModule.getFlow(fn);
},
saveFlow : function(fn, data) {
saveFlow: function(fn, data) {
if (is_malicious(fn)) {
return when.reject(new Error('forbidden flow name'));
}
return storageModule.saveFlow(fn, data);
},
getLibraryEntry : function(type, path) {
getLibraryEntry: function(type, path) {
if (is_malicious(path)) {
return when.reject(new Error('forbidden flow name'));
}
return storageModule.getLibraryEntry(type, path);
},
saveLibraryEntry : function(type, path, meta, body) {
saveLibraryEntry: function(type, path, meta, body) {
if (is_malicious(path)) {
return when.reject(new Error('forbidden flow name'));
}

View File

@@ -33,6 +33,7 @@ var oldCredentialsFile;
var userDir;
var libDir;
var libFlowsDir;
var globalSettingsFile;
function listFiles(dir) {
var dirs = {};
@@ -140,6 +141,9 @@ var localfilesystem = {
libDir = fspath.join(userDir,"lib");
libFlowsDir = fspath.join(libDir,"flows");
globalSettingsFile = fspath.join(userDir,".config.json");
return promiseDir(libFlowsDir);
},
@@ -207,7 +211,20 @@ var localfilesystem = {
return nodeFn.call(fs.writeFile, credentialsFile, credentialData)
},
getSettings: function() {
if (fs.existsSync(globalSettingsFile)) {
return nodeFn.call(fs.readFile,globalSettingsFile,'utf8').then(function(data) {
return JSON.parse(data);
});
}
return when.resolve({});
},
saveSettings: function(settings) {
return nodeFn.call(fs.writeFile,globalSettingsFile,JSON.stringify(settings),'utf8');
},
getAllFlows: function() {
return listFiles(libFlowsDir);
},