diff --git a/app/components/swarmVisualizer/swarmVisualizer.html b/app/components/swarmVisualizer/swarmVisualizer.html index 098a854ee..d8d16a72c 100644 --- a/app/components/swarmVisualizer/swarmVisualizer.html +++ b/app/components/swarmVisualizer/swarmVisualizer.html @@ -50,6 +50,25 @@ +
+
+ Refresh +
+
+ +
+ +
+
+
@@ -75,6 +94,7 @@
{{ node.Role }}
CPU: {{ node.CPUs / 1000000000 }}
Memory: {{ node.Memory|humansize: 2 }}
+
{{ node.Status }}
diff --git a/app/components/swarmVisualizer/swarmVisualizerController.js b/app/components/swarmVisualizer/swarmVisualizerController.js index c46ec3d87..f4b4f7706 100644 --- a/app/components/swarmVisualizer/swarmVisualizerController.js +++ b/app/components/swarmVisualizer/swarmVisualizerController.js @@ -1,12 +1,57 @@ angular.module('swarmVisualizer', []) -.controller('SwarmVisualizerController', ['$q', '$scope', '$document', 'NodeService', 'ServiceService', 'TaskService', 'Notifications', -function ($q, $scope, $document, NodeService, ServiceService, TaskService, Notifications) { +.controller('SwarmVisualizerController', ['$q', '$scope', '$document', '$interval', 'NodeService', 'ServiceService', 'TaskService', 'Notifications', +function ($q, $scope, $document, $interval, NodeService, ServiceService, TaskService, Notifications) { $scope.state = { ShowInformationPanel: true, - DisplayOnlyRunningTasks: false + DisplayOnlyRunningTasks: false, + refreshRate: '5' }; + $scope.$on('$destroy', function() { + stopRepeater(); + }); + + $scope.changeUpdateRepeater = function() { + stopRepeater(); + setUpdateRepeater(); + $('#refreshRateChange').show(); + $('#refreshRateChange').fadeOut(1500); + }; + + function stopRepeater() { + var repeater = $scope.repeater; + if (angular.isDefined(repeater)) { + $interval.cancel(repeater); + repeater = null; + } + } + + function setUpdateRepeater() { + var refreshRate = $scope.state.refreshRate; + $scope.repeater = $interval(function() { + $q.all({ + nodes: NodeService.nodes(), + services: ServiceService.services(), + tasks: TaskService.tasks() + }) + .then(function success(data) { + var nodes = data.nodes; + $scope.nodes = nodes; + var services = data.services; + $scope.services = services; + var tasks = data.tasks; + $scope.tasks = tasks; + prepareVisualizerData(nodes, services, tasks); + }) + .catch(function error(err) { + stopRepeater(); + Notifications.error('Failure', err, 'Unable to retrieve cluster information'); + }); + }, refreshRate * 1000); + } + + function assignServiceName(services, tasks) { for (var i = 0; i < services.length; i++) { var service = services[i]; @@ -60,6 +105,7 @@ function ($q, $scope, $document, NodeService, ServiceService, TaskService, Notif var tasks = data.tasks; $scope.tasks = tasks; prepareVisualizerData(nodes, services, tasks); + setUpdateRepeater(); }) .catch(function error(err) { Notifications.error('Failure', err, 'Unable to initialize cluster visualizer');