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);
}
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;
}
}
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;
}
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);
}
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);
}
Aggregations