Rename CapabilityControl to AccountLimits
The class no longer controls capabilities. It now only provides limits over server resources consumed during a request. Change-Id: I70408bd5dda68b05502c4ece989b60f55793a8dd
This commit is contained in:
parent
8800928410
commit
ee59afd5ab
@ -20,7 +20,7 @@ import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE;
|
||||
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.account.CapabilityControl;
|
||||
import com.google.gerrit.server.account.AccountLimits;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.git.QueueProvider;
|
||||
import com.google.gerrit.server.git.WorkQueue.CancelableRunnable;
|
||||
@ -78,7 +78,7 @@ public class ProjectQoSFilter implements Filter {
|
||||
}
|
||||
}
|
||||
|
||||
private final CapabilityControl.Factory capabilityFactory;
|
||||
private final AccountLimits.Factory limitsFactory;
|
||||
private final Provider<CurrentUser> user;
|
||||
private final QueueProvider queue;
|
||||
private final ServletContext context;
|
||||
@ -86,12 +86,12 @@ public class ProjectQoSFilter implements Filter {
|
||||
|
||||
@Inject
|
||||
ProjectQoSFilter(
|
||||
CapabilityControl.Factory capabilityFactory,
|
||||
AccountLimits.Factory limitsFactory,
|
||||
Provider<CurrentUser> user,
|
||||
QueueProvider queue,
|
||||
ServletContext context,
|
||||
@GerritServerConfig Config cfg) {
|
||||
this.capabilityFactory = capabilityFactory;
|
||||
this.limitsFactory = limitsFactory;
|
||||
this.user = user;
|
||||
this.queue = queue;
|
||||
this.context = context;
|
||||
@ -138,7 +138,7 @@ public class ProjectQoSFilter implements Filter {
|
||||
}
|
||||
|
||||
private ScheduledThreadPoolExecutor getExecutor() {
|
||||
QueueProvider.QueueType qt = capabilityFactory.create(user.get()).getQueueType();
|
||||
QueueProvider.QueueType qt = limitsFactory.create(user.get()).getQueueType();
|
||||
return queue.getQueue(qt);
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,8 @@ import com.google.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** Access control management for server-wide capabilities. */
|
||||
public class CapabilityControl {
|
||||
/** Limits which QoS a user runs as, and how many search results it can request. */
|
||||
public class AccountLimits {
|
||||
@Singleton
|
||||
public static class Factory {
|
||||
private final ProjectCache projectCache;
|
||||
@ -37,15 +37,15 @@ public class CapabilityControl {
|
||||
this.projectCache = projectCache;
|
||||
}
|
||||
|
||||
public CapabilityControl create(CurrentUser user) {
|
||||
return new CapabilityControl(projectCache, user);
|
||||
public AccountLimits create(CurrentUser user) {
|
||||
return new AccountLimits(projectCache, user);
|
||||
}
|
||||
}
|
||||
|
||||
private final CapabilityCollection capabilities;
|
||||
private final CurrentUser user;
|
||||
|
||||
private CapabilityControl(ProjectCache projectCache, CurrentUser currentUser) {
|
||||
private AccountLimits(ProjectCache projectCache, CurrentUser currentUser) {
|
||||
capabilities = projectCache.getAllProjects().getCapabilityCollection();
|
||||
user = currentUser;
|
||||
}
|
@ -56,18 +56,18 @@ class GetCapabilities implements RestReadView<AccountResource> {
|
||||
private Set<String> query;
|
||||
|
||||
private final PermissionBackend permissionBackend;
|
||||
private final CapabilityControl.Factory capabilityFactory;
|
||||
private final AccountLimits.Factory limitsFactory;
|
||||
private final Provider<CurrentUser> self;
|
||||
private final DynamicMap<CapabilityDefinition> pluginCapabilities;
|
||||
|
||||
@Inject
|
||||
GetCapabilities(
|
||||
PermissionBackend permissionBackend,
|
||||
CapabilityControl.Factory capabilityFactory,
|
||||
AccountLimits.Factory limitsFactory,
|
||||
Provider<CurrentUser> self,
|
||||
DynamicMap<CapabilityDefinition> pluginCapabilities) {
|
||||
this.permissionBackend = permissionBackend;
|
||||
this.capabilityFactory = capabilityFactory;
|
||||
this.limitsFactory = limitsFactory;
|
||||
this.self = self;
|
||||
this.pluginCapabilities = pluginCapabilities;
|
||||
}
|
||||
@ -85,9 +85,9 @@ class GetCapabilities implements RestReadView<AccountResource> {
|
||||
have.put(p.permissionName(), true);
|
||||
}
|
||||
|
||||
CapabilityControl cc = capabilityFactory.create(rsrc.getUser());
|
||||
addRanges(have, cc);
|
||||
addPriority(have, cc);
|
||||
AccountLimits limits = limitsFactory.create(rsrc.getUser());
|
||||
addRanges(have, limits);
|
||||
addPriority(have, limits);
|
||||
|
||||
return OutputFormat.JSON
|
||||
.newGson()
|
||||
@ -117,16 +117,16 @@ class GetCapabilities implements RestReadView<AccountResource> {
|
||||
return query == null || query.contains(name.toLowerCase());
|
||||
}
|
||||
|
||||
private void addRanges(Map<String, Object> have, CapabilityControl cc) {
|
||||
private void addRanges(Map<String, Object> have, AccountLimits limits) {
|
||||
for (String name : GlobalCapability.getRangeNames()) {
|
||||
if (want(name) && cc.hasExplicitRange(name)) {
|
||||
have.put(name, new Range(cc.getRange(name)));
|
||||
if (want(name) && limits.hasExplicitRange(name)) {
|
||||
have.put(name, new Range(limits.getRange(name)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addPriority(Map<String, Object> have, CapabilityControl cc) {
|
||||
QueueProvider.QueueType queue = cc.getQueueType();
|
||||
private void addPriority(Map<String, Object> have, AccountLimits limits) {
|
||||
QueueProvider.QueueType queue = limits.getQueueType();
|
||||
if (queue != QueueProvider.QueueType.INTERACTIVE
|
||||
|| (query != null && query.contains(PRIORITY))) {
|
||||
have.put(PRIORITY, queue);
|
||||
|
@ -17,7 +17,7 @@ package com.google.gerrit.server.git;
|
||||
import static com.google.gerrit.common.data.GlobalCapability.BATCH_CHANGES_LIMIT;
|
||||
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.account.CapabilityControl;
|
||||
import com.google.gerrit.server.account.AccountLimits;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
@ -29,22 +29,22 @@ class ReceiveConfig {
|
||||
final boolean checkReferencedObjectsAreReachable;
|
||||
final boolean allowDrafts;
|
||||
private final int systemMaxBatchChanges;
|
||||
private final CapabilityControl.Factory capabilityFactory;
|
||||
private final AccountLimits.Factory limitsFactory;
|
||||
|
||||
@Inject
|
||||
ReceiveConfig(@GerritServerConfig Config config, CapabilityControl.Factory capabilityFactory) {
|
||||
ReceiveConfig(@GerritServerConfig Config config, AccountLimits.Factory limitsFactory) {
|
||||
checkMagicRefs = config.getBoolean("receive", null, "checkMagicRefs", true);
|
||||
checkReferencedObjectsAreReachable =
|
||||
config.getBoolean("receive", null, "checkReferencedObjectsAreReachable", true);
|
||||
allowDrafts = config.getBoolean("change", null, "allowDrafts", true);
|
||||
systemMaxBatchChanges = config.getInt("receive", "maxBatchChanges", 0);
|
||||
this.capabilityFactory = capabilityFactory;
|
||||
this.limitsFactory = limitsFactory;
|
||||
}
|
||||
|
||||
public int getEffectiveMaxBatchChangesLimit(CurrentUser user) {
|
||||
CapabilityControl cap = capabilityFactory.create(user);
|
||||
if (cap.hasExplicitRange(BATCH_CHANGES_LIMIT)) {
|
||||
return cap.getRange(BATCH_CHANGES_LIMIT).getMax();
|
||||
AccountLimits limits = limitsFactory.create(user);
|
||||
if (limits.hasExplicitRange(BATCH_CHANGES_LIMIT)) {
|
||||
return limits.getRange(BATCH_CHANGES_LIMIT).getMax();
|
||||
}
|
||||
return systemMaxBatchChanges;
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ public class ProjectState {
|
||||
final GitRepositoryManager gitMgr,
|
||||
final RulesCache rulesCache,
|
||||
final List<CommentLinkInfo> commentLinks,
|
||||
final CapabilityCollection.Factory capabilityFactory,
|
||||
final CapabilityCollection.Factory limitsFactory,
|
||||
@Assisted final ProjectConfig config) {
|
||||
this.sitePaths = sitePaths;
|
||||
this.projectCache = projectCache;
|
||||
@ -136,7 +136,7 @@ public class ProjectState {
|
||||
this.configs = new HashMap<>();
|
||||
this.capabilities =
|
||||
isAllProjects
|
||||
? capabilityFactory.create(config.getAccessSection(AccessSection.GLOBAL_CAPABILITIES))
|
||||
? limitsFactory.create(config.getAccessSection(AccessSection.GLOBAL_CAPABILITIES))
|
||||
: null;
|
||||
|
||||
if (isAllProjects && !Permission.canBeOnAllProjects(AccessSection.ALL, Permission.OWNER)) {
|
||||
|
@ -24,7 +24,7 @@ import com.google.gerrit.metrics.Field;
|
||||
import com.google.gerrit.metrics.MetricMaker;
|
||||
import com.google.gerrit.metrics.Timer1;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.account.CapabilityControl;
|
||||
import com.google.gerrit.server.account.AccountLimits;
|
||||
import com.google.gerrit.server.index.Index;
|
||||
import com.google.gerrit.server.index.IndexCollection;
|
||||
import com.google.gerrit.server.index.IndexConfig;
|
||||
@ -62,7 +62,7 @@ public abstract class QueryProcessor<T> {
|
||||
|
||||
protected final Provider<CurrentUser> userProvider;
|
||||
|
||||
private final CapabilityControl.Factory capabilityFactory;
|
||||
private final AccountLimits.Factory limitsFactory;
|
||||
private final Metrics metrics;
|
||||
private final SchemaDefinitions<T> schemaDef;
|
||||
private final IndexConfig indexConfig;
|
||||
@ -78,7 +78,7 @@ public abstract class QueryProcessor<T> {
|
||||
|
||||
protected QueryProcessor(
|
||||
Provider<CurrentUser> userProvider,
|
||||
CapabilityControl.Factory capabilityFactory,
|
||||
AccountLimits.Factory limitsFactory,
|
||||
Metrics metrics,
|
||||
SchemaDefinitions<T> schemaDef,
|
||||
IndexConfig indexConfig,
|
||||
@ -86,7 +86,7 @@ public abstract class QueryProcessor<T> {
|
||||
IndexRewriter<T> rewriter,
|
||||
String limitField) {
|
||||
this.userProvider = userProvider;
|
||||
this.capabilityFactory = capabilityFactory;
|
||||
this.limitsFactory = limitsFactory;
|
||||
this.metrics = metrics;
|
||||
this.schemaDef = schemaDef;
|
||||
this.indexConfig = indexConfig;
|
||||
@ -235,7 +235,7 @@ public abstract class QueryProcessor<T> {
|
||||
|
||||
private int getPermittedLimit() {
|
||||
if (enforceVisibility) {
|
||||
return capabilityFactory
|
||||
return limitsFactory
|
||||
.create(userProvider.get())
|
||||
.getRange(GlobalCapability.QUERY_LIMIT)
|
||||
.getMax();
|
||||
|
@ -19,8 +19,8 @@ import static com.google.gerrit.server.query.account.AccountQueryBuilder.FIELD_L
|
||||
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.account.AccountControl;
|
||||
import com.google.gerrit.server.account.AccountLimits;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.account.CapabilityControl;
|
||||
import com.google.gerrit.server.index.IndexConfig;
|
||||
import com.google.gerrit.server.index.IndexPredicate;
|
||||
import com.google.gerrit.server.index.account.AccountIndexCollection;
|
||||
@ -45,7 +45,7 @@ public class AccountQueryProcessor extends QueryProcessor<AccountState> {
|
||||
@Inject
|
||||
protected AccountQueryProcessor(
|
||||
Provider<CurrentUser> userProvider,
|
||||
CapabilityControl.Factory capabilityFactory,
|
||||
AccountLimits.Factory limitsFactory,
|
||||
Metrics metrics,
|
||||
IndexConfig indexConfig,
|
||||
AccountIndexCollection indexes,
|
||||
@ -53,7 +53,7 @@ public class AccountQueryProcessor extends QueryProcessor<AccountState> {
|
||||
AccountControl.Factory accountControlFactory) {
|
||||
super(
|
||||
userProvider,
|
||||
capabilityFactory,
|
||||
limitsFactory,
|
||||
metrics,
|
||||
AccountSchemaDefinitions.INSTANCE,
|
||||
indexConfig,
|
||||
|
@ -21,7 +21,7 @@ import com.google.gerrit.extensions.common.PluginDefinedInfo;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.account.CapabilityControl;
|
||||
import com.google.gerrit.server.account.AccountLimits;
|
||||
import com.google.gerrit.server.index.IndexConfig;
|
||||
import com.google.gerrit.server.index.IndexPredicate;
|
||||
import com.google.gerrit.server.index.QueryOptions;
|
||||
@ -66,7 +66,7 @@ public class ChangeQueryProcessor extends QueryProcessor<ChangeData>
|
||||
@Inject
|
||||
ChangeQueryProcessor(
|
||||
Provider<CurrentUser> userProvider,
|
||||
CapabilityControl.Factory capabilityFactory,
|
||||
AccountLimits.Factory limitsFactory,
|
||||
Metrics metrics,
|
||||
IndexConfig indexConfig,
|
||||
ChangeIndexCollection indexes,
|
||||
@ -77,7 +77,7 @@ public class ChangeQueryProcessor extends QueryProcessor<ChangeData>
|
||||
DynamicMap<ChangeAttributeFactory> attributeFactories) {
|
||||
super(
|
||||
userProvider,
|
||||
capabilityFactory,
|
||||
limitsFactory,
|
||||
metrics,
|
||||
ChangeSchemaDefinitions.INSTANCE,
|
||||
indexConfig,
|
||||
|
@ -19,7 +19,7 @@ import static com.google.gerrit.server.query.group.GroupQueryBuilder.FIELD_LIMIT
|
||||
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.account.CapabilityControl;
|
||||
import com.google.gerrit.server.account.AccountLimits;
|
||||
import com.google.gerrit.server.account.GroupControl;
|
||||
import com.google.gerrit.server.index.IndexConfig;
|
||||
import com.google.gerrit.server.index.IndexPredicate;
|
||||
@ -45,7 +45,7 @@ public class GroupQueryProcessor extends QueryProcessor<AccountGroup> {
|
||||
@Inject
|
||||
protected GroupQueryProcessor(
|
||||
Provider<CurrentUser> userProvider,
|
||||
CapabilityControl.Factory capabilityFactory,
|
||||
AccountLimits.Factory limitsFactory,
|
||||
Metrics metrics,
|
||||
IndexConfig indexConfig,
|
||||
GroupIndexCollection indexes,
|
||||
@ -53,7 +53,7 @@ public class GroupQueryProcessor extends QueryProcessor<AccountGroup> {
|
||||
GroupControl.GenericFactory groupControlFactory) {
|
||||
super(
|
||||
userProvider,
|
||||
capabilityFactory,
|
||||
limitsFactory,
|
||||
metrics,
|
||||
GroupSchemaDefinitions.INSTANCE,
|
||||
indexConfig,
|
||||
|
@ -15,27 +15,27 @@
|
||||
package com.google.gerrit.sshd;
|
||||
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.account.CapabilityControl;
|
||||
import com.google.gerrit.server.account.AccountLimits;
|
||||
import com.google.gerrit.server.git.QueueProvider;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
|
||||
class CommandExecutorProvider implements Provider<ScheduledThreadPoolExecutor> {
|
||||
private final CapabilityControl.Factory capabilityFactory;
|
||||
private final AccountLimits.Factory limitsFactory;
|
||||
private final QueueProvider queues;
|
||||
private final CurrentUser user;
|
||||
|
||||
@Inject
|
||||
CommandExecutorProvider(
|
||||
CapabilityControl.Factory capabilityFactory, QueueProvider queues, CurrentUser user) {
|
||||
this.capabilityFactory = capabilityFactory;
|
||||
AccountLimits.Factory limitsFactory, QueueProvider queues, CurrentUser user) {
|
||||
this.limitsFactory = limitsFactory;
|
||||
this.queues = queues;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScheduledThreadPoolExecutor get() {
|
||||
return queues.getQueue(capabilityFactory.create(user).getQueueType());
|
||||
return queues.getQueue(limitsFactory.create(user).getQueueType());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user