本文整理汇总了Java中com.amazonaws.services.ec2.model.InstanceState类的典型用法代码示例。如果您正苦于以下问题:Java InstanceState类的具体用法?Java InstanceState怎么用?Java InstanceState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InstanceState类属于com.amazonaws.services.ec2.model包,在下文中一共展示了InstanceState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDescribeInstanceStatusResult
import com.amazonaws.services.ec2.model.InstanceState; //导入依赖的package包/类
public void createDescribeInstanceStatusResult(String instanceId,
String stateName, String instanceStatusName,
String systemStatusName) {
InstanceState state = new InstanceState().withName(stateName);
InstanceStatusSummary instanceSummary = new InstanceStatusSummary()
.withStatus(instanceStatusName);
InstanceStatusSummary systemSummary = new InstanceStatusSummary()
.withStatus(systemStatusName);
InstanceStatus instanceStatus = new com.amazonaws.services.ec2.model.InstanceStatus()
.withInstanceId(instanceId).withInstanceState(state)
.withInstanceStatus(instanceSummary)
.withSystemStatus(systemSummary);
DescribeInstanceStatusResult instanceStatusResult = new DescribeInstanceStatusResult()
.withInstanceStatuses(instanceStatus);
doReturn(instanceStatusResult).when(ec2).describeInstanceStatus(
any(DescribeInstanceStatusRequest.class));
}
示例2: addDescribeInstanceStatusResult
import com.amazonaws.services.ec2.model.InstanceState; //导入依赖的package包/类
public void addDescribeInstanceStatusResult(String instanceId,
String stateName, String instanceStatusName,
String systemStatusName) {
InstanceState state = new InstanceState().withName(stateName);
InstanceStatusSummary instanceSummary = new InstanceStatusSummary()
.withStatus(instanceStatusName);
InstanceStatusSummary systemSummary = new InstanceStatusSummary()
.withStatus(systemStatusName);
com.amazonaws.services.ec2.model.InstanceStatus instanceStatus = new com.amazonaws.services.ec2.model.InstanceStatus()
.withInstanceId(instanceId).withInstanceState(state)
.withInstanceStatus(instanceSummary)
.withSystemStatus(systemSummary);
DescribeInstanceStatusResult instanceStatusResult = new DescribeInstanceStatusResult()
.withInstanceStatuses(instanceStatus);
answerDescribeInstanceStatus.add(instanceStatusResult);
}
示例3: startInstances
import com.amazonaws.services.ec2.model.InstanceState; //导入依赖的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;
}
示例4: stopInstances
import com.amazonaws.services.ec2.model.InstanceState; //导入依赖的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;
}
示例5: terminateInstances
import com.amazonaws.services.ec2.model.InstanceState; //导入依赖的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;
}
示例6: itShouldStartAnEC2InstanceFromAnAMI
import com.amazonaws.services.ec2.model.InstanceState; //导入依赖的package包/类
@Test
public void itShouldStartAnEC2InstanceFromAnAMI()
throws ServiceBrokerException {
when(
ec2Client.runInstances(awsRqst(r -> r.getImageId().equals(
"test_image")))).thenReturn(runInstanceResult);
when(ec2Client.describeAddresses()).thenReturn(
new DescribeAddressesResult().withAddresses(Collections
.singleton(new Address().withPublicIp("10.10.10.10"))));
when(ec2Client.describeInstanceStatus(any())).thenReturn(
new DescribeInstanceStatusResult()
.withInstanceStatuses(Collections
.singleton(new InstanceStatus()
.withInstanceState(new InstanceState()
.withName("running")))));
when(hostUtils.waitForBoot(anyString(), anyInt())).thenReturn(true);
assertThat(aws.startEC2Instance("test_image"),
is(equalTo("test_instance")));
}
示例7: testStartInstance
import com.amazonaws.services.ec2.model.InstanceState; //导入依赖的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);
}
示例8: testStopInstanceStopping
import com.amazonaws.services.ec2.model.InstanceState; //导入依赖的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);
}
示例9: testStopInstanceStopped
import com.amazonaws.services.ec2.model.InstanceState; //导入依赖的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);
}
示例10: convertObject
import com.amazonaws.services.ec2.model.InstanceState; //导入依赖的package包/类
@Override
protected InstanceStateChange convertObject(TerminatingInstanceDescription from) {
InstanceStateChange to = new InstanceStateChange();
to.setInstanceId(from.getInstanceId());
InstanceState previousState = new InstanceState();
previousState.setCode(from.getPreviousStateCode());
previousState.setName(from.getPreviousState());
to.setPreviousState(previousState);
InstanceState currentState = new InstanceState();
currentState.setCode(from.getShutdownStateCode());
currentState.setName(from.getShutdownState());
to.setCurrentState(currentState);
return to;
}
开发者ID:primecloud-controller-org,项目名称:primecloud-controller,代码行数:19,代码来源:InstanceStateChangeTerminateConverter.java
示例11: 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()));
}
}
示例12: launchInstances
import com.amazonaws.services.ec2.model.InstanceState; //导入依赖的package包/类
@Override
public List<Instance> launchInstances(Ec2ProvisioningTemplate provisioningDetails, int count)
throws AmazonClientException {
List<Instance> launchedInstances = new ArrayList<>();
for (int i = 0; i < count; i++) {
int idNum = ++this.idSequencer;
Instance newInstance = new Instance().withInstanceId("i-" + idNum)
.withState(new InstanceState().withName("pending")).withPublicIpAddress("1.2.3." + idNum)
.withImageId(provisioningDetails.getAmiId())
.withInstanceType(provisioningDetails.getInstanceType());
for (Entry<String, String> tagItem : provisioningDetails.getTags().entrySet()) {
newInstance.withTags(new Tag(tagItem.getKey(), tagItem.getValue()));
}
this.instances.add(newInstance);
launchedInstances.add(newInstance);
}
return launchedInstances;
}
示例13: launchInstances
import com.amazonaws.services.ec2.model.InstanceState; //导入依赖的package包/类
@Override
public List<Instance> launchInstances(Ec2ProvisioningTemplate template, int count) throws AmazonClientException {
List<Instance> launchedInstances = new ArrayList<>();
for (int i = 0; i < count; i++) {
int idNum = ++this.idSequencer;
String id = "i-" + idNum;
LOG.info("launching instance {} into fake account ...", id);
Instance newInstance = new Instance().withInstanceId(id).withState(new InstanceState().withName("pending"))
.withPublicIpAddress("1.2.3." + idNum).withImageId(template.getAmiId())
.withInstanceType(template.getInstanceType());
if (!template.getTags().isEmpty()) {
List<Tag> tags = new ArrayList<>();
for (Entry<String, String> tag : template.getTags().entrySet()) {
tags.add(new Tag(tag.getKey(), tag.getValue()));
}
newInstance.withTags(tags);
}
this.instances.put(newInstance.getInstanceId(), newInstance);
launchedInstances.add(newInstance);
}
return launchedInstances;
}
示例14: terminateInstances
import com.amazonaws.services.ec2.model.InstanceState; //导入依赖的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;
}
示例15: convertCompleteInstance
import com.amazonaws.services.ec2.model.InstanceState; //导入依赖的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)));
}