本文整理汇总了Java中com.amazonaws.services.ec2.model.InstanceState.getCode方法的典型用法代码示例。如果您正苦于以下问题:Java InstanceState.getCode方法的具体用法?Java InstanceState.getCode怎么用?Java InstanceState.getCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.ec2.model.InstanceState
的用法示例。
在下文中一共展示了InstanceState.getCode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isRunningOrPending
import com.amazonaws.services.ec2.model.InstanceState; //导入方法依赖的package包/类
private boolean isRunningOrPending(InstanceState state) {
boolean ret = false;
if (state != null) {
ret = state.getCode() == 0 || state.getCode() == 16; //0 - pending. 16 -- running
}
return ret;
}
示例2: mapToPowerState
import com.amazonaws.services.ec2.model.InstanceState; //导入方法依赖的package包/类
/**
* Maps the Aws machine state to {@link PowerState}
*
* @param state
* @return the {@link PowerState} of the machine
*/
public static PowerState mapToPowerState(InstanceState state) {
PowerState powerState = PowerState.UNKNOWN;
switch (state.getCode()) {
case 16:
powerState = PowerState.ON;
break;
case 80:
powerState = PowerState.OFF;
break;
default:
break;
}
return powerState;
}
示例3: terminateInstance
import com.amazonaws.services.ec2.model.InstanceState; //导入方法依赖的package包/类
/**
* Terminates the specified instance.
*
* @param instanceId Id of the instance to terminate
*/
public boolean terminateInstance(final String instanceId) {
TerminateInstancesRequest terminateRequest = new TerminateInstancesRequest();
terminateRequest.withInstanceIds(instanceId);
if(client == null){
throw new RuntimeException("The client is not initialized");
}
TerminateInstancesResult result = client.terminateInstances(terminateRequest);
List<InstanceStateChange> stateChanges = result.getTerminatingInstances();
boolean terminatedInstance = false;
for (InstanceStateChange stateChange : stateChanges) {
if (instanceId.equals(stateChange.getInstanceId())) {
terminatedInstance = true;
InstanceState currentState = stateChange.getCurrentState();
if (currentState.getCode() != 32 && currentState.getCode() != 48) {
log.error(String.format(
"Machine state for id %s should be terminated (48) or shutting down (32) but was %s instead",
instanceId, currentState.getCode()));
return false;
}
}
}
if (!terminatedInstance) {
log.error("Matching terminated instance was not found for instance " + instanceId);
return false;
}
return true;
}