use of com.amazonaws.services.rds.model.CreateDBParameterGroupRequest 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.CreateDBParameterGroupRequest in project Synapse-Stack-Builder by Sage-Bionetworks.
the class DatabaseParameterGroup method createOrGetDatabaseParameterGroup.
/**
* Create or get the DBParameter group used by this stack.
* @param stack
*/
public DBParameterGroup createOrGetDatabaseParameterGroup() {
// The group name
String groupName = config.getDatabaseParameterGroupName();
// First query for the group
try {
// Query for this group
DescribeDBParameterGroupsResult result = client.describeDBParameterGroups(new DescribeDBParameterGroupsRequest().withDBParameterGroupName(groupName));
if (result.getDBParameterGroups() == null || result.getDBParameterGroups().size() != 1)
throw new IllegalStateException("Expected one and only one DB parameter group with name: " + groupName);
log.info("DB parameter group: '" + groupName + "' already exists");
return result.getDBParameterGroups().get(0);
} catch (AmazonServiceException e) {
if (ERROR_CODE_DB_PARAMETER_GROUP_NOT_FOUND.equals(e.getErrorCode())) {
log.info("Creating DB parameter group: '" + groupName + "' for the first time...");
// We need to create it since it does not exist
CreateDBParameterGroupRequest request = new CreateDBParameterGroupRequest();
request.setDBParameterGroupFamily(MYSQL_5_6_DB_PARAMETER_GROUP_FAMILY);
request.setDBParameterGroupName(groupName);
request.setDescription(config.getDatabaseParameterGroupDescription());
return client.createDBParameterGroup(request);
} else {
// Any other error gets thrown
throw e;
}
}
}
Aggregations