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:com.er.sylvite.CustomEnvironmentVariableCredentialsProvider.java

License:Open Source License

@Override
public AWSCredentials getCredentials() {

    String prefix = System.getProperty(PREFIX_ENV_VAR, DEFAULT_PREFIX);

    String accessKeyEnvVar = prefix + "_" + ACCESS_KEY_ENV_VAR;
    String secretKeyEnvVar = prefix + "_" + SECRET_KEY_ENV_VAR;

    String accessKey = System.getenv(accessKeyEnvVar);
    String secretKey = System.getenv(secretKeyEnvVar);

    accessKey = StringUtils.trim(accessKey);
    secretKey = StringUtils.trim(secretKey);

    if (StringUtils.isNullOrEmpty(accessKey) || StringUtils.isNullOrEmpty(secretKey)) {

        throw new AmazonClientException("Unable to load AWS credentials from environment variables " + "("
                + accessKeyEnvVar + " and " + secretKeyEnvVar + ")");
    }//from  w  w w  . j a  v a2  s .  com

    return new BasicAWSCredentials(accessKey, secretKey);
}

From source file:com.facebook.presto.kinesis.util.MockKinesisClient.java

License:Apache License

@Override
public PutRecordResult putRecord(PutRecordRequest putRecordRequest)
        throws AmazonServiceException, AmazonClientException {
    // Setup method to add a new record:
    InternalStream theStream = this.getStream(putRecordRequest.getStreamName());
    if (theStream != null) {
        PutRecordResult result = theStream.putRecord(putRecordRequest.getData(),
                putRecordRequest.getPartitionKey());
        return result;
    } else {//from   w  w  w . j a  v a2 s  . c  om
        throw new AmazonClientException("This stream does not exist!");
    }
}

From source file:com.facebook.presto.kinesis.util.MockKinesisClient.java

License:Apache License

@Override
public PutRecordsResult putRecords(PutRecordsRequest putRecordsRequest)
        throws AmazonServiceException, AmazonClientException {
    // Setup method to add a batch of new records:
    InternalStream theStream = this.getStream(putRecordsRequest.getStreamName());
    if (theStream != null) {
        PutRecordsResult result = new PutRecordsResult();
        ArrayList<PutRecordsResultEntry> resultList = new ArrayList<PutRecordsResultEntry>();
        for (PutRecordsRequestEntry entry : putRecordsRequest.getRecords()) {
            PutRecordResult putResult = theStream.putRecord(entry.getData(), entry.getPartitionKey());
            resultList.add((new PutRecordsResultEntry()).withShardId(putResult.getShardId())
                    .withSequenceNumber(putResult.getSequenceNumber()));
        }//from  w  w  w  .  j  av  a 2s. c  o m

        result.setRecords(resultList);
        return result;
    } else {
        throw new AmazonClientException("This stream does not exist!");
    }
}

From source file:com.facebook.presto.kinesis.util.MockKinesisClient.java

License:Apache License

@Override
public DescribeStreamResult describeStream(DescribeStreamRequest describeStreamRequest)
        throws AmazonServiceException, AmazonClientException {
    InternalStream theStream = this.getStream(describeStreamRequest.getStreamName());
    if (theStream != null) {
        StreamDescription desc = new StreamDescription();
        desc = desc.withStreamName(theStream.getStreamName()).withStreamStatus(theStream.getStreamStatus())
                .withStreamARN(theStream.getStreamARN());

        if (describeStreamRequest.getExclusiveStartShardId() == null
                || describeStreamRequest.getExclusiveStartShardId().isEmpty()) {
            desc.setShards(this.getShards(theStream));
            desc.setHasMoreShards(false);
        } else {/*from  ww w  .j  a  v  a  2s  .c  o  m*/
            // Filter from given shard Id, or may not have any more
            String startId = describeStreamRequest.getExclusiveStartShardId();
            desc.setShards(this.getShards(theStream, startId));
            desc.setHasMoreShards(false);
        }

        DescribeStreamResult result = new DescribeStreamResult();
        result = result.withStreamDescription(desc);
        return result;
    } else {
        throw new AmazonClientException("This stream does not exist!");
    }
}

From source file:com.facebook.presto.kinesis.util.MockKinesisClient.java

License:Apache License

@Override
public GetShardIteratorResult getShardIterator(GetShardIteratorRequest getShardIteratorRequest)
        throws AmazonServiceException, AmazonClientException {
    ShardIterator iter = ShardIterator.fromStreamAndShard(getShardIteratorRequest.getStreamName(),
            getShardIteratorRequest.getShardId());
    if (iter != null) {
        InternalStream theStream = this.getStream(iter.streamId);
        if (theStream != null) {
            String seqAsString = getShardIteratorRequest.getStartingSequenceNumber();
            if (seqAsString != null && !seqAsString.isEmpty()
                    && getShardIteratorRequest.getShardIteratorType().equals("AFTER_SEQUENCE_NUMBER")) {
                int sequence = Integer.parseInt(seqAsString);
                iter.recordIndex = sequence + 1;
            } else {
                iter.recordIndex = 100;/*from  w  w  w  .  j  av a2 s  .c om*/
            }

            GetShardIteratorResult result = new GetShardIteratorResult();
            return result.withShardIterator(iter.makeString());
        } else {
            throw new AmazonClientException("Unknown stream or bad shard iterator!");
        }
    } else {
        throw new AmazonClientException("Bad stream or shard iterator!");
    }
}

From source file:com.facebook.presto.kinesis.util.MockKinesisClient.java

License:Apache License

@Override
public GetRecordsResult getRecords(GetRecordsRequest getRecordsRequest)
        throws AmazonServiceException, AmazonClientException {
    ShardIterator iter = ShardIterator.fromString(getRecordsRequest.getShardIterator());
    if (iter == null) {
        throw new AmazonClientException("Bad shard iterator.");
    }/*from w ww. j  a  va 2 s.  c o m*/

    // TODO: incorporate maximum batch size (getRecordsRequest.getLimit)
    GetRecordsResult result = null;
    InternalStream stream = this.getStream(iter.streamId);
    if (stream != null) {
        InternalShard shard = stream.getShards().get(iter.shardIndex);

        if (iter.recordIndex == 100) {
            result = new GetRecordsResult();
            ArrayList<Record> recs = shard.getRecords();
            result.setRecords(recs); // NOTE: getting all for now
            result.setNextShardIterator(getNextShardIterator(iter, recs).makeString());
            result.setMillisBehindLatest(100L);
        } else {
            result = new GetRecordsResult();
            ArrayList<Record> recs = shard.getRecordsFrom(iter);
            result.setRecords(recs); // may be empty
            result.setNextShardIterator(getNextShardIterator(iter, recs).makeString());
            result.setMillisBehindLatest(100L);
        }
    } else {
        throw new AmazonClientException("Unknown stream or bad shard iterator.");
    }

    return result;
}

From source file:com.github.rholder.esthree.command.Get.java

License:Apache License

@Override
public Integer call() throws Exception {

    // this is the most up to date digest, it's initialized here but later holds the most up to date valid digest
    currentDigest = MessageDigest.getInstance("MD5");
    currentDigest = retryingGet();//from w w  w.j  a v a  2s  .c o  m

    if (progressListener != null) {
        progressListener.progressChanged(new ProgressEvent(ProgressEventType.TRANSFER_STARTED_EVENT));
    }

    if (!fullETag.contains("-")) {
        byte[] expected = BinaryUtils.fromHex(fullETag);
        byte[] current = currentDigest.digest();
        if (!Arrays.equals(expected, current)) {
            throw new AmazonClientException("Unable to verify integrity of data download.  "
                    + "Client calculated content hash didn't match hash calculated by Amazon S3.  "
                    + "The data may be corrupt.");
        }
    } else {
        // TODO log warning that we can't validate the MD5
        if (verbose) {
            System.err.println("\nMD5 does not exist on AWS for file, calculated value: "
                    + BinaryUtils.toHex(currentDigest.digest()));
        }
    }
    // TODO add ability to resume from previously downloaded chunks
    // TODO add rate limiter

    return 0;

}

From source file:com.github.rholder.esthree.command.GetMultipart.java

License:Apache License

@Override
public Integer call() throws Exception {
    ObjectMetadata om = amazonS3Client.getObjectMetadata(bucket, key);
    contentLength = om.getContentLength();

    // this is the most up to date digest, it's initialized here but later holds the most up to date valid digest
    currentDigest = MessageDigest.getInstance("MD5");
    chunkSize = chunkSize == null ? DEFAULT_CHUNK_SIZE : chunkSize;
    fileParts = Parts.among(contentLength, chunkSize);
    for (Part fp : fileParts) {

        /*/*from w  ww .  j a  v a 2s . c o m*/
         * We'll need to compute the digest on the full incoming stream for
         * each valid chunk that comes in. Invalid chunks will need to be
         * recomputed and fed through a copy of the MD5 that was valid up
         * until the latest chunk.
         */
        currentDigest = retryingGetWithRange(fp.start, fp.end);
    }

    // TODO fix total content length progress bar
    if (progressListener != null) {
        progressListener.progressChanged(new ProgressEvent(ProgressEventType.TRANSFER_STARTED_EVENT));
    }

    String fullETag = om.getETag();
    if (!fullETag.contains("-")) {
        byte[] expected = BinaryUtils.fromHex(fullETag);
        byte[] current = currentDigest.digest();
        if (!Arrays.equals(expected, current)) {
            throw new AmazonClientException("Unable to verify integrity of data download.  "
                    + "Client calculated content hash didn't match hash calculated by Amazon S3.  "
                    + "The data may be corrupt.");
        }
    } else {
        // TODO log warning that we can't validate the MD5
        if (verbose) {
            System.err.println("\nMD5 does not exist on AWS for file, calculated value: "
                    + BinaryUtils.toHex(currentDigest.digest()));
        }
    }
    // TODO add ability to resume from previously downloaded chunks
    // TODO add rate limiter

    return 0;
}

From source file:com.github.sjones4.youcan.youare.model.transform.CreateAccountRequestMarshaller.java

License:Open Source License

public Request<CreateAccountRequest> marshall(CreateAccountRequest createAccountRequest) {
    if (createAccountRequest == null) {
        throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }/* w ww  .  j a v  a  2s . c om*/
    Request<CreateAccountRequest> request = new DefaultRequest<>(createAccountRequest,
            "AmazonIdentityManagement");
    request.addParameter("Action", "CreateAccount");
    request.addParameter("Version", "2010-05-08");
    if (createAccountRequest.getAccountName() != null) {
        request.addParameter("AccountName", StringUtils.fromString(createAccountRequest.getAccountName()));
    }
    return request;
}

From source file:com.github.sjones4.youcan.youare.model.transform.DeleteAccountPolicyRequestMarshaller.java

License:Open Source License

public Request<DeleteAccountPolicyRequest> marshall(DeleteAccountPolicyRequest deleteAccountPolicyRequest) {

    if (deleteAccountPolicyRequest == null) {
        throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }/*from ww w  . j  av  a 2 s.co m*/

    Request<DeleteAccountPolicyRequest> request = new DefaultRequest<>(deleteAccountPolicyRequest,
            "AmazonIdentityManagement");
    request.addParameter("Action", "DeleteAccountPolicy");
    request.addParameter("Version", "2010-05-08");

    if (deleteAccountPolicyRequest.getAccountName() != null) {
        request.addParameter("AccountName",
                StringUtils.fromString(deleteAccountPolicyRequest.getAccountName()));
    }
    if (deleteAccountPolicyRequest.getPolicyName() != null) {
        request.addParameter("PolicyName", StringUtils.fromString(deleteAccountPolicyRequest.getPolicyName()));
    }

    return request;
}