Search in sources :

Example 1 with UnmonitorInstancesResult

use of com.amazonaws.services.ec2.model.UnmonitorInstancesResult 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 2 with UnmonitorInstancesResult

use of com.amazonaws.services.ec2.model.UnmonitorInstancesResult 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 3 with UnmonitorInstancesResult

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

the class EC2ProducerTest method ec2UnmonitorInstancesTest.

@Test
public void ec2UnmonitorInstancesTest() throws Exception {
    mock.expectedMessageCount(1);
    Exchange exchange = template.request("direct:unmonitor", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            Collection l = new ArrayList();
            l.add("test-1");
            exchange.getIn().setHeader(EC2Constants.INSTANCES_IDS, l);
        }
    });
    assertMockEndpointsSatisfied();
    UnmonitorInstancesResult resultGet = (UnmonitorInstancesResult) exchange.getIn().getBody();
    assertEquals(resultGet.getInstanceMonitorings().size(), 1);
    assertEquals(resultGet.getInstanceMonitorings().get(0).getInstanceId(), "test-1");
    assertEquals(resultGet.getInstanceMonitorings().get(0).getMonitoring().getState(), MonitoringState.Disabled.toString());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) ArrayList(java.util.ArrayList) Collection(java.util.Collection) UnmonitorInstancesResult(com.amazonaws.services.ec2.model.UnmonitorInstancesResult) Test(org.junit.Test)

Example 4 with UnmonitorInstancesResult

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

the class EC2ComponentSpringTest method ec2UnmonitorInstancesTest.

@Test
public void ec2UnmonitorInstancesTest() throws Exception {
    Exchange exchange = template.request("direct:unmonitor", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            Collection l = new ArrayList();
            l.add("test-1");
            exchange.getIn().setHeader(EC2Constants.INSTANCES_IDS, l);
        }
    });
    UnmonitorInstancesResult resultGet = (UnmonitorInstancesResult) exchange.getOut().getBody();
    assertEquals(resultGet.getInstanceMonitorings().size(), 1);
    assertEquals(resultGet.getInstanceMonitorings().get(0).getInstanceId(), "test-1");
    assertEquals(resultGet.getInstanceMonitorings().get(0).getMonitoring().getState(), MonitoringState.Disabled.toString());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) ArrayList(java.util.ArrayList) Collection(java.util.Collection) UnmonitorInstancesResult(com.amazonaws.services.ec2.model.UnmonitorInstancesResult) Test(org.junit.Test)

Aggregations

UnmonitorInstancesResult (com.amazonaws.services.ec2.model.UnmonitorInstancesResult)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 Exchange (org.apache.camel.Exchange)2 Processor (org.apache.camel.Processor)2 Test (org.junit.Test)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 InstanceMonitoring (com.amazonaws.services.ec2.model.InstanceMonitoring)1 Monitoring (com.amazonaws.services.ec2.model.Monitoring)1 UnmonitorInstancesRequest (com.amazonaws.services.ec2.model.UnmonitorInstancesRequest)1 Iterator (java.util.Iterator)1 Message (org.apache.camel.Message)1