Search in sources :

Example 6 with Monitoring

use of com.amazonaws.services.ec2.model.Monitoring in project camel by apache.

the class AmazonEC2ClientMock method monitorInstances.

@Override
public MonitorInstancesResult monitorInstances(MonitorInstancesRequest monitorInstancesRequest) {
    MonitorInstancesResult result = new MonitorInstancesResult();
    if (!monitorInstancesRequest.getInstanceIds().isEmpty()) {
        Collection<InstanceMonitoring> coll = new ArrayList();
        Iterator it = monitorInstancesRequest.getInstanceIds().iterator();
        while (it.hasNext()) {
            String id = (String) it.next();
            InstanceMonitoring mon = new InstanceMonitoring();
            mon.setInstanceId(id);
            Monitoring monitoring = new Monitoring();
            monitoring.setState(MonitoringState.Enabled);
            mon.setMonitoring(monitoring);
            coll.add(mon);
        }
        result.setInstanceMonitorings(coll);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) MonitorInstancesResult(com.amazonaws.services.ec2.model.MonitorInstancesResult) InstanceMonitoring(com.amazonaws.services.ec2.model.InstanceMonitoring) InstanceMonitoring(com.amazonaws.services.ec2.model.InstanceMonitoring) Monitoring(com.amazonaws.services.ec2.model.Monitoring)

Example 7 with Monitoring

use of com.amazonaws.services.ec2.model.Monitoring 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)

Example 8 with Monitoring

use of com.amazonaws.services.ec2.model.Monitoring in project aws-doc-sdk-examples by awsdocs.

the class MonitorInstance method monitorInstance.

public static void monitorInstance(String instance_id) {
    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
    DryRunSupportedRequest<MonitorInstancesRequest> dry_request = () -> {
        MonitorInstancesRequest request = new MonitorInstancesRequest().withInstanceIds(instance_id);
        return request.getDryRunRequest();
    };
    DryRunResult dry_response = ec2.dryRun(dry_request);
    if (!dry_response.isSuccessful()) {
        System.out.printf("Failed dry run to enable monitoring on instance %s", instance_id);
        throw dry_response.getDryRunResponse();
    }
    MonitorInstancesRequest request = new MonitorInstancesRequest().withInstanceIds(instance_id);
    ec2.monitorInstances(request);
    System.out.printf("Successfully enabled monitoring for instance %s", instance_id);
}
Also used : AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) MonitorInstancesRequest(com.amazonaws.services.ec2.model.MonitorInstancesRequest) DryRunResult(com.amazonaws.services.ec2.model.DryRunResult)

Aggregations

AmazonServiceException (com.amazonaws.AmazonServiceException)3 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)3 Collection (java.util.Collection)3 Message (org.apache.camel.Message)3 DryRunResult (com.amazonaws.services.ec2.model.DryRunResult)2 InstanceMonitoring (com.amazonaws.services.ec2.model.InstanceMonitoring)2 MonitorInstancesRequest (com.amazonaws.services.ec2.model.MonitorInstancesRequest)2 MonitorInstancesResult (com.amazonaws.services.ec2.model.MonitorInstancesResult)2 Monitoring (com.amazonaws.services.ec2.model.Monitoring)2 UnmonitorInstancesRequest (com.amazonaws.services.ec2.model.UnmonitorInstancesRequest)2 UnmonitorInstancesResult (com.amazonaws.services.ec2.model.UnmonitorInstancesResult)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)1 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)1 Instance (com.amazonaws.services.ec2.model.Instance)1 InstanceType (com.amazonaws.services.ec2.model.InstanceType)1 Placement (com.amazonaws.services.ec2.model.Placement)1 Reservation (com.amazonaws.services.ec2.model.Reservation)1 RunInstancesRequest (com.amazonaws.services.ec2.model.RunInstancesRequest)1