]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3218 Add a new status to the '/api/server' WS
authorFabrice Bellingard <bellingard@gmail.com>
Mon, 21 May 2012 09:24:25 +0000 (11:24 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Mon, 21 May 2012 09:35:56 +0000 (11:35 +0200)
=> 'MIGRATION_RUNNING'

sonar-server/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/setup_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/database_migration_manager.rb

index e81924ec968d0de0338182b338101edc8819312d..120624abeb80b9580ff970dbe5c3634bd5118fc7 100644 (file)
@@ -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
 
index 2cac046bdbc919fd9dae3b3d8978c531d4092e8b..2644d16ce171218f875d949d8384bf227b260149 100644 (file)
@@ -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?
index a2b59ea9cfebb0f679963e536fe8f1940b31f5b3..5d412ea62844e137d65d78e17a1af93263cec16d 100644 (file)
@@ -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