Search in sources :

Example 1 with DBSecurityGroup

use of com.amazonaws.services.rds.model.DBSecurityGroup in project Synapse-Stack-Builder by Sage-Bionetworks.

the class DatabaseSecuritySetup method createSecurityGroup.

/**
 * Create a security group. If the group already exists
 * @param ec2Client
 * @param request
 */
void createSecurityGroup(CreateDBSecurityGroupRequest request) {
    try {
        // First create the EC2 group
        log.info("Creating Database Security Group: " + request.getDBSecurityGroupName() + "...");
        DBSecurityGroup result = rdsClient.createDBSecurityGroup(request);
    } catch (AmazonServiceException e) {
        if (ERROR_CODE_DB_SECURITY_GROUP_ALREADY_EXISTS.equals(e.getErrorCode())) {
            // This group already exists
            log.info("Database Security Group: " + request.getDBSecurityGroupName() + " already exits");
        } else {
            throw e;
        }
    }
}
Also used : DBSecurityGroup(com.amazonaws.services.rds.model.DBSecurityGroup) AmazonServiceException(com.amazonaws.AmazonServiceException)

Example 2 with DBSecurityGroup

use of com.amazonaws.services.rds.model.DBSecurityGroup in project Synapse-Stack-Builder by Sage-Bionetworks.

the class DatabaseSecuritySetupTest method testTeardownResources.

@Test
public void testTeardownResources() {
    resources.setIdGeneratorDatabaseSecurityGroup(new DBSecurityGroup().withDBSecurityGroupName(config.getIdGeneratorDatabaseSecurityGroupName()));
    resources.setStackInstancesDatabaseSecurityGroup(new DBSecurityGroup().withDBSecurityGroupName(config.getStackDatabaseSecurityGroupName()));
    DeleteDBSecurityGroupRequest req = new DeleteDBSecurityGroupRequest().withDBSecurityGroupName(resources.getStackInstancesDatabaseSecurityGroup().getDBSecurityGroupName());
    databaseSecuritySetup.teardownResources();
    verify(mockClient, times(1)).deleteDBSecurityGroup(req);
    assertNotNull(resources.getIdGeneratorDatabaseSecurityGroup());
    assertNull(resources.getStackInstancesDatabaseSecurityGroup());
}
Also used : DeleteDBSecurityGroupRequest(com.amazonaws.services.rds.model.DeleteDBSecurityGroupRequest) DBSecurityGroup(com.amazonaws.services.rds.model.DBSecurityGroup) Test(org.junit.Test)

Example 3 with DBSecurityGroup

use of com.amazonaws.services.rds.model.DBSecurityGroup in project Synapse-Stack-Builder by Sage-Bionetworks.

the class DatabaseSecuritySetupTest method testCreateSecurityGroup.

/**
 * Test that that the data is passed to the client as expected.
 */
@Test
public void testCreateSecurityGroup() {
    CreateDBSecurityGroupRequest request = new CreateDBSecurityGroupRequest();
    request.setDBSecurityGroupName("name");
    request.setDBSecurityGroupDescription("description");
    when(mockClient.createDBSecurityGroup(request)).thenReturn(new DBSecurityGroup());
    databaseSecuritySetup.createSecurityGroup(request);
    verify(mockClient, times(1)).createDBSecurityGroup(request);
}
Also used : CreateDBSecurityGroupRequest(com.amazonaws.services.rds.model.CreateDBSecurityGroupRequest) DBSecurityGroup(com.amazonaws.services.rds.model.DBSecurityGroup) Test(org.junit.Test)

Example 4 with DBSecurityGroup

use of com.amazonaws.services.rds.model.DBSecurityGroup in project Synapse-Stack-Builder by Sage-Bionetworks.

the class DatabaseSecuritySetupTest method testDescribeResourcesExist.

@Test
public void testDescribeResourcesExist() {
    DescribeDBSecurityGroupsRequest reqIdGen = new DescribeDBSecurityGroupsRequest();
    reqIdGen.setDBSecurityGroupName(config.getIdGeneratorDatabaseSecurityGroupName());
    DescribeDBSecurityGroupsRequest reqStackInst = new DescribeDBSecurityGroupsRequest();
    reqStackInst.setDBSecurityGroupName(config.getStackDatabaseSecurityGroupName());
    when(mockClient.describeDBSecurityGroups(reqIdGen)).thenReturn(new DescribeDBSecurityGroupsResult().withDBSecurityGroups(new DBSecurityGroup().withDBSecurityGroupName(config.getIdGeneratorDatabaseSecurityGroupName())));
    when(mockClient.describeDBSecurityGroups(reqStackInst)).thenReturn(new DescribeDBSecurityGroupsResult().withDBSecurityGroups(new DBSecurityGroup().withDBSecurityGroupName(config.getStackDatabaseSecurityGroupName())));
    databaseSecuritySetup.describeResources();
    assertNotNull(resources.getIdGeneratorDatabaseSecurityGroup());
    assertNotNull(resources.getStackInstancesDatabaseSecurityGroup());
}
Also used : DescribeDBSecurityGroupsRequest(com.amazonaws.services.rds.model.DescribeDBSecurityGroupsRequest) DBSecurityGroup(com.amazonaws.services.rds.model.DBSecurityGroup) DescribeDBSecurityGroupsResult(com.amazonaws.services.rds.model.DescribeDBSecurityGroupsResult) Test(org.junit.Test)

Example 5 with DBSecurityGroup

use of com.amazonaws.services.rds.model.DBSecurityGroup in project Synapse-Stack-Builder by Sage-Bionetworks.

the class DatabaseSecuritySetupTest method testDescribeSecurityGroupExists.

@Test
public void testDescribeSecurityGroupExists() {
    DescribeDBSecurityGroupsRequest req = new DescribeDBSecurityGroupsRequest();
    req.setDBSecurityGroupName("name");
    when(mockClient.describeDBSecurityGroups(req)).thenReturn(new DescribeDBSecurityGroupsResult().withDBSecurityGroups(new DBSecurityGroup().withDBSecurityGroupName("name")));
    DBSecurityGroup grp = databaseSecuritySetup.describeDBSecurityGroup("name");
    assertEquals("name", grp.getDBSecurityGroupName());
}
Also used : DescribeDBSecurityGroupsRequest(com.amazonaws.services.rds.model.DescribeDBSecurityGroupsRequest) DBSecurityGroup(com.amazonaws.services.rds.model.DBSecurityGroup) DescribeDBSecurityGroupsResult(com.amazonaws.services.rds.model.DescribeDBSecurityGroupsResult) Test(org.junit.Test)

Aggregations

DBSecurityGroup (com.amazonaws.services.rds.model.DBSecurityGroup)8 Test (org.junit.Test)7 AmazonServiceException (com.amazonaws.AmazonServiceException)3 AuthorizeDBSecurityGroupIngressRequest (com.amazonaws.services.rds.model.AuthorizeDBSecurityGroupIngressRequest)3 DescribeDBSecurityGroupsRequest (com.amazonaws.services.rds.model.DescribeDBSecurityGroupsRequest)3 DescribeDBSecurityGroupsResult (com.amazonaws.services.rds.model.DescribeDBSecurityGroupsResult)3 CreateDBSecurityGroupRequest (com.amazonaws.services.rds.model.CreateDBSecurityGroupRequest)2 DeleteDBSecurityGroupRequest (com.amazonaws.services.rds.model.DeleteDBSecurityGroupRequest)1