Search in sources :

Example 11 with DBInstance

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

the class MySqlDatabaseSetup method setupAllDatabaseInstances.

/**
 * Create all database instances if they do not already exist.
 *
 * @param client
 * @param config
 */
public void setupAllDatabaseInstances() throws InterruptedException {
    // Build the request to create the ID generator database.
    CreateDBInstanceRequest request = buildIdGeneratorCreateDBInstanceRequest();
    // Get the instances
    DBInstance idGenInstance = createOrGetDatabaseInstance(request);
    log.debug("Database instance: ");
    log.debug(idGenInstance);
    // Now create the stack instance database
    request = buildStackInstancesCreateDBInstanceRequest();
    // Get the instances
    DBInstance stackInstance = createOrGetDatabaseInstance(request);
    log.debug("Database instance: ");
    log.debug(stackInstance);
    // Create the table instances databases
    int numTableInstances = Integer.parseInt(config.getNumberTableInstances());
    List<DBInstance> stackTableInstances = new ArrayList<DBInstance>();
    for (int inst = 0; inst < numTableInstances; inst++) {
        request = buildStackTableDBInstanceCreateDBInstanceRequest(inst);
        DBInstance dbInst = createOrGetDatabaseInstance(request);
        log.debug("Database instance: " + dbInst);
        stackTableInstances.add(dbInst);
    }
    // Wait for both to be created
    idGenInstance = waitForDatabase(idGenInstance);
    stackInstance = waitForDatabase(stackInstance);
    List<DBInstance> updStackTableInstances = new ArrayList<DBInstance>();
    for (DBInstance ti : stackTableInstances) {
        ti = waitForDatabase(ti);
        updStackTableInstances.add(ti);
    }
    resources.setIdGeneratorDatabase(idGenInstance);
    resources.setStackInstancesDatabase(stackInstance);
    resources.setStackInstanceTablesDatabases(updStackTableInstances);
}
Also used : CreateDBInstanceRequest(com.amazonaws.services.rds.model.CreateDBInstanceRequest) DBInstance(com.amazonaws.services.rds.model.DBInstance) ArrayList(java.util.ArrayList)

Example 12 with DBInstance

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

the class MySqlDatabaseSetup method waitForDatabase.

/**
 * Wait for a database to be available
 * @param stackInstance
 */
public DBInstance waitForDatabase(DBInstance stackInstance) throws InterruptedException {
    String status = null;
    DBInstance instance = null;
    // Try to minimize risk of bouncing available status
    boolean available = false;
    for (int i = 0; i < 10; i++) {
        sleeper.sleep(30000);
        DescribeDBInstancesResult result = client.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier(stackInstance.getDBInstanceIdentifier()));
        if ((result != null) && (result.getDBInstances() != null) && (result.getDBInstances().size() >= 1)) {
            instance = result.getDBInstances().get(0);
            status = instance.getDBInstanceStatus();
            log.info(String.format("Waiting for database: instance: %1$s status: %2$s ", stackInstance.getDBInstanceIdentifier(), status));
            if (available = "available".equals(status.toLowerCase())) {
                break;
            }
        }
    }
    if (available) {
        return instance;
    } else {
        return null;
    }
}
Also used : DBInstance(com.amazonaws.services.rds.model.DBInstance) DescribeDBInstancesResult(com.amazonaws.services.rds.model.DescribeDBInstancesResult) DescribeDBInstancesRequest(com.amazonaws.services.rds.model.DescribeDBInstancesRequest)

Example 13 with DBInstance

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

the class StackConfigurationSetup method createConfigProperties.

/**
 * Create the configuration properties using everything gather to this point.
 * @return
 * @throws IOException
 */
Properties createConfigProperties() throws IOException {
    // First load the template
    Properties template = InputConfiguration.loadPropertyFile(Constants.FILE_STACK_CONFIG_TEMPLATE);
    // Create the union of the template and all configuration properties
    Properties union = config.createUnionOfInputAndConfig(template);
    // Add the required properties from the loaded resources
    // Capture the id gen DB end point.
    union.put(Constants.KEY_ID_GENERATOR_DB_ADDRESS, resources.getIdGeneratorDatabase().getEndpoint().getAddress());
    // Capture the stack instance DB end point.
    union.put(Constants.KEY_STACK_INSTANCE_DB_ADDRESS, resources.getStackInstancesDatabase().getEndpoint().getAddress());
    // Search index search endpoint
    union.put(Constants.KEY_STACK_INSTANCE_SEARCH_INDEX_SEARCH_ENDPOINT, resources.getSearchDomain().getSearchService().getEndpoint());
    // Search index document endpoint
    union.put(Constants.KEY_STACK_INSTANCE_SEARCH_INDEX_DOCUMENT_ENDPOINT, resources.getSearchDomain().getDocService().getEndpoint());
    // Add the urls for searach
    // Apply the filter to replace all regular expression with the final values
    PropertyFilter.replaceAllRegularExp(union);
    // The final step is to copy over the values defined in the template
    for (Object keyOb : template.keySet()) {
        String key = (String) keyOb;
        // Set the values
        String value = union.getProperty(key);
        if (value == null)
            throw new IllegalArgumentException("Failed to find a final value for the property key: " + key);
        template.setProperty(key, value);
    }
    // Add the table's database instance properties.
    List<DBInstance> list = resources.getStackInstanceTablesDatabases();
    // The database count.
    template.put(Constants.KEY_TABLE_CLUSTER_DATABASE_COUNT, "" + list.size());
    for (int i = 0; i < list.size(); i++) {
        // add two properties for each instance.
        DBInstance instance = list.get(i);
        template.put(Constants.KEY_TABLE_CLUSTER_DATABASE_ENDPOINT_PREFIX + i, instance.getEndpoint().getAddress());
        template.put(Constants.KEY_TABLE_CLUSTER_DATABASE_SCHEMA_PREFIX + i, config.getStackInstanceTablesDBSchema());
    }
    return template;
}
Also used : DBInstance(com.amazonaws.services.rds.model.DBInstance) Properties(java.util.Properties)

