Skip to content

Commit

Permalink
[HWKMETRICS-326] No reason to use generics for MetricType; removed it…
Browse files Browse the repository at this point in the history
… and also cleaned MetricId.
  • Loading branch information
Stefan Negrea committed Nov 25, 2015
1 parent 9e5c0de commit 8cd7930
Show file tree
Hide file tree
Showing 45 changed files with 429 additions and 439 deletions.
56 changes: 26 additions & 30 deletions api/diff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -525,11 +525,11 @@ diff -r '--exclude-from=api/diff-excludes' api/metrics-api-jaxrs/src/main/java/o
> .AVAILABILITY.getText()));
115,118c95,106
< metric = new Metric<>(
< new MetricId<>(tenantId, AVAILABILITY, metric.getMetricId().getName()), metric.getTags(),
< new MetricId(tenantId, AVAILABILITY, metric.getMetricId().getName()), metric.getTags(),
< metric.getDataRetention());
< metricsService.createMetric(metric).subscribe(new MetricCreatedObserver(asyncResponse, location));
---
> metric = new Metric<>(new MetricId<>(tenantId, AVAILABILITY, metric.getId()),
> metric = new Metric<>(new MetricId(tenantId, AVAILABILITY, metric.getId()),
> metric.getTags(), metric.getDataRetention());
> try {
> Observable<Void> observable = metricsService.createMetric(metric);
Expand Down Expand Up @@ -590,11 +590,11 @@ diff -r '--exclude-from=api/diff-excludes' api/metrics-api-jaxrs/src/main/java/o
< response = ApiError.class) })
< public void getAvailabilityMetric(@Suspended final AsyncResponse asyncResponse, @PathParam("id") String id) {
<
< metricsService.findMetric(new MetricId<>(tenantId, AVAILABILITY, id))
< metricsService.findMetric(new MetricId(tenantId, AVAILABILITY, id))
---
> public Response getAvailabilityMetric(@PathParam("id") String id) {
> try {
> return metricsService.findMetric(new MetricId<>(tenantId, AVAILABILITY, id))
> return metricsService.findMetric(new MetricId(tenantId, AVAILABILITY, id))
166c138,142
< .subscribe(asyncResponse::resume, t -> asyncResponse.resume(serverError(t)));
---
Expand All @@ -616,12 +616,12 @@ diff -r '--exclude-from=api/diff-excludes' api/metrics-api-jaxrs/src/main/java/o
---
> public Response getMetricTags(
182,184c150,159
< metricsService.getMetricTags(new MetricId<>(tenantId, AVAILABILITY, id)).subscribe(
< metricsService.getMetricTags(new MetricId(tenantId, AVAILABILITY, id)).subscribe(
< optional -> asyncResponse.resume(valueToResponse(optional)),
< t -> asyncResponse.resume(serverError(t)));
---
> Observable<Optional<Map<String, String>>> something = metricsService
> .getMetricTags(new MetricId<>(tenantId, AVAILABILITY, id));
> .getMetricTags(new MetricId(tenantId, AVAILABILITY, id));
> try {
> return something
> .map(ApiUtils::valueToResponse)
Expand Down Expand Up @@ -911,11 +911,11 @@ diff -r '--exclude-from=api/diff-excludes' api/metrics-api-jaxrs/src/main/java/o
< response = ApiError.class) })
< public void getCounter(@Suspended final AsyncResponse asyncResponse, @PathParam("id") String id) {
<
< metricsService.findMetric(new MetricId<>(tenantId, COUNTER, id))
< metricsService.findMetric(new MetricId(tenantId, COUNTER, id))
---
> public Response getCounter(@PathParam("id") String id) {
> try {
> return metricsService.findMetric(new MetricId<>(tenantId, COUNTER, id))
> return metricsService.findMetric(new MetricId(tenantId, COUNTER, id))
169,170c136,140
< .switchIfEmpty(Observable.just(noContent()))
< .subscribe(asyncResponse::resume, t -> asyncResponse.resume(serverError(t)));
Expand All @@ -935,14 +935,14 @@ diff -r '--exclude-from=api/diff-excludes' api/metrics-api-jaxrs/src/main/java/o
< public void getMetricTags(
< @Suspended final AsyncResponse asyncResponse,
< @PathParam("id") String id) {
< metricsService.getMetricTags(new MetricId<>(tenantId, COUNTER, id))
< metricsService.getMetricTags(new MetricId(tenantId, COUNTER, id))
< .subscribe(
< optional -> asyncResponse.resume(valueToResponse(optional)),
< t -> asyncResponse.resume(serverError(t)));
---
> public Response getMetricTags(@PathParam("id") String id) {
> try {
> return metricsService.getMetricTags(new MetricId<>(tenantId, COUNTER, id))
> return metricsService.getMetricTags(new MetricId(tenantId, COUNTER, id))
> .map(ApiUtils::valueToResponse)
> .toBlocking().lastOrDefault(null);
> } catch (Exception e) {
Expand Down Expand Up @@ -986,12 +986,12 @@ diff -r '--exclude-from=api/diff-excludes' api/metrics-api-jaxrs/src/main/java/o
> public Response deleteMetricTags(
216,218c175,182
< @ApiParam("Tag list") @PathParam("tags") Tags tags) {
< Metric<Long> metric = new Metric<>(new MetricId<>(tenantId, COUNTER, id));
< Metric<Long> metric = new Metric<>(new MetricId(tenantId, COUNTER, id));
< metricsService.deleteTags(metric, tags.getTags()).subscribe(new ResultSetObserver(asyncResponse));
---
> @PathParam("tags") Tags tags) {
> try {
> Metric<Long> metric = new Metric<>(new MetricId<>(tenantId, COUNTER, id));
> Metric<Long> metric = new Metric<>(new MetricId(tenantId, COUNTER, id));
> metricsService.deleteTags(metric, tags.getTags()).toBlocking().lastOrDefault(null);
> return Response.ok().build();
> } catch (Exception e) {
Expand Down Expand Up @@ -1416,10 +1416,10 @@ diff -r '--exclude-from=api/diff-excludes' api/metrics-api-jaxrs/src/main/java/o
> return badRequest(new ApiError("Metric type does not match " + MetricType
> .GAUGE.getText()));
115,116c94,95
< metric = new Metric<>(new MetricId<>(tenantId, GAUGE, metric.getId()), metric.getTags(),
< metric = new Metric<>(new MetricId(tenantId, GAUGE, metric.getId()), metric.getTags(),
< metric.getDataRetention());
---
> metric = new Metric<>(new MetricId<>(tenantId, GAUGE, metric.getId()),
> metric = new Metric<>(new MetricId(tenantId, GAUGE, metric.getId()),
> metric.getTags(), metric.getDataRetention());
118c97,106
< metricsService.createMetric(metric).subscribe(new MetricCreatedObserver(asyncResponse, location));
Expand Down Expand Up @@ -1482,11 +1482,11 @@ diff -r '--exclude-from=api/diff-excludes' api/metrics-api-jaxrs/src/main/java/o
< @ApiResponse(code = 500, message = "Unexpected error occurred while fetching metric's definition.",
< response = ApiError.class) })
< public void getGaugeMetric(@Suspended final AsyncResponse asyncResponse, @PathParam("id") String id) {
< metricsService.findMetric(new MetricId<>(tenantId, GAUGE, id))
< metricsService.findMetric(new MetricId(tenantId, GAUGE, id))
---
> public Response getGaugeMetric(@PathParam("id") String id) {
> try {
> return metricsService.findMetric(new MetricId<>(tenantId, GAUGE, id))
> return metricsService.findMetric(new MetricId(tenantId, GAUGE, id))
164,165c137,140
< .switchIfEmpty(Observable.just(ApiUtils.noContent()))
< .subscribe(asyncResponse::resume, t -> asyncResponse.resume(ApiUtils.serverError(t)));
Expand All @@ -1506,15 +1506,15 @@ diff -r '--exclude-from=api/diff-excludes' api/metrics-api-jaxrs/src/main/java/o
< @Suspended final AsyncResponse asyncResponse,
< @PathParam("id") String id
< ) {
< metricsService.getMetricTags(new MetricId<>(tenantId, GAUGE, id))
< metricsService.getMetricTags(new MetricId(tenantId, GAUGE, id))
< .subscribe(
< optional -> asyncResponse.resume(ApiUtils.valueToResponse(optional)),
< t ->asyncResponse.resume(ApiUtils.serverError(t))
< );
---
> public Response getMetricTags(@PathParam("id") String id) {
> try {
> return metricsService.getMetricTags(new MetricId<>(tenantId, GAUGE, id))
> return metricsService.getMetricTags(new MetricId(tenantId, GAUGE, id))
> .map(ApiUtils::valueToResponse)
> .toBlocking().lastOrDefault(null);
> } catch (Exception e) {
Expand Down Expand Up @@ -1562,11 +1562,11 @@ diff -r '--exclude-from=api/diff-excludes' api/metrics-api-jaxrs/src/main/java/o
---
> @PathParam("tags") Tags tags
216,217c177,183
< Metric<Double> metric = new Metric<>(new MetricId<>(tenantId, GAUGE, id));
< Metric<Double> metric = new Metric<>(new MetricId(tenantId, GAUGE, id));
< metricsService.deleteTags(metric, tags.getTags()).subscribe(new ResultSetObserver(asyncResponse));
---
> try {
> Metric<Double> metric = new Metric<>(new MetricId<>(tenantId, GAUGE, id));
> Metric<Double> metric = new Metric<>(new MetricId(tenantId, GAUGE, id));
> metricsService.deleteTags(metric, tags.getTags()).toBlocking().lastOrDefault(null);
> return Response.ok().build();
> } catch (Exception e) {
Expand Down Expand Up @@ -1822,13 +1822,13 @@ diff -r '--exclude-from=api/diff-excludes' api/metrics-api-jaxrs/src/main/java/o
> return badRequest(
> new ApiError("Invalid value for op parameter. Supported values are lt, lte, eq, gt, gte."));
436,439c355,362
< MetricId<Double> metricId = new MetricId<>(tenantId, GAUGE, id);
< MetricId metricId = new MetricId(tenantId, GAUGE, id);
< metricsService.getPeriods(metricId, predicate, timeRange.getStart(), timeRange.getEnd())
< .map(ApiUtils::collectionToResponse)
< .subscribe(asyncResponse::resume, t -> asyncResponse.resume(ApiUtils.serverError(t)));
---
> try {
> MetricId<Double> metricId = new MetricId<>(tenantId, GAUGE, id);
> MetricId metricId = new MetricId(tenantId, GAUGE, id);
> return metricsService.getPeriods(metricId, predicate, timeRange.getStart(), timeRange.getEnd())
> .map(ApiUtils::collectionToResponse)
> .toBlocking().lastOrDefault(null);
Expand Down Expand Up @@ -1877,10 +1877,6 @@ diff -r '--exclude-from=api/diff-excludes' api/metrics-api-jaxrs/src/main/java/o
< asyncResponse.resume(badRequest(new ApiError("Metric type is invalid")));
---
> return badRequest(new ApiError("Metric type is invalid"));
103c83
< MetricId<T> id = new MetricId<T>(tenantId, metric.getMetricId().getType(), metric.getId());
---
> MetricId<T> id = new MetricId<>(tenantId, metric.getMetricId().getType(), metric.getId());
107c87,97
< metricsService.createMetric(metric).subscribe(new MetricCreatedObserver(asyncResponse, location));
---
Expand Down Expand Up @@ -1910,12 +1906,12 @@ diff -r '--exclude-from=api/diff-excludes' api/metrics-api-jaxrs/src/main/java/o
< AsyncResponse asyncResponse,
< @ApiParam(value = "Queried metric type", required = false, allowableValues = "gauge, availability, counter")
< @QueryParam("type")
< MetricType<T> metricType,
< MetricType metricType,
< @ApiParam(value = "List of tags filters", required = false) @QueryParam("tags")
< Tags tags
---
> public <T> Response findMetrics(
> @QueryParam("type") MetricType<T> metricType,
> @QueryParam("type") MetricType metricType,
> @QueryParam("tags") Tags tags
131,132c107
< asyncResponse.resume(badRequest(new ApiError("Incorrect type param " + metricType.toString())));
Expand Down Expand Up @@ -2130,10 +2126,10 @@ diff -r '--exclude-from=api/diff-excludes' api/metrics-api-jaxrs/src/main/java/o
21a23
> import org.jboss.resteasy.spi.StringConverter;
28c30,31
< public class MetricTypeConverter implements ParamConverter<MetricType<?>> {
< public class MetricTypeConverter implements ParamConverter<MetricType> {
---
> @Provider
> public class MetricTypeConverter implements StringConverter<MetricType<?>> {
> public class MetricTypeConverter implements StringConverter<MetricType> {
diff -r '--exclude-from=api/diff-excludes' api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/param/PercentilesConverter.java api/metrics-api-jaxrs-1.1/src/main/java/org/hawkular/metrics/api/jaxrs/param/PercentilesConverter.java
22c22
< import javax.ws.rs.ext.ParamConverter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class MetricTypeTextConverter {

private MetricTypeTextConverter() { }

public static String getLongForm(MetricType<?> mt) {
public static String getLongForm(MetricType mt) {

if(mt == MetricType.GAUGE) {
return "gauges";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public Response createAvailabilityMetric(
.AVAILABILITY.getText()));
}
URI location = uriInfo.getBaseUriBuilder().path("/availability/{id}").build(metric.getId());
metric = new Metric<>(new MetricId<>(tenantId, AVAILABILITY, metric.getId()),
metric = new Metric<>(new MetricId(tenantId, AVAILABILITY, metric.getId()),
metric.getTags(), metric.getDataRetention());
try {
Observable<Void> observable = metricsService.createMetric(metric);
Expand Down Expand Up @@ -132,7 +132,7 @@ public Response findAvailabilityMetrics(
@Path("/{id}")
public Response getAvailabilityMetric(@PathParam("id") String id) {
try {
return metricsService.findMetric(new MetricId<>(tenantId, AVAILABILITY, id))
return metricsService.findMetric(new MetricId(tenantId, AVAILABILITY, id))
.map(metricDef -> Response.ok(metricDef).build())
.switchIfEmpty(Observable.just(noContent()))
.toBlocking()
Expand All @@ -148,7 +148,7 @@ public Response getMetricTags(
@PathParam("id") String id
) {
Observable<Optional<Map<String, String>>> something = metricsService
.getMetricTags(new MetricId<>(tenantId, AVAILABILITY, id));
.getMetricTags(new MetricId(tenantId, AVAILABILITY, id));
try {
return something
.map(ApiUtils::valueToResponse)
Expand All @@ -166,7 +166,7 @@ public Response updateMetricTags(
@PathParam("id") String id,
Map<String, String> tags
) {
Metric<AvailabilityType> metric = new Metric<>(new MetricId<>(tenantId, AVAILABILITY, id));
Metric<AvailabilityType> metric = new Metric<>(new MetricId(tenantId, AVAILABILITY, id));
try {
metricsService.addTags(metric, tags).toBlocking().lastOrDefault(null);
return Response.ok().build();
Expand All @@ -183,7 +183,7 @@ public Response deleteMetricTags(
@PathParam("id") String id,
@PathParam("tags") Tags tags
) {
Metric<AvailabilityType> metric = new Metric<>(new MetricId<>(tenantId, AVAILABILITY, id));
Metric<AvailabilityType> metric = new Metric<>(new MetricId(tenantId, AVAILABILITY, id));

try {
metricsService.deleteTags(metric, tags.getTags()).toBlocking().lastOrDefault(null);
Expand Down Expand Up @@ -242,7 +242,7 @@ public Response findAvailabilityData(
return badRequest(new ApiError(bucketConfig.getProblem()));
}

MetricId<AvailabilityType> metricId = new MetricId<>(tenantId, AVAILABILITY, id);
MetricId metricId = new MetricId(tenantId, AVAILABILITY, id);
Buckets buckets = bucketConfig.getBuckets();
try {
if (buckets == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public Response createCounter(
return badRequest(new ApiError("Metric type does not match " + MetricType
.COUNTER.getText()));
}
metric = new Metric<>(new MetricId<>(tenantId, COUNTER, metric.getId()),
metric = new Metric<>(new MetricId(tenantId, COUNTER, metric.getId()),
metric.getTags(), metric.getDataRetention());
URI location = uriInfo.getBaseUriBuilder().path("/counters/{id}").build(metric.getMetricId().getName());
try {
Expand Down Expand Up @@ -131,7 +131,7 @@ public Response findCounterMetrics(
@Path("/{id}")
public Response getCounter(@PathParam("id") String id) {
try {
return metricsService.findMetric(new MetricId<>(tenantId, COUNTER, id))
return metricsService.findMetric(new MetricId(tenantId, COUNTER, id))
.map(metricDef -> Response.ok(metricDef).build())
.switchIfEmpty(Observable.just(noContent()))
.toBlocking().lastOrDefault(null);
Expand All @@ -144,7 +144,7 @@ public Response getCounter(@PathParam("id") String id) {
@Path("/{id}/tags")
public Response getMetricTags(@PathParam("id") String id) {
try {
return metricsService.getMetricTags(new MetricId<>(tenantId, COUNTER, id))
return metricsService.getMetricTags(new MetricId(tenantId, COUNTER, id))
.map(ApiUtils::valueToResponse)
.toBlocking().lastOrDefault(null);
} catch (Exception e) {
Expand All @@ -157,7 +157,7 @@ public Response getMetricTags(@PathParam("id") String id) {
public Response updateMetricTags(
@PathParam("id") String id,
Map<String, String> tags) {
Metric<Long> metric = new Metric<>(new MetricId<>(tenantId, COUNTER, id));
Metric<Long> metric = new Metric<>(new MetricId(tenantId, COUNTER, id));
try {
metricsService.addTags(metric, tags).toBlocking().lastOrDefault(null);
return Response.ok().build();
Expand All @@ -174,7 +174,7 @@ public Response deleteMetricTags(
@PathParam("id") String id,
@PathParam("tags") Tags tags) {
try {
Metric<Long> metric = new Metric<>(new MetricId<>(tenantId, COUNTER, id));
Metric<Long> metric = new Metric<>(new MetricId(tenantId, COUNTER, id));
metricsService.deleteTags(metric, tags.getTags()).toBlocking().lastOrDefault(null);
return Response.ok().build();
} catch (Exception e) {
Expand Down Expand Up @@ -228,7 +228,7 @@ public Response findCounterData(
return badRequest(new ApiError(bucketConfig.getProblem()));
}

MetricId<Long> metricId = new MetricId<>(tenantId, COUNTER, id);
MetricId metricId = new MetricId(tenantId, COUNTER, id);
Buckets buckets = bucketConfig.getBuckets();
try {
if (buckets == null) {
Expand Down Expand Up @@ -273,7 +273,7 @@ public Response findRate(
return badRequest(new ApiError(bucketConfig.getProblem()));
}

MetricId<Long> metricId = new MetricId<>(tenantId, COUNTER, id);
MetricId metricId = new MetricId(tenantId, COUNTER, id);
Buckets buckets = bucketConfig.getBuckets();
try {
if (buckets == null) {
Expand Down

0 comments on commit 8cd7930

Please sign in to comment.