Skip to content
Permalink
Browse files
JCLOUDS-1598: Support Metric Alert Operation (#134)
  • Loading branch information
SATYANAN-ANAND committed Feb 25, 2022
1 parent 99f2ff8 commit 83deb0efef180f75c05d291e4a03d45d59bd0bce
Showing 15 changed files with 1,096 additions and 0 deletions.
@@ -31,6 +31,7 @@
import org.jclouds.azurecompute.arm.features.LoadBalancerApi;
import org.jclouds.azurecompute.arm.features.LocalNetworkGatewayApi;
import org.jclouds.azurecompute.arm.features.LocationApi;
import org.jclouds.azurecompute.arm.features.MetricAlertApi;
import org.jclouds.azurecompute.arm.features.MetricDefinitionsApi;
import org.jclouds.azurecompute.arm.features.MetricsApi;
import org.jclouds.azurecompute.arm.features.NetworkInterfaceCardApi;
@@ -315,4 +316,14 @@ NetworkSecurityRuleApi getNetworkSecurityRuleApi(@PathParam("resourcegroup") Str
*/
@Delegate
AlertApi getAlertApi(@PathParam("resourceid") String resourceid);

/**
* The Metric Alert API includes operations to get insights available for
* entities within your subscription
*
* @see <a href=
* "https://docs.microsoft.com/en-us/rest/api/monitor/metric-alerts">docs</a>
*/
@Delegate
MetricAlertApi getMetricAlertApi(@PathParam("resourcegroup") String resourcegroup);
}
@@ -49,6 +49,7 @@
import org.jclouds.azurecompute.arm.features.LoadBalancerApi;
import org.jclouds.azurecompute.arm.features.LocalNetworkGatewayApi;
import org.jclouds.azurecompute.arm.features.LocationApi;
import org.jclouds.azurecompute.arm.features.MetricAlertApi;
import org.jclouds.azurecompute.arm.features.MetricDefinitionsApi;
import org.jclouds.azurecompute.arm.features.MetricsApi;
import org.jclouds.azurecompute.arm.features.NetworkInterfaceCardApi;
@@ -140,6 +141,7 @@ public static Properties defaultProperties() {
properties.put(API_VERSION_PREFIX + VirtualNetworkGatewayConnectionApi.class.getSimpleName(), "2018-02-01");
properties.put(API_VERSION_PREFIX + ActivityLogAlertApi.class.getSimpleName(), "2020-10-01");
properties.put(API_VERSION_PREFIX + AlertApi.class.getSimpleName(), "2019-03-01");
properties.put(API_VERSION_PREFIX + MetricAlertApi.class.getSimpleName(), "2018-03-01");

return properties;
}
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.azurecompute.arm.domain;

import java.util.List;

import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;

import com.google.auto.value.AutoValue;

@AutoValue
public abstract class Criteria {

@Nullable
public abstract List<MetricAlertCriteria> allOf();

@Nullable
public abstract String odatatype();

@SerializedNames({ "allOf", "odata.type" })
public static Criteria create(final List<MetricAlertCriteria> allOf,
final String odatatype) {
return builder().allOf(allOf).odatatype(odatatype).build();
}

public abstract Builder toBuilder();

public static Builder builder() {
return new AutoValue_Criteria.Builder();
}

@AutoValue.Builder
public abstract static class Builder {

public abstract Builder allOf(List<MetricAlertCriteria> allOf);

public abstract Builder odatatype(String odatatype);

public abstract Criteria build();
}
}
@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.azurecompute.arm.domain;

import org.jclouds.json.SerializedNames;

import com.google.auto.value.AutoValue;

@AutoValue
public abstract class DynamicThresholdFailingPeriods {

public abstract int minFailingPeriodsToAlert();

public abstract int numberOfEvaluationPeriods();

@SerializedNames({ "minFailingPeriodsToAlert", "numberOfEvaluationPeriods" })
public static DynamicThresholdFailingPeriods create(final int minFailingPeriodsToAlert,
final int numberOfEvaluationPeriods) {
return new AutoValue_DynamicThresholdFailingPeriods(minFailingPeriodsToAlert, numberOfEvaluationPeriods);

}

}
@@ -0,0 +1,91 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.azurecompute.arm.domain;

import java.util.Map;

import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;

import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableMap;

@AutoValue
public abstract class MetricAlert {

/**
* The id of the resource
*/
public abstract String id();

/**
* The name of the resource
*/
public abstract String name();

/**
* The location of the resource
*/
public abstract String location();

/**
* The type of the resource
*/
public abstract String type();

@Nullable
public abstract Map<String, String> tags();

@Nullable
public abstract MetricAlertProperties properties();

@SerializedNames({ "id", "name", "location", "type", "tags", "properties" })
public static MetricAlert create(final String id, final String name, final String location,
final String type, final Map<String, String> tags, final MetricAlertProperties properties) {
return builder().id(id).name(name).location(location).type(type).tags(tags).properties(properties).build();
}

public abstract Builder toBuilder();

public static Builder builder() {
return new AutoValue_MetricAlert.Builder();
}

@AutoValue.Builder
public abstract static class Builder {
public abstract Builder id(String id);

public abstract Builder name(String name);

public abstract Builder location(String location);

public abstract Builder type(String type);

public abstract Builder tags(Map<String, String> tags);

public abstract Builder properties(MetricAlertProperties properties);

abstract Map<String, String> tags();

abstract MetricAlert autoBuild();

public MetricAlert build() {
tags(tags() != null ? ImmutableMap.copyOf(tags()) : null);
return autoBuild();
}
}
}
@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.azurecompute.arm.domain;

import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;

import com.google.auto.value.AutoValue;

@AutoValue
public abstract class MetricAlertAction {
@Nullable
public abstract String actionGroupId();

@Nullable
public abstract Object webhookProperties();

@SerializedNames({ "actionGroupId", "webhookProperties" })
public static MetricAlertAction create(final String actionGroupId, final Object webhookProperties) {
return new AutoValue_MetricAlertAction(actionGroupId, webhookProperties);

}

}
@@ -0,0 +1,116 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.azurecompute.arm.domain;

import java.util.List;

import org.jclouds.azurecompute.arm.util.GetEnumValue;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;

import com.google.auto.value.AutoValue;

@AutoValue
public abstract class MetricAlertCriteria {

@Nullable
public abstract String criterionType();

@Nullable
public abstract List<MetricDimension> dimensions();

@Nullable
public abstract String metricName();

@Nullable
public abstract String metricNamespace();

@Nullable
public abstract String name();

@Nullable
public abstract Operator operator();

public abstract boolean skipMetricValidation();

public abstract int threshold();

@Nullable
public abstract AggregationTypeEnum timeAggregation();

@Nullable
public abstract DynamicThresholdSensitivity alertSensitivity();

@Nullable
public abstract DynamicThresholdFailingPeriods failingPeriods();

@Nullable
public abstract String ignoreDataBefore();

@Nullable
public abstract String componentId();

public abstract int failedLocationCount();

@Nullable
public abstract String webTestId();

@SerializedNames({ "criterionType", "dimensions", "metricName", "metricNamespace", "name", "operator",
"skipMetricValidation", "threshold", "timeAggregation", "alertSensitivity", "failingPeriods",
"ignoreDataBefore", "componentId", "failedLocationCount", "webTestId" })
public static MetricAlertCriteria create(final String criterionType, List<MetricDimension> dimensions,
final String metricName, final String metricNamespace, final String name, final Operator operator,
final boolean skipMetricValidation, final int threshold, final AggregationTypeEnum timeAggregation,
final DynamicThresholdSensitivity alertSensitivity, final DynamicThresholdFailingPeriods failingPeriods,
final String ignoreDataBefore, final String componentId, final int failedLocationCount,
final String webTestId) {
return new AutoValue_MetricAlertCriteria(criterionType, dimensions, metricName, metricNamespace, name, operator,
skipMetricValidation, threshold, timeAggregation, alertSensitivity, failingPeriods, ignoreDataBefore,
componentId, failedLocationCount, webTestId);

}

public enum AggregationTypeEnum {
Average, Count, Maximum, Minimum, Total;
public static AggregationTypeEnum fromValue(final String text) {
return (AggregationTypeEnum) GetEnumValue.fromValueOrDefault(text, AggregationTypeEnum.Average);
}
}

public enum Operator {
Equals, GreaterThan, GreaterThanOrEqual, LessThan, LessThanOrEqual, GreaterOrLessThan;
public static Operator fromValue(final String text) {
return (Operator) GetEnumValue.fromValueOrDefault(text, Operator.Equals);
}
}

public enum DynamicThresholdSensitivity {
High, Low, Medium;
public static DynamicThresholdSensitivity fromValue(final String text) {
return (DynamicThresholdSensitivity) GetEnumValue.fromValueOrDefault(text,
DynamicThresholdSensitivity.High);
}
}

public enum DynamicThresholdOperator {
GreaterOrLessThan, GreaterThan, LessThan;
public static DynamicThresholdOperator fromValue(final String text) {
return (DynamicThresholdOperator) GetEnumValue.fromValueOrDefault(text,
DynamicThresholdOperator.GreaterOrLessThan);
}
}
}

0 comments on commit 83deb0e

Please sign in to comment.