mirror of https://github.com/apache/jclouds.git
addressed nullables
This commit is contained in:
parent
84de4b30db
commit
cd08ce98cc
|
@ -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 extends HttpRequest> R bindToRequest(R request, Object payload) {
|
||||
GetMetricStatistics getRequest = GetMetricStatistics.class.cast(payload);
|
||||
Set<Dimension> dimensions = getRequest.getDimensions() != null ?
|
||||
getRequest.getDimensions() :
|
||||
new HashSet<Dimension>();
|
||||
Set<Statistics> statistics = getRequest.getStatistics() != null ?
|
||||
getRequest.getStatistics() :
|
||||
new HashSet<Statistics>();
|
||||
GetMetricStatistics getRequest = GetMetricStatistics.class.cast(checkNotNull(payload,
|
||||
"GetMetricStatistics must be set!"));
|
||||
int dimensionIndex = 1;
|
||||
int statisticIndex = 1;
|
||||
ImmutableMultimap.Builder<String, String> 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());
|
||||
|
|
|
@ -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 extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||
Iterable<MetricDatum> metrics = input != null ?
|
||||
(Iterable<MetricDatum>)input :
|
||||
new HashSet<MetricDatum>();
|
||||
Iterable<MetricDatum> metrics = (Iterable<MetricDatum>) checkNotNull(input, "metrics must be set!");
|
||||
|
||||
ImmutableMultimap.Builder<String, String> formParameters = ImmutableMultimap.builder();
|
||||
int metricDatumIndex = 1;
|
||||
|
||||
for (MetricDatum metricDatum : metrics) {
|
||||
int dimensionIndex = 1;
|
||||
StatisticSet statisticSet = metricDatum.getStatisticSet();
|
||||
Set<Dimension> dimensions = metricDatum.getDimensions() != null ?
|
||||
metricDatum.getDimensions() :
|
||||
new HashSet<Dimension>();
|
||||
|
||||
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()));
|
||||
}
|
||||
if (metricDatum.getTimestamp() != null) {
|
||||
formParameters.put("MetricData.member." + metricDatumIndex + ".Timestamp",
|
||||
dateService.iso8601SecondsDateFormat(metricDatum.getTimestamp()));
|
||||
String.valueOf(statisticValues.getSum()));
|
||||
}
|
||||
|
||||
if (metricDatum.getTimestamp().isPresent()) {
|
||||
formParameters.put("MetricData.member." + metricDatumIndex + ".Timestamp",
|
||||
dateService.iso8601SecondsDateFormat(metricDatum.getTimestamp().get()));
|
||||
}
|
||||
|
||||
if (metricDatum.getUnit() != null) {
|
||||
formParameters.put("MetricData.member." + metricDatumIndex + ".Unit",
|
||||
String.valueOf(metricDatum.getUnit()));
|
||||
}
|
||||
|
||||
if (metricDatum.getValue() != null) {
|
||||
formParameters.put("MetricData.member." + metricDatumIndex + ".Value",
|
||||
String.valueOf(metricDatum.getValue()));
|
||||
}
|
||||
|
||||
metricDatumIndex++;
|
||||
}
|
||||
|
|
|
@ -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<Dimension> dimensions;
|
||||
private final Date endTime;
|
||||
private final Optional<Date> endTime;
|
||||
private final String metricName;
|
||||
private final String namespace;
|
||||
private final int period;
|
||||
private final Date startTime;
|
||||
private final Optional<Date> startTime;
|
||||
private final Set<Statistics> statistics;
|
||||
private final Unit unit;
|
||||
private final Optional<Unit> unit;
|
||||
|
||||
/**
|
||||
* Private constructor to enforce using {@link Builder}.
|
||||
*/
|
||||
private GetMetricStatistics(Set<Dimension> dimensions, Date endTime, String metricName, String namespace, int period,
|
||||
protected GetMetricStatistics(Set<Dimension> dimensions, Date endTime, String metricName, String namespace, int period,
|
||||
Date startTime, Set<Statistics> statistics, Unit unit) {
|
||||
this.dimensions = dimensions;
|
||||
this.endTime = endTime;
|
||||
this.metricName = metricName;
|
||||
this.namespace = namespace;
|
||||
this.dimensions = ImmutableSet.<Dimension>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.<Statistics>copyOf(checkNotNull(statistics, "statistics"));
|
||||
this.unit = Optional.fromNullable(unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* return the set of dimensions for this request
|
||||
*/
|
||||
@Nullable
|
||||
public Set<Dimension> getDimensions() {
|
||||
return dimensions;
|
||||
}
|
||||
|
@ -71,15 +74,13 @@ public class GetMetricStatistics {
|
|||
/**
|
||||
* return the end time for this request
|
||||
*/
|
||||
@Nullable
|
||||
public Date getEndTime() {
|
||||
public Optional<Date> 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<Date> getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the statistics for this request
|
||||
*/
|
||||
@Nullable
|
||||
public Set<Statistics> getStatistics() {
|
||||
return statistics;
|
||||
}
|
||||
|
@ -119,8 +116,7 @@ public class GetMetricStatistics {
|
|||
/**
|
||||
* return the unit for this request
|
||||
*/
|
||||
@Nullable
|
||||
public Unit getUnit() {
|
||||
public Optional<Unit> getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
|
@ -134,13 +130,15 @@ public class GetMetricStatistics {
|
|||
|
||||
public static class Builder {
|
||||
|
||||
private Set<Dimension> dimensions;
|
||||
// this builder is set to be additive on dimension calls, so make this mutable
|
||||
private Set<Dimension> 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> statistics;
|
||||
// this builder is set to be additive on dimension calls, so make this mutable
|
||||
private Set<Statistics> statistics = Sets.newLinkedHashSet();
|
||||
private Unit unit;
|
||||
|
||||
/**
|
||||
|
@ -157,7 +155,7 @@ public class GetMetricStatistics {
|
|||
* @return this {@code Builder} object
|
||||
*/
|
||||
public Builder dimensions(Set<Dimension> 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> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <a href="http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html" />
|
||||
*
|
||||
|
@ -33,28 +39,27 @@ public class MetricDatum {
|
|||
|
||||
private final Set<Dimension> dimensions;
|
||||
private final String metricName;
|
||||
private final StatisticSet statisticSet;
|
||||
private final Date timestamp;
|
||||
private final Optional<StatisticValues> statisticValues;
|
||||
private final Optional<Date> timestamp;
|
||||
private final Unit unit;
|
||||
private final Double value;
|
||||
private final double value;
|
||||
|
||||
/**
|
||||
* Private constructor to enforce using {@link Builder}.
|
||||
*/
|
||||
private MetricDatum(Set<Dimension> 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<Dimension> dimensions, String metricName, StatisticValues statisticValues, Date timestamp,
|
||||
Unit unit, 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.unit = checkNotNull(unit, "unit");
|
||||
this.value = checkNotNull(value, "value");
|
||||
}
|
||||
|
||||
/**
|
||||
* return the list of dimensions describing the the metric.
|
||||
*/
|
||||
@Nullable
|
||||
public Set<Dimension> 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<StatisticValues> getStatisticValues() {
|
||||
return statisticValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the time stamp used for the metric
|
||||
*/
|
||||
@Nullable
|
||||
public Date getTimestamp() {
|
||||
public Optional<Date> 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<Dimension> dimensions;
|
||||
// this builder is set to be additive on dimension calls, so make this mutable
|
||||
private Set<Dimension> 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<Dimension> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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" +
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue