Search in sources :

Example 36 with AmazonClientException

use of com.amazonaws.AmazonClientException in project teiid by teiid.

the class SimpleDBConnectionImpl method performSelect.

/**
 * Performs select expression. This expression must be in format which is understandable to SimpleDB database
 * @param selectExpression
 * @param columns
 * @return Iterator of List<String> results
 */
@Override
public SelectResult performSelect(String selectExpression, String nextToken) throws TranslatorException {
    try {
        SelectRequest selectRequest = new SelectRequest(selectExpression);
        if (nextToken != null) {
            selectRequest.setNextToken(nextToken);
        }
        selectRequest.setConsistentRead(true);
        return client.select(selectRequest);
    } catch (AmazonServiceException e) {
        throw new TranslatorException(e);
    } catch (AmazonClientException e) {
        throw new TranslatorException(e);
    }
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) AmazonServiceException(com.amazonaws.AmazonServiceException) TranslatorException(org.teiid.translator.TranslatorException)

Example 37 with AmazonClientException

use of com.amazonaws.AmazonClientException in project teiid by teiid.

the class SimpleDBConnectionImpl method performUpdate.

/**
 *  Performs update on given domain and items
 * @param domainName
 * @param items
 */
@Override
public int performUpdate(String domainName, Map<String, Object> updateAttributes, String selectExpression) throws TranslatorException {
    try {
        List<ReplaceableAttribute> attributes = new ArrayList<ReplaceableAttribute>();
        for (Map.Entry<String, Object> column : updateAttributes.entrySet()) {
            addAttribute(column.getKey(), column.getValue(), attributes);
        }
        List<ReplaceableItem> updateItems = new ArrayList<ReplaceableItem>();
        int count = 0;
        String nextToken = null;
        do {
            SelectResult result = performSelect(selectExpression, nextToken);
            nextToken = result.getNextToken();
            Iterator<Item> iter = result.getItems().iterator();
            while (iter.hasNext()) {
                Item item = iter.next();
                updateItems.add(new ReplaceableItem(item.getName(), attributes));
                count++;
                if (count % 25 == 0) {
                    executeBatch(domainName, updateItems);
                    updateItems.clear();
                }
            }
            executeBatch(domainName, updateItems);
        } while (nextToken != null);
        return count;
    } catch (AmazonServiceException e) {
        throw new TranslatorException(e);
    } catch (AmazonClientException e) {
        throw new TranslatorException(e);
    }
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) ArrayList(java.util.ArrayList) AmazonServiceException(com.amazonaws.AmazonServiceException) TranslatorException(org.teiid.translator.TranslatorException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 38 with AmazonClientException

use of com.amazonaws.AmazonClientException in project opencast by opencast.

the class AwsS3DistributionServiceImpl method retractElement.

/**
 * Retracts the media package element with the given identifier from the distribution channel.
 *
 * @param channelId
 *          the channel id
 * @param mediaPackage
 *          the media package
 * @param element
 *          the element
 * @return the retracted element or <code>null</code> if the element was not retracted
 */
protected MediaPackageElement retractElement(String channelId, MediaPackage mediaPackage, MediaPackageElement element) throws DistributionException {
    notNull(mediaPackage, "mediaPackage");
    notNull(element, "element");
    try {
        String objectName = getDistributedObjectName(element);
        if (objectName != null) {
            s3.deleteObject(bucketName, objectName);
            logger.info("Retracted element {}, object {}", element.getIdentifier(), objectName);
        }
        return element;
    } catch (AmazonClientException e) {
        throw new DistributionException("AWS error: " + e.getMessage(), e);
    }
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) DistributionException(org.opencastproject.distribution.api.DistributionException)

Example 39 with AmazonClientException

use of com.amazonaws.AmazonClientException in project spring-integration-aws by spring-projects.

the class S3MessageHandler method handleRequestMessage.

@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
    Command command = this.commandExpression.getValue(this.evaluationContext, requestMessage, Command.class);
    Assert.state(command != null, "'commandExpression' [" + this.commandExpression.getExpressionString() + "] cannot evaluate to null.");
    Transfer transfer = null;
    switch(command) {
        case UPLOAD:
            transfer = upload(requestMessage);
            break;
        case DOWNLOAD:
            transfer = download(requestMessage);
            break;
        case COPY:
            transfer = copy(requestMessage);
            break;
    }
    if (this.produceReply) {
        return transfer;
    } else {
        try {
            AmazonClientException amazonClientException = transfer.waitForException();
            if (amazonClientException != null) {
                throw amazonClientException;
            }
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        return null;
    }
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) PersistableTransfer(com.amazonaws.services.s3.transfer.PersistableTransfer) Transfer(com.amazonaws.services.s3.transfer.Transfer)

Example 40 with AmazonClientException

use of com.amazonaws.AmazonClientException in project thunder by RohanNagar.

the class UsersDao method insert.

/**
 * Insert a new PilotUser into the data store.
 *
 * @param user The object to insert.
 * @return The PilotUser object that was created.
 * @throws DatabaseException If the user already exists or if the database is down.
 */
public PilotUser insert(PilotUser user) {
    checkNotNull(user);
    long now = Instant.now().toEpochMilli();
    Item item = new Item().withPrimaryKey("email", user.getEmail().getAddress()).withString("id", UUID.randomUUID().toString()).withString("version", UUID.randomUUID().toString()).withLong("creation_time", now).withLong("update_time", now).withJSON("document", toJson(mapper, user));
    try {
        table.putItem(item, new Expected("email").notExist());
    } catch (ConditionalCheckFailedException e) {
        LOG.error("The user {} already exists in the database. Throwing DatabaseException.", user.getEmail());
        throw new DatabaseException("The user already exists.", DatabaseError.CONFLICT);
    } catch (AmazonServiceException e) {
        LOG.error("The database rejected the create request.", e);
        throw new DatabaseException("The database rejected the create request.", DatabaseError.REQUEST_REJECTED);
    } catch (AmazonClientException e) {
        LOG.error("The database is currently unresponsive.", e);
        throw new DatabaseException("The database is currently unavailable.", DatabaseError.DATABASE_DOWN);
    }
    return user;
}
Also used : Item(com.amazonaws.services.dynamodbv2.document.Item) Expected(com.amazonaws.services.dynamodbv2.document.Expected) AmazonClientException(com.amazonaws.AmazonClientException) AmazonServiceException(com.amazonaws.AmazonServiceException) ConditionalCheckFailedException(com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException)

Aggregations

AmazonClientException (com.amazonaws.AmazonClientException)202 IOException (java.io.IOException)70 AmazonServiceException (com.amazonaws.AmazonServiceException)32 ArrayList (java.util.ArrayList)32 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)23 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)19 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)17 HashMap (java.util.HashMap)16 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)14 Test (org.junit.Test)14 SienaException (siena.SienaException)12 AWSCredentials (com.amazonaws.auth.AWSCredentials)11 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)11 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)11 ListObjectsRequest (com.amazonaws.services.s3.model.ListObjectsRequest)11 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)10 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)10 InterruptedIOException (java.io.InterruptedIOException)10 DeleteObjectsRequest (com.amazonaws.services.s3.model.DeleteObjectsRequest)9 File (java.io.File)9