mirror of https://github.com/apache/jclouds.git
fixed CloudWatch.putMetricData
This commit is contained in:
parent
884e0d867e
commit
84de4b30db
|
@ -18,16 +18,17 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudwatch;
|
package org.jclouds.cloudwatch;
|
||||||
|
|
||||||
import com.google.common.collect.AbstractIterator;
|
import java.util.Iterator;
|
||||||
import com.google.common.collect.Sets;
|
import java.util.List;
|
||||||
|
|
||||||
import org.jclouds.cloudwatch.domain.ListMetricsResponse;
|
import org.jclouds.cloudwatch.domain.ListMetricsResponse;
|
||||||
import org.jclouds.cloudwatch.domain.Metric;
|
import org.jclouds.cloudwatch.domain.Metric;
|
||||||
import org.jclouds.cloudwatch.domain.MetricDatum;
|
import org.jclouds.cloudwatch.domain.MetricDatum;
|
||||||
import org.jclouds.cloudwatch.features.MetricClient;
|
import org.jclouds.cloudwatch.features.MetricClient;
|
||||||
import org.jclouds.cloudwatch.options.ListMetricsOptions;
|
import org.jclouds.cloudwatch.options.ListMetricsOptions;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import com.google.common.collect.AbstractIterator;
|
||||||
import java.util.Set;
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities for using CloudWatch.
|
* Utilities for using CloudWatch.
|
||||||
|
@ -109,20 +110,9 @@ public class CloudWatch {
|
||||||
public static void putMetricData(CloudWatchClient cloudWatchClient, String region, Iterable<MetricDatum> metrics,
|
public static void putMetricData(CloudWatchClient cloudWatchClient, String region, Iterable<MetricDatum> metrics,
|
||||||
String namespace) {
|
String namespace) {
|
||||||
MetricClient metricClient = cloudWatchClient.getMetricClientForRegion(region);
|
MetricClient metricClient = cloudWatchClient.getMetricClientForRegion(region);
|
||||||
Iterator<MetricDatum> mIterator = metrics.iterator();
|
|
||||||
Set<MetricDatum> metricsData = Sets.newLinkedHashSet();
|
|
||||||
|
|
||||||
while (mIterator.hasNext()) {
|
for (List<MetricDatum> slice : Iterables.partition(metrics, 10)) {
|
||||||
metricsData.add(mIterator.next());
|
metricClient.putMetricData(slice, namespace);
|
||||||
if (metricsData.size() == 10 || !mIterator.hasNext()) {
|
|
||||||
// Make the call
|
|
||||||
metricClient.putMetricData(metrics, namespace);
|
|
||||||
|
|
||||||
// Reset the list for subsequent call if necessary
|
|
||||||
if (mIterator.hasNext()) {
|
|
||||||
metricsData = Sets.newLinkedHashSet();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,13 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudwatch;
|
package org.jclouds.cloudwatch;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import static org.easymock.EasyMock.anyObject;
|
||||||
import com.google.common.collect.Iterables;
|
import static org.easymock.EasyMock.createMock;
|
||||||
import com.google.common.collect.Sets;
|
import static org.easymock.EasyMock.expect;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.easymock.EasyMock;
|
import org.easymock.EasyMock;
|
||||||
import org.jclouds.cloudwatch.domain.ListMetricsResponse;
|
import org.jclouds.cloudwatch.domain.ListMetricsResponse;
|
||||||
import org.jclouds.cloudwatch.domain.Metric;
|
import org.jclouds.cloudwatch.domain.Metric;
|
||||||
|
@ -30,18 +34,16 @@ import org.jclouds.cloudwatch.options.ListMetricsOptions;
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import java.util.Set;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import static org.easymock.EasyMock.anyObject;
|
import com.google.common.collect.Sets;
|
||||||
import static org.easymock.EasyMock.createMock;
|
|
||||||
import static org.easymock.EasyMock.expect;
|
|
||||||
import static org.easymock.EasyMock.expectLastCall;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of {@code CloudWatch}.
|
* Tests behavior of {@code CloudWatch}.
|
||||||
*
|
*
|
||||||
* @author Jeremy Whitlock
|
* @author Jeremy Whitlock
|
||||||
*/
|
*/
|
||||||
|
@Test(testName = "CloudWatchTest")
|
||||||
public class CloudWatchTest {
|
public class CloudWatchTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,7 +117,7 @@ public class CloudWatchTest {
|
||||||
String namespace = "JCLOUDS/Test";
|
String namespace = "JCLOUDS/Test";
|
||||||
|
|
||||||
for (int i = 0; i < 11; i++) {
|
for (int i = 0; i < 11; i++) {
|
||||||
metrics.add(MetricDatum.builder().build());
|
metrics.add(MetricDatum.builder().metricName("foo").build());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Using EasyMock.eq("") because EasyMock makes it impossible to pass null as a String value here
|
// Using EasyMock.eq("") because EasyMock makes it impossible to pass null as a String value here
|
||||||
|
@ -123,10 +125,9 @@ public class CloudWatchTest {
|
||||||
.andReturn(metricClient)
|
.andReturn(metricClient)
|
||||||
.atLeastOnce();
|
.atLeastOnce();
|
||||||
|
|
||||||
|
for (List<MetricDatum> slice : Iterables.partition(metrics, 10)) {
|
||||||
metricClient.putMetricData(metrics, namespace);
|
metricClient.putMetricData(slice, namespace);
|
||||||
|
}
|
||||||
expectLastCall().times(2);
|
|
||||||
|
|
||||||
EasyMock.replay(client, metricClient);
|
EasyMock.replay(client, metricClient);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue