use of com.amazonaws.services.ec2.model.UnmonitorInstancesRequest in project aws-doc-sdk-examples by awsdocs.
the class MonitorInstance method unmonitorInstance.
public static void unmonitorInstance(String instance_id) {
final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
DryRunSupportedRequest<UnmonitorInstancesRequest> dry_request = () -> {
UnmonitorInstancesRequest request = new UnmonitorInstancesRequest().withInstanceIds(instance_id);
return request.getDryRunRequest();
};
DryRunResult dry_response = ec2.dryRun(dry_request);
if (!dry_response.isSuccessful()) {
System.out.printf("Failed dry run to disable monitoring on instance %s", instance_id);
throw dry_response.getDryRunResponse();
}
UnmonitorInstancesRequest request = new UnmonitorInstancesRequest().withInstanceIds(instance_id);
ec2.unmonitorInstances(request);
System.out.printf("Successfully disabled monitoring for instance %s", instance_id);
}
use of com.amazonaws.services.ec2.model.UnmonitorInstancesRequest in project camel by apache.
the class EC2Producer method unmonitorInstances.
private void unmonitorInstances(AmazonEC2Client ec2Client, Exchange exchange) {
Collection instanceIds;
UnmonitorInstancesRequest request = new UnmonitorInstancesRequest();
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");
}
UnmonitorInstancesResult result;
try {
result = ec2Client.unmonitorInstances(request);
} catch (AmazonServiceException ase) {
LOG.trace("Unmonitor Instances command returned the error code {}", ase.getErrorCode());
throw ase;
}
LOG.trace("Stop Monitoring instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
Message message = getMessageForResponse(exchange);
message.setBody(result);
}
use of com.amazonaws.services.ec2.model.UnmonitorInstancesRequest in project camel by apache.
the class AmazonEC2ClientMock method unmonitorInstances.
@Override
public UnmonitorInstancesResult unmonitorInstances(UnmonitorInstancesRequest unmonitorInstancesRequest) {
UnmonitorInstancesResult result = new UnmonitorInstancesResult();
if (!unmonitorInstancesRequest.getInstanceIds().isEmpty()) {
Collection<InstanceMonitoring> coll = new ArrayList();
Iterator it = unmonitorInstancesRequest.getInstanceIds().iterator();
while (it.hasNext()) {
String id = (String) it.next();
InstanceMonitoring mon = new InstanceMonitoring();
mon.setInstanceId(id);
Monitoring monitoring = new Monitoring();
monitoring.setState(MonitoringState.Disabled);
mon.setMonitoring(monitoring);
coll.add(mon);
}
result.setInstanceMonitorings(coll);
}
return result;
}
Aggregations