Merge "Use ClusterRolesHandler as a source of available roles in UI"

This commit is contained in:
Jenkins 2015-07-09 15:22:36 +00:00 committed by Gerrit Code Review
commit ae63905b18
5 changed files with 38 additions and 32 deletions

View File

@ -260,11 +260,19 @@ define([
});
models.Role = BaseModel.extend(restrictionMixin).extend({
constructorName: 'Role'
idAttribute: 'name',
constructorName: 'Role',
parse: function(response) {
_.extend(response, _.omit(response.meta, 'name'));
response.label = response.meta.name;
delete response.meta;
return response;
}
});
models.Roles = BaseCollection.extend(restrictionMixin).extend({
constructorName: 'Roles',
comparator: 'weight',
model: models.Role,
processConflicts: function() {
this.each(function(role) {
@ -284,21 +292,7 @@ define([
models.Release = BaseModel.extend({
constructorName: 'Release',
urlRoot: '/api/releases',
parse: function(response) {
response.role_models = new models.Roles(_.map(response.roles, function(roleName) {
var roleData = response.roles_metadata[roleName];
roleData.label = roleData.name;
return _.extend(roleData, {name: roleName});
}));
response.role_models.each(function(role) {
role.expandRestrictions(role.get('restrictions'));
role.expandLimits(role.get('limits'));
});
response.role_models.processConflicts();
delete response.roles_metadata;
return response;
}
urlRoot: '/api/releases'
});
models.ReleaseNetworkProperties = BaseModel.extend({

View File

@ -98,14 +98,26 @@ function($, _, i18n, Backbone, React, utils, models, dispatcher, componentMixins
promise = tab.fetchData ? tab.fetchData({cluster: cluster, tabOptions: tabOptions}) : $.Deferred().resolve();
} else {
cluster = new models.Cluster({id: id});
var settings = new models.Settings();
settings.url = _.result(cluster, 'url') + '/attributes';
cluster.set({settings: settings});
var roles = new models.Roles();
roles.url = _.result(cluster, 'url') + '/roles';
cluster.set({roles: roles});
cluster.get('nodes').fetch = function(options) {
return this.constructor.__super__.fetch.call(this, _.extend({data: {cluster_id: id}}, options));
};
promise = $.when(cluster.fetch(), cluster.get('settings').fetch(), cluster.fetchRelated('nodes'), cluster.fetchRelated('tasks'))
promise = $.when(cluster.fetch(), cluster.get('settings').fetch(), cluster.get('roles').fetch(), cluster.fetchRelated('nodes'), cluster.fetchRelated('tasks'))
.then(function() {
cluster.get('roles').each(function(role) {
role.expandRestrictions(role.get('restrictions'));
role.expandLimits(role.get('limits'));
});
cluster.get('roles').processConflicts();
var networkConfiguration = new models.NetworkConfiguration();
networkConfiguration.url = _.result(cluster, 'url') + '/network_configuration/' + cluster.get('net_provider');
cluster.set({

View File

@ -105,7 +105,7 @@ function($, _, i18n, Backbone, React, utils, models, dispatcher, controls, dialo
maxNumberOfNodes = [],
processedRoleLimits = {};
cluster.get('release').get('role_models').map(function(role) {
cluster.get('roles').map(function(role) {
if ((role.get('limits') || {}).max) {
var roleName = role.get('name'),
isRoleAlreadyAssigned = nodesForLimitCheck.any(function(node) {
@ -454,7 +454,7 @@ function($, _, i18n, Backbone, React, utils, models, dispatcher, controls, dialo
}, this);
},
assignRoles: function() {
var roles = this.props.cluster.get('release').get('role_models');
var roles = this.props.cluster.get('roles');
this.props.nodes.each(function(node) {
if (this.props.selectedNodeIds[node.id]) roles.each(function(role) {
var roleName = role.get('name');
@ -474,7 +474,7 @@ function($, _, i18n, Backbone, React, utils, models, dispatcher, controls, dialo
var name = role.get('name'),
restrictionsCheck = role.checkRestrictions(models, 'disable'),
roleLimitsCheckResults = this.props.processedRoleLimits[name],
roles = this.props.cluster.get('release').get('role_models'),
roles = this.props.cluster.get('roles'),
conflicts = _.chain(this.props.selectedRoles)
.union(this.props.indeterminateRoles)
.map(function(role) {return roles.findWhere({name: role}).conflicts;})
@ -496,7 +496,7 @@ function($, _, i18n, Backbone, React, utils, models, dispatcher, controls, dialo
return (
<div className='well role-panel'>
<h4>{i18n('cluster_page.nodes_tab.assign_roles')}</h4>
{this.props.cluster.get('release').get('role_models').map(function(role) {
{this.props.cluster.get('roles').map(function(role) {
if (!role.checkRestrictions(this.props.configModels, 'hide').result) {
var name = role.get('name'),
processedRestrictions = this.props.nodes.length ? this.processRestrictions(role, this.props.configModels) : {};
@ -558,15 +558,15 @@ function($, _, i18n, Backbone, React, utils, models, dispatcher, controls, dialo
return i18n(ns + 'no_nodes_in_environment');
},
groupNodes: function() {
var releaseRoles = this.props.cluster.get('release').get('role_models'),
var roles = this.props.cluster.get('roles'),
method = _.bind(function(node) {
if (this.props.grouping == 'roles') return node.getRolesSummary(releaseRoles);
if (this.props.grouping == 'roles') return node.getRolesSummary(roles);
if (this.props.grouping == 'hardware') return node.getHardwareSummary();
return node.getRolesSummary(releaseRoles) + '; \u00A0' + node.getHardwareSummary();
return node.getRolesSummary(roles) + '; \u00A0' + node.getHardwareSummary();
}, this),
groups = _.pairs(_.groupBy(this.props.nodes, method));
if (this.props.grouping == 'hardware') return _.sortBy(groups, _.first);
var preferredOrder = releaseRoles.pluck('name');
var preferredOrder = roles.pluck('name');
return groups.sort(function(group1, group2) {
var roles1 = group1[1][0].sortedRoles(preferredOrder),
roles2 = group2[1][0].sortedRoles(preferredOrder),

View File

@ -274,7 +274,7 @@ function($, _, i18n, React, utils, models, Expression, componentMixins, controls
var valueAttribute = this.props.getValueAttribute(settingName),
valuesToCheck = this.getValuesToCheck(setting, valueAttribute),
pathToCheck = this.props.makePath(path, valueAttribute),
roles = this.props.cluster.get('release').get('role_models');
roles = this.props.cluster.get('roles');
return _.compact(this.props.allocatedRoles.map(function(roleName) {
var role = roles.findWhere({name: roleName});
if (_.any(role.expandedRestrictions.restrictions, function(restriction) {

View File

@ -314,24 +314,24 @@ function($, _, i18n, Backbone, React, utils, models, dispatcher, controls, compo
// Amount restrictions
function(cluster) {
var configModels = this.getConfigModels(),
roleModels = cluster.get('release').get('role_models'),
validRoleModels = roleModels.filter(function(role) {
roles = cluster.get('roles'),
validRoles = roles.filter(function(role) {
return !role.checkRestrictions(configModels).result;
}),
limitValidations = _.zipObject(validRoleModels.map(function(role) {
limitValidations = _.zipObject(validRoles.map(function(role) {
return [role.get('name'), role.checkLimits(configModels)];
})),
limitRecommendations = _.zipObject(validRoleModels.map(function(role) {
limitRecommendations = _.zipObject(validRoles.map(function(role) {
return [role.get('name'), role.checkLimits(configModels, true, ['recommended'])];
}));
return {
blocker: roleModels.map(_.bind(
blocker: roles.map(_.bind(
function(role) {
var name = role.get('name'),
limits = limitValidations[name];
return limits && !limits.valid && limits.message;
}, this)),
warning: roleModels.map(_.bind(
warning: roles.map(_.bind(
function(role) {
var name = role.get('name'),
recommendation = limitRecommendations[name];