Search in sources :

Example 1 with UnmonitorInstancesRequest

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);
}
Also used : AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) DryRunResult(com.amazonaws.services.ec2.model.DryRunResult) UnmonitorInstancesRequest(com.amazonaws.services.ec2.model.UnmonitorInstancesRequest)

Example 2 with UnmonitorInstancesRequest

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);
}
Also used : Message(org.apache.camel.Message) AmazonServiceException(com.amazonaws.AmazonServiceException) Collection(java.util.Collection) UnmonitorInstancesResult(com.amazonaws.services.ec2.model.UnmonitorInstancesResult) UnmonitorInstancesRequest(com.amazonaws.services.ec2.model.UnmonitorInstancesRequest)

Example 3 with UnmonitorInstancesRequest

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;
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) UnmonitorInstancesResult(com.amazonaws.services.ec2.model.UnmonitorInstancesResult) InstanceMonitoring(com.amazonaws.services.ec2.model.InstanceMonitoring) InstanceMonitoring(com.amazonaws.services.ec2.model.InstanceMonitoring) Monitoring(com.amazonaws.services.ec2.model.Monitoring)

Aggregations

UnmonitorInstancesRequest (com.amazonaws.services.ec2.model.UnmonitorInstancesRequest)2 UnmonitorInstancesResult (com.amazonaws.services.ec2.model.UnmonitorInstancesResult)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)1 DryRunResult (com.amazonaws.services.ec2.model.DryRunResult)1 InstanceMonitoring (com.amazonaws.services.ec2.model.InstanceMonitoring)1 Monitoring (com.amazonaws.services.ec2.model.Monitoring)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 Message (org.apache.camel.Message)1