Example usage for com.amazonaws AmazonServiceException getErrorMessage

List of usage examples for com.amazonaws AmazonServiceException getErrorMessage

Introduction

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

Prototype

public String getErrorMessage() 

Source Link

Usage

From source file:org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxy.java

License:Apache License

/**
 * {@inheritDoc}/*from w  w w .j av  a 2s.c  o  m*/
 */
@Override
public GetRecordsResult getRecords(String shardIterator, int maxRecordsToGet) throws InterruptedException {
    final GetRecordsRequest getRecordsRequest = new GetRecordsRequest();
    getRecordsRequest.setShardIterator(shardIterator);
    getRecordsRequest.setLimit(maxRecordsToGet);

    GetRecordsResult getRecordsResult = null;

    int attempt = 0;
    while (attempt <= getRecordsMaxAttempts && getRecordsResult == null) {
        try {
            getRecordsResult = kinesisClient.getRecords(getRecordsRequest);
        } catch (AmazonServiceException ex) {
            if (isRecoverableException(ex)) {
                long backoffMillis = fullJitterBackoff(getRecordsBaseBackoffMillis, getRecordsMaxBackoffMillis,
                        getRecordsExpConstant, attempt++);
                LOG.warn("Got recoverable AmazonServiceException. Backing off for " + backoffMillis
                        + " millis (" + ex.getErrorMessage() + ")");
                Thread.sleep(backoffMillis);
            } else {
                throw ex;
            }
        }
    }

    if (getRecordsResult == null) {
        throw new RuntimeException("Rate Exceeded for getRecords operation - all " + getRecordsMaxAttempts
                + " retry attempts returned ProvisionedThroughputExceededException.");
    }

    return getRecordsResult;
}

From source file:org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxy.java

License:Apache License

private String getShardIterator(GetShardIteratorRequest getShardIteratorRequest) throws InterruptedException {
    GetShardIteratorResult getShardIteratorResult = null;

    int attempt = 0;
    while (attempt <= getShardIteratorMaxAttempts && getShardIteratorResult == null) {
        try {/*w  w  w . j  a  v  a2  s. c o m*/
            getShardIteratorResult = kinesisClient.getShardIterator(getShardIteratorRequest);
        } catch (AmazonServiceException ex) {
            if (isRecoverableException(ex)) {
                long backoffMillis = fullJitterBackoff(getShardIteratorBaseBackoffMillis,
                        getShardIteratorMaxBackoffMillis, getShardIteratorExpConstant, attempt++);
                LOG.warn("Got recoverable AmazonServiceException. Backing off for " + backoffMillis
                        + " millis (" + ex.getErrorMessage() + ")");
                Thread.sleep(backoffMillis);
            } else {
                throw ex;
            }
        }
    }

    if (getShardIteratorResult == null) {
        throw new RuntimeException(
                "Rate Exceeded for getShardIterator operation - all " + getShardIteratorMaxAttempts
                        + " retry attempts returned ProvisionedThroughputExceededException.");
    }
    return getShardIteratorResult.getShardIterator();
}

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

License:Apache License

/**
 * Get low level details of an amazon exception for logging; multi-line.
 * @param e exception/*from   www.  j a va  2  s  . c o  m*/
 * @return string details
 */
public static String stringify(AmazonServiceException e) {
    StringBuilder builder = new StringBuilder(String.format("%s: %s error %d: %s; %s%s%n", e.getErrorType(),
            e.getServiceName(), e.getStatusCode(), e.getErrorCode(), e.getErrorMessage(),
            (e.isRetryable() ? " (retryable)" : "")));
    String rawResponseContent = e.getRawResponseContent();
    if (rawResponseContent != null) {
        builder.append(rawResponseContent);
    }
    return builder.toString();
}

From source file:org.apache.nifi.processors.aws.dynamodb.AbstractDynamoDBProcessor.java

License:Apache License

