]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7903 Drop pending tasks
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 4 Aug 2016 19:59:10 +0000 (21:59 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 5 Aug 2016 13:45:01 +0000 (15:45 +0200)
12 files changed:
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ExtractReportStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/queue/CeQueueCleanerTest.java
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1302_create_table_ce_task_data.rb
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1303_delete_reports_from_ce_queue.rb [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java
sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java
sonar-db/src/main/java/org/sonar/db/version/v61/DeleteReportsFromCeQueue.java [new file with mode: 0644]
sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql
sonar-db/src/test/java/org/sonar/db/ce/CeTaskDataDaoTest.java
sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java
sonar-db/src/test/java/org/sonar/db/version/v61/DeleteReportsFromCeQueueTest.java [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/version/v61/DeleteReportsFromCeQueueTest/schema.sql [new file with mode: 0644]

index 6d94a12a777d4f6c14f1c5e655e31a9934fccfe7..513bc7a2738ac5ae2a27adcc690a54e28c25dfca 100644 (file)
@@ -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");
       }
index 923a684213cbd5e3216d4e77a3a3213ce0d3c557..2016648619687fc2389f531c9717c02a8c36e7b1 100644 (file)
@@ -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);
index c46371778b32568542ab2b72e0e5dc2ffbf35172..73038de8329024bfc244e314655ef887f9391607 100644 (file)
@@ -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 (file)
index 0000000..3ad2bfc
--- /dev/null
@@ -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
index 8be4800dac9802f5601a1d66224919b7896cab23..9a21f9dcb5be527db8c5b99ac894eaea89f2955b 100644 (file)
@@ -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
index c36dcd67234a5cc6e68bc9f2acd22893b6be4fb6..83cef38603872bb7f0bd6b9f42013da0742c2b12 100644 (file)
@@ -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 (file)
index 0000000..805e858
--- /dev/null
@@ -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();
+  }
+
+}
index 02da496f80588f35b4378565efb78e97d9c0aac3..86e4ace840e7dd7fb798836456c45b5cdb7f3933 100644 (file)
@@ -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;
index bacd7101fceaff191ce481ad6a2e96a6588fd9c3..42704cc027a52e509c2d1bf47153b9b30f1a7d28 100644 (file)
@@ -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();
   }
index 1983e73c711918982aea6ca7c2342c3b4a2d35a1..cd190a68543c02d614e080375726ed6c5e3cc58c 100644 (file)
@@ -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 (file)
index 0000000..a357db1
--- /dev/null
@@ -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<Map<String, Object>> 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 (file)
index 0000000..2b74746
--- /dev/null
@@ -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
+);