diff --git a/.gitignore b/.gitignore index b5811ac..de08a67 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,5 @@ *.log *credentials.json *node_modules -doc .project .settings \ No newline at end of file diff --git a/coffee/http_listener.coffee b/coffee/http-listener.coffee similarity index 74% rename from coffee/http_listener.coffee rename to coffee/http-listener.coffee index f0c4418..10eb39a 100644 --- a/coffee/http_listener.coffee +++ b/coffee/http-listener.coffee @@ -2,9 +2,9 @@ HTTP Listener ============= -> Receives the HTTP requests to the server at the port specified by the -> [config](config.html) file. These requests (bound to a method) are then -> redirected to the appropriate handler which then takes care of the request. +> Receives the HTTP requests to the server at the given port. The requests +> (bound to a method) are then redirected to the appropriate handler which +> takes care of the request. ### @@ -13,12 +13,8 @@ HTTP Listener # - [Logging](logging.html) log = require './logging' -# - [Config](config.html) -config = require './config' -# TODO remove config - -# - [User Handler](user_handler.html) -requestHandler = require './request_handler' +# - [Request Handler](request-handler.html) +requestHandler = require './request-handler' # - Node.js Modules: [path](http://nodejs.org/api/path.html) and # [querystring](http://nodejs.org/api/querystring.html) @@ -34,33 +30,29 @@ app = express() ### Module call ----------- -Initializes the HTTP Listener and its child modules Logging, -Configuration and Request Handler, then tries to fetch the session -key from the configuration. +Initializes the HTTP listener and its request handler. @param {Object} args ### exports = module.exports = ( args ) -> args = args ? {} log args - config args requestHandler args + initRouting args[ 'http-port' ] module.exports ### -Adds the shutdown handler to the admin commands. +Initializes the request routing and starts listening on the given port. -@param {function} fshutDown -@public addHandlers( *fShutDown* ) +@param {int} port +@private initRouting( *fShutDown* ) ### -exports.addHandlers = ( fShutDown ) -> - requestHandler.addShutdownHandler fShutDown +initRouting = ( port ) -> # Add cookie support for session handling. app.use express.cookieParser() - #TODO This needs to be fixed! + #TODO The session secret appriach needs to be fixed! sess_sec = "149u*y8C:@kmN/520Gt\\v'+KFBnQ!\\r<>5X/xRI`sT # - **`POST` to _"/user"_:** User requests are possible for all users with an account app.post '/usercommand', requestHandler.handleUserCommand try - http_port = config.getHttpPort() - if http_port - app.listen http_port # inbound event channel - else - log.error 'HL', new Error 'No HTTP port found!? Nothing to listen on!...' + app.listen port # inbound event channel catch e e.addInfo = 'opening port' log.error e +### +Adds the shutdown handler to the admin commands. + +@param {function} fshutDown +@public addShutdownHandler( *fShutDown* ) +### +exports.addShutdownHandler = ( fShutDown ) -> + requestHandler.addShutdownHandler fShutDown + ### Shuts down the http listener. diff --git a/coffee/new_logging.coffee b/coffee/new-logging.coffee similarity index 100% rename from coffee/new_logging.coffee rename to coffee/new-logging.coffee diff --git a/coffee/request_handler.coffee b/coffee/request-handler.coffee similarity index 98% rename from coffee/request_handler.coffee rename to coffee/request-handler.coffee index cd537c8..6c4f5b5 100644 --- a/coffee/request_handler.coffee +++ b/coffee/request-handler.coffee @@ -14,8 +14,8 @@ log = require './logging' # - [Persistence](persistence.html) db = require './persistence' -# - [Module Manager](module_manager.html) -mm = require './module_manager' +# - [Module Manager](module-manager.html) +mm = require './module-manager' # - Node.js Modules: [fs](http://nodejs.org/api/fs.html), # [path](http://nodejs.org/api/path.html) and @@ -37,6 +37,7 @@ objUserCmds = 'get_eventmodules': mm.getAllEventModules 'store_rule': mm.storeRule +objAdminCmds = {} exports = module.exports = ( args ) -> args = args ? {} @@ -56,7 +57,7 @@ The shutdown function will be called if the admin command shutdown is issued. @param {function} fShutdown ### exports.addShutdownHandler = ( fShutdown ) => - @objAdminCmds.shutdown = ( args, answerHandler ) -> + objAdminCmds.shutdown = ( args, answerHandler ) -> answerHandler.answerSuccess 'Shutting down... BYE!' setTimeout fShutdown, 500 diff --git a/coffee/server.coffee b/coffee/webapi-eca.coffee similarity index 94% rename from coffee/server.coffee rename to coffee/webapi-eca.coffee index ac8c5a5..553e298 100644 --- a/coffee/server.coffee +++ b/coffee/webapi-eca.coffee @@ -13,7 +13,7 @@ Server # **Requires:** # - [Logging](logging.html) -logger = require './new_logging' +logger = require './new-logging' # - [Configuration](config.html) conf = require './config' @@ -24,8 +24,8 @@ db = require './persistence' # - [Engine](engine.html) engine = require './engine' -# - [HTTP Listener](http_listener.html) -http_listener = require './http_listener' +# - [HTTP Listener](http-listener.html) +http = require './http-listener' # - Node.js Modules: [fs](http://nodejs.org/api/fs.html), # [path](http://nodejs.org/api/path.html) @@ -133,14 +133,14 @@ init = -> log.info 'RS | Initialzing engine' engine args log.info 'RS | Initialzing http listener' - http_listener args + http args # > Distribute handlers between modules to link the application. log.info 'RS | Passing handlers to engine' engine.addPersistence db log.info 'RS | Passing handlers to http listener' #TODO engine pushEvent needs to go into redis queue - http_listener.addShutdownHandler shutDown + http.addShutdownHandler shutDown #TODO loadAction and addRule will be removed #mm.addHandlers db, engine.loadActionModule, engine.addRule log.info 'RS | For e child process for the event poller' @@ -151,7 +151,7 @@ init = -> args.logconf['file-path'] args.logconf['nolog'] ] - poller = cp.fork path.resolve( __dirname, 'event_poller' ), cliArgs + poller = cp.fork path.resolve( __dirname, 'event-poller' ), cliArgs ### Shuts down the server. @@ -161,7 +161,7 @@ Shuts down the server. shutDown = -> log.warn 'RS | Received shut down command!' engine?.shutDown() - http_listener?.shutDown() + http?.shutDown() ### ## Process Commands diff --git a/documentation/user_acceptance_tests.txt b/documentation/user_acceptance_tests.txt deleted file mode 100644 index 62ba254..0000000 --- a/documentation/user_acceptance_tests.txt +++ /dev/null @@ -1,10 +0,0 @@ -load rules rules -load rules -load action probinder -load actions -load event probinder -load events --> all these from server started from shell and node (different cwd!) -shutdown -upload rules/actions/events -look at doc ([host]/doc/) diff --git a/js-coffee/engine.js b/js-coffee/engine.js index 9e20ac1..9d3a2c9 100644 --- a/js-coffee/engine.js +++ b/js-coffee/engine.js @@ -7,12 +7,12 @@ var path = require('path'), listRules = {}, listActionModules = {}, isRunning = true, - ml, poller, db; + mm, poller, db; exports = module.exports = function( args ) { args = args || {}; log(args); - ml = require('./module_loader')(args); + mm = require('./module-manager')(args); return module.exports; }; @@ -24,7 +24,7 @@ exports = module.exports = function( args ) { */ exports.addPersistence = function(db_link) { db = db_link; - // if(ml && db) db.getActionModules(function(err, obj) { + // if(mm && db) db.getActionModules(function(err, obj) { // if(err) log.error('EN', 'retrieving Action Modules from DB!'); // else { // if(!obj) { @@ -35,7 +35,7 @@ exports.addPersistence = function(db_link) { // for(var el in obj) { // log.print('EN', 'Loading Action Module from DB: ' + el); // try{ - // m = ml.requireFromString(obj[el], el); + // m = mm.requireFromString(obj[el], el); // db.getActionModuleAuth(el, function(mod) { // return function(err, obj) { // if(obj && mod.loadCredentials) mod.loadCredentials(JSON.parse(obj)); diff --git a/js-coffee/event_poller.js b/js-coffee/event-poller.js similarity index 98% rename from js-coffee/event_poller.js rename to js-coffee/event-poller.js index 52f6c70..3027f2d 100644 --- a/js-coffee/event_poller.js +++ b/js-coffee/event-poller.js @@ -2,7 +2,7 @@ 'use strict'; -var logger = require('./new_logging'), +var logger = require('./new-logging'), listMessageActions = {}, listAdminCommands = {}, listEventModules = {}, @@ -31,7 +31,7 @@ function init() { log = logger(logconf); var args = { logger: log }; - (ml = require('./module_manager'))(args); + (ml = require('./module-manager'))(args); (db = require('./persistence'))(args); initAdminCommands(); initMessageActions(); diff --git a/js-coffee/http_listener.js b/js-coffee/http-listener.js similarity index 63% rename from js-coffee/http_listener.js rename to js-coffee/http-listener.js index 14e8344..997201d 100644 --- a/js-coffee/http_listener.js +++ b/js-coffee/http-listener.js @@ -3,20 +3,18 @@ HTTP Listener ============= -> Receives the HTTP requests to the server at the port specified by the -> [config](config.html) file. These requests (bound to a method) are then -> redirected to the appropriate handler which then takes care of the request. +> Receives the HTTP requests to the server at the given port. The requests +> (bound to a method) are then redirected to the appropriate handler which +> takes care of the request. */ (function() { - var app, config, exports, express, log, path, qs, requestHandler; + var app, exports, express, initRouting, log, path, qs, requestHandler; log = require('./logging'); - config = require('./config'); - - requestHandler = require('./request_handler'); + requestHandler = require('./request-handler'); path = require('path'); @@ -29,9 +27,7 @@ HTTP Listener /* Module call ----------- - Initializes the HTTP Listener and its child modules Logging, - Configuration and Request Handler, then tries to fetch the session - key from the configuration. + Initializes the HTTP listener and its request handler. @param {Object} args */ @@ -40,22 +36,21 @@ HTTP Listener exports = module.exports = function(args) { args = args != null ? args : {}; log(args); - config(args); requestHandler(args); + initRouting(args['http-port']); return module.exports; }; /* - Adds the shutdown handler to the admin commands. + Initializes the request routing and starts listening on the given port. - @param {function} fshutDown - @public addHandlers( *fShutDown* ) + @param {int} port + @private initRouting( *fShutDown* ) */ - exports.addHandlers = function(fShutDown) { - var e, http_port, sess_sec; - requestHandler.addShutdownHandler(fShutDown); + initRouting = function(port) { + var e, sess_sec; app.use(express.cookieParser()); sess_sec = "149u*y8C:@kmN/520Gt\\v'+KFBnQ!\\r<>5X/xRI`sT try @fs.unlinkSync @stdPath catch e - @log = require @path.join '..', 'js-coffee', 'new_logging' + @log = require @path.join '..', 'js-coffee', 'new-logging' cb() exports.tearDown = ( cb ) => diff --git a/webpages/public/.gitignore b/webpages/public/.gitignore new file mode 100644 index 0000000..325ab0d --- /dev/null +++ b/webpages/public/.gitignore @@ -0,0 +1 @@ +doc \ No newline at end of file