use of com.amazonaws.services.rds.model.DescribeDBInstancesRequest in project Synapse-Stack-Builder by Sage-Bionetworks.
the class MySqlDatabaseSetupTest method testCreateOrGetDatabaseInstanceDoesExist.
@Test
public void testCreateOrGetDatabaseInstanceDoesExist() {
// For this case the database already exists so it should not be created again.
String dbIdentifier = "id-123";
CreateDBInstanceRequest request = MySqlDatabaseSetup.getDefaultCreateDBInstanceRequest();
request.setDBInstanceIdentifier(dbIdentifier);
DescribeDBInstancesRequest describeRequest = new DescribeDBInstancesRequest().withDBInstanceIdentifier(dbIdentifier);
DBInstance instance = new DBInstance();
instance.setDBInstanceIdentifier(dbIdentifier);
DescribeDBInstancesResult describeResult = new DescribeDBInstancesResult();
describeResult.withDBInstances(instance);
when(mockClient.describeDBInstances(describeRequest)).thenReturn(describeResult);
DBInstance instanceResult = databaseSetup.createOrGetDatabaseInstance(request);
assertEquals(instance, instanceResult);
// Describe once
verify(mockClient, times(1)).describeDBInstances(describeRequest);
// Create should not be called this time.
verify(mockClient, times(0)).createDBInstance(request);
}
use of com.amazonaws.services.rds.model.DescribeDBInstancesRequest in project Synapse-Stack-Builder by Sage-Bionetworks.
the class MySqlDatabaseSetupTest method testCreateOrGetDatabaseInstanceDoesNotExist.
@Test
public void testCreateOrGetDatabaseInstanceDoesNotExist() {
// Amazon notifies us that a database instances does not exist by throwing DBInstanceNotFoundException
// with a describe methods. This should trigger a create.
String dbIdentifier = "id-123";
CreateDBInstanceRequest request = MySqlDatabaseSetup.getDefaultCreateDBInstanceRequest();
request.setDBInstanceIdentifier(dbIdentifier);
DescribeDBInstancesRequest describeRequest = new DescribeDBInstancesRequest().withDBInstanceIdentifier(dbIdentifier);
when(mockClient.describeDBInstances(describeRequest)).thenThrow(new DBInstanceNotFoundException("Does not exist"));
databaseSetup.createOrGetDatabaseInstance(request);
verify(mockClient, times(1)).createDBInstance(request);
}
use of com.amazonaws.services.rds.model.DescribeDBInstancesRequest in project Synapse-Stack-Builder by Sage-Bionetworks.
the class MySqlDatabaseSetupTest method testWaitForDatabaseBecomesAvailable.
@Test
public void testWaitForDatabaseBecomesAvailable() throws Exception {
when(mockDbInstance.getDBInstanceStatus()).thenReturn("busy", "busy", "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);
List<DescribeDBInstancesRequest> actualRequests = captor.getAllValues();
assertEquals(3, actualRequests.size());
assertNotNull(instance);
}
use of com.amazonaws.services.rds.model.DescribeDBInstancesRequest in project Synapse-Stack-Builder by Sage-Bionetworks.
the class MySqlDatabaseSetup method buildIdGeneratorDescribeDBInstanceRequest.
DescribeDBInstancesRequest buildIdGeneratorDescribeDBInstanceRequest() {
DescribeDBInstancesRequest req = new DescribeDBInstancesRequest();
req.setDBInstanceIdentifier(config.getIdGeneratorDatabaseIdentifier());
return req;
}
use of com.amazonaws.services.rds.model.DescribeDBInstancesRequest in project Synapse-Stack-Builder by Sage-Bionetworks.
the class MySqlDatabaseSetup method createOrGetDatabaseInstance.
/**
* If this database instances does not already exist it will be created, otherwise the instance information will be returned.
*
* @param request
* @return
*/
DBInstance createOrGetDatabaseInstance(CreateDBInstanceRequest request) {
// First query for the instance
try {
DescribeDBInstancesResult result = client.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier(request.getDBInstanceIdentifier()));
if (result.getDBInstances() == null || result.getDBInstances().size() != 1)
throw new IllegalStateException("Did not find exactly one database instances with the identifier: " + request.getDBInstanceIdentifier());
log.debug("Database: " + request.getDBInstanceIdentifier() + " already exists");
return result.getDBInstances().get(0);
} catch (DBInstanceNotFoundException e) {
// This database does not exist to create it
// Create the database.
log.debug("Creating database...");
log.debug(request);
return client.createDBInstance(request);
}
}
Aggregations