Skip to content
This repository was archived by the owner on Mar 25, 2018. It is now read-only.

Commit 20763b7

Browse files
author
Adrian Cole
committed
Merge pull request #1558 from whitlockjc/master
Complete CloudWatch API by adding Alarm APIs
2 parents 3ec6313 + e490579 commit 20763b7

File tree

49 files changed

+4168
-66
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+4168
-66
lines changed

apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatch.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@
2020

2121
import java.util.List;
2222

23+
import com.google.common.base.Function;
24+
import com.google.common.collect.Iterables;
2325
import org.jclouds.cloudwatch.domain.Metric;
2426
import org.jclouds.cloudwatch.domain.MetricDatum;
2527
import org.jclouds.cloudwatch.features.MetricApi;
2628
import org.jclouds.cloudwatch.options.ListMetricsOptions;
2729
import org.jclouds.collect.IterableWithMarker;
2830
import org.jclouds.collect.PagedIterables;
2931

30-
import com.google.common.base.Function;
31-
import com.google.common.collect.Iterables;
32-
3332
/**
3433
* Utilities for using CloudWatch.
3534
*

apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchApi.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
import java.io.Closeable;
2222
import java.util.Set;
2323

24+
import com.google.inject.Provides;
25+
import org.jclouds.cloudwatch.features.AlarmApi;
2426
import org.jclouds.cloudwatch.features.MetricApi;
2527
import org.jclouds.javax.annotation.Nullable;
2628
import org.jclouds.location.Region;
2729
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
2830
import org.jclouds.rest.annotations.Delegate;
2931
import org.jclouds.rest.annotations.EndpointParam;
30-
31-
import com.google.inject.Provides;
3232
/**
3333
* Provides access to Amazon CloudWatch via the Query API
3434
* <p/>
@@ -58,4 +58,16 @@ public interface CloudWatchApi extends Closeable {
5858
*/
5959
@Delegate
6060
MetricApi getMetricApiForRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
61+
62+
/**
63+
* Provides synchronous access to Alarm features.
64+
*/
65+
@Delegate
66+
AlarmApi getAlarmApi();
67+
68+
/**
69+
* Provides synchronous access to Alarm features.
70+
*/
71+
@Delegate
72+
AlarmApi getAlarmApiForRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
6173
}

apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchApiMetadata.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@
2424
import java.net.URI;
2525
import java.util.Properties;
2626

27+
import com.google.common.reflect.TypeToken;
2728
import org.jclouds.apis.ApiMetadata;
2829
import org.jclouds.cloudwatch.config.CloudWatchRestClientModule;
2930
import org.jclouds.rest.internal.BaseRestApiMetadata;
3031

31-
import com.google.common.reflect.TypeToken;
32-
3332
/**
3433
* Implementation of {@link ApiMetadata} for Amazon's CloudWatch api.
3534
*

apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchAsyncApi.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
import java.io.Closeable;
2222
import java.util.Set;
2323

24+
import com.google.inject.Provides;
25+
import org.jclouds.cloudwatch.features.AlarmAsyncApi;
2426
import org.jclouds.cloudwatch.features.MetricAsyncApi;
2527
import org.jclouds.javax.annotation.Nullable;
2628
import org.jclouds.location.Region;
2729
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
2830
import org.jclouds.rest.annotations.Delegate;
2931
import org.jclouds.rest.annotations.EndpointParam;
3032

31-
import com.google.inject.Provides;
32-
3333
/**
3434
* Provides access to Amazon CloudWatch via the Query API
3535
* <p/>
@@ -57,7 +57,21 @@ public interface CloudWatchAsyncApi extends Closeable {
5757
@Delegate
5858
MetricAsyncApi getMetricApi();
5959

60+
/**
61+
* Provides asynchronous access to Metric features.
62+
*/
6063
@Delegate
6164
MetricAsyncApi getMetricApiForRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
6265

66+
/**
67+
* Provides asynchronous access to Alarm features.
68+
*/
69+
@Delegate
70+
AlarmAsyncApi getAlarmApi();
71+
72+
/**
73+
* Provides asynchronous access to Metric features.
74+
*/
75+
@Delegate
76+
AlarmAsyncApi getAlarmApiForRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
6377
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Licensed to jclouds, Inc. (jclouds) under one or more
3+
* contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. jclouds licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.jclouds.cloudwatch.binders;
20+
21+
import static com.google.common.base.Preconditions.checkNotNull;
22+
23+
import com.google.common.annotations.Beta;
24+
import com.google.common.collect.ImmutableMultimap;
25+
import org.jclouds.http.HttpRequest;
26+
27+
/**
28+
* Binds the alarm names request to the http request
29+
*
30+
* @author Jeremy Whitlock
31+
*/
32+
@Beta
33+
public class AlarmNamesBinder implements org.jclouds.rest.Binder {
34+
35+
@SuppressWarnings("unchecked")
36+
@Override
37+
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
38+
Iterable<String> alarmNames = (Iterable<String>) checkNotNull(input, "alarm names must be set");
39+
ImmutableMultimap.Builder<String, String> formParameters = ImmutableMultimap.builder();
40+
int alarmNameIndex = 1;
41+
42+
for (String alarmName : alarmNames) {
43+
formParameters.put("AlarmNames.member." + alarmNameIndex, alarmName);
44+
alarmNameIndex++;
45+
}
46+
47+
return (R) request.toBuilder().replaceFormParams(formParameters.build()).build();
48+
}
49+
50+
}

apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/config/CloudWatchRestClientModule.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,23 @@
1818
*/
1919
package org.jclouds.cloudwatch.config;
2020

21-
import static org.jclouds.reflect.Reflection2.typeToken;
22-
23-
import java.util.Map;
24-
21+
import com.google.common.collect.ImmutableMap;
2522
import org.jclouds.aws.config.FormSigningRestClientModule;
2623
import org.jclouds.cloudwatch.CloudWatchApi;
2724
import org.jclouds.cloudwatch.CloudWatchAsyncApi;
25+
import org.jclouds.cloudwatch.features.AlarmApi;
26+
import org.jclouds.cloudwatch.features.AlarmAsyncApi;
2827
import org.jclouds.cloudwatch.features.MetricApi;
2928
import org.jclouds.cloudwatch.features.MetricAsyncApi;
29+
import org.jclouds.cloudwatch.handlers.CloudWatchErrorHandler;
30+
import org.jclouds.http.HttpErrorHandler;
31+
import org.jclouds.http.annotation.ClientError;
32+
import org.jclouds.http.annotation.ServerError;
3033
import org.jclouds.rest.ConfiguresRestClient;
3134

32-
import com.google.common.collect.ImmutableMap;
35+
import java.util.Map;
36+
37+
import static org.jclouds.reflect.Reflection2.typeToken;
3338

3439
/**
3540
* Configures the Monitoring connection.
@@ -40,10 +45,17 @@
4045
public class CloudWatchRestClientModule extends FormSigningRestClientModule<CloudWatchApi, CloudWatchAsyncApi> {
4146
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
4247
.put(MetricApi.class, MetricAsyncApi.class)
48+
.put(AlarmApi.class, AlarmAsyncApi.class)
4349
.build();
4450

4551
public CloudWatchRestClientModule() {
4652
super(typeToken(CloudWatchApi.class), typeToken(CloudWatchAsyncApi.class), DELEGATE_MAP);
4753
}
4854

55+
@Override
56+
protected void bindErrorHandlers() {
57+
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(CloudWatchErrorHandler.class);
58+
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(CloudWatchErrorHandler.class);
59+
}
60+
4961
}

0 commit comments

Comments
 (0)