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 "";
}
}
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()));
}
}
}
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();
}
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;
}
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);
}
Aggregations