You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by mi...@apache.org on 2019/11/22 21:58:00 UTC

[trafficcontrol] branch master updated: Removed restangular from DeliveryServiceStatsService (#3614)

This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 2e89b79  Removed restangular from DeliveryServiceStatsService (#3614)
2e89b79 is described below

commit 2e89b797bca9aedb6ff9bc3024d513c69316de7c
Author: ocket8888 <oc...@gmail.com>
AuthorDate: Fri Nov 22 14:57:42 2019 -0700

    Removed restangular from DeliveryServiceStatsService (#3614)
    
    * Removed restangular from ./DeliveryServiceStatsService.js
    
    * fixed bad stats parameter
---
 .../src/common/api/DeliveryServiceStatsService.js  | 98 ++++++++++++----------
 1 file changed, 52 insertions(+), 46 deletions(-)

diff --git a/traffic_portal/app/src/common/api/DeliveryServiceStatsService.js b/traffic_portal/app/src/common/api/DeliveryServiceStatsService.js
index 1898c3d..0ffb53c 100644
--- a/traffic_portal/app/src/common/api/DeliveryServiceStatsService.js
+++ b/traffic_portal/app/src/common/api/DeliveryServiceStatsService.js
@@ -17,69 +17,75 @@
  * under the License.
  */
 
-var DeliveryServiceStatsService = function($http, $q, ENV, messageModel) {
+var DeliveryServiceStatsService = function($http, ENV, messageModel) {
 
 	this.getBPS = function(xmlId, start, end) {
-		var request = $q.defer();
+		const url = ENV.api['root'] + "deliveryservice_stats";
+		const params = {
+			deliveryServiceName: xmlId,
+			metricType: 'kbps',
+			serverType: 'edge',
+			startDate: start.seconds(0).format(),
+			endDate: end.seconds(0).format(),
+			interval: '1m'
+		};
 
-		var url = ENV.api['root'] + "deliveryservice_stats",
-			params = { deliveryServiceName: xmlId, metricType: 'kbps', serverType: 'edge', startDate: start.seconds(00).format(), endDate: end.seconds(00).format(), interval: '1m' };
-
-		$http.get(url, { params: params })
-			.then(
+		return $http.get(url, { params: params }).then(
 				function(result) {
-					request.resolve(result.data.response);
+					return result.data.response;
 				},
-				function(fault) {
-					messageModel.setMessages(fault.data.alerts, false);
-					request.reject();
+				function(err) {
+					messageModel.setMessages(err.data.alerts, false);
+					throw err;
 				}
 			);
-
-		return request.promise;
 	};
 
 	this.getTPS = function(xmlId, start, end) {
-		var request = $q.defer();
-
-		var url = ENV.api['root'] + "deliveryservice_stats",
-			params = { deliveryServiceName: xmlId, metricType: 'tps_total', serverType: 'edge', startDate: start.seconds(00).format(), endDate: end.seconds(00).format(), interval: '1m' };
-
-		$http.get(url, { params: params })
-			.then(
-				function(result) {
-					request.resolve(result.data.response);
-				},
-				function(fault) {
-					messageModel.setMessages(fault.data.alerts, false);
-					request.reject();
-				}
-			);
+		const url = ENV.api['root'] + "deliveryservice_stats";
+		const params = {
+			deliveryServiceName: xmlId,
+			metricType: 'tps_total',
+			serverType: 'edge',
+			startDate: start.seconds(0).format(),
+			endDate: end.seconds(0).format(),
+			interval: '1m'
+		};
 
-		return request.promise;
+		return $http.get(url, { params: params }).then(
+			function(result) {
+				return result.data.response;
+			},
+			function(err) {
+				messageModel.setMessages(err.data.alerts, false);
+				throw err;
+			}
+		);
 	};
 
 	this.getHttpStatusByGroup = function(xmlId, httpStatus, start, end) {
-		var request = $q.defer();
-
-		var url = ENV.api['root'] + "deliveryservice_stats",
-			params = { deliveryServiceName: xmlId, metricType: 'tps_' + httpStatus, serverType: 'edge', startDate: start.seconds(00).format(), endDate: end.seconds(00).format(), interval: '1m' };
-
-		$http.get(url, { params: params })
-			.then(
-				function(result) {
-					request.resolve(result.data.response);
-				},
-				function(fault) {
-					messageModel.setMessages(fault.data.alerts, false);
-					request.reject();
-				}
-			);
+		const url = ENV.api['root'] + "deliveryservice_stats";
+		const params = {
+			deliveryServiceName: xmlId,
+			metricType: 'tps_' + httpStatus,
+			serverType: 'edge',
+			startDate: start.seconds(0).format(),
+			endDate: end.seconds(0).format(),
+			interval: '1m'
+		};
 
-		return request.promise;
+		return $http.get(url, { params: params }).then(
+			function(result) {
+				return result.data.response;
+			},
+			function(err) {
+				messageModel.setMessages(err.data.alerts, false);
+				throw err;
+			}
+		);
 	};
 
 };
 
-DeliveryServiceStatsService.$inject = ['$http', '$q', 'ENV', 'messageModel'];
+DeliveryServiceStatsService.$inject = ['$http', 'ENV', 'messageModel'];
 module.exports = DeliveryServiceStatsService;