From: Stas Vilchik Date: Wed, 13 Jan 2016 14:05:58 +0000 (+0100) Subject: SONAR-1976 Administrators should be able to request a server restart from web console X-Git-Tag: 5.4-M5~11 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7ec0fe0237570367de259b69bd71a8add7fa10b9;p=sonarqube.git SONAR-1976 Administrators should be able to request a server restart from web console --- diff --git a/server/sonar-web/src/main/js/api/system.js b/server/sonar-web/src/main/js/api/system.js index a5972203853..4ce89bf320e 100644 --- a/server/sonar-web/src/main/js/api/system.js +++ b/server/sonar-web/src/main/js/api/system.js @@ -29,3 +29,31 @@ export function getSystemInfo () { const url = window.baseUrl + '/api/system/info'; return getJSON(url); } + +export function getStatus () { + const url = window.baseUrl + '/api/system/status'; + return getJSON(url); +} + +export function restart () { + const url = window.baseUrl + '/api/system/restart'; + return post(url); +} + +const POLLING_INTERVAL = 2000; + +function pollStatus (cb) { + setTimeout(() => { + getStatus() + .then(() => cb()) + .catch(() => pollStatus(cb)); + }, POLLING_INTERVAL); +} + +function promiseStatus () { + return new Promise(resolve => pollStatus(resolve)); +} + +export function restartAndWait () { + return restart().then(promiseStatus); +} diff --git a/server/sonar-web/src/main/js/apps/system/main.js b/server/sonar-web/src/main/js/apps/system/main.js index 17615da1265..b09a129e878 100644 --- a/server/sonar-web/src/main/js/apps/system/main.js +++ b/server/sonar-web/src/main/js/apps/system/main.js @@ -19,7 +19,7 @@ */ import _ from 'underscore'; import React from 'react'; -import { getSystemInfo } from '../../api/system'; +import { getSystemInfo, restartAndWait } from '../../api/system'; import Section from './section'; import { translate } from '../../helpers/l10n'; @@ -27,6 +27,10 @@ const SECTIONS_ORDER = ['SonarQube', 'Database', 'Plugins', 'System', 'ElasticSe 'ComputeEngine']; export default React.createClass({ + getInitialState() { + return { restarting: false }; + }, + componentDidMount() { getSystemInfo().then(info => this.setState({ sections: this.parseSections(info) })); }, @@ -53,9 +57,16 @@ export default React.createClass({ return _.sortBy(items, 'name'); }, + handleServerRestart () { + this.setState({ restarting: true }); + restartAndWait().then(() => { + document.location.reload(); + }); + }, + render() { let sections = null; - if (this.state && this.state.sections) { + if (this.state.sections) { sections = this.state.sections.map(section => { return
; }); @@ -67,6 +78,16 @@ export default React.createClass({
Logs Download + {this.state.restarting ? ( + + ) : ( + + )}
{sections} diff --git a/server/sonar-web/src/main/js/apps/update-center/header-view.js b/server/sonar-web/src/main/js/apps/update-center/header-view.js index 4d2672f4f85..0ed3a8f8962 100644 --- a/server/sonar-web/src/main/js/apps/update-center/header-view.js +++ b/server/sonar-web/src/main/js/apps/update-center/header-view.js @@ -20,6 +20,7 @@ import _ from 'underscore'; import Marionette from 'backbone.marionette'; import Template from './templates/update-center-header.hbs'; +import { restartAndWait } from '../../api/system'; export default Marionette.ItemView.extend({ template: Template, @@ -29,17 +30,31 @@ export default Marionette.ItemView.extend({ }, events: { + 'click .js-restart': 'restart', 'click .js-cancel-all': 'cancelAll' }, - cancelAll: function () { + initialize () { + this.restarting = false; + }, + + restart () { + this.restarting = true; + this.render(); + restartAndWait().then(() => { + document.location.reload(true); + }); + }, + + cancelAll () { this.collection.cancelAll(); }, - serializeData: function () { + serializeData () { return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { installing: this.collection._installedCount, - uninstalling: this.collection._uninstalledCount + uninstalling: this.collection._uninstalledCount, + restarting: this.restarting }); } }); diff --git a/server/sonar-web/src/main/js/apps/update-center/templates/update-center-header.hbs b/server/sonar-web/src/main/js/apps/update-center/templates/update-center-header.hbs index 0bcfd3cd734..518c96ce81b 100644 --- a/server/sonar-web/src/main/js/apps/update-center/templates/update-center-header.hbs +++ b/server/sonar-web/src/main/js/apps/update-center/templates/update-center-header.hbs @@ -21,8 +21,13 @@ {{/if}}

-
- +
+ {{#if restarting}} + + {{else}} + + + {{/if}}
{{/any}} diff --git a/server/sonar-web/src/main/less/components/page.less b/server/sonar-web/src/main/less/components/page.less index 8d43b4bc2ab..0c1a834ddc7 100644 --- a/server/sonar-web/src/main/less/components/page.less +++ b/server/sonar-web/src/main/less/components/page.less @@ -86,10 +86,15 @@ body { float: right; margin-bottom: 10px; margin-left: 10px; + line-height: @formControlHeight; .badge { margin: 3px 0; } + + .spinner { + top: 0 !important; + } } .page-description {