{"action":"created","comment":{"url":"https://api.github.com/repos/SonarSource/sonarqube/pulls/comments/29433052","id":29433052,"diff_hunk":"@@ -0,0 +1,168 @@\n+/*\n+ * SonarQube, open source software quality management tool.\n+ * Copyright (C) 2008-2014 SonarSource\n+ * mailto:contact AT sonarsource DOT com\n+ *\n+ * SonarQube is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 3 of the License, or (at your option) any later version.\n+ *\n+ * SonarQube is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ * Lesser General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU Lesser General Public License\n+ * along with this program; if not, write to the Free Software Foundation,\n+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\n+ */\n+package org.sonar.server.platform.ws;\n+\n+import com.google.common.io.Resources;\n+import org.sonar.api.server.ws.Request;\n+import org.sonar.api.server.ws.Response;\n+import org.sonar.api.server.ws.WebService;\n+import org.sonar.api.utils.text.JsonWriter;\n+import org.sonar.core.persistence.Database;\n+import org.sonar.core.persistence.DatabaseVersion;\n+import org.sonar.server.db.migrations.DatabaseMigration;\n+\n+import static org.sonar.server.db.migrations.DatabaseMigration.Status.NONE;\n+import static org.sonar.server.db.migrations.DatabaseMigration.Status.SUCCEEDED;\n+\n+/**\n+ * Implementation of the {@code migrate_db} action for the System WebService.\n+ */\n+public class MigrateDbSystemWsAction implements SystemWsAction {\n+\n+  private static final String UNSUPPORTED_DATABASE_MIGRATION_STATUS = \"Unsupported DatabaseMigration status\";\n+\n+  private final DatabaseVersion databaseVersion;\n+  private final DatabaseMigration databaseMigration;\n+  private final Database database;\n+\n+  public MigrateDbSystemWsAction(DatabaseVersion databaseVersion,\n+    Database database,\n+    DatabaseMigration databaseMigration) {\n+    this.databaseVersion = databaseVersion;\n+    this.database = database;\n+    this.databaseMigration = databaseMigration;\n+  }\n+\n+  @Override\n+  public void define(WebService.NewController controller) {\n+    controller.createAction(\"migrate_db\")\n+      .setDescription(\"Migrate the database to match the current version of SonarQube.\" +\n+        \"<br/>\" +\n+        \"Sending a POST request to this URL will start the DB migration. \" +\n+        \"It is strongly advised to <strong>make a database backup</strong> before invoking this WS.\" +\n+        \"<br/>\" +\n+        \"State values are:\" +\n+        \"<ul>\" +\n+        \"<li>NO_MIGRATION: DB is up to date with current version of SonarQube</li>\" +\n+        \"<li>MIGRATION_NEEDED: DB needs to be upgraded in order for the current version of SonarQube to run</li>\" +\n+        \"<li>MIGRATION_RUNNING: DB migration is under go</li>\" +\n+        \"<li>MIGRATION_SUCCEEDED: DB migration has run and has been successful</li>\" +\n+        \"<li>MIGRATION_FAILED: DB migration has run and failed. SonarQube must be restarted in order to retry a \" +\n+        \"DB migration (optionally after DB has been restored from backup)</li>\" +\n+        \"</ul>\")\n+      .setSince(\"5.2\")\n+      .setPost(true)\n+      .setHandler(this)\n+      .setResponseExample(Resources.getResource(this.getClass(), \"example-migrate.json\"));\n+  }\n+\n+  @Override\n+  public void handle(Request request, Response response) throws Exception {\n+    Integer currentVersion = databaseVersion.getVersion();\n+    if (currentVersion == null) {\n+      throw new IllegalStateException(\"Version can not be retrieved from Database. Database is either blank or corrupted\");\n+    }\n+\n+    if (currentVersion >= DatabaseVersion.LAST_VERSION) {\n+      writeResponse(response, databaseMigration);\n+    } else if (!database.getDialect().supportsMigration()) {\n+      writeNotSupportedResponse(response);\n+    } else {\n+      switch (databaseMigration.status()) {\n+        case RUNNING:\n+        case FAILED:\n+        case SUCCEEDED:\n+          writeResponse(response, databaseMigration);\n+          break;\n+        case NONE:\n+          databaseMigration.startIt();\n+          writeResponse(response, databaseMigration);\n+          break;\n+        default:\n+          throw new RuntimeException(UNSUPPORTED_DATABASE_MIGRATION_STATUS);","path":"server/sonar-server/src/main/java/org/sonar/server/platform/ws/MigrateDbSystemWsAction.java","position":99,"original_position":99,"commit_id":"48874aa28ce2bca98f648613905229aa4ea575cb","original_commit_id":"48874aa28ce2bca98f648613905229aa4ea575cb","user":{"login":"sns-seb","id":11717580,"avatar_url":"https://avatars.githubusercontent.com/u/11717580?v=3","gravatar_id":"","url":"https://api.github.com/users/sns-seb","html_url":"https://github.com/sns-seb","followers_url":"https://api.github.com/users/sns-seb/followers","following_url":"https://api.github.com/users/sns-seb/following{/other_user}","gists_url":"https://api.github.com/users/sns-seb/gists{/gist_id}","starred_url":"https://api.github.com/users/sns-seb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sns-seb/subscriptions","organizations_url":"https://api.github.com/users/sns-seb/orgs","repos_url":"https://api.github.com/users/sns-seb/repos","events_url":"https://api.github.com/users/sns-seb/events{/privacy}","received_events_url":"https://api.github.com/users/sns-seb/received_events","type":"User","site_admin":false},"body":"for a lack of better alternative, I'll go with `IllegalArgumentException`","created_at":"2015-04-30T14:19:04Z","updated_at":"2015-04-30T14:19:04Z","html_url":"https://github.com/SonarSource/sonarqube/pull/233#discussion_r29433052","pull_request_url":"https://api.github.com/repos/SonarSource/sonarqube/pulls/233","_links":{"self":{"href":"https://api.github.com/repos/SonarSource/sonarqube/pulls/comments/29433052"},"html":{"href":"https://github.com/SonarSource/sonarqube/pull/233#discussion_r29433052"},"pull_request":{"href":"https://api.github.com/repos/SonarSource/sonarqube/pulls/233"}}},"pull_request":{"url":"https://api.github.com/repos/SonarSource/sonarqube/pulls/233","id":33649026,"html_url":"https://github.com/SonarSource/sonarqube/pull/233","diff_url":"https://github.com/SonarSource/sonarqube/pull/233.diff","patch_url":"https://github.com/SonarSource/sonarqube/pull/233.patch","issue_url":"https://api.github.com/repos/SonarSource/sonarqube/issues/233","number":233,"state":"open","locked":false,"title":"SONAR-6366 new ws for db migration","user":{"login":"sns-seb","id":11717580,"avatar_url":"https://avatars.githubusercontent.com/u/11717580?v=3","gravatar_id":"","url":"https://api.github.com/users/sns-seb","html_url":"https://github.com/sns-seb","followers_url":"https://api.github.com/users/sns-seb/followers","following_url":"https://api.github.com/users/sns-seb/following{/other_user}","gists_url":"https://api.github.com/users/sns-seb/gists{/gist_id}","starred_url":"https://api.github.com/users/sns-seb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sns-seb/subscriptions","organizations_url":"https://api.github.com/users/sns-seb/orgs","repos_url":"https://api.github.com/users/sns-seb/repos","events_url":"https://api.github.com/users/sns-seb/events{/privacy}","received_events_url":"https://api.github.com/users/sns-seb/received_events","type":"User","site_admin":false},"body":"this PR adds the new WS server/migrate\r\n\r\nthis PR is the same as #202, but recreated based on master\r\n\r\nIT tests are currently failing because restarting the Java WS after db upgrade does not work anymore","created_at":"2015-04-20T09:36:38Z","updated_at":"2015-04-30T14:19:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"049b7b2f05228f4670456932884af1ab0bd78759","assignee":{"login":"sns-seb","id":11717580,"avatar_url":"https://avatars.githubusercontent.com/u/11717580?v=3","gravatar_id":"","url":"https://api.github.com/users/sns-seb","html_url":"https://github.com/sns-seb","followers_url":"https://api.github.com/users/sns-seb/followers","following_url":"https://api.github.com/users/sns-seb/following{/other_user}","gists_url":"https://api.github.com/users/sns-seb/gists{/gist_id}","starred_url":"https://api.github.com/users/sns-seb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sns-seb/subscriptions","organizations_url":"https://api.github.com/users/sns-seb/orgs","repos_url":"https://api.github.com/users/sns-seb/repos","events_url":"https://api.github.com/users/sns-seb/events{/privacy}","received_events_url":"https://api.github.com/users/sns-seb/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/SonarSource/sonarqube/pulls/233/commits","review_comments_url":"https://api.github.com/repos/SonarSource/sonarqube/pulls/233/comments","review_comment_url":"https://api.github.com/repos/SonarSource/sonarqube/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SonarSource/sonarqube/issues/233/comments","statuses_url":"https://api.github.com/repos/SonarSource/sonarqube/statuses/48874aa28ce2bca98f648613905229aa4ea575cb","head":{"label":"SonarSource:feature/add_java_ws_db_upgrade","ref":"feature/add_java_ws_db_upgrade","sha":"48874aa28ce2bca98f648613905229aa4ea575cb","user":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"repo":{"id":1222504,"name":"sonarqube","full_name":"SonarSource/sonarqube","owner":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SonarSource/sonarqube","description":"Put your technical debt under control","fork":false,"url":"https://api.github.com/repos/SonarSource/sonarqube","forks_url":"https://api.github.com/repos/SonarSource/sonarqube/forks","keys_url":"https://api.github.com/repos/SonarSource/sonarqube/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SonarSource/sonarqube/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SonarSource/sonarqube/teams","hooks_url":"https://api.github.com/repos/SonarSource/sonarqube/hooks","issue_events_url":"https://api.github.com/repos/SonarSource/sonarqube/issues/events{/number}","events_url":"https://api.github.com/repos/SonarSource/sonarqube/events","assignees_url":"https://api.github.com/repos/SonarSource/sonarqube/assignees{/user}","branches_url":"https://api.github.com/repos/SonarSource/sonarqube/branches{/branch}","tags_url":"https://api.github.com/repos/SonarSource/sonarqube/tags","blobs_url":"https://api.github.com/repos/SonarSource/sonarqube/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SonarSource/sonarqube/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SonarSource/sonarqube/git/refs{/sha}","trees_url":"https://api.github.com/repos/SonarSource/sonarqube/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SonarSource/sonarqube/statuses/{sha}","languages_url":"https://api.github.com/repos/SonarSource/sonarqube/languages","stargazers_url":"https://api.github.com/repos/SonarSource/sonarqube/stargazers","contributors_url":"https://api.github.com/repos/SonarSource/sonarqube/contributors","subscribers_url":"https://api.github.com/repos/SonarSource/sonarqube/subscribers","subscription_url":"https://api.github.com/repos/SonarSource/sonarqube/subscription","commits_url":"https://api.github.com/repos/SonarSource/sonarqube/commits{/sha}","git_commits_url":"https://api.github.com/repos/SonarSource/sonarqube/git/commits{/sha}","comments_url":"https://api.github.com/repos/SonarSource/sonarqube/comments{/number}","issue_comment_url":"https://api.github.com/repos/SonarSource/sonarqube/issues/comments{/number}","contents_url":"https://api.github.com/repos/SonarSource/sonarqube/contents/{+path}","compare_url":"https://api.github.com/repos/SonarSource/sonarqube/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SonarSource/sonarqube/merges","archive_url":"https://api.github.com/repos/SonarSource/sonarqube/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SonarSource/sonarqube/downloads","issues_url":"https://api.github.com/repos/SonarSource/sonarqube/issues{/number}","pulls_url":"https://api.github.com/repos/SonarSource/sonarqube/pulls{/number}","milestones_url":"https://api.github.com/repos/SonarSource/sonarqube/milestones{/number}","notifications_url":"https://api.github.com/repos/SonarSource/sonarqube/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SonarSource/sonarqube/labels{/name}","releases_url":"https://api.github.com/repos/SonarSource/sonarqube/releases{/id}","created_at":"2011-01-05T11:05:17Z","updated_at":"2015-04-30T12:08:03Z","pushed_at":"2015-04-30T13:11:43Z","git_url":"git://github.com/SonarSource/sonarqube.git","ssh_url":"git@github.com:SonarSource/sonarqube.git","clone_url":"https://github.com/SonarSource/sonarqube.git","svn_url":"https://github.com/SonarSource/sonarqube","homepage":"http://www.sonarqube.org","size":643295,"stargazers_count":591,"watchers_count":591,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":324,"mirror_url":null,"open_issues_count":7,"forks":324,"open_issues":7,"watchers":591,"default_branch":"master"}},"base":{"label":"SonarSource:master","ref":"master","sha":"a0014d9bdd2e874bb74a26035b0fa5e473506769","user":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"repo":{"id":1222504,"name":"sonarqube","full_name":"SonarSource/sonarqube","owner":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SonarSource/sonarqube","description":"Put your technical debt under control","fork":false,"url":"https://api.github.com/repos/SonarSource/sonarqube","forks_url":"https://api.github.com/repos/SonarSource/sonarqube/forks","keys_url":"https://api.github.com/repos/SonarSource/sonarqube/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SonarSource/sonarqube/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SonarSource/sonarqube/teams","hooks_url":"https://api.github.com/repos/SonarSource/sonarqube/hooks","issue_events_url":"https://api.github.com/repos/SonarSource/sonarqube/issues/events{/number}","events_url":"https://api.github.com/repos/SonarSource/sonarqube/events","assignees_url":"https://api.github.com/repos/SonarSource/sonarqube/assignees{/user}","branches_url":"https://api.github.com/repos/SonarSource/sonarqube/branches{/branch}","tags_url":"https://api.github.com/repos/SonarSource/sonarqube/tags","blobs_url":"https://api.github.com/repos/SonarSource/sonarqube/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SonarSource/sonarqube/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SonarSource/sonarqube/git/refs{/sha}","trees_url":"https://api.github.com/repos/SonarSource/sonarqube/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SonarSource/sonarqube/statuses/{sha}","languages_url":"https://api.github.com/repos/SonarSource/sonarqube/languages","stargazers_url":"https://api.github.com/repos/SonarSource/sonarqube/stargazers","contributors_url":"https://api.github.com/repos/SonarSource/sonarqube/contributors","subscribers_url":"https://api.github.com/repos/SonarSource/sonarqube/subscribers","subscription_url":"https://api.github.com/repos/SonarSource/sonarqube/subscription","commits_url":"https://api.github.com/repos/SonarSource/sonarqube/commits{/sha}","git_commits_url":"https://api.github.com/repos/SonarSource/sonarqube/git/commits{/sha}","comments_url":"https://api.github.com/repos/SonarSource/sonarqube/comments{/number}","issue_comment_url":"https://api.github.com/repos/SonarSource/sonarqube/issues/comments{/number}","contents_url":"https://api.github.com/repos/SonarSource/sonarqube/contents/{+path}","compare_url":"https://api.github.com/repos/SonarSource/sonarqube/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SonarSource/sonarqube/merges","archive_url":"https://api.github.com/repos/SonarSource/sonarqube/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SonarSource/sonarqube/downloads","issues_url":"https://api.github.com/repos/SonarSource/sonarqube/issues{/number}","pulls_url":"https://api.github.com/repos/SonarSource/sonarqube/pulls{/number}","milestones_url":"https://api.github.com/repos/SonarSource/sonarqube/milestones{/number}","notifications_url":"https://api.github.com/repos/SonarSource/sonarqube/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SonarSource/sonarqube/labels{/name}","releases_url":"https://api.github.com/repos/SonarSource/sonarqube/releases{/id}","created_at":"2011-01-05T11:05:17Z","updated_at":"2015-04-30T12:08:03Z","pushed_at":"2015-04-30T13:11:43Z","git_url":"git://github.com/SonarSource/sonarqube.git","ssh_url":"git@github.com:SonarSource/sonarqube.git","clone_url":"https://github.com/SonarSource/sonarqube.git","svn_url":"https://github.com/SonarSource/sonarqube","homepage":"http://www.sonarqube.org","size":643295,"stargazers_count":591,"watchers_count":591,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":324,"mirror_url":null,"open_issues_count":7,"forks":324,"open_issues":7,"watchers":591,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SonarSource/sonarqube/pulls/233"},"html":{"href":"https://github.com/SonarSource/sonarqube/pull/233"},"issue":{"href":"https://api.github.com/repos/SonarSource/sonarqube/issues/233"},"comments":{"href":"https://api.github.com/repos/SonarSource/sonarqube/issues/233/comments"},"review_comments":{"href":"https://api.github.com/repos/SonarSource/sonarqube/pulls/233/comments"},"review_comment":{"href":"https://api.github.com/repos/SonarSource/sonarqube/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SonarSource/sonarqube/pulls/233/commits"},"statuses":{"href":"https://api.github.com/repos/SonarSource/sonarqube/statuses/48874aa28ce2bca98f648613905229aa4ea575cb"}}}}