Fix role limits calculation

also nodes collection becomes an abligatory attribute
in Roles.checkLimits method

Closes-Bug: #1496328

Change-Id: I363f5ad095dc27af268453d5a4f878af13ea41b0
This commit is contained in:
Julia Aranovich 2015-12-08 13:22:30 +03:00 committed by Alexey Stupnikov
parent 88e136a351
commit bea4f60cc8
3 changed files with 17 additions and 20 deletions

View File

@ -115,10 +115,11 @@ define([
this.expandedLimits = this.expandedLimits || {};
this.expandedLimits[this.get('name')] = limits;
},
checkLimits: function(models, checkLimitIsReached, limitTypes, nodes) {
checkLimits: function(models, nodes, checkLimitIsReached, limitTypes) {
/*
* Check the 'limits' section of configuration.
* models -- current model to check the limits
* models -- current models to check the limits
* nodes -- node collection to check the limits
* checkLimitIsReached -- boolean (default: true), if true then for min = 1, 1 node is allowed
* if false, then for min = 1, 1 node is not allowed anymore
* This is because validation runs in 2 modes: validate current model as is
@ -127,7 +128,6 @@ define([
* - the model is valid as is (return true) -- case for checkLimitIsReached = true
* - there can be no more nodes added (return false) -- case for checkLimitIsReached = false
* limitType -- array of limit types to check. Possible choices are 'min', 'max', 'recommended'
* nodes -- node collection to check the limits, cluster nodes collection by default
**/
// Default values
@ -161,9 +161,10 @@ define([
min: evaluateExpressionHelper(limits.min, models).value,
recommended: evaluateExpressionHelper(limits.recommended, models).value
},
count = nodes ? nodes.length : models.cluster.get('nodes').nodesAfterDeploymentWithRole(name).length,
count = nodes.nodesAfterDeploymentWithRole(name).length,
messages,
label = this.get('label');
var checkOneLimit = function(obj, limitType) {
var limitValue,
comparator;
@ -212,7 +213,6 @@ define([
if (checkedLimitTypes[limitType]) {
return;
}
return checkOneLimit(limitValues, limitType);
})
.flatten()

View File

@ -395,10 +395,10 @@ function(_, i18n, $, React, utils, models, dispatcher, dialogs, componentMixins,
return !role.checkRestrictions(configModels).result;
}),
limitValidations = _.zipObject(validRoleModels.map(function(role) {
return [role.get('name'), role.checkLimits(configModels)];
return [role.get('name'), role.checkLimits(configModels, cluster.get('nodes'))];
})),
limitRecommendations = _.zipObject(validRoleModels.map(function(role) {
return [role.get('name'), role.checkLimits(configModels, true, ['recommended'])];
return [role.get('name'), role.checkLimits(configModels, cluster.get('nodes'), true, ['recommended'])];
}));
return {
blocker: roleModels.map(_.bind(

View File

@ -202,18 +202,24 @@ function($, _, i18n, Backbone, React, utils, models, dispatcher, controls, dialo
},
processRoleLimits: function() {
var cluster = this.props.cluster,
nodesForLimitCheck = this.getNodesForLimitsCheck(),
maxNumberOfNodes = [],
processedRoleLimits = {};
cluster.get('roles').map(function(role) {
var selectedNodes = this.props.nodes.filter(function(node) {
return this.props.selectedNodeIds[node.id];
}, this),
clusterNodes = this.props.cluster.get('nodes').filter(function(node) {
return !_.contains(this.props.selectedNodeIds, node.id);
}, this),
nodesForLimitCheck = new models.Nodes(_.union(selectedNodes, clusterNodes));
cluster.get('roles').each(function(role) {
if ((role.get('limits') || {}).max) {
var roleName = role.get('name'),
isRoleAlreadyAssigned = nodesForLimitCheck.any(function(node) {
return node.hasRole(roleName);
}, this);
processedRoleLimits[roleName] = role.checkLimits(this.state.configModels,
!isRoleAlreadyAssigned, ['max'], nodesForLimitCheck);
processedRoleLimits[roleName] = role.checkLimits(this.state.configModels, nodesForLimitCheck, !isRoleAlreadyAssigned, ['max']);
}
}, this);
@ -361,15 +367,6 @@ function($, _, i18n, Backbone, React, utils, models, dispatcher, controls, dialo
node.set({pending_roles: this.initialRoles[node.id]}, {silent: true});
}, this);
},
getNodesForLimitsCheck: function() {
var selectedNodes = this.props.nodes.filter(function(node) {
return this.props.selectedNodeIds[node.id];
}, this),
clusterNodes = this.props.cluster.get('nodes').filter(function(node) {
return !_.contains(this.props.selectedNodeIds, node.id);
}, this);
return new models.Nodes(_.union(selectedNodes, clusterNodes));
},
toggleLabelsPanel: function(value) {
this.setState({
isLabelsPanelOpen: _.isUndefined(value) ? !this.state.isLabelsPanelOpen : value