]> source.dussan.org Git - sonarqube.git/commitdiff
Add db column ce_activity.error_type
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 28 Sep 2017 11:20:32 +0000 (13:20 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 28 Sep 2017 14:45:25 +0000 (16:45 +0200)
server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDto.java
server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/AddErrorTypeColumnToCeActivityTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/AddErrorTypeColumnToCeActivityTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66Test.java
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/AddErrorTypeColumnToCeActivityTableTest/ce_activity_6_5.sql [new file with mode: 0644]

index 760b11ce89dd11f3716bd9de69da94ce4506264f..19e5a27b81f4d1d733c8571b0e011c9ec0773a57 100644 (file)
@@ -609,7 +609,8 @@ CREATE TABLE "CE_ACTIVITY" (
   "UPDATED_AT" BIGINT NOT NULL,
   "EXECUTION_TIME_MS" BIGINT NULL,
   "ERROR_MESSAGE" VARCHAR(1000),
-  "ERROR_STACKTRACE" CLOB(2147483647)
+  "ERROR_STACKTRACE" CLOB(2147483647),
+  "ERROR_TYPE" VARCHAR(20)
 );
 
 CREATE UNIQUE INDEX "CE_ACTIVITY_UUID" ON "CE_ACTIVITY" ("UUID");
index 0183618a348fbe195da8382872fe0172377b1ad7..692244129fdd13957bdfa2ef6471930214699c96 100644 (file)
@@ -69,6 +69,13 @@ public class CeActivityDto {
    * @see CeActivityDao#selectByUuid(DbSession, String)
    */
   private String errorStacktrace;
+
+  /**
+   * Optional free-text type of error. It may be set only when {@link #errorMessage} is not null.
+   */
+  @Nullable
+  private String errorType;
+
   /**
    * Flag indicating whether the analysis of the current activity has a scanner context or not.
    * <p>
@@ -247,6 +254,16 @@ public class CeActivityDto {
     return this;
   }
 
+  @CheckForNull
+  public String getErrorType() {
+    return errorType;
+  }
+
+  public CeActivityDto setErrorType(@Nullable String s) {
+    this.errorType = ensureNotTooBig(s, 20);
+    return this;
+  }
+
   @CheckForNull
   private static String ensureNotTooBig(@Nullable String str, int maxSize) {
     if (str == null) {
index 59f459c8df33a791acb15d3bf724d20a3390a7ae..3b1b34b6a3381f34b4911a5032f2107d33a5bb6c 100644 (file)
@@ -34,6 +34,7 @@
     ca.is_last_key as isLastKey,
     ca.execution_time_ms as executionTimeMs,
     ca.error_message as errorMessage,
+    ca.error_type as errorType,
     <include refid="hasScannerContextColumn"/>
   </sql>
 
       updated_at,
       execution_time_ms,
       error_message,
-      error_stacktrace
+      error_stacktrace,
+      error_type
     )
     values (
       #{uuid,jdbcType=VARCHAR},
       #{updatedAt,jdbcType=BIGINT},
       #{executionTimeMs,jdbcType=BIGINT},
       #{errorMessage,jdbcType=VARCHAR},
-      #{errorStacktrace,jdbcType=CLOB}
+      #{errorStacktrace,jdbcType=CLOB},
+      #{errorType,jdbcType=VARCHAR}
     )
   </insert>
 
index f11864bb66bd0f583d17624823907c8498d2f7f7..f887e5f49f0c224dd964bcc83a38b7d168d59883 100644 (file)
@@ -77,6 +77,7 @@ public class CeActivityDaoTest {
     assertThat(dto.toString()).isNotEmpty();
     assertThat(dto.getErrorMessage()).isNull();
     assertThat(dto.getErrorStacktrace()).isNull();
+    assertThat(dto.getErrorType()).isNull();
     assertThat(dto.isHasScannerContext()).isFalse();
   }
 
@@ -111,6 +112,7 @@ public class CeActivityDaoTest {
     CeActivityDto read = saved.get();
     assertThat(read.getErrorMessage()).isEqualTo(dto.getErrorMessage());
     assertThat(read.getErrorStacktrace()).isEqualTo(dto.getErrorStacktrace());
+    assertThat(read.getErrorType()).isNotNull().isEqualTo(dto.getErrorType());
   }
 
   @Test
@@ -360,6 +362,7 @@ public class CeActivityDaoTest {
     dto.setAnalysisUuid(uuid + "_2");
     if (status == FAILED) {
       dto.setErrorMessage("error msg for " + uuid);
+      dto.setErrorType("anErrorType");
     }
     return dto;
   }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/AddErrorTypeColumnToCeActivityTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/AddErrorTypeColumnToCeActivityTable.java
new file mode 100644 (file)
index 0000000..c423bb0
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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.v66;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+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 AddErrorTypeColumnToCeActivityTable extends DdlChange {
+
+  public AddErrorTypeColumnToCeActivityTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AddColumnsBuilder(getDialect(), "ce_activity")
+      .addColumn(VarcharColumnDef.newVarcharColumnDefBuilder()
+        .setColumnName("error_type")
+        .setLimit(20)
+        .setIsNullable(true)
+        .build())
+      .build());
+  }
+}
+
index 3bfe2ec422f963a65a33a417dc7a7414811f594c..3cb9ff5735c6f40b8097ffc5da9930f84d4b786c 100644 (file)
@@ -35,6 +35,8 @@ public class DbVersion66 implements DbVersion {
       .add(1806, "Create table project_branches", CreateTableProjectBranches.class)
       .add(1807, "Add on project_branches key", AddIndexOnProjectBranchesKey.class)
       .add(1808, "Add branch column to projects table", AddBranchColumnToProjectsTable.class)
-      .add(1809, "Populate project_branches with existing main branches", PopulateMainProjectBranches.class);
+      .add(1809, "Populate project_branches with existing main branches", PopulateMainProjectBranches.class)
+      .add(1810, "Add ce_activity.error_type", AddErrorTypeColumnToCeActivityTable.class)
+    ;
   }
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/AddErrorTypeColumnToCeActivityTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/AddErrorTypeColumnToCeActivityTableTest.java
new file mode 100644 (file)
index 0000000..f46ba8e
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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.v66;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+
+public class AddErrorTypeColumnToCeActivityTableTest {
+
+  @Rule
+  public final CoreDbTester dbTester = CoreDbTester.createForSchema(AddErrorTypeColumnToCeActivityTableTest.class, "ce_activity_6_5.sql");
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private AddErrorTypeColumnToCeActivityTable underTest = new AddErrorTypeColumnToCeActivityTable(dbTester.database());
+
+  @Test
+  public void column_is_added_to_table() throws SQLException {
+    underTest.execute();
+
+    dbTester.assertColumnDefinition("ce_activity", "error_type", java.sql.Types.VARCHAR, 20, true);
+  }
+
+  @Test
+  public void migration_is_not_reentrant() throws SQLException {
+    underTest.execute();
+
+    expectedException.expect(IllegalStateException.class);
+
+    underTest.execute();
+  }
+
+}
index 76a9365740c7fd1e35c7aabb87f69894a52ab6d3..6ebcf647366f882cdd56cfbd11ee13264b0a60a7 100644 (file)
@@ -36,7 +36,7 @@ public class DbVersion66Test {
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 9);
+    verifyMigrationCount(underTest, 10);
   }
 
 }
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/AddErrorTypeColumnToCeActivityTableTest/ce_activity_6_5.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/AddErrorTypeColumnToCeActivityTableTest/ce_activity_6_5.sql
new file mode 100644 (file)
index 0000000..588109c
--- /dev/null
@@ -0,0 +1,21 @@
+CREATE TABLE "CE_ACTIVITY" (
+  "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,
+  "ANALYSIS_UUID" VARCHAR(50) NULL,
+  "STATUS" VARCHAR(15) NOT NULL,
+  "IS_LAST" BOOLEAN NOT NULL,
+  "IS_LAST_KEY" VARCHAR(55) NOT NULL,
+  "SUBMITTER_LOGIN" VARCHAR(255) NULL,
+  "WORKER_UUID" VARCHAR(40) NULL,
+  "EXECUTION_COUNT" INTEGER NOT NULL,
+  "SUBMITTED_AT" BIGINT NOT NULL,
+  "STARTED_AT" BIGINT NULL,
+  "EXECUTED_AT" BIGINT NULL,
+  "CREATED_AT" BIGINT NOT NULL,
+  "UPDATED_AT" BIGINT NOT NULL,
+  "EXECUTION_TIME_MS" BIGINT NULL,
+  "ERROR_MESSAGE" VARCHAR(1000),
+  "ERROR_STACKTRACE" CLOB(2147483647)
+);