Search in sources :

Example 41 with AmazonClientException

use of com.amazonaws.AmazonClientException in project cloudbreak by hortonworks.

the class AwsCredentialConnector method verifyAccessKeySecretKeyIsAssumable.

private CloudCredentialStatus verifyAccessKeySecretKeyIsAssumable(CloudCredential cloudCredential) {
    AwsCredentialView awsCredential = new AwsCredentialView(cloudCredential);
    try {
        AmazonEC2Client access = awsClient.createAccess(cloudCredential);
        DescribeRegionsRequest describeRegionsRequest = new DescribeRegionsRequest();
        access.describeRegions(describeRegionsRequest);
    } catch (AmazonClientException ae) {
        String errorMessage = "Unable to verify AWS credentials: please make sure the access key and secret key is correct";
        LOGGER.error(errorMessage, ae);
        return new CloudCredentialStatus(cloudCredential, CredentialStatus.FAILED, ae, errorMessage);
    } catch (RuntimeException e) {
        String errorMessage = String.format("Could not verify keys '%s': check if the keys exists and if it's created with the correct external ID", awsCredential.getAccessKey());
        LOGGER.error(errorMessage, e);
        return new CloudCredentialStatus(cloudCredential, CredentialStatus.FAILED, e, errorMessage);
    }
    return new CloudCredentialStatus(cloudCredential, CredentialStatus.CREATED);
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) AmazonClientException(com.amazonaws.AmazonClientException) DescribeRegionsRequest(com.amazonaws.services.ec2.model.DescribeRegionsRequest) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)

Example 42 with AmazonClientException

use of com.amazonaws.AmazonClientException in project cloudbreak by hortonworks.

the class AwsSetup method prerequisites.

@Override
public void prerequisites(AuthenticatedContext ac, CloudStack stack, PersistenceNotifier persistenceNotifier) {
    AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork());
    AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
    String region = ac.getCloudContext().getLocation().getRegion().value();
    verifySpotInstances(stack);
    AwsCredentialView awsCredentialView = new AwsCredentialView(ac.getCloudCredential());
    AwsInstanceProfileView awsInstanceProfileView = new AwsInstanceProfileView(stack);
    if (awsClient.roleBasedCredential(awsCredentialView) && awsInstanceProfileView.isCreateInstanceProfile()) {
        validateInstanceProfileCreation(awsCredentialView);
    }
    if (awsNetworkView.isExistingVPC()) {
        try {
            AmazonEC2Client amazonEC2Client = awsClient.createAccess(credentialView, region);
            validateExistingIGW(awsNetworkView, amazonEC2Client);
            validateExistingSubnet(awsNetworkView, amazonEC2Client);
        } catch (AmazonServiceException e) {
            throw new CloudConnectorException(e.getErrorMessage());
        } catch (AmazonClientException e) {
            throw new CloudConnectorException(e.getMessage());
        }
    }
    validateExistingKeyPair(stack.getInstanceAuthentication(), credentialView, region);
    LOGGER.debug("setup has been executed");
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsNetworkView) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AmazonClientException(com.amazonaws.AmazonClientException) AmazonServiceException(com.amazonaws.AmazonServiceException) AwsInstanceProfileView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsInstanceProfileView)

Example 43 with AmazonClientException

use of com.amazonaws.AmazonClientException in project dataverse by IQSS.

the class S3AccessIO method savePathAsAux.

@Override
public // this method copies a local filesystem Path into this DataAccess Auxiliary location:
void savePathAsAux(Path fileSystemPath, String auxItemTag) throws IOException {
    if (!this.canWrite()) {
        open(DataAccessOption.WRITE_ACCESS);
    }
    String destinationKey = getDestinationKey(auxItemTag);
    try {
        File inputFile = fileSystemPath.toFile();
        s3.putObject(new PutObjectRequest(bucketName, destinationKey, inputFile));
    } catch (AmazonClientException ase) {
        logger.warning("Caught an AmazonServiceException in S3AccessIO.savePathAsAux():    " + ase.getMessage());
        throw new IOException("S3AccessIO: Failed to save path as an auxiliary object.");
    }
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) IOException(java.io.IOException) DataFile(edu.harvard.iq.dataverse.DataFile) File(java.io.File) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 44 with AmazonClientException

use of com.amazonaws.AmazonClientException in project dataverse by IQSS.

the class S3AccessIO method listAuxObjects.

@Override
public List<String> listAuxObjects() throws IOException {
    if (!this.canWrite()) {
        open();
    }
    String prefix = getDestinationKey("");
    List<String> ret = new ArrayList<>();
    ListObjectsRequest req = new ListObjectsRequest().withBucketName(bucketName).withPrefix(prefix);
    ObjectListing storedAuxFilesList = s3.listObjects(req);
    List<S3ObjectSummary> storedAuxFilesSummary = storedAuxFilesList.getObjectSummaries();
    try {
        while (storedAuxFilesList.isTruncated()) {
            logger.fine("S3 listAuxObjects: going to next page of list");
            storedAuxFilesList = s3.listNextBatchOfObjects(storedAuxFilesList);
            storedAuxFilesSummary.addAll(storedAuxFilesList.getObjectSummaries());
        }
    } catch (AmazonClientException ase) {
        logger.warning("Caught an AmazonServiceException in S3AccessIO.listAuxObjects():    " + ase.getMessage());
        throw new IOException("S3AccessIO: Failed to get aux objects for listing.");
    }
    for (S3ObjectSummary item : storedAuxFilesSummary) {
        String destinationKey = item.getKey();
        String fileName = destinationKey.substring(destinationKey.lastIndexOf(".") + 1);
        logger.fine("S3 cached aux object fileName: " + fileName);
        ret.add(fileName);
    }
    return ret;
}
Also used : ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest) AmazonClientException(com.amazonaws.AmazonClientException) ArrayList(java.util.ArrayList) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) IOException(java.io.IOException)

Example 45 with AmazonClientException

use of com.amazonaws.AmazonClientException in project krypton-android by kryptco.

the class SNSTransport method registerWithAWS.

public synchronized void registerWithAWS() throws TransportException {
    try {
        AmazonSNSClient client = getClient();
        CreatePlatformEndpointRequest request = new CreatePlatformEndpointRequest().withPlatformApplicationArn(PLATFORM_APPLICATION_ARN).withToken(token);
        CreatePlatformEndpointResult result = client.createPlatformEndpoint(request);
        setEndpointARN(result.getEndpointArn());
        HashMap<String, String> enabledAttribute = new HashMap<>();
        enabledAttribute.put("Enabled", "true");
        SetEndpointAttributesRequest enableRequest = new SetEndpointAttributesRequest().withEndpointArn(endpointARN).withAttributes(enabledAttribute);
        client.setEndpointAttributes(enableRequest);
    } catch (AmazonClientException e) {
        throw new TransportException(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) SetEndpointAttributesRequest(com.amazonaws.services.sns.model.SetEndpointAttributesRequest) CreatePlatformEndpointResult(com.amazonaws.services.sns.model.CreatePlatformEndpointResult) AmazonClientException(com.amazonaws.AmazonClientException) CreatePlatformEndpointRequest(com.amazonaws.services.sns.model.CreatePlatformEndpointRequest) AmazonSNSClient(com.amazonaws.services.sns.AmazonSNSClient) TransportException(co.krypt.krypton.exception.TransportException)

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