Skip to content

Commit

Permalink
[HWKMETRICS-185] Fix master rebase errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Negrea committed Aug 10, 2015
1 parent 0a77d41 commit bdf618f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static <E> Response simpleOKResponse(E optional) {
return Response.ok().build();
}

public static <E> Response valueToResponse(Optional<E> optional) {
public static Response valueToResponse(Optional<?> optional) {
return optional.map(value -> Response.ok(value).build()).orElse(noContent());
}

Expand All @@ -80,18 +80,18 @@ public static List<DataPoint<Double>> requestToGaugeDataPoints(List<GaugeDataPoi
}

public static Observable<Metric<Double>> requestToGauges(String tenantId, List<Gauge> gauges) {
return Observable.from(gauges).map(g ->
new Metric<>(tenantId, GAUGE, new MetricId(g.getId()), requestToGaugeDataPoints(g.getData())));
return Observable.from(gauges).map(
g -> new Metric<>(new MetricId(tenantId, GAUGE, g.getId()), requestToGaugeDataPoints(g.getData())));
}

public static Observable<Metric<Long>> requestToCounters(String tenantId, List<Counter> counters) {
return Observable.from(counters).map(c ->
new Metric<>(tenantId, COUNTER, new MetricId(c.getId()), requestToCounterDataPoints(c.getData())));
return Observable.from(counters).map(
c -> new Metric<>(new MetricId(tenantId, COUNTER, c.getId()), requestToCounterDataPoints(c.getData())));
}

public static Observable<Metric<AvailabilityType>> requestToAvailabilities(String tenantId,
List<Availability> avails) {
return Observable.from(avails).map(a -> new Metric<>(tenantId, AVAILABILITY, new MetricId(a.getId()),
return Observable.from(avails).map(a -> new Metric<>(new MetricId(tenantId, AVAILABILITY, a.getId()),
requestToAvailabilityDataPoints(a.getData())));
}

Expand Down Expand Up @@ -120,4 +120,4 @@ public static Response emptyPayload() {
public static Response badRequest(ApiError error) {
return Response.status(Response.Status.BAD_REQUEST).entity(error).build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ public Response createAvailabilityMetric(
@Context UriInfo uriInfo
) {
URI location = uriInfo.getBaseUriBuilder().path("/availability/{id}").build(metricDefinition.getId());
Metric<?> metric = new Metric<DataPoint<?>>(tenantId, AVAILABILITY,
new MetricId(metricDefinition.getId()),
Metric<?> metric = new Metric<DataPoint<?>>(new MetricId(tenantId, AVAILABILITY, metricDefinition.getId()),
metricDefinition.getTags(), metricDefinition.getDataRetention());
try {
EntityCreatedObserver<MetricAlreadyExistsException> observer = new MetricCreatedObserver(location);
Expand All @@ -135,7 +134,7 @@ public Response createAvailabilityMetric(
response = ApiError.class) })
public Response getAvailabilityMetric(@HeaderParam("tenantId") String tenantId, @PathParam("id") String id) {
try {
return metricsService.findMetric(tenantId, AVAILABILITY, new MetricId(id))
return metricsService.findMetric(new MetricId(tenantId, AVAILABILITY, id))
.map(MetricDefinition::new)
.map(metricDef -> Response.ok(metricDef).build())
.switchIfEmpty(Observable.just(noContent()))
Expand All @@ -157,8 +156,8 @@ public Response getAvailabilityMetric(@HeaderParam("tenantId") String tenantId,
public Response getAvailabilityMetricTags(
@PathParam("id") String id
) {
Observable<Optional<Map<String, String>>> something = metricsService.getMetricTags(tenantId, AVAILABILITY,
new MetricId(id));
Observable<Optional<Map<String, String>>> something = metricsService
.getMetricTags(new MetricId(tenantId, AVAILABILITY, id));
try {
return something.map(optional -> valueToResponse(optional)).toBlocking().last();
} catch (Exception e) {
Expand All @@ -178,7 +177,7 @@ public Response updateAvailabilityMetricTags(
@PathParam("id") String id,
@ApiParam(required = true) Map<String, String> tags
) {
Metric<AvailabilityType> metric = new Metric<>(tenantId, AVAILABILITY, new MetricId(id));
Metric<AvailabilityType> metric = new Metric<>(new MetricId(tenantId, AVAILABILITY, id));
try {
return metricsService.addTags(metric, tags).map(ApiUtils::simpleOKResponse).toBlocking().last();
} catch (Exception e) {
Expand All @@ -198,7 +197,7 @@ public Response deleteAvailabilityMetricTags(
@PathParam("id") String id,
@ApiParam("Tag list") @PathParam("tags") Tags tags
) {
Metric<AvailabilityType> metric = new Metric<>(tenantId, AVAILABILITY, new MetricId(id));
Metric<AvailabilityType> metric = new Metric<>(new MetricId(tenantId, AVAILABILITY, id));

try {
return metricsService.deleteTags(metric, tags.getTags()).map(ApiUtils::simpleOKResponse).toBlocking()
Expand All @@ -221,7 +220,7 @@ public Response addAvailabilityForMetric(
@PathParam("id") String id,
@ApiParam(value = "List of availability datapoints", required = true) List<AvailabilityDataPoint> data
) {
Metric<AvailabilityType> metric = new Metric<>(tenantId, AVAILABILITY, new MetricId(id),
Metric<AvailabilityType> metric = new Metric<>(new MetricId(tenantId, AVAILABILITY, id),
requestToAvailabilityDataPoints(data));

try {
Expand Down Expand Up @@ -306,10 +305,10 @@ public Response findAvailabilityData(
Long startTime = start == null ? now - EIGHT_HOURS : start;
Long endTime = end == null ? now : end;

Metric<AvailabilityType> metric = new Metric<>(tenantId, AVAILABILITY, new MetricId(id));
Metric<AvailabilityType> metric = new Metric<>(new MetricId(tenantId, AVAILABILITY, id));
if (bucketsCount == null && bucketDuration == null) {
try {
return metricsService.findAvailabilityData(tenantId, metric.getId(), startTime, endTime, distinct)
return metricsService.findAvailabilityData(metric.getId(), startTime, endTime, distinct)
.map(AvailabilityDataPoint::new)
.toList()
.map(ApiUtils::collectionToResponse).toBlocking().last();
Expand Down Expand Up @@ -351,7 +350,7 @@ public Response tagAvailabilityData(
@ApiParam(required = true) TagRequest params
) {
Observable<Void> resultSetObservable;
Metric<AvailabilityType> metric = new Metric<>(tenantId, AVAILABILITY, new MetricId(id));
Metric<AvailabilityType> metric = new Metric<>(new MetricId(tenantId, AVAILABILITY, id));
if (params.getTimestamp() != null) {
resultSetObservable = metricsService.tagAvailabilityData(metric, params.getTags(), params.getTimestamp());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public Response createCounter(
@ApiParam(required = true) MetricDefinition metricDefinition,
@Context UriInfo uriInfo
) {
Metric<Double> metric = new Metric<>(tenantId, COUNTER, new MetricId(metricDefinition.getId()),
Metric<Double> metric = new Metric<>(new MetricId(tenantId, COUNTER, metricDefinition.getId()),
metricDefinition.getTags(), metricDefinition.getDataRetention());
URI location = uriInfo.getBaseUriBuilder().path("/counters/{id}").build(metric.getId().getName());

Expand All @@ -127,7 +127,7 @@ public Response createCounter(
response = ApiError.class) })
public Response getCounter(@PathParam("id") String id) {
try {
return metricsService.findMetric(tenantId, COUNTER, new MetricId(id))
return metricsService.findMetric(new MetricId(tenantId, COUNTER, id))
.map(MetricDefinition::new)
.map(metricDef -> Response.ok(metricDef).build())
.switchIfEmpty(Observable.just(ApiUtils.noContent()))
Expand Down Expand Up @@ -170,7 +170,7 @@ public Response addData(
@ApiParam(value = "List of data points containing timestamp and value", required = true)
List<CounterDataPoint> data
) {
Metric<Long> metric = new Metric<>(tenantId, COUNTER, new MetricId(id), requestToCounterDataPoints(data));
Metric<Long> metric = new Metric<>(new MetricId(tenantId, COUNTER, id), requestToCounterDataPoints(data));
try {
return metricsService.addCounterData(Observable.just(metric)).map(ApiUtils::simpleOKResponse).toBlocking()
.last();
Expand Down Expand Up @@ -199,7 +199,7 @@ public Response findCounterData(
long endTime = end == null ? now : end;

try {
return metricsService.findCounterData(tenantId, new MetricId(id), startTime, endTime)
return metricsService.findCounterData(new MetricId(tenantId, COUNTER, id), startTime, endTime)
.map(CounterDataPoint::new)
.toList()
.map(ApiUtils::collectionToResponse).toBlocking().last();
Expand Down Expand Up @@ -232,7 +232,7 @@ public Response findRate(
long endTime = end == null ? now : end;

try {
return metricsService.findRateData(tenantId, new MetricId(id), startTime, endTime)
return metricsService.findRateData(new MetricId(tenantId, COUNTER, id), startTime, endTime)
.map(GaugeDataPoint::new)
.toList()
.map(ApiUtils::collectionToResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public Response createGaugeMetric(
@ApiParam(required = true) MetricDefinition metricDefinition,
@Context UriInfo uriInfo
) {
Metric<Double> metric = new Metric<>(tenantId, GAUGE, new MetricId(metricDefinition.getId()),
Metric<Double> metric = new Metric<>(new MetricId(tenantId, GAUGE, metricDefinition.getId()),
metricDefinition.getTags(), metricDefinition.getDataRetention());
URI location = uriInfo.getBaseUriBuilder().path("/gauges/{id}").build(metric.getId().getName());

Expand All @@ -128,7 +128,7 @@ public Response createGaugeMetric(
response = ApiError.class) })
public Response getGaugeMetric(@PathParam("id") String id) {
try {
return metricsService.findMetric(tenantId, GAUGE, new MetricId(id))
return metricsService.findMetric(new MetricId(tenantId, GAUGE, id))
.map(MetricDefinition::new)
.map(metricDef -> Response.ok(metricDef).build())
.switchIfEmpty(Observable.just(ApiUtils.noContent()))
Expand All @@ -149,7 +149,7 @@ public Response getGaugeMetric(@PathParam("id") String id) {
response = ApiError.class) })
public Response getGaugeMetricTags(@PathParam("id") String id) {
try {
return metricsService.getMetricTags(tenantId, GAUGE, new MetricId(id))
return metricsService.getMetricTags(new MetricId(tenantId, GAUGE, id))
.map(ApiUtils::valueToResponse).toBlocking().last();
} catch (Exception e) {
return ApiUtils.serverError(e);
Expand All @@ -167,7 +167,7 @@ public Response updateGaugeMetricTags(
@PathParam("id") String id,
@ApiParam(required = true) Map<String, String> tags
) {
Metric<Double> metric = new Metric<>(tenantId, GAUGE, new MetricId(id));
Metric<Double> metric = new Metric<>(new MetricId(tenantId, GAUGE, id));
try {
return metricsService.addTags(metric, tags).map(ApiUtils::simpleOKResponse).toBlocking().last();
} catch (Exception e) {
Expand All @@ -188,7 +188,7 @@ public Response deleteGaugeMetricTags(
@ApiParam("Tag list") @PathParam("tags") Tags tags
) {
try {
Metric<Double> metric = new Metric<>(tenantId, GAUGE, new MetricId(id));
Metric<Double> metric = new Metric<>(new MetricId(tenantId, GAUGE, id));
return metricsService.deleteTags(metric, tags.getTags()).map(ApiUtils::simpleOKResponse).toBlocking()
.last();
} catch (Exception e) {
Expand All @@ -210,7 +210,7 @@ public Response addDataForMetric(
@ApiParam(value = "List of datapoints containing timestamp and value", required = true)
List<GaugeDataPoint> data
) {
Metric<Double> metric = new Metric<>(tenantId, GAUGE, new MetricId(id), requestToGaugeDataPoints(data));
Metric<Double> metric = new Metric<>(new MetricId(tenantId, GAUGE, id), requestToGaugeDataPoints(data));
try {
Observable<Void> observable = metricsService.addGaugeData(Observable.just(metric));
return observable.map(ApiUtils::simpleOKResponse).toBlocking().last();
Expand Down Expand Up @@ -290,7 +290,7 @@ public Response findGaugeData(
long endTime = end == null ? now : end;

try {
return metricsService.findGaugeData(tenantId, new MetricId(id), startTime, endTime)
return metricsService.findGaugeData(new MetricId(tenantId, GAUGE, id), startTime, endTime)
.toList()
.map(ApiUtils::collectionToResponse).toBlocking().last();
} catch (Exception e) {
Expand All @@ -303,7 +303,7 @@ public Response findGaugeData(
long startTime = start == null ? now - EIGHT_HOURS : start;
long endTime = end == null ? now : end;

Metric<Double> metric = new Metric<>(tenantId, GAUGE, new MetricId(id));
Metric<Double> metric = new Metric<>(new MetricId(tenantId, GAUGE, id));

Buckets buckets;
try {
Expand Down Expand Up @@ -383,7 +383,8 @@ public Response findPeriods(
new ApiError("Invalid value for op parameter. Supported values are lt, lte, eq, gt, gte."));
} else {
try {
return metricsService.getPeriods(tenantId, new MetricId(id), predicate, startTime, endTime)
return metricsService
.getPeriods(new MetricId(tenantId, GAUGE, id), predicate, startTime, endTime)
.map(ApiUtils::collectionToResponse).toBlocking().last();
} catch (Exception e) {
return ApiUtils.serverError(e);
Expand All @@ -403,7 +404,7 @@ public Response findTaggedGaugeData(@ApiParam("Tag list") @PathParam("tags") Tag
return metricsService.findGaugeDataByTags(tenantId, tags.getTags())
.flatMap(input -> Observable.from(input.entrySet()))
.toMap(e -> e.getKey().getName(), e2 -> e2.getValue())
.map(m -> {
.map(m -> {
if (m.isEmpty()) {
return ApiUtils.noContent();
} else {
Expand All @@ -425,7 +426,7 @@ public Response findTaggedGaugeData(@ApiParam("Tag list") @PathParam("tags") Tag
})
public Response tagGaugeData(@PathParam("id") final String id, @ApiParam(required = true) TagRequest params) {
Observable<Void> resultSetObservable;
Metric<Double> metric = new Metric<>(tenantId, GAUGE, new MetricId(id));
Metric<Double> metric = new Metric<>(new MetricId(tenantId, GAUGE, id));
if (params.getTimestamp() != null) {
resultSetObservable = metricsService.tagGaugeData(metric, params.getTags(), params.getTimestamp());
} else {
Expand Down

0 comments on commit bdf618f

Please sign in to comment.