use of com.amazonaws.services.rds.model.DBParameterGroup in project Synapse-Stack-Builder by Sage-Bionetworks.
the class DatabaseParameterGroupTest method testCreateOrGetDatabaseParameterDoesNotExist.
@Test
public void testCreateOrGetDatabaseParameterDoesNotExist() {
String stack = "stack";
// this param group should get created.
DBParameterGroup expected = new DBParameterGroup();
expected.setDBParameterGroupName(config.getDatabaseParameterGroupName());
expected.setDescription(config.getDatabaseParameterGroupDescription());
expected.setDBParameterGroupFamily(MYSQL_5_6_DB_PARAMETER_GROUP_FAMILY);
CreateDBParameterGroupRequest request = new CreateDBParameterGroupRequest();
request.setDBParameterGroupFamily(expected.getDBParameterGroupFamily());
request.setDBParameterGroupName(expected.getDBParameterGroupName());
request.setDescription(expected.getDescription());
// Throwing an exception with this error code indicates that the group does not exist.
AmazonServiceException exception = new AmazonServiceException("Not found");
exception.setErrorCode(ERROR_CODE_DB_PARAMETER_GROUP_NOT_FOUND);
when(mockClient.describeDBParameterGroups(any(DescribeDBParameterGroupsRequest.class))).thenThrow(exception);
when(mockClient.createDBParameterGroup(request)).thenReturn(expected);
// simulate the group already exists
DBParameterGroup paramGroup = databaseParamGroup.createOrGetDatabaseParameterGroup();
assertEquals(expected, paramGroup);
verify(mockClient).createDBParameterGroup(request);
}
use of com.amazonaws.services.rds.model.DBParameterGroup in project Synapse-Stack-Builder by Sage-Bionetworks.
the class DatabaseParameterGroupTest method testCreateOrGetDatabaseParameterExists.
@Test
public void testCreateOrGetDatabaseParameterExists() {
DBParameterGroup group = new DBParameterGroup().withDBParameterGroupName("some group name");
DescribeDBParameterGroupsResult result = new DescribeDBParameterGroupsResult();
result.setDBParameterGroups(new LinkedList<DBParameterGroup>());
result.getDBParameterGroups().add(group);
when(mockClient.describeDBParameterGroups(any(DescribeDBParameterGroupsRequest.class))).thenReturn(result);
// simulate the group already exists
DBParameterGroup paramGroup = databaseParamGroup.createOrGetDatabaseParameterGroup();
assertEquals(group, paramGroup);
}
use of com.amazonaws.services.rds.model.DBParameterGroup 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.model.DBParameterGroup in project Synapse-Stack-Builder by Sage-Bionetworks.
the class DatabaseParameterGroup method setupDBParameterGroup.
/**
* Setup the DB parameter group with all of the values we want to use.
* @param client
* @param stack
* @return
*/
public DBParameterGroup setupDBParameterGroup() {
// First get the group
DBParameterGroup paramGroup = createOrGetDatabaseParameterGroup();
// Now make sure it has the parameters we want
Map<String, Parameter> map = getAllDBGroupParams(paramGroup.getDBParameterGroupName());
// Turn on the slow query log.
setValueIfNeeded(paramGroup.getDBParameterGroupName(), map, Constants.DB_PARAM_KEY_SLOW_QUERY_LOG, "1");
// Set the slow query time (how long a query must be to get recored in the slow query log) in seconds..
setValueIfNeeded(paramGroup.getDBParameterGroupName(), map, Constants.DB_PARAM_KEY_LONG_QUERY_TIME, "1");
// See PLFM-1526
setValueIfNeeded(paramGroup.getDBParameterGroupName(), map, Constants.DB_PARAM_KEY_MAX_ALLOWED_PACKET, "" + Constants.DB_PARAM_VALUE_MAX_ALLOWED_PACKET);
// See PLFM-4276
setValueIfNeeded(paramGroup.getDBParameterGroupName(), map, Constants.DB_PARAM_KEY_LOG_BIN_TRUST_FUNCTION_CREATORS, "1");
return createOrGetDatabaseParameterGroup();
}
use of com.amazonaws.services.rds.model.DBParameterGroup in project Synapse-Stack-Builder by Sage-Bionetworks.
the class DatabaseParameterGroup method setupResources.
public void setupResources() {
DBParameterGroup grp = setupDBParameterGroup();
this.resources.setDbParameterGroup(grp);
}
Aggregations