Search in sources :

Example 76 with Message

use of org.apache.camel.Message in project camel by apache.

the class EC2Producer method startInstances.

private void startInstances(AmazonEC2Client ec2Client, Exchange exchange) {
    Collection instanceIds;
    StartInstancesRequest request = new StartInstancesRequest();
    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");
    }
    StartInstancesResult result;
    try {
        result = ec2Client.startInstances(request);
    } catch (AmazonServiceException ase) {
        LOG.trace("Start Instances command returned the error code {}", ase.getErrorCode());
        throw ase;
    }
    LOG.trace("Starting instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
    Message message = getMessageForResponse(exchange);
    message.setBody(result);
}
Also used : Message(org.apache.camel.Message) StartInstancesResult(com.amazonaws.services.ec2.model.StartInstancesResult) StartInstancesRequest(com.amazonaws.services.ec2.model.StartInstancesRequest) AmazonServiceException(com.amazonaws.AmazonServiceException) Collection(java.util.Collection)

Example 77 with Message

use of org.apache.camel.Message in project camel by apache.

the class EC2Producer method createTags.

private void createTags(AmazonEC2Client ec2Client, Exchange exchange) {
    Collection instanceIds;
    Collection tags;
    CreateTagsRequest request = new CreateTagsRequest();
    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS))) {
        instanceIds = exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS, Collection.class);
        request.withResources(instanceIds);
    } else {
        throw new IllegalArgumentException("Instances Ids must be specified");
    }
    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_TAGS))) {
        tags = exchange.getIn().getHeader(EC2Constants.INSTANCES_TAGS, Collection.class);
        request.withTags(tags);
    } else {
        throw new IllegalArgumentException("Tags must be specified");
    }
    CreateTagsResult result = new CreateTagsResult();
    try {
        result = ec2Client.createTags(request);
    } catch (AmazonServiceException ase) {
        LOG.trace("Create tags command returned the error code {}", ase.getErrorCode());
        throw ase;
    }
    LOG.trace("Created tags [{}] on resources with Ids [{}] ", Arrays.toString(tags.toArray()), Arrays.toString(instanceIds.toArray()));
    Message message = getMessageForResponse(exchange);
    message.setBody(result);
}
Also used : CreateTagsResult(com.amazonaws.services.ec2.model.CreateTagsResult) Message(org.apache.camel.Message) CreateTagsRequest(com.amazonaws.services.ec2.model.CreateTagsRequest) AmazonServiceException(com.amazonaws.AmazonServiceException) Collection(java.util.Collection)

Example 78 with Message

use of org.apache.camel.Message in project camel by apache.

the class EC2Producer method describeInstancesStatus.

private void describeInstancesStatus(AmazonEC2Client ec2Client, Exchange exchange) {
    Collection instanceIds;
    DescribeInstanceStatusRequest request = new DescribeInstanceStatusRequest();
    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS))) {
        instanceIds = exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS, Collection.class);
        request.withInstanceIds(instanceIds);
    }
    DescribeInstanceStatusResult result;
    try {
        result = ec2Client.describeInstanceStatus(request);
    } catch (AmazonServiceException ase) {
        LOG.trace("Describe Instances Status command returned the error code {}", ase.getErrorCode());
        throw ase;
    }
    Message message = getMessageForResponse(exchange);
    message.setBody(result);
}
Also used : DescribeInstanceStatusResult(com.amazonaws.services.ec2.model.DescribeInstanceStatusResult) Message(org.apache.camel.Message) DescribeInstanceStatusRequest(com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest) AmazonServiceException(com.amazonaws.AmazonServiceException) Collection(java.util.Collection)

Example 79 with Message

use of org.apache.camel.Message in project camel by apache.

the class DescribeTableCommand method execute.

@Override
public void execute() {
    DescribeTableResult result = ddbClient.describeTable(new DescribeTableRequest().withTableName(determineTableName()));
    Message msg = getMessageForResponse(exchange);
    msg.setHeader(DdbConstants.TABLE_NAME, result.getTable().getTableName());
    msg.setHeader(DdbConstants.TABLE_STATUS, result.getTable().getTableStatus());
    msg.setHeader(DdbConstants.CREATION_DATE, result.getTable().getCreationDateTime());
    msg.setHeader(DdbConstants.ITEM_COUNT, result.getTable().getItemCount());
    msg.setHeader(DdbConstants.KEY_SCHEMA, result.getTable().getKeySchema());
    msg.setHeader(DdbConstants.READ_CAPACITY, result.getTable().getProvisionedThroughput().getReadCapacityUnits());
    msg.setHeader(DdbConstants.WRITE_CAPACITY, result.getTable().getProvisionedThroughput().getWriteCapacityUnits());
    msg.setHeader(DdbConstants.TABLE_SIZE, result.getTable().getTableSizeBytes());
}
Also used : Message(org.apache.camel.Message) DescribeTableResult(com.amazonaws.services.dynamodbv2.model.DescribeTableResult) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)

Example 80 with Message

use of org.apache.camel.Message in project camel by apache.

the class AwsExchangeUtil method getMessageForResponse.

public static Message getMessageForResponse(final Exchange exchange) {
    if (exchange.getPattern().isOutCapable()) {
        Message out = exchange.getOut();
        out.copyFrom(exchange.getIn());
        return out;
    }
    return exchange.getIn();
}
Also used : Message(org.apache.camel.Message)

Aggregations

Message (org.apache.camel.Message)721 Exchange (org.apache.camel.Exchange)341 Test (org.junit.Test)215 Processor (org.apache.camel.Processor)118 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)104 DefaultMessage (org.apache.camel.impl.DefaultMessage)51 DefaultExchange (org.apache.camel.impl.DefaultExchange)44 Endpoint (org.apache.camel.Endpoint)40 Response (javax.ws.rs.core.Response)38 InputStream (java.io.InputStream)36 HashMap (java.util.HashMap)35 ArrayList (java.util.ArrayList)26 RouteBuilder (org.apache.camel.builder.RouteBuilder)25 Customer (org.apache.camel.component.cxf.jaxrs.testbean.Customer)25 ActionResponse (org.openstack4j.model.common.ActionResponse)25 IOException (java.io.IOException)24 Map (java.util.Map)24 DataHandler (javax.activation.DataHandler)21 Producer (org.apache.camel.Producer)21 CxfOperationException (org.apache.camel.component.cxf.CxfOperationException)19