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

com.elastisys.scale.cloudpool.aws.commons.functions.InstanceStateToMachineState Maven / Gradle / Ivy

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

import com.amazonaws.services.ec2.model.InstanceState;
import com.elastisys.scale.cloudpool.api.types.Machine;
import com.elastisys.scale.cloudpool.api.types.MachineState;
import com.google.common.base.Function;

/**
 * {@link Function} that translates an EC2 API instance state representation to
 * its corresponding {@link Machine} state representation.
 *
 *
 *
 */
public class InstanceStateToMachineState implements
		Function {

	/**
	 * Convert an {@link InstanceState} to a {@link MachineState}.
	 *
	 * @see com.google.common.base.Function#apply(java.lang.Object)
	 */
	@Override
	public MachineState apply(InstanceState state) {
		switch (state.getName()) {
		case "pending":
			return MachineState.PENDING;
		case "running":
			return MachineState.RUNNING;
		case "shutting-down":
			return MachineState.TERMINATING;
		case "terminated":
			return MachineState.TERMINATED;
		case "stopping":
			return MachineState.TERMINATING;
		case "stopped":
			return MachineState.TERMINATED;
		default:
			throw new IllegalArgumentException(String.format(
					"failed to translate unrecognized instance state '%s'",
					state.getName()));
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy