summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@sonymobile.com>2015-10-22 11:56:36 +0900
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2015-10-22 13:49:06 +0900
commit6ee0a32f594c42a656e9080083e924b34779a4ab (patch)
treeddd45282b3ddb1a316f25f054796b4f034433ccb
parent10b903e488519a215dc0701c9e275745fbca5b9a (diff)
Destination: parse replication delay and retry as time unitsv2.11.5
The replication delay and retry values are interpreted as seconds and minutes respectively, but are being parsed as integers. This is inconsistent with how time units are handled in other Gerrit confiuration settings, and can cause confusion when the user configures them using the time unit syntax such as "15s" and it causes the plugin to fail with "invalid value". Change it so that the delay and retry are parsed as time units. The value can be given in any recognised time unit. Defaults remain the same as before - 15 seconds and 1 minute respectively. Change-Id: I7e518c6b8cac7f7af35d66df33eb6fd85d924eea
-rw-r--r--src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java13
-rw-r--r--src/main/resources/Documentation/config.md10
2 files changed, 16 insertions, 7 deletions
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
index a175285..eea1038 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
@@ -28,6 +28,7 @@ import com.google.gerrit.server.PluginUser;
import com.google.gerrit.server.account.GroupBackend;
import com.google.gerrit.server.account.GroupBackends;
import com.google.gerrit.server.account.ListGroupMembership;
+import com.google.gerrit.server.config.ConfigUtil;
import com.google.gerrit.server.config.FactoryModule;
import com.google.gerrit.server.config.RequestScopedReviewDbProvider;
import com.google.gerrit.server.git.GitRepositoryManager;
@@ -103,8 +104,10 @@ class Destination {
final GroupBackend groupBackend) {
remote = rc;
gitManager = gitRepositoryManager;
- delay = Math.max(0, getInt(rc, cfg, "replicationdelay", 15));
- retryDelay = Math.max(0, getInt(rc, cfg, "replicationretry", 1));
+ delay = Math.max(0,
+ getTimeUnit(rc, cfg, "replicationdelay", 15, TimeUnit.SECONDS));
+ retryDelay = Math.max(0,
+ getTimeUnit(rc, cfg, "replicationretry", 1, TimeUnit.MINUTES));
lockErrorMaxRetries = cfg.getInt("replication", "lockErrorMaxRetries", 0);
adminUrls = cfg.getStringList("remote", rc.getName(), "adminUrl");
@@ -199,6 +202,12 @@ class Destination {
return cfg.getInt("remote", rc.getName(), name, defValue);
}
+ private static int getTimeUnit(
+ RemoteConfig rc, Config cfg, String name, int defValue, TimeUnit unit) {
+ return (int)ConfigUtil.getTimeUnit(
+ cfg, "remote", rc.getName(), name, defValue, unit);
+ }
+
private boolean isVisible(final Project.NameKey project,
ReplicationState... states) {
try {
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index 29626d8..54251ce 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -183,17 +183,17 @@ remote.NAME.push
[2]: #example_file
remote.NAME.replicationDelay
-: Number of seconds to wait before scheduling a remote push
- operation. Setting the delay to 0 effectively disables the
- delay, causing the push to start as soon as possible.
+: Time to wait before scheduling a remote push operation. Setting
+ the delay to 0 effectively disables the delay, causing the push
+ to start as soon as possible.
This is a Gerrit specific extension to the Git remote block.
By default, 15 seconds.
remote.NAME.replicationRetry
-: Number of minutes to wait before scheduling a remote push
- operation previously failed due to an offline remote server.
+: Time to wait before scheduling a remote push operation previously
+ failed due to an offline remote server.
If a remote push operation fails because a remote server was
offline, all push operations to the same destination URL are