@Test(expected = CloudConnectorException.class) public void shouldThrowCloudConnectorExceptionInCaseOfRdsClientException() throws InterruptedException, ExecutionException, TimeoutException { ArgumentCaptor<ModifyDBInstanceRequest> modifyDBInstanceRequestArgumentCaptor = ArgumentCaptor.forClass(ModifyDBInstanceRequest.class); when(amazonRDS.modifyDBInstance(modifyDBInstanceRequestArgumentCaptor.capture())).thenThrow(new RuntimeException()); victim.disableDeleteProtection(authenticatedContext, dbStack); }
public void disableDeleteProtection(AuthenticatedContext ac, DatabaseStack dbStack) throws ExecutionException, TimeoutException, InterruptedException { AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); String regionName = ac.getCloudContext().getLocation().getRegion().value(); AmazonRDS 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); }
AwsRdsModifyService { public void disableDeleteProtection(AuthenticatedContext ac, DatabaseStack dbStack) throws ExecutionException, TimeoutException, InterruptedException { AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); String regionName = ac.getCloudContext().getLocation().getRegion().value(); AmazonRDS 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); } }
AwsRdsModifyService { public void disableDeleteProtection(AuthenticatedContext ac, DatabaseStack dbStack) throws ExecutionException, TimeoutException, InterruptedException { AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); String regionName = ac.getCloudContext().getLocation().getRegion().value(); AmazonRDS 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); }  }
AwsRdsModifyService { public void disableDeleteProtection(AuthenticatedContext ac, DatabaseStack dbStack) throws ExecutionException, TimeoutException, InterruptedException { AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); String regionName = ac.getCloudContext().getLocation().getRegion().value(); AmazonRDS 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); }  void disableDeleteProtection(AuthenticatedContext ac, DatabaseStack dbStack); }
AwsRdsModifyService { public void disableDeleteProtection(AuthenticatedContext ac, DatabaseStack dbStack) throws ExecutionException, TimeoutException, InterruptedException { AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); String regionName = ac.getCloudContext().getLocation().getRegion().value(); AmazonRDS 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); }  void disableDeleteProtection(AuthenticatedContext ac, DatabaseStack dbStack);  }