Example usage for com.amazonaws AmazonClientException AmazonClientException

List of usage examples for com.amazonaws AmazonClientException AmazonClientException

Introduction

In this page you can find the example usage for com.amazonaws AmazonClientException AmazonClientException.

Prototype

public AmazonClientException(Throwable t) 

Source Link

Usage

From source file:org.apache.hadoop.fs.s3a.BasicAWSCredentialsProvider.java

License:Apache License

public AWSCredentials getCredentials() {
    if (accessKey != null && secretKey != null) {
        return new BasicAWSCredentials(accessKey, secretKey);
    }//from   w w  w.j  a  va2 s . c o  m

    throw new AmazonClientException("Access key or secret key is null");
}

From source file:org.apache.jackrabbit.oak.blob.cloud.aws.s3.S3Backend.java

License:Apache License

public void init(CachingDataStore store, String homeDir, Properties prop) throws DataStoreException {

    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {/*from  ww w  .  j a v  a2 s .c o  m*/
        startTime = new Date();
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        LOG.debug("init");
        this.store = store;
        s3ReqDecorator = new S3RequestDecorator(prop);
        s3service = Utils.openService(prop);
        if (bucket == null || "".equals(bucket.trim())) {
            bucket = prop.getProperty(S3Constants.S3_BUCKET);
        }
        String region = prop.getProperty(S3Constants.S3_REGION);
        Region s3Region = null;
        if (StringUtils.isNullOrEmpty(region)) {
            com.amazonaws.regions.Region ec2Region = Regions.getCurrentRegion();
            if (ec2Region != null) {
                s3Region = Region.fromValue(ec2Region.getName());
            } else {
                throw new AmazonClientException("parameter [" + S3Constants.S3_REGION
                        + "] not configured and cannot be derived from environment");
            }
        } else {
            if (Utils.DEFAULT_AWS_BUCKET_REGION.equals(region)) {
                s3Region = Region.US_Standard;
            } else if (Region.EU_Ireland.toString().equals(region)) {
                s3Region = Region.EU_Ireland;
            } else {
                s3Region = Region.fromValue(region);
            }
        }

        if (!s3service.doesBucketExist(bucket)) {
            s3service.createBucket(bucket, s3Region);
            LOG.info("Created bucket [{}] in [{}] ", bucket, region);
        } else {
            LOG.info("Using bucket [{}] in [{}] ", bucket, region);
        }

        int writeThreads = 10;
        String writeThreadsStr = prop.getProperty(S3Constants.S3_WRITE_THREADS);
        if (writeThreadsStr != null) {
            writeThreads = Integer.parseInt(writeThreadsStr);
        }
        LOG.info("Using thread pool of [{}] threads in S3 transfer manager.", writeThreads);
        tmx = new TransferManager(s3service, (ThreadPoolExecutor) Executors.newFixedThreadPool(writeThreads,
                new NamedThreadFactory("s3-transfer-manager-worker")));

        int asyncWritePoolSize = 10;
        String maxConnsStr = prop.getProperty(S3Constants.S3_MAX_CONNS);
        if (maxConnsStr != null) {
            asyncWritePoolSize = Integer.parseInt(maxConnsStr) - writeThreads;
        }

        asyncWriteExecuter = (ThreadPoolExecutor) Executors.newFixedThreadPool(asyncWritePoolSize,
                new NamedThreadFactory("s3-write-worker"));
        String renameKeyProp = prop.getProperty(S3Constants.S3_RENAME_KEYS);
        boolean renameKeyBool = (renameKeyProp == null || "".equals(renameKeyProp)) ? false
                : Boolean.parseBoolean(renameKeyProp);
        LOG.info("Rename keys [{}]", renameKeyBool);
        if (renameKeyBool) {
            renameKeys();
        }
        LOG.debug("S3 Backend initialized in [{}] ms", +(System.currentTimeMillis() - startTime.getTime()));
    } catch (Exception e) {
        LOG.debug("  error ", e);
        Map<String, String> filteredMap = Maps.newHashMap();
        if (prop != null) {
            filteredMap = Maps.filterKeys(Maps.fromProperties(prop), new Predicate<String>() {
                @Override
                public boolean apply(String input) {
                    return !input.equals(S3Constants.ACCESS_KEY) && !input.equals(S3Constants.SECRET_KEY);
                }
            });
        }
        throw new DataStoreException("Could not initialize S3 from " + filteredMap, e);
    } finally {
        if (contextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
}

From source file:org.apache.jackrabbit.oak.blob.cloud.aws.s3.Utils.java

License:Apache License

/**
 * Create AmazonS3Client from properties.
 * /*from  ww w  .java 2 s . co m*/
 * @param prop properties to configure @link {@link AmazonS3Client}
 * @return {@link AmazonS3Client}
 */
public static AmazonS3Client openService(final Properties prop) {
    String accessKey = prop.getProperty(S3Constants.ACCESS_KEY);
    String secretKey = prop.getProperty(S3Constants.SECRET_KEY);
    AmazonS3Client s3service = null;
    if (StringUtils.isNullOrEmpty(accessKey) || StringUtils.isNullOrEmpty(secretKey)) {
        LOG.info("Configuring Amazon Client from environment");
        s3service = new AmazonS3Client(getClientConfiguration(prop));
    } else {
        LOG.info("Configuring Amazon Client from property file.");
        AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
        s3service = new AmazonS3Client(credentials, getClientConfiguration(prop));
    }
    String region = prop.getProperty(S3Constants.S3_REGION);
    String endpoint = null;
    String propEndPoint = prop.getProperty(S3Constants.S3_END_POINT);
    if ((propEndPoint != null) & !"".equals(propEndPoint)) {
        endpoint = propEndPoint;
    } else {
        if (StringUtils.isNullOrEmpty(region)) {
            com.amazonaws.regions.Region s3Region = Regions.getCurrentRegion();
            if (s3Region != null) {
                region = s3Region.getName();
            } else {
                throw new AmazonClientException("parameter [" + S3Constants.S3_REGION
                        + "] not configured and cannot be derived from environment");
            }
        }
        if (DEFAULT_AWS_BUCKET_REGION.equals(region)) {
            endpoint = S3 + DOT + AWSDOTCOM;
        } else if (Region.EU_Ireland.toString().equals(region)) {
            endpoint = "s3-eu-west-1" + DOT + AWSDOTCOM;
        } else {
            endpoint = S3 + DASH + region + DOT + AWSDOTCOM;
        }
    }
    /*
     * setting endpoint to remove latency of redirection. If endpoint is
     * not set, invocation first goes us standard region, which
     * redirects it to correct location.
     */
    s3service.setEndpoint(endpoint);
    LOG.info("S3 service endpoint [{}] ", endpoint);
    return s3service;
}

From source file:org.apache.tajo.storage.s3.BasicAWSCredentialsProvider.java

License:Apache License

public AWSCredentials getCredentials() {
    if (!StringUtils.isEmpty(accessKey) && !StringUtils.isEmpty(secretKey)) {
        return new BasicAWSCredentials(accessKey, secretKey);
    }/*from   w  w w . j a v  a2 s.  c  om*/
    throw new AmazonClientException("Access key or secret key is null");
}

From source file:org.apache.usergrid.persistence.queue.impl.UsergridAwsCredentials.java

License:Apache License

public String getAWSAccessKeyIdJson(Map<String, Object> jsonObject) {
    String accessKey = (String) jsonObject.get(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR);
    if (StringUtils.isEmpty(accessKey)) {
        accessKey = (String) jsonObject.get(SDKGlobalConfiguration.ALTERNATE_ACCESS_KEY_ENV_VAR);
    }/*w  w w  .  j  a va2s  .  c o m*/

    if (StringUtils.isEmpty(accessKey)) {
        throw new AmazonClientException("Could not get aws access key from json object.");
    }

    return StringUtils.trim(accessKey);
}

From source file:org.apache.usergrid.persistence.queue.impl.UsergridAwsCredentials.java

License:Apache License

public String getAWSSecretKeyJson(Map<String, Object> jsonObject) {
    String secretKey = (String) jsonObject.get(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR);
    if (StringUtils.isEmpty(secretKey)) {
        secretKey = (String) jsonObject.get(SDKGlobalConfiguration.ALTERNATE_SECRET_KEY_ENV_VAR);
    }/*ww w  .  j  a  v  a2  s.  c  o m*/
    if (StringUtils.isEmpty(secretKey)) {
        throw new AmazonClientException("Could not get aws secret key from json object.");
    }
    return StringUtils.trim(secretKey);
}

From source file:org.apache.usergrid.persistence.queue.impl.UsergridAwsCredentialsProvider.java

License:Apache License

private void init() {
    if (StringUtils.isEmpty(creds.getAWSAccessKeyId())) {
        throw new AmazonClientException("could not get aws access key from system properties");
    }// w  ww  .j  a  v  a 2 s  . c o m
    if (StringUtils.isEmpty(creds.getAWSSecretKey())) {
        throw new AmazonClientException("could not get aws secret key from system properties");
    }
}

From source file:org.flite.mock.amazonaws.sqs.AmazonSQSMock.java

License:Open Source License

public GetQueueUrlResult getQueueUrl(final GetQueueUrlRequest request)
        throws AmazonServiceException, AmazonClientException {
    if (request == null) {
        throw new AmazonClientException("Null GetQueueUrlRequest");
    }/*w  w w  . j  ava2 s.  c  om*/
    final String queueName = request.getQueueName();
    final String queueUrl = QUEUE_URL_PREFIX + queueName;
    checkURLForException(queueUrl);
    // Per documentation, supposedly throws QueueDoesNotExistException,
    // but in my tests, they actually just throw AmazonServiceException
    if (!allQueues.containsKey(queueUrl)) {
        throw new AmazonServiceException("Queue Not Found: " + queueUrl);
    }
    return new GetQueueUrlResult().withQueueUrl(queueUrl);
}

From source file:org.flite.mock.amazonaws.sqs.AmazonSQSMock.java

License:Open Source License

public CreateQueueResult createQueue(final CreateQueueRequest request)
        throws AmazonServiceException, AmazonClientException {
    if (request == null) {
        throw new AmazonClientException("Null CreateQueueRequest");
    }/*from  w  w  w  .jav  a 2  s  .co  m*/
    final String queueName = request.getQueueName();
    if (StringUtils.isBlank(queueName) || queueName.length() > 80) {
        throw new AmazonServiceException("Invalid queue name: " + queueName);
    }
    final String queueUrl = QUEUE_URL_PREFIX + queueName;
    checkURLForException(queueUrl);
    // Per documentation, throws QueueNameExistsException, but in my testing, they actually
    // just quietly return the CreateQueueResult
    // (Also note: we are ignoring the documented exception: QueueDeletedRecentlyException)
    if (!allQueues.containsKey(queueUrl)) {
        allQueues.put(queueUrl, Collections.synchronizedList(new ArrayList<Message>()));
        retrievedMessages.put(queueUrl, new ConcurrentHashMap<String, Message>());
    }
    return new CreateQueueResult().withQueueUrl(queueUrl);
}

From source file:org.flite.mock.amazonaws.sqs.AmazonSQSMock.java

License:Open Source License

public SendMessageResult sendMessage(final SendMessageRequest request)
        throws AmazonServiceException, AmazonClientException {
    if (request == null) {
        throw new AmazonClientException("Null SendMessageRequest");
    }//from   ww  w  .j a va 2  s.c om
    final String queueUrl = request.getQueueUrl();
    checkURLForException(queueUrl);
    checkStringForExceptionMarker(request.getMessageBody());
    // Ignoring the following exception: InvalidMessageContentsException (thrown for character set conditions?)
    if (!allQueues.containsKey(queueUrl)) {
        throw new AmazonServiceException("Queue Not Found: " + queueUrl);
    }
    final Long seq = incrementer.getAndIncrement();
    final Message msg = new Message().withBody(StringUtils.defaultString(request.getMessageBody()))
            .withMD5OfBody(makeMD5(request.getMessageBody())).withMessageId(MESSAGE_ID_PREFIX + seq);
    allQueues.get(queueUrl).add(msg);
    return new SendMessageResult().withMD5OfMessageBody(msg.getMD5OfBody()).withMessageId(msg.getMessageId());
}