- Only fail after all URLs are tried

- Move registration from servlet to manager and delay
- Fix plugin updates
- More logging
This commit is contained in:
zzz
2012-10-21 17:14:54 +00:00
parent 0fc452b683
commit 8b2889e317
8 changed files with 69 additions and 36 deletions

View File

@ -62,7 +62,7 @@ public class ConsoleUpdateManager implements UpdateManager {
/** active updating tasks, pointing to the next ones to try */
private final Map<UpdateTask, List<RegisteredUpdater>> _downloaders;
/** as reported by checkers */
private final Map<UpdateItem, VersionAvailable> _available;
private final ConcurrentHashMap<UpdateItem, VersionAvailable> _available;
/** downloaded but NOT installed */
private final Map<UpdateItem, Version> _downloaded;
/** downloaded AND installed */
@ -406,15 +406,19 @@ public class ConsoleUpdateManager implements UpdateManager {
/**
* Install a plugin. Non-blocking.
* If returns true, then call isUpdateInProgress() in a loop
* @param name if null, a new install
* @return true if task started
*/
public boolean installPlugin(URI uri) {
String fakeName = Long.toString(_context.random().nextLong());
public boolean installPlugin(String name, URI uri) {
if (name == null)
name = Long.toString(_context.random().nextLong());
List<URI> uris = Collections.singletonList(uri);
UpdateItem fake = new UpdateItem(PLUGIN_INSTALL, fakeName);
UpdateItem item = new UpdateItem(PLUGIN_INSTALL, name);
VersionAvailable va = new VersionAvailable("", "", HTTP, uris);
_available.put(fake, va);
return update(PLUGIN_INSTALL, fakeName);
_available.putIfAbsent(item, va);
if (_log.shouldLog(Log.WARN))
_log.warn("Install plugin: " + name + ' ' + va);
return update(PLUGIN_INSTALL, name);
}
/**
@ -479,8 +483,11 @@ public class ConsoleUpdateManager implements UpdateManager {
List<URI> updateSources = null;
UpdateItem ui = new UpdateItem(type, id);
VersionAvailable va = _available.get(ui);
if (va == null)
if (va == null) {
if (_log.shouldLog(Log.WARN))
_log.warn("No version available for: " + type + ' ' + id);
return false;
}
List<RegisteredUpdater> sorted = new ArrayList(_registeredUpdaters);
Collections.sort(sorted);
return retry(ui, va.sourceMap, sorted, maxTime) != null;
@ -505,14 +512,21 @@ public class ConsoleUpdateManager implements UpdateManager {
if (t != null) {
// race window here
// store the remaining ones for retrying
if (_log.shouldLog(Log.INFO))
_log.info("Starting " + r);
if (_log.shouldLog(Log.INFO))
_log.info("Starting " + r);
_downloaders.put(t, toTry);
return t;
} else {
if (_log.shouldLog(Log.WARN))
_log.warn("Updater refused: " + r + " for " + meth + ' ' + e.getValue());
}
}
}
if (_log.shouldLog(Log.WARN))
_log.warn("Nothing left to try for: " + r);
}
if (_log.shouldLog(Log.WARN))
_log.warn("Nothing left to try for: " + ui);
return null;
}
@ -1097,7 +1111,7 @@ public class ConsoleUpdateManager implements UpdateManager {
@Override
public String toString() {
return "RegisteredUpdater " + updater.getClass().getSimpleName() + " for " + type + ' ' + method + " @pri " + priority;
return "RegisteredUpdater " + updater.getClass() + " for " + type + ' ' + method + " @pri " + priority;
}
}
@ -1138,7 +1152,7 @@ public class ConsoleUpdateManager implements UpdateManager {
@Override
public String toString() {
return "RegisteredChecker " + checker.getClass().getSimpleName() + " for " + type + ' ' + method + " @pri " + priority;
return "RegisteredChecker " + checker.getClass() + " for " + type + ' ' + method + " @pri " + priority;
}
}
@ -1206,7 +1220,7 @@ public class ConsoleUpdateManager implements UpdateManager {
@Override
public String toString() {
return "VersionAvailable " + version + ' ' + sourceMap;
return "VersionAvailable \"" + version + "\" " + sourceMap;
}
}
}

View File

@ -70,10 +70,9 @@ class PluginUpdateHandler implements Checker, Updater {
return null;
Properties props = PluginStarter.pluginProperties(_context, appName);
String oldVersion = props.getProperty("version");
String xpi2pURL = props.getProperty("updateURL");
if (oldVersion == null || xpi2pURL == null) {
//updateStatus("<b>" + _("Cannot check, plugin {0} is not installed", appName) + "</b>");
return null;
if (oldVersion == null) {
// assume new install
oldVersion = "0";
}
UpdateRunner update = new PluginUpdateRunner(_context, _mgr, updateSources, appName, oldVersion);

View File

@ -111,6 +111,8 @@ class PluginUpdateRunner extends UpdateRunner {
_log.error("Error downloading plugin", t);
}
}
if (!_updated)
_mgr.notifyTaskFailed(this, "", null);
}
@Override

View File

@ -167,6 +167,7 @@ class UpdateRunner extends I2PAppThread implements UpdateTask, EepGet.StatusList
if (_log.shouldLog(Log.DEBUG))
_log.debug("Attempt failed on " + url, cause);
// ignored
_mgr.notifyAttemptFailed(this, url, null);
}
/** subclasses should override */
@ -204,10 +205,12 @@ class UpdateRunner extends I2PAppThread implements UpdateTask, EepGet.StatusList
/** subclasses should override */
public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) {
// don't display bytesTransferred as it is meaningless
_log.error("Update from " + url + " did not download completely (" +
if (_log.shouldLog(Log.WARN))
_log.warn("Update from " + url + " did not download completely (" +
bytesRemaining + " remaining after " + currentAttempt + " tries)");
updateStatus("<b>" + _("Transfer failed from {0}", linkify(url)) + "</b>");
_mgr.notifyTaskFailed(this, "", null);
_mgr.notifyAttemptFailed(this, url, null);
// update() will call notifyTaskFailed() after last URL
}
public void headerReceived(String url, int attemptNum, String key, String val) {}

View File

@ -322,7 +322,7 @@ public class ConfigClientsHandler extends FormHandler {
addFormError(_("No plugin URL specified."));
return;
}
installPlugin(url);
installPlugin(null, url);
}
private void updatePlugin(String app) {
@ -332,7 +332,7 @@ public class ConfigClientsHandler extends FormHandler {
addFormError(_("No update URL specified for {0}",app));
return;
}
installPlugin(url);
installPlugin(app, url);
}
/** @since 0.8.13 */
@ -349,7 +349,10 @@ public class ConfigClientsHandler extends FormHandler {
} catch (InterruptedException ie) {}
}
private void installPlugin(String url) {
/**
* @param app null for a new install
*/
private void installPlugin(String app, String url) {
ConsoleUpdateManager mgr = (ConsoleUpdateManager) _context.updateManager();
if (mgr == null) {
addFormError("Update manager not registered, cannot install");
@ -366,7 +369,7 @@ public class ConfigClientsHandler extends FormHandler {
addFormError(_("Bad URL {0}", url));
return;
}
if (mgr.installPlugin(uri))
if (mgr.installPlugin(app, uri))
addFormNotice(_("Downloading plugin from {0}", url));
else
addFormError("Cannot install, check logs");