Updated timestamps to be ISO 8601 formatted
This commit is contained in:
parent
7cf8a0ee3a
commit
e1917a48cf
2
pom.xml
2
pom.xml
|
@ -15,7 +15,7 @@
|
|||
<properties>
|
||||
<computedVersion>${project.version}-${timestamp}-${buildNumber}</computedVersion>
|
||||
<computedName>${project.artifactId}-${computedVersion}</computedName>
|
||||
<mon.common.version>1.0.0.36</mon.common.version>
|
||||
<mon.common.version>1.0.0.40</mon.common.version>
|
||||
<dropwizard.version>0.7.0</dropwizard.version>
|
||||
|
||||
<skipITs>true</skipITs>
|
||||
|
|
|
@ -15,6 +15,7 @@ import javax.ws.rs.ext.ExceptionMapper;
|
|||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.hp.csbu.cc.middleware.TokenAuth;
|
||||
import com.hpcloud.messaging.kafka.KafkaHealthCheck;
|
||||
import com.hpcloud.mon.bundle.SwaggerBundle;
|
||||
|
@ -89,6 +90,7 @@ public class MonApiApplication extends Application<MonApiConfiguration> {
|
|||
environment.getObjectMapper().setPropertyNamingStrategy(
|
||||
PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
|
||||
environment.getObjectMapper().enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
|
||||
environment.getObjectMapper().disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
|
||||
/** Configure health checks */
|
||||
environment.healthChecks().register("kafka", new KafkaHealthCheck(config.kafka));
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.hpcloud.mon.domain.model.alarmstatehistory;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import com.hpcloud.mon.common.model.alarm.AlarmState;
|
||||
|
||||
public class AlarmStateHistory {
|
||||
|
@ -8,14 +10,13 @@ public class AlarmStateHistory {
|
|||
private AlarmState newState;
|
||||
private String reason;
|
||||
private String reasonData;
|
||||
/** POSIX timestamp */
|
||||
private long timestamp;
|
||||
private DateTime timestamp;
|
||||
|
||||
public AlarmStateHistory() {
|
||||
}
|
||||
|
||||
public AlarmStateHistory(String alarmId, AlarmState oldState, AlarmState newState, String reason,
|
||||
String reasonData, long timestamp) {
|
||||
String reasonData, DateTime timestamp) {
|
||||
this.alarmId = alarmId;
|
||||
this.oldState = oldState;
|
||||
this.newState = newState;
|
||||
|
@ -52,7 +53,10 @@ public class AlarmStateHistory {
|
|||
return false;
|
||||
} else if (!reasonData.equals(other.reasonData))
|
||||
return false;
|
||||
if (timestamp != other.timestamp)
|
||||
if (timestamp == null) {
|
||||
if (other.timestamp != null)
|
||||
return false;
|
||||
} else if (!timestamp.equals(other.timestamp))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
@ -77,7 +81,7 @@ public class AlarmStateHistory {
|
|||
return reasonData;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
public DateTime getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
|
@ -90,7 +94,7 @@ public class AlarmStateHistory {
|
|||
result = prime * result + ((oldState == null) ? 0 : oldState.hashCode());
|
||||
result = prime * result + ((reason == null) ? 0 : reason.hashCode());
|
||||
result = prime * result + ((reasonData == null) ? 0 : reasonData.hashCode());
|
||||
result = prime * result + (int) (timestamp ^ (timestamp >>> 32));
|
||||
result = prime * result + ((timestamp == null) ? 0 : timestamp.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -114,7 +118,7 @@ public class AlarmStateHistory {
|
|||
this.reasonData = reasonData;
|
||||
}
|
||||
|
||||
public void setTimestamp(long timestamp) {
|
||||
public void setTimestamp(DateTime timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ public class AlarmStateHistoryRepositoryImpl implements AlarmStateHistoryReposit
|
|||
public List<AlarmStateHistory> findById(String tenantId, String alarmId) {
|
||||
try (Handle h = db.open()) {
|
||||
return h.createQuery(
|
||||
"select * from MonAlarms.StateHistory where tenant_id = :tenantId and alarm_id = :alarmId")
|
||||
"select alarm_id, old_state, new_state, reason, reason_data, time_stamp as timestamp from MonAlarms.StateHistory where tenant_id = :tenantId and alarm_id = :alarmId")
|
||||
.bind("tenantId", tenantId)
|
||||
.bind("alarmId", alarmId)
|
||||
.map(new BeanMapper<>(AlarmStateHistory.class))
|
||||
|
|
|
@ -13,6 +13,8 @@ import javax.inject.Inject;
|
|||
import javax.inject.Named;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
import org.joda.time.format.ISODateTimeFormat;
|
||||
import org.skife.jdbi.v2.DBI;
|
||||
import org.skife.jdbi.v2.Handle;
|
||||
import org.skife.jdbi.v2.Query;
|
||||
|
@ -26,6 +28,8 @@ import com.hpcloud.mon.domain.model.measurement.Measurements;
|
|||
* @author Jonathan Halterman
|
||||
*/
|
||||
public class MeasurementRepositoryImpl implements MeasurementRepository {
|
||||
public static final DateTimeFormatter DATETIME_FORMATTER = ISODateTimeFormat.dateTimeNoMillis()
|
||||
.withZoneUTC();
|
||||
private static final String FIND_BY_METRIC_DEF_SQL = "select m.definition_dimensions_id, dd.dimension_set_id, m.id, m.time_stamp, m.value "
|
||||
+ "from MonMetrics.Measurements m, MonMetrics.Definitions def, MonMetrics.DefinitionDimensions dd%s "
|
||||
+ "where m.definition_dimensions_id = dd.id and def.id = dd.definition_id "
|
||||
|
@ -71,7 +75,7 @@ public class MeasurementRepositoryImpl implements MeasurementRepository {
|
|||
byte[] dimSetIdBytes = (byte[]) row.get("dimension_set_id");
|
||||
ByteBuffer defId = ByteBuffer.wrap(defIdBytes);
|
||||
long measurementId = (Long) row.get("id");
|
||||
long timestamp = ((Timestamp) row.get("time_stamp")).getTime() / 1000;
|
||||
String timestamp = DATETIME_FORMATTER.print(((Timestamp) row.get("time_stamp")).getTime());
|
||||
double value = (double) row.get("value");
|
||||
|
||||
Measurements measurements = results.get(defId);
|
||||
|
|
|
@ -9,6 +9,8 @@ import javax.inject.Named;
|
|||
import com.hpcloud.mon.domain.model.statistic.Statistics;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
import org.joda.time.format.ISODateTimeFormat;
|
||||
import org.skife.jdbi.v2.DBI;
|
||||
|
||||
import com.hpcloud.mon.domain.model.statistic.StatisticRepository;
|
||||
|
@ -20,13 +22,15 @@ import org.skife.jdbi.v2.Query;
|
|||
* Vertica statistic repository implementation.
|
||||
*/
|
||||
public class StatisticRepositoryImpl implements StatisticRepository {
|
||||
private final DBI db;
|
||||
|
||||
public static final DateTimeFormatter DATETIME_FORMATTER = ISODateTimeFormat.dateTimeNoMillis()
|
||||
.withZoneUTC();
|
||||
private static final String FIND_BY_METRIC_DEF_SQL = "select dd.id, def.name, d.name as dname, d.value as dvalue "
|
||||
+ "from MonMetrics.Definitions def, MonMetrics.DefinitionDimensions dd "
|
||||
+ "left outer join MonMetrics.Dimensions d on d.dimension_set_id = dd.dimension_set_id%s "
|
||||
+ "where def.id = dd.definition_id and def.tenant_id = :tenantId%s order by dd.id";
|
||||
|
||||
private final DBI db;
|
||||
|
||||
@Inject
|
||||
public StatisticRepositoryImpl(@Named("vertica") DBI db) {
|
||||
this.db = db;
|
||||
|
@ -62,7 +66,7 @@ public class StatisticRepositoryImpl implements StatisticRepository {
|
|||
Timestamp time_stamp = (Timestamp) row.get("time_interval");
|
||||
|
||||
if (time_stamp != null) {
|
||||
statisticsRow.add(time_stamp.getTime());
|
||||
statisticsRow.add(DATETIME_FORMATTER.print(time_stamp.getTime()));
|
||||
}
|
||||
|
||||
if (average != null) {
|
||||
|
|
|
@ -17,6 +17,8 @@ import java.util.List;
|
|||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.hpcloud.mon.app.AlarmService;
|
||||
|
@ -307,9 +309,9 @@ public class AlarmResourceTest extends AbstractMonApiResourceTest {
|
|||
|
||||
public void shouldGetAlarmStateHistory() {
|
||||
AlarmStateHistory history1 = new AlarmStateHistory("123", AlarmState.OK, AlarmState.ALARM,
|
||||
"foo", "foobar", System.currentTimeMillis() / 1000);
|
||||
"foo", "foobar", new DateTime(2014, 1, 1, 1, 1, DateTimeZone.UTC));
|
||||
AlarmStateHistory history2 = new AlarmStateHistory("123", AlarmState.ALARM, AlarmState.OK,
|
||||
"foo", "foobar", System.currentTimeMillis() / 1000);
|
||||
"foo", "foobar", new DateTime(2014, 1, 1, 1, 1, DateTimeZone.UTC));
|
||||
List<AlarmStateHistory> expected = Arrays.asList(history1, history2);
|
||||
|
||||
when(stateHistoryRepo.findById(eq("abc"), eq("123"))).thenReturn(expected);
|
||||
|
|
Loading…
Reference in New Issue