
software.amazon.awssdk.services.opsworks.model.AutoScalingThresholds Maven / Gradle / Ivy
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file 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 software.amazon.awssdk.services.opsworks.model;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Function;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.ListTrait;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.SdkAutoConstructList;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* Describes a load-based auto scaling upscaling or downscaling threshold configuration, which specifies when AWS
* OpsWorks Stacks starts or stops load-based instances.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class AutoScalingThresholds implements SdkPojo, Serializable,
ToCopyableBuilder {
private static final SdkField INSTANCE_COUNT_FIELD = SdkField. builder(MarshallingType.INTEGER)
.memberName("InstanceCount").getter(getter(AutoScalingThresholds::instanceCount))
.setter(setter(Builder::instanceCount))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("InstanceCount").build()).build();
private static final SdkField THRESHOLDS_WAIT_TIME_FIELD = SdkField. builder(MarshallingType.INTEGER)
.memberName("ThresholdsWaitTime").getter(getter(AutoScalingThresholds::thresholdsWaitTime))
.setter(setter(Builder::thresholdsWaitTime))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ThresholdsWaitTime").build())
.build();
private static final SdkField IGNORE_METRICS_TIME_FIELD = SdkField. builder(MarshallingType.INTEGER)
.memberName("IgnoreMetricsTime").getter(getter(AutoScalingThresholds::ignoreMetricsTime))
.setter(setter(Builder::ignoreMetricsTime))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("IgnoreMetricsTime").build()).build();
private static final SdkField CPU_THRESHOLD_FIELD = SdkField. builder(MarshallingType.DOUBLE)
.memberName("CpuThreshold").getter(getter(AutoScalingThresholds::cpuThreshold)).setter(setter(Builder::cpuThreshold))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("CpuThreshold").build()).build();
private static final SdkField MEMORY_THRESHOLD_FIELD = SdkField. builder(MarshallingType.DOUBLE)
.memberName("MemoryThreshold").getter(getter(AutoScalingThresholds::memoryThreshold))
.setter(setter(Builder::memoryThreshold))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("MemoryThreshold").build()).build();
private static final SdkField LOAD_THRESHOLD_FIELD = SdkField. builder(MarshallingType.DOUBLE)
.memberName("LoadThreshold").getter(getter(AutoScalingThresholds::loadThreshold))
.setter(setter(Builder::loadThreshold))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("LoadThreshold").build()).build();
private static final SdkField> ALARMS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("Alarms")
.getter(getter(AutoScalingThresholds::alarms))
.setter(setter(Builder::alarms))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Alarms").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.STRING)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(INSTANCE_COUNT_FIELD,
THRESHOLDS_WAIT_TIME_FIELD, IGNORE_METRICS_TIME_FIELD, CPU_THRESHOLD_FIELD, MEMORY_THRESHOLD_FIELD,
LOAD_THRESHOLD_FIELD, ALARMS_FIELD));
private static final long serialVersionUID = 1L;
private final Integer instanceCount;
private final Integer thresholdsWaitTime;
private final Integer ignoreMetricsTime;
private final Double cpuThreshold;
private final Double memoryThreshold;
private final Double loadThreshold;
private final List alarms;
private AutoScalingThresholds(BuilderImpl builder) {
this.instanceCount = builder.instanceCount;
this.thresholdsWaitTime = builder.thresholdsWaitTime;
this.ignoreMetricsTime = builder.ignoreMetricsTime;
this.cpuThreshold = builder.cpuThreshold;
this.memoryThreshold = builder.memoryThreshold;
this.loadThreshold = builder.loadThreshold;
this.alarms = builder.alarms;
}
/**
*
* The number of instances to add or remove when the load exceeds a threshold.
*
*
* @return The number of instances to add or remove when the load exceeds a threshold.
*/
public final Integer instanceCount() {
return instanceCount;
}
/**
*
* The amount of time, in minutes, that the load must exceed a threshold before more instances are added or removed.
*
*
* @return The amount of time, in minutes, that the load must exceed a threshold before more instances are added or
* removed.
*/
public final Integer thresholdsWaitTime() {
return thresholdsWaitTime;
}
/**
*
* The amount of time (in minutes) after a scaling event occurs that AWS OpsWorks Stacks should ignore metrics and
* suppress additional scaling events. For example, AWS OpsWorks Stacks adds new instances following an upscaling
* event but the instances won't start reducing the load until they have been booted and configured. There is no
* point in raising additional scaling events during that operation, which typically takes several minutes.
* IgnoreMetricsTime
allows you to direct AWS OpsWorks Stacks to suppress scaling events long enough to
* get the new instances online.
*
*
* @return The amount of time (in minutes) after a scaling event occurs that AWS OpsWorks Stacks should ignore
* metrics and suppress additional scaling events. For example, AWS OpsWorks Stacks adds new instances
* following an upscaling event but the instances won't start reducing the load until they have been booted
* and configured. There is no point in raising additional scaling events during that operation, which
* typically takes several minutes. IgnoreMetricsTime
allows you to direct AWS OpsWorks Stacks
* to suppress scaling events long enough to get the new instances online.
*/
public final Integer ignoreMetricsTime() {
return ignoreMetricsTime;
}
/**
*
* The CPU utilization threshold, as a percent of the available CPU. A value of -1 disables the threshold.
*
*
* @return The CPU utilization threshold, as a percent of the available CPU. A value of -1 disables the threshold.
*/
public final Double cpuThreshold() {
return cpuThreshold;
}
/**
*
* The memory utilization threshold, as a percent of the available memory. A value of -1 disables the threshold.
*
*
* @return The memory utilization threshold, as a percent of the available memory. A value of -1 disables the
* threshold.
*/
public final Double memoryThreshold() {
return memoryThreshold;
}
/**
*
* The load threshold. A value of -1 disables the threshold. For more information about how load is computed, see Load (computing).
*
*
* @return The load threshold. A value of -1 disables the threshold. For more information about how load is
* computed, see Load (computing).
*/
public final Double loadThreshold() {
return loadThreshold;
}
/**
* For responses, this returns true if the service returned a value for the Alarms property. This DOES NOT check
* that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is
* useful because the SDK will never return a null collection or map, but you may need to differentiate between the
* service returning nothing (or null) and the service returning an empty collection or map. For requests, this
* returns true if a value for the property was specified in the request builder, and false if a value was not
* specified.
*/
public final boolean hasAlarms() {
return alarms != null && !(alarms instanceof SdkAutoConstructList);
}
/**
*
* Custom Cloudwatch auto scaling alarms, to be used as thresholds. This parameter takes a list of up to five alarm
* names, which are case sensitive and must be in the same region as the stack.
*
*
*
* To use custom alarms, you must update your service role to allow cloudwatch:DescribeAlarms
. You can
* either have AWS OpsWorks Stacks update the role for you when you first use this feature or you can edit the role
* manually. For more information, see Allowing AWS
* OpsWorks Stacks to Act on Your Behalf.
*
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasAlarms} method.
*
*
* @return Custom Cloudwatch auto scaling alarms, to be used as thresholds. This parameter takes a list of up to
* five alarm names, which are case sensitive and must be in the same region as the stack.
*
* To use custom alarms, you must update your service role to allow cloudwatch:DescribeAlarms
.
* You can either have AWS OpsWorks Stacks update the role for you when you first use this feature or you
* can edit the role manually. For more information, see Allowing
* AWS OpsWorks Stacks to Act on Your Behalf.
*
*/
public final List alarms() {
return alarms;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class extends Builder> serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public final int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(instanceCount());
hashCode = 31 * hashCode + Objects.hashCode(thresholdsWaitTime());
hashCode = 31 * hashCode + Objects.hashCode(ignoreMetricsTime());
hashCode = 31 * hashCode + Objects.hashCode(cpuThreshold());
hashCode = 31 * hashCode + Objects.hashCode(memoryThreshold());
hashCode = 31 * hashCode + Objects.hashCode(loadThreshold());
hashCode = 31 * hashCode + Objects.hashCode(hasAlarms() ? alarms() : null);
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof AutoScalingThresholds)) {
return false;
}
AutoScalingThresholds other = (AutoScalingThresholds) obj;
return Objects.equals(instanceCount(), other.instanceCount())
&& Objects.equals(thresholdsWaitTime(), other.thresholdsWaitTime())
&& Objects.equals(ignoreMetricsTime(), other.ignoreMetricsTime())
&& Objects.equals(cpuThreshold(), other.cpuThreshold())
&& Objects.equals(memoryThreshold(), other.memoryThreshold())
&& Objects.equals(loadThreshold(), other.loadThreshold()) && hasAlarms() == other.hasAlarms()
&& Objects.equals(alarms(), other.alarms());
}
/**
* Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
* redacted from this string using a placeholder value.
*/
@Override
public final String toString() {
return ToString.builder("AutoScalingThresholds").add("InstanceCount", instanceCount())
.add("ThresholdsWaitTime", thresholdsWaitTime()).add("IgnoreMetricsTime", ignoreMetricsTime())
.add("CpuThreshold", cpuThreshold()).add("MemoryThreshold", memoryThreshold())
.add("LoadThreshold", loadThreshold()).add("Alarms", hasAlarms() ? alarms() : null).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "InstanceCount":
return Optional.ofNullable(clazz.cast(instanceCount()));
case "ThresholdsWaitTime":
return Optional.ofNullable(clazz.cast(thresholdsWaitTime()));
case "IgnoreMetricsTime":
return Optional.ofNullable(clazz.cast(ignoreMetricsTime()));
case "CpuThreshold":
return Optional.ofNullable(clazz.cast(cpuThreshold()));
case "MemoryThreshold":
return Optional.ofNullable(clazz.cast(memoryThreshold()));
case "LoadThreshold":
return Optional.ofNullable(clazz.cast(loadThreshold()));
case "Alarms":
return Optional.ofNullable(clazz.cast(alarms()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function