use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsRdsStopService method stop.
public void stop(AuthenticatedContext ac, DatabaseStack dbStack) throws ExecutionException, TimeoutException, InterruptedException {
AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
String regionName = ac.getCloudContext().getLocation().getRegion().value();
AmazonRdsClient rdsClient = awsClient.createRdsClient(credentialView, regionName);
String dbInstanceIdentifier = dbStack.getDatabaseServer().getServerId();
StopDBInstanceRequest stopDBInstanceRequest = new StopDBInstanceRequest();
stopDBInstanceRequest.setDBInstanceIdentifier(dbInstanceIdentifier);
LOGGER.debug("RDS stop request");
try {
rdsClient.stopDBInstance(stopDBInstanceRequest);
} catch (RuntimeException ex) {
throw new CloudConnectorException(ex.getMessage(), ex);
}
Waiter<DescribeDBInstancesRequest> rdsWaiter = customAmazonWaiterProvider.getDbInstanceStopWaiter(rdsClient);
DescribeDBInstancesRequest describeDBInstancesRequest = new DescribeDBInstancesRequest().withDBInstanceIdentifier(dbInstanceIdentifier);
StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId());
run(rdsWaiter, describeDBInstancesRequest, stackCancellationCheck, "RDS stop failed");
LOGGER.debug("RDS stop process finished. DB Instance ID: {}", dbInstanceIdentifier);
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsRdsTerminateService method terminate.
/**
* Terminates a database server (stack).
*
* @param ac authenticated cloud context
* @param stack database stack to delete
* @param force whether to continue even if stack termination fails in AWS
* @param persistenceNotifier notifies Resources table of resource deletion
* @param resources list of resources tracked in DB
* @return list of affected cloud resources (not yet implemented)
* @throws AmazonServiceException if the search for the stack fails
* @throws ExecutionException if stack deletion fails (and force is false)
* @throws TimeoutException if stack deletion times out
* @throws InterruptedException if the wait for stack deletion is interrupted
* @throws CloudConnectorException if stack deletion fails due to a runtime exception
*/
public List<CloudResourceStatus> terminate(AuthenticatedContext ac, DatabaseStack stack, boolean force, PersistenceNotifier persistenceNotifier, List<CloudResource> resources) throws Exception {
String cFStackName = cfStackUtil.getCfStackName(ac);
AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
String regionName = ac.getCloudContext().getLocation().getRegion().value();
try {
initiateCFTemplateDeletion(ac, cFStackName, credentialView, regionName);
} catch (AmazonServiceException e) {
return getAmazonServiceException(force, cFStackName, e);
} catch (Exception ex) {
Exception runtimeException = getRuntimeException(force, cFStackName, ex);
if (runtimeException != null) {
throw runtimeException;
}
}
CloudContext cloudContext = ac.getCloudContext();
resources.forEach(r -> persistenceNotifier.notifyDeletion(r, cloudContext));
// FIXME
return List.of();
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsNetworkCfTemplateProvider method describeVpcServiceDetails.
private List<ServiceDetail> describeVpcServiceDetails(NetworkCreationRequest networkCreationRequest, Map<String, String> endpointNameMappings) {
AwsCredentialView awsCredential = new AwsCredentialView(networkCreationRequest.getCloudCredential());
AmazonEc2Client awsClientAccess = awsClient.createEc2Client(awsCredential, networkCreationRequest.getRegion().value());
return awsClientAccess.describeVpcEndpointServices().getServiceDetails().stream().filter(sd -> endpointNameMappings.containsKey(sd.getServiceName())).collect(Collectors.toList());
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsNetworkConnector method getNetworkCidr.
@Override
public NetworkCidr getNetworkCidr(Network network, CloudCredential credential) {
AwsCredentialView awsCredentialView = new AwsCredentialView(credential);
AmazonEc2Client awsClientAccess = awsClient.createEc2Client(awsCredentialView, network.getStringParameter(AwsNetworkView.REGION));
AwsNetworkView awsNetworkView = new AwsNetworkView(network);
String existingVpc = awsNetworkView.getExistingVpc();
DescribeVpcsResult describeVpcsResult = awsClientAccess.describeVpcs(new DescribeVpcsRequest().withVpcIds(existingVpc));
List<String> vpcCidrs = new ArrayList<>();
for (Vpc vpc : describeVpcsResult.getVpcs()) {
if (vpc.getCidrBlockAssociationSet() != null) {
LOGGER.info("The VPC {} has associated CIDR block so using the CIDR blocks in the VPC.", vpc.getVpcId());
List<String> cidrs = vpc.getCidrBlockAssociationSet().stream().map(VpcCidrBlockAssociation::getCidrBlock).distinct().filter(e -> !vpcCidrs.contains(e)).collect(Collectors.toList());
LOGGER.info("The VPC {} CIDRs block are {}.", vpc.getVpcId(), cidrs);
vpcCidrs.addAll(cidrs);
} else {
LOGGER.info("The VPC {} has no associated CIDR block so using the CIDR block in the VPC.", vpc.getVpcId());
vpcCidrs.add(vpc.getCidrBlock());
}
}
if (vpcCidrs.isEmpty()) {
throw new BadRequestException("VPC cidr could not fetch from AWS: " + existingVpc);
}
if (vpcCidrs.size() > 1) {
LOGGER.info("More than one vpc cidrs for VPC {}. We will use the first one: {}", existingVpc, vpcCidrs.get(0));
}
return new NetworkCidr(vpcCidrs.get(0), vpcCidrs);
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsStackValidator method validateStackNameAvailability.
private void validateStackNameAvailability(AuthenticatedContext ac) {
AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
String regionName = ac.getCloudContext().getLocation().getRegion().value();
AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, regionName);
String cFStackName = cfStackUtil.getCfStackName(ac);
try {
LOGGER.debug("Checking stack name availability. [{}]", cFStackName);
cfClient.describeStacks(new DescribeStacksRequest().withStackName(cFStackName));
throw new CloudConnectorException(String.format("Stack already exists with the given name: %s", cFStackName));
} catch (AmazonServiceException e) {
if (e.getErrorMessage().contains(cFStackName + " does not exist")) {
LOGGER.info("Stack name is available, CF stack not found by name {}", cFStackName);
} else {
LOGGER.warn("Exception while checking stack name availability.", e);
}
}
}
Aggregations