use of com.amazonaws.services.ec2.model.MonitorInstancesResult in project camel by apache.
the class EC2ProducerTest method ec2MonitorInstancesTest.
@Test
public void ec2MonitorInstancesTest() throws Exception {
mock.expectedMessageCount(1);
Exchange exchange = template.request("direct:monitor", 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();
MonitorInstancesResult resultGet = (MonitorInstancesResult) exchange.getIn().getBody();
assertEquals(resultGet.getInstanceMonitorings().size(), 1);
assertEquals(resultGet.getInstanceMonitorings().get(0).getInstanceId(), "test-1");
assertEquals(resultGet.getInstanceMonitorings().get(0).getMonitoring().getState(), MonitoringState.Enabled.toString());
}
use of com.amazonaws.services.ec2.model.MonitorInstancesResult in project camel by apache.
the class EC2Producer method monitorInstances.
private void monitorInstances(AmazonEC2Client ec2Client, Exchange exchange) {
Collection instanceIds;
MonitorInstancesRequest request = new MonitorInstancesRequest();
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");
}
MonitorInstancesResult result;
try {
result = ec2Client.monitorInstances(request);
} catch (AmazonServiceException ase) {
LOG.trace("Monitor Instances command returned the error code {}", ase.getErrorCode());
throw ase;
}
LOG.trace("Start Monitoring instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
Message message = getMessageForResponse(exchange);
message.setBody(result);
}
use of com.amazonaws.services.ec2.model.MonitorInstancesResult 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;
}
use of com.amazonaws.services.ec2.model.MonitorInstancesResult in project camel by apache.
the class EC2ComponentSpringTest method ec2MonitorInstancesTest.
@Test
public void ec2MonitorInstancesTest() throws Exception {
Exchange exchange = template.request("direct:monitor", 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);
}
});
MonitorInstancesResult resultGet = (MonitorInstancesResult) exchange.getOut().getBody();
assertEquals(resultGet.getInstanceMonitorings().size(), 1);
assertEquals(resultGet.getInstanceMonitorings().get(0).getInstanceId(), "test-1");
assertEquals(resultGet.getInstanceMonitorings().get(0).getMonitoring().getState(), MonitoringState.Enabled.toString());
}
Aggregations