Repository: mesos Updated Branches: refs/heads/master a0fd3491e -> ce900da3d
Fixed issue in the webui where task counts did not update. Review: https://reviews.apache.org/r/38056 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/ce900da3 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/ce900da3 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/ce900da3 Branch: refs/heads/master Commit: ce900da3df6479edd4ec8224a5697049ed816c5a Parents: a0fd349 Author: haosdent huang <[email protected]> Authored: Wed Sep 23 13:47:49 2015 -0700 Committer: Niklas Q. Nielsen <[email protected]> Committed: Wed Sep 23 14:24:34 2015 -0700 ---------------------------------------------------------------------- src/webui/master/static/js/controllers.js | 172 ++++++++++++++++--------- 1 file changed, 111 insertions(+), 61 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/ce900da3/src/webui/master/static/js/controllers.js ---------------------------------------------------------------------- diff --git a/src/webui/master/static/js/controllers.js b/src/webui/master/static/js/controllers.js index c4340ab..ccf5c31 100644 --- a/src/webui/master/static/js/controllers.js +++ b/src/webui/master/static/js/controllers.js @@ -51,7 +51,7 @@ // Update the outermost scope with the new state. - function update($scope, $timeout, data) { + function updateState($scope, $timeout, data) { // Don't do anything if the data hasn't changed. if ($scope.data == data) { return true; // Continue polling. @@ -123,13 +123,6 @@ $scope.offered_cpus = 0; $scope.offered_mem = 0; - $scope.staged_tasks = $scope.state.staged_tasks; - $scope.started_tasks = $scope.state.started_tasks; - $scope.finished_tasks = $scope.state.finished_tasks; - $scope.killed_tasks = $scope.state.killed_tasks; - $scope.failed_tasks = $scope.state.failed_tasks; - $scope.lost_tasks = $scope.state.lost_tasks; - $scope.activated_slaves = $scope.state.activated_slaves; $scope.deactivated_slaves = $scope.state.deactivated_slaves; @@ -213,6 +206,20 @@ } }); + // Update the outermost scope with the metrics/snapshot endpoint. + function updateMetrics($scope, $timeout, data) { + var metrics = JSON.parse(data); + $scope.staged_tasks = metrics['master/tasks_staging']; + $scope.started_tasks = metrics['master/tasks_starting']; + $scope.finished_tasks = metrics['master/tasks_finished']; + $scope.killed_tasks = metrics['master/tasks_killed']; + $scope.failed_tasks = metrics['master/tasks_failed']; + $scope.lost_tasks = metrics['master/tasks_lost']; + + return true; // Continue polling. + } + + // Main controller that can be used to handle "global" events. E.g.,: // $scope.$on('$afterRouteChange', function() { ...; }); // @@ -247,6 +254,7 @@ $scope.delay = 2000; $scope.retry = 0; $scope.time_since_update = 0; + $scope.isErrorModalOpen = false; // Ordered Array of path => activeTab mappings. On successful route changes, // the `pathRegexp` values are matched against the current route. The first @@ -281,66 +289,94 @@ if (!matched) $scope.navbarActiveTab = null; }); - var poll = function() { - $http.get('master/state', + var popupErrorModal = function() { + if ($scope.delay >= 128000) { + $scope.delay = 2000; + } else { + $scope.delay = $scope.delay * 2; + } + + $scope.isErrorModalOpen = true; + + var errorModal = $modal.open({ + controller: function($scope, $modalInstance, scope) { + // Give the modal reference to the root scope so it can access the + // `retry` variable. It needs to be passed by reference, not by + // value, since its value is changed outside the scope of the + // modal. + $scope.rootScope = scope; + }, + resolve: { + scope: function() { return $scope; } + }, + templateUrl: "template/dialog/masterGone.html" + }); + + // Make it such that everytime we hide the error-modal, we stop the + // countdown and restart the polling. + errorModal.result.then(function() { + $scope.isErrorModalOpen = false; + + if ($scope.countdown != null) { + if ($timeout.cancel($scope.countdown)) { + // Restart since they cancelled the countdown. + $scope.delay = 2000; + } + } + + // Start polling again, but do it asynchronously (and wait at + // least a second because otherwise the error-modal won't get + // properly shown). + $timeout(pollState, 1000); + $timeout(pollMetrics, 1000); + }); + + $scope.retry = $scope.delay; + var countdown = function() { + if ($scope.retry === 0) { + errorModal.close(); + } else { + $scope.retry = $scope.retry - 1000; + $scope.countdown = $timeout(countdown, 1000); + } + }; + countdown(); + }; + + var pollState = function() { + $http.get('master/state.json', {transformResponse: function(data) { return data; }}) .success(function(data) { - if (update($scope, $timeout, data)) { + if (updateState($scope, $timeout, data)) { $scope.delay = updateInterval(_.size($scope.slaves)); - $timeout(poll, $scope.delay); + $timeout(pollState, $scope.delay); } }) .error(function() { - if ($scope.delay >= 128000) { - $scope.delay = 2000; - } else { - $scope.delay = $scope.delay * 2; + if ($scope.isErrorModalOpen === false) { + popupErrorModal(); } + }); + }; - var errorModal = $modal.open({ - controller: function($scope, $modalInstance, scope) { - // Give the modal reference to the root scope so it can access the - // `retry` variable. It needs to be passed by reference, not by - // value, since its value is changed outside the scope of the - // modal. - $scope.rootScope = scope; - }, - resolve: { - scope: function() { return $scope; } - }, - templateUrl: "template/dialog/masterGone.html" - }); - - // Make it such that everytime we hide the error-modal, we stop the - // countdown and restart the polling. - errorModal.result.then(function() { - if ($scope.countdown != null) { - if ($timeout.cancel($scope.countdown)) { - // Restart since they cancelled the countdown. - $scope.delay = 2000; - } - } - - // Start polling again, but do it asynchronously (and wait at - // least a second because otherwise the error-modal won't get - // properly shown). - $timeout(poll, 1000); - }); - - $scope.retry = $scope.delay; - var countdown = function() { - if ($scope.retry === 0) { - errorModal.close(); - } else { - $scope.retry = $scope.retry - 1000; - $scope.countdown = $timeout(countdown, 1000); - } - }; - countdown(); + var pollMetrics = function() { + $http.get('metrics/snapshot', + {transformResponse: function(data) { return data; }}) + .success(function(data) { + if (updateMetrics($scope, $timeout, data)) { + $scope.delay = updateInterval(_.size($scope.slaves)); + $timeout(pollMetrics, $scope.delay); + } + }) + .error(function() { + if ($scope.isErrorModalOpen === false) { + popupErrorModal(); + } }); }; - poll(); + pollState(); + pollMetrics(); }]); @@ -435,10 +471,6 @@ $scope.slave.frameworks = {}; $scope.slave.completed_frameworks = {}; - $scope.slave.staging_tasks = 0; - $scope.slave.starting_tasks = 0; - $scope.slave.running_tasks = 0; - // Computes framework stats by setting new attributes on the 'framework' // object. function computeFrameworkStats(framework) { @@ -471,6 +503,24 @@ $scope.alert_message = 'Failed to get slave usage / state: ' + reason; $('#alert').show(); }); + + $http.jsonp('//' + host + '/metrics/snapshot?jsonp=JSON_CALLBACK') + .success(function (response) { + if (!$scope.state) { + $scope.state = {}; + } + + $scope.state.staged_tasks = response['slave/tasks_staging']; + $scope.state.started_tasks = response['slave/tasks_starting']; + $scope.state.finished_tasks = response['slave/tasks_finished']; + $scope.state.killed_tasks = response['slave/tasks_killed']; + $scope.state.failed_tasks = response['slave/tasks_failed']; + $scope.state.lost_tasks = response['slave/tasks_lost']; + }) + .error(function(reason) { + $scope.alert_message = 'Failed to get slave metrics: ' + reason; + $('#alert').show(); + }); }; if ($scope.state) {
