use of com.amazonaws.services.rds.AmazonRDSClient in project Synapse-Stack-Builder by Sage-Bionetworks.
the class BuildStackMainTest method before.
@Before
public void before() throws IOException {
inputProps = TestHelper.createInputProperties("dev");
InputConfiguration config = TestHelper.createTestConfig("dev");
defaultProps = TestHelper.createDefaultProperties();
clientFactory = new MockAmazonClientFactory();
AmazonS3Client mockS3Client = clientFactory.createS3Client();
AmazonEC2Client mockEC2Client = clientFactory.createEC2Client();
AmazonSNSClient mockSNSnsClient = clientFactory.createSNSClient();
AmazonRDSClient mockRdsClient = clientFactory.createRDSClient();
// Write the default properties.
when(mockS3Client.getObject(any(GetObjectRequest.class), any(File.class))).thenAnswer(new Answer<ObjectMetadata>() {
public ObjectMetadata answer(InvocationOnMock invocation) throws Throwable {
// Write the property file
File file = (File) invocation.getArguments()[1];
FileWriter writer = new FileWriter(file);
try {
defaultProps.store(writer, "test generated");
} finally {
writer.close();
}
return new ObjectMetadata();
}
});
// Return a valid EC2 security group.
DescribeSecurityGroupsRequest dsgr = new DescribeSecurityGroupsRequest().withGroupNames(config.getElasticSecurityGroupName());
when(mockEC2Client.describeSecurityGroups(dsgr)).thenReturn(new DescribeSecurityGroupsResult().withSecurityGroups(new SecurityGroup().withGroupName(config.getElasticSecurityGroupName())));
// Return a valid topic
String topicArn = "some:arn";
when(mockSNSnsClient.createTopic(new CreateTopicRequest(config.getRDSAlertTopicName()))).thenReturn(new CreateTopicResult().withTopicArn(topicArn));
when(mockSNSnsClient.listSubscriptionsByTopic(new ListSubscriptionsByTopicRequest(topicArn))).thenReturn(new ListSubscriptionsByTopicResult().withSubscriptions(new Subscription()));
// return a valid group
when(mockRdsClient.describeDBParameterGroups(new DescribeDBParameterGroupsRequest().withDBParameterGroupName(config.getDatabaseParameterGroupName()))).thenReturn(new DescribeDBParameterGroupsResult().withDBParameterGroups(new DBParameterGroup().withDBParameterGroupName(config.getDatabaseParameterGroupName())));
when(mockRdsClient.describeDBParameters(new DescribeDBParametersRequest().withDBParameterGroupName(config.getDatabaseParameterGroupName()))).thenReturn(new DescribeDBParametersResult().withParameters(new Parameter().withParameterName(Constants.DB_PARAM_KEY_SLOW_QUERY_LOG)).withParameters(new Parameter().withParameterName(Constants.DB_PARAM_KEY_LONG_QUERY_TIME)));
}
use of com.amazonaws.services.rds.AmazonRDSClient in project Gatekeeper by FINRAOS.
the class RdsLookupService method loadInstances.
private List<GatekeeperRDSInstance> loadInstances(AWSEnvironment environment) {
logger.info("Refreshing RDS Instance Data");
Long startTime = System.currentTimeMillis();
DescribeDBInstancesRequest describeDBInstancesRequest = new DescribeDBInstancesRequest();
List<String> securityGroupIds = sgLookupService.fetchSgsForAccountRegion(environment);
AmazonRDSClient amazonRDSClient = awsSessionService.getRDSSession(environment);
DescribeDBInstancesResult result = amazonRDSClient.describeDBInstances(describeDBInstancesRequest);
List<GatekeeperRDSInstance> gatekeeperRDSInstances = loadToGatekeeperRDSInstance(amazonRDSClient, result.getDBInstances(), securityGroupIds);
// At a certain point (Usually ~100 instances) amazon starts paging the rds results, so we need to get each page, which is keyed off by a marker.
while (result.getMarker() != null) {
result = amazonRDSClient.describeDBInstances(describeDBInstancesRequest.withMarker(result.getMarker()));
gatekeeperRDSInstances.addAll(loadToGatekeeperRDSInstance(amazonRDSClient, result.getDBInstances(), securityGroupIds));
}
logger.info("Refreshed instance data in " + ((double) (System.currentTimeMillis() - startTime) / 1000) + " Seconds");
return gatekeeperRDSInstances;
}
use of com.amazonaws.services.rds.AmazonRDSClient in project Gatekeeper by FINRAOS.
the class AwsSessionService method getRDSSession.
public AmazonRDSClient getRDSSession(AWSEnvironment environment) {
BasicSessionCredentials creds = credentialCache.getUnchecked(environment);
AmazonRDSClient rds = awsSessionFactory.createRdsSession(creds);
rds.setRegion(Region.getRegion(Regions.fromName(environment.getRegion())));
return rds;
}
Aggregations