Search in sources :

Example 56 with AmazonClientException

use of com.amazonaws.AmazonClientException in project siena by mandubian.

the class SdbPersistenceManager method deleteByKeys.

@Override
public <T> int deleteByKeys(Class<T> clazz, Iterable<?> keys) {
    List<DeletableItem> doList = new ArrayList<DeletableItem>();
    int nb = 0;
    String domain = SdbMappingUtils.getDomainName(clazz, prefix);
    for (Object key : keys) {
        doList.add(SdbMappingUtils.createDeletableItemFromKey(clazz, key));
        nb++;
    }
    try {
        checkDomain(domain);
        int len = doList.size() > MAX_ITEMS_PER_CALL ? MAX_ITEMS_PER_CALL : doList.size();
        for (int i = 0; i < doList.size(); i += len) {
            int sz = i + len;
            if (sz > doList.size()) {
                sz = doList.size();
            }
            sdb.batchDeleteAttributes(new BatchDeleteAttributesRequest(domain, doList.subList(i, sz)));
        }
    } catch (AmazonClientException ex) {
        throw new SienaException(ex);
    }
    return nb;
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) ArrayList(java.util.ArrayList) BatchDeleteAttributesRequest(com.amazonaws.services.simpledb.model.BatchDeleteAttributesRequest) DeletableItem(com.amazonaws.services.simpledb.model.DeletableItem) SienaException(siena.SienaException)

Example 57 with AmazonClientException

use of com.amazonaws.AmazonClientException in project siena by mandubian.

the class SdbPersistenceManager method rawGet.

protected <T> int rawGet(Iterable<T> models) {
    StringBuffer domainBuf = new StringBuffer();
    SelectRequest req = SdbMappingUtils.buildBatchGetQuery(models, prefix, domainBuf);
    req.setConsistentRead(isReadConsistent());
    try {
        checkDomain(domainBuf.toString());
        SelectResult res = sdb.select(req);
        int nb = SdbMappingUtils.mapSelectResult(res, models);
        // join management
        // gets class
        Class<?> clazz = null;
        for (T obj : models) {
            if (clazz == null) {
                clazz = obj.getClass();
                break;
            }
        }
        if (!ClassInfo.getClassInfo(clazz).joinFields.isEmpty()) {
            mapJoins(models);
        }
        return nb;
    } catch (AmazonClientException ex) {
        throw new SienaException(ex);
    }
}
Also used : SelectResult(com.amazonaws.services.simpledb.model.SelectResult) AmazonClientException(com.amazonaws.AmazonClientException) SienaException(siena.SienaException) SelectRequest(com.amazonaws.services.simpledb.model.SelectRequest)

Example 58 with AmazonClientException

use of com.amazonaws.AmazonClientException in project siena by mandubian.

the class SdbPersistenceManager method update.

public <T> int update(Iterable<T> models) {
    Map<String, List<ReplaceableItem>> doMap = new HashMap<String, List<ReplaceableItem>>();
    int nb = 0;
    for (Object obj : models) {
        Class<?> clazz = obj.getClass();
        String domain = SdbMappingUtils.getDomainName(clazz, prefix);
        List<ReplaceableItem> doList = doMap.get(domain);
        if (doList == null) {
            doList = new ArrayList<ReplaceableItem>();
            doMap.put(domain, doList);
        }
        doList.add(SdbMappingUtils.createItem(obj));
        nb++;
    }
    try {
        for (String domain : doMap.keySet()) {
            checkDomain(domain);
            List<ReplaceableItem> doList = doMap.get(domain);
            int len = doList.size() > MAX_ITEMS_PER_CALL ? MAX_ITEMS_PER_CALL : doList.size();
            for (int i = 0; i < doList.size(); i += len) {
                int sz = i + len;
                if (sz > doList.size()) {
                    sz = doList.size();
                }
                sdb.batchPutAttributes(new BatchPutAttributesRequest(domain, doList.subList(i, sz)));
            }
        }
    } catch (AmazonClientException ex) {
        throw new SienaException(ex);
    }
    return nb;
}
Also used : HashMap(java.util.HashMap) AmazonClientException(com.amazonaws.AmazonClientException) ReplaceableItem(com.amazonaws.services.simpledb.model.ReplaceableItem) BatchPutAttributesRequest(com.amazonaws.services.simpledb.model.BatchPutAttributesRequest) ArrayList(java.util.ArrayList) List(java.util.List) SienaException(siena.SienaException)

