@@ -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);
}
diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchApiMetadata.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchApiMetadata.java
index 77495a8767..cf9aa43773 100644
--- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchApiMetadata.java
+++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchApiMetadata.java
@@ -24,12 +24,11 @@ import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG;
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.
*
diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchAsyncApi.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchAsyncApi.java
index eddb4b636e..ab0d447e38 100644
--- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchAsyncApi.java
+++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchAsyncApi.java
@@ -21,6 +21,8 @@ package org.jclouds.cloudwatch;
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;
@@ -28,8 +30,6 @@ 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
*
@@ -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);
}
diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/binders/AlarmNamesBinder.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/binders/AlarmNamesBinder.java
new file mode 100644
index 0000000000..c193da288a
--- /dev/null
+++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/binders/AlarmNamesBinder.java
@@ -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 bindToRequest(R request, Object input) {
+ Iterable alarmNames = (Iterable) checkNotNull(input, "alarm names must be set");
+ ImmutableMultimap.Builder 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();
+ }
+
+}
diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/config/CloudWatchRestClientModule.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/config/CloudWatchRestClientModule.java
index 8e34d9c55a..64a3369248 100644
--- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/config/CloudWatchRestClientModule.java
+++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/config/CloudWatchRestClientModule.java
@@ -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.
@@ -40,10 +45,17 @@ import com.google.common.collect.ImmutableMap;
public class CloudWatchRestClientModule extends FormSigningRestClientModule {
public static final Map, Class>> DELEGATE_MAP = ImmutableMap., 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);
+ }
+
}
diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/Alarm.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/Alarm.java
new file mode 100644
index 0000000000..5987c85667
--- /dev/null
+++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/Alarm.java
@@ -0,0 +1,329 @@
+/**
+ * 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.domain;
+
+import static com.google.common.base.Objects.equal;
+import static com.google.common.base.Objects.toStringHelper;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Date;
+import java.util.Set;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Objects;
+import com.google.common.base.Optional;
+
+/**
+ * @see
+ *
+ * @author Jeremy Whitlock
+ */
+@Beta
+public class Alarm {
+
+ public static enum State {
+ ALARM,
+ INSUFFICIENT_DATA,
+ OK,
+ UNRECOGNIZED;
+
+ public static State fromValue(String value) {
+ try {
+ return State.valueOf(checkNotNull(value, "value"));
+ } catch (IllegalArgumentException e) {
+ return UNRECOGNIZED;
+ }
+ }
+ }
+
+ private final boolean areActionsEnabled;
+ private final Set alarmActions;
+ private final String alarmARN;
+ private final Date alarmConfigurationUpdatedTimestamp;
+ private final String alarmDescription;
+ private final String alarmName;
+ private final ComparisonOperator comparisonOperator;
+ private final Set dimensions;
+ private final int evaluationPeriods;
+ private final Set insufficientDataActions;
+ private final String metricName;
+ private final String namespace;
+ private final Set okActions;
+ private final int period;
+ private final String stateReason;
+ private final Optional stateReasonData;
+ private final Date stateUpdatedTimestamp;
+ private final State state;
+ private final Statistics statistic;
+ private final double threshold;
+ private final Optional unit;
+
+ public Alarm(boolean areActionsEnabled, Set alarmActions, String alarmARN,
+ Date alarmConfigurationUpdatedTimestamp, String alarmDescription, String alarmName,
+ ComparisonOperator comparisonOperator, Set dimensions, int evaluationPeriods,
+ Set insufficientDataActions, String metricName, String namespace, Set okActions,
+ int period, String stateReason, Optional stateReasonData, Date stateUpdatedTimestamp,
+ State state, Statistics statistic, double threshold, Optional unit) {
+ this.alarmName = checkNotNull(alarmName, "alarmName");
+ this.areActionsEnabled = checkNotNull(areActionsEnabled, "actionsEnabled for %s", alarmName);
+ this.alarmActions = checkNotNull(alarmActions, "alarmActions for %s", alarmName);
+ this.alarmARN = checkNotNull(alarmARN, "alarmArn for %s", alarmName);
+ this.alarmConfigurationUpdatedTimestamp = checkNotNull(alarmConfigurationUpdatedTimestamp,
+ "alarmConfigurationUpdatedTimestamp for %s", alarmName);
+ this.alarmDescription = checkNotNull(alarmDescription, "alarmDescription for %s", alarmName);
+ this.comparisonOperator = checkNotNull(comparisonOperator, "comparisonOperator for %s", alarmName);
+ checkArgument(comparisonOperator != ComparisonOperator.UNRECOGNIZED, "comparisonOperator unrecognized");
+ this.dimensions = checkNotNull(dimensions, "dimensions for %s", alarmName);
+ this.evaluationPeriods = checkNotNull(evaluationPeriods, "evaluationPeriods for %s", alarmName);
+ this.insufficientDataActions = checkNotNull(insufficientDataActions, "insufficientDataActions for %s", alarmName);
+ this.metricName = checkNotNull(metricName, "metricName for %s", alarmName);
+ this.namespace = checkNotNull(namespace, "namespace for %s", alarmName);
+ this.okActions = checkNotNull(okActions, "okActions for %s", alarmName);
+ this.period = checkNotNull(period, "period for %s", alarmName);
+ this.stateReason = checkNotNull(stateReason, "stateReason for %s", alarmName);
+ this.stateReasonData = checkNotNull(stateReasonData, "stateReasonData for %s", alarmName);
+ this.stateUpdatedTimestamp = checkNotNull(stateUpdatedTimestamp, "stateUpdatedTimestamp for %s", alarmName);
+ this.state = checkNotNull(state, "state for %s", alarmName);
+ checkArgument(state != State.UNRECOGNIZED, "state unrecognized");
+ this.statistic = checkNotNull(statistic, "statistic for %s", alarmName);
+ checkArgument(statistic != Statistics.UNRECOGNIZED, "statistic unrecognized");
+ this.threshold = checkNotNull(threshold, "threshold for %s", alarmName);
+ this.unit = checkNotNull(unit, "unit for %s", alarmName);
+ if (unit.isPresent()) {
+ checkArgument(unit.get() != Unit.UNRECOGNIZED, "unit unrecognized");
+ }
+ }
+
+ /**
+ * return whether actions are enabled if the alarm state changes
+ */
+ public boolean areActionsEnabled() {
+ return areActionsEnabled;
+ }
+
+ /**
+ * return list of actions to perform when the alarm state changes to {@link org.jclouds.cloudwatch.domain.Alarm.State#ALARM} from any other state
+ */
+ public Set getAlarmActions() {
+ return alarmActions;
+ }
+
+ /**
+ * return the Amazon Resource Name (ARN) of the alarm
+ */
+ public String getAlarmARN() {
+ return alarmARN;
+ }
+
+ /**
+ * return the date timestamp of when the alarm was last updated
+ */
+ public Date getAlarmConfigurationUpdatedTimestamp() {
+ return alarmConfigurationUpdatedTimestamp;
+ }
+
+ /**
+ * return the description of the alarm
+ */
+ public String getAlarmDescription() {
+ return alarmDescription;
+ }
+
+ /**
+ * return the name of the alarm
+ */
+ public String getAlarmName() {
+ return alarmName;
+ }
+
+ /**
+ * return the arithmetic operation to use when comparing the specified statistic and threshold
+ */
+ public ComparisonOperator getComparisonOperator() {
+ return comparisonOperator;
+ }
+
+ /**
+ * return the list of dimensions associated with the alarm's associated metric
+ */
+ public Set getDimensions() {
+ return dimensions;
+ }
+
+ /**
+ * return the number of periods over which data is compared to the specified threshold
+ */
+ public int getEvaluationPeriods() {
+ return evaluationPeriods;
+ }
+
+ /**
+ * return the list of actions to execute when this alarm transitions into an {@link org.jclouds.cloudwatch.domain.Alarm.State#INSUFFICIENT_DATA} state
+ * from any other state
+ */
+ public Set getInsufficientDataActions() {
+ return insufficientDataActions;
+ }
+
+ /**
+ * return the name of the alarm's metric
+ */
+ public String getMetricName() {
+ return metricName;
+ }
+
+ /**
+ * return the namespace of alarm's associated metric
+ */
+ public String getNamespace() {
+ return namespace;
+ }
+
+ /**
+ * return the list of actions to execute when this alarm transitions into an {@link org.jclouds.cloudwatch.domain.Alarm.State#OK} state from any other
+ * state
+ */
+ public Set getOkActions() {
+ return okActions;
+ }
+
+ /**
+ * return the period in seconds over which the statistic is applied
+ */
+ public int getPeriod() {
+ return period;
+ }
+
+ /**
+ * return the human-readable explanation for the alarm's state
+ */
+ public String getStateReason() {
+ return stateReason;
+ }
+
+ /**
+ * return the explanation for the alarm's state in machine-readable JSON format
+ */
+ public Optional getStateReasonData() {
+ return stateReasonData;
+ }
+
+ /**
+ * return the time stamp of the last update to the alarm's state
+ */
+ public Date getStateUpdatedTimestamp() {
+ return stateUpdatedTimestamp;
+ }
+
+ /**
+ * return the state value for the alarm
+ */
+ public State getState() {
+ return state;
+ }
+
+ /**
+ * return the statistic to apply to the alarm's associated metric
+ */
+ public Statistics getStatistic() {
+ return statistic;
+ }
+
+ /**
+ * return the value against which the specified statistic is compared
+ */
+ public double getThreshold() {
+ return threshold;
+ }
+
+ /**
+ * return the unit of the alarm's associated metric
+ */
+ public Optional getUnit() {
+ return unit;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(alarmActions, alarmARN, alarmConfigurationUpdatedTimestamp, alarmDescription, alarmName,
+ areActionsEnabled, comparisonOperator, dimensions, evaluationPeriods,
+ insufficientDataActions, metricName, namespace, okActions, period, stateReason,
+ stateReasonData, stateUpdatedTimestamp, state, statistic, threshold, unit);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Alarm other = (Alarm) obj;
+ return equal(this.alarmActions, other.alarmActions) &&
+ equal(this.alarmARN, other.alarmARN) &&
+ equal(this.alarmConfigurationUpdatedTimestamp, other.alarmConfigurationUpdatedTimestamp) &&
+ equal(this.alarmDescription, other.alarmDescription) &&
+ equal(this.alarmName, other.alarmName) &&
+ equal(this.areActionsEnabled, other.areActionsEnabled) &&
+ equal(this.comparisonOperator, other.comparisonOperator) &&
+ equal(this.dimensions, other.dimensions) &&
+ equal(this.evaluationPeriods, other.evaluationPeriods) &&
+ equal(this.insufficientDataActions, other.insufficientDataActions) &&
+ equal(this.metricName, other.metricName) &&
+ equal(this.namespace, other.namespace) &&
+ equal(this.okActions, other.okActions) &&
+ equal(this.period, other.period) &&
+ equal(this.stateReason, other.stateReason) &&
+ equal(this.stateReasonData, other.stateReasonData) &&
+ equal(this.stateUpdatedTimestamp, other.stateUpdatedTimestamp) &&
+ equal(this.state, other.state) &&
+ equal(this.statistic, other.statistic) &&
+ equal(this.threshold, other.threshold) &&
+ equal(this.unit, other.unit);
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("alarmActions", alarmActions)
+ .add("alarmARN", alarmARN)
+ .add("alarmConfigurationUpdateTimestamp", alarmConfigurationUpdatedTimestamp)
+ .add("alarmDescription", alarmDescription)
+ .add("alarmName", alarmName)
+ .add("areActionsEnabled", areActionsEnabled)
+ .add("comparisonOperator", comparisonOperator)
+ .add("dimensions", dimensions)
+ .add("evaluationPeriods", evaluationPeriods)
+ .add("insufficientDataActions", insufficientDataActions)
+ .add("metricName", metricName)
+ .add("namespace", namespace)
+ .add("okActions", okActions)
+ .add("period", period)
+ .add("stateReason", stateReason)
+ .add("stateReasonData", stateReasonData.orNull())
+ .add("stateUpdatedTimestamp", stateUpdatedTimestamp)
+ .add("state", state)
+ .add("statistic", statistic)
+ .add("threshold", threshold)
+ .add("unit", unit.orNull()).toString();
+ }
+
+}
diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/AlarmHistoryItem.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/AlarmHistoryItem.java
new file mode 100644
index 0000000000..7e7ec7a03d
--- /dev/null
+++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/AlarmHistoryItem.java
@@ -0,0 +1,119 @@
+/**
+ * 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.domain;
+
+import static com.google.common.base.Objects.equal;
+import static com.google.common.base.Objects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Date;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Objects;
+
+/**
+ * @see
+ *
+ * @author Jeremy Whitlock
+ */
+@Beta
+public class AlarmHistoryItem {
+
+ private final String alarmName;
+ private final String historyData;
+ private final HistoryItemType historyItemType;
+ private final String historySummary;
+ private final Date timestamp;
+
+ public AlarmHistoryItem(String alarmName, String historyData, HistoryItemType historyItemType,
+ String historySummary, Date timestamp) {
+ this.alarmName = checkNotNull(alarmName, "alarmName");
+ this.historyData = checkNotNull(historyData, "historyData for %s", alarmName);
+ this.historyItemType = checkNotNull(historyItemType, "historyItemType for %s", alarmName);
+ this.historySummary = checkNotNull(historySummary, "historySummary for %s", alarmName);
+ this.timestamp = checkNotNull(timestamp, "timestamp for %s", alarmName);
+ }
+
+ /**
+ * return the descriptive name for the alarm
+ */
+ public String getAlarmName() {
+ return alarmName;
+ }
+
+ /**
+ * return the machine-readable data about the alarm in JSON format
+ */
+ public String getHistoryData() {
+ return historyData;
+ }
+
+ /**
+ * return the type of alarm history item
+ */
+ public HistoryItemType getHistoryItemType() {
+ return historyItemType;
+ }
+
+ /**
+ * return the human-readable summary of the alarm history
+ */
+ public String getHistorySummary() {
+ return historySummary;
+ }
+
+ /**
+ * return the time stamp for the alarm history item
+ */
+ public Date getTimestamp() {
+ return timestamp;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(alarmName, historyData, historyItemType, historySummary, timestamp);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ AlarmHistoryItem other = (AlarmHistoryItem) obj;
+ return equal(this.alarmName, other.alarmName) &&
+ equal(this.historyData, other.historyData) &&
+ equal(this.historyItemType, other.historyItemType) &&
+ equal(this.historySummary, other.historySummary) &&
+ equal(this.timestamp, other.timestamp);
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("alarmName", alarmName)
+ .add("historyData", historyData)
+ .add("historyItemType", historyItemType)
+ .add("historySummary", historySummary)
+ .add("timestamp", timestamp).toString();
+ }
+
+}
diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/ComparisonOperator.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/ComparisonOperator.java
new file mode 100644
index 0000000000..be79e00f6c
--- /dev/null
+++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/ComparisonOperator.java
@@ -0,0 +1,58 @@
+/**
+ * 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.domain;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.CaseFormat;
+
+/**
+ * @see
+ *
+ * @author Jeremy Whitlock
+ */
+@Beta
+public enum ComparisonOperator {
+
+ GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
+ GREATER_THAN_THRESHOLD,
+ LESS_THAN_THRESHOLD,
+ LESS_THAN_OR_EQUAL_TO_THRESHOLD,
+ UNRECOGNIZED;
+
+ public String value() {
+ return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
+ }
+
+ @Override
+ public String toString() {
+ return value();
+ }
+
+ public static ComparisonOperator fromValue(String value) {
+ try {
+ return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(value, "value")));
+
+ } catch (IllegalArgumentException e) {
+ return UNRECOGNIZED;
+ }
+ }
+
+}
diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/HistoryItemType.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/HistoryItemType.java
new file mode 100644
index 0000000000..c50e430431
--- /dev/null
+++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/HistoryItemType.java
@@ -0,0 +1,56 @@
+/**
+ * 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.domain;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.CaseFormat;
+
+/**
+ * @see
+ *
+ * @author Jeremy Whitlock
+ */
+@Beta
+public enum HistoryItemType {
+
+ CONFIGURATION_UPDATE,
+ STATE_UPDATE,
+ ACTION,
+ UNRECOGNIZED;
+
+ public String value() {
+ return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
+ }
+
+ @Override
+ public String toString() {
+ return value();
+ }
+
+ public static HistoryItemType fromValue(String value) {
+ try {
+ return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(value, "value")));
+ } catch (IllegalArgumentException e) {
+ return UNRECOGNIZED;
+ }
+ }
+
+}
diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/ListMetricsResponse.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/ListMetricsResponse.java
index 77e2810863..8fe416f8ee 100644
--- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/ListMetricsResponse.java
+++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/ListMetricsResponse.java
@@ -32,7 +32,7 @@ import com.google.common.collect.ImmutableSet;
*
* @author Jeremy Whitlock
*/
-public class ListMetricsResponse extends ForwardingSet{
+public class ListMetricsResponse extends ForwardingSet {
private final Set metrics;
private final String nextToken;
diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/Unit.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/Unit.java
index 5f936d2dc9..6b0f06b270 100644
--- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/Unit.java
+++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/Unit.java
@@ -66,10 +66,10 @@ public enum Unit {
return value();
}
- public static Unit fromValue(String state) {
+ public static Unit fromValue(String value) {
try {
- return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(state, "state").replace(
- "/", "_PER_")));
+ return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(value, "value").replace(
+ "/", "Per")));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/AlarmApi.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/AlarmApi.java
new file mode 100644
index 0000000000..103da3a7e9
--- /dev/null
+++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/AlarmApi.java
@@ -0,0 +1,142 @@
+/**
+ * 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.features;
+
+import com.google.common.annotations.Beta;
+import com.google.common.collect.FluentIterable;
+import org.jclouds.cloudwatch.domain.Alarm;
+import org.jclouds.cloudwatch.domain.AlarmHistoryItem;
+import org.jclouds.cloudwatch.options.ListAlarmHistoryOptions;
+import org.jclouds.cloudwatch.options.ListAlarmsForMetric;
+import org.jclouds.cloudwatch.options.ListAlarmsOptions;
+import org.jclouds.cloudwatch.options.SaveAlarmOptions;
+import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.PagedIterable;
+import org.jclouds.javax.annotation.Nullable;
+
+/**
+ * Provides access to Amazon CloudWatch via the Query API
+ *
+ *
+ * @see AlarmAsyncApi
+ * @see
+ * @author Jeremy Whitlock
+ */
+@Beta
+public interface AlarmApi {
+
+ /**
+ * Deletes all specified alarms.
+ *
+ *
+ *
Note
In the event of an error, no alarms are deleted.
+ *
+ * @param alarmNames the list of alarms to delete
+ */
+ void delete(Iterable alarmNames);
+
+ /**
+ * Return all history for all alarms.
+ *
+ * @return the response object
+ */
+ PagedIterable listHistory();
+
+ /**
+ * Return all history based on the options query
+ *
+ * @return the response object
+ */
+ PagedIterable listHistory(ListAlarmHistoryOptions options);
+
+ /**
+ * Return a single page of history for the specified alarm.
+ *
+ * @param nextToken the token corresponding with the data you want to get
+ *
+ * @return the response object
+ */
+ IterableWithMarker listHistoryAt(String nextToken);
+
+ /**
+ * Return all alarms.
+ *
+ * @return the response object
+ */
+ PagedIterable list();
+
+ /**
+ * Return all alarms based on the options query
+ *
+ * @param options the options describing the alarms query
+ *
+ * @return the response object
+ */
+ PagedIterable list(ListAlarmsOptions options);
+
+ /**
+ * Return a single page of alarms based on the options query
+ *
+ * @param nextToken the token corresponding with the data you want to get
+ *
+ * @return the response object
+ */
+ IterableWithMarker listAt(String nextToken);
+
+ /**
+ * Return alarms all alarms for a single metric.
+ *
+ * @param options the options describing the alarms for metric query
+ *
+ * @return the response object
+ */
+ FluentIterable listForMetric(ListAlarmsForMetric options);
+
+ /**
+ * Disables actions for the specified alarms.
+ *
+ * @param alarmNames the list of alarms to disable
+ */
+ void disable(Iterable alarmNames);
+
+ /**
+ * Enables actions for the specified alarms.
+ *
+ * @param alarmNames the list of alarms to enable
+ */
+ void enable(Iterable alarmNames);
+
+ /**
+ * Creates or updates an alarm and associates it with the specified Amazon CloudWatch metric.
+ *
+ * @param options the options describing the metric alarm to create/update
+ */
+ void save(SaveAlarmOptions options);
+
+ /**
+ * Temporarily sets the state of an alarm.
+ *
+ * @param alarmName the descriptive name for the alarm
+ * @param stateReason the reason that this alarm is set to this specific state (in human-readable text format)
+ * @param stateReasonData the reason that this alarm is set to this specific state (in machine-readable JSON format)
+ * @param state the value of the state
+ */
+ void setState(String alarmName, String stateReason, @Nullable String stateReasonData, Alarm.State state);
+
+}
diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/AlarmAsyncApi.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/AlarmAsyncApi.java
new file mode 100644
index 0000000000..5bdc4d0aa9
--- /dev/null
+++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/AlarmAsyncApi.java
@@ -0,0 +1,195 @@
+/**
+ * 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.features;
+
+import javax.inject.Named;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+
+import com.google.common.annotations.Beta;
+import com.google.common.collect.FluentIterable;
+import com.google.common.util.concurrent.ListenableFuture;
+import org.jclouds.Fallbacks;
+import org.jclouds.aws.filters.FormSigner;
+import org.jclouds.cloudwatch.binders.AlarmNamesBinder;
+import org.jclouds.cloudwatch.domain.Alarm;
+import org.jclouds.cloudwatch.domain.AlarmHistoryItem;
+import org.jclouds.cloudwatch.functions.ListAlarmsToPagedIterable;
+import org.jclouds.cloudwatch.options.ListAlarmHistoryOptions;
+import org.jclouds.cloudwatch.options.ListAlarmsForMetric;
+import org.jclouds.cloudwatch.options.ListAlarmsOptions;
+import org.jclouds.cloudwatch.options.SaveAlarmOptions;
+import org.jclouds.cloudwatch.xml.ListAlarmHistoryResponseHandler;
+import org.jclouds.cloudwatch.xml.ListAlarmsForMetricResponseHandler;
+import org.jclouds.cloudwatch.xml.ListAlarmsResponseHandler;
+import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.PagedIterable;
+import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.rest.annotations.BinderParam;
+import org.jclouds.rest.annotations.Fallback;
+import org.jclouds.rest.annotations.FormParams;
+import org.jclouds.rest.annotations.RequestFilters;
+import org.jclouds.rest.annotations.Transform;
+import org.jclouds.rest.annotations.VirtualHost;
+import org.jclouds.rest.annotations.XMLResponseParser;
+
+/**
+ * Provides access to Amazon CloudWatch via the Query API
+ *
+ *
+ * @see
+ * @author Jeremy Whitlock
+ */
+@RequestFilters(FormSigner.class)
+@VirtualHost
+@Beta
+public interface AlarmAsyncApi {
+
+ /**
+ * @see AlarmApi#delete(Iterable)
+ */
+ @Named("DeleteAlarms")
+ @POST
+ @Path("/")
+ @FormParams(keys = "Action", values = "DeleteAlarms")
+ ListenableFuture delete(@BinderParam(AlarmNamesBinder.class) Iterable alarmNames);
+
+ /**
+ * @see AlarmApi#listHistory()
+ */
+ @Named("DescribeAlarmHistory")
+ @POST
+ @Path("/")
+ @XMLResponseParser(ListAlarmHistoryResponseHandler.class)
+ @FormParams(keys = "Action", values = "DescribeAlarmHistory")
+ @Transform(ListAlarmsToPagedIterable.class)
+ @Fallback(Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404.class)
+ ListenableFuture extends PagedIterable> listHistory();
+
+ /**
+ * @see AlarmApi#listHistory(org.jclouds.cloudwatch.options.ListAlarmHistoryOptions)
+ */
+ @Named("DescribeAlarmHistory")
+ @POST
+ @Path("/")
+ @XMLResponseParser(ListAlarmHistoryResponseHandler.class)
+ @FormParams(keys = "Action", values = "DescribeAlarmHistory")
+ @Transform(ListAlarmsToPagedIterable.class)
+ @Fallback(Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404.class)
+ ListenableFuture extends PagedIterable> listHistory(ListAlarmHistoryOptions options);
+
+ /**
+ * @see AlarmApi#listHistoryAt(String)
+ */
+ @Named("DescribeAlarmHistory")
+ @POST
+ @Path("/")
+ @XMLResponseParser(ListAlarmHistoryResponseHandler.class)
+ @FormParams(keys = "Action", values = "DescribeAlarmHistory")
+ @Fallback(Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404.class)
+ ListenableFuture extends IterableWithMarker> listHistoryAt(@FormParam("NextToken")
+ String nextToken);
+
+ /**
+ * @see org.jclouds.cloudwatch.features.AlarmApi#list()
+ */
+ @Named("DescribeAlarms")
+ @POST
+ @Path("/")
+ @XMLResponseParser(ListAlarmsResponseHandler.class)
+ @FormParams(keys = "Action", values = "DescribeAlarms")
+ @Transform(ListAlarmsToPagedIterable.class)
+ @Fallback(Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404.class)
+ ListenableFuture extends PagedIterable> list();
+
+ /**
+ * @see AlarmApi#list(org.jclouds.cloudwatch.options.ListAlarmsOptions)
+ */
+ @Named("DescribeAlarms")
+ @POST
+ @Path("/")
+ @XMLResponseParser(ListAlarmsResponseHandler.class)
+ @FormParams(keys = "Action", values = "DescribeAlarms")
+ @Transform(ListAlarmsToPagedIterable.class)
+ @Fallback(Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404.class)
+ ListenableFuture extends PagedIterable> list(ListAlarmsOptions options);
+
+ /**
+ * @see AlarmApi#listAt(String)
+ */
+ @Named("DescribeAlarms")
+ @POST
+ @Path("/")
+ @XMLResponseParser(ListAlarmsResponseHandler.class)
+ @FormParams(keys = "Action", values = "DescribeAlarms")
+ @Fallback(Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404.class)
+ ListenableFuture extends IterableWithMarker> listAt(@FormParam("NextToken") String nextToken);
+
+ /**
+ * @see AlarmApi#listForMetric(org.jclouds.cloudwatch.options.ListAlarmsForMetric)
+ */
+ @Named("DescribeAlarmsForMetric")
+ @POST
+ @Path("/")
+ @XMLResponseParser(ListAlarmsForMetricResponseHandler.class)
+ @FormParams(keys = "Action", values = "DescribeAlarmsForMetric")
+ @Fallback(Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404.class)
+ ListenableFuture extends FluentIterable> listForMetric(ListAlarmsForMetric options);
+
+ /**
+ * @see AlarmApi#disable(Iterable)
+ */
+ @Named("DisableAlarmActions")
+ @POST
+ @Path("/")
+ @FormParams(keys = "Action", values = "DisableAlarmActions")
+ ListenableFuture disable(@BinderParam(AlarmNamesBinder.class) Iterable alarmNames);
+
+ /**
+ * @see AlarmApi#enable(Iterable)
+ */
+ @Named("EnableAlarmActions")
+ @POST
+ @Path("/")
+ @FormParams(keys = "Action", values = "EnableAlarmActions")
+ ListenableFuture enable(@BinderParam(AlarmNamesBinder.class) Iterable alarmNames);
+
+ /**
+ * @see AlarmApi#save(org.jclouds.cloudwatch.options.SaveAlarmOptions)
+ */
+ @Named("PutMetricAlarm")
+ @POST
+ @Path("/")
+ @FormParams(keys = "Action", values = "PutMetricAlarm")
+ ListenableFuture save(SaveAlarmOptions options);
+
+ /**
+ * @see AlarmApi#setState(String, String, String, org.jclouds.cloudwatch.domain.Alarm.State)
+ */
+ @Named("SetAlarmState")
+ @POST
+ @Path("/")
+ @FormParams(keys = "Action", values = "SetAlarmState")
+ ListenableFuture setState(@FormParam("AlarmName") String alarmName,
+ @FormParam("StateReason") String stateReason,
+ @FormParam("StateReasonData") @Nullable String stateReasonData,
+ @FormParam("StateValue") Alarm.State state);
+
+}
diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/functions/ListAlarmHistoryToPagedIterable.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/functions/ListAlarmHistoryToPagedIterable.java
new file mode 100644
index 0000000000..3e1b596c5d
--- /dev/null
+++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/functions/ListAlarmHistoryToPagedIterable.java
@@ -0,0 +1,63 @@
+/**
+ * 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.functions;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Function;
+import com.google.inject.Inject;
+import org.jclouds.cloudwatch.CloudWatchApi;
+import org.jclouds.cloudwatch.domain.AlarmHistoryItem;
+import org.jclouds.cloudwatch.features.AlarmApi;
+import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.internal.CallerArg0ToPagedIterable;
+
+/**
+ * @author Jeremy Whitlock
+ */
+@Beta
+public class ListAlarmHistoryToPagedIterable
+ extends CallerArg0ToPagedIterable {
+
+ private final CloudWatchApi api;
+
+ @Inject
+ ListAlarmHistoryToPagedIterable(CloudWatchApi api) {
+ this.api = checkNotNull(api, "api");
+ }
+
+ @Override
+ protected Function