Skip to content
Browse files

Widespread changes to file structure to allow the GPII infrastructure…

… and libraries to be loaded blind as node modules without explicit file paths. This relies on updates to the Fluid framework and module loader under FLUID-4609. Improvements to debugging by raising node stack trace limits. Minor improvements to gpii.dataSource "hierarchy" with identification of separate file and URL modules. Behaviour of demo servers should be unchanged.
  • Loading branch information...
1 parent 417db3c commit 7b8be98c517b5d1cb3357350c552ffefce18d35b @amb26 amb26 committed
Showing with 159 additions and 109 deletions.
  1. +11 −0 .project
  2. 0 { → gpii/node_modules}/flowManager/README.md
  3. 0 { → gpii/node_modules}/flowManager/config.development.json
  4. 0 { → gpii/node_modules}/flowManager/config.production.json
  5. 0 flowManager/test/data/transformer.payload.example.json → gpii/node_modules/flowManager/snapshot.json
  6. +21 −48 { → gpii/node_modules}/flowManager/src/FlowManager.js
  7. 0 { → gpii/node_modules}/flowManager/test/data/device.reporter.payload.example.json
  8. 0 { → gpii/node_modules}/flowManager/test/data/launchmanager.payload.example.json
  9. 0 { → gpii/node_modules}/flowManager/test/data/matchmaker.payload.example.json
  10. +1 −0 gpii/node_modules/flowManager/test/data/transformer.payload.example.json
  11. 0 { → gpii/node_modules}/flowManager/test/data/user.profile.payload.example.json
  12. 0 {shared → gpii/node_modules/gpii-framework}/README.md
  13. +19 −10 {shared → gpii/node_modules/gpii-framework}/dataSource.js
  14. +7 −0 gpii/node_modules/gpii-framework/framework.js
  15. +19 −0 gpii/node_modules/gpii-framework/package.json
  16. +3 −3 {shared → gpii/node_modules/gpii-framework}/source.js
  17. +53 −0 gpii/node_modules/gpii-framework/utils.js
  18. 0 { → gpii/node_modules}/preferencesServer/README.md
  19. +5 −12 { → gpii/node_modules}/preferencesServer/src/preferencesServer.js
  20. 0 { → gpii/node_modules}/preferencesServer/test/data/user/123.json
  21. +6 −2 node_modules/infusion/src/webapp/framework/core/js/Fluid.js
  22. +14 −2 node_modules/infusion/src/webapp/module/fluid.js
  23. +0 −32 shared/utils.js
