本文整理汇总了Java中com.amazonaws.services.ec2.model.InstanceState.getName方法的典型用法代码示例。如果您正苦于以下问题:Java InstanceState.getName方法的具体用法?Java InstanceState.getName怎么用?Java InstanceState.getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.ec2.model.InstanceState
的用法示例。
在下文中一共展示了InstanceState.getName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import com.amazonaws.services.ec2.model.InstanceState; //导入方法依赖的package包/类
/**
* 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()));
}
}
示例2: ec2StateToLifecycleState
import com.amazonaws.services.ec2.model.InstanceState; //导入方法依赖的package包/类
private static LifecycleState ec2StateToLifecycleState(InstanceState state) {
switch (state.getName()) {
case "pending":
return LifecycleState.Pending;
case "running":
return LifecycleState.InService;
case "shutting-down":
return LifecycleState.Terminating;
case "terminated":
return LifecycleState.Terminated;
case "stopping":
return LifecycleState.Terminating;
case "stopped":
return LifecycleState.Terminated;
default:
throw new IllegalArgumentException(String.format("unrecognized instance state: '%s'", state));
}
}
示例3: getMachineState
import com.amazonaws.services.ec2.model.InstanceState; //导入方法依赖的package包/类
private MachineState getMachineState(Instance instance) {
InstanceState state = instance.getState();
String stateName = state.getName();
if (stateName.equals("running")) {
return STARTED;
} else if (stateName.equals("pending")) {
return STARTING;
} else if (stateName.equals("shutting-down")) {
return STOPPING;
} else if (stateName.equals("terminated")) {
return STOPPED;
} else if (stateName.equals("stopped")) {
return STARTED; // we dont need to create a new state as workflow dont support this
} else {
throw new IllegalStateException("State " + stateName + " is not known");
}
}
示例4: startInstance
import com.amazonaws.services.ec2.model.InstanceState; //导入方法依赖的package包/类
@Override
public void startInstance(String ec2InstanceId) throws InterruptedException {
Instance instance = getSingleEc2InstanceById(ec2InstanceId);
InstanceState state = instance.getState();
// different possible states: pending, running, shutting-down,
// terminated, stopping, stopped
String stateName = state.getName();
if (stateName.equalsIgnoreCase("pending")) {
log.info("startInstance: instance with id= " + ec2InstanceId
+ " state is pending, no action was taken.");
} else if (stateName.equalsIgnoreCase("running")) {
log.info("startInstance: instance with id= " + ec2InstanceId
+ " state is running, no action was taken.");
} else if (stateName.equalsIgnoreCase("shutting-down")) {
log.info("startInstance: instance with id= " + ec2InstanceId
+ " state is shutting-down, no action was taken.");
// TODO maybe we should wait for the instance to shutdown before
// starting it again.. ?
} else if (stateName.equalsIgnoreCase("terminated")) {
log.info("startInstance: instance with id= " + ec2InstanceId
+ " state is terminated, no action was taken.");
// TODO throw error ?
} else if (stateName.equalsIgnoreCase("stopping")) {
log.info("startInstance: instance with id= " + ec2InstanceId
+ " state is stopping, no action was taken.");
// TODO maybe we should wait for the instance to stop before
// starting it again.. ? what is the difference between
// shutting-down and stopping ??
} else if (stateName.equalsIgnoreCase("stopped")) {
log.info("startInstance: instance with id= "
+ ec2InstanceId
+ " state is stopped, the instance has been asked to start...");
StartInstancesRequest startRequest = new StartInstancesRequest()
.withInstanceIds(ec2InstanceId);
StartInstancesResult startResult = config.getAmazonEC2Client()
.startInstances(startRequest);
List<InstanceStateChange> stateChangeList = startResult
.getStartingInstances();
waitForTransitionCompletion(stateChangeList, "running",
ec2InstanceId);
}
}