]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8146 Upgrade form does not fail if server stops
authorStas Vilchik <stas.vilchik@sonarsource.com>
Mon, 16 Oct 2017 15:15:50 +0000 (17:15 +0200)
committerStas Vilchik <stas.vilchik@sonarsource.com>
Tue, 17 Oct 2017 09:32:58 +0000 (11:32 +0200)
server/sonar-web/src/main/js/api/system.ts
server/sonar-web/src/main/js/apps/maintenance/main-view.js
server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-offline.hbs [new file with mode: 0644]
server/sonar-web/src/main/js/apps/maintenance/templates/maintenance-main.hbs
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 18851e79091950bdd24deaa80a8c894fe8bea043..a98d8bdff8a105f8b1a36fa2877f764012a01e94 100644 (file)
@@ -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);
 }
index d3bf4f8c64c994005654cfc8d72c04a38a1bb90f..7a0ebd4afc40452d222e5e2f375685cee452046d 100644 (file)
  * 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 (file)
index 0000000..6e7bac3
--- /dev/null
@@ -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>
index 6b660cf18418db8720e892a2706140e516476422..3a7f14e72a352eafa6b10ac0afaf0ce8a510249a 100644 (file)
@@ -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}}
index 43cf2a8e953e196080958caf36552fec977f10f2..724b0dd0bf037b29fbaf96e4a9379fcaad34ad0b 100644 (file)
@@ -2641,3 +2641,5 @@ maintenance.sonarqube_is_under_maintenance.2=If you are an administrator and hav
 maintenance.sonarqube_is_starting=SonarQube is starting
 maintenance.sonarqube_is_up=SonarQube is up
 maintenance.all_systems_opetational=All systems operational.
+maintenance.sonarqube_is_offline=SonarQube is offline
+maintenance.sonarqube_is_offline.text=The connection to SonarQube is lost. Please contact your system administrator.