Example 14 with DBInstance

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

the class RdsAlarmSetup method setupAllAlarms.

/**
 * Setup all alarms.
 */
public void setupAllAlarms() {
    List<PutMetricAlarmRequest> l;
    DescribeAlarmsResult r;
    // This is the topic where all alarm notification are sent
    String topicArn = resources.getStackInstanceNotificationTopicArn();
    // setup the alarms for the id generator
    DBInstance instance = resources.getIdGeneratorDatabase();
    l = createAllAlarmsForDatabase(instance, topicArn);
    r = describeAllAlarmsForDatabase(instance);
    resources.setIdGeneratorDatabaseAlarms(r);
    // setup the alarms for the stack instances database.
    instance = resources.getStackInstancesDatabase();
    l = createAllAlarmsForDatabase(instance, topicArn);
    r = describeAllAlarmsForDatabase(instance);
    resources.setStackInstancesDatabaseAlarms(r);
    // setup the alarms for the stack table databases.
    List<DescribeAlarmsResult> lr = new ArrayList<DescribeAlarmsResult>();
    List<DBInstance> tblInstances = resources.getStackInstanceTablesDatabases();
    for (DBInstance i : tblInstances) {
        l = createAllAlarmsForDatabase(i, topicArn);
        r = describeAllAlarmsForDatabase(i);
        lr.add(r);
    }
    resources.setStackInstanceTablesDatabaseAlarms(lr);
}
Also used : PutMetricAlarmRequest(com.amazonaws.services.cloudwatch.model.PutMetricAlarmRequest) DescribeAlarmsResult(com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult) DBInstance(com.amazonaws.services.rds.model.DBInstance) ArrayList(java.util.ArrayList)

Example 15 with DBInstance

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

the class MySqlDatabaseSetupTest method testWaitForDatabaseAvailable.

@Test
public void testWaitForDatabaseAvailable() throws Exception {
    when(mockDbInstance.getDBInstanceStatus()).thenReturn("available");
    when(mockDbInstance.getDBInstanceIdentifier()).thenReturn("dbInstanceId");
    List<DBInstance> expectedDBInstances = Arrays.asList(mockDbInstance);
    when(mockDBInstancesResult.getDBInstances()).thenReturn(expectedDBInstances);
    ArgumentCaptor<DescribeDBInstancesRequest> captor = new ArgumentCaptor<>();
    when(mockClient.describeDBInstances(captor.capture())).thenReturn(mockDBInstancesResult);
    DBInstance instance = databaseSetup.waitForDatabase(mockDbInstance);
    DescribeDBInstancesRequest actualRequest = captor.getValue();
    assertEquals(mockDbInstance.getDBInstanceIdentifier(), actualRequest.getDBInstanceIdentifier());
    assertNotNull(instance);
}
Also used : ArgumentCaptor(org.mockito.ArgumentCaptor) DBInstance(com.amazonaws.services.rds.model.DBInstance) DescribeDBInstancesRequest(com.amazonaws.services.rds.model.DescribeDBInstancesRequest) Test(org.junit.Test)

Aggregations

DBInstance (com.amazonaws.services.rds.model.DBInstance)16 DescribeDBInstancesRequest (com.amazonaws.services.rds.model.DescribeDBInstancesRequest)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)4 DeleteDBInstanceRequest (com.amazonaws.services.rds.model.DeleteDBInstanceRequest)3 DescribeDBInstancesResult (com.amazonaws.services.rds.model.DescribeDBInstancesResult)3 ArgumentCaptor (org.mockito.ArgumentCaptor)3 CreateDBInstanceRequest (com.amazonaws.services.rds.model.CreateDBInstanceRequest)2 DomainStatus (com.amazonaws.services.cloudsearchv2.model.DomainStatus)1 ServiceEndpoint (com.amazonaws.services.cloudsearchv2.model.ServiceEndpoint)1 DescribeAlarmsResult (com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult)1 PutMetricAlarmRequest (com.amazonaws.services.cloudwatch.model.PutMetricAlarmRequest)1 KeyPairInfo (com.amazonaws.services.ec2.model.KeyPairInfo)1 ApplicationVersionDescription (com.amazonaws.services.elasticbeanstalk.model.ApplicationVersionDescription)1 ServerCertificateMetadata (com.amazonaws.services.identitymanagement.model.ServerCertificateMetadata)1 DBInstanceNotFoundException (com.amazonaws.services.rds.model.DBInstanceNotFoundException)1 Endpoint (com.amazonaws.services.rds.model.Endpoint)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1 Before (org.junit.Before)1