diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/binders/GetMetricStatisticsBinder.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/binders/GetMetricStatisticsBinder.java index e27aa85627..1fb4dafe98 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/binders/GetMetricStatisticsBinder.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/binders/GetMetricStatisticsBinder.java @@ -18,8 +18,10 @@ */ package org.jclouds.cloudwatch.binders; -import com.google.common.annotations.Beta; -import com.google.common.collect.ImmutableMultimap; +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; + import org.jclouds.cloudwatch.domain.Dimension; import org.jclouds.cloudwatch.domain.GetMetricStatistics; import org.jclouds.cloudwatch.domain.Statistics; @@ -27,9 +29,8 @@ import org.jclouds.date.DateService; import org.jclouds.http.HttpRequest; import org.jclouds.http.utils.ModifyRequest; -import javax.inject.Inject; -import java.util.HashSet; -import java.util.Set; +import com.google.common.annotations.Beta; +import com.google.common.collect.ImmutableMultimap; /** * Binds the metrics request to the http request @@ -51,41 +52,36 @@ public class GetMetricStatisticsBinder implements org.jclouds.rest.Binder { @Override public R bindToRequest(R request, Object payload) { - GetMetricStatistics getRequest = GetMetricStatistics.class.cast(payload); - Set dimensions = getRequest.getDimensions() != null ? - getRequest.getDimensions() : - new HashSet(); - Set statistics = getRequest.getStatistics() != null ? - getRequest.getStatistics() : - new HashSet(); + GetMetricStatistics getRequest = GetMetricStatistics.class.cast(checkNotNull(payload, + "GetMetricStatistics must be set!")); int dimensionIndex = 1; int statisticIndex = 1; ImmutableMultimap.Builder formParameters = ImmutableMultimap.builder(); - for (Dimension dimension : dimensions) { + for (Dimension dimension : getRequest.getDimensions()) { formParameters.put("Dimensions.member." + dimensionIndex + ".Name", dimension.getName()); formParameters.put("Dimensions.member." + dimensionIndex + ".Value", dimension.getValue()); dimensionIndex++; } - if (getRequest.getEndTime() != null) { - formParameters.put("EndTime", dateService.iso8601SecondsDateFormat(getRequest.getEndTime())); + if (getRequest.getEndTime().isPresent()) { + formParameters.put("EndTime", dateService.iso8601SecondsDateFormat(getRequest.getEndTime().get())); } formParameters.put("MetricName", getRequest.getMetricName()); formParameters.put("Namespace", getRequest.getNamespace()); formParameters.put("Period", Integer.toString(getRequest.getPeriod())); - if (getRequest.getStartTime() != null) { + if (getRequest.getStartTime().isPresent()) { formParameters.put("StartTime", dateService.iso8601SecondsDateFormat(getRequest - .getStartTime())); + .getStartTime().get())); } - - for (Statistics statistic : statistics) { + + for (Statistics statistic : getRequest.getStatistics()) { formParameters.put("Statistics.member." + statisticIndex, statistic.toString()); statisticIndex++; } - if (getRequest.getUnit() != null) { - formParameters.put("Unit", getRequest.getUnit().toString()); + if (getRequest.getUnit().isPresent()) { + formParameters.put("Unit", getRequest.getUnit().get().toString()); } return ModifyRequest.putFormParams(request, formParameters.build()); diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/binders/MetricDataBinder.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/binders/MetricDataBinder.java index 1ddffd48cf..15f28503c6 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/binders/MetricDataBinder.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/binders/MetricDataBinder.java @@ -18,18 +18,18 @@ */ package org.jclouds.cloudwatch.binders; -import com.google.common.annotations.Beta; -import com.google.common.collect.ImmutableMultimap; -import com.google.inject.Inject; +import static com.google.common.base.Preconditions.checkNotNull; + import org.jclouds.cloudwatch.domain.Dimension; import org.jclouds.cloudwatch.domain.MetricDatum; -import org.jclouds.cloudwatch.domain.StatisticSet; +import org.jclouds.cloudwatch.domain.StatisticValues; import org.jclouds.date.DateService; import org.jclouds.http.HttpRequest; import org.jclouds.http.utils.ModifyRequest; -import java.util.HashSet; -import java.util.Set; +import com.google.common.annotations.Beta; +import com.google.common.collect.ImmutableMultimap; +import com.google.inject.Inject; /** * Binds the metrics request to the http request @@ -51,22 +51,18 @@ public class MetricDataBinder implements org.jclouds.rest.Binder { /** * {@inheritDoc} */ + @SuppressWarnings("unchecked") @Override public R bindToRequest(R request, Object input) { - Iterable metrics = input != null ? - (Iterable)input : - new HashSet(); + Iterable metrics = (Iterable) checkNotNull(input, "metrics must be set!"); + ImmutableMultimap.Builder formParameters = ImmutableMultimap.builder(); int metricDatumIndex = 1; for (MetricDatum metricDatum : metrics) { int dimensionIndex = 1; - StatisticSet statisticSet = metricDatum.getStatisticSet(); - Set dimensions = metricDatum.getDimensions() != null ? - metricDatum.getDimensions() : - new HashSet(); - for (Dimension dimension : dimensions) { + for (Dimension dimension : metricDatum.getDimensions()) { formParameters.put("MetricData.member." + metricDatumIndex + ".Dimensions.member." + dimensionIndex + ".Name", dimension.getName()); formParameters.put("MetricData.member." + metricDatumIndex + ".Dimensions.member." + dimensionIndex + @@ -76,30 +72,30 @@ public class MetricDataBinder implements org.jclouds.rest.Binder { formParameters.put("MetricData.member." + metricDatumIndex + ".MetricName", metricDatum.getMetricName()); - if (statisticSet != null) { + + if (metricDatum.getStatisticValues().isPresent()) { + StatisticValues statisticValues = metricDatum.getStatisticValues().get(); + formParameters.put("MetricData.member." + metricDatumIndex + ".StatisticValues.Maximum", - String.valueOf(statisticSet.getMaximum())); + String.valueOf(statisticValues.getMaximum())); formParameters.put("MetricData.member." + metricDatumIndex + ".StatisticValues.Minimum", - String.valueOf(statisticSet.getMinimum())); + String.valueOf(statisticValues.getMinimum())); formParameters.put("MetricData.member." + metricDatumIndex + ".StatisticValues.SampleCount", - String.valueOf(statisticSet.getSampleCount())); + String.valueOf(statisticValues.getSampleCount())); formParameters.put("MetricData.member." + metricDatumIndex + ".StatisticValues.Sum", - String.valueOf(statisticSet.getSum())); + String.valueOf(statisticValues.getSum())); } - if (metricDatum.getTimestamp() != null) { + + if (metricDatum.getTimestamp().isPresent()) { formParameters.put("MetricData.member." + metricDatumIndex + ".Timestamp", - dateService.iso8601SecondsDateFormat(metricDatum.getTimestamp())); + dateService.iso8601SecondsDateFormat(metricDatum.getTimestamp().get())); } - if (metricDatum.getUnit() != null) { - formParameters.put("MetricData.member." + metricDatumIndex + ".Unit", - String.valueOf(metricDatum.getUnit())); - } + formParameters.put("MetricData.member." + metricDatumIndex + ".Unit", + String.valueOf(metricDatum.getUnit())); - if (metricDatum.getValue() != null) { - formParameters.put("MetricData.member." + metricDatumIndex + ".Value", - String.valueOf(metricDatum.getValue())); - } + formParameters.put("MetricData.member." + metricDatumIndex + ".Value", + String.valueOf(metricDatum.getValue())); metricDatumIndex++; } diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/GetMetricStatistics.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/GetMetricStatistics.java index 17f961dbf0..a386602bae 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/GetMetricStatistics.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/GetMetricStatistics.java @@ -18,14 +18,18 @@ */ package org.jclouds.cloudwatch.domain; -import com.google.common.annotations.Beta; -import com.google.common.collect.Sets; -import org.jclouds.cloudwatch.options.ListMetricsOptions; -import org.jclouds.javax.annotation.Nullable; +import static com.google.common.base.Preconditions.checkNotNull; import java.util.Date; import java.util.Set; +import org.jclouds.cloudwatch.options.ListMetricsOptions; + +import com.google.common.annotations.Beta; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; + /** * Options use to get statistics for the specified metric. * @@ -37,33 +41,32 @@ import java.util.Set; public class GetMetricStatistics { private final Set dimensions; - private final Date endTime; + private final Optional endTime; private final String metricName; private final String namespace; private final int period; - private final Date startTime; + private final Optional startTime; private final Set statistics; - private final Unit unit; + private final Optional unit; /** * Private constructor to enforce using {@link Builder}. */ - private GetMetricStatistics(Set dimensions, Date endTime, String metricName, String namespace, int period, + protected GetMetricStatistics(Set dimensions, Date endTime, String metricName, String namespace, int period, Date startTime, Set statistics, Unit unit) { - this.dimensions = dimensions; - this.endTime = endTime; - this.metricName = metricName; - this.namespace = namespace; + this.dimensions = ImmutableSet.copyOf(checkNotNull(dimensions, "dimensions")); + this.endTime = Optional.fromNullable(endTime); + this.metricName = checkNotNull(metricName, "metricName"); + this.namespace = checkNotNull(namespace, "namespace"); this.period = period; - this.startTime = startTime; - this.statistics = statistics; - this.unit = unit; + this.startTime = Optional.fromNullable(startTime); + this.statistics = ImmutableSet.copyOf(checkNotNull(statistics, "statistics")); + this.unit = Optional.fromNullable(unit); } /** * return the set of dimensions for this request */ - @Nullable public Set getDimensions() { return dimensions; } @@ -71,15 +74,13 @@ public class GetMetricStatistics { /** * return the end time for this request */ - @Nullable - public Date getEndTime() { + public Optional getEndTime() { return endTime; } /** * return the metric name for this request */ - @Nullable public String getMetricName() { return metricName; } @@ -87,7 +88,6 @@ public class GetMetricStatistics { /** * return the namespace for this request */ - @Nullable public String getNamespace() { return namespace; } @@ -95,7 +95,6 @@ public class GetMetricStatistics { /** * return the period for this request */ - @Nullable public int getPeriod() { return period; } @@ -103,15 +102,13 @@ public class GetMetricStatistics { /** * return the start time for this request */ - @Nullable - public Date getStartTime() { + public Optional getStartTime() { return startTime; } /** * return the statistics for this request */ - @Nullable public Set getStatistics() { return statistics; } @@ -119,8 +116,7 @@ public class GetMetricStatistics { /** * return the unit for this request */ - @Nullable - public Unit getUnit() { + public Optional getUnit() { return unit; } @@ -134,13 +130,15 @@ public class GetMetricStatistics { public static class Builder { - private Set dimensions; + // this builder is set to be additive on dimension calls, so make this mutable + private Set dimensions = Sets.newLinkedHashSet(); private Date endTime; private String metricName; private String namespace; - private int period; + private int period = 60; private Date startTime; - private Set statistics; + // this builder is set to be additive on dimension calls, so make this mutable + private Set statistics = Sets.newLinkedHashSet(); private Unit unit; /** @@ -157,7 +155,7 @@ public class GetMetricStatistics { * @return this {@code Builder} object */ public Builder dimensions(Set dimensions) { - this.dimensions = dimensions; + this.dimensions.addAll(checkNotNull(dimensions, "dimensions")); return this; } @@ -169,10 +167,7 @@ public class GetMetricStatistics { * @return this {@code Builder} object */ public Builder dimension(Dimension dimension) { - if (dimensions == null) { - dimensions = Sets.newLinkedHashSet(); - } - this.dimensions.add(dimension); + this.dimensions.add(checkNotNull(dimension, "dimension")); return this; } @@ -246,7 +241,7 @@ public class GetMetricStatistics { * @return this {@code Builder} object */ public Builder statistics(Set statistics) { - this.statistics = statistics; + this.statistics.addAll(checkNotNull(statistics, "statistics")); return this; } @@ -258,10 +253,7 @@ public class GetMetricStatistics { * @return this {@code Builder} object */ public Builder statistic(Statistics statistic) { - if (statistics == null) { - statistics = Sets.newLinkedHashSet(); - } - this.statistics.add(statistic); + this.statistics.add(checkNotNull(statistic, "statistic")); return this; } diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/MetricDatum.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/MetricDatum.java index 6f0e36cc30..2bd2d1385e 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/MetricDatum.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/MetricDatum.java @@ -18,12 +18,18 @@ */ package org.jclouds.cloudwatch.domain; -import com.google.common.collect.Sets; -import org.jclouds.javax.annotation.Nullable; +import static com.google.common.base.Objects.equal; +import static com.google.common.base.Preconditions.checkNotNull; 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.collect.ImmutableSet; +import com.google.common.collect.Sets; + /** * @see * @@ -33,28 +39,27 @@ public class MetricDatum { private final Set dimensions; private final String metricName; - private final StatisticSet statisticSet; - private final Date timestamp; + private final Optional statisticValues; + private final Optional timestamp; private final Unit unit; - private final Double value; + private final double value; /** * Private constructor to enforce using {@link Builder}. */ - private MetricDatum(Set dimensions, String metricName, StatisticSet statisticSet, Date timestamp, - Unit unit, Double value) { - this.dimensions = dimensions; - this.metricName = metricName; - this.statisticSet = statisticSet; - this.timestamp = timestamp; - this.unit = unit; - this.value = value; + protected MetricDatum(Set dimensions, String metricName, StatisticValues statisticValues, Date timestamp, + Unit unit, double value) { + this.dimensions = ImmutableSet.copyOf(checkNotNull(dimensions, "dimensions")); + this.metricName = checkNotNull(metricName, "metricName"); + this.statisticValues = Optional.fromNullable(statisticValues); + this.timestamp = Optional.fromNullable(timestamp); + this.unit = checkNotNull(unit, "unit"); + this.value = checkNotNull(value, "value"); } /** * return the list of dimensions describing the the metric. */ - @Nullable public Set getDimensions() { return dimensions; } @@ -62,7 +67,6 @@ public class MetricDatum { /** * return the metric name for the metric. */ - @Nullable public String getMetricName() { return metricName; } @@ -70,23 +74,20 @@ public class MetricDatum { /** * return the object describing the set of statistical values for the metric */ - @Nullable - public StatisticSet getStatisticSet() { - return statisticSet; + public Optional getStatisticValues() { + return statisticValues; } /** * return the time stamp used for the metric */ - @Nullable - public Date getTimestamp() { + public Optional getTimestamp() { return timestamp; } /** * return Standard unit used for the metric. */ - @Nullable public Unit getUnit() { return unit; } @@ -94,8 +95,7 @@ public class MetricDatum { /** * return the actual value of the metric */ - @Nullable - public Double getValue() { + public double getValue() { return value; } @@ -109,12 +109,13 @@ public class MetricDatum { public static class Builder { - private Set dimensions; + // this builder is set to be additive on dimension calls, so make this mutable + private Set dimensions = Sets.newLinkedHashSet(); private String metricName; - private StatisticSet statisticSet; + private StatisticValues statisticValues; private Date timestamp; - private Unit unit; - private Double value; + private Unit unit = Unit.NONE; + private double value; /** * Creates a new builder. The returned builder is equivalent to the builder @@ -130,7 +131,7 @@ public class MetricDatum { * @return this {@code Builder} object */ public Builder dimensions(Set dimensions) { - this.dimensions = dimensions; + this.dimensions.addAll(checkNotNull(dimensions, "dimensions")); return this; } @@ -142,10 +143,7 @@ public class MetricDatum { * @return this {@code Builder} object */ public Builder dimension(Dimension dimension) { - if (dimensions == null) { - dimensions = Sets.newLinkedHashSet(); - } - this.dimensions.add(dimension); + this.dimensions.add(checkNotNull(dimension, "dimension")); return this; } @@ -164,12 +162,12 @@ public class MetricDatum { /** * The object describing the set of statistical values describing the metric. * - * @param statisticSet 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 statisticSet(StatisticSet statisticSet) { - this.statisticSet = statisticSet; + public Builder statisticValues(StatisticValues statisticValues) { + this.statisticValues = statisticValues; return this; } @@ -205,7 +203,7 @@ public class MetricDatum { * * @return this {@code Builder} object */ - public Builder value(Double value) { + public Builder value(double value) { this.value = value; return this; } @@ -214,9 +212,35 @@ 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, statisticSet, timestamp, unit, value); + return new MetricDatum(dimensions, metricName, statisticValues, timestamp, unit, value); } } + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + MetricDatum that = MetricDatum.class.cast(o); + return equal(this.dimensions, that.dimensions) && equal(this.metricName, that.metricName) + && equal(this.statisticValues, that.statisticValues) && equal(this.timestamp, that.timestamp) + && equal(this.unit, that.unit) && equal(this.value, that.value); + } + + @Override + public int hashCode() { + return Objects.hashCode(dimensions, metricName, statisticValues, timestamp, unit, value); + } + + @Override + public String toString() { + return string().toString(); + } + + protected ToStringHelper string() { + return Objects.toStringHelper("").add("dimensions", dimensions).add("metricName", metricName).add( + "statisticValues", statisticValues).add("timestamp", timestamp).add("unit", unit).add("value", value); + } } diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/StatisticSet.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/StatisticValues.java similarity index 79% rename from apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/StatisticSet.java rename to apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/StatisticValues.java index 82674dbf87..d0e235f9b5 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/StatisticSet.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/StatisticValues.java @@ -25,14 +25,14 @@ import org.jclouds.javax.annotation.Nullable; * * @author Jeremy Whitlock */ -public class StatisticSet { +public class StatisticValues { - private final Double maximum; - private final Double minimum; - private final Double sampleCount; - private final Double sum; + private final double maximum; + private final double minimum; + private final double sampleCount; + private final double sum; - public StatisticSet(Double maximum, Double minimum, Double sampleCount, Double sum) { + public StatisticValues(double maximum, double minimum, double sampleCount, double sum) { this.maximum = maximum; this.minimum = minimum; this.sampleCount = sampleCount; @@ -43,7 +43,7 @@ public class StatisticSet { * return the maximum value of the sample set */ @Nullable - public Double getMaximum() { + public double getMaximum() { return maximum; } @@ -51,7 +51,7 @@ public class StatisticSet { * return the minimum value of the sample set */ @Nullable - public Double getMinimum() { + public double getMinimum() { return minimum; } @@ -59,7 +59,7 @@ public class StatisticSet { * return the number of samples used for the statistic set */ @Nullable - public Double getSampleCount() { + public double getSampleCount() { return sampleCount; } @@ -67,7 +67,7 @@ public class StatisticSet { * return the sum of values for the sample set */ @Nullable - public Double getSum() { + public double getSum() { return sum; } @@ -81,14 +81,14 @@ public class StatisticSet { public static class Builder { - private Double maximum; - private Double minimum; - private Double sampleCount; - private Double sum; + private double maximum; + private double minimum; + private double sampleCount; + private double sum; /** * Creates a new builder. The returned builder is equivalent to the builder - * generated by {@link org.jclouds.cloudwatch.domain.StatisticSet#builder}. + * generated by {@link org.jclouds.cloudwatch.domain.StatisticValues#builder}. */ public Builder() {} @@ -99,7 +99,7 @@ public class StatisticSet { * * @return this {@code Builder} object */ - public Builder maximum(Double maximum) { + public Builder maximum(double maximum) { this.maximum = maximum; return this; } @@ -111,7 +111,7 @@ public class StatisticSet { * * @return this {@code Builder} object */ - public Builder minimum(Double minimum) { + public Builder minimum(double minimum) { this.minimum = minimum; return this; } @@ -123,7 +123,7 @@ public class StatisticSet { * * @return this {@code Builder} object */ - public Builder sampleCount(Double sampleCount) { + public Builder sampleCount(double sampleCount) { this.sampleCount = sampleCount; return this; } @@ -135,7 +135,7 @@ public class StatisticSet { * * @return this {@code Builder} object */ - public Builder sum(Double sum) { + public Builder sum(double sum) { this.sum = sum; return this; } @@ -143,8 +143,8 @@ public class StatisticSet { /** * Returns a newly-created {@code StatisticSet} based on the contents of the {@code Builder}. */ - public StatisticSet build() { - return new StatisticSet(maximum, minimum, sampleCount, sum); + public StatisticValues build() { + return new StatisticValues(maximum, minimum, sampleCount, sum); } } diff --git a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/binders/MetricDataBinderTest.java b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/binders/MetricDataBinderTest.java index 0b79702422..554deab5ca 100644 --- a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/binders/MetricDataBinderTest.java +++ b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/binders/MetricDataBinderTest.java @@ -24,7 +24,7 @@ import com.google.inject.Injector; import junit.framework.Assert; import org.jclouds.cloudwatch.domain.Dimension; import org.jclouds.cloudwatch.domain.MetricDatum; -import org.jclouds.cloudwatch.domain.StatisticSet; +import org.jclouds.cloudwatch.domain.StatisticValues; import org.jclouds.cloudwatch.domain.Unit; import org.jclouds.http.HttpRequest; import org.testng.annotations.Test; @@ -37,28 +37,33 @@ import java.util.Date; * * @author Jeremy Whitlock */ -@Test(groups = "unit") +@Test(groups = "unit", testName = "MetricDataBinderTest") public class MetricDataBinderTest { Injector injector = Guice.createInjector(); MetricDataBinder binder = injector.getInstance(MetricDataBinder.class); - HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build(); + + HttpRequest request() { + return HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build(); + } public void testMetricWithoutTimestamp() throws Exception { - StatisticSet ss = StatisticSet.builder() + StatisticValues ss = StatisticValues.builder() .maximum(4.0) .minimum(1.0) .sampleCount(4.0) .sum(10.0) .build(); + MetricDatum metricDatum = MetricDatum.builder() .metricName("TestMetricName") - .statisticSet(ss) + .statisticValues(ss) .dimension(new Dimension("TestDimension", "FAKE")) .unit(Unit.COUNT) + .value(2) .build(); - request = binder.bindToRequest(request, ImmutableSet.of(metricDatum)); + HttpRequest request = binder.bindToRequest(request(), ImmutableSet.of(metricDatum)); Assert.assertEquals(request.getPayload().getRawContent(), "MetricData.member.1.Dimensions.member.1.Name=TestDimension" + @@ -68,7 +73,8 @@ 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.Unit=" + Unit.COUNT.toString() + + "&MetricData.member.1.Value=2.0"); } public void testMetricWithMultipleDimensions() throws Exception { @@ -81,7 +87,7 @@ public class MetricDataBinderTest { .value(5.0) .build(); - request = binder.bindToRequest(request, ImmutableSet.of(metricDatum)); + HttpRequest request = binder.bindToRequest(request(), ImmutableSet.of(metricDatum)); Assert.assertEquals(request.getPayload().getRawContent(), "MetricData.member.1.Dimensions.member.1.Name=TestDimension" + @@ -95,7 +101,7 @@ public class MetricDataBinderTest { } public void testMetricWithMultipleDatum() throws Exception { - StatisticSet ss = StatisticSet.builder() + StatisticValues ss = StatisticValues.builder() .maximum(4.0) .minimum(1.0) .sampleCount(4.0) @@ -103,11 +109,12 @@ public class MetricDataBinderTest { .build(); MetricDatum metricDatum = MetricDatum.builder() .metricName("TestMetricName") - .statisticSet(ss) + .statisticValues(ss) .dimension(new Dimension("TestDimension", "FAKE")) .dimension(new Dimension("TestDimension2", "FAKE2")) .unit(Unit.COUNT) .timestamp(new Date(10000000l)) + .value(2.0) .build(); MetricDatum metricDatum2 = MetricDatum.builder() .metricName("TestMetricName") @@ -117,7 +124,7 @@ public class MetricDataBinderTest { .value(5.0) .build(); - request = binder.bindToRequest(request, ImmutableSet.of(metricDatum, metricDatum2)); + HttpRequest request = binder.bindToRequest(request(), ImmutableSet.of(metricDatum, metricDatum2)); Assert.assertEquals(request.getPayload().getRawContent(), "MetricData.member.1.Dimensions.member.1.Name=TestDimension" + @@ -131,6 +138,7 @@ public class MetricDataBinderTest { "&MetricData.member.1.StatisticValues.Sum=10.0" + "&MetricData.member.1.Timestamp=1970-01-01T02%3A46%3A40Z" + "&MetricData.member.1.Unit=" + Unit.COUNT.toString() + + "&MetricData.member.1.Value=2.0" + "&MetricData.member.2.Dimensions.member.1.Name=TestDimension" + "&MetricData.member.2.Dimensions.member.1.Value=FAKE" + "&MetricData.member.2.MetricName=TestMetricName" + diff --git a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/features/MetricClientLiveTest.java b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/features/MetricClientLiveTest.java index 4d340598dd..e582f8ff49 100644 --- a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/features/MetricClientLiveTest.java +++ b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/features/MetricClientLiveTest.java @@ -31,7 +31,7 @@ import org.jclouds.cloudwatch.domain.ListMetricsResponse; import org.jclouds.cloudwatch.domain.Metric; import org.jclouds.cloudwatch.domain.MetricDatum; import org.jclouds.cloudwatch.domain.Namespaces; -import org.jclouds.cloudwatch.domain.StatisticSet; +import org.jclouds.cloudwatch.domain.StatisticValues; import org.jclouds.cloudwatch.domain.Statistics; import org.jclouds.cloudwatch.domain.Unit; import org.jclouds.cloudwatch.internal.BaseCloudWatchClientLiveTest; @@ -61,7 +61,7 @@ public class MetricClientLiveTest extends BaseCloudWatchClientLiveTest { // CloudWatch rounds metric timestamps down to the closest minute Date metricTimestampInCloudWatch = new Date(metricTimestamp.getTime() - (metricTimestamp.getTime() % (60 * 1000))); - StatisticSet ss = StatisticSet.builder() + StatisticValues ss = StatisticValues.builder() .maximum(4.0) .minimum(1.0) .sampleCount(4.0) @@ -69,7 +69,7 @@ public class MetricClientLiveTest extends BaseCloudWatchClientLiveTest { .build(); MetricDatum metricDatum = MetricDatum.builder() .metricName(metricName + "_1") - .statisticSet(ss) + .statisticValues(ss) .dimension(new Dimension("BaseMetricName", metricName)) .dimension(new Dimension("TestDimension2", "TEST2")) .unit(Unit.COUNT)