View
11 .project
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>gpii-universal</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ </buildSpec>
+ <natures>
+ </natures>
+</projectDescription>
View
0 flowManager/README.md → gpii/node_modules/flowManager/README.md
File renamed without changes.
View
0 flowManager/config.development.json → ...dules/flowManager/config.development.json
File renamed without changes.
View
0 flowManager/config.production.json → ...odules/flowManager/config.production.json
File renamed without changes.
View
0 ...est/data/transformer.payload.example.json → gpii/node_modules/flowManager/snapshot.json
File renamed without changes.
View
69 flowManager/src/FlowManager.js → ...de_modules/flowManager/src/FlowManager.js
@@ -1,13 +1,15 @@
(function () {
"use strict";
-
+
var express = require("express"),
fluid = require("infusion"),
fs = require("fs"),
path = require("path"),
- querystring = require("querystring"),
- gpii = fluid.registerNamespace("gpii");
+ querystring = require("querystring");
+
+
+ var gpii = fluid.registerNamespace("gpii");
var findArgv = function (key) {
return fluid.find(process.argv, function (arg) {
@@ -17,16 +19,7 @@
});
};
- fluid.require("../../../../../shared/dataSource.js");
-
- process.on("uncaughtException", function (err) {
- console.log("Uncaught Exception: " + err);
- process.exit(1);
- });
-
- process.on("SIGTERM", function () {
- process.exit(0);
- });
+ fluid.require("gpii-framework", require);
fluid.defaults("gpii.flowManager", {
gradeNames: ["fluid.eventedComponent", "autoInit"],
@@ -36,17 +29,22 @@
userPreferencesDataSource: {
type: "gpii.dataSource",
options: {
+ url: "{gpii.flowManager}.config.userPreferences.url",
termMap: {
token: "%token"
}
}
},
deviceReporterDataSource: {
- type: "gpii.dataSource"
+ type: "gpii.dataSource",
+ options: {
+ url: "{gpii.flowManager}.config.deviceReporter.url"
+ }
},
matchMakerDataSource: {
type: "gpii.dataSource",
options: {
+ url: "{gpii.flowManager}.config.matchMaker.url",
termMap: {
query: "%query"
}
@@ -55,6 +53,7 @@
transformerDataSource: {
type: "gpii.dataSource",
options: {
+ url: "{gpii.flowManager}.config.transformer.url",
termMap: {
query: "%query"
}
@@ -63,6 +62,7 @@
launchManagerDataSource: {
type: "gpii.dataSource",
options: {
+ url: "{gpii.flowManager}.config.launchManager.url",
termMap: {
query: "%query"
}
@@ -71,6 +71,7 @@
snapshotDataSource: {
type: "gpii.dataSource",
options: {
+ url: "{gpii.flowManager}.config.snapshot.url",
writable: true
}
}
@@ -220,42 +221,14 @@
}
});
- fluid.demands("userPreferencesDataSource", "gpii.flowManager", {
- options: {
- url: "{gpii.flowManager}.config.userPreferences.url"
- }
- });
-
- fluid.demands("deviceReporterDataSource", "gpii.flowManager", {
- options: {
- url: "{gpii.flowManager}.config.deviceReporter.url"
- }
- });
-
- fluid.demands("matchMakerDataSource", "gpii.flowManager", {
- options: {
- url: "{gpii.flowManager}.config.matchMaker.url"
- }
+ fluid.demands("gpii.dataSource", ["gpii.flowManager", "gpii.production"], {
+ funcName: "gpii.dataSource.URL"
});
-
- fluid.demands("transformerDataSource", "gpii.flowManager", {
- options: {
- url: "{gpii.flowManager}.config.transformer.url"
- }
+
+ fluid.demands("gpii.dataSource", ["gpii.flowManager", "gpii.development"], {
+ funcName: "gpii.dataSource.file"
});
-
- fluid.demands("launchManagerDataSource", "gpii.flowManager", {
- options: {
- url: "{gpii.flowManager}.config.launchManager.url"
- }
- });
-
- fluid.demands("snapshotDataSource", "gpii.flowManager", {
- options: {
- url: "{gpii.flowManager}.config.snapshot.url"
- }
- });
-
+
gpii.flowManager();
})();
View
0 ...data/device.reporter.payload.example.json → ...data/device.reporter.payload.example.json
File renamed without changes.
View
0 ...t/data/launchmanager.payload.example.json → ...t/data/launchmanager.payload.example.json
File renamed without changes.
View
0 ...test/data/matchmaker.payload.example.json → ...test/data/matchmaker.payload.example.json
File renamed without changes.
View
1 gpii/node_modules/flowManager/test/data/transformer.payload.example.json
@@ -0,0 +1 @@
+{}
View
0 ...st/data/user.profile.payload.example.json → ...st/data/user.profile.payload.example.json
File renamed without changes.
View
0 shared/README.md → gpii/node_modules/gpii-framework/README.md
File renamed without changes.
View
29 shared/dataSource.js → ...node_modules/gpii-framework/dataSource.js
@@ -9,8 +9,6 @@
path = require("path"),
url = require("url"),
eUC = "encodeURIComponent:";
-
- fluid.require("../../../../../shared/utils.js");
fluid.defaults("gpii.dataSource", {
gradeNames: ["autoInit", "fluid.littleComponent"],
@@ -23,19 +21,31 @@
get: "gpii.dataSource.get",
resolveUrl: "gpii.dataSource.resolveUrl"
},
- url: "",
+ nickName: "dataSource", // framework bug FLUID-4636 - this is not resolved
termMap: {},
writable: false,
preInitFunction: "gpii.dataSource.preInit"
});
+
+ fluid.defaults("gpii.dataSource.URL", {
+ gradeNames: ["gpii.dataSource", "autoInit"]
+ });
+
+ // TODO - just abolish file dataSource and let URL dataSource deal with
+ // file:// protocol
+ fluid.defaults("gpii.dataSource.file", {
+ gradeNames: ["gpii.dataSource", "autoInit"]
+ });
+
gpii.dataSource.preInit = function (that) {
+ that.nickName = "dataSource"; // work around FLUID-4636
if (that.options.writable) {
that.options.invokers.set = "gpii.dataSource.set";
}
};
- fluid.demands("gpii.dataSource.get", "gpii.development", {
+ fluid.demands("gpii.dataSource.get", "gpii.dataSource.file", {
funcName: "gpii.dataSource.FSGet",
args: [
"{dataSource}.options.responseParser",
@@ -45,7 +55,7 @@
]
});
- fluid.demands("gpii.dataSource.set", "gpii.development", {
+ fluid.demands("gpii.dataSource.set", "gpii.dataSource.file", {
funcName: "gpii.dataSource.FSSet",
args: [
"{dataSource}.options.responseParser",
@@ -56,7 +66,7 @@
]
});
- fluid.demands("gpii.dataSource.get", "gpii.production", {
+ fluid.demands("gpii.dataSource.get", "gpii.dataSource.URL", {
funcName: "gpii.dataSource.DBGet",
args: [
"{dataSource}.options.responseParser",
@@ -66,7 +76,7 @@
]
});
- fluid.demands("gpii.dataSource.set", "gpii.production", {
+ fluid.demands("gpii.dataSource.set", "gpii.dataSource.URL", {
funcName: "gpii.dataSource.DBSet",
args: [
"{dataSource}.options.responseParser",
@@ -77,8 +87,7 @@
]
});
- fluid.demands("gpii.dataSource.resolveUrl", "gpii.dataSource", {
- funcName: "gpii.dataSource.resolveUrl",
+ fluid.demands("gpii.dataSource.resolveUrl", null, {
args: [
"{urlExpander}.expand",
"{dataSource}.options.url",
@@ -102,7 +111,7 @@
urlObj = url.parse(path, true);
var req = http.request({
host: urlObj.hostname,
- port: praseInt(urlObj.port, 10),
+ port: parseInt(urlObj.port, 10),
path: urlObj.pathname,
method: method
}, function (res) {
View
7 gpii/node_modules/gpii-framework/framework.js
@@ -0,0 +1,7 @@
+var fluid = require("infusion");
+
+var loader = fluid.getLoader(__dirname);
+
+loader.require("./dataSource.js");
+loader.require("./utils.js");
+loader.require("./source.js");
View
19 gpii/node_modules/gpii-framework/package.json
@@ -0,0 +1,19 @@
+{
+ "name": "gpii-framework",
+ "description": "Utilities and definitions useful across the GPII architecture",
+ "version": "0.1",
+ "author": "GPII",
+ "bugs": "http://issues.fluidproject.org/browse/FLUID",
+ "homepage": "http://gpii.net/",
+ "dependencies": {},
+ "licenses": [
+ {
+ "type": "BSD-3-Clause",
+ "url": "http://www.opensource.org/licenses/BSD-3-Clause"
+ }
+ ],
+ "keywords": ["infusion", "framework", "application", "fluid", "IoC", "Inversion of Control", "MVC", "evented"],
+ "repository": "git://github.com/GPII/universal.git",
+ "main": "./framework.js",
+ "engines": { "node" : ">=0.1.9" }
+}
View
6 shared/source.js → gpii/node_modules/gpii-framework/source.js
@@ -6,9 +6,6 @@
uuid = require("node-uuid"),
gpii = fluid.registerNamespace("gpii");
- fluid.require("../../../../../shared/dataSource.js");
- fluid.require("../../../../../shared/utils.js");
-
fluid.defaults("gpii.source", {
gradeNames: ["autoInit", "fluid.littleComponent"],
mergePolicy: {
@@ -37,6 +34,8 @@
if (that.options.writable) {
that.options.invokers.post = "gpii.source.post";
}
+ console.log("Constructed source with path " + that.options.path + " and termmap",
+ that.options.termMap);
that.options.termMap = gpii.pathToTermMap(that.options.path);
that.server = that.options.server;
};
@@ -62,6 +61,7 @@
};
gpii.source.get = function (dataSource, req, res) {
+ console.log("Get with directModel of ", req.directModel);
dataSource.get(req.directModel, gpii.source.makeCallback(res));
};
View
53 gpii/node_modules/gpii-framework/utils.js
@@ -0,0 +1,53 @@
+(function () {
+
+ "use strict";
+
+ var fluid = require("infusion");
+ var path = require("path");
+ var os = require("os");
+
+ var gpii = fluid.registerNamespace("gpii");
+
+ // Debugging definition - node.js's default is only 10!
+ fluid.Error.stackTraceLimit = 100;
+
+ // There seems to be no other way to determine whether signals are supported
+ // than direct OS detection. Signals are current completley unsupported on
+ // Windows - https://github.com/joyent/node/issues/1553
+ // The purpose of this code is to avoid hung or detached processes if node
+ // is "killed" with CTRL-C etc.
+ if (os.type().indexOf("Windows") === -1) {
+ console.log(typeof(process.on));
+
+ process.on("SIGTERM", function () {
+ process.exit(0);
+ });
+ }
+
+
+ gpii.pathToTermMap = function (path) {
+ var termMap = {};
+ fluid.each(path.match(/(:\w+)?/gi), function (param) {
+ if (!param) {
+ return;
+ }
+ param = param.substr(1);
+ termMap[param] = "%" + param;
+ });
+ return termMap;
+ };
+
+ fluid.defaults("gpii.urlExpander", {
+ gradeNames: ["fluid.littleComponent", "autoInit"],
+ finalInitFunction: "gpii.urlExpander.finalInit"
+ });
+
+ gpii.urlExpander.finalInit = function (that) {
+ console.log("urlExpander constructed with vars ", that.options.vars);
+ that.expand = function (url) {
+ console.log("urlExpander expanding url " + url);
+ return fluid.stringTemplate(url, that.options.vars);
+ };
+ };
+
+})();
View
0 preferencesServer/README.md → .../node_modules/preferencesServer/README.md
File renamed without changes.
View
17 preferencesServer/src/preferencesServer.js → ...referencesServer/src/preferencesServer.js
@@ -15,16 +15,7 @@
});
};
- fluid.require("../../../../../shared/source.js");
-
- process.on("uncaughtException", function (err) {
- console.log("Uncaught Exception: " + err);
- process.exit(1);
- });
-
- process.on("SIGTERM", function () {
- process.exit(0);
- });
+ fluid.require("gpii-framework", require);
fluid.defaults("gpii.preferencesServer", {
gradeNames: ["fluid.littleComponent", "autoInit"],
@@ -65,7 +56,7 @@
that.server.listen(typeof port === "string" ? parseInt(port, 10) : port);
};
- fluid.demands("gpii.urlExpander", ["gpii.development", "gpii.flowManager"], {
+ fluid.demands("gpii.urlExpander", ["gpii.development", "gpii.preferencesServer"], {
options: {
vars: {
db: path.join(__dirname, ".."),
@@ -75,14 +66,16 @@
});
fluid.demands("gpii.dataSource", ["gpii.development", "gpii.preferencesServer"], {
+ funcName: "gpii.dataSource.file",
options: {
url: "%db/test/data/user/%token.json"
}
});
fluid.demands("gpii.dataSource", ["gpii.production", "gpii.preferencesServer"], {
+ funcName: "gpii.dataSource.URL",
options: {
- url: "0.0.0.0:5984/%db/user/%token"
+ url: "http://localhost:5984/%db/user/%token"
}
});
View
0 preferencesServer/test/data/user/123.json → ...preferencesServer/test/data/user/123.json
File renamed without changes.
View
8 node_modules/infusion/src/webapp/framework/core/js/Fluid.js
@@ -34,9 +34,13 @@ var fluid_1_5 = fluid_1_5 || {};
var fluid = fluid || fluid_1_5;
(function ($, fluid) {
-
+
fluid.version = "Infusion 1.5";
+ // Export this for use in environments like node.js, where it is useful for
+ // configuring stack trace behaviour
+ fluid.Error = Error;
+
fluid.environment = {
fluid: fluid
};
@@ -639,7 +643,7 @@ var fluid = fluid || fluid_1_5;
*/
fluid.invokeGlobalFunction = function (functionPath, args, environment) {
var func = fluid.getGlobalValue(functionPath, environment);
- if (!func) {
+ if (!func || !func.apply) {
fluid.fail("Error invoking global function: " + functionPath + " could not be located");
} else {
return func.apply(null, args);
View
16 node_modules/infusion/src/webapp/module/fluid.js
@@ -48,12 +48,24 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
var fluid = context.fluid;
- fluid.require = function (moduleName, namespace) {
+ fluid.require = function (moduleName, foreignRequire, namespace) {
+ foreignRequire = foreignRequire || require;
namespace = namespace || moduleName;
- var module = require(moduleName);
+ var module = foreignRequire(moduleName);
fluid.set(context, namespace, module);
return module;
};
+
+ fluid.getLoader = function (dirName, foreignRequire) {
+ return {
+ require: function (moduleName, namespace) {
+ if (moduleName.indexOf("/") > -1) {
+ moduleName = dirName + "/" + moduleName;
+ }
+ return fluid.require(moduleName, foreignRequire, namespace);
+ }
+ }
+ };
module.exports = fluid;
View
32 shared/utils.js
@@ -1,32 +0,0 @@
-(function () {
-
- "use strict";
-
- var fluid = require("infusion"),
- path = require("path"),
- gpii = fluid.registerNamespace("gpii");
-
- gpii.pathToTermMap = function (path) {
- var termMap = {};
- fluid.each(path.match(/(:\w+)?/gi), function (param) {
- if (!param) {
- return;
- }
- param = param.substr(1);
- termMap[param] = "%" + param;
- });
- return termMap;
- };
-
- fluid.defaults("gpii.urlExpander", {
- gradeNames: ["fluid.littleComponent", "autoInit"],
- finalInitFunction: "gpii.urlExpander.finalInit"
- });
-
- gpii.urlExpander.finalInit = function (that) {
- that.expand = function (url) {
- return fluid.stringTemplate(url, that.options.vars);
- };
- };
-
-})();

0 comments on commit 7b8be98

Please sign in to comment.
Something went wrong with that request. Please try again.