<commit_before>"use strict";
var hostsServices = soajsApp.components;
hostsServices.service('envHosts', ['ngDataApi', '$timeout', '$modal', '$compile', function(ngDataApi, $timeout, $modal, $compile) {

	function listHosts(currentScope, env, noPopulate) {
		var controllers = [];
		currentScope.hostList = [];
		if(currentScope.access.listHosts) {
			getSendDataFromServer(currentScope, ngDataApi, {
				"method": "get",
				"routeName": "/dashboard/hosts/list",
				"params": {
					"env": env
				}
			}, function(error, response) {
				if(error || !response) {
					console.log(error.message);
					currentScope.generateNewMsg(env, 'danger', 'Unable to retrieve services hosts information.');
				}
				else {
					currentScope.hostList = response;
					for(var i = 0; i < response.length; i++) {
						if(response[i].name === 'controller') {
							controllers.push({'name': 'controller', 'hostname': response[i].hostname, 'ip': response[i].ip, 'color': 'red', 'port': 4000});
						}
					}
					controllers.forEach(function(oneController) {
						invokeHostsAwareness(oneController.hostname);
					});
				}
			});
		}

		function invokeHostsAwareness(defaultControllerHost) {
			getSendDataFromServer(currentScope, ngDataApi, {
				"method": "send",
				"routeName": "/dashboard/hosts/maintenanceOperation",
				"data": {
					"serviceName": "controller",
					"operation": "awarenessStat",
					"hostname": defaultControllerHost,
					"servicePort": 4000,
					"env": env
				}
			}, function(error, response) {
				if(error || !response || !response.result || !response.data) {
					currentScope.generateNewMsg(env, 'danger', 'Unable to retrieve services hosts information.');
					console.log(error.message);
				}
				else {
					propulateServices(response.data);
				}
			});
		}

		function propulateServices(regServices) {
			for(var i = 0; i < currentScope.grid.rows.length; i++) {
				if(currentScope.grid.rows[i]['code'] === env) {

					currentScope.grid.rows[i].controllers = controllers;
					var renderedHosts = {};
					var services = Object.keys(regServices);
					services.forEach(function(serviceName) {
						var oneService = regServices[serviceName];
						if(oneService.hosts && Array.isArray(oneService.hosts) && oneService.hosts.length > 0) {
							renderedHosts[serviceName] = {
								'name': serviceName,
								'port': regServices[serviceName].port,
								'ips': [],
								'color': 'red'
							};
							if(serviceName === 'controller') {
								renderedHosts[serviceName].heartbeat = false;
							}
							else {
								renderedHosts[serviceName].healthy = false;
							}

							regServices[serviceName].hosts.forEach(function(oneHostIP) {
								var oneHost;
								if(serviceName === 'controller') {
									oneHost = {
										'ip': oneHostIP,
										'name': serviceName,
										'heartbeat': false,
										'color': 'red',
										'port': regServices[serviceName].port
									};
									controllers.forEach(function(oneCtrl) {
										if(oneCtrl.ip == oneHostIP) {
											oneHost.hostname = oneCtrl.hostname;
										}
									});

									$timeout(function() {
										currentScope.executeHeartbeatTest(env, oneHost);
									}, 2000);
								}
								else {<commit_msg>bug fix when controller is down and refresh is invoked, controller cannot be removed.<commit_after>"use strict";
var hostsServices = soajsApp.components;
hostsServices.service('envHosts', ['ngDataApi', '$timeout', '$modal', '$compile', function(ngDataApi, $timeout, $modal, $compile) {

	function listHosts(currentScope, env, noPopulate) {
		var controllers = [];
		currentScope.hostList = [];
		if(currentScope.access.listHosts) {
			getSendDataFromServer(currentScope, ngDataApi, {
				"method": "get",
				"routeName": "/dashboard/hosts/list",
				"params": {
					"env": env
				}
			}, function(error, response) {
				if(error || !response) {
					console.log(error.message);
					currentScope.generateNewMsg(env, 'danger', 'Unable to retrieve services hosts information.');
				}
				else {
					currentScope.hostList = response;
					for(var i = 0; i < response.length; i++) {
						if(response[i].name === 'controller') {
							controllers.push({'name': 'controller', 'hostname': response[i].hostname, 'ip': response[i].ip, 'color': 'red', 'port': 4000});
						}
					}
					controllers.forEach(function(oneController) {
						invokeHostsAwareness(oneController.hostname);
					});
				}
			});
		}

		function invokeHostsAwareness(defaultControllerHost) {
			getSendDataFromServer(currentScope, ngDataApi, {
				"method": "send",
				"routeName": "/dashboard/hosts/maintenanceOperation",
				"data": {
					"serviceName": "controller",
					"operation": "awarenessStat",
					"hostname": defaultControllerHost,
					"servicePort": 4000,
					"env": env
				}
			}, function(error, response) {
				if(error || !response || !response.result || !response.data) {
					currentScope.generateNewMsg(env, 'danger', 'Unable to retrieve services hosts information.');
					console.log(error.message);
				}
				else {
					propulateServices(response.data);
				}
			});
		}

		function propulateServices(regServices) {
			for(var i = 0; i < currentScope.grid.rows.length; i++) {
				if(currentScope.grid.rows[i]['code'] === env) {

					currentScope.grid.rows[i].controllers = controllers;
					var renderedHosts = {};
					var services = Object.keys(regServices);
					services.forEach(function(serviceName) {
						var oneService = regServices[serviceName];
						if(oneService.hosts && Array.isArray(oneService.hosts) && oneService.hosts.length > 0) {
							renderedHosts[serviceName] = {
								'name': serviceName,
								'port': regServices[serviceName].port,
								'ips': [],
								'color': 'red'
							};
							if(serviceName === 'controller') {
								renderedHosts[serviceName].heartbeat = false;
							}
							else {
								renderedHosts[serviceName].healthy = false;
							}

							regServices[serviceName].hosts.forEach(function(oneHostIP) {
								var oneHost;
								if(serviceName === 'controller') {
									oneHost = {
										'ip': oneHostIP,
										'name': serviceName,
										'heartbeat': false,
										'color': 'red',
										'port': regServices[serviceName].port
									};
									currentScope.hostList.forEach(function(origHostRec) {
										if(origHostRec.name === oneHost.name) {
											oneHost.hostname = origHostRec.hostname;
											oneHost.cid = origHostRec.cid;
										}
									});
									controllers.forEach(function(oneCtrl) {
										if(oneCtrl.ip == oneHostIP) {
											oneHost.hostname = oneCtrl.hostname;
										}
									});

									$timeout(function() {
										currentScope.executeHeartbeatTest(env, oneHost);
									}, 2000);
								}
								else {
{'fraction_non_alphanumeric': 0.1473437041385383, 'fraction_numerical': 0.0044027003228646906, 'mean_word_length': 2.865570051049348, 'pattern_counts': {'":': 24, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1202729', 'n_tokens_mistral': 2960, 'n_tokens_neox': 2011, 'n_words': 359}