]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8985 SONAR-9040 add CE_QUEUE.WORKER_UUID and EXECUTION_COUNT
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 27 Mar 2017 08:42:17 +0000 (10:42 +0200)
committerEric Hartmann <hartmann.eric@gmail.Com>
Thu, 27 Apr 2017 07:23:18 +0000 (09:23 +0200)
server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql
server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/AddCeQueueWorkerUuidAndExecutionCount.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/AddCeQueueWorkerUuidAndExecutionCountTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/AddCeQueueWorkerUuidAndExecutionCountTest/ce_queue.sql [new file with mode: 0644]

index 7f83bcc46d74c95d36651944ed1017b23c608fc6..48066f27ded957e48b4b529e8c4306cd90d82ac1 100644 (file)
@@ -1,5 +1,3 @@
--- All the rows inserted during Rails migrations. Rows inserted during server startup tasks (Java) are excluded : rules, profiles, metrics, ...
-
 INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, USER_LOCAL, CRYPTED_PASSWORD, SALT, IS_ROOT, CREATED_AT, UPDATED_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', true, 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', false, '1418215735482', '1418215735482');
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
 
index 1571813a23fce93ef46781811c547bf1e0e62087..8bc83c2586cd8c288ecf22c07b85ed9b9136e233 100644 (file)
@@ -562,6 +562,8 @@ CREATE TABLE "CE_QUEUE" (
   "COMPONENT_UUID" VARCHAR(40) NULL,
   "STATUS" VARCHAR(15) NOT NULL,
   "SUBMITTER_LOGIN" VARCHAR(255) NULL,
+  "WORKER_UUID" VARCHAR(40) NULL,
+  "EXECUTION_COUNT" INTEGER NULL,
   "STARTED_AT" BIGINT NULL,
   "CREATED_AT" BIGINT NOT NULL,
   "UPDATED_AT" BIGINT NOT NULL
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/AddCeQueueWorkerUuidAndExecutionCount.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/AddCeQueueWorkerUuidAndExecutionCount.java
new file mode 100644 (file)
index 0000000..21faaeb
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v64;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.IntegerColumnDef;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class AddCeQueueWorkerUuidAndExecutionCount extends DdlChange {
+
+  private static final String TABLE_CE_QUEUE = "ce_queue";
+
+  public AddCeQueueWorkerUuidAndExecutionCount(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AddColumnsBuilder(getDialect(), TABLE_CE_QUEUE)
+      .addColumn(VarcharColumnDef.newVarcharColumnDefBuilder()
+        .setColumnName("worker_uuid")
+        .setLimit(VarcharColumnDef.UUID_SIZE)
+        .setIsNullable(true)
+        .build())
+      .addColumn(IntegerColumnDef.newIntegerColumnDefBuilder()
+        .setColumnName("execution_count")
+        .setIsNullable(true)
+        .build())
+      .build());
+  }
+}
index 9bc19a648459e7468f25bc15a76a8ba2c9dcb8d8..a1101fd8932d72537cf893fa332e6f60fb942098 100644 (file)
@@ -45,6 +45,7 @@ public class DbVersion64 implements DbVersion {
       .add(1615, "Create table RULES_METADATA", CreateRulesMetadata.class)
       .add(1616, "Populate table RULES_METADATA", PopulateRulesMetadata.class)
       .add(1617, "Drop metadata columns from RULES", DropMetadataColumnsFromRules.class)
+
       // ensure the index is made unique even on existing 6.4-SNAPSHOT instances (such as next or the developer machines)
       .add(1618, "Make index on ORGANIZATIONS.KEE unique", org.sonar.server.platform.db.migration.version.v63.MakeIndexOnOrganizationsKeeUnique.class)
       .add(1619, "Restore 'sonar-users' group", RestoreSonarUsersGroups.class)
@@ -57,5 +58,6 @@ public class DbVersion64 implements DbVersion {
       .add(1626, "Clean orphan rows in table GROUPS_USERS", CleanOrphanRowsInGroupsUsers.class)
       .add(1627, "Delete permission templates linked to removed users", DeletePermissionTemplatesLinkedToRemovedUsers.class)
     ;
+      .add(1628, "Add columns CE_QUEUE.WORKER_UUID and EXECUTION_COUNT", AddCeQueueWorkerUuidAndExecutionCount.class);
   }
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/AddCeQueueWorkerUuidAndExecutionCountTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/AddCeQueueWorkerUuidAndExecutionCountTest.java
new file mode 100644 (file)
index 0000000..3f320b6
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v64;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+public class AddCeQueueWorkerUuidAndExecutionCountTest {
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddCeQueueWorkerUuidAndExecutionCountTest.class, "ce_queue.sql");
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private AddCeQueueWorkerUuidAndExecutionCount underTest = new AddCeQueueWorkerUuidAndExecutionCount(db.database());
+
+  @Test
+  public void execute_adds_columns_worker_uuid_and_processing_count() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDefinition("ce_queue", "worker_uuid", Types.VARCHAR, 40, true);
+    db.assertColumnDefinition("ce_queue", "execution_count", Types.INTEGER, null, true);
+  }
+
+  @Test
+  public void execute_is_not_reentreant() throws SQLException {
+    underTest.execute();
+
+    expectedException.expect(IllegalStateException.class);
+    expectedException.expectMessage("Fail to execute");
+
+    underTest.execute();
+  }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/AddCeQueueWorkerUuidAndExecutionCountTest/ce_queue.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/AddCeQueueWorkerUuidAndExecutionCountTest/ce_queue.sql
new file mode 100644 (file)
index 0000000..50faa80
--- /dev/null
@@ -0,0 +1,14 @@
+CREATE TABLE "CE_QUEUE" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "UUID" VARCHAR(40) NOT NULL,
+  "TASK_TYPE" VARCHAR(15) NOT NULL,
+  "COMPONENT_UUID" VARCHAR(40) NULL,
+  "STATUS" VARCHAR(15) NOT NULL,
+  "SUBMITTER_LOGIN" VARCHAR(255) NULL,
+  "STARTED_AT" BIGINT NULL,
+  "CREATED_AT" BIGINT NOT NULL,
+  "UPDATED_AT" BIGINT NOT NULL
+);
+CREATE UNIQUE INDEX "CE_QUEUE_UUID" ON "CE_QUEUE" ("UUID");
+CREATE INDEX "CE_QUEUE_COMPONENT_UUID" ON "CE_QUEUE" ("COMPONENT_UUID");
+CREATE INDEX "CE_QUEUE_STATUS" ON "CE_QUEUE" ("STATUS");