Search in sources :

Example 16 with AmazonClientException

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

the class S3Client method put.

public void put(InputStream inputStream, Long contentLength, URI destination) {
    checkRequiredJigsawModuleIsOnPath();
    try {
        S3RegionalResource s3RegionalResource = new S3RegionalResource(destination);
        String bucketName = s3RegionalResource.getBucketName();
        String s3BucketKey = s3RegionalResource.getKey();
        configureClient(s3RegionalResource);
        ObjectMetadata objectMetadata = new ObjectMetadata();
        objectMetadata.setContentLength(contentLength);
        PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, s3BucketKey, inputStream, objectMetadata);
        LOGGER.debug("Attempting to put resource:[{}] into s3 bucket [{}]", s3BucketKey, bucketName);
        amazonS3Client.putObject(putObjectRequest);
    } catch (AmazonClientException e) {
        throw ResourceExceptions.putFailed(destination, e);
    }
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 17 with AmazonClientException

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

the class S3CheckpointSpi method removeCheckpoint.

/**
 * {@inheritDoc}
 */
@Override
public boolean removeCheckpoint(String key) {
    assert !F.isEmpty(key);
    timeoutWrk.remove(key);
    boolean rmv = false;
    try {
        rmv = delete(key);
    } catch (AmazonClientException e) {
        U.error(log, "Failed to delete data by key: " + key, e);
    }
    if (rmv) {
        CheckpointListener tmpLsnr = lsnr;
        if (tmpLsnr != null)
            tmpLsnr.onCheckpointRemoved(key);
    }
    return rmv;
}
Also used : CheckpointListener(org.apache.ignite.spi.checkpoint.CheckpointListener) AmazonClientException(com.amazonaws.AmazonClientException)

Example 18 with AmazonClientException

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

the class S3CheckpointSpi method saveCheckpoint.

/**
 * {@inheritDoc}
 */
