mirror of https://github.com/apache/jclouds.git
value and statistics values are not compatible in cloudwatch
This commit is contained in:
parent
f7feb0248a
commit
09065a32ca
|
@ -93,8 +93,10 @@ public class MetricDataBinder implements org.jclouds.rest.Binder {
|
|||
formParameters.put("MetricData.member." + metricDatumIndex + ".Unit",
|
||||
String.valueOf(metricDatum.getUnit()));
|
||||
|
||||
formParameters.put("MetricData.member." + metricDatumIndex + ".Value",
|
||||
String.valueOf(metricDatum.getValue()));
|
||||
if (metricDatum.getValue().isPresent()) {
|
||||
formParameters.put("MetricData.member." + metricDatumIndex + ".Value",
|
||||
String.valueOf(metricDatum.getValue().get()));
|
||||
}
|
||||
|
||||
metricDatumIndex++;
|
||||
}
|
||||
|
|
|
@ -25,13 +25,15 @@ import java.util.Date;
|
|||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* @see <a href="http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html" />
|
||||
* @see <a href=
|
||||
* "http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html"
|
||||
* />
|
||||
*
|
||||
* @author Jeremy Whitlock
|
||||
*/
|
||||
|
@ -42,17 +44,17 @@ public class MetricDatum {
|
|||
private final Optional<StatisticValues> statisticValues;
|
||||
private final Optional<Date> timestamp;
|
||||
private final Unit unit;
|
||||
private final double value;
|
||||
private final Optional<Double> value;
|
||||
|
||||
/**
|
||||
* Private constructor to enforce using {@link Builder}.
|
||||
*/
|
||||
protected MetricDatum(Set<Dimension> dimensions, String metricName, StatisticValues statisticValues, Date timestamp,
|
||||
Unit unit, double value) {
|
||||
this.dimensions = ImmutableSet.<Dimension>copyOf(checkNotNull(dimensions, "dimensions"));
|
||||
protected MetricDatum(Iterable<Dimension> dimensions, String metricName, Optional<StatisticValues> statisticValues,
|
||||
Optional<Date> timestamp, Unit unit, Optional<Double> value) {
|
||||
this.dimensions = ImmutableSet.<Dimension> copyOf(checkNotNull(dimensions, "dimensions"));
|
||||
this.metricName = checkNotNull(metricName, "metricName");
|
||||
this.statisticValues = Optional.fromNullable(statisticValues);
|
||||
this.timestamp = Optional.fromNullable(timestamp);
|
||||
this.statisticValues = checkNotNull(statisticValues, "statisticValues");
|
||||
this.timestamp = checkNotNull(timestamp, "timestamp");
|
||||
this.unit = checkNotNull(unit, "unit");
|
||||
this.value = checkNotNull(value, "value");
|
||||
}
|
||||
|
@ -95,13 +97,13 @@ public class MetricDatum {
|
|||
/**
|
||||
* return the actual value of the metric
|
||||
*/
|
||||
public double getValue() {
|
||||
public Optional<Double> getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new builder. The generated builder is equivalent to the builder
|
||||
* created by the {@link Builder} constructor.
|
||||
* Returns a new builder. The generated builder is equivalent to the builder created by the
|
||||
* {@link Builder} constructor.
|
||||
*/
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
|
@ -110,27 +112,29 @@ public class MetricDatum {
|
|||
public static class Builder {
|
||||
|
||||
// this builder is set to be additive on dimension calls, so make this mutable
|
||||
private Set<Dimension> dimensions = Sets.newLinkedHashSet();
|
||||
private ImmutableList.Builder<Dimension> dimensions = ImmutableList.<Dimension> builder();
|
||||
private String metricName;
|
||||
private StatisticValues statisticValues;
|
||||
private Date timestamp;
|
||||
private Optional<StatisticValues> statisticValues = Optional.absent();
|
||||
private Optional<Date> timestamp = Optional.absent();
|
||||
private Unit unit = Unit.NONE;
|
||||
private double value;
|
||||
private Optional<Double> value = Optional.absent();
|
||||
|
||||
/**
|
||||
* Creates a new builder. The returned builder is equivalent to the builder
|
||||
* generated by {@link org.jclouds.cloudwatch.domain.MetricDatum#builder}.
|
||||
* Creates a new builder. The returned builder is equivalent to the builder generated by
|
||||
* {@link org.jclouds.cloudwatch.domain.MetricDatum#builder}.
|
||||
*/
|
||||
public Builder() {}
|
||||
public Builder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of dimensions describing qualities of the metric.
|
||||
*
|
||||
* @param dimensions the dimensions describing the qualities of the metric
|
||||
* @param dimensions
|
||||
* the dimensions describing the qualities of the metric
|
||||
*
|
||||
* @return this {@code Builder} object
|
||||
*/
|
||||
public Builder dimensions(Set<Dimension> dimensions) {
|
||||
public Builder dimensions(Iterable<Dimension> dimensions) {
|
||||
this.dimensions.addAll(checkNotNull(dimensions, "dimensions"));
|
||||
return this;
|
||||
}
|
||||
|
@ -138,7 +142,8 @@ public class MetricDatum {
|
|||
/**
|
||||
* A dimension describing qualities of the metric.
|
||||
*
|
||||
* @param dimension the dimension describing the qualities of the metric
|
||||
* @param dimension
|
||||
* the dimension describing the qualities of the metric
|
||||
*
|
||||
* @return this {@code Builder} object
|
||||
*/
|
||||
|
@ -150,7 +155,8 @@ public class MetricDatum {
|
|||
/**
|
||||
* The name of the metric.
|
||||
*
|
||||
* @param metricName the metric name
|
||||
* @param metricName
|
||||
* the metric name
|
||||
*
|
||||
* @return this {@code Builder} object
|
||||
*/
|
||||
|
@ -162,32 +168,35 @@ public class MetricDatum {
|
|||
/**
|
||||
* The object describing the set of statistical values describing the metric.
|
||||
*
|
||||
* @param statisticValues the object describing the set of statistical values for the metric
|
||||
* @param statisticValues
|
||||
* the object describing the set of statistical values for the metric
|
||||
*
|
||||
* @return this {@code Builder} object
|
||||
*/
|
||||
public Builder statisticValues(StatisticValues statisticValues) {
|
||||
this.statisticValues = statisticValues;
|
||||
this.statisticValues = Optional.fromNullable(statisticValues);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The time stamp used for the metric. If not specified, the default value is set to the time the metric data was
|
||||
* received.
|
||||
* The time stamp used for the metric. If not specified, the default value is set to the time
|
||||
* the metric data was received.
|
||||
*
|
||||
* @param timestamp the time stamp used for the metric
|
||||
* @param timestamp
|
||||
* the time stamp used for the metric
|
||||
*
|
||||
* @return this {@code Builder} object
|
||||
*/
|
||||
public Builder timestamp(Date timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
this.timestamp = Optional.fromNullable(timestamp);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The unit for the metric.
|
||||
*
|
||||
* @param unit the unit for the metric
|
||||
* @param unit
|
||||
* the unit for the metric
|
||||
*
|
||||
* @return this {@code Builder} object
|
||||
*/
|
||||
|
@ -199,12 +208,13 @@ public class MetricDatum {
|
|||
/**
|
||||
* The value for the metric.
|
||||
*
|
||||
* @param value the value for the metric
|
||||
* @param value
|
||||
* the value for the metric
|
||||
*
|
||||
* @return this {@code Builder} object
|
||||
*/
|
||||
public Builder value(double value) {
|
||||
this.value = value;
|
||||
public Builder value(Double value) {
|
||||
this.value = Optional.fromNullable(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -212,7 +222,7 @@ public class MetricDatum {
|
|||
* Returns a newly-created {@code MetricDatum} based on the contents of the {@code Builder}.
|
||||
*/
|
||||
public MetricDatum build() {
|
||||
return new MetricDatum(dimensions, metricName, statisticValues, timestamp, unit, value);
|
||||
return new MetricDatum(dimensions.build(), metricName, statisticValues, timestamp, unit, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -240,7 +250,8 @@ public class MetricDatum {
|
|||
}
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return Objects.toStringHelper("").add("dimensions", dimensions).add("metricName", metricName).add(
|
||||
"statisticValues", statisticValues).add("timestamp", timestamp).add("unit", unit).add("value", value);
|
||||
return Objects.toStringHelper("").omitNullValues().add("dimensions", dimensions).add("metricName", metricName)
|
||||
.add("statisticValues", statisticValues.orNull()).add("timestamp", timestamp.orNull()).add("unit", unit)
|
||||
.add("value", value.orNull());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,6 @@ public class MetricDataBinderTest {
|
|||
.statisticValues(ss)
|
||||
.dimension(new Dimension("TestDimension", "FAKE"))
|
||||
.unit(Unit.COUNT)
|
||||
.value(2)
|
||||
.build();
|
||||
|
||||
HttpRequest request = binder.bindToRequest(request(), ImmutableSet.of(metricDatum));
|
||||
|
@ -73,8 +72,7 @@ public class MetricDataBinderTest {
|
|||
"&MetricData.member.1.StatisticValues.Minimum=1.0" +
|
||||
"&MetricData.member.1.StatisticValues.SampleCount=4.0" +
|
||||
"&MetricData.member.1.StatisticValues.Sum=10.0" +
|
||||
"&MetricData.member.1.Unit=" + Unit.COUNT.toString() +
|
||||
"&MetricData.member.1.Value=2.0");
|
||||
"&MetricData.member.1.Unit=" + Unit.COUNT.toString());
|
||||
}
|
||||
|
||||
public void testMetricWithMultipleDimensions() throws Exception {
|
||||
|
|
Loading…
Reference in New Issue