Search in sources :

Example 1 with DBInstanceNotFoundException

use of com.amazonaws.services.rds.model.DBInstanceNotFoundException 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);
}
Also used : DBInstanceNotFoundException(com.amazonaws.services.rds.model.DBInstanceNotFoundException) CreateDBInstanceRequest(com.amazonaws.services.rds.model.CreateDBInstanceRequest) DescribeDBInstancesRequest(com.amazonaws.services.rds.model.DescribeDBInstancesRequest) Test(org.junit.Test)

Example 2 with DBInstanceNotFoundException

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

the class MySqlDatabaseSetupTest method testDeleteDatabaseInstanceDoesNotExist.

@Test
public void testDeleteDatabaseInstanceDoesNotExist() {
    // Should just be a no-op
    DeleteDBInstanceRequest req = new DeleteDBInstanceRequest();
    when(mockClient.deleteDBInstance(req)).thenThrow(new DBInstanceNotFoundException("Database instance does not exist"));
    DBInstance inst = databaseSetup.deleteDatabaseInstance(req);
    assertNull(inst);
}
Also used : DeleteDBInstanceRequest(com.amazonaws.services.rds.model.DeleteDBInstanceRequest) DBInstanceNotFoundException(com.amazonaws.services.rds.model.DBInstanceNotFoundException) DBInstance(com.amazonaws.services.rds.model.DBInstance) Test(org.junit.Test)

Example 3 with DBInstanceNotFoundException

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

Aggregations

DBInstanceNotFoundException (com.amazonaws.services.rds.model.DBInstanceNotFoundException)3 DescribeDBInstancesRequest (com.amazonaws.services.rds.model.DescribeDBInstancesRequest)2 Test (org.junit.Test)2 CreateDBInstanceRequest (com.amazonaws.services.rds.model.CreateDBInstanceRequest)1 DBInstance (com.amazonaws.services.rds.model.DBInstance)1 DeleteDBInstanceRequest (com.amazonaws.services.rds.model.DeleteDBInstanceRequest)1 DescribeDBInstancesResult (com.amazonaws.services.rds.model.DescribeDBInstancesResult)1