@Override
public boolean saveCheckpoint(String key, byte[] state, long timeout, boolean overwrite) throws IgniteSpiException {
    assert !F.isEmpty(key);
    long expireTime = 0;
    if (timeout > 0) {
        expireTime = U.currentTimeMillis() + timeout;
        if (expireTime < 0)
            expireTime = Long.MAX_VALUE;
    }
    try {
        if (hasKey(key)) {
            if (!overwrite)
                return false;
            if (log.isDebugEnabled())
                log.debug("Overriding existing key: " + key);
        }
        S3CheckpointData data = new S3CheckpointData(state, expireTime, key);
        write(data);
    } catch (AmazonClientException e) {
        throw new IgniteSpiException("Failed to write checkpoint data [key=" + key + ", state=" + Arrays.toString(state) + ']', e);
    } catch (IgniteCheckedException e) {
        throw new IgniteSpiException("Failed to marshal checkpoint data [key=" + key + ", state=" + Arrays.toString(state) + ']', e);
    }
    if (timeout > 0)
        timeoutWrk.add(new S3TimeData(expireTime, key));
    return true;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AmazonClientException(com.amazonaws.AmazonClientException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 19 with AmazonClientException

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

the class S3CheckpointSpi method spiStart.

/**
 * {@inheritDoc}
 */
@SuppressWarnings({ "BusyWait" })
@Override
public void spiStart(String igniteInstanceName) throws IgniteSpiException {
    // Start SPI start stopwatch.
    startStopwatch();
    assertParameter(cred != null, "awsCredentials != null");
    if (log.isDebugEnabled()) {
        log.debug(configInfo("awsCredentials", cred));
        log.debug(configInfo("clientConfiguration", cfg));
        log.debug(configInfo("bucketNameSuffix", bucketNameSuffix));
        log.debug(configInfo("bucketEndpoint", bucketEndpoint));
        log.debug(configInfo("SSEAlgorithm", sseAlg));
    }
    if (cfg == null)
        U.warn(log, "Amazon client configuration is not set (will use default).");
    if (F.isEmpty(bucketNameSuffix)) {
        U.warn(log, "Bucket name suffix is null or empty (will use default bucket name).");
        bucketName = BUCKET_NAME_PREFIX + DFLT_BUCKET_NAME_SUFFIX;
    } else
        bucketName = BUCKET_NAME_PREFIX + bucketNameSuffix;
    s3 = cfg != null ? new AmazonS3Client(cred, cfg) : new AmazonS3Client(cred);
    if (!F.isEmpty(bucketEndpoint))
        s3.setEndpoint(bucketEndpoint);
    if (!s3.doesBucketExist(bucketName)) {
        try {
            s3.createBucket(bucketName);
            if (log.isDebugEnabled())
                log.debug("Created S3 bucket: " + bucketName);
            while (!s3.doesBucketExist(bucketName)) try {
                U.sleep(200);
            } catch (IgniteInterruptedCheckedException e) {
                throw new IgniteSpiException("Thread has been interrupted.", e);
            }
        } catch (AmazonClientException e) {
            try {
                if (!s3.doesBucketExist(bucketName))
                    throw new IgniteSpiException("Failed to create bucket: " + bucketName, e);
            } catch (AmazonClientException ignored) {
                throw new IgniteSpiException("Failed to create bucket: " + bucketName, e);
            }
        }
    }
    Collection<S3TimeData> s3TimeDataLst = new LinkedList<>();
    try {
        ObjectListing list = s3.listObjects(bucketName);
        while (true) {
            for (S3ObjectSummary sum : list.getObjectSummaries()) {
                S3CheckpointData data = read(sum.getKey());
                if (data != null) {
                    s3TimeDataLst.add(new S3TimeData(data.getExpireTime(), data.getKey()));
                    if (log.isDebugEnabled())
                        log.debug("Registered existing checkpoint from key: " + data.getKey());
                }
            }
            if (list.isTruncated())
                list = s3.listNextBatchOfObjects(list);
            else
                break;
        }
    } catch (AmazonClientException e) {
        throw new IgniteSpiException("Failed to read checkpoint bucket: " + bucketName, e);
    } catch (IgniteCheckedException e) {
        throw new IgniteSpiException("Failed to marshal/unmarshal objects in bucket: " + bucketName, e);
    }
    // Track expiration for only those data that are made by this node
    timeoutWrk = new S3TimeoutWorker();
    timeoutWrk.add(s3TimeDataLst);
    timeoutWrk.start();
    registerMBean(igniteInstanceName, new S3CheckpointSpiMBeanImpl(this), S3CheckpointSpiMBean.class);
    // Ack ok start.
    if (log.isDebugEnabled())
        log.debug(startInfo());
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) LinkedList(java.util.LinkedList) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 20 with AmazonClientException

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

the class TcpDiscoveryS3IpFinder method getRegisteredAddresses.

/**
 * {@inheritDoc}
 */
@Override
public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException {
    initClient();
    Collection<InetSocketAddress> addrs = new LinkedList<>();
    try {
        ObjectListing list = s3.listObjects(bucketName);
        while (true) {
            for (S3ObjectSummary sum : list.getObjectSummaries()) {
                String key = sum.getKey();
                StringTokenizer st = new StringTokenizer(key, DELIM);
                if (st.countTokens() != 2)
                    U.error(log, "Failed to parse S3 entry due to invalid format: " + key);
                else {
                    String addrStr = st.nextToken();
                    String portStr = st.nextToken();
                    int port = -1;
                    try {
                        port = Integer.parseInt(portStr);
                    } catch (NumberFormatException e) {
                        U.error(log, "Failed to parse port for S3 entry: " + key, e);
                    }
                    if (port != -1)
                        try {
                            addrs.add(new InetSocketAddress(addrStr, port));
                        } catch (IllegalArgumentException e) {
                            U.error(log, "Failed to parse port for S3 entry: " + key, e);
                        }
                }
            }
            if (list.isTruncated())
                list = s3.listNextBatchOfObjects(list);
            else
                break;
        }
    } catch (AmazonClientException e) {
        throw new IgniteSpiException("Failed to list objects in the bucket: " + bucketName, e);
    }
    return addrs;
}
Also used : StringTokenizer(java.util.StringTokenizer) InetSocketAddress(java.net.InetSocketAddress) AmazonClientException(com.amazonaws.AmazonClientException) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) LinkedList(java.util.LinkedList)

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