protected List<FlowFile> processServiceException(final ProcessSession session, List<FlowFile> flowFiles,
        AmazonServiceException exception) {
    List<FlowFile> failedFlowFiles = new ArrayList<>();
    for (FlowFile flowFile : flowFiles) {
        Map<String, String> attributes = new HashMap<>();
        attributes.put(DYNAMODB_ERROR_EXCEPTION_MESSAGE, exception.getMessage());
        attributes.put(DYNAMODB_ERROR_CODE, exception.getErrorCode());
        attributes.put(DYNAMODB_ERROR_MESSAGE, exception.getErrorMessage());
        attributes.put(DYNAMODB_ERROR_TYPE, exception.getErrorType().name());
        attributes.put(DYNAMODB_ERROR_SERVICE, exception.getServiceName());
        attributes.put(DYNAMODB_ERROR_RETRYABLE, Boolean.toString(exception.isRetryable()));
        attributes.put(DYNAMODB_ERROR_REQUEST_ID, exception.getRequestId());
        attributes.put(DYNAMODB_ERROR_STATUS_CODE, Integer.toString(exception.getStatusCode()));
        attributes.put(DYNAMODB_ERROR_EXCEPTION_MESSAGE, exception.getMessage());
        attributes.put(DYNAMODB_ERROR_RETRYABLE, Boolean.toString(exception.isRetryable()));
        flowFile = session.putAllAttributes(flowFile, attributes);
        failedFlowFiles.add(flowFile);/*from   w w w .ja  v a2  s. co  m*/
    }
    return failedFlowFiles;
}

From source file:org.apache.nifi.processors.aws.lambda.PutLambda.java

License:Apache License

/**
 * Populate exception attributes in the flow file
 * @param session process session/*from  w  w w . j ava2 s  .co m*/
 * @param flowFile the flow file
 * @param exception exception thrown during invocation
 * @return FlowFile the updated flow file
 */
private FlowFile populateExceptionAttributes(final ProcessSession session, FlowFile flowFile,
        final AmazonServiceException exception) {
    Map<String, String> attributes = new HashMap<>();
    attributes.put(AWS_LAMBDA_EXCEPTION_MESSAGE, exception.getErrorMessage());
    attributes.put(AWS_LAMBDA_EXCEPTION_ERROR_CODE, exception.getErrorCode());
    attributes.put(AWS_LAMBDA_EXCEPTION_REQUEST_ID, exception.getRequestId());
    attributes.put(AWS_LAMBDA_EXCEPTION_STATUS_CODE, Integer.toString(exception.getStatusCode()));
    if (exception.getCause() != null)
        attributes.put(AWS_LAMBDA_EXCEPTION_CAUSE, exception.getCause().getMessage());
    attributes.put(AWS_LAMBDA_EXCEPTION_ERROR_TYPE, exception.getErrorType().toString());
    attributes.put(AWS_LAMBDA_EXCEPTION_MESSAGE, exception.getErrorMessage());
    flowFile = session.putAllAttributes(flowFile, attributes);
    return flowFile;
}

From source file:org.finra.dm.dao.impl.Ec2DaoImpl.java

License:Apache License

/**
 * This implementation uses the DescribeSubnets API.
 *//*from ww w .  java  2 s . c o m*/
@Override
public List<Subnet> getSubnets(Collection<String> subnetIds, AwsParamsDto awsParamsDto) {
    AmazonEC2Client ec2Client = getEc2Client(awsParamsDto);
    DescribeSubnetsRequest describeSubnetsRequest = new DescribeSubnetsRequest();
    describeSubnetsRequest.setSubnetIds(subnetIds);
    try {
        DescribeSubnetsResult describeSubnetsResult = ec2Operations.describeSubnets(ec2Client,
                describeSubnetsRequest);
        return describeSubnetsResult.getSubnets();
    } catch (AmazonServiceException amazonServiceException) {
        /*
         * AWS throws a 400 error when any one of the specified subnet ID is not found.
         * We want to catch it and throw as an handled DM error as a 404 not found.
         */
        if (ERROR_CODE_SUBNET_ID_NOT_FOUND.equals(amazonServiceException.getErrorCode())) {
            throw new ObjectNotFoundException(amazonServiceException.getErrorMessage(), amazonServiceException);
        }
        // Any other type of error we throw as is because they are unexpected.
        else {
            throw amazonServiceException;
        }
    }
}

From source file:org.finra.herd.dao.impl.Ec2DaoImpl.java

License:Apache License

/**
 * This implementation uses the DescribeSubnets API.
 *//*w w  w .jav  a2s .c om*/
@Override
public List<Subnet> getSubnets(Collection<String> subnetIds, AwsParamsDto awsParamsDto) {
    AmazonEC2Client ec2Client = getEc2Client(awsParamsDto);
    DescribeSubnetsRequest describeSubnetsRequest = new DescribeSubnetsRequest();
    describeSubnetsRequest.setSubnetIds(subnetIds);
    try {
        DescribeSubnetsResult describeSubnetsResult = ec2Operations.describeSubnets(ec2Client,
                describeSubnetsRequest);
        return describeSubnetsResult.getSubnets();
    } catch (AmazonServiceException amazonServiceException) {
        /*
         * AWS throws a 400 error when any one of the specified subnet ID is not found.
         * We want to catch it and throw as an handled herd error as a 404 not found.
         */
        if (ERROR_CODE_SUBNET_ID_NOT_FOUND.equals(amazonServiceException.getErrorCode())) {
            throw new ObjectNotFoundException(amazonServiceException.getErrorMessage(), amazonServiceException);
        }
        // Any other type of error we throw as is because they are unexpected.
        else {
            throw amazonServiceException;
        }
    }
}

From source file:org.occiware.clouddriver.IAM.KeyPairOperation.java

License:Apache License

/**
 * Create a new Key Pair on AWS side./* w ww.  j a  va 2 s.c om*/
 * @param keyPairName
 * @return
 * @throws KeyPairOperationException
 */
public KeyPairDO createKeyPair(final String keyPairName) throws KeyPairOperationException {

    if (keyPairName == null) {
        throw new KeyPairOperationException(
                "The 'keyPairName' must be provided for operation create KeyPair. Constraints: Accepts alphanumeric characters, spaces, dashes, and underscores.");
    }
    KeyPairDO keyPairDO = new KeyPairDO();

    try {
        CreateKeyPairResult result = ec2Client.getClientInstance()
                .createKeyPair(new CreateKeyPairRequest(keyPairName));

        keyPairDO.setFingerPrintPrivateKey(result.getKeyPair().getKeyFingerprint());
        keyPairDO.setPrivateKey(result.getKeyPair().getKeyMaterial());
        keyPairDO.setKeyPairName(result.getKeyPair().getKeyName());
        ec2Client.getClientInstance().shutdown();

    } catch (AmazonServiceException ase) {
        logger.error("Exception thrown from aws : " + ase.getErrorCode() + " --> " + ase.getErrorMessage());
        throw new KeyPairOperationException(ase);
    } catch (AmazonClientException ace) {
        logger.error("Exception thrown from aws : " + ace.getMessage());
        throw new KeyPairOperationException(ace);
    } finally {
        ec2Client.getClientInstance().shutdown();
    }
    return keyPairDO;
}

From source file:org.occiware.clouddriver.IAM.KeyPairOperation.java

License:Apache License

/**
 * Import key pair to AWS./*from w  w w  .  ja  v  a  2s .c  om*/
 * @param keyPair a keypair data object with a public key and a name set..
 * @throws KeyPairOperationException Exception when aws exception when importing a new key pair.
 */
public void importKeyPair(KeyPairDO keyPair) throws KeyPairOperationException {

    String keyPairName = keyPair.getKeyPairName();
    String encodedPublicKey = keyPair.getPublicKey(); // Base 64 encoded, DER

    if (keyPairName == null) {
        throw new KeyPairOperationException("The keyPair name must be provided for operation import KeyPair.");
    }
    if (encodedPublicKey == null) {
        throw new KeyPairOperationException(
                "The keyPair public key encoded base 64, DER must be provided for operation importKeyPair.");
    }
    try {
        ImportKeyPairResult result = ec2Client.getClientInstance()
                .importKeyPair(new ImportKeyPairRequest(keyPairName, encodedPublicKey));
        keyPair.setKeyPairName(result.getKeyName());
        keyPair.setFingerPrintPublicKey(result.getKeyFingerprint());
        ec2Client.getClientInstance().shutdown();
    } catch (AmazonServiceException ase) {
        logger.error("Exception thrown from aws : " + ase.getErrorCode() + " --> " + ase.getErrorMessage());
        throw new KeyPairOperationException(ase);
    } catch (AmazonClientException ace) {
        logger.error("Exception thrown from aws : " + ace.getMessage());
        throw new KeyPairOperationException(ace);
    } finally {
        ec2Client.getClientInstance().shutdown();
    }
}

From source file:org.occiware.clouddriver.IAM.KeyPairOperation.java

License:Apache License

/**
 * Delete a key pair from AWS EC2 Service.
 * @param keyPairName//from ww w . java2 s . com
 * @throws KeyPairOperationException
 */
public void deleteKeyPair(final String keyPairName) throws KeyPairOperationException {

    if (keyPairName == null) {
        throw new KeyPairOperationException("The keyPair name must be provided for operation delete KeyPair.");
    }
    try {
        ec2Client.getClientInstance().deleteKeyPair(new DeleteKeyPairRequest(keyPairName));
    } catch (AmazonServiceException ase) {
        logger.error("Exception thrown from aws : " + ase.getErrorCode() + " --> " + ase.getErrorMessage());
        throw new KeyPairOperationException(ase);
    } catch (AmazonClientException ace) {
        logger.error("Exception thrown from aws : " + ace.getMessage());
        throw new KeyPairOperationException(ace);
    } finally {
        ec2Client.getClientInstance().shutdown();
    }

}