Search in sources :

Example 6 with AuthenticatedContextView

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

the class AwsInstanceConnector method getConsoleOutput.

@Override
public String getConsoleOutput(AuthenticatedContext authenticatedContext, CloudInstance vm) {
    if (!verifyHostKey) {
        throw new CloudOperationNotSupportedException("Host key verification is disabled on AWS");
    }
    AmazonEc2Client amazonEC2Client = new AuthenticatedContextView(authenticatedContext).getAmazonEC2Client();
    GetConsoleOutputRequest getConsoleOutputRequest = new GetConsoleOutputRequest().withInstanceId(vm.getInstanceId());
    GetConsoleOutputResult getConsoleOutputResult = amazonEC2Client.getConsoleOutput(getConsoleOutputRequest);
    try {
        return getConsoleOutputResult.getOutput() == null ? "" : getConsoleOutputResult.getDecodedOutput();
    } catch (Exception ex) {
        LOGGER.warn(ex.getMessage(), ex);
        return "";
    }
}
Also used : CloudOperationNotSupportedException(com.sequenceiq.cloudbreak.cloud.exception.CloudOperationNotSupportedException) AuthenticatedContextView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AuthenticatedContextView) GetConsoleOutputResult(com.amazonaws.services.ec2.model.GetConsoleOutputResult) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) GetConsoleOutputRequest(com.amazonaws.services.ec2.model.GetConsoleOutputRequest) SdkClientException(com.amazonaws.SdkClientException) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) CloudOperationNotSupportedException(com.sequenceiq.cloudbreak.cloud.exception.CloudOperationNotSupportedException)

Example 7 with AuthenticatedContextView

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

the class AwsSetup method validateExistingKeyPair.

private void validateExistingKeyPair(InstanceAuthentication instanceAuthentication, AwsCredentialView credentialView, String region, AuthenticatedContext ac) {
    String keyPairName = awsClient.getExistingKeyPairName(instanceAuthentication);
    if (StringUtils.isNotEmpty(keyPairName)) {
        boolean keyPairIsPresentOnEC2 = false;
        try {
            AmazonEc2Client client = new AuthenticatedContextView(ac).getAmazonEC2Client();
            DescribeKeyPairsResult describeKeyPairsResult = client.describeKeyPairs(new DescribeKeyPairsRequest().withKeyNames(keyPairName));
            keyPairIsPresentOnEC2 = describeKeyPairsResult.getKeyPairs().stream().findFirst().isPresent();
        } catch (RuntimeException e) {
            String errorMessage = String.format("Failed to get the key pair [name: '%s'] from EC2 [roleArn:'%s'], detailed message: %s.", keyPairName, credentialView.getRoleArn(), e.getMessage());
            LOGGER.info(errorMessage, e);
        }
        if (!keyPairIsPresentOnEC2) {
            throw new CloudConnectorException(String.format("The key pair '%s' could not be found in the '%s' region of EC2. " + "Please check AWS EC2 console because probably you are using a wrong key or " + "refer to Cloudera documentation at %s for the required setup", keyPairName, region, DocumentationLinkProvider.awsSshKeySetupLink()));
        }
    }
}
Also used : DescribeKeyPairsRequest(com.amazonaws.services.ec2.model.DescribeKeyPairsRequest) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) DescribeKeyPairsResult(com.amazonaws.services.ec2.model.DescribeKeyPairsResult) AuthenticatedContextView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AuthenticatedContextView) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client)

Example 8 with AuthenticatedContextView

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

the class VolumeBuilderUtil method getRootDeviceName.

public String getRootDeviceName(AuthenticatedContext ac, CloudStack cloudStack) {
    AmazonEc2Client ec2Client = new AuthenticatedContextView(ac).getAmazonEC2Client();
    DescribeImagesResult images = ec2Client.describeImages(new DescribeImagesRequest().withImageIds(cloudStack.getImage().getImageName()));
    if (images.getImages().isEmpty()) {
        throw new CloudConnectorException(String.format("AMI is not available: '%s'.", cloudStack.getImage().getImageName()));
    }
    com.amazonaws.services.ec2.model.Image image = images.getImages().get(0);
    if (image == null) {
        throw new CloudConnectorException(String.format("Couldn't describe AMI '%s'.", cloudStack.getImage().getImageName()));
    }
    return image.getRootDeviceName();
}
Also used : DescribeImagesResult(com.amazonaws.services.ec2.model.DescribeImagesResult) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) DescribeImagesRequest(com.amazonaws.services.ec2.model.DescribeImagesRequest) AuthenticatedContextView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AuthenticatedContextView) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client)

Example 9 with AuthenticatedContextView

use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AuthenticatedContextView 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 10 with AuthenticatedContextView

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

the class AwsContextBuilder method contextInit.

@Override
public AwsContext contextInit(CloudContext context, AuthenticatedContext auth, Network network, List<CloudResource> resources, boolean build) {
    Location location = context.getLocation();
    AuthenticatedContextView authenticatedContextView = new AuthenticatedContextView(auth);
    AmazonEc2Client amazonEC2Client = authenticatedContextView.getAmazonEC2Client();
    AmazonElasticLoadBalancingClient elasticLoadBalancingClient = authenticatedContextView.getElasticLoadBalancingClient();
    return new AwsContext(context.getName(), amazonEC2Client, location, PARALLEL_RESOURCE_REQUEST, build, elasticLoadBalancingClient);
}
Also used : AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) AuthenticatedContextView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AuthenticatedContextView) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Aggregations

AmazonEc2Client (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client)11 AuthenticatedContextView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AuthenticatedContextView)11 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)5 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)5 AmazonServiceException (com.amazonaws.AmazonServiceException)3 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)3 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)3 SdkClientException (com.amazonaws.SdkClientException)2 AmazonEC2Exception (com.amazonaws.services.ec2.model.AmazonEC2Exception)2 DescribeImagesRequest (com.amazonaws.services.ec2.model.DescribeImagesRequest)2 DescribeImagesResult (com.amazonaws.services.ec2.model.DescribeImagesResult)2 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)2 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)2 GetConsoleOutputRequest (com.amazonaws.services.ec2.model.GetConsoleOutputRequest)2 GetConsoleOutputResult (com.amazonaws.services.ec2.model.GetConsoleOutputResult)2 Instance (com.amazonaws.services.ec2.model.Instance)2 AmazonAutoScalingClient (com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient)2 AmazonCloudFormationClient (com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient)2 AmazonElasticLoadBalancingClient (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient)2 CloudOperationNotSupportedException (com.sequenceiq.cloudbreak.cloud.exception.CloudOperationNotSupportedException)2