Add plugins.jsLoadTimeout configuration option

JavaScript plugin load time depends highly on the network performance.
In some cases default value of 5s would be not enough to load all
plugins. This will result in standard Gerrit error page saying that
plugin failed to load.

New configuration option plugins.jsLoadTimeout allows administrators to
configure the plugin load timeout value, giving them possibility to
increase this value when 'plugin load failed' message is showing too
often.

Change-Id: I5979bc16e218db514a7eadefb2b41eacd935897d
Signed-off-by: Dariusz Luksza <dariusz@luksza.org>
This commit is contained in:
Dariusz Luksza
2015-03-11 11:41:41 +01:00
parent 4c7c21adee
commit 98f2352a09
5 changed files with 32 additions and 6 deletions

View File

@@ -2648,6 +2648,13 @@ Enable remote installation, enable and disable of plugins over HTTP
and SSH. If set to true Administrators can install new plugins
remotely, or disable existing plugins. Defaults to false.
[[plugins.jsLoadTimeout]]plugins.jsLoadTimeout::
+
Set the timeout value for loading JavaScript plugins in Gerrit UI.
Values can be specified using standard time unit abbreviations ('ms',
'sec', 'min', etc.).
+
Default is 5 seconds. Negative values will be converted to 0.
[[receive]]
=== Section receive

View File

@@ -30,6 +30,7 @@ public class HostPageData {
public Theme theme;
public List<String> plugins;
public List<Message> messages;
public Integer pluginsLoadTimeout;
public boolean isNoteDbEnabled;
public static class Theme {

View File

@@ -579,6 +579,7 @@ public class Gerrit implements EntryPoint {
AccountApi.self().view("preferences").get(cbg.add(createMyMenuBarCallback()));
}
PluginLoader.load(hpd.plugins,
hpd.pluginsLoadTimeout,
cbg.addFinal(new GerritCallback<VoidResult>() {
@Override
public void onSuccess(VoidResult result) {

View File

@@ -32,15 +32,14 @@ import java.util.List;
/** Loads JavaScript plugins with a progress meter visible. */
public class PluginLoader extends DialogBox {
private static final int MAX_LOAD_TIME_MILLIS = 5000;
private static PluginLoader self;
public static void load(List<String> plugins,
AsyncCallback<VoidResult> callback) {
int loadTimeout, AsyncCallback<VoidResult> callback) {
if (plugins == null || plugins.isEmpty()) {
callback.onSuccess(VoidResult.create());
} else {
self = new PluginLoader(callback);
self = new PluginLoader(loadTimeout, callback);
self.load(plugins);
self.startTimers();
self.center();
@@ -51,6 +50,7 @@ public class PluginLoader extends DialogBox {
self.loadedOne();
}
private final int loadTimeout;
private final AsyncCallback<VoidResult> callback;
private ProgressBar progress;
private Timer show;
@@ -58,9 +58,10 @@ public class PluginLoader extends DialogBox {
private Timer timeout;
private boolean visible;
private PluginLoader(AsyncCallback<VoidResult> cb) {
private PluginLoader(int loadTimeout, AsyncCallback<VoidResult> cb) {
super(/* auto hide */false, /* modal */true);
callback = cb;
this.loadTimeout = loadTimeout;
progress = new ProgressBar(Gerrit.C.loadingPlugins());
setStyleName(Gerrit.RESOURCES.css().errorDialog());
@@ -98,7 +99,7 @@ public class PluginLoader extends DialogBox {
@Override
public void run() {
progress.setValue(100 * ++cycle * 250 / MAX_LOAD_TIME_MILLIS);
progress.setValue(100 * ++cycle * 250 / loadTimeout);
}
};
update.scheduleRepeating(250);
@@ -109,7 +110,7 @@ public class PluginLoader extends DialogBox {
finish();
}
};
timeout.schedule(MAX_LOAD_TIME_MILLIS);
timeout.schedule(loadTimeout);
}
private void loadedOne() {

View File

@@ -32,6 +32,7 @@ import com.google.gerrit.httpd.HtmlDomUtil;
import com.google.gerrit.httpd.WebSession;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.config.ConfigUtil;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.SitePaths;
import com.google.gerrit.server.notedb.NotesMigration;
@@ -57,6 +58,7 @@ import java.io.StringWriter;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
@@ -72,6 +74,7 @@ public class HostPageServlet extends HttpServlet {
LoggerFactory.getLogger(HostPageServlet.class);
private static final boolean IS_DEV = Boolean.getBoolean("Gerrit.GwtDevMode");
private static final String HPD_ID = "gerrit_hostpagedata";
private static final int DEFAULT_JS_LOAD_TIMEOUT = 5000;
private final Provider<CurrentUser> currentUser;
private final DynamicItem<WebSession> session;
@@ -86,6 +89,7 @@ public class HostPageServlet extends HttpServlet {
private final boolean refreshHeaderFooter;
private final StaticServlet staticServlet;
private final boolean isNoteDbEnabled;
private final Integer pluginsLoadTimeout;
private volatile Page page;
@Inject
@@ -109,6 +113,7 @@ public class HostPageServlet extends HttpServlet {
refreshHeaderFooter = cfg.getBoolean("site", "refreshHeaderFooter", true);
staticServlet = ss;
isNoteDbEnabled = migration.enabled();
pluginsLoadTimeout = getPluginsLoadTimeout(cfg);
final String pageName = "HostPage.html";
template = HtmlDomUtil.parseFile(getClass(), pageName);
@@ -156,6 +161,16 @@ public class HostPageServlet extends HttpServlet {
page = new Page();
}
private static int getPluginsLoadTimeout(final Config cfg) {
long cfgValue =
ConfigUtil.getTimeUnit(cfg, "plugins", null, "jsLoadTimeout",
DEFAULT_JS_LOAD_TIMEOUT, TimeUnit.MILLISECONDS);
if (cfgValue < 0) {
return 0;
}
return (int) cfgValue;
}
private void json(final Object data, final StringWriter w) {
JsonServlet.defaultGsonBuilder().create().toJson(data, w);
}
@@ -318,6 +333,7 @@ public class HostPageServlet extends HttpServlet {
pageData.version = Version.getVersion();
pageData.config = config;
pageData.isNoteDbEnabled = isNoteDbEnabled;
pageData.pluginsLoadTimeout = pluginsLoadTimeout;
final StringWriter w = new StringWriter();
w.write("var " + HPD_ID + "=");