Example 59 with AmazonClientException

use of com.amazonaws.AmazonClientException in project siena by mandubian.

the class SdbPersistenceManager method insert.

@Override
public int insert(Iterable<?> objects) {
    Map<String, List<ReplaceableItem>> doMap = new HashMap<String, List<ReplaceableItem>>();
    int nb = 0;
    for (Object obj : objects) {
        Class<?> clazz = obj.getClass();
        String domain = SdbMappingUtils.getDomainName(clazz, prefix);
        List<ReplaceableItem> doList = doMap.get(domain);
        if (doList == null) {
            doList = new ArrayList<ReplaceableItem>();
            doMap.put(domain, doList);
        }
        doList.add(SdbMappingUtils.createItem(obj));
        nb++;
    }
    try {
        for (String domain : doMap.keySet()) {
            checkDomain(domain);
            List<ReplaceableItem> doList = doMap.get(domain);
            int len = doList.size() > MAX_ITEMS_PER_CALL ? MAX_ITEMS_PER_CALL : doList.size();
            for (int i = 0; i < doList.size(); i += len) {
                int sz = i + len;
                if (sz > doList.size()) {
                    sz = doList.size();
                }
                sdb.batchPutAttributes(new BatchPutAttributesRequest(domain, doList.subList(i, sz)));
            }
        }
    } catch (AmazonClientException ex) {
        throw new SienaException(ex);
    }
    return nb;
}
Also used : HashMap(java.util.HashMap) AmazonClientException(com.amazonaws.AmazonClientException) ReplaceableItem(com.amazonaws.services.simpledb.model.ReplaceableItem) BatchPutAttributesRequest(com.amazonaws.services.simpledb.model.BatchPutAttributesRequest) ArrayList(java.util.ArrayList) List(java.util.List) SienaException(siena.SienaException)

Example 60 with AmazonClientException

use of com.amazonaws.AmazonClientException in project beam by apache.

the class S3FileSystem method expandGlob.

private ExpandedGlob expandGlob(S3ResourceId glob) {
    // The S3 API can list objects, filtered by prefix, but not by wildcard.
    // Here, we find the longest prefix without wildcard "*",
    // then filter the results with a regex.
    checkArgument(glob.isWildcard(), "isWildcard");
    String keyPrefix = glob.getKeyNonWildcardPrefix();
    Pattern wildcardRegexp = Pattern.compile(wildcardToRegexp(glob.getKey()));
    LOG.debug("expanding bucket {}, prefix {}, against pattern {}", glob.getBucket(), keyPrefix, wildcardRegexp.toString());
    ImmutableList.Builder<S3ResourceId> expandedPaths = ImmutableList.builder();
    String continuationToken = null;
    do {
        ListObjectsV2Request request = new ListObjectsV2Request().withBucketName(glob.getBucket()).withPrefix(keyPrefix).withContinuationToken(continuationToken);
        ListObjectsV2Result result;
        try {
            result = amazonS3.get().listObjectsV2(request);
        } catch (AmazonClientException e) {
            return ExpandedGlob.create(glob, new IOException(e));
        }
        continuationToken = result.getNextContinuationToken();
        for (S3ObjectSummary objectSummary : result.getObjectSummaries()) {
            // Filter against regex.
            if (wildcardRegexp.matcher(objectSummary.getKey()).matches()) {
                S3ResourceId expandedPath = S3ResourceId.fromComponents(glob.getScheme(), objectSummary.getBucketName(), objectSummary.getKey()).withSize(objectSummary.getSize()).withLastModified(objectSummary.getLastModified());
                LOG.debug("Expanded S3 object path {}", expandedPath);
                expandedPaths.add(expandedPath);
            }
        }
    } while (continuationToken != null);
    return ExpandedGlob.create(glob, expandedPaths.build());
}
Also used : Pattern(java.util.regex.Pattern) ListObjectsV2Request(com.amazonaws.services.s3.model.ListObjectsV2Request) ListObjectsV2Result(com.amazonaws.services.s3.model.ListObjectsV2Result) ImmutableList(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList) AmazonClientException(com.amazonaws.AmazonClientException) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) IOException(java.io.IOException)

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