Search in sources :

Example 6 with AmazonServiceException

use of com.amazonaws.AmazonServiceException 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 7 with AmazonServiceException

use of com.amazonaws.AmazonServiceException 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 8 with AmazonServiceException

use of com.amazonaws.AmazonServiceException 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 9 with AmazonServiceException

use of com.amazonaws.AmazonServiceException in project camel by apache.

the class DdbEndpoint method waitForTableToBecomeAvailable.

private void waitForTableToBecomeAvailable(String tableName) {
    LOG.trace("Waiting for [{}] to become ACTIVE...", tableName);
    long waitTime = 5 * 60 * 1000;
    while (waitTime > 0) {
        try {
            Thread.sleep(1000 * 5);
            waitTime -= 5000;
        } catch (Exception e) {
        }
        try {
            DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
            TableDescription tableDescription = getDdbClient().describeTable(request).getTable();
            if (isTableActive(tableDescription)) {
                LOG.trace("Table [{}] became active", tableName);
                return;
            }
            LOG.trace("Table [{}] not active yet", tableName);
        } catch (AmazonServiceException ase) {
            if (!ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException")) {
                throw ase;
            }
        }
    }
    throw new RuntimeException("Table " + tableName + " never went active");
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) AmazonServiceException(com.amazonaws.AmazonServiceException) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)

Example 10 with AmazonServiceException

use of com.amazonaws.AmazonServiceException in project camel by apache.

the class AmazonEC2ClientMock method startInstances.

@Override
public StartInstancesResult startInstances(StartInstancesRequest startInstancesRequest) {
    StartInstancesResult result = new StartInstancesResult();
    if (startInstancesRequest.getInstanceIds().get(0).equals("test-1")) {
        Collection<InstanceStateChange> coll = new ArrayList<InstanceStateChange>();
        InstanceStateChange sc = new InstanceStateChange();
        InstanceState previousState = new InstanceState();
        previousState.setCode(80);
        previousState.setName(InstanceStateName.Stopped);
        InstanceState newState = new InstanceState();
        newState.setCode(16);
        newState.setName(InstanceStateName.Running);
        sc.setPreviousState(previousState);
        sc.setCurrentState(newState);
        sc.setInstanceId("test-1");
        coll.add(sc);
        result.setStartingInstances(coll);
    } else {
        throw new AmazonServiceException("The image-id doesn't exists");
    }
    return result;
}
Also used : InstanceState(com.amazonaws.services.ec2.model.InstanceState) StartInstancesResult(com.amazonaws.services.ec2.model.StartInstancesResult) ArrayList(java.util.ArrayList) AmazonServiceException(com.amazonaws.AmazonServiceException) InstanceStateChange(com.amazonaws.services.ec2.model.InstanceStateChange)

Aggregations

AmazonServiceException (com.amazonaws.AmazonServiceException)109 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)21 AmazonS3 (com.amazonaws.services.s3.AmazonS3)15 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)15 AmazonClientException (com.amazonaws.AmazonClientException)13 IOException (java.io.IOException)12 Collection (java.util.Collection)12 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)11 File (java.io.File)10 Message (org.apache.camel.Message)10 ArrayList (java.util.ArrayList)8 S3Object (com.amazonaws.services.s3.model.S3Object)7 TransferManager (com.amazonaws.services.s3.transfer.TransferManager)7 FileNotFoundException (java.io.FileNotFoundException)7 Copy (com.amazonaws.services.s3.transfer.Copy)6 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)5 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)5 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)5 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)4 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)4