![JAR search and dependency download from the Maven repository](/logo.png)
com.elastisys.scale.cloudpool.aws.commons.functions.InstanceStateToMachineState Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cloudpool.aws.commons Show documentation
Show all versions of cloudpool.aws.commons Show documentation
Common utility classes for building Amazon AWS-based cloud pools.
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