aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-10-04 15:01:33 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-10-04 15:01:33 +0200
commitef2ea270621dfb8e3b1b856bdecd2d54549c301b (patch)
treedbffe2b6e2b00d61d4a7fe937d1334ae9cb2b35e /sonar-server
parent953921932fc67fc72a88ed0d49992d51f4ac8ae3 (diff)
downloadsonarqube-ef2ea270621dfb8e3b1b856bdecd2d54549c301b.tar.gz
sonarqube-ef2ea270621dfb8e3b1b856bdecd2d54549c301b.zip
SONAR-4667 database upgrade should do not block HTTP request
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/setup_controller.rb4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/database_migration_manager.rb27
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/setup/form.html.erb14
3 files changed, 20 insertions, 25 deletions
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 9283b853910..eeb2db5beba 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
@@ -42,10 +42,10 @@ class SetupController < ApplicationController
def setup_database
# Ask the DB migration manager to start the migration
# => No need to check for authorizations (actually everybody can run the upgrade)
- # nor concurrent calls (this is handled directly by DatabaseMigrationManager)
+ # nor concurrent calls (this is handled directly by DatabaseMigrationManager)
DatabaseMigrationManager.instance.start_migration
# and return some text that will actually never be displayed
- render :text => DatabaseMigrationManager.instance.message
+ redirect_to :action => :index
end
def maintenance
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 852f6d14b2d..4b0e7b4e4ee 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
@@ -97,25 +97,26 @@ class DatabaseMigrationManager
Thread.exclusive do
if requires_migration?
@status = MIGRATION_RUNNING
- @message = "Database migration is currently running."
+ @message = "Database migration is running"
can_start_migration = true
end
end
if can_start_migration
- # launch the upgrade
- begin
- @start_time = Time.now
- DatabaseVersion.upgrade_and_start
- @status = MIGRATION_SUCCEEDED
- @message = "The migration succeeded."
- rescue Exception => e
- @status = MIGRATION_FAILED
- @message = "The migration failed: " + e.clean_message + ".<br/> Please check the logs."
- # rethrow the exception so that it is logged and so that the whole system knows that a problem occured
- raise
+ Thread.new do
+ begin
+ Thread.current[:name] = "Database Upgrade"
+ @start_time = Time.now
+ DatabaseVersion.upgrade_and_start
+ @status = MIGRATION_SUCCEEDED
+ @message = "Migration succeeded."
+ rescue Exception => e
+ @status = MIGRATION_FAILED
+ @message = "Migration failed: " + e.clean_message + ".<br/> Please check logs."
+ Api::Utils.java_facade.logError("Fail to upgrade database\n#{Api::Utils.exception_message(e, :backtrace => true)}")
+ end
end
- end
+ end
end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/setup/form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/setup/form.html.erb
index 6a5286dba59..00dd7c69869 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/setup/form.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/setup/form.html.erb
@@ -1,3 +1,4 @@
+<form action="<%= ApplicationController.root_context -%>/setup/setup_database" method="POST">
<div class="admin migration">
<h1 class="marginbottom10">Upgrade database</h1>
<br/>
@@ -8,13 +9,6 @@
<li><b>Copy the directory /extensions</b> from previous version before upgrading.</li>
</ul>
<br/>
- <input type="button"
- value="Upgrade"
- onclick="
- $j.ajax({
- url:'<%= url_for(:action => 'setup_database')-%>',
- type:'post',
- success:function(request){window.location.reload();}
- });
- return false;">
-</div> \ No newline at end of file
+ <input type="submit" value="Upgrade">
+</div>
+</form>