/** * List metrics based on the criteria in the {@link ListMetricsOptions} passed in. * * @param cloudWatchApi the {@link CloudWatchApi} to use for the request * @param region the region to list metrics in * @param options the options describing the ListMetrics request * * @return iterable of metrics fitting the criteria */ public static Iterable<Metric> listMetrics(CloudWatchApi cloudWatchApi, String region, final ListMetricsOptions options) { return listMetrics(cloudWatchApi.getMetricApiForRegion(region), options); }
/** * List metrics based on the criteria in the {@link ListMetricsOptions} passed in. * * @param cloudWatchApi the {@link CloudWatchApi} to use for the request * @param region the region to list metrics in * @param options the options describing the ListMetrics request * * @return iterable of metrics fitting the criteria */ public static Iterable<Metric> listMetrics(CloudWatchApi cloudWatchApi, String region, final ListMetricsOptions options) { return listMetrics(cloudWatchApi.getMetricApiForRegion(region), options); }
/** * List metrics based on the criteria in the {@link ListMetricsOptions} passed in. * * @param cloudWatchApi the {@link CloudWatchApi} to use for the request * @param region the region to list metrics in * @param options the options describing the ListMetrics request * * @return iterable of metrics fitting the criteria */ public static Iterable<Metric> listMetrics(CloudWatchApi cloudWatchApi, String region, final ListMetricsOptions options) { return listMetrics(cloudWatchApi.getMetricApiForRegion(region), options); }
/** * List metrics based on the criteria in the {@link ListMetricsOptions} passed in. * * @param cloudWatchApi the {@link CloudWatchApi} to use for the request * @param region the region to list metrics in * @param options the options describing the ListMetrics request * * @return iterable of metrics fitting the criteria */ public static Iterable<Metric> listMetrics(CloudWatchApi cloudWatchApi, String region, final ListMetricsOptions options) { return listMetrics(cloudWatchApi.getMetricApiForRegion(region), options); }
/** * List metrics based on the criteria in the {@link ListMetricsOptions} passed in. * * @param cloudWatchApi the {@link CloudWatchApi} to use for the request * @param region the region to list metrics in * @param options the options describing the ListMetrics request * * @return iterable of metrics fitting the criteria */ public static Iterable<Metric> listMetrics(CloudWatchApi cloudWatchApi, String region, final ListMetricsOptions options) { return listMetrics(cloudWatchApi.getMetricApiForRegion(region), options); }
/** * List metrics based on the criteria in the {@link ListMetricsOptions} passed in. * * @param cloudWatchApi the {@link CloudWatchApi} to use for the request * @param region the region to list metrics in * @param options the options describing the ListMetrics request * * @return iterable of metrics fitting the criteria */ public static Iterable<Metric> listMetrics(CloudWatchApi cloudWatchApi, String region, final ListMetricsOptions options) { return listMetrics(cloudWatchApi.getMetricApiForRegion(region), options); }
public boolean apply(ListMetricsOptions options) { return Iterables.size(CloudWatch.listMetrics(api, null, options)) == 11; } }, 20, 1, MINUTES).apply(lmo);
public boolean apply(ListMetricsOptions options) { return Iterables.size(CloudWatch.listMetrics(api, null, options)) == 11; } }, 20, 1, MINUTES).apply(lmo);
/** * Returns the count of metrics stored for the given nodeId and region. * * @param cloudWatchClient the cloud watch client (Will use MetricsClient when Issue 922 is fixed) * @param region the region the instance is in * @param nodeId the instance id * * @return the total count of metrics stored for the given instance id and region */ private static int getMetricsCountForInstance(CloudWatchClient cloudWatchClient, String region, String nodeId) { // Uses CloudWatchClient+region instead of MetricsClient because the pagination helper only works with // CloudWatchClient: http://code.google.com/p/jclouds/issues/detail?id=922 return Iterators.size(CloudWatch.listMetrics(cloudWatchClient, region, ListMetricsOptions.builder() // Only return metrics for the given instance .dimension(new Dimension( EC2Constants.Dimension.INSTANCE_ID, nodeId)) .build()).iterator()); }
/** * Tests {@link CloudWatch#listMetrics(CloudWatchApi, String, org.jclouds.cloudwatch.options.ListMetricsOptions)} * where a single response returns all results. * * @throws Exception if anything goes wrong */ @Test public void testSinglePageResult() throws Exception { CloudWatchApi api = createMock(CloudWatchApi.class); MetricApi metricApi = createMock(MetricApi.class); ListMetricsOptions options = new ListMetricsOptions(); IterableWithMarker<Metric> response = IterableWithMarkers.from(ImmutableSet.of(createMock(Metric.class)), null); expect(api.getMetricApiForRegion(null)) .andReturn(metricApi) .atLeastOnce(); expect(metricApi.list(options)) .andReturn(response) .once(); EasyMock.replay(api, metricApi); Assert.assertEquals(1, Iterables.size(CloudWatch.listMetrics(api, null, options))); }
/** * Tests {@link CloudWatch#listMetrics(CloudWatchApi, String, org.jclouds.cloudwatch.options.ListMetricsOptions)} * where a single response returns all results. * * @throws Exception if anything goes wrong */ @Test public void testSinglePageResult() throws Exception { CloudWatchApi api = createMock(CloudWatchApi.class); MetricApi metricApi = createMock(MetricApi.class); ListMetricsOptions options = new ListMetricsOptions(); IterableWithMarker<Metric> response = IterableWithMarkers.from(ImmutableSet.of(createMock(Metric.class)), null); expect(api.getMetricApiForRegion(null)) .andReturn(metricApi) .atLeastOnce(); expect(metricApi.list(options)) .andReturn(response) .once(); EasyMock.replay(api, metricApi); Assert.assertEquals(1, Iterables.size(CloudWatch.listMetrics(api, null, options))); }
/** * Tests {@link CloudWatch#listMetrics(CloudWatchApi, String, org.jclouds.cloudwatch.options.ListMetricsOptions)} * where retrieving all results requires multiple requests. * * @throws Exception if anything goes wrong */ @Test public void testMultiPageResult() throws Exception { CloudWatchApi api = createMock(CloudWatchApi.class); MetricApi metricApi = createMock(MetricApi.class); ListMetricsOptions options = new ListMetricsOptions(); IterableWithMarker<Metric> response1 = IterableWithMarkers.from(ImmutableSet.of(createMock(Metric.class)), "NEXTTOKEN"); IterableWithMarker<Metric> response2 = IterableWithMarkers.from(ImmutableSet.of(createMock(Metric.class)), null); // Using EasyMock.eq("") because EasyMock makes it impossible to pass null as a String value here expect(api.getMetricApiForRegion(EasyMock.eq(""))) .andReturn(metricApi) .atLeastOnce(); expect(metricApi.list(anyObject(ListMetricsOptions.class))) .andReturn(response1) .once(); expect(metricApi.list(anyObject(ListMetricsOptions.class))) .andReturn(response2) .once(); EasyMock.replay(api, metricApi); Assert.assertEquals(2, Iterables.size(CloudWatch.listMetrics(api, "", options))); }
/** * Tests {@link CloudWatch#listMetrics(CloudWatchApi, String, org.jclouds.cloudwatch.options.ListMetricsOptions)} * where retrieving all results requires multiple requests. * * @throws Exception if anything goes wrong */ @Test public void testMultiPageResult() throws Exception { CloudWatchApi api = createMock(CloudWatchApi.class); MetricApi metricApi = createMock(MetricApi.class); ListMetricsOptions options = new ListMetricsOptions(); IterableWithMarker<Metric> response1 = IterableWithMarkers.from(ImmutableSet.of(createMock(Metric.class)), "NEXTTOKEN"); IterableWithMarker<Metric> response2 = IterableWithMarkers.from(ImmutableSet.of(createMock(Metric.class)), null); // Using EasyMock.eq("") because EasyMock makes it impossible to pass null as a String value here expect(api.getMetricApiForRegion(EasyMock.eq(""))) .andReturn(metricApi) .atLeastOnce(); expect(metricApi.list(anyObject(ListMetricsOptions.class))) .andReturn(response1) .once(); expect(metricApi.list(anyObject(ListMetricsOptions.class))) .andReturn(response2) .once(); EasyMock.replay(api, metricApi); Assert.assertEquals(2, Iterables.size(CloudWatch.listMetrics(api, "", options))); }