Conversion to milliseconds

Change-Id: I7117b8055b6773e400de1bc847cba4d2ebd161ba
This commit is contained in:
Roland Hochmuth 2015-03-10 20:54:45 -06:00
parent 970a817c1c
commit b3a8042949
7 changed files with 14 additions and 14 deletions

View File

@ -726,7 +726,7 @@ Consists of a single metric object or an array of metric objects. A metric has t
* name (string(255), required) - The name of the metric.
* dimensions ({string(255): string(255)}, optional) - A dictionary consisting of (key, value) pairs used to uniquely identify a metric.
* timestamp (string, required) - The timestamp in seconds from the Epoch.
* timestamp (string, required) - The timestamp in milliseconds from the Epoch.
* value (float, required) - Value of the metric. Values with base-10 exponents greater than 126 or less than -130 are truncated.
* value_meta ({string(255): string(2048)}, optional) - A dictionary consisting of (key, value) pairs used to add information about the value.

View File

@ -30,8 +30,8 @@ import monasca.common.model.metric.Metric;
import monasca.api.resource.exception.Exceptions;
public class CreateMetricCommand {
private static final long TIME_2MIN = 120;
private static final long TIME_2WEEKS = 1209600;
private static final long TIME_2MIN_MILLIS = 120*1000;
private static final long TIME_2WEEKS_MILLIS = 1209600*1000;
public static final int MAX_NAME_LENGTH = 255;
@NotEmpty
@ -54,8 +54,8 @@ public class CreateMetricCommand {
}
private static void validateTimestamp(long timestamp) {
long time = System.currentTimeMillis() / 1000;
if (timestamp > time + TIME_2MIN || timestamp < time - TIME_2WEEKS)
long time = System.currentTimeMillis();
if (timestamp > time + TIME_2MIN_MILLIS || timestamp < time - TIME_2WEEKS_MILLIS)
throw Exceptions.unprocessableEntity("Timestamp %s is out of legal range", timestamp);
}
@ -118,7 +118,7 @@ public class CreateMetricCommand {
@JsonProperty
public void setTimestamp(Long timestamp) {
this.timestamp =
timestamp == null || timestamp.longValue() == 0L ? System.currentTimeMillis() / 1000L
timestamp == null || timestamp.longValue() == 0L ? System.currentTimeMillis()
: timestamp.longValue();
}

View File

@ -54,7 +54,7 @@ public class InfluxV8MeasurementRepo implements MeasurementRepo {
.unmodifiableMap(new HashMap<String, String>());
public static final DateTimeFormatter DATETIME_FORMATTER = ISODateTimeFormat.dateTimeNoMillis()
public static final DateTimeFormatter DATETIME_FORMATTER = ISODateTimeFormat.dateTime()
.withZoneUTC();
@Inject

View File

@ -60,7 +60,7 @@ public class InfluxV8MetricDefinitionRepo implements MetricDefinitionRepo {
List<Serie>
result =
this.influxDB.Query(this.config.influxDB.getName(), query, TimeUnit.SECONDS);
this.influxDB.Query(this.config.influxDB.getName(), query, TimeUnit.MILLISECONDS);
return buildMetricDefList(result, offset);
}

View File

@ -85,7 +85,7 @@ public class MetricIntegrationTest extends AbstractMonApiResourceTest {
valueMeta = new HashMap<String, String>();
valueMeta.put("rc", "404");
valueMeta.put("errMsg", "Not Found");
long timestamp = System.currentTimeMillis() / 1000;
long timestamp = System.currentTimeMillis();
ClientResponse response =
client()
.resource("/v2.0/metrics")

View File

@ -443,7 +443,7 @@ public class ITInfluxDBTest {
@Test
public void metricCreateRawTest() {
long unixTime = System.currentTimeMillis() / 1000L;
long unixTime = System.currentTimeMillis();
given().headers("Accept", "application/json", "Content-Type", "application/json",
"X-Auth-Token", "82510970543135")

View File

@ -56,7 +56,7 @@ public class MetricResourceTest extends AbstractMonApiResourceTest {
valueMeta = new HashMap<String, String>();
valueMeta.put("rc", "404");
valueMeta.put("errorMsg", "Not Found");
timestamp = System.currentTimeMillis() / 1000L;
timestamp = System.currentTimeMillis();
service = mock(MetricService.class);
doNothing().when(service).create(any(List.class), anyString(), anyString());
@ -278,7 +278,7 @@ public class MetricResourceTest extends AbstractMonApiResourceTest {
}
public void shouldErrorOnCreateWithHighTimestamp() {
long local_timestamp = timestamp + 1000;
long local_timestamp = timestamp + 1000000;
ClientResponse response =
createResponseFor(new CreateMetricCommand("test_metrictype", dimensions, local_timestamp,
22.0, valueMeta));
@ -288,7 +288,7 @@ public class MetricResourceTest extends AbstractMonApiResourceTest {
}
public void shouldErrorOnCreateWithLowTimestamp() {
long local_timestamp = timestamp - 1309600;
long local_timestamp = timestamp - 1309600000;
ClientResponse response =
createResponseFor(new CreateMetricCommand("test_metrictype", dimensions, local_timestamp,
22.0, valueMeta));
@ -313,4 +313,4 @@ public class MetricResourceTest extends AbstractMonApiResourceTest {
.header("X-Tenant-Id", "abc").header("Content-Type", MediaType.APPLICATION_JSON)
.post(ClientResponse.class, request);
}
}
}