From: Simon Brandhof Date: Thu, 4 Aug 2016 19:59:10 +0000 (+0200) Subject: SONAR-7903 Drop pending tasks X-Git-Tag: 6.1-RC1~447 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=82f2a7ed671632948054da3fa22bff9ac4b118fa;p=sonarqube.git SONAR-7903 Drop pending tasks --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ExtractReportStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ExtractReportStep.java index 6d94a12a777..513bc7a2738 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ExtractReportStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ExtractReportStep.java @@ -25,8 +25,6 @@ import java.util.Optional; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.TempFolder; import org.sonar.api.utils.ZipUtils; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; import org.sonar.ce.queue.CeTask; import org.sonar.db.DbClient; import org.sonar.db.DbSession; @@ -39,7 +37,6 @@ import org.sonar.server.computation.task.step.ComputationStep; * representing that temp directory to the {@link MutableBatchReportDirectoryHolder}. */ public class ExtractReportStep implements ComputationStep { - private static final Logger LOG = Loggers.get(ExtractReportStep.class); private final DbClient dbClient; private final CeTask task; @@ -66,7 +63,6 @@ public class ExtractReportStep implements ComputationStep { throw new IllegalStateException("Fail to extract report " + task.getUuid() + " from database", e); } reportDirectoryHolder.setDirectory(unzippedDir); - LOG.info("Analysis report extracted"); } else { throw MessageException.of("Analysis report " + task.getUuid() + " is missing in database"); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/queue/CeQueueCleanerTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/queue/CeQueueCleanerTest.java index 923a684213c..20166486196 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/queue/CeQueueCleanerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/queue/CeQueueCleanerTest.java @@ -24,7 +24,6 @@ import java.util.Optional; import org.apache.commons.io.IOUtils; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.TemporaryFolder; import org.sonar.api.platform.ServerUpgradeStatus; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; @@ -42,9 +41,6 @@ public class CeQueueCleanerTest { @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder(); - private ServerUpgradeStatus serverUpgradeStatus = mock(ServerUpgradeStatus.class); private InternalCeQueue queue = mock(InternalCeQueue.class); private CeQueueCleaner underTest = new CeQueueCleaner(dbTester.getDbClient(), serverUpgradeStatus, queue); diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1302_create_table_ce_task_data.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1302_create_table_ce_task_data.rb index c46371778b3..73038de8329 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1302_create_table_ce_task_data.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1302_create_table_ce_task_data.rb @@ -24,7 +24,6 @@ class CreateTableCeTaskData < ActiveRecord::Migration def self.up - # FIXME define primary key create_table 'ce_task_data', :id => false do |t| t.column 'task_uuid', :string, :limit => 40, :null => false t.column 'data', :binary, :null => true diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1303_delete_reports_from_ce_queue.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1303_delete_reports_from_ce_queue.rb new file mode 100644 index 00000000000..3ad2bfc3e67 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1303_delete_reports_from_ce_queue.rb @@ -0,0 +1,29 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube 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. +# +# SonarQube 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. +# + +# +# SonarQube 6.1 +# +class DeleteReportsFromCeQueue < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.db.version.v61.DeleteReportsFromCeQueue') + end +end diff --git a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java index 8be4800dac9..9a21f9dcb5b 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java +++ b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java @@ -30,7 +30,7 @@ import org.sonar.db.MyBatis; public class DatabaseVersion { - public static final int LAST_VERSION = 1_302; + public static final int LAST_VERSION = 1_303; /** * The minimum supported version which can be upgraded. Lower diff --git a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java index c36dcd67234..83cef386038 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java +++ b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java @@ -145,6 +145,7 @@ import org.sonar.db.version.v60.PopulateUuidColumnsOfResourceIndex; import org.sonar.db.version.v60.PopulateUuidPathColumnOnProjects; import org.sonar.db.version.v60.RemoveUsersPasswordWhenNotLocal; import org.sonar.db.version.v61.DeleteProjectDashboards; +import org.sonar.db.version.v61.DeleteReportsFromCeQueue; import org.sonar.db.version.v61.DropIsGlobalFromDashboards; public class MigrationStepModule extends Module { @@ -310,7 +311,8 @@ public class MigrationStepModule extends Module { // 6.1 DeleteProjectDashboards.class, - DropIsGlobalFromDashboards.class + DropIsGlobalFromDashboards.class, + DeleteReportsFromCeQueue.class ); } } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v61/DeleteReportsFromCeQueue.java b/sonar-db/src/main/java/org/sonar/db/version/v61/DeleteReportsFromCeQueue.java new file mode 100644 index 00000000000..805e858aaf4 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v61/DeleteReportsFromCeQueue.java @@ -0,0 +1,48 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v61; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.ce.CeTaskTypes; +import org.sonar.db.version.BaseDataChange; + +/** + * SONAR-7903 - in version 6.1 analysis reports are not persisted on FS anymore + * but in DB. For simplicity of migration report files are not copied to DB. + * To avoid failures on missing reports, tasks are simply ignored and removed from + * queue. + */ +public class DeleteReportsFromCeQueue extends BaseDataChange { + + public DeleteReportsFromCeQueue(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context + .prepareUpsert("delete from ce_queue where task_type=?") + .setString(1, CeTaskTypes.REPORT) + .execute() + .commit(); + } + +} diff --git a/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql index 02da496f805..86e4ace840e 100644 --- a/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql +++ b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql @@ -489,6 +489,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1277'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1300'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1301'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1302'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1303'); INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, USER_LOCAL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', true, 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482'); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; diff --git a/sonar-db/src/test/java/org/sonar/db/ce/CeTaskDataDaoTest.java b/sonar-db/src/test/java/org/sonar/db/ce/CeTaskDataDaoTest.java index bacd7101fce..42704cc027a 100644 --- a/sonar-db/src/test/java/org/sonar/db/ce/CeTaskDataDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/ce/CeTaskDataDaoTest.java @@ -88,8 +88,6 @@ public class CeTaskDataDaoTest { @Test public void selectUuidsNotInQueue() { - assertThat(underTest.selectUuidsNotInQueue(dbTester.getSession())).isEmpty(); - insertData("U1"); insertData("U2"); assertThat(underTest.selectUuidsNotInQueue(dbTester.getSession())).containsOnly("U1", "U2"); @@ -110,7 +108,6 @@ public class CeTaskDataDaoTest { } private void insertData(String uuid) { - dbTester.executeInsert(TABLE_NAME, "TASK_UUID", uuid, "CREATED_AT", NOW, "UPDATED_AT", NOW); dbTester.commit(); } diff --git a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java index 1983e73c711..cd190a68543 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java @@ -29,6 +29,6 @@ public class MigrationStepModuleTest { public void verify_count_of_added_MigrationStep_types() { ComponentContainer container = new ComponentContainer(); new MigrationStepModule().configure(container); - assertThat(container.size()).isEqualTo(128); + assertThat(container.size()).isEqualTo(129); } } diff --git a/sonar-db/src/test/java/org/sonar/db/version/v61/DeleteReportsFromCeQueueTest.java b/sonar-db/src/test/java/org/sonar/db/version/v61/DeleteReportsFromCeQueueTest.java new file mode 100644 index 00000000000..a357db11dd6 --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v61/DeleteReportsFromCeQueueTest.java @@ -0,0 +1,61 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.db.version.v61; + +import java.sql.SQLException; +import java.util.List; +import java.util.Map; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.utils.System2; +import org.sonar.db.DbTester; +import org.sonar.db.ce.CeTaskTypes; + +import static org.assertj.core.api.Assertions.assertThat; + +public class DeleteReportsFromCeQueueTest { + + private static final long NOW = 1_500_000_000_000L; + private static final String TABLE_NAME = "ce_queue"; + + @Rule + public DbTester db = DbTester.createForSchema(System2.INSTANCE, DeleteReportsFromCeQueueTest.class, "schema.sql"); + + private DeleteReportsFromCeQueue underTest = new DeleteReportsFromCeQueue(db.database()); + + @Test + public void no_effect_on_empty_tables() throws SQLException { + underTest.execute(); + + assertThat(db.countRowsOfTable(TABLE_NAME)).isEqualTo(0); + } + + @Test + public void delete_tasks_with_type_REPORT_only() throws SQLException { + db.executeInsert("ce_queue", "uuid", "U1", "task_type", CeTaskTypes.REPORT, "status", "PENDING", "created_at", NOW, "updated_at", NOW); + db.executeInsert("ce_queue", "uuid", "U2", "task_type", "REFRESH_VIEWS", "status", "PENDING", "created_at", NOW, "updated_at", NOW); + + underTest.execute(); + + List> uuids = db.select("select uuid as \"uuid\" from ce_queue"); + assertThat(uuids).hasSize(1); + assertThat(uuids.get(0).get("uuid")).isEqualTo("U2"); + } +} diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v61/DeleteReportsFromCeQueueTest/schema.sql b/sonar-db/src/test/resources/org/sonar/db/version/v61/DeleteReportsFromCeQueueTest/schema.sql new file mode 100644 index 00000000000..2b74746090d --- /dev/null +++ b/sonar-db/src/test/resources/org/sonar/db/version/v61/DeleteReportsFromCeQueueTest/schema.sql @@ -0,0 +1,11 @@ +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 +);