From ee59afd5ab00c9eba1445ab36c66f367607ebdaf Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Sat, 29 Apr 2017 15:22:21 -0700 Subject: [PATCH] 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 --- .../pgm/http/jetty/ProjectQoSFilter.java | 10 ++++----- ...abilityControl.java => AccountLimits.java} | 10 ++++----- .../server/account/GetCapabilities.java | 22 +++++++++---------- .../gerrit/server/git/ReceiveConfig.java | 14 ++++++------ .../gerrit/server/project/ProjectState.java | 4 ++-- .../gerrit/server/query/QueryProcessor.java | 10 ++++----- .../query/account/AccountQueryProcessor.java | 6 ++--- .../query/change/ChangeQueryProcessor.java | 6 ++--- .../query/group/GroupQueryProcessor.java | 6 ++--- .../gerrit/sshd/CommandExecutorProvider.java | 10 ++++----- 10 files changed, 49 insertions(+), 49 deletions(-) rename gerrit-server/src/main/java/com/google/gerrit/server/account/{CapabilityControl.java => AccountLimits.java} (93%) diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/ProjectQoSFilter.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/ProjectQoSFilter.java index 8561dce95b..35beaeb60a 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/ProjectQoSFilter.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/ProjectQoSFilter.java @@ -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 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 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); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/CapabilityControl.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountLimits.java similarity index 93% rename from gerrit-server/src/main/java/com/google/gerrit/server/account/CapabilityControl.java rename to gerrit-server/src/main/java/com/google/gerrit/server/account/AccountLimits.java index 496ea1bd7b..e8e6d9ecbd 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/CapabilityControl.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountLimits.java @@ -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; } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/GetCapabilities.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/GetCapabilities.java index fe01b322b3..616ea79ae4 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/GetCapabilities.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/GetCapabilities.java @@ -56,18 +56,18 @@ class GetCapabilities implements RestReadView { private Set query; private final PermissionBackend permissionBackend; - private final CapabilityControl.Factory capabilityFactory; + private final AccountLimits.Factory limitsFactory; private final Provider self; private final DynamicMap pluginCapabilities; @Inject GetCapabilities( PermissionBackend permissionBackend, - CapabilityControl.Factory capabilityFactory, + AccountLimits.Factory limitsFactory, Provider self, DynamicMap pluginCapabilities) { this.permissionBackend = permissionBackend; - this.capabilityFactory = capabilityFactory; + this.limitsFactory = limitsFactory; this.self = self; this.pluginCapabilities = pluginCapabilities; } @@ -85,9 +85,9 @@ class GetCapabilities implements RestReadView { 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 { return query == null || query.contains(name.toLowerCase()); } - private void addRanges(Map have, CapabilityControl cc) { + private void addRanges(Map 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 have, CapabilityControl cc) { - QueueProvider.QueueType queue = cc.getQueueType(); + private void addPriority(Map have, AccountLimits limits) { + QueueProvider.QueueType queue = limits.getQueueType(); if (queue != QueueProvider.QueueType.INTERACTIVE || (query != null && query.contains(PRIORITY))) { have.put(PRIORITY, queue); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/ReceiveConfig.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/ReceiveConfig.java index 3a82456a43..2b9f5941d6 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/ReceiveConfig.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/ReceiveConfig.java @@ -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; } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/project/ProjectState.java b/gerrit-server/src/main/java/com/google/gerrit/server/project/ProjectState.java index dfaa370f44..6e17b2c170 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/project/ProjectState.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/project/ProjectState.java @@ -120,7 +120,7 @@ public class ProjectState { final GitRepositoryManager gitMgr, final RulesCache rulesCache, final List 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)) { diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/query/QueryProcessor.java b/gerrit-server/src/main/java/com/google/gerrit/server/query/QueryProcessor.java index 0d0777fe2c..7176d809ed 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/query/QueryProcessor.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/query/QueryProcessor.java @@ -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 { protected final Provider userProvider; - private final CapabilityControl.Factory capabilityFactory; + private final AccountLimits.Factory limitsFactory; private final Metrics metrics; private final SchemaDefinitions schemaDef; private final IndexConfig indexConfig; @@ -78,7 +78,7 @@ public abstract class QueryProcessor { protected QueryProcessor( Provider userProvider, - CapabilityControl.Factory capabilityFactory, + AccountLimits.Factory limitsFactory, Metrics metrics, SchemaDefinitions schemaDef, IndexConfig indexConfig, @@ -86,7 +86,7 @@ public abstract class QueryProcessor { IndexRewriter 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 { private int getPermittedLimit() { if (enforceVisibility) { - return capabilityFactory + return limitsFactory .create(userProvider.get()) .getRange(GlobalCapability.QUERY_LIMIT) .getMax(); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/query/account/AccountQueryProcessor.java b/gerrit-server/src/main/java/com/google/gerrit/server/query/account/AccountQueryProcessor.java index 6a9b37c919..75213e718b 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/query/account/AccountQueryProcessor.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/query/account/AccountQueryProcessor.java @@ -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 { @Inject protected AccountQueryProcessor( Provider userProvider, - CapabilityControl.Factory capabilityFactory, + AccountLimits.Factory limitsFactory, Metrics metrics, IndexConfig indexConfig, AccountIndexCollection indexes, @@ -53,7 +53,7 @@ public class AccountQueryProcessor extends QueryProcessor { AccountControl.Factory accountControlFactory) { super( userProvider, - capabilityFactory, + limitsFactory, metrics, AccountSchemaDefinitions.INSTANCE, indexConfig, diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/query/change/ChangeQueryProcessor.java b/gerrit-server/src/main/java/com/google/gerrit/server/query/change/ChangeQueryProcessor.java index d8c872d6c8..f4064f5115 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/query/change/ChangeQueryProcessor.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/query/change/ChangeQueryProcessor.java @@ -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 @Inject ChangeQueryProcessor( Provider userProvider, - CapabilityControl.Factory capabilityFactory, + AccountLimits.Factory limitsFactory, Metrics metrics, IndexConfig indexConfig, ChangeIndexCollection indexes, @@ -77,7 +77,7 @@ public class ChangeQueryProcessor extends QueryProcessor DynamicMap attributeFactories) { super( userProvider, - capabilityFactory, + limitsFactory, metrics, ChangeSchemaDefinitions.INSTANCE, indexConfig, diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/query/group/GroupQueryProcessor.java b/gerrit-server/src/main/java/com/google/gerrit/server/query/group/GroupQueryProcessor.java index 6229f18ba3..e0966561bc 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/query/group/GroupQueryProcessor.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/query/group/GroupQueryProcessor.java @@ -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 { @Inject protected GroupQueryProcessor( Provider userProvider, - CapabilityControl.Factory capabilityFactory, + AccountLimits.Factory limitsFactory, Metrics metrics, IndexConfig indexConfig, GroupIndexCollection indexes, @@ -53,7 +53,7 @@ public class GroupQueryProcessor extends QueryProcessor { GroupControl.GenericFactory groupControlFactory) { super( userProvider, - capabilityFactory, + limitsFactory, metrics, GroupSchemaDefinitions.INSTANCE, indexConfig, diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/CommandExecutorProvider.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/CommandExecutorProvider.java index 5bc59e944d..993f280ed3 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/CommandExecutorProvider.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/CommandExecutorProvider.java @@ -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 { - 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()); } }