use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonRdsClient in project cloudbreak by hortonworks.
the class AwsPlatformResourcesTest method databaseServerGeneralSslRootCertificatesTestWhenSuccess.
@Test
void databaseServerGeneralSslRootCertificatesTestWhenSuccess() {
Certificate certificate1 = mock(Certificate.class);
when(certificate1.getCertificateIdentifier()).thenReturn("cert1");
Certificate certificate2 = mock(Certificate.class);
when(certificate2.getCertificateIdentifier()).thenReturn("cert2");
AmazonRdsClient amazonRdsClient = mock(AmazonRdsClient.class);
when(amazonRdsClient.describeCertificates(any(DescribeCertificatesRequest.class))).thenReturn(List.of(certificate1, certificate2));
when(awsClient.createRdsClient(any(AwsCredentialView.class), eq(REGION_NAME))).thenReturn(amazonRdsClient);
CloudDatabaseServerSslCertificates cloudDatabaseServerSslCertificates = underTest.databaseServerGeneralSslRootCertificates(cloudCredential, region);
assertThat(cloudDatabaseServerSslCertificates).isNotNull();
Set<CloudDatabaseServerSslCertificate> sslCertificates = cloudDatabaseServerSslCertificates.getSslCertificates();
assertThat(sslCertificates).isNotNull();
assertThat(sslCertificates).hasSize(2);
verifySslRootCertificate(sslCertificates, "cert1");
verifySslRootCertificate(sslCertificates, "cert2");
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonRdsClient in project cloudbreak by hortonworks.
the class AwsRdsStartService method start.
public void start(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();
StartDBInstanceRequest startDBInstanceRequest = new StartDBInstanceRequest();
startDBInstanceRequest.setDBInstanceIdentifier(dbInstanceIdentifier);
try {
rdsClient.startDBInstance(startDBInstanceRequest);
} catch (RuntimeException ex) {
throw new CloudConnectorException(ex.getMessage(), ex);
}
Waiter<DescribeDBInstancesRequest> rdsWaiter = rdsClient.waiters().dBInstanceAvailable();
DescribeDBInstancesRequest describeDBInstancesRequest = new DescribeDBInstancesRequest().withDBInstanceIdentifier(dbInstanceIdentifier);
StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId());
run(rdsWaiter, describeDBInstancesRequest, stackCancellationCheck, "RDS start failed");
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonRdsClient in project cloudbreak by hortonworks.
the class AwsPlatformResources method databaseServerGeneralSslRootCertificates.
@Override
public CloudDatabaseServerSslCertificates databaseServerGeneralSslRootCertificates(CloudCredential cloudCredential, Region region) {
requireNonNull(cloudCredential);
requireNonNull(region);
AmazonRdsClient rdsClient = getAmazonRdsClient(cloudCredential, region);
List<Certificate> certificates = rdsClient.describeCertificates(new DescribeCertificatesRequest());
Set<CloudDatabaseServerSslCertificate> sslCertificates = certificates.stream().map(Certificate::getCertificateIdentifier).map(id -> new CloudDatabaseServerSslCertificate(CloudDatabaseServerSslCertificateType.ROOT, id)).collect(Collectors.toSet());
return new CloudDatabaseServerSslCertificates(sslCertificates);
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonRdsClient in project cloudbreak by hortonworks.
the class AwsRdsModifyService method disableDeleteProtection.
public void disableDeleteProtection(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();
ModifyDBInstanceRequest modifyDBInstanceRequest = new ModifyDBInstanceRequest();
modifyDBInstanceRequest.setDBInstanceIdentifier(dbInstanceIdentifier);
modifyDBInstanceRequest.setDeletionProtection(false);
LOGGER.debug("RDS modify request to disable delete protection for DB: {}", dbInstanceIdentifier);
try {
rdsClient.modifyDBInstance(modifyDBInstanceRequest);
} catch (RuntimeException ex) {
throw new CloudConnectorException(ex.getMessage(), ex);
}
Waiter<DescribeDBInstancesRequest> rdsWaiter = customAmazonWaiterProvider.getDbInstanceModifyWaiter(rdsClient);
DescribeDBInstancesRequest describeDBInstancesRequest = new DescribeDBInstancesRequest().withDBInstanceIdentifier(dbInstanceIdentifier);
StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId());
run(rdsWaiter, describeDBInstancesRequest, stackCancellationCheck);
LOGGER.debug("RDS delete protection is disabled for DB Instance ID: {}", dbInstanceIdentifier);
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonRdsClient in project cloudbreak by hortonworks.
the class AwsRdsStatusLookupService method getDescribeDBInstancesResultInternal.
private DescribeDBInstancesResult getDescribeDBInstancesResultInternal(AuthenticatedContext ac, DatabaseStack dbStack, String preDescribeMessage, String notFoundMessage) {
AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
String regionName = ac.getCloudContext().getLocation().getRegion().value();
AmazonRdsClient rdsClient = awsClient.createRdsClient(credentialView, regionName);
String dbInstanceIdentifier = dbStack.getDatabaseServer().getServerId();
DescribeDBInstancesRequest describeDBInstancesRequest = new DescribeDBInstancesRequest().withDBInstanceIdentifier(dbInstanceIdentifier);
DescribeDBInstancesResult describeDBInstancesResult;
try {
if (preDescribeMessage != null) {
LOGGER.debug(preDescribeMessage);
}
describeDBInstancesResult = rdsClient.describeDBInstances(describeDBInstancesRequest);
} catch (DBInstanceNotFoundException ex) {
LOGGER.debug(notFoundMessage, ex.getMessage());
describeDBInstancesResult = null;
} catch (RuntimeException ex) {
throw new CloudConnectorException(ex.getMessage(), ex);
}
return describeDBInstancesResult;
}
Aggregations