From: Fabrice Bellingard Date: Mon, 21 May 2012 09:24:25 +0000 (+0200) Subject: SONAR-3218 Add a new status to the '/api/server' WS X-Git-Tag: 3.1~159 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d9fc557825a2d9474efb6aa23736319b54043ea1;p=sonarqube.git SONAR-3218 Add a new status to the '/api/server' WS => 'MIGRATION_RUNNING' --- diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb index e81924ec968..120624abeb8 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb @@ -107,13 +107,16 @@ class Api::ServerController < Api::ApiController end def complete_with_status(hash) - if DatabaseVersion.uptodate? + if DatabaseMigrationManager.instance.is_sonar_access_allowed? hash[:status]='UP' - elsif ActiveRecord::Base.connected? + elsif DatabaseMigrationManager.instance.migration_running? + hash[:status]='MIGRATION_RUNNING' + elsif DatabaseMigrationManager.instance.requires_migration? hash[:status]='SETUP' else + # migration failed or not connected to the database hash[:status]='DOWN' - hash[:status_msg]='Not connected to database' + hash[:status_msg]=DatabaseMigrationManager.instance.message end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/setup_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/setup_controller.rb index 2cac046bdbc..2644d16ce17 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/setup_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/setup_controller.rb @@ -25,12 +25,10 @@ class SetupController < ApplicationController verify :method => :post, :only => [ :setup_database ], :redirect_to => { :action => :index } def index - if DatabaseMigrationManager.instance.requires_migration? - if ActiveRecord::Base.connected? - render :template => 'setup/form', :layout => 'nonav' - else - render :template => 'setup/dbdown', :layout => 'nonav' - end + if !ActiveRecord::Base.connected? + render :template => 'setup/dbdown', :layout => 'nonav' + elsif DatabaseMigrationManager.instance.requires_migration? + render :template => 'setup/form', :layout => 'nonav' elsif DatabaseMigrationManager.instance.migration_running? render :template => 'setup/migration_running', :layout => 'nonav' elsif DatabaseMigrationManager.instance.migration_failed? diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/database_migration_manager.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/database_migration_manager.rb index a2b59ea9cfe..5d412ea6284 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/database_migration_manager.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/database_migration_manager.rb @@ -46,7 +46,10 @@ class DatabaseMigrationManager @start_time def initialize - if DatabaseVersion.uptodate? + if !ActiveRecord::Base.connected? + @status = MIGRATION_FAILED + @message = "Not connected to database." + elsif DatabaseVersion.uptodate? @status = NO_MIGRATION @message = "Database is up-to-date, no migration needed." else