use of com.amazonaws.services.ec2.model.InstanceStateChange in project camel by apache.
the class AmazonEC2ClientMock method startInstances.
@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;
}
use of com.amazonaws.services.ec2.model.InstanceStateChange in project photon-model by vmware.
the class AWSRemoteCleanup method triggerEC2Deletion.
private void triggerEC2Deletion(List<String> instanceIdsToBeDeleted, AmazonEC2 ec2Client) {
if (instanceIdsToBeDeleted.isEmpty()) {
return;
}
TerminateInstancesRequest terminateInstancesRequest = new TerminateInstancesRequest(instanceIdsToBeDeleted);
TerminateInstancesResult terminateInstancesResult = ec2Client.terminateInstances(terminateInstancesRequest);
terminateInstancesResult.getTerminatingInstances().stream().forEach(instanceStateChange -> {
this.host.log("Terminating stale instance: %s", instanceStateChange.getInstanceId());
});
}
use of com.amazonaws.services.ec2.model.InstanceStateChange in project aws-doc-sdk-examples by awsdocs.
the class TerminateInstance method terminateEC2.
// snippet-start:[ec2.java2.terminate_instance]
public static void terminateEC2(Ec2Client ec2, String instanceID) {
try {
TerminateInstancesRequest ti = TerminateInstancesRequest.builder().instanceIds(instanceID).build();
TerminateInstancesResponse response = ec2.terminateInstances(ti);
List<InstanceStateChange> list = response.terminatingInstances();
for (int i = 0; i < list.size(); i++) {
InstanceStateChange sc = (list.get(i));
System.out.println("The ID of the terminated instance is " + sc.instanceId());
}
} catch (Ec2Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of com.amazonaws.services.ec2.model.InstanceStateChange in project camel by apache.
the class AmazonEC2ClientMock method stopInstances.
@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;
}
use of com.amazonaws.services.ec2.model.InstanceStateChange in project camel by apache.
the class AmazonEC2ClientMock method terminateInstances.
@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;
}
Aggregations