diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-03-02 11:48:53 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-03-02 11:48:53 +0100 |
commit | bcce12869f28494813918b4a8b62f3714599ec98 (patch) | |
tree | e4ccaafae408c62b62a7e329a0e6c126c77cd8b5 /sonar-core/src | |
parent | 6c2a68be94ec4c43e012a22276b24ce8c639f6c1 (diff) | |
parent | e29d4bfc46b6d00f80a89089a72f86b121707188 (diff) | |
download | sonarqube-bcce12869f28494813918b4a8b62f3714599ec98.tar.gz sonarqube-bcce12869f28494813918b4a8b62f3714599ec98.zip |
Merge remote-tracking branch 'origin/master' into branch-5.2
Conflicts:
server/sonar-server/src/main/java/org/sonar/server/computation/ComputationContext.java
server/sonar-server/src/main/java/org/sonar/server/computation/ComputationService.java
server/sonar-server/src/test/java/org/sonar/server/computation/ComputationServiceTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ParseReportStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeDatastoresStepMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeDatastoresStepTest.java
Diffstat (limited to 'sonar-core/src')
11 files changed, 72 insertions, 50 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java b/sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java index fe72cc88037..b528ac47aec 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java +++ b/sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java @@ -19,6 +19,7 @@ */ package org.sonar.core.component; +import org.apache.commons.lang.builder.ToStringBuilder; import org.sonar.api.component.Component; import org.sonar.api.resources.Scopes; import org.sonar.core.persistence.Dto; @@ -238,6 +239,7 @@ public class ComponentDto extends Dto<String> implements Component { return moduleUuid == null && Scopes.PROJECT.equals(scope); } + // FIXME equals/hashCode mean nothing on DTOs, especially when on id @Override public boolean equals(Object o) { if (this == o) { @@ -246,19 +248,40 @@ public class ComponentDto extends Dto<String> implements Component { if (o == null || getClass() != o.getClass()) { return false; } - ComponentDto that = (ComponentDto) o; - - if (!id.equals(that.id)) { + if (id != null ? !id.equals(that.id) : that.id != null) { return false; } - return true; } + // FIXME equals/hashCode mean nothing on DTOs, especially when on id @Override public int hashCode() { - return id.hashCode(); + return id != null ? id.hashCode() : 0; + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("id", id) + .append("uuid", uuid) + .append("kee", kee) + .append("scope", scope) + .append("qualifier", qualifier) + .append("projectUuid", projectUuid) + .append("moduleUuid", moduleUuid) + .append("moduleUuidPath", moduleUuidPath) + .append("parentProjectId", parentProjectId) + .append("copyResourceId", copyResourceId) + .append("path", path) + .append("deprecatedKey", deprecatedKey) + .append("name", name) + .append("longName", longName) + .append("language", language) + .append("enabled", enabled) + .append("authorizationUpdatedAt", authorizationUpdatedAt) + .toString(); } @Override diff --git a/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java b/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java index 4987652b89d..d5cfc718ccf 100644 --- a/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java +++ b/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java @@ -23,16 +23,12 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Objects; import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import java.io.InputStream; public class AnalysisReportDto { private Long id; private String projectKey; private Status status; - private InputStream data; - private Long snapshotId; + private String uuid; private Long createdAt; private Long updatedAt; private Long startedAt; @@ -76,19 +72,15 @@ public class AnalysisReportDto { this.status = Status.SUCCESS; } - public InputStream getData() { - return data; + public String getUuid() { + return uuid; } - public AnalysisReportDto setData(@Nullable InputStream data) { - this.data = data; + public AnalysisReportDto setUuid(String s) { + this.uuid = s; return this; } - public String getKey() { - return String.valueOf(getId()); - } - public Long getId() { return id; } @@ -98,7 +90,7 @@ public class AnalysisReportDto { return Objects.toStringHelper(this) .add("id", getId()) .add("projectKey", getProjectKey()) - .add("snapshotId", getSnapshotId()) + .add("uuid", getUuid()) .add("status", getStatus()) .add("createdAt", getCreatedAt()) .add("startedAt", getStartedAt()) @@ -106,15 +98,6 @@ public class AnalysisReportDto { .toString(); } - public Long getSnapshotId() { - return snapshotId; - } - - public AnalysisReportDto setSnapshotId(Long snapshotId) { - this.snapshotId = snapshotId; - return this; - } - @CheckForNull public Long getStartedAt() { return startedAt; diff --git a/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportMapper.java b/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportMapper.java index 223eacbe69e..f9995986a24 100644 --- a/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportMapper.java @@ -34,6 +34,8 @@ public interface AnalysisReportMapper { void truncate(); + void insert(AnalysisReportDto reportDto); + int update(AnalysisReportDto report); int updateWithBookingReport(@Param("id") Long id, @Param("startedAt") long startedAt, diff --git a/sonar-core/src/main/java/org/sonar/core/computation/dbcleaner/period/DefaultPeriodCleaner.java b/sonar-core/src/main/java/org/sonar/core/computation/dbcleaner/period/DefaultPeriodCleaner.java index e87214d4e0e..5b003323855 100644 --- a/sonar-core/src/main/java/org/sonar/core/computation/dbcleaner/period/DefaultPeriodCleaner.java +++ b/sonar-core/src/main/java/org/sonar/core/computation/dbcleaner/period/DefaultPeriodCleaner.java @@ -21,12 +21,12 @@ package org.sonar.core.computation.dbcleaner.period; import com.google.common.annotations.VisibleForTesting; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.sonar.api.ServerExtension; import org.sonar.api.config.Settings; import org.sonar.api.task.TaskExtension; import org.sonar.api.utils.DateUtils; +import org.sonar.api.utils.log.Logger; +import org.sonar.api.utils.log.Loggers; import org.sonar.core.persistence.DbSession; import org.sonar.core.persistence.MyBatis; import org.sonar.core.purge.PurgeDao; @@ -37,7 +37,7 @@ import java.util.List; public class DefaultPeriodCleaner implements TaskExtension, ServerExtension { - private static final Logger LOG = LoggerFactory.getLogger(DefaultPeriodCleaner.class); + private static final Logger LOG = Loggers.get(DefaultPeriodCleaner.class); private PurgeDao purgeDao; private Settings settings; private MyBatis mybatis; @@ -76,7 +76,7 @@ public class DefaultPeriodCleaner implements TaskExtension, ServerExtension { private void delete(List<PurgeableSnapshotDto> snapshots, DbSession session) { for (PurgeableSnapshotDto snapshot : snapshots) { - LOG.info("<- Delete snapshot: " + DateUtils.formatDateTime(snapshot.getDate()) + " [" + snapshot.getSnapshotId() + "]"); + LOG.debug("<- Delete snapshot: {} [{}]", DateUtils.formatDateTime(snapshot.getDate()), snapshot.getSnapshotId()); purgeDao.deleteSnapshots(PurgeSnapshotQuery.create().setRootSnapshotId(snapshot.getSnapshotId()), session); purgeDao.deleteSnapshots(PurgeSnapshotQuery.create().setId(snapshot.getSnapshotId()), session); } diff --git a/sonar-core/src/main/java/org/sonar/core/computation/dbcleaner/period/DeleteAllFilter.java b/sonar-core/src/main/java/org/sonar/core/computation/dbcleaner/period/DeleteAllFilter.java index 25dcb409ea1..0b6d34cbfb9 100644 --- a/sonar-core/src/main/java/org/sonar/core/computation/dbcleaner/period/DeleteAllFilter.java +++ b/sonar-core/src/main/java/org/sonar/core/computation/dbcleaner/period/DeleteAllFilter.java @@ -21,8 +21,8 @@ package org.sonar.core.computation.dbcleaner.period; import com.google.common.collect.Lists; -import org.slf4j.LoggerFactory; import org.sonar.api.utils.DateUtils; +import org.sonar.api.utils.log.Loggers; import org.sonar.core.purge.PurgeableSnapshotDto; import java.util.Date; @@ -48,6 +48,6 @@ class DeleteAllFilter implements Filter { @Override public void log() { - LoggerFactory.getLogger(getClass()).info("-> Delete data prior to: " + DateUtils.formatDate(before)); + Loggers.get(getClass()).debug("-> Delete data prior to: {}", DateUtils.formatDate(before)); } } diff --git a/sonar-core/src/main/java/org/sonar/core/computation/dbcleaner/period/KeepOneFilter.java b/sonar-core/src/main/java/org/sonar/core/computation/dbcleaner/period/KeepOneFilter.java index 419add8383f..b1087066243 100644 --- a/sonar-core/src/main/java/org/sonar/core/computation/dbcleaner/period/KeepOneFilter.java +++ b/sonar-core/src/main/java/org/sonar/core/computation/dbcleaner/period/KeepOneFilter.java @@ -22,8 +22,8 @@ package org.sonar.core.computation.dbcleaner.period; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Lists; -import org.slf4j.LoggerFactory; import org.sonar.api.utils.DateUtils; +import org.sonar.api.utils.log.Loggers; import org.sonar.core.purge.PurgeableSnapshotDto; import java.util.Date; @@ -56,7 +56,7 @@ class KeepOneFilter implements Filter { @Override public void log() { - LoggerFactory.getLogger(getClass()).info("-> Keep one snapshot per " + label + " between " + DateUtils.formatDate(start) + " and " + DateUtils.formatDate(end)); + Loggers.get(getClass()).debug("-> Keep one snapshot per {} between {} and {}", label, DateUtils.formatDate(start), DateUtils.formatDate(end)); } private void appendSnapshotsToDelete(Interval interval, List<PurgeableSnapshotDto> toDelete) { diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index 0ab6f186cd4..48459ea8fc6 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -33,7 +33,7 @@ import java.util.List; */ public class DatabaseVersion implements BatchComponent, ServerComponent { - public static final int LAST_VERSION = 795; + public static final int LAST_VERSION = 796; /** * List of all the tables.n diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java index 6af3a526fcd..a294dce2a6b 100644 --- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java @@ -32,7 +32,11 @@ import org.sonar.core.persistence.MyBatis; import org.sonar.core.resource.ResourceDao; import org.sonar.core.resource.ResourceDto; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.List; import static org.sonar.api.utils.DateUtils.dateToLong; @@ -69,7 +73,7 @@ public class PurgeDao { PurgeCommands commands = new PurgeCommands(session, mapper, profiler); List<ResourceDto> projects = getProjects(conf.rootProjectIdUuid().getId(), session); for (ResourceDto project : projects) { - LOG.info("-> Clean " + project.getLongName() + " [id=" + project.getId() + "]"); + LOG.debug("-> Clean " + project.getLongName() + " [id=" + project.getId() + "]"); deleteAbortedBuilds(project, commands); purge(project, conf.scopesWithoutHistoricalData(), commands); } @@ -87,7 +91,7 @@ public class PurgeDao { private void deleteAbortedBuilds(ResourceDto project, PurgeCommands commands) { if (hasAbortedBuilds(project.getId(), commands)) { - LOG.info("<- Delete aborted builds"); + LOG.debug("<- Delete aborted builds"); PurgeSnapshotQuery query = PurgeSnapshotQuery.create() .setIslast(false) .setStatus(new String[] {"U"}) @@ -112,7 +116,7 @@ public class PurgeDao { .setNotPurged(true) ); for (final Long projectSnapshotId : projectSnapshotIds) { - LOG.info("<- Clean snapshot " + projectSnapshotId); + LOG.debug("<- Clean snapshot " + projectSnapshotId); if (!ArrayUtils.isEmpty(scopesWithoutHistoricalData)) { PurgeSnapshotQuery query = PurgeSnapshotQuery.create() .setIslast(false) diff --git a/sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml b/sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml index bcaf5eea10e..7e37e574d99 100644 --- a/sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml @@ -7,22 +7,32 @@ ar.id, ar.project_key as projectKey, ar.report_status as status, - ar.snapshot_id as snapshotId, + ar.uuid as uuid, ar.created_at as createdAt, ar.updated_at as updatedAt, ar.started_at as startedAt, ar.finished_at as finishedAt </sql> + <insert id="insert" parameterType="AnalysisReport" useGeneratedKeys="true" keyColumn="id" keyProperty="id"> + insert into analysis_reports + (project_key, uuid, report_status, created_at, updated_at, started_at, finished_at) + values ( + #{projectKey,jdbcType=VARCHAR}, #{uuid,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, + #{createdAt,jdbcType=BIGINT}, #{updatedAt,jdbcType=BIGINT}, #{startedAt,jdbcType=BIGINT}, + #{finishedAt,jdbcType=BIGINT} + ) + </insert> + <update id="resetAllToPendingStatus" parameterType="map"> update analysis_reports - set report_status='PENDING', updated_at=#{updatedAt}, started_at=NULL + set report_status='PENDING', updated_at=#{updatedAt,jdbcType=BIGINT}, started_at=NULL </update> <update id="updateWithBookingReport" parameterType="map"> update analysis_reports - set report_status=#{busyStatus}, - started_at=#{startedAt} + set report_status=#{busyStatus,jdbcType=VARCHAR}, + started_at=#{startedAt,jdbcType=BIGINT} where id=#{id} and report_status=#{availableStatus} </update> @@ -59,7 +69,7 @@ where ar.project_key = ar2.project_key and ar2.report_status=#{busyStatus} ) - order by created_at asc + order by ar.created_at asc, ar.id asc </select> <select id="selectAll" resultType="AnalysisReport"> diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql index c8a2417dba7..a410243e678 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql @@ -322,6 +322,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('792'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('793'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('794'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('795'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('796'); INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482', null, null); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl index 092477c188c..a722b4673ae 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl @@ -541,11 +541,10 @@ CREATE TABLE "ANALYSIS_REPORTS" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "PROJECT_KEY" VARCHAR(400) NOT NULL, "PROJECT_NAME" VARCHAR(256) NULL, - "SNAPSHOT_ID" INTEGER NOT NULL, "REPORT_STATUS" VARCHAR(20) NOT NULL, - "REPORT_DATA" BLOB(2147483647), - "CREATED_AT" BIGINT, - "UPDATED_AT" BIGINT, + "UUID" VARCHAR(50) NOT NULL, + "CREATED_AT" BIGINT NOT NULL, + "UPDATED_AT" BIGINT NOT NULL, "STARTED_AT" BIGINT, "FINISHED_AT" BIGINT ); |