All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.elastisys.scale.cloudpool.aws.commons.predicates.AutoScalingPredicates Maven / Gradle / Ivy

There is a newer version: 5.2.3
Show newest version
package com.elastisys.scale.cloudpool.aws.commons.predicates;

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

import com.amazonaws.services.autoscaling.model.AutoScalingGroup;
import com.amazonaws.services.ec2.model.Instance;
import com.google.common.base.Predicate;

/**
 * A factory class for {@link Predicate}s relating to the Amazon Auto Scaling
 * API.
 */
public class AutoScalingPredicates {

	private AutoScalingPredicates() {
		throw new UnsupportedOperationException("cannot instantiate");
	}

	/**
	 * Returns a {@link Predicate} that returns true for any EC2
	 * {@link Instance} with a given instance identifier.
	 *
	 * @param instanceId
	 *            The instance identifier to match {@link Instance}s against.
	 * @return
	 */
	public static Predicate autoScalingGroupSize(
			int expectedSize) {
		return new AutoScalingGroupSizePredicate(expectedSize);
	}

	/**
	 * A {@link Predicate} that returns true for an
	 * {@link AutoScalingGroup} that has an expected size.
	 */
	public static class AutoScalingGroupSizePredicate implements
			Predicate {
		private final int expectedSize;

		public AutoScalingGroupSizePredicate(int expectedSize) {
			checkArgument(expectedSize >= 0,
					"expected group size cannot be negative");
			this.expectedSize = expectedSize;
		}

		@Override
		public boolean apply(AutoScalingGroup autoScalingGroup) {
			return autoScalingGroup.getInstances().size() == this.expectedSize;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy