提交 e889232b 编写于 作者: K Keith Zantow 提交者: Oliver Gondža

[FIX JENKINS-33374] - Correct Lifecycle-based restart behavior during setup wizard (#2515)

* JENKINS-33374 - correct restart behavior during setup wizard

* Add tests

* One more test

(cherry picked from commit 58ba65ca)
上级 065e1a3a
......@@ -309,6 +309,19 @@ public class SetupWizard extends PageDecorator {
return HttpResponses.okJSON();
}
/**
* Returns whether the system needs a restart, and if it is supported
* e.g. { restartRequired: true, restartSupported: false }
*/
@Restricted(DoNotUse.class) // WebOnly
public HttpResponse doRestartStatus() throws IOException {
JSONObject response = new JSONObject();
Jenkins jenkins = Jenkins.getInstance();
response.put("restartRequired", jenkins.getUpdateCenter().isRestartRequiredForCompletion());
response.put("restartSupported", jenkins.getLifecycle().canRestart());
return HttpResponses.okJSON(response);
}
/**
* Provides the list of platform plugin updates from the last time
* the upgrade was run.
......
......@@ -16,6 +16,7 @@ You may choose to continue by configuring a proxy or skipping plugin installatio
installWizard_error_header=An error occurred
installWizard_error_message=An error occurred during installation:
installWizard_error_connection=Unable to connect to Jenkins
installWizard_error_restartNotSupported=Restart is not supported, please manually restart this instance
installWizard_installCustom_title=Getting Started
installWizard_installCustom_selectAll=All
installWizard_installCustom_selectNone=None
......@@ -29,10 +30,12 @@ installWizard_installing_title=Getting Started
installWizard_installing_detailsLink=Details...
installWizard_installComplete_title=Getting Started
installWizard_installComplete_banner=Jenkins is ready!
installWizard_installComplete_bannerRestart=Jenkins is almost ready!
installWizard_pluginsInstalled_message=Your plugin installations are complete.
installWizard_installComplete_message=Your Jenkins setup is complete.
installWizard_installComplete_finishButtonLabel=Start using Jenkins
installWizard_installComplete_restartRequiredMessage=Some plugins require Jenkins to be restarted.
installWizard_installComplete_installComplete_restartRequiredMessage=Your Jenkins setup is complete, but some plugins require Jenkins to be restarted.
installWizard_installComplete_installComplete_restartRequiredNotSupportedMessage=Your Jenkins setup is complete, but some plugins require Jenkins to be restarted and it appears this instance does not support an automated restart. Please manually restart your instance now to complete installation.
installWizard_installComplete_restartLabel=Restart
installWizard_installIncomplete_title=Resume Installation
installWizard_installIncomplete_banner=Resume Installation
......
......@@ -190,8 +190,8 @@ exports.completeInstall = function(handler) {
/**
* Indicates there is a restart required to complete plugin installations
*/
exports.isRestartRequired = function(handler) {
jenkins.get('/updateCenter/api/json?tree=restartRequiredForCompletion', function(response) {
exports.getRestartStatus = function(handler) {
jenkins.get('/setupWizard/restartStatus', function(response) {
handler.call({ isError: false }, response.data);
}, {
timeout: pluginManagerErrorTimeoutMillis,
......
......@@ -421,7 +421,13 @@ var createPluginSetupWizard = function(appendTarget) {
var setupFirstUser = function() {
setPanel(firstUserPanel, {}, enableButtonsAfterFrameLoad);
};
var showSetupCompletePanel = function(messages) {
pluginManager.getRestartStatus(function(restartStatus) {
setPanel(setupCompletePanel, $.extend(restartStatus, messages));
});
};
// used to handle displays based on current Jenkins install state
var stateHandlers = {
DEFAULT: function() {
......@@ -430,8 +436,8 @@ var createPluginSetupWizard = function(appendTarget) {
$('.install-recommended').focus();
},
CREATE_ADMIN_USER: function() { setupFirstUser(); },
RUNNING: function() { setPanel(setupCompletePanel); },
INITIAL_SETUP_COMPLETED: function() { setPanel(setupCompletePanel); },
RUNNING: function() { showSetupCompletePanel(); },
INITIAL_SETUP_COMPLETED: function() { showSetupCompletePanel(); },
INITIAL_PLUGINS_INSTALLING: function() { showInstallProgress(); }
};
var showStatePanel = function(state) {
......@@ -882,7 +888,7 @@ var createPluginSetupWizard = function(appendTarget) {
var skipFirstUser = function() {
$('button').prop({disabled:true});
setPanel(setupCompletePanel, {message: translations.installWizard_firstUserSkippedMessage});
showSetupCompletePanel({message: translations.installWizard_firstUserSkippedMessage});
};
// call to setup the proxy
......@@ -938,10 +944,14 @@ var createPluginSetupWizard = function(appendTarget) {
console.log('Waiting for Jenkins to come back online...');
console.log('-------------------');
var pingUntilRestarted = function() {
pluginManager.isRestartRequired(function(isRequired) {
if(this.isError || isRequired) {
console.log('Waiting...');
setTimeout(pingUntilRestarted, 1000);
pluginManager.getRestartStatus(function(restartStatus) {
if(this.isError || restartStatus.restartRequired) {
if (this.isError || restartStatus.restartSupported) {
console.log('Waiting...');
setTimeout(pingUntilRestarted, 1000);
} else if(!restartStatus.restartSupported) {
throw new Error(translations.installWizard_error_restartNotSupported);
}
}
else {
jenkins.goTo('/');
......
......@@ -3,15 +3,23 @@
</div>
<div class="modal-body">
<div class="jumbotron welcome-panel success-panel">
{{#if restartRequired}}
<h1>{{translations.installWizard_installComplete_bannerRestart}}</h1>
{{else}}
<h1>{{translations.installWizard_installComplete_banner}}</h1>
{{/if}}
{{{message}}}
{{#if restartRequired}}
<p>{{translations.installWizard_installComplete_message}} {{translations.installWizard_installComplete_restartRequiredMessage}}</p>
<button type="button" class="btn btn-primary install-done-restart">
{{translations.installWizard_installComplete_restartLabel}}
</button>
{{#if restartSupported}}
<p>{{translations.installWizard_installComplete_installComplete_restartRequiredMessage}}</p>
<button type="button" class="btn btn-primary install-done-restart">
{{translations.installWizard_installComplete_restartLabel}}
</button>
{{else}}
<p>{{translations.installWizard_installComplete_installComplete_restartRequiredNotSupportedMessage}}</p>
{{/if}}
{{else}}
<p>{{translations.installWizard_installComplete_message}}</p>
<button type="button" class="btn btn-primary install-done">
......
......@@ -315,6 +315,78 @@ describe("pluginSetupWizard.js", function () {
});
});
it("restart required", function (done) {
var ajaxMappings = {
'/jenkins/setupWizard/restartStatus': {
status: 'ok',
data: {
restartRequired: true,
restartSupported: true,
}
},
'/jenkins/updateCenter/installStatus': {
status: 'ok',
data: {
state: 'INITIAL_SETUP_COMPLETED',
jobs: [],
}
},
};
test(function($) {
expect($('.install-done').size()).toBe(0);
expect($('.install-done-restart').size()).toBe(1);
done();
}, ajaxMappings);
});
it("restart required not supported", function (done) {
var ajaxMappings = {
'/jenkins/setupWizard/restartStatus': {
status: 'ok',
data: {
restartRequired: true,
restartSupported: false,
}
},
'/jenkins/updateCenter/installStatus': {
status: 'ok',
data: {
state: 'INITIAL_SETUP_COMPLETED',
jobs: [],
}
},
};
test(function($) {
expect($('.install-done').size()).toBe(0);
expect($('.install-done-restart').size()).toBe(0);
done();
}, ajaxMappings);
});
it("restart not required", function (done) {
var ajaxMappings = {
'/jenkins/setupWizard/restartStatus': {
status: 'ok',
data: {
restartRequired: false,
restartSupported: false,
}
},
'/jenkins/updateCenter/installStatus': {
status: 'ok',
data: {
state: 'INITIAL_SETUP_COMPLETED',
jobs: [],
}
},
};
test(function($) {
expect($('.install-done').size()).toBe(1);
expect($('.install-done-restart').size()).toBe(0);
done();
}, ajaxMappings);
});
it("resume install", function (done) {
var ajaxMappings = {
'/jenkins/updateCenter/incompleteInstallStatus': {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册