use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.
the class AwsResourceConnector method getExistingSubnetCidr.
private List<String> getExistingSubnetCidr(AuthenticatedContext ac, CloudStack stack) {
AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork());
String region = ac.getCloudContext().getLocation().getRegion().value();
AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()), region);
DescribeSubnetsRequest subnetsRequest = new DescribeSubnetsRequest().withSubnetIds(awsNetworkView.getSubnetList());
List<Subnet> subnets = ec2Client.describeSubnets(subnetsRequest).getSubnets();
if (subnets.isEmpty()) {
throw new CloudConnectorException("The specified subnet does not exist (maybe it's in a different region).");
}
List<String> cidrs = Lists.newArrayList();
for (Subnet subnet : subnets) {
cidrs.add(subnet.getCidrBlock());
}
return cidrs;
}
use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.
the class AwsSetup method validateExistingSubnet.
private void validateExistingSubnet(AwsNetworkView awsNetworkView, AmazonEC2 amazonEC2Client) {
if (awsNetworkView.isExistingSubnet()) {
DescribeSubnetsRequest describeSubnetsRequest = new DescribeSubnetsRequest();
describeSubnetsRequest.withSubnetIds(awsNetworkView.getSubnetList());
DescribeSubnetsResult describeSubnetsResult = amazonEC2Client.describeSubnets(describeSubnetsRequest);
if (describeSubnetsResult.getSubnets().size() < awsNetworkView.getSubnetList().size()) {
throw new CloudConnectorException(String.format(SUBNET_DOES_NOT_EXIST_MSG, awsNetworkView.getExistingSubnet()));
} else {
for (Subnet subnet : describeSubnetsResult.getSubnets()) {
String vpcId = subnet.getVpcId();
if (vpcId != null && !vpcId.equals(awsNetworkView.getExistingVPC())) {
throw new CloudConnectorException(String.format(SUBNETVPC_DOES_NOT_EXIST_MSG, awsNetworkView.getExistingSubnet(), awsNetworkView.getExistingVPC()));
}
}
}
}
}
use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.
the class AwsSetup method validateInstanceProfileCreation.
private void validateInstanceProfileCreation(AwsCredentialView awsCredentialView) {
GetRoleRequest roleRequest = new GetRoleRequest();
String roleName = awsCredentialView.getRoleArn().split("/")[1];
LOGGER.info("Start validate {} role for S3 access.", roleName);
roleRequest.withRoleName(roleName);
AmazonIdentityManagement client = awsClient.createAmazonIdentityManagement(awsCredentialView);
try {
ListRolePoliciesRequest listRolePoliciesRequest = new ListRolePoliciesRequest();
listRolePoliciesRequest.setRoleName(roleName);
ListRolePoliciesResult listRolePoliciesResult = client.listRolePolicies(listRolePoliciesRequest);
for (String s : listRolePoliciesResult.getPolicyNames()) {
if (checkIamOrS3Statement(roleName, client, s)) {
LOGGER.info("Validation successful for s3 or iam access.");
return;
}
}
ListAttachedRolePoliciesRequest listAttachedRolePoliciesRequest = new ListAttachedRolePoliciesRequest();
listAttachedRolePoliciesRequest.setRoleName(roleName);
ListAttachedRolePoliciesResult listAttachedRolePoliciesResult = client.listAttachedRolePolicies(listAttachedRolePoliciesRequest);
for (AttachedPolicy attachedPolicy : listAttachedRolePoliciesResult.getAttachedPolicies()) {
if (checkIamOrS3Access(client, attachedPolicy)) {
LOGGER.info("Validation successful for s3 or iam access.");
return;
}
}
} catch (AmazonServiceException ase) {
if (ase.getStatusCode() == UNAUTHORIZED) {
String policyMEssage = "Could not get policies on the role because the arn role do not have enough permission: %s";
LOGGER.info(String.format(policyMEssage, ase.getErrorMessage()));
throw new CloudConnectorException(String.format(policyMEssage, ase.getErrorMessage()));
} else {
LOGGER.info(ase.getMessage());
throw new CloudConnectorException(ase.getErrorMessage());
}
} catch (Exception e) {
LOGGER.info(e.getMessage());
throw new CloudConnectorException(e.getMessage());
}
LOGGER.info("Could not get policies on the role because the arn role do not have enough permission.");
throw new CloudConnectorException("Could not get policies on the role because the arn role do not have enough permission.");
}
use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.
the class AwsSetup method validateExistingIGW.
private void validateExistingIGW(AwsNetworkView awsNetworkView, AmazonEC2 amazonEC2Client) {
if (awsNetworkView.isExistingIGW()) {
DescribeInternetGatewaysRequest describeInternetGatewaysRequest = new DescribeInternetGatewaysRequest();
describeInternetGatewaysRequest.withInternetGatewayIds(awsNetworkView.getExistingIGW());
DescribeInternetGatewaysResult describeInternetGatewaysResult = amazonEC2Client.describeInternetGateways(describeInternetGatewaysRequest);
if (describeInternetGatewaysResult.getInternetGateways().size() < 1) {
throw new CloudConnectorException(String.format(IGW_DOES_NOT_EXIST_MSG, awsNetworkView.getExistingIGW()));
} else {
InternetGateway internetGateway = describeInternetGatewaysResult.getInternetGateways().get(0);
InternetGatewayAttachment attachment = internetGateway.getAttachments().get(0);
if (attachment != null && !attachment.getVpcId().equals(awsNetworkView.getExistingVPC())) {
throw new CloudConnectorException(String.format(IGWVPC_DOES_NOT_EXIST_MSG, awsNetworkView.getExistingIGW(), awsNetworkView.getExistingVPC()));
}
}
}
}
use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException 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");
}
Aggregations