Search in sources :

Example 11 with DescribeDBInstancesRequest

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

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

the class MySqlDatabaseSetupTest method testbuildStackTableDBInstanceDescribeDBInstanceRequest.

@Test
public void testbuildStackTableDBInstanceDescribeDBInstanceRequest() {
    int numTableInstances = Integer.parseInt(config.getNumberTableInstances());
    for (int i = 0; i < numTableInstances; i++) {
        DescribeDBInstancesRequest expectedReq = new DescribeDBInstancesRequest().withDBInstanceIdentifier(config.getStackTableDBInstanceDatabaseIdentifier(i));
        DescribeDBInstancesRequest req = databaseSetup.buildStackTableDBInstanceDescribeDBInstanceRequest(i);
        assertEquals(expectedReq, req);
    }
}
Also used : DescribeDBInstancesRequest(com.amazonaws.services.rds.model.DescribeDBInstancesRequest) Test(org.junit.Test)

Example 13 with DescribeDBInstancesRequest

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

the class MySqlDatabaseSetupTest method testbuildIdGeneratorDescribeDBInstanceRequest.

@Test
public void testbuildIdGeneratorDescribeDBInstanceRequest() {
    DescribeDBInstancesRequest expectedReq = new DescribeDBInstancesRequest().withDBInstanceIdentifier(config.getIdGeneratorDatabaseIdentifier());
    DescribeDBInstancesRequest req = databaseSetup.buildIdGeneratorDescribeDBInstanceRequest();
    assertEquals(expectedReq, req);
}
Also used : DescribeDBInstancesRequest(com.amazonaws.services.rds.model.DescribeDBInstancesRequest) Test(org.junit.Test)

Example 14 with DescribeDBInstancesRequest

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

DescribeDBInstancesRequest (com.amazonaws.services.rds.model.DescribeDBInstancesRequest)14 Test (org.junit.Test)8 DBInstance (com.amazonaws.services.rds.model.DBInstance)6 DescribeDBInstancesResult (com.amazonaws.services.rds.model.DescribeDBInstancesResult)4 ArgumentCaptor (org.mockito.ArgumentCaptor)3 CreateDBInstanceRequest (com.amazonaws.services.rds.model.CreateDBInstanceRequest)2 DBInstanceNotFoundException (com.amazonaws.services.rds.model.DBInstanceNotFoundException)2 ArrayList (java.util.ArrayList)1