incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [46/50] [abbrv] git commit: More code cleanup for clarity
Date Sat, 31 May 2014 14:22:19 GMT
More code cleanup for clarity


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/7f8ef320
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/7f8ef320
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/7f8ef320

Branch: refs/heads/apache-blur-0.2
Commit: 7f8ef3205db415ddfdb63dacf5a585e4888a1732
Parents: de24dc2
Author: Chris Rohr <rohr.chris@gmail.com>
Authored: Fri May 30 08:42:25 2014 -0400
Committer: Chris Rohr <rohr.chris@gmail.com>
Committed: Fri May 30 08:42:25 2014 -0400

----------------------------------------------------------------------
 .../src/main/webapp/js/blurconsole.data.js      |  38 +-
 .../src/main/webapp/js/blurconsole.fake.js      | 263 ++++++-------
 .../src/main/webapp/js/blurconsole.js           |   6 +-
 .../src/main/webapp/js/blurconsole.logging.js   |  32 +-
 .../src/main/webapp/js/blurconsole.model.js     | 369 ++++++++++---------
 5 files changed, 347 insertions(+), 361 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/7f8ef320/contrib/blur-console/src/main/webapp/js/blurconsole.data.js
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/webapp/js/blurconsole.data.js b/contrib/blur-console/src/main/webapp/js/blurconsole.data.js
index 9710ddc..b89ff80 100644
--- a/contrib/blur-console/src/main/webapp/js/blurconsole.data.js
+++ b/contrib/blur-console/src/main/webapp/js/blurconsole.data.js
@@ -21,26 +21,35 @@ under the License.
 blurconsole.data = (function() {
 	'use strict';
 
+	//------------------- Private methods --------------------------
+	function _logError (errorMsg, status, module, callback) {
+		blurconsole.model.logs.logError(status + ' - ' + errorMsg, module);
+		if (callback) {
+			callback('error');
+		}
+	}
+
+	//------------------- Public API -------------------------------
 	function getTableList(callback) {
 		$.getJSON('/service/tables', callback).fail(function(xhr) {
-			logError(xhr.responseText, xhr.status, 'tables', callback);
+			_logError(xhr.responseText, xhr.status, 'tables', callback);
 		});
 	}
 
 	function getNodeList(callback) {
 		$.getJSON('/service/nodes', callback).fail(function(xhr) {
-			logError(xhr.responseText, xhr.status, 'tables', callback);
+			_logError(xhr.responseText, xhr.status, 'tables', callback);
 		});
 	}
 	function getQueryPerformance(callback) {
 		$.getJSON('/service/queries/performance', callback).fail(function(xhr) {
-			logError(xhr.responseText, xhr.status, 'tables', callback);
+			_logError(xhr.responseText, xhr.status, 'tables', callback);
 		});
 	}
 
 	function getQueries(callback) {
 		$.getJSON('/service/queries', callback).fail(function(xhr) {
-			logError(xhr.responseText, xhr.status, 'tables', callback);
+			_logError(xhr.responseText, xhr.status, 'tables', callback);
 		});
 	}
 
@@ -50,7 +59,7 @@ blurconsole.data = (function() {
 				table: table
 			},
 			error: function(xhr) {
-				logError(xhr.responseText, xhr.status, 'tables');
+				_logError(xhr.responseText, xhr.status, 'tables');
 			}
 		});
 	}
