use of com.yahoo.athenz.common.server.status.StatusCheckException in project athenz by yahoo.
the class DynamoDBStatusChecker method check.
@Override
public void check() throws StatusCheckException {
DynamoDBClientAndCredentials clientAndCreds = null;
try {
// Get DynamoDB client and temp credentials (if required)
DynamoDBClientFetcher dynamoDBClientFetcher = getDynamoDBClientFetcher();
clientAndCreds = dynamoDBClientFetcher.getDynamoDBClient(null, keyStore);
AmazonDynamoDB amazonDynamoDB = clientAndCreds.getAmazonDynamoDB();
// Get list of tables and verify our table appears
boolean tableFound = amazonDynamoDB.listTables().getTableNames().stream().anyMatch(fetchedTableName -> fetchedTableName.equals(tableName));
if (!tableFound) {
throw new StatusCheckException(HttpStatus.SC_OK, "Table named " + tableName + " wasn't found in DynamoDB");
}
} catch (StatusCheckException ex) {
throw ex;
} catch (Throwable ex) {
throw new StatusCheckException(ex);
} finally {
// Close resources
if (clientAndCreds != null) {
try {
if (clientAndCreds.getAmazonDynamoDB() != null) {
clientAndCreds.getAmazonDynamoDB().shutdown();
}
if (clientAndCreds.getAwsCredentialsProvider() != null) {
clientAndCreds.getAwsCredentialsProvider().close();
}
} catch (IOException ignored) {
}
}
}
}
use of com.yahoo.athenz.common.server.status.StatusCheckException in project athenz by yahoo.
the class JDBCCertRecordStoreStatusCheckerTest method testCheckNoDBConnection.
@Test
public void testCheckNoDBConnection() {
JDBCCertRecordStore jdbcCertRecordStore = Mockito.mock(JDBCCertRecordStore.class);
Mockito.when(jdbcCertRecordStore.getConnection()).thenThrow(new ResourceException(503));
JDBCCertRecordStoreStatusChecker jdbcCertRecordStoreStatusChecker = new JDBCCertRecordStoreStatusChecker(jdbcCertRecordStore);
try {
jdbcCertRecordStoreStatusChecker.check();
fail();
} catch (StatusCheckException ex) {
assertEquals(500, ex.getCode());
assertEquals("ResourceException (503): {code: 503, message: \"Service Unavailable\"}", ex.getMsg());
}
Mockito.verify(jdbcCertRecordStore, Mockito.times(1)).getConnection();
}
Aggregations