提交 0b3dbfce 编写于 作者: O Oleg Nenashev

Merge pull request #2319 from oleg-nenashev/JENKINS-34674

[JENKINS-34674,JENKINS-34675] - Handling of the default update site ID
......@@ -144,9 +144,10 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas
/**
* {@linkplain UpdateSite#getId() ID} of the default update site.
* @since 1.483
* @since 1.483 - public property
* @since TODO - configurable via system property
*/
public static final String ID_DEFAULT = "default";
public static final String ID_DEFAULT = System.getProperty(UpdateCenter.class.getName()+".defaultUpdateSiteId", "default");
@Restricted(NoExternalUse.class)
public static final String ID_UPLOAD = "_upload";
......@@ -290,7 +291,7 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas
/**
* Get the current connection status.
* <p>
* Supports a "siteId" request parameter, defaulting to "default" for the default
* Supports a "siteId" request parameter, defaulting to {@link #ID_DEFAULT} for the default
* update site.
*
* @return The current connection status.
......@@ -302,6 +303,9 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas
String siteId = request.getParameter("siteId");
if (siteId == null) {
siteId = ID_DEFAULT;
} else if (siteId.equals("default")) {
// If the request explicitly requires the default ID, ship it
siteId = ID_DEFAULT;
}
ConnectionCheckJob checkJob = getConnectionCheckJob(siteId);
if (checkJob == null) {
......@@ -334,7 +338,8 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas
}
return HttpResponses.okJSON(checkJob.connectionStates);
} else {
return HttpResponses.errorJSON(String.format("Unknown site '%s'.", siteId));
return HttpResponses.errorJSON(String.format("Cannot check connection status of the update site with ID='%s'"
+ ". This update center cannot be resolved", siteId));
}
} catch (Exception e) {
return HttpResponses.errorJSON(String.format("ERROR: %s", e.getMessage()));
......@@ -463,7 +468,10 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas
/**
* Alias for {@link #getById}.
* @param id ID of the update site to be retrieved
* @return Discovered {@link UpdateSite}. {@code null} if it cannot be found
*/
@CheckForNull
public UpdateSite getSite(String id) {
return getById(id);
}
......@@ -488,7 +496,10 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas
/**
* Gets {@link UpdateSite} by its ID.
* Used to bind them to URL.
* @param id ID of the update site to be retrieved
* @return Discovered {@link UpdateSite}. {@code null} if it cannot be found
*/
@CheckForNull
public UpdateSite getById(String id) {
for (UpdateSite s : sites) {
if (s.getId().equals(id)) {
......@@ -502,8 +513,9 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas
* Gets the {@link UpdateSite} from which we receive updates for <tt>jenkins.war</tt>.
*
* @return
* null if no such update center is provided.
* {@code null} if no such update center is provided.
*/
@CheckForNull
public UpdateSite getCoreSource() {
for (UpdateSite s : sites) {
Data data = s.getData();
......@@ -527,6 +539,7 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas
/**
* Gets the plugin with the given name from the first {@link UpdateSite} to contain it.
* @return Discovered {@link Plugin}. {@code null} if it cannot be found
*/
public @CheckForNull Plugin getPlugin(String artifactId) {
for (UpdateSite s : sites) {
......@@ -2042,12 +2055,19 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas
@Restricted(NoExternalUse.class)
public static void updateDefaultSite() {
final UpdateSite site = Jenkins.getInstance().getUpdateCenter().getSite(UpdateCenter.ID_DEFAULT);
if (site == null) {
LOGGER.log(Level.SEVERE, "Upgrading Jenkins. Cannot retrieve the default Update Site ''{0}''. "
+ "Plugin installation may fail.", UpdateCenter.ID_DEFAULT);
return;
}
try {
// Need to do the following because the plugin manager will attempt to access
// $JENKINS_HOME/updates/default.json. Needs to be up to date.
Jenkins.getInstance().getUpdateCenter().getSite(UpdateCenter.ID_DEFAULT).updateDirectlyNow(true);
// $JENKINS_HOME/updates/$ID_DEFAULT.json. Needs to be up to date.
site.updateDirectlyNow(true);
} catch (Exception e) {
LOGGER.log(WARNING, "Upgrading Jenkins. Failed to update default UpdateSite. Plugin upgrades may fail.", e);
LOGGER.log(WARNING, "Upgrading Jenkins. Failed to update the default Update Site '" + UpdateCenter.ID_DEFAULT +
"'. Plugin upgrades may fail.", e);
}
}
......
......@@ -67,7 +67,7 @@ public class UpdateCenterConnectionStatusTest {
JSONObject response = jenkinsRule.getJSON("updateCenter/connectionStatus?siteId=blahblah").getJSONObject();
Assert.assertEquals("error", response.getString("status"));
Assert.assertEquals("Unknown site 'blahblah'.", response.getString("message"));
Assert.assertEquals("Cannot check connection status of the update site with ID='blahblah'. This update center cannot be resolved", response.getString("message"));
}
private UpdateSite updateSite = new UpdateSite(UpdateCenter.ID_DEFAULT, "http://xyz") {
......
......@@ -889,9 +889,15 @@ var createPluginSetupWizard = function(appendTarget) {
translations = localizations;
// check for connectivity
jenkins.testConnectivity(handleGenericError(function(isConnected) {
//TODO: make the Update Center ID configurable
var siteId = 'default';
jenkins.testConnectivity(siteId, handleGenericError(function(isConnected, isFatal, errorMessage) {
if(!isConnected) {
setPanel(offlinePanel);
if (isFatal) { // We cannot continue, show error
setPanel(errorPanel, { errorMessage: 'Default update site connectivity check failed with fatal error: ' + errorMessage + '. If you see this issue for the custom Jenkins WAR bundle, consider setting the correct value of the hudson.model.UpdateCenter.defaultUpdateSiteId system property (requires Jenkins restart). Otherwise please create a bug in Jenkins JIRA.' });
} else { // The update center is offline, no problem
setPanel(offlinePanel);
}
return;
}
......
......@@ -192,18 +192,22 @@ exports.loadTranslations = function(bundleName, handler, onError) {
/**
* Runs a connectivity test, calls handler with a boolean whether there is sufficient connectivity to the internet
*/
exports.testConnectivity = function(handler) {
exports.testConnectivity = function(siteId, handler) {
// check the connectivity api
var testConnectivity = function() {
exports.get('/updateCenter/connectionStatus?siteId=default', function(response) {
exports.get('/updateCenter/connectionStatus?siteId=' + siteId, function(response) {
if(response.status !== 'ok') {
handler(false, true, response.message);
}
var uncheckedStatuses = ['PRECHECK', 'CHECKING', 'UNCHECKED'];
if(uncheckedStatuses.indexOf(response.data.updatesite) >= 0 || uncheckedStatuses.indexOf(response.data.internet) >= 0) {
setTimeout(testConnectivity, 100);
}
else {
if(response.status !== 'ok' || response.data.updatesite !== 'OK' || response.data.internet !== 'OK') {
// no connectivity
handler(false);
// no connectivity, but not fatal
handler(false, false);
}
else {
handler(true);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册