Search in sources :

Example 1 with Parameter

use of com.amazonaws.services.rds.model.Parameter 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 2 with Parameter

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

Example 3 with Parameter

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

the class DatabaseParameterGroup method setValueIfNeeded.

/**
 * Set the value of the given parameter if it does not already have the passed value.
 *
 * @param client
 * @param map
 * @param key
 * @param value
 * @return true if changed.
 */
boolean setValueIfNeeded(String paramGroupName, Map<String, Parameter> map, String key, String value) {
    // Check the slow query log value
    Parameter param = map.get(key);
    if (param == null)
        throw new IllegalStateException("Cannot find the expected DB parameter: " + key);
    // Do we need to change it?
    if (!value.equals(param.getParameterValue())) {
        // We need to change the value.
        ModifyDBParameterGroupRequest modifyRequest = new ModifyDBParameterGroupRequest();
        modifyRequest.setDBParameterGroupName(paramGroupName);
        List<Parameter> list = new LinkedList<Parameter>();
        list.add(param);
        param.setParameterValue(value);
        param.setApplyMethod(ApplyMethod.Immediate);
        modifyRequest.setParameters(list);
        client.modifyDBParameterGroup(modifyRequest);
        return true;
    }
    return false;
}
Also used : Parameter(com.amazonaws.services.rds.model.Parameter) ModifyDBParameterGroupRequest(com.amazonaws.services.rds.model.ModifyDBParameterGroupRequest) LinkedList(java.util.LinkedList)

Example 4 with Parameter

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

the class DatabaseParameterGroup method getAllDBGroupParams.

/**
 * The DB group parameters are paged so get all pages.
 *
 * @param client
 * @param dbGroupName
 * @return
 */
Map<String, Parameter> getAllDBGroupParams(String dbGroupName) {
    log.info("Fetching all DB group parameters...");
    List<Parameter> fullParams = new LinkedList<Parameter>();
    DescribeDBParametersResult results = client.describeDBParameters(new DescribeDBParametersRequest().withDBParameterGroupName(dbGroupName));
    fullParams.addAll(results.getParameters());
    String marker = results.getMarker();
    while (marker != null) {
        log.info("Fetching next page of DB group parameters. Count: " + fullParams.size());
        results = client.describeDBParameters(new DescribeDBParametersRequest().withDBParameterGroupName(dbGroupName).withMarker(marker));
        fullParams.addAll(results.getParameters());
        marker = results.getMarker();
    }
    log.info("DB parameters count: " + fullParams.size());
    // Put all of the parameters into a map
    Map<String, Parameter> map = new HashMap<String, Parameter>();
    for (Parameter param : fullParams) {
        log.info(param.toString());
        map.put(param.getParameterName(), param);
    }
    return map;
}
Also used : HashMap(java.util.HashMap) DescribeDBParametersResult(com.amazonaws.services.rds.model.DescribeDBParametersResult) DescribeDBParametersRequest(com.amazonaws.services.rds.model.DescribeDBParametersRequest) Parameter(com.amazonaws.services.rds.model.Parameter) LinkedList(java.util.LinkedList)

Aggregations

Parameter (com.amazonaws.services.rds.model.Parameter)4 DBParameterGroup (com.amazonaws.services.rds.model.DBParameterGroup)2 DescribeDBParametersRequest (com.amazonaws.services.rds.model.DescribeDBParametersRequest)2 DescribeDBParametersResult (com.amazonaws.services.rds.model.DescribeDBParametersResult)2 LinkedList (java.util.LinkedList)2 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 DescribeDBParameterGroupsRequest (com.amazonaws.services.rds.model.DescribeDBParameterGroupsRequest)1 DescribeDBParameterGroupsResult (com.amazonaws.services.rds.model.DescribeDBParameterGroupsResult)1 ModifyDBParameterGroupRequest (com.amazonaws.services.rds.model.ModifyDBParameterGroupRequest)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