diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-03-27 10:42:17 +0200 |
---|---|---|
committer | Eric Hartmann <hartmann.eric@gmail.Com> | 2017-04-27 09:23:18 +0200 |
commit | 489aa80776a2dc1881ad87eb0df19bb66b0fa23e (patch) | |
tree | 956b67a635d229a9f5855f63687abc50ad1999b9 /server | |
parent | 81b3cf750f8bd0bfc5603601d0ad8ab976953b0e (diff) | |
download | sonarqube-489aa80776a2dc1881ad87eb0df19bb66b0fa23e.tar.gz sonarqube-489aa80776a2dc1881ad87eb0df19bb66b0fa23e.zip |
SONAR-8985 SONAR-9040 add CE_QUEUE.WORKER_UUID and EXECUTION_COUNT
Diffstat (limited to 'server')
6 files changed, 123 insertions, 2 deletions
diff --git a/server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql b/server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql index 7f83bcc46d7..48066f27ded 100644 --- a/server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql +++ b/server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql @@ -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; diff --git a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl index 1571813a23f..8bc83c2586c 100644 --- a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl +++ b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl @@ -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 index 00000000000..21faaebe6cf --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/AddCeQueueWorkerUuidAndExecutionCount.java @@ -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()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64.java index 9bc19a64845..a1101fd8932 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64.java @@ -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 index 00000000000..3f320b6e38a --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/AddCeQueueWorkerUuidAndExecutionCountTest.java @@ -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 index 00000000000..50faa80d9c5 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/AddCeQueueWorkerUuidAndExecutionCountTest/ce_queue.sql @@ -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"); |