Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
kzantow authored and oleg-nenashev committed Aug 23, 2016
1 parent f4edf91 commit 58ba65c
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 15 deletions.
13 changes: 13 additions & 0 deletions core/src/main/java/jenkins/install/SetupWizard.java
Expand Up @@ -309,6 +309,19 @@ public HttpResponse doPlatformPluginList() throws IOException {
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.
Expand Down
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions war/src/main/js/api/pluginManager.js
Expand Up @@ -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,
Expand Down
26 changes: 18 additions & 8 deletions war/src/main/js/pluginSetupWizardGui.js
Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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('/');
Expand Down
16 changes: 12 additions & 4 deletions war/src/main/js/templates/setupCompletePanel.hbs
Expand Up @@ -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">
Expand Down
72 changes: 72 additions & 0 deletions war/src/test/js/pluginSetupWizard-spec.js
Expand Up @@ -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': {
Expand Down

0 comments on commit 58ba65c

Please sign in to comment.