use of com.amazonaws.services.ec2.model.StopInstancesRequest in project camel by apache.
the class EC2Producer method stopInstances.
private void stopInstances(AmazonEC2Client ec2Client, Exchange exchange) {
Collection instanceIds;
StopInstancesRequest request = new StopInstancesRequest();
if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS))) {
instanceIds = exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS, Collection.class);
request.withInstanceIds(instanceIds);
} else {
throw new IllegalArgumentException("Instances Ids must be specified");
}
StopInstancesResult result;
try {
result = ec2Client.stopInstances(request);
} catch (AmazonServiceException ase) {
LOG.trace("Stop Instances command returned the error code {}", ase.getErrorCode());
throw ase;
}
LOG.trace("Stopping instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
Message message = getMessageForResponse(exchange);
message.setBody(result);
}
use of com.amazonaws.services.ec2.model.StopInstancesRequest in project GNS by MobilityFirst.
the class AWSEC2 method stopInstance.
/**
* Stop an instance
*
* @param ec2
* @param createdInstanceId
*/
public static void stopInstance(AmazonEC2 ec2, String createdInstanceId) {
System.out.println("Stopping Instance:" + createdInstanceId);
List<String> instanceIds = new LinkedList<>();
instanceIds.add(createdInstanceId);
StopInstancesRequest stopIR = new StopInstancesRequest(instanceIds);
ec2.stopInstances(stopIR);
}
use of com.amazonaws.services.ec2.model.StopInstancesRequest 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.StopInstancesRequest in project aws-doc-sdk-examples by awsdocs.
the class StartStopInstance method stopInstance.
public static void stopInstance(String instance_id) {
final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
DryRunSupportedRequest<StopInstancesRequest> dry_request = () -> {
StopInstancesRequest request = new StopInstancesRequest().withInstanceIds(instance_id);
return request.getDryRunRequest();
};
DryRunResult dry_response = ec2.dryRun(dry_request);
if (!dry_response.isSuccessful()) {
System.out.printf("Failed dry run to stop instance %s", instance_id);
throw dry_response.getDryRunResponse();
}
StopInstancesRequest request = new StopInstancesRequest().withInstanceIds(instance_id);
ec2.stopInstances(request);
System.out.printf("Successfully stop instance %s", instance_id);
}
Aggregations