package org.sonar.server.computation;
import com.google.common.collect.ImmutableMap;
-import org.sonar.api.utils.DateUtils;
import org.sonar.core.activity.ActivityLog;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.computation.db.AnalysisReportDto;
import java.util.Map;
+import static org.sonar.api.utils.DateUtils.formatDateTimeNullSafe;
+import static org.sonar.api.utils.DateUtils.timeToDate;
+
public class AnalysisReportLog implements ActivityLog {
private static final String ACTION = "LOG_ANALYSIS_REPORT";
.put("projectName", project.name())
.put("projectUuid", project.uuid())
.put("status", String.valueOf(report.getStatus()))
- .put("submittedAt", DateUtils.formatDateTimeNullSafe(report.getCreatedAt()))
- .put("startedAt", DateUtils.formatDateTimeNullSafe(report.getStartedAt()))
- .put("finishedAt", DateUtils.formatDateTimeNullSafe(report.getFinishedAt()))
+ .put("submittedAt", formatDateTimeNullSafe(timeToDate(report.getCreatedAt())))
+ .put("startedAt", formatDateTimeNullSafe(timeToDate(report.getStartedAt())))
+ .put("finishedAt", formatDateTimeNullSafe(timeToDate(report.getFinishedAt())))
.build();
}
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import java.io.InputStream;
-import java.util.Date;
import java.util.List;
import static com.google.common.base.Preconditions.checkArgument;
DbSession session = dbClient.openSession(false);
try {
- report.setFinishedAt(new Date(system2.now()));
+ report.setFinishedAt(system2.now());
dbClient.analysisReportDao().delete(session, report.getId());
session.commit();
} finally {
}
private void logActivity(DbSession session, AnalysisReportDto report, ComponentDto project) {
- report.setFinishedAt(System2.INSTANCE.newDate());
+ report.setFinishedAt(System2.INSTANCE.now());
activityService.write(session, Activity.Type.ANALYSIS_REPORT, new AnalysisReportLog(report, project));
}
}
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Timestamp;
-import java.util.Date;
+import java.sql.*;
import java.util.List;
import static org.sonar.core.computation.db.AnalysisReportDto.Status.PENDING;
* Update all rows with: STATUS='PENDING', STARTED_AT=NULL, UPDATED_AT={now}
*/
public void resetAllToPendingStatus(DbSession session) {
- mapper(session).resetAllToPendingStatus(system2.newDate());
+ mapper(session).resetAllToPendingStatus(system2.now());
}
public void truncate(DbSession session) {
@VisibleForTesting
AnalysisReportDto tryToPop(DbSession session, long reportId) {
AnalysisReportMapper mapper = mapper(session);
- int nbOfReportBooked = mapper.updateWithBookingReport(reportId, system2.newDate(), PENDING, WORKING);
+ int nbOfReportBooked = mapper.updateWithBookingReport(reportId, system2.now(), PENDING, WORKING);
if (nbOfReportBooked == 0) {
return null;
}
}
public AnalysisReportDto insert(DbSession session, AnalysisReportDto report) {
- report.setCreatedAt(system2.newDate());
- report.setUpdatedAt(system2.newDate());
+ report.setCreatedAt(system2.now());
+ report.setUpdatedAt(system2.now());
Connection connection = session.getConnection();
PreparedStatement ps = null;
ps.setLong(2, report.getSnapshotId());
ps.setString(3, report.getStatus().toString());
setData(ps, 4, report.getData());
- ps.setTimestamp(5, dateToTimestamp(report.getCreatedAt()));
- ps.setTimestamp(6, dateToTimestamp(report.getUpdatedAt()));
- ps.setTimestamp(7, dateToTimestamp(report.getStartedAt()));
- ps.setTimestamp(8, dateToTimestamp(report.getFinishedAt()));
+ ps.setLong(5, report.getCreatedAt());
+ setLong(ps, 6, report.getUpdatedAt());
+ setLong(ps, 7, report.getStartedAt());
+ setLong(ps, 8, report.getFinishedAt());
ps.executeUpdate();
connection.commit();
return report;
}
+ private void setLong(PreparedStatement ps, int index, @Nullable Long time) throws SQLException {
+ if (time == null) {
+ ps.setNull(index, Types.BIGINT);
+ } else {
+ ps.setLong(index, time);
+ }
+ }
+
private void setData(PreparedStatement ps, int parameterIndex, @Nullable InputStream reportDataStream) throws IOException, SQLException {
if (reportDataStream == null) {
ps.setBytes(parameterIndex, null);
}
}
- private Timestamp dateToTimestamp(@Nullable Date date) {
- if (date == null) {
- return null;
- }
- return new Timestamp(date.getTime());
- }
-
public void delete(DbSession session, long id) {
mapper(session).delete(id);
}
import java.util.List;
+import static org.sonar.api.utils.DateUtils.timeToDate;
+
/**
* @since 5.0
*/
json.prop("key", report.getId());
json.prop("projectKey", report.getProjectKey());
json.prop("projectName", report.getProjectKey());
- json.propDateTime("startedAt", report.getStartedAt());
- json.propDateTime("finishedAt", report.getFinishedAt());
- json.propDateTime("submittedAt", report.getCreatedAt());
+ json.propDateTime("startedAt", timeToDate(report.getStartedAt()));
+ json.propDateTime("finishedAt", timeToDate(report.getFinishedAt()));
+ json.propDateTime("submittedAt", timeToDate(report.getCreatedAt()));
json.prop("status", report.getStatus().toString());
json.endObject();
}
FeedUsersLongDates.class,
RenameComponentRelatedParamsInIssueFilters.class,
CopyScmAccountsFromAuthorsToUsers.class,
- FeedIssueChangesLongDates.class
+ FeedIssueChangesLongDates.class,
+ FeedAnalysisReportsLongDates.class
);
}
--- /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.
+ */
+
+package org.sonar.server.db.migrations.v51;
+
+import org.sonar.api.utils.System2;
+import org.sonar.core.persistence.Database;
+import org.sonar.server.db.migrations.BaseDataChange;
+import org.sonar.server.db.migrations.MassUpdate;
+import org.sonar.server.db.migrations.Select;
+import org.sonar.server.db.migrations.SqlStatement;
+
+import java.sql.SQLException;
+import java.util.Date;
+
+public class FeedAnalysisReportsLongDates extends BaseDataChange {
+
+ private final System2 system;
+
+ public FeedAnalysisReportsLongDates(Database db, System2 system) {
+ super(db);
+ this.system = system;
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ final long now = system.now();
+
+ MassUpdate massUpdate = context.prepareMassUpdate();
+ massUpdate.select("SELECT a.created_at, a.updated_at, a.started_at, a.finished_at, a.id FROM analysis_reports a WHERE created_at_ms IS NULL");
+ massUpdate.update("UPDATE analysis_reports SET created_at_ms=?, updated_at_ms=?, started_at_ms=?, finished_at_ms=? WHERE id=?");
+ massUpdate.rowPluralName("analysis_reports");
+ massUpdate.execute(new MassUpdate.Handler() {
+ @Override
+ public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
+ Date createdAt = row.getDate(1);
+ Date updatedAt = row.getDate(2);
+ Date startedAt = row.getDate(3);
+ Date finishedAt = row.getDate(4);
+ Long id = row.getLong(5);
+
+ updateColumn(update, 1, createdAt);
+ updateColumn(update, 2, updatedAt);
+ update.setLong(3, startedAt == null ? null : startedAt.getTime());
+ update.setLong(4, finishedAt == null ? null : finishedAt.getTime());
+ update.setLong(5, id);
+ return true;
+ }
+
+ private void updateColumn(SqlStatement update, int position, Date time) throws SQLException {
+ if (time == null) {
+ update.setLong(position, now);
+ } else {
+ update.setLong(position, Math.min(now, time.getTime()));
+ }
+ }
+ });
+ }
+
+}
AnalysisReportDto report = AnalysisReportDto.newForTests(1L)
.setProjectKey("projectKey")
.setStatus(FAILED)
- .setCreatedAt(DateUtils.parseDate("2014-10-15"))
- .setUpdatedAt(DateUtils.parseDate("2014-10-16"))
- .setStartedAt(DateUtils.parseDate("2014-10-17"))
- .setFinishedAt(DateUtils.parseDate("2014-10-18"));
+ .setCreatedAt(DateUtils.parseDate("2014-10-15").getTime())
+ .setUpdatedAt(DateUtils.parseDate("2014-10-16").getTime())
+ .setStartedAt(DateUtils.parseDate("2014-10-17").getTime())
+ .setFinishedAt(DateUtils.parseDate("2014-10-18").getTime());
ComponentDto project = ComponentTesting.newProjectDto();
service.write(dbSession, ANALYSIS_REPORT, new AnalysisReportLog(report, project));
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TemporaryFolder;
-import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.System2;
import org.sonar.core.computation.db.AnalysisReportDto;
import org.sonar.core.persistence.DbSession;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.sonar.api.utils.DateUtils.parseDate;
import static org.sonar.core.computation.db.AnalysisReportDto.Status.PENDING;
import static org.sonar.core.computation.db.AnalysisReportDto.Status.WORKING;
this.system2 = mock(System2.class);
this.sut = new AnalysisReportDao(system2);
- when(system2.now()).thenReturn(DateUtils.parseDate("2014-09-26").getTime());
- when(system2.newDate()).thenReturn(DateUtils.parseDate("2014-09-26"));
+ when(system2.now()).thenReturn(parseDate("2014-09-26").getTime());
+ when(system2.newDate()).thenReturn(parseDate("2014-09-26"));
}
@After
AnalysisReportDto report = sut.selectById(session, 1L);
assertThat(report.getProjectKey()).isEqualTo(DEFAULT_PROJECT_KEY);
- assertThat(report.getCreatedAt()).isEqualTo(DateUtils.parseDate("2014-09-24"));
- assertThat(report.getUpdatedAt()).isEqualTo(DateUtils.parseDate("2014-09-25"));
- assertThat(report.getStartedAt()).isEqualTo(DateUtils.parseDate("2014-09-26"));
- assertThat(report.getFinishedAt()).isEqualTo(DateUtils.parseDate("2014-09-27"));
+ assertThat(report.getCreatedAt()).isEqualTo(parseDate("2014-09-24").getTime());
+ assertThat(report.getUpdatedAt()).isEqualTo(parseDate("2014-09-25").getTime());
+ assertThat(report.getStartedAt()).isEqualTo(parseDate("2014-09-26").getTime());
+ assertThat(report.getFinishedAt()).isEqualTo(parseDate("2014-09-27").getTime());
assertThat(report.getStatus()).isEqualTo(WORKING);
assertThat(report.getData()).isNull();
assertThat(report.getKey()).isEqualTo("1");
.setProjectKey("project-key")
.setStatus(PENDING)
.setData(null)
- .setCreatedAt(DateUtils.parseDateTime("2014-10-13T00:00:00+0200"))
- .setStartedAt(DateUtils.parseDateTime("2014-10-13T00:00:00+0200"))
- .setFinishedAt(DateUtils.parseDateTime("2014-10-13T00:00:00+0200"));
+ .setCreatedAt(DateUtils.parseDateTime("2014-10-13T00:00:00+0200").getTime())
+ .setStartedAt(DateUtils.parseDateTime("2014-10-13T00:00:00+0200").getTime())
+ .setFinishedAt(DateUtils.parseDateTime("2014-10-13T00:00:00+0200").getTime());
List<AnalysisReportDto> reports = Lists.newArrayList(report);
when(queue.all()).thenReturn(reports);
--- /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.
+ */
+
+package org.sonar.server.db.migrations.v51;
+
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.core.persistence.DbTester;
+import org.sonar.server.db.migrations.DatabaseMigration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class FeedAnalysisReportsLongDatesTest {
+ @ClassRule
+ public static DbTester db = new DbTester().schema(FeedAnalysisReportsLongDatesTest.class, "schema.sql");
+
+ @Test
+ public void execute() throws Exception {
+ db.prepareDbUnit(getClass(), "before.xml");
+
+ System2 system = mock(System2.class);
+ when(system.now()).thenReturn(1500000000000L);
+ DatabaseMigration migration = new FeedAnalysisReportsLongDates(db.database(), system);
+ migration.execute();
+
+ int count = db.countSql("select count(*) from analysis_reports where created_at_ms is not null and updated_at_ms is not null");
+ assertThat(count).isEqualTo(3);
+
+ int countWithAllDateFieldsNull = db
+ .countSql("select count(*) from analysis_reports where created_at_ms is not null and updated_at_ms is not null and started_at_ms is not null and finished_at_ms is not null");
+ assertThat(countWithAllDateFieldsNull).isEqualTo(2);
+ }
+}
depth="1" scope="DIR" qualifier="PAC" created_at="2008-12-02" build_date="2011-09-29"
version="2.1-SNAPSHOT" path="1.2."/>
- <!-- PROJECT_ID = 3 – no last snapshot -->
+ <!-- PROJECT_ID = 3 - no last snapshot -->
<snapshots id="5" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
status="P" islast="[false]" purge_status="1"
period1_mode="days1" period1_param="30" period1_date="2011-09-24"
period5_mode="days5" period5_param="34" period5_date="2011-09-28"
depth="1" scope="DIR" qualifier="PAC" created_at="2008-12-03" build_date="2011-09-29"
version="2.1-SNAPSHOT" path="1.2."/>
- <!-- PROJECT_ID = 3 – no last snapshot -->
+ <!-- PROJECT_ID = 3 - no last snapshot -->
<snapshots id="4" project_id="3" parent_snapshot_id="2" root_project_id="123" root_snapshot_id="1"
status="U" islast="[false]" purge_status="1"
period1_mode="days1" period1_param="30" period1_date="2011-09-24"
period5_mode="days5" period5_param="34" period5_date="2011-09-28"
depth="1" scope="DIR" qualifier="PAC" created_at="2008-12-02" build_date="2011-09-29"
version="2.1-SNAPSHOT" path="1.2."/>
- <!-- PROJECT_ID = 3 – no last snapshot -->
+ <!-- PROJECT_ID = 3 - no last snapshot -->
<snapshots id="24" project_id="3" parent_snapshot_id="2" root_project_id="123" root_snapshot_id="21"
status="P" islast="[true]" purge_status="1"
period1_mode="days1" period1_param="30" period1_date="2011-09-24"
period5_mode="days5" period5_param="34" period5_date="2011-09-28"
depth="1" scope="DIR" qualifier="PAC" created_at="2008-12-01" build_date="2011-09-29"
version="2.1-SNAPSHOT" path="1.2."/>
- <!-- PROJECT_ID = 3 – no last snapshot -->
+ <!-- PROJECT_ID = 3 - no last snapshot -->
<snapshots id="49" project_id="3" parent_snapshot_id="2" root_project_id="123" root_snapshot_id="46"
status="P" islast="[false]" purge_status="1"
period1_mode="days1" period1_param="30" period1_date="2011-09-24"
snapshot_id="123"
report_data="data-project"
report_status="WORKING"
- created_at="2014-09-24"
- updated_at="2014-09-24"
+ created_at="1411509600000"
+ updated_at="1411509600000"
/>
<analysis_reports
id="2"
snapshot_id="123"
report_data="data-project"
report_status="WORKING"
- created_at="2014-09-25"
- updated_at="2014-09-25"
+ created_at="1411596000000"
+ updated_at="1411596000000"
/>
<analysis_reports
id="3"
snapshot_id="123"
report_data="data-project"
report_status="PENDING"
- created_at="2014-09-26"
- updated_at="2014-09-26"
+ created_at="1411682400000"
+ updated_at="1411682400000"
/>
</dataset>
\ No newline at end of file
snapshot_id="123"
report_data="data-project"
report_status="PENDING"
- created_at="2014-09-24"
- updated_at="2014-09-25"
+ created_at="1411509600000"
+ updated_at="1411596000000"
/>
<analysis_reports
id="2"
snapshot_id="123"
report_data="data-project"
report_status="WORKING"
- created_at="2014-09-23"
- updated_at="2014-09-26"
+ created_at="1411423200000"
+ updated_at="1411682400000"
/>
</dataset>
\ No newline at end of file
report_status="PENDING"
started_at="[null]"
finished_at="[null]"
- created_at="2014-09-26 00:00:00.0"
- updated_at="2014-09-26 00:00:00.0"
+ created_at="1411682400000"
+ updated_at="1411682400000"
/>
<analysis_reports
id="2"
report_status="PENDING"
started_at="[null]"
finished_at="[null]"
- created_at="2014-09-26 00:00:00.0"
- updated_at="2014-09-26 00:00:00.0"
+ created_at="1411682400000"
+ updated_at="1411682400000"
/>
</dataset>
snapshot_id="123"
report_data="data-project"
report_status="WORKING"
- created_at="2014-09-24"
- updated_at="2014-09-25"
- started_at="2014-09-26"
- finished_at="2014-09-27"
+ created_at="1411509600000"
+ updated_at="1411596000000"
+ started_at="1411682400000"
+ finished_at="1411768800000"
/>
</dataset>
\ No newline at end of file
snapshot_id="123"
report_data="data-project"
report_status="PENDING"
- created_at="2014-09-24"
- updated_at="2014-09-25"
+ created_at="1411509600000"
+ updated_at="1411596000000"
/>
<analysis_reports
id="2"
snapshot_id="123"
report_data="data-project"
report_status="PENDING"
- created_at="2014-09-24"
- updated_at="2014-09-25"
+ created_at="1411509600000"
+ updated_at="1411596000000"
/>
</dataset>
snapshot_id="123"
report_data="data-project"
report_status="PENDING"
- created_at="2014-09-24"
- updated_at="2014-09-25"
+ created_at="1411509600000"
+ updated_at="1411596000000"
/>
<analysis_reports
id="2"
snapshot_id="123"
report_data="data-project"
report_status="WORKING"
- created_at="2014-09-23"
- updated_at="2014-09-26"
+ created_at="1411423200000"
+ updated_at="1411682400000"
/>
</dataset>
\ No newline at end of file
snapshot_id="123"
report_data="data-project"
report_status="WORKING"
- created_at="2014-09-24"
- updated_at="2014-09-25"
+ created_at="1411509600000"
+ updated_at="1411596000000"
/>
</dataset>
snapshot_id="123"
report_data="data-project"
report_status="WORKING"
- created_at="2014-09-25"
- updated_at="2014-09-26"
+ created_at="1411596000000"
+ updated_at="1411682400000"
/>
<analysis_reports
id="2"
snapshot_id="123"
report_data="data-project"
report_status="WORKING"
- created_at="2014-09-24"
- updated_at="2014-09-26"
+ created_at="1411509600000"
+ updated_at="1411682400000"
/>
<!-- not select as the previous report which is working is on the same project -->
<analysis_reports
snapshot_id="123"
report_data="data-project"
report_status="PENDING"
- created_at="2014-09-25"
- updated_at="2014-09-26"
+ created_at="1411596000000"
+ updated_at="1411682400000"
/>
</dataset>
\ No newline at end of file
snapshot_id="1"
report_data="data-project"
report_status="WORKING"
- created_at="2014-09-25"
- updated_at="2014-09-26"
+ created_at="1411596000000"
+ updated_at="1411682400000"
/>
<!-- PENDING on P1, which is already being WORKING-->
snapshot_id="2"
report_data="data-project"
report_status="PENDING"
- created_at="2014-09-24"
- updated_at="2014-09-26"
+ created_at="1411509600000"
+ updated_at="1411682400000"
/>
<analysis_reports
id="3"
snapshot_id="3"
report_data="data-project"
report_status="PENDING"
- created_at="2014-09-25"
- updated_at="2014-09-26"
+ created_at="1411596000000"
+ updated_at="1411682400000"
/>
<analysis_reports
id="4"
snapshot_id="4"
report_data="data-project"
report_status="PENDING"
- created_at="2015-01-01"
- updated_at="2015-01-01"
+ created_at="1420066800000"
+ updated_at="1420066800000"
/>
</dataset>
snapshot_id="123"
report_data="data-project"
report_status="WORKING"
- created_at="2014-09-24"
- updated_at="2014-09-25"
+ created_at="1411509600000"
+ updated_at="1411596000000"
/>
<analysis_reports
id="2"
snapshot_id="123"
report_data="data-project"
report_status="WORKING"
- created_at="2014-09-25"
- updated_at="2014-09-25"
+ created_at="1411596000000"
+ updated_at="1411596000000"
/>
<analysis_reports
id="3"
snapshot_id="123"
report_data="data-project"
report_status="PENDING"
- created_at="2014-09-26"
- updated_at="2014-09-26"
+ created_at="1411682400000"
+ updated_at="1411682400000"
/>
</dataset>
\ No newline at end of file
snapshot_id="123"
report_data="data-project"
report_status="WORKING"
- created_at="2014-09-23"
- updated_at="2014-09-26"
+ created_at="1411423200000"
+ updated_at="1411682400000"
/>
<analysis_reports
id="2"
snapshot_id="123"
report_data="data-project"
report_status="PENDING"
- created_at="2014-09-24"
- updated_at="2014-09-26"
+ created_at="1411509600000"
+ updated_at="1411682400000"
/>
<analysis_reports
id="3"
snapshot_id="123"
report_data="data-project"
report_status="WORKING"
- created_at="2014-09-25"
- updated_at="2014-09-26"
+ created_at="1411596000000"
+ updated_at="1411682400000"
/>
</dataset>
\ No newline at end of file
snapshot_id="123"
report_data="data-project"
report_status="WORKING"
- created_at="2014-09-24"
- updated_at="2014-09-25"
+ created_at="1411509600000"
+ updated_at="1411596000000"
/>
<analysis_reports
id="2"
snapshot_id="123"
report_data="data-project"
report_status="WORKING"
- created_at="2014-09-25"
- updated_at="2014-09-25"
+ created_at="1411596000000"
+ updated_at="1411596000000"
/>
<analysis_reports
id="3"
snapshot_id="123"
report_data="data-project"
report_status="PENDING"
- created_at="2014-09-26"
- updated_at="2014-09-26"
+ created_at="1411682400000"
+ updated_at="1411682400000"
/>
</dataset>
\ No newline at end of file
snapshot_id="1"
report_data="data-project"
report_status="PENDING"
- created_at="2014-09-24"
- updated_at="2014-09-26 00:00:00.0"
+ created_at="1411509600000"
+ updated_at="1411682400000"
started_at="[null]"
finished_at="[null]"
/>
snapshot_id="123"
report_data="data-project"
report_status="PENDING"
- created_at="2014-09-25"
- updated_at="2014-09-26 00:00:00.0"
+ created_at="1411596000000"
+ updated_at="1411682400000"
started_at="[null]"
finished_at="[null]"
/>
snapshot_id="123"
report_data="data-project"
report_status="PENDING"
- created_at="2014-09-26"
- updated_at="2014-09-26 00:00:00.0"
+ created_at="1411682400000"
+ updated_at="1411682400000"
started_at="[null]"
finished_at="[null]"
/>
snapshot_id="1"
report_data="data-project"
report_status="WORKING"
- created_at="2014-09-24"
- updated_at="2014-09-24"
- started_at="2014-09-24"
+ created_at="1411509600000"
+ updated_at="1411509600000"
+ started_at="1411509600000"
finished_at="[null]"
/>
<analysis_reports
snapshot_id="123"
report_data="data-project"
report_status="WORKING"
- created_at="2014-09-25"
- updated_at="2014-09-25"
- started_at="2014-09-24"
+ created_at="1411596000000"
+ updated_at="1411596000000"
+ started_at="1411509600000"
finished_at="[null]"
/>
<analysis_reports
snapshot_id="123"
report_data="data-project"
report_status="PENDING"
- created_at="2014-09-26"
- updated_at="2014-09-26"
+ created_at="1411682400000"
+ updated_at="1411682400000"
started_at="[null]"
finished_at="[null]"
/>
period5_mode="days5" period5_param="34" period5_date="2011-09-28"
depth="1" scope="DIR" qualifier="PAC" created_at="2008-12-03" build_date="2011-09-29"
version="2.1-SNAPSHOT" path="1.2."/>
- <!-- PROJECT_ID = 3 – no last snapshot -->
+ <!-- PROJECT_ID = 3 - no last snapshot -->
<snapshots id="4" project_id="3" parent_snapshot_id="2" root_project_id="123" root_snapshot_id="1"
status="P" islast="[true]" purge_status="1"
period1_mode="days1" period1_param="30" period1_date="2011-09-24"
period5_mode="days5" period5_param="34" period5_date="2011-09-28"
depth="1" scope="DIR" qualifier="PAC" created_at="2008-12-02" build_date="2011-09-29"
version="2.1-SNAPSHOT" path="1.2."/>
- <!-- PROJECT_ID = 3 – no last snapshot -->
+ <!-- PROJECT_ID = 3 - no last snapshot -->
<snapshots id="24" project_id="3" parent_snapshot_id="2" root_project_id="123" root_snapshot_id="21"
status="P" islast="[false]" purge_status="1"
period1_mode="days1" period1_param="30" period1_date="2011-09-24"
period5_mode="days5" period5_param="34" period5_date="2011-09-28"
depth="1" scope="DIR" qualifier="PAC" created_at="2008-12-01" build_date="2011-09-29"
version="2.1-SNAPSHOT" path="1.2."/>
- <!-- PROJECT_ID = 3 – no last snapshot -->
+ <!-- PROJECT_ID = 3 - no last snapshot -->
<snapshots id="49" project_id="3" parent_snapshot_id="2" root_project_id="123" root_snapshot_id="46"
status="P" islast="[false]" purge_status="1"
period1_mode="days1" period1_param="30" period1_date="2011-09-24"
period5_mode="days5" period5_param="34" period5_date="2011-09-28"
depth="1" scope="DIR" qualifier="PAC" created_at="2008-12-03" build_date="2011-09-29"
version="2.1-SNAPSHOT" path="1.2."/>
- <!-- PROJECT_ID = 3 – no last snapshot -->
+ <!-- PROJECT_ID = 3 - no last snapshot -->
<snapshots id="4" project_id="3" parent_snapshot_id="2" root_project_id="123" root_snapshot_id="1"
status="U" islast="[false]" purge_status="1"
period1_mode="days1" period1_param="30" period1_date="2011-09-24"
period5_mode="days5" period5_param="34" period5_date="2011-09-28"
depth="1" scope="DIR" qualifier="PAC" created_at="2008-12-02" build_date="2011-09-29"
version="2.1-SNAPSHOT" path="1.2."/>
- <!-- PROJECT_ID = 3 – no last snapshot -->
+ <!-- PROJECT_ID = 3 - no last snapshot -->
<snapshots id="24" project_id="3" parent_snapshot_id="2" root_project_id="123" root_snapshot_id="21"
status="P" islast="[true]" purge_status="1"
period1_mode="days1" period1_param="30" period1_date="2011-09-24"
period5_mode="days5" period5_param="34" period5_date="2011-09-28"
depth="1" scope="DIR" qualifier="PAC" created_at="2008-12-01" build_date="2011-09-29"
version="2.1-SNAPSHOT" path="1.2."/>
- <!-- PROJECT_ID = 3 – no last snapshot -->
+ <!-- PROJECT_ID = 3 - no last snapshot -->
<snapshots id="49" project_id="3" parent_snapshot_id="2" root_project_id="123" root_snapshot_id="46"
status="P" islast="[false]" purge_status="1"
period1_mode="days1" period1_param="30" period1_date="2011-09-24"
--- /dev/null
+<dataset>
+ <!-- new migration -->
+ <analysis_reports
+ id="1"
+ project_key="123456789-987654321"
+ snapshot_id="123"
+ report_data="data-project"
+ report_status="WORKING"
+ created_at="2014-09-25"
+ updated_at="2014-09-24"
+ started_at="2014-09-23"
+ finished_at="2014-09-22"
+ created_at_ms="[null]"
+ updated_at_ms="[null]"
+ started_at_ms="[null]"
+ finished_at_ms="[null]"
+ />
+
+ <!-- re-entrant migration - ignore the issues that are already fed with new dates -->
+ <analysis_reports
+ id="2"
+ project_key="123456789-987654321"
+ snapshot_id="123"
+ report_data="data-project"
+ report_status="WORKING"
+ created_at="2014-09-25"
+ updated_at="2014-09-24"
+ started_at="2014-09-23"
+ finished_at="2014-09-22"
+ created_at_ms="1500000000000"
+ updated_at_ms="1500000000000"
+ started_at_ms="1500000000000"
+ finished_at_ms="1500000000000"
+ />
+
+ <!-- NULL dates -->
+ <analysis_reports
+ id="3"
+ project_key="123456789-987654321"
+ snapshot_id="123"
+ report_data="data-project"
+ report_status="WORKING"
+ created_at="[null]"
+ updated_at="[null]"
+ started_at="[null]"
+ finished_at="[null]"
+ created_at_ms="[null]"
+ updated_at_ms="[null]"
+ started_at_ms="[null]"
+ finished_at_ms="[null]"
+ />
+</dataset>
--- /dev/null
+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" TIMESTAMP,
+ "UPDATED_AT" TIMESTAMP,
+ "STARTED_AT" TIMESTAMP,
+ "FINISHED_AT" TIMESTAMP,
+ "CREATED_AT_MS" BIGINT,
+ "UPDATED_AT_MS" BIGINT,
+ "STARTED_AT_MS" BIGINT,
+ "FINISHED_AT_MS" BIGINT
+);
--- /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 5.1
+#
+class AddAnalysisReportsLongDates < ActiveRecord::Migration
+
+ def self.up
+ add_column 'analysis_reports', :created_at_ms, :big_integer, :null => true
+ add_column 'analysis_reports', :updated_at_ms, :big_integer, :null => true
+ add_column 'analysis_reports', :started_at_ms, :big_integer, :null => true
+ add_column 'analysis_reports', :finished_at_ms, :big_integer, :null => true
+ end
+end
--- /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 5.1
+#
+class FeedAnalysisReportsLongDates < ActiveRecord::Migration
+
+ def self.up
+ execute_java_migration('org.sonar.server.db.migrations.v51.FeedAnalysisReportsLongDates')
+ end
+
+end
+
--- /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 5.1
+#
+class RenameAnalysisReportsLongDates < ActiveRecord::Migration
+
+ def self.up
+ remove_column 'analysis_reports', 'created_at'
+ remove_column 'analysis_reports', 'updated_at'
+ remove_column 'analysis_reports', 'started_at'
+ remove_column 'analysis_reports', 'finished_at'
+ rename_column 'analysis_reports', 'created_at_ms', 'created_at'
+ rename_column 'analysis_reports', 'updated_at_ms', 'updated_at'
+ rename_column 'analysis_reports', 'started_at_ms', 'started_at'
+ rename_column 'analysis_reports', 'finished_at_ms', 'finished_at'
+ end
+end
+
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Objects;
-import org.sonar.core.persistence.Dto;
+import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import java.io.InputStream;
-import java.util.Date;
-
-public class AnalysisReportDto extends Dto<String> {
-
- public static enum Status {
- PENDING, WORKING, SUCCESS, FAILED;
-
- public boolean isInFinalState() {
- return SUCCESS.equals(this) || FAILED.equals(this);
- }
- }
+public class AnalysisReportDto {
private Long id;
private String projectKey;
private Status status;
private InputStream data;
private Long snapshotId;
- private Date startedAt;
- private Date finishedAt;
+ private Long createdAt;
+ private Long updatedAt;
+ private Long startedAt;
+ private Long finishedAt;
@VisibleForTesting
public static AnalysisReportDto newForTests(Long id) {
return this;
}
- @Override
public String getKey() {
return String.valueOf(getId());
}
return this;
}
- public Date getStartedAt() {
+ @CheckForNull
+ public Long getStartedAt() {
return startedAt;
}
- public AnalysisReportDto setStartedAt(Date startedAt) {
+ public AnalysisReportDto setStartedAt(Long startedAt) {
this.startedAt = startedAt;
return this;
}
- public Date getFinishedAt() {
+ @CheckForNull
+ public Long getFinishedAt() {
return finishedAt;
}
- public AnalysisReportDto setFinishedAt(Date finishedAt) {
+ public AnalysisReportDto setFinishedAt(Long finishedAt) {
this.finishedAt = finishedAt;
return this;
}
- @Override
- public AnalysisReportDto setUpdatedAt(Date datetime) {
- super.setUpdatedAt(datetime);
+ public Long getCreatedAt() {
+ return createdAt;
+ }
+
+ public AnalysisReportDto setCreatedAt(Long createdAt) {
+ this.createdAt = createdAt;
return this;
}
- @Override
- public AnalysisReportDto setCreatedAt(Date datetime) {
- super.setCreatedAt(datetime);
+ public Long getUpdatedAt() {
+ return updatedAt;
+ }
+
+ public AnalysisReportDto setUpdatedAt(Long updatedAt) {
+ this.updatedAt = updatedAt;
return this;
}
+
+ public static enum Status {
+ PENDING, WORKING, SUCCESS, FAILED;
+
+ public boolean isInFinalState() {
+ return SUCCESS.equals(this) || FAILED.equals(this);
+ }
+ }
}
import org.apache.ibatis.annotations.Param;
-import java.util.Date;
import java.util.List;
public interface AnalysisReportMapper {
@Param("availableStatus") AnalysisReportDto.Status availableStatus,
@Param("busyStatus") AnalysisReportDto.Status busyStatus);
- void resetAllToPendingStatus(@Param("updatedAt") Date updatedAt);
+ void resetAllToPendingStatus(@Param("updatedAt") long updatedAt);
void truncate();
int update(AnalysisReportDto report);
- int updateWithBookingReport(@Param("id") Long id, @Param("startedAt") Date startedAt,
+ int updateWithBookingReport(@Param("id") Long id, @Param("startedAt") long startedAt,
@Param("availableStatus") AnalysisReportDto.Status availableStatus,
@Param("busyStatus") AnalysisReportDto.Status busyStatus);
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.TimeUtils;
+import org.sonar.core.computation.dbcleaner.period.DefaultPeriodCleaner;
import org.sonar.core.purge.*;
import org.sonar.core.resource.ResourceDao;
import org.sonar.core.resource.ResourceDto;
import org.sonar.plugins.dbcleaner.api.PurgeTask;
-import org.sonar.core.computation.dbcleaner.period.DefaultPeriodCleaner;
import static org.sonar.core.purge.PurgeConfiguration.newDefaultPurgeConfiguration;
try {
periodCleaner.clean(resourceId);
} catch (Exception e) {
- // purge errors must no fail the batch
+ // purge errors must not fail the batch
LOG.error("Fail to clean historical data [id=" + resourceId + "]", e);
}
}
try {
purgeDao.purge(newPurgeConfigurationOnResource(resourceId), PurgeListener.EMPTY);
} catch (Exception e) {
- // purge errors must no fail the report analysis
+ // purge errors must not fail the report analysis
LOG.error("Fail to purge data [id=" + resourceId + "]", e);
}
}
*/
public class DatabaseVersion implements BatchComponent, ServerComponent {
- public static final int LAST_VERSION = 762;
+ public static final int LAST_VERSION = 765;
/**
* List of all the tables.n
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('760');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('761');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('762');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('763');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('764');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('765');
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;
"SNAPSHOT_ID" INTEGER NOT NULL,
"REPORT_STATUS" VARCHAR(20) NOT NULL,
"REPORT_DATA" BLOB(2147483647),
- "CREATED_AT" TIMESTAMP NOT NULL,
- "UPDATED_AT" TIMESTAMP,
- "STARTED_AT" TIMESTAMP,
- "FINISHED_AT" TIMESTAMP
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "STARTED_AT" BIGINT,
+ "FINISHED_AT" BIGINT
);
CREATE TABLE "FILE_SOURCES" (
package org.sonar.api.utils;
import javax.annotation.Nullable;
-
import java.io.NotSerializableException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
return THREAD_SAFE_DATETIME_FORMAT.format(date);
}
+ public static Date timeToDate(@Nullable Long time) {
+ return time == null ? null : new Date(time);
+ }
+
/**
* @param s string in format {@link #DATE_FORMAT}
* @throws SonarException when string cannot be parsed