aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorStas Vilchik <stas.vilchik@sonarsource.com>2017-10-16 17:15:50 +0200
committerStas Vilchik <stas.vilchik@sonarsource.com>2017-10-17 11:32:58 +0200
commit3df08566ce8ae085a6d785bf47b411f27247f55c (patch)
tree64152df56c9fa7b98cc3269fc80539a23c5ab47d /server
parent3715dddeae5b101b705cd5d3e21d0173b445603c (diff)
downloadsonarqube-3df08566ce8ae085a6d785bf47b411f27247f55c.tar.gz
sonarqube-3df08566ce8ae085a6d785bf47b411f27247f55c.zip
SONAR-8146 Upgrade form does not fail if server stops
Diffstat (limited to 'server')
-rw-r--r--server/sonar-web/src/main/js/api/system.ts10
-rw-r--r--server/sonar-web/src/main/js/apps/maintenance/main-view.js72
-rw-r--r--server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-offline.hbs5
-rw-r--r--server/sonar-web/src/main/js/apps/maintenance/templates/maintenance-main.hbs34
4 files changed, 74 insertions, 47 deletions
diff --git a/server/sonar-web/src/main/js/api/system.ts b/server/sonar-web/src/main/js/api/system.ts
index 18851e79091..a98d8bdff8a 100644
--- a/server/sonar-web/src/main/js/api/system.ts
+++ b/server/sonar-web/src/main/js/api/system.ts
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { getJSON, post } from '../helpers/request';
+import { getJSON, post, postJSON } from '../helpers/request';
import throwGlobalError from '../app/utils/throwGlobalError';
export type SysValue = boolean | string | number | HealthType | SysValueObject | SysValueArray;
@@ -70,6 +70,14 @@ export function getSystemStatus(): Promise<any> {
return getJSON('/api/system/status');
}
+export function getMigrationStatus(): Promise<any> {
+ return getJSON('/api/system/db_migration_status');
+}
+
+export function migrateDatabase() {
+ return postJSON('/api/system/migrate_db');
+}
+
export function restart(): Promise<void | Response> {
return post('/api/system/restart').catch(throwGlobalError);
}
diff --git a/server/sonar-web/src/main/js/apps/maintenance/main-view.js b/server/sonar-web/src/main/js/apps/maintenance/main-view.js
index d3bf4f8c64c..7a0ebd4afc4 100644
--- a/server/sonar-web/src/main/js/apps/maintenance/main-view.js
+++ b/server/sonar-web/src/main/js/apps/maintenance/main-view.js
@@ -17,10 +17,10 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import $ from 'jquery';
-import Backbone from 'backbone';
import Marionette from 'backbone.marionette';
import Template from './templates/maintenance-main.hbs';
+import { getSystemStatus, getMigrationStatus, migrateDatabase } from '../../api/system';
+import { getBaseUrl } from '../../helpers/urls';
export default Marionette.ItemView.extend({
template: Template,
@@ -30,33 +30,40 @@ export default Marionette.ItemView.extend({
},
initialize() {
- this.requestOptions = {
- type: 'GET',
- url: window.baseUrl + '/api/system/' + (this.options.setup ? 'db_migration_status' : 'status')
- };
this.pollingInternal = setInterval(() => {
this.refresh();
}, 5000);
this.wasStarting = false;
},
+ getStatus() {
+ return this.options.setup ? getMigrationStatus() : getSystemStatus();
+ },
+
refresh() {
- return Backbone.ajax(this.requestOptions).done(r => {
- if (r.status === 'STARTING') {
- this.wasStarting = true;
- }
- this.model.set(r);
- this.render();
- if (this.model.get('status') === 'UP' || this.model.get('state') === 'NO_MIGRATION') {
- this.stopPolling();
- }
- if (this.model.get('status') === 'UP' && this.wasStarting) {
- this.loadPreviousPage();
+ return this.getStatus().then(
+ r => {
+ if (r.status === 'STARTING') {
+ this.wasStarting = true;
+ }
+ // unset `status` in case if was `OFFLINE` previously
+ this.model.set({ status: undefined, ...r });
+ this.render();
+ if (this.model.get('status') === 'UP' || this.model.get('state') === 'NO_MIGRATION') {
+ this.stopPolling();
+ }
+ if (this.model.get('status') === 'UP' && this.wasStarting) {
+ this.loadPreviousPage();
+ }
+ if (this.model.get('state') === 'MIGRATION_SUCCEEDED') {
+ this.loadPreviousPage();
+ }
+ },
+ () => {
+ this.model.set({ status: 'OFFLINE' });
+ this.render();
}
- if (this.model.get('state') === 'MIGRATION_SUCCEEDED') {
- this.loadPreviousPage();
- }
- });
+ );
},
stopPolling() {
@@ -64,25 +71,24 @@ export default Marionette.ItemView.extend({
},
startMigration() {
- Backbone.ajax({
- url: window.baseUrl + '/api/system/migrate_db',
- type: 'POST'
- }).done(r => {
- this.model.set(r);
- this.render();
- });
+ migrateDatabase().then(
+ r => {
+ this.model.set(r);
+ this.render();
+ },
+ () => {}
+ );
},
onRender() {
- $('.page-simple').toggleClass(
- 'panel-warning',
- this.model.get('state') === 'MIGRATION_REQUIRED'
- );
+ document
+ .querySelector('.page-simple')
+ .classList.toggle('panel-warning', this.model.get('state') === 'MIGRATION_REQUIRED');
},
loadPreviousPage() {
setInterval(() => {
- window.location = this.options.returnTo || window.baseUrl;
+ window.location = this.options.returnTo || getBaseUrl();
}, 2500);
},
diff --git a/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-offline.hbs b/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-offline.hbs
new file mode 100644
index 00000000000..6e7bac35c3f
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-offline.hbs
@@ -0,0 +1,5 @@
+<h1 class="maintenance-title text-danger">{{t 'maintenance.sonarqube_is_offline'}}</h1>
+<p class="maintenance-text">{{t 'maintenance.sonarqube_is_offline.text'}}</p>
+<p class="maintenance-text text-center">
+ <a href="{{link '/'}}">{{t 'maintenance.try_again'}}</a>
+</p>
diff --git a/server/sonar-web/src/main/js/apps/maintenance/templates/maintenance-main.hbs b/server/sonar-web/src/main/js/apps/maintenance/templates/maintenance-main.hbs
index 6b660cf1841..3a7f14e72a3 100644
--- a/server/sonar-web/src/main/js/apps/maintenance/templates/maintenance-main.hbs
+++ b/server/sonar-web/src/main/js/apps/maintenance/templates/maintenance-main.hbs
@@ -1,18 +1,26 @@
-{{#unless setup}}
+{{#eq status 'OFFLINE'}}
- {{#eq status 'UP'}}{{> '_maintenance-status-up'}}{{/eq}}
- {{#eq status 'STARTING'}}{{> '_maintenance-status-starting'}}{{/eq}}
- {{#eq status 'DOWN'}}{{> '_maintenance-status-down'}}{{/eq}}
- {{#eq status 'DB_MIGRATION_NEEDED'}}{{> '_maintenance-status-migration'}}{{/eq}}
- {{#eq status 'DB_MIGRATION_RUNNING'}}{{> '_maintenance-status-migration'}}{{/eq}}
+ {{> '_maintenance-status-offline'}}
{{else}}
- {{#eq state 'NO_MIGRATION'}}{{> '_maintenance-state-no-migration'}}{{/eq}}
- {{#eq state 'MIGRATION_REQUIRED'}}{{> '_maintenance-state-migration-required'}}{{/eq}}
- {{#eq state 'NOT_SUPPORTED'}}{{> '_maintenance-state-migration-not-supported'}}{{/eq}}
- {{#eq state 'MIGRATION_RUNNING'}}{{> '_maintenance-state-migration-running'}}{{/eq}}
- {{#eq state 'MIGRATION_SUCCEEDED'}}{{> '_maintenance-state-migration-succeeded'}}{{/eq}}
- {{#eq state 'MIGRATION_FAILED'}}{{> '_maintenance-state-migration-failed'}}{{/eq}}
+ {{#unless setup}}
-{{/unless}}
+ {{#eq status 'UP'}}{{> '_maintenance-status-up'}}{{/eq}}
+ {{#eq status 'STARTING'}}{{> '_maintenance-status-starting'}}{{/eq}}
+ {{#eq status 'DOWN'}}{{> '_maintenance-status-down'}}{{/eq}}
+ {{#eq status 'DB_MIGRATION_NEEDED'}}{{> '_maintenance-status-migration'}}{{/eq}}
+ {{#eq status 'DB_MIGRATION_RUNNING'}}{{> '_maintenance-status-migration'}}{{/eq}}
+
+ {{else}}
+
+ {{#eq state 'NO_MIGRATION'}}{{> '_maintenance-state-no-migration'}}{{/eq}}
+ {{#eq state 'MIGRATION_REQUIRED'}}{{> '_maintenance-state-migration-required'}}{{/eq}}
+ {{#eq state 'NOT_SUPPORTED'}}{{> '_maintenance-state-migration-not-supported'}}{{/eq}}
+ {{#eq state 'MIGRATION_RUNNING'}}{{> '_maintenance-state-migration-running'}}{{/eq}}
+ {{#eq state 'MIGRATION_SUCCEEDED'}}{{> '_maintenance-state-migration-succeeded'}}{{/eq}}
+ {{#eq state 'MIGRATION_FAILED'}}{{> '_maintenance-state-migration-failed'}}{{/eq}}
+
+ {{/unless}}
+
+{{/eq}}