diff options
author | Aurelien Poscia <aurelien.poscia@sonarsource.com> | 2022-12-21 09:06:32 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-12-23 20:02:51 +0000 |
commit | 6bf8a78f319ad666cb31d2100910dd34e5fcaf13 (patch) | |
tree | 72b7de555bd9e9849a39e1c21b2325a1c58aa82b /server/sonar-db-migration | |
parent | dabdad1e611a5a7d14ec4b443d29289ec5ddc4a2 (diff) | |
download | sonarqube-6bf8a78f319ad666cb31d2100910dd34e5fcaf13.tar.gz sonarqube-6bf8a78f319ad666cb31d2100910dd34e5fcaf13.zip |
SONAR-14128 Store and provide node name of CE Task in /api/ce/activity
Diffstat (limited to 'server/sonar-db-migration')
6 files changed, 202 insertions, 0 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java index 1208b855f29..cf8c29ce3bc 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java @@ -37,6 +37,7 @@ import org.sonar.server.platform.db.migration.version.v95.DbVersion95; import org.sonar.server.platform.db.migration.version.v96.DbVersion96; import org.sonar.server.platform.db.migration.version.v97.DbVersion97; import org.sonar.server.platform.db.migration.version.v98.DbVersion98; +import org.sonar.server.platform.db.migration.version.v99.DbVersion99; public class MigrationConfigurationModule extends Module { @Override @@ -54,6 +55,7 @@ public class MigrationConfigurationModule extends Module { DbVersion96.class, DbVersion97.class, DbVersion98.class, + DbVersion99.class, // migration steps MigrationStepRegistryImpl.class, diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v99/AddNodeNameColumnToCeActivityTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v99/AddNodeNameColumnToCeActivityTable.java new file mode 100644 index 00000000000..042605d88fc --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v99/AddNodeNameColumnToCeActivityTable.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.v99; + +import com.google.common.annotations.VisibleForTesting; +import java.sql.Connection; +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.DatabaseUtils; +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; + +class AddNodeNameColumnToCeActivityTable extends DdlChange { + @VisibleForTesting + static final String TABLE_NAME = "ce_activity"; + @VisibleForTesting + static final String COLUMN_NAME = "node_name"; + + public AddNodeNameColumnToCeActivityTable(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + try (Connection c = getDatabase().getDataSource().getConnection()) { + if (!DatabaseUtils.tableColumnExists(c, TABLE_NAME, COLUMN_NAME)) { + context.execute(new AddColumnsBuilder(getDialect(), TABLE_NAME) + .addColumn(VarcharColumnDef.newVarcharColumnDefBuilder(COLUMN_NAME).setLimit(100).setIsNullable(true).build()) + .build()); + } + } + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v99/DbVersion99.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v99/DbVersion99.java new file mode 100644 index 00000000000..1d345f5b118 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v99/DbVersion99.java @@ -0,0 +1,31 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.v99; + +import org.sonar.server.platform.db.migration.step.MigrationStepRegistry; +import org.sonar.server.platform.db.migration.version.DbVersion; + +public class DbVersion99 implements DbVersion { + @Override + public void addSteps(MigrationStepRegistry registry) { + registry + .add(6800, "Add node_name column to ce_activity table", AddNodeNameColumnToCeActivityTable.class); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v99/AddNodeNameColumnToCeActivityTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v99/AddNodeNameColumnToCeActivityTableTest.java new file mode 100644 index 00000000000..927e9d57666 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v99/AddNodeNameColumnToCeActivityTableTest.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.v99; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; + +import static org.sonar.server.platform.db.migration.version.v99.AddNodeNameColumnToCeActivityTable.COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v99.AddNodeNameColumnToCeActivityTable.TABLE_NAME; + +public class AddNodeNameColumnToCeActivityTableTest { + + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(AddNodeNameColumnToCeActivityTableTest.class, "schema.sql"); + + private final AddNodeNameColumnToCeActivityTable underTest = new AddNodeNameColumnToCeActivityTable(db.database()); + + @Test + public void migration_should_add_column() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, null, true); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + underTest.execute(); + // re-entrant + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, null, true); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v99/DbVersion99Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v99/DbVersion99Test.java new file mode 100644 index 00000000000..ce39f82e710 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v99/DbVersion99Test.java @@ -0,0 +1,40 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.v99; + +import org.junit.Test; + +import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationNotEmpty; +import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber; + +public class DbVersion99Test { + private final DbVersion99 underTest = new DbVersion99(); + + @Test + public void migrationNumber_starts_at_6800() { + verifyMinimumMigrationNumber(underTest, 6800); + } + + @Test + public void verify_migration_is_not_empty() { + verifyMigrationNotEmpty(underTest); + } + +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v99/AddNodeNameColumnToCeActivityTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v99/AddNodeNameColumnToCeActivityTableTest/schema.sql new file mode 100644 index 00000000000..578f6db77d0 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v99/AddNodeNameColumnToCeActivityTableTest/schema.sql @@ -0,0 +1,25 @@ + +CREATE TABLE "CE_ACTIVITY"( + "UUID" CHARACTER VARYING(40) NOT NULL, + "TASK_TYPE" CHARACTER VARYING(15) NOT NULL, + "MAIN_COMPONENT_UUID" CHARACTER VARYING(40), + "COMPONENT_UUID" CHARACTER VARYING(40), + "STATUS" CHARACTER VARYING(15) NOT NULL, + "MAIN_IS_LAST" BOOLEAN NOT NULL, + "MAIN_IS_LAST_KEY" CHARACTER VARYING(55) NOT NULL, + "IS_LAST" BOOLEAN NOT NULL, + "IS_LAST_KEY" CHARACTER VARYING(55) NOT NULL, + "SUBMITTER_UUID" CHARACTER VARYING(255), + "SUBMITTED_AT" BIGINT NOT NULL, + "STARTED_AT" BIGINT, + "EXECUTED_AT" BIGINT, + "EXECUTION_COUNT" INTEGER NOT NULL, + "EXECUTION_TIME_MS" BIGINT, + "ANALYSIS_UUID" CHARACTER VARYING(50), + "ERROR_MESSAGE" CHARACTER VARYING(1000), + "ERROR_STACKTRACE" CHARACTER LARGE OBJECT, + "ERROR_TYPE" CHARACTER VARYING(20), + "WORKER_UUID" CHARACTER VARYING(40), + "CREATED_AT" BIGINT NOT NULL, + "UPDATED_AT" BIGINT NOT NULL +); |