Search in sources :

Example 56 with AwsCredentialView

use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.

the class AwsPublicKeyConnector method unregister.

@Override
public void unregister(PublicKeyUnregisterRequest request) {
    LOGGER.debug("Deleting public key {} in {} region on AWS", request.getPublicKeyId(), request.getRegion());
    AwsCredentialView awsCredential = new AwsCredentialView(request.getCredential());
    try {
        AmazonEc2Client client = awsClient.createEc2Client(awsCredential, request.getRegion());
        DeleteKeyPairRequest deleteKeyPairRequest = new DeleteKeyPairRequest(request.getPublicKeyId());
        client.deleteKeyPair(deleteKeyPairRequest);
    } catch (Exception e) {
        String errorMessage = String.format("Failed to delete public key [%s: '%s', region: '%s'], detailed message: %s", getType(awsCredential), getAwsId(awsCredential), request.getRegion(), e.getMessage());
        LOGGER.error(errorMessage, e);
    }
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) DeleteKeyPairRequest(com.amazonaws.services.ec2.model.DeleteKeyPairRequest) AmazonServiceException(com.amazonaws.AmazonServiceException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)

Example 57 with AwsCredentialView

use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.

the class AwsEfsResourceBuilder method getAmazonEfsClient.

private AmazonEfsClient getAmazonEfsClient(AuthenticatedContext auth) {
    AwsCredentialView credentialView = new AwsCredentialView(auth.getCloudCredential());
    String regionName = auth.getCloudContext().getLocation().getRegion().value();
    return awsClient.createElasticFileSystemClient(credentialView, regionName);
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)

Example 58 with AwsCredentialView

use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.

the class AwsClient method createAuthenticatedContext.

public AuthenticatedContext createAuthenticatedContext(CloudContext cloudContext, CloudCredential cloudCredential) {
    AuthenticatedContext authenticatedContext = new AuthenticatedContext(cloudContext, cloudCredential);
    try {
        AuthenticatedContextView authenticatedContextView = new AuthenticatedContextView(authenticatedContext);
        String region = authenticatedContextView.getRegion();
        AwsCredentialView awsCredentialView = authenticatedContextView.getAwsCredentialView();
        AmazonEc2Client amazonEC2Client = null;
        if (region != null) {
            amazonEC2Client = createEc2Client(awsCredentialView, region);
            AmazonElasticLoadBalancingClient loadBalancingClient = createElasticLoadBalancingClient(awsCredentialView, region);
            authenticatedContext.putParameter(AmazonElasticLoadBalancingClient.class, loadBalancingClient);
        } else {
            amazonEC2Client = createEc2Client(awsCredentialView);
        }
        authenticatedContext.putParameter(AmazonEc2Client.class, amazonEC2Client);
    } catch (AmazonServiceException e) {
        throw new CredentialVerificationException(e.getErrorMessage(), e);
    }
    return authenticatedContext;
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) AuthenticatedContextView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AuthenticatedContextView) AmazonServiceException(com.amazonaws.AmazonServiceException) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) CredentialVerificationException(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationException)

Example 59 with AwsCredentialView

use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.

the class AwsCredentialConnector method verifyIamRoleIsAssumable.

private CloudCredentialStatus verifyIamRoleIsAssumable(CloudCredential cloudCredential, CredentialVerificationContext credentialVerificationContext) {
    AwsCredentialView awsCredential = credentialViewProvider.createAwsCredentialView(cloudCredential);
    CloudCredentialStatus credentialStatus = new CloudCredentialStatus(cloudCredential, CredentialStatus.VERIFIED);
    try {
        credentialClient.retrieveSessionCredentials(awsCredential);
        checkRoleIsAssumableWithoutExternalId(credentialVerificationContext, awsCredential);
        credentialStatus = verifyCredentialsPermission(cloudCredential, awsCredential, credentialStatus);
        credentialStatus = determineDefaultRegion(cloudCredential, credentialStatus);
    } catch (AmazonClientException ae) {
        String errorMessage = getErrorMessageForAwsClientException(awsCredential, ae);
        LOGGER.warn(errorMessage, ae);
        credentialStatus = new CloudCredentialStatus(cloudCredential, CredentialStatus.FAILED, ae, errorMessage);
    } catch (AwsConfusedDeputyException confusedDeputyEx) {
        credentialStatus = new CloudCredentialStatus(cloudCredential, CredentialStatus.FAILED, confusedDeputyEx, confusedDeputyEx.getMessage());
    } catch (RuntimeException e) {
        String errorMessage = String.format("Unable to verify credential: check if the role '%s' exists and it's created with the correct external ID. " + "Cause: '%s'", awsCredential.getRoleArn(), e.getMessage());
        LOGGER.warn(errorMessage, e);
        credentialStatus = new CloudCredentialStatus(cloudCredential, CredentialStatus.FAILED, e, errorMessage);
    }
    return credentialStatus;
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AmazonClientException(com.amazonaws.AmazonClientException) AwsConfusedDeputyException(com.sequenceiq.cloudbreak.cloud.aws.common.exception.AwsConfusedDeputyException) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)

Example 60 with AwsCredentialView

use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.

the class AwsAvailabilityZoneProvider method describeAvailabilityZones.

@Cacheable(cacheNames = "cloudResourceAzCache", key = "{ #cloudCredential?.id, #awsRegion.regionName }")
public List<AvailabilityZone> describeAvailabilityZones(CloudCredential cloudCredential, DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest, com.amazonaws.services.ec2.model.Region awsRegion) {
    AmazonEc2Client ec2Client = awsClient.createEc2Client(new AwsCredentialView(cloudCredential), awsRegion.getRegionName());
    DescribeAvailabilityZonesResult describeAvailabilityZonesResult = ec2Client.describeAvailabilityZones(describeAvailabilityZonesRequest);
    return describeAvailabilityZonesResult.getAvailabilityZones();
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) DescribeAvailabilityZonesResult(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)94 AmazonEc2Client (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client)32 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)32 List (java.util.List)25 AmazonServiceException (com.amazonaws.AmazonServiceException)22 AmazonCloudFormationClient (com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient)21 Logger (org.slf4j.Logger)21 Inject (javax.inject.Inject)20 ArrayList (java.util.ArrayList)19 Collectors (java.util.stream.Collectors)19 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)18 Group (com.sequenceiq.cloudbreak.cloud.model.Group)18 Set (java.util.Set)18 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)17 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)17 Map (java.util.Map)16 LoggerFactory (org.slf4j.LoggerFactory)16 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)15 Service (org.springframework.stereotype.Service)15 AmazonAutoScalingClient (com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient)14