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;
* 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;
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");
}
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;
@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);
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
--- /dev/null
+#
+# 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
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
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 {
// 6.1
DeleteProjectDashboards.class,
- DropIsGlobalFromDashboards.class
+ DropIsGlobalFromDashboards.class,
+ DeleteReportsFromCeQueue.class
);
}
}
--- /dev/null
+/*
+ * 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();
+ }
+
+}
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;
@Test
public void selectUuidsNotInQueue() {
- assertThat(underTest.selectUuidsNotInQueue(dbTester.getSession())).isEmpty();
-
insertData("U1");
insertData("U2");
assertThat(underTest.selectUuidsNotInQueue(dbTester.getSession())).containsOnly("U1", "U2");
}
private void insertData(String uuid) {
-
dbTester.executeInsert(TABLE_NAME, "TASK_UUID", uuid, "CREATED_AT", NOW, "UPDATED_AT", NOW);
dbTester.commit();
}
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);
}
}
--- /dev/null
+/*
+ * 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");
+ }
+}
--- /dev/null
+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
+);