Search in sources :

Example 1 with DescribeDBParameterGroupsResult

use of com.amazonaws.services.rds.model.DescribeDBParameterGroupsResult 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);
}
Also used : DescribeDBParameterGroupsResult(com.amazonaws.services.rds.model.DescribeDBParameterGroupsResult) DBParameterGroup(com.amazonaws.services.rds.model.DBParameterGroup) DescribeDBParameterGroupsRequest(com.amazonaws.services.rds.model.DescribeDBParameterGroupsRequest) Test(org.junit.Test)

Example 2 with DescribeDBParameterGroupsResult

use of com.amazonaws.services.rds.model.DescribeDBParameterGroupsResult 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)));
}
Also used : DescribeSecurityGroupsRequest(com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest) DescribeDBParameterGroupsResult(com.amazonaws.services.rds.model.DescribeDBParameterGroupsResult) FileWriter(java.io.FileWriter) AmazonSNSClient(com.amazonaws.services.sns.AmazonSNSClient) CreateTopicResult(com.amazonaws.services.sns.model.CreateTopicResult) DescribeDBParametersRequest(com.amazonaws.services.rds.model.DescribeDBParametersRequest) DescribeDBParameterGroupsRequest(com.amazonaws.services.rds.model.DescribeDBParameterGroupsRequest) DescribeSecurityGroupsResult(com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult) Subscription(com.amazonaws.services.sns.model.Subscription) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) DBParameterGroup(com.amazonaws.services.rds.model.DBParameterGroup) ListSubscriptionsByTopicRequest(com.amazonaws.services.sns.model.ListSubscriptionsByTopicRequest) DescribeDBParametersResult(com.amazonaws.services.rds.model.DescribeDBParametersResult) CreateTopicRequest(com.amazonaws.services.sns.model.CreateTopicRequest) MockAmazonClientFactory(org.sagebionetworks.factory.MockAmazonClientFactory) AmazonRDSClient(com.amazonaws.services.rds.AmazonRDSClient) SecurityGroup(com.amazonaws.services.ec2.model.SecurityGroup) InputConfiguration(org.sagebionetworks.stack.config.InputConfiguration) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ListSubscriptionsByTopicResult(com.amazonaws.services.sns.model.ListSubscriptionsByTopicResult) Parameter(com.amazonaws.services.rds.model.Parameter) File(java.io.File) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) Before(org.junit.Before)

Example 3 with DescribeDBParameterGroupsResult

use of com.amazonaws.services.rds.model.DescribeDBParameterGroupsResult 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;
        }
    }
}
Also used : DescribeDBParameterGroupsResult(com.amazonaws.services.rds.model.DescribeDBParameterGroupsResult) CreateDBParameterGroupRequest(com.amazonaws.services.rds.model.CreateDBParameterGroupRequest) AmazonServiceException(com.amazonaws.AmazonServiceException) DescribeDBParameterGroupsRequest(com.amazonaws.services.rds.model.DescribeDBParameterGroupsRequest)

Example 4 with DescribeDBParameterGroupsResult

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

the class DatabaseParameterGroup method describeResources.

public void describeResources() {
    DescribeDBParameterGroupsRequest req;
    DescribeDBParameterGroupsResult res;
    req = new DescribeDBParameterGroupsRequest().withDBParameterGroupName(config.getDatabaseParameterGroupName());
    res = client.describeDBParameterGroups(req);
    if ((res.getDBParameterGroups() != null) && (res.getDBParameterGroups().size() == 1)) {
        resources.setDbParameterGroup(res.getDBParameterGroups().get(0));
    }
}
Also used : DescribeDBParameterGroupsResult(com.amazonaws.services.rds.model.DescribeDBParameterGroupsResult) DescribeDBParameterGroupsRequest(com.amazonaws.services.rds.model.DescribeDBParameterGroupsRequest)

Aggregations

DescribeDBParameterGroupsRequest (com.amazonaws.services.rds.model.DescribeDBParameterGroupsRequest)4 DescribeDBParameterGroupsResult (com.amazonaws.services.rds.model.DescribeDBParameterGroupsResult)4 DBParameterGroup (com.amazonaws.services.rds.model.DBParameterGroup)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)1 DescribeSecurityGroupsRequest (com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest)1 DescribeSecurityGroupsResult (com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult)1 SecurityGroup (com.amazonaws.services.ec2.model.SecurityGroup)1 AmazonRDSClient (com.amazonaws.services.rds.AmazonRDSClient)1 CreateDBParameterGroupRequest (com.amazonaws.services.rds.model.CreateDBParameterGroupRequest)1 DescribeDBParametersRequest (com.amazonaws.services.rds.model.DescribeDBParametersRequest)1 DescribeDBParametersResult (com.amazonaws.services.rds.model.DescribeDBParametersResult)1 Parameter (com.amazonaws.services.rds.model.Parameter)1 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)1 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)1 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)1 AmazonSNSClient (com.amazonaws.services.sns.AmazonSNSClient)1 CreateTopicRequest (com.amazonaws.services.sns.model.CreateTopicRequest)1 CreateTopicResult (com.amazonaws.services.sns.model.CreateTopicResult)1 ListSubscriptionsByTopicRequest (com.amazonaws.services.sns.model.ListSubscriptionsByTopicRequest)1