Skip to content

Commit

Permalink
[HWKMETRICS-326] Remove concrete DataPoint implementations and add gl…
Browse files Browse the repository at this point in the history
…obal custom deserializer for AvailabilityType.
  • Loading branch information
Stefan Negrea committed Nov 24, 2015
1 parent 22abbe0 commit a22b369
Show file tree
Hide file tree
Showing 18 changed files with 274 additions and 399 deletions.
193 changes: 99 additions & 94 deletions api/diff.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@

import org.hawkular.metrics.api.jaxrs.util.ApiUtils;
import org.hawkular.metrics.core.api.ApiError;
import org.hawkular.metrics.core.api.AvailabilityDataPoint;
import org.hawkular.metrics.core.api.AvailabilityType;
import org.hawkular.metrics.core.api.Buckets;
import org.hawkular.metrics.core.api.DataPoint;
import org.hawkular.metrics.core.api.Metric;
import org.hawkular.metrics.core.api.MetricDefinition;
import org.hawkular.metrics.core.api.MetricId;
Expand Down Expand Up @@ -198,9 +198,9 @@ public Response deleteMetricTags(
@Path("/{id}/data")
public Response addAvailabilityForMetric(
@PathParam("id") String id,
List<AvailabilityDataPoint> data
List<DataPoint<AvailabilityType>> data
) {
Observable<Metric<AvailabilityType>> metrics = AvailabilityDataPoint.toObservable(tenantId, id, data);
Observable<Metric<AvailabilityType>> metrics = DataPoint.toObservable(tenantId, id, data, AVAILABILITY);
try {
metricsService.addDataPoints(AVAILABILITY, metrics).toBlocking().lastOrDefault(null);
return Response.ok().build();
Expand All @@ -212,7 +212,7 @@ public Response addAvailabilityForMetric(
@POST
@Path("/data")
public Response addAvailabilityData(
List<MetricRequest<AvailabilityType, AvailabilityDataPoint>> availabilities
List<MetricRequest<AvailabilityType, DataPoint<AvailabilityType>>> availabilities
) {
Observable<Metric<AvailabilityType>> metrics = MetricRequest.toObservable(tenantId, availabilities,
AVAILABILITY);
Expand Down Expand Up @@ -248,7 +248,6 @@ public Response findAvailabilityData(
try {
if (buckets == null) {
return metricsService.findAvailabilityData(metricId, timeRange.getStart(), timeRange.getEnd(), distinct)
.map(AvailabilityDataPoint::new)
.toList()
.map(ApiUtils::collectionToResponse)
.toBlocking()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
import org.hawkular.metrics.api.jaxrs.util.ApiUtils;
import org.hawkular.metrics.core.api.ApiError;
import org.hawkular.metrics.core.api.Buckets;
import org.hawkular.metrics.core.api.CounterDataPoint;
import org.hawkular.metrics.core.api.GaugeDataPoint;
import org.hawkular.metrics.core.api.DataPoint;
import org.hawkular.metrics.core.api.Metric;
import org.hawkular.metrics.core.api.MetricDefinition;
import org.hawkular.metrics.core.api.MetricId;
Expand Down Expand Up @@ -187,7 +186,7 @@ public Response deleteMetricTags(

@POST
@Path("/data")
public Response addData(List<MetricRequest<Long, CounterDataPoint>> counters) {
public Response addData(List<MetricRequest<Long, DataPoint<Long>>> counters) {
Observable<Metric<Long>> metrics = MetricRequest.toObservable(tenantId, counters, COUNTER);
try {
metricsService.addDataPoints(COUNTER, metrics).toBlocking().lastOrDefault(null);
Expand All @@ -201,9 +200,9 @@ public Response addData(List<MetricRequest<Long, CounterDataPoint>> counters) {
@Path("/{id}/data")
public Response addData(
@PathParam("id") String id,
List<CounterDataPoint> data
List<DataPoint<Long>> data
) {
Observable<Metric<Long>> metrics = CounterDataPoint.toObservable(tenantId, id, data);
Observable<Metric<Long>> metrics = DataPoint.toObservable(tenantId, id, data, COUNTER);
try {
metricsService.addDataPoints(COUNTER, metrics).toBlocking().lastOrDefault(null);
return Response.ok().build();
Expand Down Expand Up @@ -236,7 +235,6 @@ public Response findCounterData(
try {
if (buckets == null) {
return metricsService.findDataPoints(metricId, timeRange.getStart(), timeRange.getEnd())
.map(CounterDataPoint::new)
.toList()
.map(ApiUtils::collectionToResponse)
.toBlocking()
Expand Down Expand Up @@ -283,7 +281,6 @@ public Response findRate(
if (buckets == null) {
return metricsService
.findRateData(metricId, timeRange.getStart(), timeRange.getEnd())
.map(GaugeDataPoint::new)
.toList()
.map(ApiUtils::collectionToResponse)
.toBlocking()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import org.hawkular.metrics.api.jaxrs.util.ApiUtils;
import org.hawkular.metrics.core.api.ApiError;
import org.hawkular.metrics.core.api.Buckets;
import org.hawkular.metrics.core.api.GaugeDataPoint;
import org.hawkular.metrics.core.api.DataPoint;
import org.hawkular.metrics.core.api.Metric;
import org.hawkular.metrics.core.api.MetricDefinition;
import org.hawkular.metrics.core.api.MetricId;
Expand Down Expand Up @@ -189,9 +189,9 @@ public Response deleteMetricTags(
@Path("/{id}/data")
public Response addDataForMetric(
@PathParam("id") String id,
List<GaugeDataPoint> data
List<DataPoint<Double>> data
) {
Observable<Metric<Double>> metrics = GaugeDataPoint.toObservable(tenantId, id, data);
Observable<Metric<Double>> metrics = DataPoint.toObservable(tenantId, id, data, GAUGE);
try {
metricsService.addDataPoints(GAUGE, metrics).toBlocking().lastOrDefault(null);
return Response.ok().build();
Expand All @@ -203,7 +203,7 @@ public Response addDataForMetric(
@POST
@Path("/data")
public Response addGaugeData(
List<MetricRequest<Double, GaugeDataPoint>> gauges
List<MetricRequest<Double, DataPoint<Double>>> gauges
) {
Observable<Metric<Double>> metrics = MetricRequest.toObservable(tenantId, gauges, GAUGE);
try {
Expand Down Expand Up @@ -239,7 +239,6 @@ public Response findGaugeData(
if (buckets == null) {
return metricsService
.findDataPoints(metricId, timeRange.getStart(), timeRange.getEnd())
.map(GaugeDataPoint::new)
.toList()
.map(ApiUtils::collectionToResponse)
.toBlocking()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@
import javax.ws.rs.ext.Provider;

import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.Version;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
import org.codehaus.jackson.map.module.SimpleModule;
import org.hawkular.metrics.core.api.AvailabilityType;
import org.hawkular.metrics.core.api.codehaus.jackson.AvailabilityTypeDeserializer;
import org.hawkular.metrics.core.api.codehaus.jackson.AvailabilityTypeSerializer;

@Provider
@Produces(MediaType.APPLICATION_JSON)
Expand All @@ -44,6 +49,11 @@ public JacksonConfig() {
mapper.setSerializationInclusion(Inclusion.NON_NULL);
mapper.configure(SerializationConfig.Feature.WRITE_EMPTY_JSON_ARRAYS, false);
mapper.configure(SerializationConfig.Feature.WRITE_NULL_MAP_VALUES, false);

SimpleModule module = new SimpleModule("hawkular-metrics", new Version(1, 0, 0, ""));
module.addDeserializer(AvailabilityType.class, new AvailabilityTypeDeserializer());
module.addSerializer(AvailabilityType.class, new AvailabilityTypeSerializer());
mapper.registerModule(module);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
import org.hawkular.metrics.api.jaxrs.handler.observer.ResultSetObserver;
import org.hawkular.metrics.api.jaxrs.util.ApiUtils;
import org.hawkular.metrics.core.api.ApiError;
import org.hawkular.metrics.core.api.AvailabilityDataPoint;
import org.hawkular.metrics.core.api.AvailabilityType;
import org.hawkular.metrics.core.api.Buckets;
import org.hawkular.metrics.core.api.DataPoint;
import org.hawkular.metrics.core.api.Metric;
import org.hawkular.metrics.core.api.MetricDefinition;
import org.hawkular.metrics.core.api.MetricId;
Expand Down Expand Up @@ -229,9 +229,9 @@ public void deleteMetricTags(
})
public void addAvailabilityForMetric(
@Suspended final AsyncResponse asyncResponse, @PathParam("id") String id,
@ApiParam(value = "List of availability datapoints", required = true) List<AvailabilityDataPoint> data
@ApiParam(value = "List of availability datapoints", required = true) List<DataPoint<AvailabilityType>> data
) {
Observable<Metric<AvailabilityType>> metrics = AvailabilityDataPoint.toObservable(tenantId, id, data);
Observable<Metric<AvailabilityType>> metrics = DataPoint.toObservable(tenantId, id, data, AVAILABILITY);
Observable<Void> observable = metricsService.addDataPoints(AVAILABILITY, metrics);
observable.subscribe(new ResultSetObserver(asyncResponse));
}
Expand All @@ -249,7 +249,7 @@ public void addAvailabilityData(
@Suspended final AsyncResponse asyncResponse,
@ApiParam(value = "List of availability metrics", required = true)
@JsonDeserialize()
List<MetricRequest<AvailabilityType, AvailabilityDataPoint>> availabilities
List<MetricRequest<AvailabilityType, DataPoint<AvailabilityType>>> availabilities
) {
Observable<Metric<AvailabilityType>> metrics = MetricRequest.toObservable(tenantId, availabilities,
AVAILABILITY);
Expand All @@ -261,7 +261,7 @@ public void addAvailabilityData(
@Path("/{id}/data")
@ApiOperation(value = "Retrieve availability data.", notes = "When buckets or bucketDuration query parameter is " +
"used, the time range between start and end will be divided in buckets of equal duration, and " +
"availability statistics will be computed for each bucket.", response = AvailabilityDataPoint.class,
"availability statistics will be computed for each bucket.", response = DataPoint.class,
responseContainer = "List")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully fetched availability data."),
Expand Down Expand Up @@ -296,7 +296,6 @@ public void findAvailabilityData(
Buckets buckets = bucketConfig.getBuckets();
if (buckets == null) {
metricsService.findAvailabilityData(metricId, timeRange.getStart(), timeRange.getEnd(), distinct)
.map(AvailabilityDataPoint::new)
.toList()
.map(ApiUtils::collectionToResponse)
.subscribe(asyncResponse::resume, t -> asyncResponse.resume(serverError(t)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@
import org.hawkular.metrics.api.jaxrs.util.ApiUtils;
import org.hawkular.metrics.core.api.ApiError;
import org.hawkular.metrics.core.api.Buckets;
import org.hawkular.metrics.core.api.CounterDataPoint;
import org.hawkular.metrics.core.api.GaugeDataPoint;
import org.hawkular.metrics.core.api.DataPoint;
import org.hawkular.metrics.core.api.Metric;
import org.hawkular.metrics.core.api.MetricDefinition;
import org.hawkular.metrics.core.api.MetricId;
Expand Down Expand Up @@ -231,7 +230,7 @@ public void deleteMetricTags(
})
public void addData(@Suspended final AsyncResponse asyncResponse,
@ApiParam(value = "List of metrics", required = true)
List<MetricRequest<Long, CounterDataPoint>> counters
List<MetricRequest<Long, DataPoint<Long>>> counters
) {
Observable<Metric<Long>> metrics = MetricRequest.toObservable(tenantId, counters, COUNTER);
Observable<Void> observable = metricsService.addDataPoints(COUNTER, metrics);
Expand All @@ -251,9 +250,9 @@ public void addData(
@Suspended final AsyncResponse asyncResponse,
@PathParam("id") String id,
@ApiParam(value = "List of data points containing timestamp and value", required = true)
List<CounterDataPoint> data
List<DataPoint<Long>> data
) {
Observable<Metric<Long>> metrics = CounterDataPoint.toObservable(tenantId, id, data);
Observable<Metric<Long>> metrics = DataPoint.toObservable(tenantId, id, data, COUNTER);
Observable<Void> observable = metricsService.addDataPoints(COUNTER, metrics);
observable.subscribe(new ResultSetObserver(asyncResponse));
}
Expand All @@ -262,7 +261,7 @@ public void addData(
@Path("/{id}/data")
@ApiOperation(value = "Retrieve counter data points.", notes = "When buckets or bucketDuration query parameter " +
"is used, the time range between start and end will be divided in buckets of equal duration, and metric " +
"statistics will be computed for each bucket.", response = CounterDataPoint.class, responseContainer =
"statistics will be computed for each bucket.", response = DataPoint.class, responseContainer =
"List")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully fetched metric data."),
Expand Down Expand Up @@ -296,7 +295,6 @@ public void findCounterData(
Buckets buckets = bucketConfig.getBuckets();
if (buckets == null) {
metricsService.findDataPoints(metricId, timeRange.getStart(), timeRange.getEnd())
.map(CounterDataPoint::new)
.toList()
.map(ApiUtils::collectionToResponse)
.subscribe(asyncResponse::resume, t -> asyncResponse.resume(serverError(t)));
Expand All @@ -319,7 +317,7 @@ public void findCounterData(
"used, the time range between start and end will be divided in buckets of equal duration, and metric " +
"statistics will be computed for each bucket. Reset events are detected and data points that immediately " +
"follow such events are filtered out prior to calculating the rates. This avoid misleading or inaccurate " +
"rates when resets occur.", response = GaugeDataPoint.class, responseContainer = "List")
"rates when resets occur.", response = DataPoint.class, responseContainer = "List")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully fetched metric data."),
@ApiResponse(code = 204, message = "No metric data was found."),
Expand Down Expand Up @@ -352,7 +350,6 @@ public void findRate(
Buckets buckets = bucketConfig.getBuckets();
if (buckets == null) {
metricsService.findRateData(metricId, timeRange.getStart(), timeRange.getEnd())
.map(GaugeDataPoint::new)
.toList()
.map(ApiUtils::collectionToResponse)
.subscribe(asyncResponse::resume, t -> asyncResponse.resume(serverError(t)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import org.hawkular.metrics.api.jaxrs.util.ApiUtils;
import org.hawkular.metrics.core.api.ApiError;
import org.hawkular.metrics.core.api.Buckets;
import org.hawkular.metrics.core.api.GaugeDataPoint;
import org.hawkular.metrics.core.api.DataPoint;
import org.hawkular.metrics.core.api.Metric;
import org.hawkular.metrics.core.api.MetricDefinition;
import org.hawkular.metrics.core.api.MetricId;
Expand Down Expand Up @@ -232,9 +232,9 @@ public void addDataForMetric(
@Suspended final AsyncResponse asyncResponse,
@PathParam("id") String id,
@ApiParam(value = "List of datapoints containing timestamp and value", required = true)
List<GaugeDataPoint> data
List<DataPoint<Double>> data
) {
Observable<Metric<Double>> metrics = GaugeDataPoint.toObservable(tenantId, id, data);
Observable<Metric<Double>> metrics = DataPoint.toObservable(tenantId, id, data, GAUGE);
Observable<Void> observable = metricsService.addDataPoints(GAUGE, metrics);
observable.subscribe(new ResultSetObserver(asyncResponse));
}
Expand All @@ -250,7 +250,7 @@ public void addDataForMetric(
})
public void addGaugeData(
@Suspended final AsyncResponse asyncResponse,
@ApiParam(value = "List of metrics", required = true) List<MetricRequest<Double, GaugeDataPoint>> gauges
@ApiParam(value = "List of metrics", required = true) List<MetricRequest<Double, DataPoint<Double>>> gauges
) {
Observable<Metric<Double>> metrics = MetricRequest.toObservable(tenantId, gauges, GAUGE);
Observable<Void> observable = metricsService.addDataPoints(GAUGE, metrics);
Expand All @@ -261,7 +261,7 @@ public void addGaugeData(
@Path("/{id}/data")
@ApiOperation(value = "Retrieve gauge data.", notes = "When buckets or bucketDuration query parameter is used, " +
"the time range between start and end will be divided in buckets of equal duration, and metric statistics" +
" will be computed for each bucket.", response = GaugeDataPoint.class, responseContainer = "List")
" will be computed for each bucket.", response = DataPoint.class, responseContainer = "List")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully fetched metric data."),
@ApiResponse(code = 204, message = "No metric data was found."),
Expand Down Expand Up @@ -293,7 +293,6 @@ public void findGaugeData(
Buckets buckets = bucketConfig.getBuckets();
if (buckets == null) {
metricsService.findDataPoints(metricId, timeRange.getStart(), timeRange.getEnd())
.map(GaugeDataPoint::new)
.toList()
.map(ApiUtils::collectionToResponse)
.subscribe(asyncResponse::resume, t -> asyncResponse.resume(ApiUtils.serverError(t)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;

import org.hawkular.metrics.core.api.AvailabilityType;
import org.hawkular.metrics.core.api.fasterxml.jackson.AvailabilityTypeDeserializer;
import org.hawkular.metrics.core.api.fasterxml.jackson.AvailabilityTypeSerializer;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;

@Provider
@Produces(MediaType.APPLICATION_JSON)
Expand All @@ -44,6 +49,11 @@ public JacksonConfig() {
mapper.setSerializationInclusion(Include.NON_NULL);
mapper.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false);
mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);

SimpleModule module = new SimpleModule();
module.addDeserializer(AvailabilityType.class, new AvailabilityTypeDeserializer());
module.addSerializer(AvailabilityType.class, new AvailabilityTypeSerializer());
mapper.registerModule(module);
}

@Override
Expand Down

0 comments on commit a22b369

Please sign in to comment.