Permalink
Browse files

Removing globals

  • Loading branch information...
1 parent d0e6157 commit 54e77604d2029a98e1ce191bf33723b62ee8c14f @MainframeEnzo MainframeEnzo committed Jan 3, 2012
Showing with 19 additions and 182 deletions.
  1. +3 −3 modules/credentials.js
  2. +6 −6 modules/dao.js
  3. +2 −2 modules/logger.js
  4. +1 −1 modules/plugins.js
  5. +0 −83 run/client.coffee
  6. +0 −10 run/client.js
  7. +0 −70 run/debug.js
  8. +7 −7 submodules/utilities.js
View
@@ -13,15 +13,15 @@ CredentialManagerModule = function (constants, utilities, logger) {
CredentialManagerModule.prototype.check = function (callback) {
var checkCredentialsArray = [Module.constants.strings.AWS_ACCESS_KEY_ID, Module.constants.strings.AWS_SECRET_ACCESS_KEY];
checkCredentialsArray.forEach(function (credential) {
- var check = Module.constants.globals[credential];
+ var check = process.env[credential];
if (!check)
Module.utilities.exit(credential + ' credential is not declared');
});
/* For node-cloudwatch */
- process.env[Module.constants.strings.AWS_SECRET_ACCESS_KEY] = Module.constants.globals[Module.constants.strings.AWS_SECRET_ACCESS_KEY];
- process.env[Module.constants.strings.AWS_ACCESS_KEY_ID] = Module.constants.globals[Module.constants.strings.AWS_ACCESS_KEY_ID];
+ process.env[Module.constants.strings.AWS_SECRET_ACCESS_KEY] = process.env[Module.constants.strings.AWS_SECRET_ACCESS_KEY];
+ process.env[Module.constants.strings.AWS_ACCESS_KEY_ID] = process.env[Module.constants.strings.AWS_ACCESS_KEY_ID];
callback();
};
View
@@ -24,7 +24,7 @@ DaoManagerModule = function (constants, utilities, logger, dao) {
};
DaoManagerModule.prototype.debugMode = function () {
- if (Module.constants.globals['debug'] == 'true') return true;
+ if (process.env['debug'] == 'true') return true;
return false;
};
@@ -40,26 +40,26 @@ DaoManagerModule.prototype.postCloudwatch = function (metricName, unit, value) {
if (this.debugMode()) return;
/* If we're not on EC2, don't post */
- if (Module.constants.globals[Module.constants.strings.EC2] != Module.constants.strings.TRUE) return;
+ if (process.env[Module.constants.strings.EC2] != Module.constants.strings.TRUE) return;
var params = {};
- params['Namespace'] = Module.constants.globals[Module.constants.strings.CLOUDWATCH_NAMESPACE];
+ params['Namespace'] = process.env[Module.constants.strings.CLOUDWATCH_NAMESPACE];
params['MetricData.member.1.MetricName'] = metricName;
params['MetricData.member.1.Unit'] = unit;
params['MetricData.member.1.Value'] = value;
params['MetricData.member.1.Dimensions.member.1.Name'] = 'InstanceID';
params['MetricData.member.1.Dimensions.member.1.Value'] = process.env[Module.constants.strings.IP];
- Module.logger.write(Module.constants.levels.INFO, 'CloudWatch Namespace: ' + Module.constants.globals[Module.constants.strings.CLOUDWATCH_NAMESPACE]);
+ Module.logger.write(Module.constants.levels.INFO, 'CloudWatch Namespace: ' + process.env[Module.constants.strings.CLOUDWATCH_NAMESPACE]);
Module.logger.write(Module.constants.levels.INFO, 'CloudWatch IP: ' + process.env[Module.constants.strings.IP]);
Module.logger.write(Module.constants.levels.INFO, 'CloudWatch MetricName: ' + metricName);
Module.logger.write(Module.constants.levels.INFO, 'CloudWatch Unit: ' + unit);
Module.logger.write(Module.constants.levels.INFO, 'CloudWatch Value: ' + value);
/* If we specified a parameter to enable, then we post */
- Module.logger.write(Module.constants.levels.INFO, 'CloudWatch? ' + Module.constants.globals[Module.constants.strings.CLOUDWATCH_ENABLED]);
- if (Module.constants.globals[Module.constants.strings.CLOUDWATCH_ENABLED] == Module.constants.strings.TRUE) {
+ Module.logger.write(Module.constants.levels.INFO, 'CloudWatch? ' + process.env[Module.constants.strings.CLOUDWATCH_ENABLED]);
+ if (process.env[Module.constants.strings.CLOUDWATCH_ENABLED] == Module.constants.strings.TRUE) {
try {
Module.cloudwatchApi.request('PutMetricData', params, function (response) {
Module.logger.write(Module.constants.levels.INFO, 'CloudWatch response: ' + response.toString());
View
@@ -14,11 +14,11 @@ LoggingManagerModule.prototype.write = function (level, message) { /* Create mes
message = date + ' ' + level + ' ' + message + '\n';
/* Log to console if specified */
- if (Module.constants.globals[Module.constants.strings.CONSOLE] == Module.constants.strings.TRUE) console.log(message);
+ if (process.env[Module.constants.strings.CONSOLE] == Module.constants.strings.TRUE) console.log(message);
/* Create log object to store */
var data = {
- origin: Module.constants.globals[Module.constants.strings.IP],
+ origin: process.env[Module.constants.strings.IP],
message: message
};
View
@@ -60,7 +60,7 @@ PluginsManagerModule.prototype.executePlugins = function () {
// Module.dao.write(pluginName, data);
});
} /* Duration between poll times */
- }, Number(Module.constants.globals[Module.constants.strings.PLUGIN_POLL_TIME]) * 1000);
+ }, Number(process.env[Module.constants.strings.PLUGIN_POLL_TIME]) * 1000);
};
exports.PluginsManagerModule = PluginsManagerModule;
View
@@ -1,83 +0,0 @@
-/* client.js */
-/* To run: node client.js ec2=true/false debug=true/false console=true/false cloudwatch=true/false */
-var fs = require('fs'),
- location = 'client.js';
-
-/* Error handling */
-require('long-stack-traces');
-process.on('uncaughtException', function (error) {
- console.log('Caught unhandled node.js exception: ' + error);
-});
-
-var modules = {
- constantsModule: '../submodules/constants-manager',
- utilitiesModule: '../submodules/utilities-manager',
- credentialsModule: '../modules/credential-manager',
- daoModule: '../modules/dao-manager',
- tailingModule: '../modules/tailing-manager',
- pluginsModule: '../modules/plugins-manager',
- loggingModule: '../modules/logging-manager'
-};
-
-/* Setup dependencies */
-for (var name in modules) {
- console.log('Evaluating dependency in location: ' + location + ', with name: ' + name + ', path:' + modules[name]);
- eval('var ' + name + ' = require(\'' + modules[name] + '\')');
-}
-
-/**
- * NodeMonitor
- *
- * @returns {NodeMonitor}
- */
-
-function NodeMonitor() {
- this.init = function (callback) {
- var constants = new constantsModule.ConstantsManagerModule();
- var utilities = new utilitiesModule.UtilitiesManagerModule(constants);
- var credentials = new credentialsModule.CredentialManagerModule(constants, utilities);
- var plugins = new pluginsModule.PluginsManagerModule(constants, utilities);
- var tailing = new tailingModule.LogManagerModule(constants, utilities);
-
- this.constants = constants;
- this.plugins = plugins;
- this.tailing = tailing;
-
- /* Use object to store config options */
- constants.globals = {};
-
- /* Parse configuration */
- utilities.parseConfig(
- constants.strings.MONITOR_CONFIG_FILE, function () {
- /* Parse command line options */
- utilities.parseCommandLineOptions(function () {
- if (constants.globals[constants.strings.EC2] == constants.strings.TRUE) {
- /* Use EC2-metadata script */
- utilities.autoPopulate();
- } else {
- /* Default to localhost */
- constants.globals[constants.strings.INSTANCE_ID] = 'none';
- constants.globals[constants.strings.LOCAL_IPV4] = '127.0.0.1';
- constants.globals[constants.strings.PUBLIC_HOSTNAME] = '127.0.0.1';
- }
-
- /* Set default IP */
- constants.globals[constants.strings.IP] = constants.globals[constants.strings.LOCAL_IPV4];
-
- /* Validate credentials */
- credentials.check();
- callback();
- });
- });
- };
-}
-
-var nodeMonitor = new NodeMonitor();
-nodeMonitor.init(function() {
- /* Debug */
- for (var i in nodeMonitor.constants.globals) {
- console.log('Global parameter: ' + i + ', with value: ' + nodeMonitor.constants.globals[i]);
- }
- nodeMonitor.plugins.start();
- // nodeMonitor.tailing.start();
-});
View
@@ -47,9 +47,6 @@ function NodeMonitor() {
this.dao = dao;
this.plugins = plugins;
- /* Use object to store config options */
- constants.globals = {};
-
/* Parse configuration */
utilities.parseConfig(constants.strings.MONITOR_CONFIG_FILE, function () {
/* Parse command line options */
@@ -69,12 +66,5 @@ function NodeMonitor() {
var nodeMonitor = new NodeMonitor();
nodeMonitor.init(function () {
- /* Debug */
- /*
- for (var i in nodeMonitor.constants.globals) {
- console.log('Global parameter: ' + i + ', with value: ' + nodeMonitor.constants.globals[i]);
- }
- console.log('Running on platform: ' + process.platform.toString());
- */
nodeMonitor.plugins.start();
});
View
@@ -1,70 +0,0 @@
-/* client.js */
-/* To run: node client.js ec2=true/false debug=true/false console=true/false cloudwatch=true/false */
-
-/* Dependency management */
-var fs = require('fs'), location = 'test.js';
-
-/* Error handling */
-process.on('uncaughtException', function(error) {
- console.log('Caught unhandled node.js exception: ' + error);
-});
-
-/* Dependencies */
-var modules = {
- constantsManager : '../submodules/constants-manager',
- utilitiesManager : '../submodules/utilities-manager',
-};
-
-/**
- * NodeMonitor
- *
- * @returns {NodeMonitor}
- */
-function NodeMonitor() {
- console.log('NodeMonitor');
- /**
- * Init
- *
- * @param callback
- * @returns {Init}
- */
- function Init(callback) {
- console.log('Init');
-
- try {
- process.chdir('../submodules');
- } catch (Exception) {
- console.log('Error loading submodule dir');
- }
-
- /* Setup dependencies */
- for ( var name in modules) {
- console.log('Evaluating dependency in location: ' + location
- + ', with name: ' + name + ', path:' + modules[name]);
- eval('var ' + name + ' = require(\'' + modules[name] + '\')');
- }
-
- var constants = new constantsManager.ConstantsManagerModule();
- var utilities = new utilitiesManager.UtilitiesManagerModule(constants);
-
- /* Use global object for config options */
- constants.globals = {};
-
- /* Read config into global object */
- utilities.readConfig(constants.strings.MONITOR_CONFIG_FILE, function() {
- console.log('callback done!');
- for ( var i in constants.globals) {
- console.log('callback debug: ' + constants.globals[i] + ', i: '
- + i);
- }
- });
- }
-
- this.init = new Init();
-}
-
-var nodeMonitor = new NodeMonitor();
-nodeMonitor.init(function() {
- // nodeMonitor.plugins.start();
- // nodeMonitor.tailing.start();
-});
View
@@ -11,12 +11,12 @@ UtilitiesManagerModule.prototype.parseCommandLineOptions = function (callback) {
var count = 0;
process.argv.forEach(function (value, index, array) {
if (count != 0 && count != 1) {
- Module.constants.globals[value.split('=')[0]] = value.split('=')[1]; /* Debug */
+ process.env[value.split('=')[0]] = value.split('=')[1]; /* Debug */
/* console.log('Read cmd parameter: ' + value.split('=')[0] + ', with value: ' + value.split('=')[1]); */
}
count++;
});
- callback(Module.constants.globals);
+ callback();
};
UtilitiesManagerModule.prototype.parseConfig = function (configFile, callback) {
@@ -30,16 +30,16 @@ UtilitiesManagerModule.prototype.parseConfig = function (configFile, callback) {
for (var i = 0; i < splitBuffer.length; i++) {
var params = splitBuffer[i].split('=');
if (params[0] != undefined && params[0] != '') {
- Module.constants.globals[params[0]] = params[1]; /* Debug */
+ process.env[params[0]] = params[1]; /* Debug */
/* console.log('Read config parameter: ' + params[0] + ', with value: ' + params[1]); */
}
}
- callback(Module.constants.globals);
+ callback();
});
};
UtilitiesManagerModule.prototype.getInstanceId = function (callback) {
- if (Module.constants.globals[Module.constants.strings.EC2] == Module.constants.strings.TRUE) {
+ if (process.env[Module.constants.strings.EC2] == Module.constants.strings.TRUE) {
[Module.constants.strings.INSTANCE_ID].forEach(function (
parameter) {
require('child_process').exec(
@@ -59,7 +59,7 @@ UtilitiesManagerModule.prototype.getInstanceId = function (callback) {
};
UtilitiesManagerModule.prototype.getPublicHostname = function (callback) {
- if (Module.constants.globals[Module.constants.strings.EC2] == Module.constants.strings.TRUE) {
+ if (process.env[Module.constants.strings.EC2] == Module.constants.strings.TRUE) {
[Module.constants.strings.PUBLIC_HOSTNAME].forEach(function (
parameter) {
require('child_process').exec(
@@ -79,7 +79,7 @@ UtilitiesManagerModule.prototype.getPublicHostname = function (callback) {
};
UtilitiesManagerModule.prototype.getInternalIP = function (callback) {
- if (Module.constants.globals[Module.constants.strings.EC2] == Module.constants.strings.TRUE) {
+ if (process.env[Module.constants.strings.EC2] == Module.constants.strings.TRUE) {
[Module.constants.strings.LOCAL_IPV4].forEach(function (
parameter) {
require('child_process').exec(

0 comments on commit 54e7760

Please sign in to comment.