You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2013/02/25 20:45:53 UTC
svn commit: r1449846 - in /incubator/mesos/trunk:
src/webui/master/static/app.js src/webui/master/static/controllers.js
src/webui/master/static/slave_executor.html
third_party/libprocess/src/statistics.cpp
Author: vinodkone
Date: Mon Feb 25 19:45:53 2013
New Revision: 1449846
URL: http://svn.apache.org/r1449846
Log:
Resource Monitoring 12: Split apart the monolithic slave controller.
From: Ben Mahler <be...@gmail.com>
Review: https://reviews.apache.org/r/9268
Modified:
incubator/mesos/trunk/src/webui/master/static/app.js
incubator/mesos/trunk/src/webui/master/static/controllers.js
incubator/mesos/trunk/src/webui/master/static/slave_executor.html
incubator/mesos/trunk/third_party/libprocess/src/statistics.cpp
Modified: incubator/mesos/trunk/src/webui/master/static/app.js
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/webui/master/static/app.js?rev=1449846&r1=1449845&r2=1449846&view=diff
==============================================================================
--- incubator/mesos/trunk/src/webui/master/static/app.js (original)
+++ incubator/mesos/trunk/src/webui/master/static/app.js Mon Feb 25 19:45:53 2013
@@ -12,8 +12,8 @@ angular.module('mesos', []).
.when('/frameworks/:id', {template: 'static/framework.html', controller: FrameworkCtrl})
.when('/slaves', {template: 'static/slaves.html', controller: SlavesCtrl})
.when('/slaves/:slave_id', {template: 'static/slave.html', controller: SlaveCtrl})
- .when('/slaves/:slave_id/frameworks/:framework_id', {template: 'static/slave_framework.html', controller: SlaveCtrl})
- .when('/slaves/:slave_id/frameworks/:framework_id/executors/:executor_id', {template: 'static/slave_executor.html', controller: SlaveCtrl})
+ .when('/slaves/:slave_id/frameworks/:framework_id', {template: 'static/slave_framework.html', controller: SlaveFrameworkCtrl})
+ .when('/slaves/:slave_id/frameworks/:framework_id/executors/:executor_id', {template: 'static/slave_executor.html', controller: SlaveExecutorCtrl})
.when('/slaves/:slave_id/browse', {template: 'static/browse.html', controller: BrowseCtrl})
.otherwise({redirectTo: '/'});
}])
Modified: incubator/mesos/trunk/src/webui/master/static/controllers.js
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/webui/master/static/controllers.js?rev=1449846&r1=1449845&r2=1449846&view=diff
==============================================================================
--- incubator/mesos/trunk/src/webui/master/static/controllers.js (original)
+++ incubator/mesos/trunk/src/webui/master/static/controllers.js Mon Feb 25 19:45:53 2013
@@ -420,96 +420,68 @@ function SlavesCtrl($scope) {
}
-// TODO(bmahler): Pull this apart into:
-// SlaveCtrl, SlaveFrameworkCtrl, SlaveExecutorCtrl.
-function SlaveCtrl($scope, $routeParams, $http) {
+function SlaveCtrl($scope, $routeParams, $http, $q) {
setNavbarActiveTab('slaves');
- // The slave controller is reused for all slave subpages, so some of the route
- // params may not be present, depending on which page is being routed.
$scope.slave_id = $routeParams.slave_id;
- if ($routeParams.framework_id) {
- $scope.framework_id = $routeParams.framework_id;
- }
- if ($routeParams.executor_id) {
- $scope.executor_id = $routeParams.executor_id;
- }
$scope.tables = {};
$scope.tables['frameworks'] = new Table('id');
$scope.tables['completed_frameworks'] = new Table('id');
- $scope.tables['executors'] = new Table('id');
- $scope.tables['completed_executors'] = new Table('id');
- $scope.tables['tasks'] = new Table('id');
- $scope.tables['queued_tasks'] = new Table('id');
- $scope.tables['completed_tasks'] = new Table('id');
$scope.columnClass = columnClass($scope);
$scope.selectColumn = selectColumn($scope);
var update = function() {
- if ($routeParams.slave_id in $scope.slaves) {
- var pid = $scope.slaves[$routeParams.slave_id].pid;
- var id = pid.substring(0, pid.indexOf('@'));
- var host = pid.substring(pid.indexOf('@') + 1);
+ if (!($routeParams.slave_id in $scope.slaves)) {
+ $scope.alert_message = 'No slave found with ID: ' + $routeParams.slave_id;
+ $('#alert').show();
+ return;
+ }
- $scope.log = function($event) {
- if (!$scope.state.log_dir) {
- $('#no-log-dir-modal').modal('show');
- } else {
- pailer(host, '/slave/log', 'Mesos Slave');
- }
+ var pid = $scope.slaves[$routeParams.slave_id].pid;
+ var id = pid.substring(0, pid.indexOf('@'));
+ var host = pid.substring(pid.indexOf('@') + 1);
+
+ $scope.log = function($event) {
+ if (!$scope.state.log_dir) {
+ $('#no-log-dir-modal').modal('show');
+ } else {
+ pailer(host, '/slave/log', 'Mesos Slave');
}
+ }
- var url = 'http://' + host + '/' + id + '/state.json?jsonp=JSON_CALLBACK';
- $http.jsonp(url)
- .success(function(data) {
- $scope.state = data;
-
- $scope.slave = {};
- $scope.slave.frameworks = {};
- $scope.slave.completed_frameworks = {};
-
- $scope.slave.staging_tasks = 0;
- $scope.slave.starting_tasks = 0;
- $scope.slave.running_tasks = 0;
-
- // Update the framework map.
- _.each($scope.state.frameworks, function(framework) {
- $scope.slave.frameworks[framework.id] = framework;
-
- var executors = {};
- _.each(framework.executors, function(executor) {
- executors[executor.id] = executor;
- });
- $scope.slave.frameworks[framework.id].executors = executors;
-
- var completed_executors = {};
- _.each(framework.completed_executors, function(executor) {
- completed_executors[executor.id] = executor;
- });
- $scope.slave.frameworks[framework.id].completed_executors = completed_executors;
- });
+ var usageRequest = $http.jsonp(
+ 'http://' + host + '/monitor/usage.json?jsonp=JSON_CALLBACK');
- // Update the completed framework map.
- _.each($scope.state.completed_frameworks, function(framework) {
- $scope.slave.completed_frameworks[framework.id] = framework;
+ var stateRequest = $http.jsonp(
+ 'http://' + host + '/' + id + '/state.json?jsonp=JSON_CALLBACK');
- var executors = {};
- _.each(framework.executors, function(executor) {
- executors[executor.id] = executor;
- });
- $scope.slave.completed_frameworks[framework.id].executors = executors;
-
- var completed_executors = {};
- _.each(framework.completed_executors, function(executor) {
- completed_executors[executor.id] = executor;
- });
- $scope.slave.completed_frameworks[framework.id].completed_executors = completed_executors;
- });
-
- // Compute the framework stats.
- _.each($scope.slave.frameworks, function(framework) {
+ $q.all([usageRequest, stateRequest]).then(function (responses) {
+ $scope.monitor = responses[0].data;
+ $scope.state = responses[1].data;
+
+ $scope.slave = {};
+ $scope.slave.frameworks = {};
+ $scope.slave.completed_frameworks = {};
+
+ $scope.slave.staging_tasks = 0;
+ $scope.slave.starting_tasks = 0;
+ $scope.slave.running_tasks = 0;
+
+ // Update the framework map.
+ _.each($scope.state.frameworks, function(framework) {
+ $scope.slave.frameworks[framework.id] = framework;
+ });
+
+ // Update the completed framework map.
+ _.each($scope.state.completed_frameworks, function(framework) {
+ $scope.slave.completed_frameworks[framework.id] = framework;
+ });
+
+ // Compute the framework stats.
+ _.each(_.values($scope.state.frameworks).concat(_.values($scope.state.completed_frameworks)),
+ function(framework) {
framework.num_tasks = 0;
framework.cpus = 0;
framework.mem = 0;
@@ -519,59 +491,179 @@ function SlaveCtrl($scope, $routeParams,
framework.cpus += executor.resources.cpus;
framework.mem += executor.resources.mem;
});
- });
+ });
- // Compute the completed framework stats.
- _.each($scope.slave.completed_frameworks, function(framework) {
- framework.num_tasks = 0;
- framework.cpus = 0;
- framework.mem = 0;
+ $('#slave').show();
+ },
+ function (reason) {
+ $scope.alert_message = 'Failed to get slave usage / state: ' + reason;
+ $('#alert').show();
+ });
+ }
- _.each(framework.executors, function(executor) {
- framework.num_tasks += _.size(executor.tasks);
- framework.cpus += executor.resources.cpus;
- framework.mem += executor.resources.mem;
- });
+ if ($scope.state) {
+ update();
+ }
+
+ $(document).on('state_updated', update);
+ $scope.$on('$beforeRouteChange', function() {
+ $(document).off('state_updated', update);
+ });
+}
+
+
+function SlaveFrameworkCtrl($scope, $routeParams, $http, $q) {
+ setNavbarActiveTab('slaves');
+
+ $scope.slave_id = $routeParams.slave_id;
+ $scope.framework_id = $routeParams.framework_id;
+
+ $scope.tables = {};
+ $scope.tables['executors'] = new Table('id');
+ $scope.tables['completed_executors'] = new Table('id');
+
+ $scope.columnClass = columnClass($scope);
+ $scope.selectColumn = selectColumn($scope);
+
+ var update = function() {
+ if (!($routeParams.slave_id in $scope.slaves)) {
+ $scope.alert_message = 'No slave found with ID: ' + $routeParams.slave_id;
+ $('#alert').show();
+ return;
+ }
+
+ var pid = $scope.slaves[$routeParams.slave_id].pid;
+ var id = pid.substring(0, pid.indexOf('@'));
+ var host = pid.substring(pid.indexOf('@') + 1);
+
+ var usageRequest = $http.jsonp(
+ 'http://' + host + '/monitor/usage.json?jsonp=JSON_CALLBACK');
+
+ var stateRequest = $http.jsonp(
+ 'http://' + host + '/' + id + '/state.json?jsonp=JSON_CALLBACK');
+
+ $q.all([usageRequest, stateRequest]).then(function (responses) {
+ $scope.monitor = responses[0].data;
+ $scope.state = responses[1].data;
+
+ $scope.slave = {};
+
+ // Find the framework; it's either active or completed.
+ $scope.framework = _.find($scope.state.frameworks.concat($scope.state.completed_frameworks),
+ function(framework) {
+ return $scope.framework_id === framework.id;
});
- // Look for the framework / executor if present in the request.
- if ($scope.framework_id) {
- // Look for the framework.
- if (_.has($scope.slave.frameworks, $scope.framework_id)) {
- $scope.framework = $scope.slave.frameworks[$scope.framework_id];
- } else if (_.has($scope.slave.completed_frameworks, $scope.framework_id)) {
- $scope.framework = $scope.slave.completed_frameworks[$scope.framework_id];
- } else {
- $scope.alert_message = 'No framework found with ID: ' + $scope.framework_id;
- $('#alert').show();
- }
-
- if ($scope.framework && $scope.executor_id) {
- // Look for the executor.
- if (_.has($scope.framework.executors, $scope.executor_id)) {
- $scope.executor = $scope.framework.executors[$scope.executor_id];
- } else if (_.has($scope.framework.completed_executors, $scope.executor_id)) {
- $scope.executor = $scope.framework.completed_executors[$scope.executor_id];
- } else {
- $scope.alert_message = 'No executor found with ID: ' + $scope.executor_id;
- $('#alert').show();
- }
- }
- }
-
- if (!$scope.framework_id || $scope.framework) {
- $('#slave').show();
- } else if ($scope.framework && (!$scope.executor_id || $scope.executor)) {
- $('#slave').show();
- }
- })
- .error(function() {
- alert('unimplemented');
- });
- } else {
+ if (!$scope.framework) {
+ $scope.alert_message = 'No framework found with ID: ' + $routeParams.framework_id;
+ $('#alert').show();
+ return;
+ }
+
+ // Construct maps of the executors.
+ $scope.framework.executors = _.object(
+ _.pluck($scope.framework.executors, 'id'), $scope.framework.executors);
+ $scope.framework.completed_executors = _.object(
+ _.pluck($scope.framework.completed_executors, 'id'), $scope.framework.completed_executors);
+
+ // Compute the framework stats.
+ $scope.framework.num_tasks = 0;
+ $scope.framework.cpus = 0;
+ $scope.framework.mem = 0;
+
+ _.each($scope.framework.executors, function(executor) {
+ $scope.framework.num_tasks += _.size(executor.tasks);
+ $scope.framework.cpus += executor.resources.cpus;
+ $scope.framework.mem += executor.resources.mem;
+ });
+
+ $('#slave').show();
+ },
+ function (reason) {
+ $scope.alert_message = 'Failed to get slave usage / state: ' + reason;
+ $('#alert').show();
+ });
+ }
+
+ if ($scope.state) {
+ update();
+ }
+
+ $(document).on('state_updated', update);
+ $scope.$on('$beforeRouteChange', function() {
+ $(document).off('state_updated', update);
+ });
+}
+
+
+function SlaveExecutorCtrl($scope, $routeParams, $http, $q) {
+ setNavbarActiveTab('slaves');
+
+ $scope.slave_id = $routeParams.slave_id;
+ $scope.framework_id = $routeParams.framework_id;
+ $scope.executor_id = $routeParams.executor_id;
+
+ $scope.tables = {};
+ $scope.tables['tasks'] = new Table('id');
+ $scope.tables['queued_tasks'] = new Table('id');
+ $scope.tables['completed_tasks'] = new Table('id');
+
+ $scope.columnClass = columnClass($scope);
+ $scope.selectColumn = selectColumn($scope);
+
+ var update = function() {
+ if (!($routeParams.slave_id in $scope.slaves)) {
$scope.alert_message = 'No slave found with ID: ' + $routeParams.slave_id;
$('#alert').show();
+ return;
}
+
+ var pid = $scope.slaves[$routeParams.slave_id].pid;
+ var id = pid.substring(0, pid.indexOf('@'));
+ var host = pid.substring(pid.indexOf('@') + 1);
+
+ var usageRequest = $http.jsonp(
+ 'http://' + host + '/monitor/usage.json?jsonp=JSON_CALLBACK');
+
+ var stateRequest = $http.jsonp(
+ 'http://' + host + '/' + id + '/state.json?jsonp=JSON_CALLBACK');
+
+ $q.all([usageRequest, stateRequest]).then(function (responses) {
+ $scope.monitor = responses[0].data;
+ $scope.state = responses[1].data;
+
+ $scope.slave = {};
+
+ // Find the framework; it's either active or completed.
+ $scope.framework = _.find($scope.state.frameworks.concat($scope.state.completed_frameworks),
+ function(framework) {
+ return $scope.framework_id === framework.id;
+ });
+
+ if (!$scope.framework) {
+ $scope.alert_message = 'No framework found with ID: ' + $routeParams.framework_id;
+ $('#alert').show();
+ return;
+ }
+
+ // Look for the executor; it's either active or completed.
+ $scope.executor = _.find($scope.framework.executors.concat($scope.framework.completed_executors),
+ function(executor) {
+ return $scope.executor_id === executor.id;
+ });
+
+ if (!$scope.executor) {
+ $scope.alert_message = 'No executor found with ID: ' + $routeParams.executor_id;
+ $('#alert').show();
+ return;
+ }
+
+ $('#slave').show();
+ },
+ function (reason) {
+ $scope.alert_message = 'Failed to get slave usage / state: ' + reason;
+ $('#alert').show();
+ });
}
if ($scope.state) {
@@ -633,4 +725,4 @@ function BrowseCtrl($scope, $routeParams
$scope.$on('$beforeRouteChange', function() {
$(document).off('state_updated', update);
});
-}
+}
\ No newline at end of file
Modified: incubator/mesos/trunk/src/webui/master/static/slave_executor.html
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/webui/master/static/slave_executor.html?rev=1449846&r1=1449845&r2=1449846&view=diff
==============================================================================
--- incubator/mesos/trunk/src/webui/master/static/slave_executor.html (original)
+++ incubator/mesos/trunk/src/webui/master/static/slave_executor.html Mon Feb 25 19:45:53 2013
@@ -60,12 +60,16 @@
<h2>Resources</h2>
<table class="table table-condensed">
<tbody>
+ <th>
+ <td></td>
+ <td>Allocated</td>
+ </th>
<tr>
<th>CPUs</th>
<td>{{executor.resources.cpus | number}}</td>
</tr>
<tr>
- <th>Memory</th>
+ <th>Mem</th>
<td>{{executor.resources.mem * (1024 * 1024) | dataSize}}</td>
</tr>
<tr>
@@ -128,11 +132,11 @@
</th>
<th ng-class="columnClass('tasks', 'resources.cpus')"
ng-click="selectColumn('tasks', 'resources.cpus')">
- <a href="">CPUs</a>
+ <a href="">CPUs (allocated)</a>
</th>
<th ng-class="columnClass('tasks', 'resources.mem')"
ng-click="selectColumn('tasks', 'resources.mem')">
- <a href="">Mem</a>
+ <a href="">Mem (allocated)</a>
</th>
<th>Executor Sandbox</th>
</tr>
@@ -172,11 +176,11 @@
</th>
<th ng-class="columnClass('completed_tasks', 'resources.cpus')"
ng-click="selectColumn('completed_tasks', 'resources.cpus')">
- <a href="">CPUs</a>
+ <a href="">CPUs (allocated)</a>
</th>
<th ng-class="columnClass('completed_tasks', 'resources.mem')"
ng-click="selectColumn('completed_tasks', 'resources.mem')">
- <a href="">Mem</a>
+ <a href="">Mem (allocated)</a>
</th>
<th>Executor Sandbox</th>
</tr>
Modified: incubator/mesos/trunk/third_party/libprocess/src/statistics.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/src/statistics.cpp?rev=1449846&r1=1449845&r2=1449846&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/src/statistics.cpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/src/statistics.cpp Mon Feb 25 19:45:53 2013
@@ -341,6 +341,9 @@ Future<Response> StatisticsProcess::snap
{
JSON::Array array;
+ Option<string> queryContext = request.query.get("context");
+ Option<string> queryName = request.query.get("name");
+
foreachkey (const string& context, statistics) {
foreachkey (const string& name, statistics[context]) {
// Exclude archived time series.
@@ -348,6 +351,14 @@ Future<Response> StatisticsProcess::snap
continue;
}
+ // Skip statistics that don't match the query, if present.
+ if (queryContext.isSome() && queryContext.get() != context) {
+ continue;
+ }
+ if (queryName.isSome() && queryName.get() != name) {
+ continue;
+ }
+
CHECK(statistics[context][name].values.size() > 0);
JSON::Object object;