-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #267 from hawkular/counter-data-rest
REST endpoints for reading/writing counter data points
- Loading branch information
Showing
6 changed files
with
405 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/model/Counter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright 2014-2015 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hawkular.metrics.api.jaxrs.model; | ||
|
||
import static java.util.Collections.unmodifiableList; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
/** | ||
* A container for data points for a single counter metric. | ||
* | ||
* @author jsanda | ||
*/ | ||
public class Counter { | ||
|
||
@JsonProperty | ||
private String id; | ||
|
||
@JsonProperty | ||
private List<CounterDataPoint> data; | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public List<CounterDataPoint> getData() { | ||
return unmodifiableList(data); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Counter gauge = (Counter) o; | ||
return Objects.equals(id, gauge.id) && | ||
Objects.equals(data, gauge.data); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, data); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return com.google.common.base.Objects.toStringHelper(this) | ||
.add("id", id) | ||
.add("data", data) | ||
.toString(); | ||
} | ||
|
||
} |
96 changes: 96 additions & 0 deletions
96
...etrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/model/CounterDataPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright 2014-2015 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hawkular.metrics.api.jaxrs.model; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.wordnik.swagger.annotations.ApiModel; | ||
import org.hawkular.metrics.core.api.DataPoint; | ||
|
||
/** | ||
* @author jsanda | ||
*/ | ||
@ApiModel(description = "A timestamp and a value where the value is interpreted as a signed 64 bit integer") | ||
public class CounterDataPoint { | ||
|
||
@JsonProperty | ||
private long timestamp; | ||
|
||
@JsonProperty | ||
private Long value; | ||
|
||
@JsonProperty | ||
private Map<String, String> tags = Collections.emptyMap(); | ||
|
||
/** | ||
* Used by JAX-RS/Jackson to deserialize HTTP request data | ||
*/ | ||
private CounterDataPoint() { | ||
} | ||
|
||
/** | ||
* Used to prepared data for serialization into the HTTP response | ||
* | ||
* @param dataPoint | ||
*/ | ||
public CounterDataPoint(DataPoint<Long> dataPoint) { | ||
timestamp = dataPoint.getTimestamp(); | ||
value = dataPoint.getValue(); | ||
tags = dataPoint.getTags(); | ||
} | ||
|
||
public Long getValue() { | ||
return value; | ||
} | ||
|
||
public long getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
public Map<String, String> getTags() { | ||
return ImmutableMap.copyOf(tags); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
CounterDataPoint that = (CounterDataPoint) o; | ||
// TODO should tags be included in equals? | ||
return Objects.equals(timestamp, that.timestamp) && | ||
Objects.equals(value, that.value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
// TODO should tags be included? | ||
return Objects.hash(timestamp, value); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return com.google.common.base.Objects.toStringHelper(this) | ||
.add("timestamp", timestamp) | ||
.add("value", value) | ||
.add("tags", tags) | ||
.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.