本文整理汇总了Java中com.amazonaws.services.ec2.model.InstanceStateName类的典型用法代码示例。如果您正苦于以下问题:Java InstanceStateName类的具体用法?Java InstanceStateName怎么用?Java InstanceStateName使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InstanceStateName类属于com.amazonaws.services.ec2.model包,在下文中一共展示了InstanceStateName类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startInstances
import com.amazonaws.services.ec2.model.InstanceStateName; //导入依赖的package包/类
@Override
public StartInstancesResult startInstances(StartInstancesRequest startInstancesRequest) {
StartInstancesResult result = new StartInstancesResult();
if (startInstancesRequest.getInstanceIds().get(0).equals("test-1")) {
Collection<InstanceStateChange> coll = new ArrayList<InstanceStateChange>();
InstanceStateChange sc = new InstanceStateChange();
InstanceState previousState = new InstanceState();
previousState.setCode(80);
previousState.setName(InstanceStateName.Stopped);
InstanceState newState = new InstanceState();
newState.setCode(16);
newState.setName(InstanceStateName.Running);
sc.setPreviousState(previousState);
sc.setCurrentState(newState);
sc.setInstanceId("test-1");
coll.add(sc);
result.setStartingInstances(coll);
} else {
throw new AmazonServiceException("The image-id doesn't exists");
}
return result;
}
示例2: stopInstances
import com.amazonaws.services.ec2.model.InstanceStateName; //导入依赖的package包/类
@Override
public StopInstancesResult stopInstances(StopInstancesRequest stopInstancesRequest) {
StopInstancesResult result = new StopInstancesResult();
if (stopInstancesRequest.getInstanceIds().get(0).equals("test-1")) {
Collection<InstanceStateChange> coll = new ArrayList<InstanceStateChange>();
InstanceStateChange sc = new InstanceStateChange();
InstanceState previousState = new InstanceState();
previousState.setCode(80);
previousState.setName(InstanceStateName.Running);
InstanceState newState = new InstanceState();
newState.setCode(16);
newState.setName(InstanceStateName.Stopped);
sc.setPreviousState(previousState);
sc.setCurrentState(newState);
sc.setInstanceId("test-1");
coll.add(sc);
result.setStoppingInstances(coll);
} else {
throw new AmazonServiceException("The image-id doesn't exists");
}
return result;
}
示例3: terminateInstances
import com.amazonaws.services.ec2.model.InstanceStateName; //导入依赖的package包/类
@Override
public TerminateInstancesResult terminateInstances(TerminateInstancesRequest terminateInstancesRequest) {
TerminateInstancesResult result = new TerminateInstancesResult();
if (terminateInstancesRequest.getInstanceIds().contains("test-1")) {
Collection<InstanceStateChange> coll = new ArrayList<InstanceStateChange>();
InstanceStateChange sc = new InstanceStateChange();
InstanceState previousState = new InstanceState();
previousState.setCode(80);
previousState.setName(InstanceStateName.Running);
InstanceState newState = new InstanceState();
newState.setCode(16);
newState.setName(InstanceStateName.Terminated);
sc.setPreviousState(previousState);
sc.setCurrentState(newState);
sc.setInstanceId("test-1");
coll.add(sc);
result.setTerminatingInstances(coll);
} else {
throw new AmazonServiceException("The image-id doesn't exists");
}
return result;
}
示例4: createState
import com.amazonaws.services.ec2.model.InstanceStateName; //导入依赖的package包/类
private static InstanceState createState(com.amazonaws.services.ec2.model.InstanceStateName instanceState) {
switch (instanceState) {
case Pending:
return InstanceState.QUEUED;
default:
case Running:
return InstanceState.LAUNCHED;
case ShuttingDown:
return InstanceState.SHUTTING_DOWN;
case Terminated:
return InstanceState.DELETING;
case Stopping:
return InstanceState.SUSPENDING;
case Stopped:
return InstanceState.SUSPENDED;
}
}
示例5: testStartInstance
import com.amazonaws.services.ec2.model.InstanceStateName; //导入依赖的package包/类
@Test
public void testStartInstance() {
final DescribeInstanceStatusRequest describeInstanceStatusRequest = new DescribeInstanceStatusRequest().withIncludeAllInstances(true).withInstanceIds(INSTANCE_ID);
final DescribeInstanceStatusResult describeInstanceStatusResult = new DescribeInstanceStatusResult().withInstanceStatuses(new InstanceStatus().withInstanceState(new InstanceState().withName(InstanceStateName.Stopped)));
final StartInstancesRequest startInstancesRequest = new StartInstancesRequest().withInstanceIds(INSTANCE_ID);
final StartInstancesResult startInstancesResult = new StartInstancesResult().withStartingInstances(new InstanceStateChange().withCurrentState(new InstanceState().withName(InstanceStateName.Running)));
Mockito.doReturn(describeInstanceStatusResult).when(amazonEC2Client).describeInstanceStatus(describeInstanceStatusRequest);
Mockito.doReturn(startInstancesResult).when(amazonEC2Client).startInstances(startInstancesRequest);
amazonEC2Service.startInstance(INSTANCE_ID);
final InOrder inOrder = Mockito.inOrder(amazonEC2Client);
inOrder.verify(amazonEC2Client).describeInstanceStatus(describeInstanceStatusRequest);
inOrder.verify(amazonEC2Client).startInstances(startInstancesRequest);
}
示例6: testStopInstanceStopping
import com.amazonaws.services.ec2.model.InstanceStateName; //导入依赖的package包/类
@Test
public void testStopInstanceStopping() {
final DescribeInstanceStatusRequest describeInstanceStatusRequest = new DescribeInstanceStatusRequest().withIncludeAllInstances(true).withInstanceIds(INSTANCE_ID);
final DescribeInstanceStatusResult describeInstanceStatusResult = new DescribeInstanceStatusResult().withInstanceStatuses(new InstanceStatus().withInstanceState(new InstanceState().withName(InstanceStateName.Running)));
final StopInstancesRequest stopInstancesRequest = new StopInstancesRequest().withInstanceIds(INSTANCE_ID);
final StopInstancesResult stopInstancesResult = new StopInstancesResult().withStoppingInstances(new InstanceStateChange().withCurrentState(new InstanceState().withName(InstanceStateName.Stopping)));
Mockito.doReturn(describeInstanceStatusResult).when(amazonEC2Client).describeInstanceStatus(describeInstanceStatusRequest);
Mockito.doReturn(stopInstancesResult).when(amazonEC2Client).stopInstances(stopInstancesRequest);
amazonEC2Service.stopInstance(INSTANCE_ID);
final InOrder inOrder = Mockito.inOrder(amazonEC2Client);
inOrder.verify(amazonEC2Client).describeInstanceStatus(describeInstanceStatusRequest);
inOrder.verify(amazonEC2Client).stopInstances(stopInstancesRequest);
}
示例7: testStopInstanceStopped
import com.amazonaws.services.ec2.model.InstanceStateName; //导入依赖的package包/类
@Test
public void testStopInstanceStopped() {
final DescribeInstanceStatusRequest describeInstanceStatusRequest = new DescribeInstanceStatusRequest().withIncludeAllInstances(true).withInstanceIds(INSTANCE_ID);
final DescribeInstanceStatusResult describeInstanceStatusResult = new DescribeInstanceStatusResult().withInstanceStatuses(new InstanceStatus().withInstanceState(new InstanceState().withName(InstanceStateName.Running)));
final StopInstancesRequest stopInstancesRequest = new StopInstancesRequest().withInstanceIds(INSTANCE_ID);
final StopInstancesResult stopInstancesResult = new StopInstancesResult().withStoppingInstances(new InstanceStateChange().withCurrentState(new InstanceState().withName(InstanceStateName.Stopped)));
Mockito.doReturn(describeInstanceStatusResult).when(amazonEC2Client).describeInstanceStatus(describeInstanceStatusRequest);
Mockito.doReturn(stopInstancesResult).when(amazonEC2Client).stopInstances(stopInstancesRequest);
amazonEC2Service.stopInstance(INSTANCE_ID);
final InOrder inOrder = Mockito.inOrder(amazonEC2Client);
inOrder.verify(amazonEC2Client).describeInstanceStatus(describeInstanceStatusRequest);
inOrder.verify(amazonEC2Client).stopInstances(stopInstancesRequest);
}
示例8: terminateInstances
import com.amazonaws.services.ec2.model.InstanceStateName; //导入依赖的package包/类
@Override
public TerminateInstancesResult terminateInstances(List<String> instanceIds)
throws NotFoundException, AmazonClientException {
TerminateInstancesResult result = new TerminateInstancesResult();
for (String instanceId : instanceIds) {
if (!this.instances.containsKey(instanceId)) {
throw new AmazonServiceException(String.format(
"The instance ID '%s' does not exist " + "(Service: AmazonEC2; Status Code: 400; Error Code: "
+ "InvalidInstanceID.NotFound;" + " Request ID: 12a2ebaf-c480-4998-95fb-6d47b4393e00)",
instanceId));
}
this.instances.remove(instanceId);
result.withTerminatingInstances(new InstanceStateChange().withInstanceId(instanceId)
.withCurrentState(new InstanceState().withName(InstanceStateName.ShuttingDown)));
}
return result;
}
示例9: testConversionOfCancelledRequestWithRunningInstance
import com.amazonaws.services.ec2.model.InstanceStateName; //导入依赖的package包/类
/**
* Conversion of request that has been cancelled but with an instance that
* is still running.
*/
@Test
public void testConversionOfCancelledRequestWithRunningInstance() {
InstancePairedSpotRequest cancelledRequest = new InstancePairedSpotRequest(
SpotTestUtil.spotRequest("sir-1", "cancelled", "i-1"),
SpotTestUtil.instance("i-1", InstanceStateName.Running, "sir-1"));
Machine machine = InstancePairedSpotRequestToMachine.convert(cancelledRequest);
assertThat(machine.getId(), is("sir-1"));
assertThat(machine.getMachineState(), is(MachineState.TERMINATED));
assertThat(machine.getCloudProvider(), is(CloudProviders.AWS_SPOT));
assertThat(machine.getRegion(), is("us-east-1"));
assertThat(machine.getMachineSize(), is("m1.medium"));
assertThat(machine.getMembershipStatus(), is(MembershipStatus.defaultStatus()));
assertThat(machine.getLaunchTime(), is(FrozenTime.now()));
assertThat(machine.getServiceState(), is(ServiceState.UNKNOWN));
assertThat(machine.getPublicIps(), is(list()));
assertThat(machine.getPrivateIps(), is(list()));
assertThat(machine.getMetadata(), is(JsonUtils.toJson(cancelledRequest)));
}
示例10: convertCompleteInstance
import com.amazonaws.services.ec2.model.InstanceStateName; //导入依赖的package包/类
@Test
public void convertCompleteInstance() {
DateTime launchTime = UtcTime.now();
Instance instance = new Instance().withInstanceId("i-1")
.withState(new InstanceState().withName(InstanceStateName.Running)).withPublicIpAddress("1.2.3.4")
.withPrivateIpAddress("1.2.3.5").withInstanceType(InstanceType.M1Small)
.withLaunchTime(launchTime.toDate())
.withMonitoring(new Monitoring().withState(MonitoringState.Disabled)).withHypervisor(HypervisorType.Xen)
.withPlacement(new Placement("us-east-1c"));
Machine machine = convert(instance);
assertThat(machine.getId(), is(instance.getInstanceId()));
assertThat(machine.getLaunchTime(), is(launchTime));
assertThat(machine.getMachineState(), is(MachineState.RUNNING));
assertThat(machine.getCloudProvider(), is(CloudProviders.AWS_EC2));
assertThat(machine.getRegion(), is("us-east-1"));
assertThat(machine.getMachineSize(), is("m1.small"));
assertThat(machine.getMembershipStatus(), is(MembershipStatus.defaultStatus()));
assertThat(machine.getServiceState(), is(ServiceState.UNKNOWN));
assertThat(machine.getPublicIps().size(), is(1));
assertThat(machine.getPublicIps().get(0), is(instance.getPublicIpAddress()));
assertThat(machine.getPrivateIps().size(), is(1));
assertThat(machine.getPrivateIps().get(0), is(instance.getPrivateIpAddress()));
assertThat(machine.getMetadata(), is(JsonUtils.toJson(instance)));
}
示例11: convertInstanceMissingPublicIp
import com.amazonaws.services.ec2.model.InstanceStateName; //导入依赖的package包/类
@Test
public void convertInstanceMissingPublicIp() {
DateTime launchTime = UtcTime.now();
Instance instance = new Instance().withInstanceId("i-1")
.withState(new InstanceState().withName(InstanceStateName.Running)).withPrivateIpAddress("1.2.3.5")
.withInstanceType(InstanceType.M1Small).withLaunchTime(launchTime.toDate())
.withMonitoring(new Monitoring().withState(MonitoringState.Disabled)).withHypervisor(HypervisorType.Xen)
.withPlacement(new Placement("us-east-1a"));
Machine machine = convert(instance);
assertThat(machine.getId(), is(instance.getInstanceId()));
assertThat(machine.getCloudProvider(), is(CloudProviders.AWS_EC2));
assertThat(machine.getRegion(), is("us-east-1"));
assertThat(machine.getMachineSize(), is("m1.small"));
assertThat(machine.getLaunchTime(), is(launchTime));
assertThat(machine.getMachineState(), is(MachineState.RUNNING));
assertThat(machine.getMembershipStatus(), is(MembershipStatus.defaultStatus()));
assertThat(machine.getServiceState(), is(ServiceState.UNKNOWN));
assertThat(machine.getPublicIps().size(), is(0));
assertThat(machine.getPrivateIps().size(), is(1));
assertThat(machine.getPrivateIps().get(0), is(instance.getPrivateIpAddress()));
assertThat(machine.getMetadata(), is(JsonUtils.toJson(instance)));
}
示例12: convertInstanceMissingPrivateIp
import com.amazonaws.services.ec2.model.InstanceStateName; //导入依赖的package包/类
@Test
public void convertInstanceMissingPrivateIp() {
DateTime launchTime = UtcTime.now();
Instance instance = new Instance().withInstanceId("i-1")
.withState(new InstanceState().withName(InstanceStateName.Running)).withPublicIpAddress("1.2.3.4")
.withInstanceType(InstanceType.M1Medium).withLaunchTime(launchTime.toDate())
.withMonitoring(new Monitoring().withState(MonitoringState.Disabled)).withHypervisor(HypervisorType.Xen)
.withPlacement(new Placement("us-east-1b"));
Machine machine = convert(instance);
assertThat(machine.getId(), is(instance.getInstanceId()));
assertThat(machine.getCloudProvider(), is(CloudProviders.AWS_EC2));
assertThat(machine.getRegion(), is("us-east-1"));
assertThat(machine.getMachineSize(), is("m1.medium"));
assertThat(machine.getLaunchTime(), is(launchTime));
assertThat(machine.getMachineState(), is(MachineState.RUNNING));
assertThat(machine.getMembershipStatus(), is(MembershipStatus.defaultStatus()));
assertThat(machine.getServiceState(), is(ServiceState.UNKNOWN));
assertThat(machine.getPublicIps().size(), is(1));
assertThat(machine.getPublicIps().get(0), is(instance.getPublicIpAddress()));
assertThat(machine.getPrivateIps().size(), is(0));
assertThat(machine.getMetadata(), is(JsonUtils.toJson(instance)));
}
示例13: convertSpotInstance
import com.amazonaws.services.ec2.model.InstanceStateName; //导入依赖的package包/类
/**
* A converted spot instance {@link Machine} should have a cloud provider
* value of {@link CloudProviders#AWS_SPOT} to distinguish it from a regular
* EC2 on-demand instance.
*/
@Test
public void convertSpotInstance() {
// convert on-demand instance: cloud provider should be AWS_EC2
Instance onDemandInstance = new Instance().withInstanceId("i-1").withInstanceType(InstanceType.M1Medium)
.withState(new InstanceState().withName(InstanceStateName.Running))
.withPlacement(new Placement("us-east-1b"));
Machine onDemandMachine = convert(onDemandInstance);
assertThat(onDemandMachine.getCloudProvider(), is(CloudProviders.AWS_EC2));
// convert spot instance: cloud provider should be AWS_EC2
Instance spotInstance = new Instance().withInstanceId("i-1").withInstanceType(InstanceType.M1Medium)
.withState(new InstanceState().withName(InstanceStateName.Running)).withSpotInstanceRequestId("sir-123")
.withPlacement(new Placement("us-east-1b"));
Machine spotMachine = convert(spotInstance);
assertThat(spotMachine.getCloudProvider(), is(CloudProviders.AWS_SPOT));
}
示例14: convert
import com.amazonaws.services.ec2.model.InstanceStateName; //导入依赖的package包/类
/**
* Converts the ec2 instance to a turbine instance.
* @param ec2 EC2 instance.
* @return Turbine instance.
*/
public com.netflix.turbine.discovery.Instance convert(final Instance ec2) {
final boolean state = InstanceStateName.fromValue(
ec2.getState().getName()
) == InstanceStateName.Running;
return new com.netflix.turbine.discovery.Instance(
ec2.getPrivateIpAddress(), this.cluster, state
);
}
示例15: convertsRunningInstances
import com.amazonaws.services.ec2.model.InstanceStateName; //导入依赖的package包/类
/**
* {@link EC2ToTurbineInstance} can convert a running ec2 instance into
* a turbine instance.
*/
@Test
public void convertsRunningInstances() {
final String ip = "172.13.131.215";
final String cluster = "blah";
final Instance ec2 = new Instance()
.withPrivateIpAddress(ip)
.withState(new InstanceState().withName(InstanceStateName.Running));
Assertions.assertThat(new EC2ToTurbineInstance(cluster).convert(ec2))
.isNotNull()
.matches(instance -> instance.getHostname().equals(ip))
.matches(com.netflix.turbine.discovery.Instance::isUp);
}