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

Commit

Permalink
Merge pull request #1558 from whitlockjc/master
Browse files Browse the repository at this point in the history
Complete CloudWatch API by adding Alarm APIs
  • Loading branch information
Adrian Cole committed Apr 24, 2013
2 parents 3ec6313 + e490579 commit 20763b7
Show file tree
Hide file tree
Showing 49 changed files with 4,168 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@

import java.util.List;

import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import org.jclouds.cloudwatch.domain.Metric;
import org.jclouds.cloudwatch.domain.MetricDatum;
import org.jclouds.cloudwatch.features.MetricApi;
import org.jclouds.cloudwatch.options.ListMetricsOptions;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterables;

import com.google.common.base.Function;
import com.google.common.collect.Iterables;

/**
* Utilities for using CloudWatch.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
import java.io.Closeable;
import java.util.Set;

import com.google.inject.Provides;
import org.jclouds.cloudwatch.features.AlarmApi;
import org.jclouds.cloudwatch.features.MetricApi;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Region;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam;

import com.google.inject.Provides;
/**
* Provides access to Amazon CloudWatch via the Query API
* <p/>
Expand Down Expand Up @@ -58,4 +58,16 @@ public interface CloudWatchApi extends Closeable {
*/
@Delegate
MetricApi getMetricApiForRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);

/**
* Provides synchronous access to Alarm features.
*/
@Delegate
AlarmApi getAlarmApi();

/**
* Provides synchronous access to Alarm features.
*/
@Delegate
AlarmApi getAlarmApiForRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
import java.net.URI;
import java.util.Properties;

import com.google.common.reflect.TypeToken;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.cloudwatch.config.CloudWatchRestClientModule;
import org.jclouds.rest.internal.BaseRestApiMetadata;

import com.google.common.reflect.TypeToken;

/**
* Implementation of {@link ApiMetadata} for Amazon's CloudWatch api.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
import java.io.Closeable;
import java.util.Set;

import com.google.inject.Provides;
import org.jclouds.cloudwatch.features.AlarmAsyncApi;
import org.jclouds.cloudwatch.features.MetricAsyncApi;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Region;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam;

import com.google.inject.Provides;

/**
* Provides access to Amazon CloudWatch via the Query API
* <p/>
Expand Down Expand Up @@ -57,7 +57,21 @@ public interface CloudWatchAsyncApi extends Closeable {
@Delegate
MetricAsyncApi getMetricApi();

/**
* Provides asynchronous access to Metric features.
*/
@Delegate
MetricAsyncApi getMetricApiForRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);

/**
* Provides asynchronous access to Alarm features.
*/
@Delegate
AlarmAsyncApi getAlarmApi();

/**
* Provides asynchronous access to Metric features.
*/
@Delegate
AlarmAsyncApi getAlarmApiForRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudwatch.binders;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableMultimap;
import org.jclouds.http.HttpRequest;

/**
* Binds the alarm names request to the http request
*
* @author Jeremy Whitlock
*/
@Beta
public class AlarmNamesBinder implements org.jclouds.rest.Binder {

@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
Iterable<String> alarmNames = (Iterable<String>) checkNotNull(input, "alarm names must be set");
ImmutableMultimap.Builder<String, String> formParameters = ImmutableMultimap.builder();
int alarmNameIndex = 1;

for (String alarmName : alarmNames) {
formParameters.put("AlarmNames.member." + alarmNameIndex, alarmName);
alarmNameIndex++;
}

return (R) request.toBuilder().replaceFormParams(formParameters.build()).build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,23 @@
*/
package org.jclouds.cloudwatch.config;

import static org.jclouds.reflect.Reflection2.typeToken;

import java.util.Map;

import com.google.common.collect.ImmutableMap;
import org.jclouds.aws.config.FormSigningRestClientModule;
import org.jclouds.cloudwatch.CloudWatchApi;
import org.jclouds.cloudwatch.CloudWatchAsyncApi;
import org.jclouds.cloudwatch.features.AlarmApi;
import org.jclouds.cloudwatch.features.AlarmAsyncApi;
import org.jclouds.cloudwatch.features.MetricApi;
import org.jclouds.cloudwatch.features.MetricAsyncApi;
import org.jclouds.cloudwatch.handlers.CloudWatchErrorHandler;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.rest.ConfiguresRestClient;

import com.google.common.collect.ImmutableMap;
import java.util.Map;

import static org.jclouds.reflect.Reflection2.typeToken;

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

public CloudWatchRestClientModule() {
super(typeToken(CloudWatchApi.class), typeToken(CloudWatchAsyncApi.class), DELEGATE_MAP);
}

@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(CloudWatchErrorHandler.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(CloudWatchErrorHandler.class);
}

}
Loading

0 comments on commit 20763b7

Please sign in to comment.