@@ -58,7 +67,7 @@ blurconsole.data = (function() {
 	function disableTable(table) {
 		$.ajax('/service/tables/' + table + '/disable', {
 			error: function(xhr) {
-				logError(xhr.responseText, xhr.status, 'tables');
+				_logError(xhr.responseText, xhr.status, 'tables');
 			}
 		});
 	}
@@ -66,7 +75,7 @@ blurconsole.data = (function() {
 	function enableTable (table){
 		$.ajax('/service/tables/' + table + '/enable', {
 			error: function(xhr) {
-				logError(xhr.responseText, xhr.status, 'tables');
+				_logError(xhr.responseText, xhr.status, 'tables');
 			}
 		});
 	}
@@ -77,20 +86,20 @@ blurconsole.data = (function() {
 				includeFiles: includeFiles
 			},
 			error: function(xhr) {
-				logError(xhr.responseText, xhr.status, 'tables');
+				_logError(xhr.responseText, xhr.status, 'tables');
 			}
 		});
 	}
 
 	function getSchema(table, callback) {
 		$.getJSON('/service/tables/' + table + '/schema', callback).fail(function(xhr) {
-			logError(xhr.responseText, xhr.status, 'tables');
+			_logError(xhr.responseText, xhr.status, 'tables');
 		});
 	}
 
 	function findTerms (table, family, column, startsWith, callback) {
 		$.getJSON('/service/tables/' + table + '/' + family + '/' + column + '/terms', {startsWith:
startsWith}, callback).fail(function(xhr) {
-			logError(xhr.responseText, xhr.status, 'tables');
+			_logError(xhr.responseText, xhr.status, 'tables');
 		});
 	}
 
@@ -101,18 +110,11 @@ blurconsole.data = (function() {
 			'data': params,
 			'success': callback,
 			'error': function(xhr) {
-				logError(xhr.responseText, xhr.status, 'tables');
+				_logError(xhr.responseText, xhr.status, 'tables');
 			}
 		});
 	}
 
-	function logError (errorMsg, status, module, callback) {
-		blurconsole.model.logs.logError(status + ' - ' + errorMsg, module);
-		if (callback) {
-			callback('error');
-		}
-	}
-
 	return {
 		getTableList : getTableList,
 		getNodeList : getNodeList,

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/7f8ef320/contrib/blur-console/src/main/webapp/js/blurconsole.fake.js
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/webapp/js/blurconsole.fake.js b/contrib/blur-console/src/main/webapp/js/blurconsole.fake.js
index 028e4d7..bb4b247 100644
--- a/contrib/blur-console/src/main/webapp/js/blurconsole.fake.js
+++ b/contrib/blur-console/src/main/webapp/js/blurconsole.fake.js
@@ -20,37 +20,93 @@ under the License.
 /*global blurconsole:false */
 blurconsole.fake = (function() {
 	'use strict';
-	var getTableList, getNodeList, getQueryPerformance, getQueries, cancelQuery, disableTable,
enableTable, deleteTable, getSchema, findTerms, sendSearch,
-		buildSchema, randomNumber, randomBoolean, randomString;
 
-	getTableList = function(callback) {
-		console.log('getting fake table list');
-		var clusters = ['prodA', 'prodB'], data = [], i, cluster, rows, records, enabled;
+	//----------------------- Private Methods ----------------------
+	function _randomNumber(max, includeZero) {
+		var random = Math.random()*max;
 
-		for (i = 0; i < 5; i++) {
-			cluster = clusters[randomNumber(2, true)];
-			rows = randomNumber(1000);
-			records = randomNumber(10000)+1000;
-			enabled = randomBoolean();
+		if (!includeZero) {
+			random++;
+		}
+
+		return Math.floor(random);
+	}
 
-			data.push({cluster:cluster, name:'testtable'+i, enabled:enabled, rows:rows, records:records,
families: blurconsole.utils.keys(buildSchema())});
+	function _randomBoolean() {
+		return _randomNumber(2) % 2 === 0;
+	}
+
+	function _randomString() {
+		var text = '';
+		var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
+
+		for( var i=0; i < Math.floor(Math.random() * 30 + 1); i++ ) {
+			text += possible.charAt(Math.floor(Math.random() * possible.length));
+		}
+
+		return text;
+	}
+
+	function _buildSchema() {
+		var schema = {}, familyCount = _randomNumber(20), types = ['string', 'long', 'int', 'date',
'stored', 'customType'];
+
+		for(var f=0; f < familyCount; f++) {
+			var c, fam = {}, columnCount = _randomNumber(30);
+			for(c=0; c < columnCount; c++) {
+				var col_name = 'col' + c;
+				if(_randomNumber(10) === 1) {
+					col_name += '.sub';
+				}
+				fam[col_name] = {
+					'fieldLess' : _randomBoolean(),
+					'type' : types[_randomNumber(6, true)],
+					'extra' : null
+				};
 
+				if (_randomBoolean()) {
+					var e, extraPropCount = _randomNumber(3), props = {};
+					for (e=0; e < extraPropCount; e++) {
+						props['extra'+e] = 'val'+e;
+					}
+					fam[col_name].extra = props;
+				}
+			}
+			schema['fam'+f] = fam;
 		}
+		return schema;
+	}
 
+	function _sendCallback(callback, data) {
 		setTimeout(function() {
-			callback({'tables':data, 'clusters':clusters});
-		}, randomNumber(1000));
-	};
+			callback(data);
+		}, _randomNumber(1000));
+	}
+
+	//-------------------------- Public API ---------------------------
+	function getTableList(callback) {
+		console.log('getting fake table list');
+		var clusters = ['prodA', 'prodB'], data = [];
+
+		for (var i = 0; i < 5; i++) {
+			var cluster = clusters[_randomNumber(2, true)];
+			var rows = _randomNumber(1000);
+			var records = _randomNumber(10000)+1000;
+			var enabled = _randomBoolean();
+
+			data.push({cluster:cluster, name:'testtable'+i, enabled:enabled, rows:rows, records:records,
families: blurconsole.utils.keys(_buildSchema())});
 
-	getNodeList = function(callback) {
+		}
+		_sendCallback(callback, {'tables':data, 'clusters':clusters});
+	}
+
+	function getNodeList(callback) {
 		console.log('getting fake node list');
 		var controllers = {online:[], offline:[]},
 			clusters = [{name:'prodA', online:[], offline:[]}, {name:'prodB', online:[], offline:[]}],
-			zookeepers = {online: [], offline:[]},
-			i, state;
+			zookeepers = {online: [], offline:[]};
 
-		for(i = 0; i < 3; i++) {
-			state = randomBoolean();
+		for(var i = 0; i < 3; i++) {
+			var state = _randomBoolean();
 			if (state) {
 				controllers.online.push('controller' + i + '.localhost');
 				clusters[0].online.push('prodA.shard' + i + '.localhost');
@@ -63,103 +119,60 @@ blurconsole.fake = (function() {
 				zookeepers.offline.push('zookeeper' + i + '.localhost');
 			}
 		}
+		_sendCallback(callback, {controllers: controllers, clusters: clusters, zookeepers: zookeepers});
+	}
 
-		setTimeout(function(){
-			callback({controllers: controllers, clusters: clusters, zookeepers: zookeepers});
-		}, randomNumber(1000));
-	};
-
-	getQueryPerformance = function(callback) {
+	function getQueryPerformance(callback) {
 		console.log('getting fake query performance');
+		_sendCallback(callback, _randomNumber(1000, true));
+	}
 
-		setTimeout(function(){
-			callback(randomNumber(1000));
-		}, randomNumber(1000));
-	};
-
-	getQueries = function(callback) {
+	function getQueries(callback) {
 		console.log('getting fake queries');
 		var queries = [];
 
-		for (var i=0; i < randomNumber(50); i++) {
+		for (var i=0; i < _randomNumber(50); i++) {
 			queries.push({
-				uuid: randomString(),
-				user: 'user_' + randomNumber(10, true),
-				query: randomString(),
-				table: 'testtable' + randomNumber(5, true),
-				state: randomNumber(3, true),
-				percent: randomNumber(100, true),
+				uuid: _randomString(),
+				user: 'user_' + _randomNumber(10, true),
+				query: _randomString(),
+				table: 'testtable' + _randomNumber(5, true),
+				state: _randomNumber(3, true),
+				percent: _randomNumber(100, true),
 				startTime: new Date().getTime()
 			});
 		}
+		_sendCallback(callback, { slowQueries : _randomNumber(10) === 1, queries : queries });
+	}
 
-		setTimeout(function(){
-			callback({
-				slowQueries : randomNumber(10) === 1,
-				queries : queries
-			});
-		}, randomNumber(1000));
-	};
-
-	cancelQuery = function(table, uuid) {
+	function cancelQuery(table, uuid) {
 		console.log('Fake sending request to cancel query [' + uuid + '] on table [' + table +
']');
-	};
+	}
 
-	disableTable = function(table) {
+	function disableTable(table) {
 		console.log('Fake sending request to disable table [' + table + ']');
-	};
+	}
 
-	enableTable = function(table) {
+	function enableTable(table) {
 		console.log('Fake sending request to enable table [' + table + ']');
-	};
+	}
 
-	deleteTable = function(table, includeFiles) {
+	function deleteTable(table, includeFiles) {
 		console.log('Fake sending request to delete table [' + table + '] with files [' + includeFiles
+ ']');
-	};
+	}
 
-	getSchema = function(table, callback) {
+	function getSchema(table, callback) {
 		console.log('getting fake schema for table [' + table + ']');
-		setTimeout(function() {
-			callback(buildSchema());
-		}, randomNumber(1000));
-	};
-
-	buildSchema = function() {
-		var f, schema = {}, familyCount = randomNumber(20), types = ['string', 'long', 'int', 'date',
'stored', 'customType'];
+		_sendCallback(callback, _buildSchema());
+	}
 
-		for(f=0; f < familyCount; f++) {
-			var c, fam = {}, columnCount = randomNumber(30);
-			for(c=0; c < columnCount; c++) {
-				var col_name = 'col' + c;
-				if(randomNumber(10) === 1) {
-					col_name += '.sub';
-				}
-				fam[col_name] = {
-					'fieldLess' : randomBoolean(),
-					'type' : types[randomNumber(6, true)],
-					'extra' : null
-				};
-
-				if (randomBoolean()) {
-					var e, extraPropCount = randomNumber(3), props = {};
-					for (e=0; e < extraPropCount; e++) {
-						props['extra'+e] = 'val'+e;
-					}
-					fam[col_name].extra = props;
-				}
-			}
-			schema['fam'+f] = fam;
-		}
-		return schema;
-	};
-
-	findTerms = function(table, family, column, startsWith, callback) {
+	function findTerms(table, family, column, startsWith, callback) {
 		console.log('getting fake terms from [' + table + '] for family [' + family + '] and column
[' + column + '] starting with [' + startsWith + ']');
 
 		var terms = [];
 
 		for (var i = 0; i < 10; i++) {
-			var randStr = randomString();
+			var randStr = _randomString();
 			if (startsWith) {
 				randStr = startsWith + randStr;
 			}
@@ -169,42 +182,41 @@ blurconsole.fake = (function() {
 		terms = terms.sort(function (a, b) {
 			return a.toLowerCase().localeCompare(b.toLowerCase());
 		});
+		_sendCallback(callback, terms);
+	}
 
-		callback(terms);
-	};
-
-	sendSearch = function(query, table, args, callback) {
+	function sendSearch(query, table, args, callback) {
 		console.log('sending fake search [' + query + '] on table [' + table + ']');
 
-		var fams = args.families, results = {}, total = (fams !== null && fams.indexOf('rowid')
>= 0) ? 1 : randomNumber(1000);
+		var fams = args.families, results = {}, total = (fams !== null && fams.indexOf('rowid')
>= 0) ? 1 : _randomNumber(1000);
 
 		if (fams !== null) {
 			$.each(fams, function(i, fam){
-				var cols = randomNumber(30, true), toFetch = (fams !== null && fams.indexOf('rowid')
>= 0)? 1 : args.fetch;
+				var cols = _randomNumber(30, true), toFetch = (fams !== null && fams.indexOf('rowid')
>= 0)? 1 : args.fetch;
 				if (total - args.start < toFetch) {
 					toFetch = total - args.start;
 				}
 
 				if (args.rowRecordOption === 'recordrecord') {
 					results[fam] = [];
-					for (var recordIndex = 0; recordIndex < randomNumber(toFetch); recordIndex++) {
+					for (var recordIndex = 0; recordIndex < _randomNumber(toFetch); recordIndex++) {
 						var recordRow = {};
-						recordRow.recordid = randomNumber(1000000).toString();
+						recordRow.recordid = _randomNumber(1000000).toString();
 						for (var recordColIndex=0; recordColIndex < cols; recordColIndex++) {
-							recordRow['col'+recordColIndex] = randomString();
+							recordRow['col'+recordColIndex] = _randomString();
 						}
 						results[fam].push(recordRow);
 					}
 				} else {
 					results[fam] = {};
-					for (var rowIndex = 0; rowIndex < randomNumber(toFetch); rowIndex++) {
-						var rowid = randomNumber(10000000).toString();
+					for (var rowIndex = 0; rowIndex < _randomNumber(toFetch); rowIndex++) {
+						var rowid = _randomNumber(10000000).toString();
 						results[fam][rowid] = [];
-						for (var rowRecordIndex = 0; rowRecordIndex < randomNumber(10); rowRecordIndex++)
{
+						for (var rowRecordIndex = 0; rowRecordIndex < _randomNumber(10); rowRecordIndex++)
{
 							var row = {};
-							row.recordid = randomNumber(1000000).toString();
+							row.recordid = _randomNumber(1000000).toString();
 							for (var rowRecordColIndex=0; rowRecordColIndex < cols; rowRecordColIndex++) {
-								row['col'+rowRecordColIndex] = randomString();
+								row['col'+rowRecordColIndex] = _randomString();
 							}
 							results[fam][rowid].push(row);
 						}
@@ -214,48 +226,13 @@ blurconsole.fake = (function() {
 		}
 
 		if (fams === null || fams.length === 0) {
-			callback({
-				total: total
-			});
+			_sendCallback(callback, { total: total });
 		} else if (fams.indexOf('rowid') >= 0) {
-			callback({
-				total: total,
-				results: results,
-				families: fams
-			});
+			_sendCallback(callback, { total: total, results: results, families: fams });
 		} else {
-			callback({
-				families: fams,
-				results: results,
-				total: total
-			});
+			_sendCallback(callback, { families: fams, results: results, total: total });
 		}
-	};
-
-	randomNumber = function(max, includeZero) {
-		var random = Math.random()*max;
-
-		if (!includeZero) {
-			random++;
-		}
-
-		return Math.floor(random);
-	};
-
-	randomBoolean = function() {
-		return randomNumber(2) % 2 === 0;
-	};
-
-	randomString = function() {
-		var text = '';
-		var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
-
-		for( var i=0; i < Math.floor(Math.random() * 30 + 1); i++ ) {
-			text += possible.charAt(Math.floor(Math.random() * possible.length));
-		}
-
-		return text;
-	};
+	}
 
 	return {
 		getTableList : getTableList,

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/7f8ef320/contrib/blur-console/src/main/webapp/js/blurconsole.js
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/webapp/js/blurconsole.js b/contrib/blur-console/src/main/webapp/js/blurconsole.js
index ccbedec..310df79 100644
--- a/contrib/blur-console/src/main/webapp/js/blurconsole.js
+++ b/contrib/blur-console/src/main/webapp/js/blurconsole.js
@@ -24,10 +24,12 @@ under the License.
  */
 var blurconsole = (function () {
 	'use strict';
-	var initModule = function ( $container ) {
+
+	//---------------------- Public API -------------------------
+	function initModule( $container ) {
 		blurconsole.model.initModule();
 		blurconsole.shell.initModule( $container );
-	};
+	}
 
 	return { initModule: initModule };
 }());
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/7f8ef320/contrib/blur-console/src/main/webapp/js/blurconsole.logging.js
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/webapp/js/blurconsole.logging.js b/contrib/blur-console/src/main/webapp/js/blurconsole.logging.js
index 00afb8f..e3a35d5 100644
--- a/contrib/blur-console/src/main/webapp/js/blurconsole.logging.js
+++ b/contrib/blur-console/src/main/webapp/js/blurconsole.logging.js
@@ -21,6 +21,8 @@ under the License.
 /*global blurconsole:false */
 blurconsole.logging = (function () {
 	'use strict';
+
+	//------------------------ Configuration and State -----------------------
 	var configMap = {
 		emptyLogMsg: 'No Errors! Yay!',
 		mainHtml: '<div class="log_display"></div>',
@@ -31,35 +33,29 @@ blurconsole.logging = (function () {
 	},
 	jqueryMap = {
 		modal: null
-	},
-	initModule, showLogging, clearLogging, drawLogs;
-
-	initModule = function() {
-		$.gevent.subscribe($(document), 'show-logging', showLogging);
-		$.gevent.subscribe($(document), 'logging-updated', drawLogs);
 	};
 
-	showLogging = function() {
+	//------------------ Event Handling and DOM Methods -------------
+	function _showLogging() {
 		if (jqueryMap.modal === null) {
 			jqueryMap.modal = $(blurconsole.browserUtils.modal('error_log_modal', 'Error Logs', configMap.mainHtml,
configMap.buttons, 'large'));
 			jqueryMap.modal.modal()
 			.on('shown.bs.modal', function(){
 				jqueryMap.logHolder = $('.log_display', jqueryMap.modal);
-				console.log(jqueryMap.logHolder);
-				drawLogs();
+				_drawLogs();
 			})
-			.on('click', '#clear-log-button', clearLogging);
+			.on('click', '#clear-log-button', _clearLogging);
 		} else {
 			jqueryMap.modal.modal('show');
 		}
-	};
+	}
 
-	clearLogging = function() {
+	function _clearLogging() {
 		jqueryMap.logHolder.html(configMap.emptyLogMsg);
 		blurconsole.model.logs.clearErrors();
-	};
+	}
 
-	drawLogs = function() {
+	function _drawLogs() {
 		var errors = blurconsole.model.logs.getLogs();
 
 		if (jqueryMap.logHolder) {
@@ -77,7 +73,13 @@ blurconsole.logging = (function () {
 				jqueryMap.logHolder.html(errorList);
 			}
 		}
-	};
+	}
+
+	//------------------ Public API ---------------------------------
+	function initModule() {
+		$.gevent.subscribe($(document), 'show-logging', _showLogging);
+		$.gevent.subscribe($(document), 'logging-updated', _drawLogs);
+	}
 
 	return {
 		initModule : initModule

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/7f8ef320/contrib/blur-console/src/main/webapp/js/blurconsole.model.js
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/webapp/js/blurconsole.model.js b/contrib/blur-console/src/main/webapp/js/blurconsole.model.js
index 1ac6882..45e6866 100644
--- a/contrib/blur-console/src/main/webapp/js/blurconsole.model.js
+++ b/contrib/blur-console/src/main/webapp/js/blurconsole.model.js
@@ -20,6 +20,8 @@ under the License.
 /*global blurconsole:false */
 blurconsole.model = (function() {
 	'use strict';
+
+	//----------------------- Configuration and State ------------------
 	var
 		configMap = {
 			poller : null
@@ -31,21 +33,20 @@ blurconsole.model = (function() {
 			queryPerformance : [],
 			queries : {},
 			errors: []
-		},
-		tables, metrics, nodes, queries, search, logs, initModule, nodePoller, updateNodes, tablePoller,
updateTables, queryPerformancePoller, updateQueryPerformance, queryPoller, updateQueries;
-
-	tables = (function() {
-		var getClusters, getEnabledTables, getDisabledTables, isDataLoaded, disableTable, enableTable,
deleteTable, getSchema, findTerms, getAllEnabledTables, getFamilies;
+		};
 
-		getClusters = function() {
+	//----------------------- Models ----------------------------------
+	var tables = (function() {
+		//-------------- Public API -----------------
+		function getClusters() {
 			if (stateMap.currentClusters === null) {
 				return [];
 			}
 
 			return blurconsole.utils.unique(stateMap.currentClusters, true);
-		};
+		}
 
-		getEnabledTables = function(cluster) {
+		function getEnabledTables(cluster) {
 			var data = [];
 
 			$.each(stateMap.currentTables, function(idx, table) {
@@ -55,9 +56,9 @@ blurconsole.model = (function() {
 			});
 
 			return data;
-		};
+		}
 
-		getDisabledTables = function(cluster) {
+		function getDisabledTables(cluster) {
 			var data = [];
 
 			$.each(stateMap.currentTables, function(idx, table) {
@@ -67,9 +68,9 @@ blurconsole.model = (function() {
 			});
 
 			return data;
-		};
+		}
 
-		getAllEnabledTables = function() {
+		function getAllEnabledTables() {
 			var tableMap = {};
 
 			$.each(getClusters(), function(c, cluster){
@@ -77,29 +78,29 @@ blurconsole.model = (function() {
 			});
 
 			return tableMap;
-		};
+		}
 
-		isDataLoaded = function() {
+		function isDataLoaded() {
 			return stateMap.currentTables !== null;
-		};
+		}
 
-		disableTable = function(tableName) {
+		function disableTable(tableName) {
 			configMap.poller.disableTable(tableName);
-		};
+		}
 
-		enableTable = function(tableName) {
+		function enableTable(tableName) {
 			configMap.poller.enableTable(tableName);
-		};
+		}
 
-		deleteTable = function(tableName, includeFiles) {
+		function deleteTable(tableName, includeFiles) {
 			configMap.poller.deleteTable(tableName, includeFiles);
-		};
+		}
 
-		getSchema = function(tableName, callback) {
+		function getSchema(tableName, callback) {
 			configMap.poller.getSchema(tableName, callback);
-		};
+		}
 
-		getFamilies = function(tableName) {
+		function getFamilies(tableName) {
 			var table;
 
 			$.each(stateMap.currentTables, function(idx, t) {
@@ -110,13 +111,13 @@ blurconsole.model = (function() {
 			});
 
 			return table.families;
-		};
+		}
 
-		findTerms = function(table, family, column, startsWith) {
+		function findTerms(table, family, column, startsWith) {
 			configMap.poller.findTerms(table, family, column, startsWith, function(terms) {
 				$.gevent.publish('terms-updated', terms);
 			});
-		};
+		}
 
 		return {
 			getClusters : getClusters,
@@ -133,43 +134,45 @@ blurconsole.model = (function() {
 		};
 	}());
 
-	nodes = (function() {
-		var getOnlineZookeeperNodes = function() {
+	var nodes = (function() {
+		//------------- Private Methods -----------------
+		function _getClusterData(clusterName) {
+			var clusterData = $.grep(stateMap.nodeMap.clusters, function(cluster) {
+				return cluster.name === clusterName;
+			});
+			return clusterData.length > 0 ? clusterData[0] : null;
+		}
+
+		//------------- Public API ----------------------
+		function getOnlineZookeeperNodes() {
 			return stateMap.nodeMap.zookeepers.online;
-		};
+		}
 
-		var getOfflineZookeeperNodes = function() {
+		function getOfflineZookeeperNodes() {
 			return stateMap.nodeMap.zookeepers.offline;
-		};
+		}
 
-		var getOnlineControllerNodes = function() {
+		function getOnlineControllerNodes() {
 			return stateMap.nodeMap.controllers.online;
-		};
+		}
 
-		var getOfflineControllerNodes = function() {
+		function getOfflineControllerNodes() {
 			return stateMap.nodeMap.controllers.offline;
-		};
-
-		var _getClusterData = function(clusterName) {
-			var clusterData = $.grep(stateMap.nodeMap.clusters, function(cluster) {
-				return cluster.name === clusterName;
-			});
-			return clusterData.length > 0 ? clusterData[0] : null;
-		};
+		}
 
-		var getOfflineShardNodes = function(clusterName) {
+		function getOfflineShardNodes(clusterName) {
 			var clusterData = _getClusterData(clusterName);
 			return clusterData ? clusterData.offline : [];
-		};
+		}
 
-		var getOnlineShardNodes = function(clusterName) {
+		function getOnlineShardNodes(clusterName) {
 			var clusterData = _getClusterData(clusterName);
 			return clusterData ? clusterData.online : [];
-		};
+		}
 
-		var isDataLoaded = function() {
+		function isDataLoaded() {
 			return stateMap.nodeMap !== null;
-		};
+		}
 
 		return {
 			getOnlineZookeeperNodes : getOnlineZookeeperNodes,
@@ -182,36 +185,51 @@ blurconsole.model = (function() {
 		};
 	}());
 
-	metrics = (function() {
-		var getZookeeperChartData, getControllerChartData, getClusters, getShardChartData, getTableChartData,
-			getQueryLoadChartData, buildPieChartData, getSlowQueryWarnings;
+	var metrics = (function() {
+		//------------- Private Methods ------------------
+		function _buildPieChartData(onlineCount, offlineCount) {
+			var onlineChart = {
+				'label':'Online',
+				'color':'#66CDCC',
+				'data':[[0,onlineCount]]
+			};
+
+			var offlineChart = {
+				'label':'Offline',
+				'color':'#FF1919',
+				'data':[[0,offlineCount]]
+			};
 
-		getZookeeperChartData = function() {
-			return buildPieChartData(stateMap.nodeMap.zookeepers.online.length, stateMap.nodeMap.zookeepers.offline.length);
-		};
+			return [onlineChart, offlineChart];
+		}
 
-		getControllerChartData = function() {
-			return buildPieChartData(stateMap.nodeMap.controllers.online.length, stateMap.nodeMap.controllers.offline.length);
-		};
+		//------------- Public API -----------------------
+		function getZookeeperChartData() {
+			return _buildPieChartData(stateMap.nodeMap.zookeepers.online.length, stateMap.nodeMap.zookeepers.offline.length);
+		}
+
+		function getControllerChartData() {
+			return _buildPieChartData(stateMap.nodeMap.controllers.online.length, stateMap.nodeMap.controllers.offline.length);
+		}
 
-		getClusters = function() {
+		function getClusters() {
 			return $.map(stateMap.nodeMap.clusters, function(cluster) {
 				return cluster.name;
 			});
-		};
+		}
 
-		getShardChartData = function(clusterName) {
+		function getShardChartData(clusterName) {
 			var clusterData = $.grep(stateMap.nodeMap.clusters, function(cluster) {
 				return cluster.name === clusterName;
 			});
 
 			if (clusterData.length > 0) {
-				return buildPieChartData(clusterData[0].online.length, clusterData[0].offline.length);
+				return _buildPieChartData(clusterData[0].online.length, clusterData[0].offline.length);
 			}
 			return null;
-		};
+		}
 
-		getTableChartData = function() {
+		function getTableChartData() {
 			var enabledData = blurconsole.utils.reduce(stateMap.currentTables, [], function(accumulator,
table){
 				var currentCluster = $.grep(accumulator, function(item){
 					return item[0] === table.cluster;
@@ -262,9 +280,9 @@ blurconsole.model = (function() {
 					'stack' : true
 				}
 			];
-		};
+		}
 
-		getQueryLoadChartData = function() {
+		function getQueryLoadChartData() {
 			var total = 0,
 				queryArray = [],
 				meanArray = [],
@@ -283,28 +301,12 @@ blurconsole.model = (function() {
 				meanArray.push([idx, mean]);
 			});
 
-			return [queryArray, meanArray];
-		};
-
-		buildPieChartData = function(onlineCount, offlineCount) {
-			var onlineChart = {
-				'label':'Online',
-				'color':'#66CDCC',
-				'data':[[0,onlineCount]]
-			};
-
-			var offlineChart = {
-				'label':'Offline',
-				'color':'#FF1919',
-				'data':[[0,offlineCount]]
-			};
-
-			return [onlineChart, offlineChart];
-		};
+			return [{label: 'Queries', data: queryArray}, {label:'Average', data:meanArray}];
+		}
 
-		getSlowQueryWarnings = function() {
+		function getSlowQueryWarnings() {
 			return stateMap.queries.slowQueries;
-		};
+		}
 
 		return {
 			getZookeeperChartData : getZookeeperChartData,
@@ -317,11 +319,22 @@ blurconsole.model = (function() {
 		};
 	}());
 
-	queries = (function() {
-		var queriesForTable, cancelQuery, tableHasActivity, matchesFilter,
-			states = ['running', 'interrupted', 'complete', 'backpressureinterrupted'];
+	var queries = (function() {
+		var states = ['running', 'interrupted', 'complete', 'backpressureinterrupted'];
+
+		//-------------- Private Methods -------------------
+		function _matchesFilter(queryData, filterText) {
+			var queryStr = queryData.user + '~~~' + queryData.query + '~~~' + states[queryData.state];
+
+			if (filterText === null || filterText === '') {
+				return true;
+			}
+
+			return queryStr.toLowerCase().indexOf(filterText.toLowerCase()) !== -1;
+		}
 
-		queriesForTable = function(table, sort, filter) {
+		//-------------- Public API -----------------------
+		function queriesForTable(table, sort, filter) {
 			var queries = [], qSort, sortField, sortDir;
 
 			qSort = (sort || 'startTime~desc').split('~');
@@ -329,7 +342,7 @@ blurconsole.model = (function() {
 			sortDir = qSort.length > 1 ? qSort[1] : 'asc';
 
 			$.each(stateMap.queries.queries, function(i, query){
-				if (query.table === table && matchesFilter(query, filter)) {
+				if (query.table === table && _matchesFilter(query, filter)) {
 					queries.push(query);
 				}
 			});
@@ -343,13 +356,13 @@ blurconsole.model = (function() {
 			});
 
 			return queries;
-		};
+		}
 
-		cancelQuery = function(table, uuid) {
+		function cancelQuery(table, uuid) {
 			configMap.poller.cancelQuery(uuid);
-		};
+		}
 
-		tableHasActivity = function(table) {
+		function tableHasActivity(table) {
 			var hasActivity = false;
 			$.each(stateMap.queries.queries, function(i, query){
 				if (query.table === table) {
@@ -358,17 +371,7 @@ blurconsole.model = (function() {
 				}
 			});
 			return hasActivity;
-		};
-
-		matchesFilter = function(queryData, filterText) {
-			var queryStr = queryData.user + '~~~' + queryData.query + '~~~' + states[queryData.state];
-
-			if (filterText === null || filterText === '') {
-				return true;
-			}
-
-			return queryStr.toLowerCase().indexOf(filterText.toLowerCase()) !== -1;
-		};
+		}
 
 		return {
 			queriesForTable : queriesForTable,
@@ -377,12 +380,30 @@ blurconsole.model = (function() {
 		};
 	}());
 
-	search = (function() {
-		var results = {}, totalRecords = 0, currentQuery, currentTable, currentArgs = {start: 0,
fetch: 10, rowRecordOption: 'rowrow', families: null},
-			runSearch, getResults, getFamilies, loadMoreResults, getTotal,
-			sendSearch, processResults;
+	var search = (function() {
+		var results = {}, totalRecords = 0, currentQuery, currentTable, currentArgs = {start: 0,
fetch: 10, rowRecordOption: 'rowrow', families: null};
+
+		//-------------- Private Methods -------------------------
+		function _sendSearch() {
+			configMap.poller.sendSearch(currentQuery, currentTable, currentArgs, _processResults);
+		}
+
+		function _processResults(data) {
+			var dataFamilies = data.families;
+			var dataResults = data.results;
+			totalRecords = data.total;
 
-		runSearch = function( query, table, searchArgs ) {
+			if (typeof dataResults !== 'undefined' && dataResults !== null) {
+				$.each(dataResults, function(family, resultList){
+					var dataList = results[family] || [];
+					results[family] = dataList.concat(resultList);
+				});
+			}
+			$.gevent.publish('results-updated', [dataFamilies]);
+		}
+
+		//-------------- Public API ------------------------------
+		function runSearch( query, table, searchArgs ) {
 			var parsedFamilies = blurconsole.utils.findFamilies(query);
 
 			currentQuery = query;
@@ -392,18 +413,18 @@ blurconsole.model = (function() {
 				currentArgs.families = parsedFamilies;
 			}
 			results = {};
-			sendSearch();
-		};
+			_sendSearch();
+		}
 
-		getResults = function() {
+		function getResults() {
 			return results;
-		};
+		}
 
-		getTotal = function() {
+		function getTotal() {
 			return totalRecords;
-		};
+		}
 
-		loadMoreResults = function(family) {
+		function loadMoreResults(family) {
 			var alreadyLoadedResults = results[family];
 
 			if (typeof alreadyLoadedResults === 'undefined' || alreadyLoadedResults === null) {
@@ -417,55 +438,33 @@ blurconsole.model = (function() {
 			// currentArgs.start = alreadyLoadedResults ? alreadyLoadedResults.length : 0;
 			currentArgs.fetch = 10;
 			currentArgs.families = [family];
-			sendSearch();
-		};
-
-		sendSearch = function() {
-			configMap.poller.sendSearch(currentQuery, currentTable, currentArgs, processResults);
-		};
-
-		processResults = function(data) {
-			var dataFamilies, dataResults;
-
-			dataFamilies = data.families;
-			dataResults = data.results;
-			totalRecords = data.total;
-
-			if (typeof dataResults !== 'undefined' && dataResults !== null) {
-				$.each(dataResults, function(family, resultList){
-					var dataList = results[family] || [];
-					results[family] = dataList.concat(resultList);
-				});
-			}
-			$.gevent.publish('results-updated', [dataFamilies]);
-		};
+			_sendSearch();
+		}
 
 		return {
 			runSearch: runSearch,
 			getResults: getResults,
-			getFamilies: getFamilies,
 			loadMoreResults: loadMoreResults,
 			getTotal: getTotal
 		};
 	}());
 
-	logs = (function() {
-		var logError, clearErrors, getLogs;
-
-		logError = function(error, module) {
+	var logs = (function() {
+		//------------- Public API -------------------
+		function logError(error, module) {
 			stateMap.errors.push({error: error, module: module, timestamp: new Date()});
 			$.gevent.publish('logging-updated');
-		};
+		}
 
-		clearErrors = function() {
+		function clearErrors() {
 			delete stateMap.errors;
 			stateMap.errors = [];
 			$.gevent.publish('logging-updated');
-		};
+		}
 
-		getLogs = function() {
+		function getLogs() {
 			return stateMap.errors;
-		};
+		}
 
 		return {
 			logError: logError,
@@ -474,23 +473,33 @@ blurconsole.model = (function() {
 		};
 	}());
 
-	nodePoller = function() {
-		configMap.poller.getNodeList(updateNodes);
-	};
+	//----------------------- Private Methods -------------------------
+	function _nodePoller() {
+		configMap.poller.getNodeList(_updateNodes);
+	}
+
+	function _tablePoller() {
+		configMap.poller.getTableList(_updateTables);
+	}
+
+	function _queryPerformancePoller() {
+		configMap.poller.getQueryPerformance(_updateQueryPerformance);
+	}
 
-	updateNodes = function(nodes) {
+	function _queryPoller() {
+		configMap.poller.getQueries(_updateQueries);
+	}
+
+	//----------------------- Event Handlers --------------------------
+	function _updateNodes(nodes) {
 		if (nodes !== 'error' && !blurconsole.utils.equals(nodes, stateMap.nodeMap)) {
 			stateMap.nodeMap = nodes;
 			$.gevent.publish('node-status-updated');
 		}
-		setTimeout(nodePoller, 5000);
-	};
+		setTimeout(_nodePoller, 5000);
+	}
 
-	tablePoller = function() {
-		configMap.poller.getTableList(updateTables);
-	};
-
-	updateTables = function(data) {
+	function _updateTables(data) {
 		if (data !== 'error') {
 			var tables = data.tables, clusters = data.clusters;
 			if (!blurconsole.utils.equals(tables, stateMap.currentTables) || !blurconsole.utils.equals(clusters,
stateMap.currentClusters)) {
@@ -499,14 +508,10 @@ blurconsole.model = (function() {
 				$.gevent.publish('tables-updated');
 			}
 		}
-		setTimeout(tablePoller, 5000);
-	};
+		setTimeout(_tablePoller, 5000);
+	}
 
-	queryPerformancePoller = function() {
-		configMap.poller.getQueryPerformance(updateQueryPerformance);
-	};
-
-	updateQueryPerformance = function(performanceMetric) {
+	function _updateQueryPerformance(performanceMetric) {
 		if (performanceMetric !== 'error') {
 			if (stateMap.queryPerformance.length === 100) {
 				stateMap.queryPerformance.shift();
@@ -515,30 +520,28 @@ blurconsole.model = (function() {
 			stateMap.queryPerformance.push(performanceMetric);
 			$.gevent.publish('query-perf-updated');
 		}
-		setTimeout(queryPerformancePoller, 5000);
-	};
+		setTimeout(_queryPerformancePoller, 5000);
+	}
 
-	queryPoller = function() {
-		configMap.poller.getQueries(updateQueries);
-	};
-
-	updateQueries = function(queries) {
+	function _updateQueries(queries) {
 		if (queries !== 'error' && !blurconsole.utils.equals(queries, stateMap.queries))
{
 			stateMap.queries = queries;
 			$.gevent.publish('queries-updated');
 		}
-		setTimeout(queryPoller, 5000);
-	};
+		setTimeout(_queryPoller, 5000);
+	}
 
-	initModule = function() {
+	//----------------------- Public API ------------------------------
+	function initModule() {
 		configMap.poller = window.location.href.indexOf('fakeIt=') > -1 ? blurconsole.fake :
blurconsole.data;
 		setTimeout(function() {
-			nodePoller();
-			tablePoller();
-			queryPerformancePoller();
-			queryPoller();
+			_nodePoller();
+			_tablePoller();
+			_queryPerformancePoller();
+			_queryPoller();
 		}, 1000);
-	};
+	}
+
 	return {
 		initModule : initModule,
 		tables : tables,


Mime
View raw message