Search in sources :

Example 1 with AmazonDynamoDBClient

use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonDynamoDBClient in project cloudbreak by hortonworks.

the class AwsPlatformResources method noSqlTables.

@Override
public CloudNoSqlTables noSqlTables(ExtendedCloudCredential cloudCredential, Region region, Map<String, String> filters) {
    List<CloudNoSqlTable> noSqlTables = new ArrayList<>();
    AmazonDynamoDBClient dynamoDbClient = getAmazonDynamoDBClient(cloudCredential, region);
    ListTablesRequest listTablesRequest = new ListTablesRequest();
    ListTablesResult listTablesResult = null;
    boolean first = true;
    while (first || !isNullOrEmpty(listTablesResult.getLastEvaluatedTableName())) {
        first = false;
        listTablesRequest.setExclusiveStartTableName(listTablesResult == null ? null : listTablesResult.getLastEvaluatedTableName());
        listTablesResult = dynamoDbClient.listTables(listTablesRequest);
        List<String> partialTableNames = listTablesResult.getTableNames();
        List<CloudNoSqlTable> partialResult = partialTableNames.stream().map(CloudNoSqlTable::new).collect(Collectors.toList());
        noSqlTables.addAll(partialResult);
    }
    return new CloudNoSqlTables(noSqlTables);
}
Also used : ListTablesResult(com.amazonaws.services.dynamodbv2.model.ListTablesResult) ArrayList(java.util.ArrayList) AmazonDynamoDBClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonDynamoDBClient) ListTablesRequest(com.amazonaws.services.dynamodbv2.model.ListTablesRequest) CloudNoSqlTables(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables) CloudNoSqlTable(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTable)

Example 2 with AmazonDynamoDBClient

use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonDynamoDBClient in project cloudbreak by hortonworks.

the class AwsNoSqlConnector method deleteNoSqlTable.

@Override
public NoSqlTableDeleteResponse deleteNoSqlTable(NoSqlTableDeleteRequest request) {
    try {
        LOGGER.debug("Calling DynamoDB.deleteTable('{}')", request.getTableName());
        AmazonDynamoDBClient dynamoDbClient = getAmazonDynamoDB(request);
        DeleteTableResult deleteTableResult = dynamoDbClient.deleteTable(request.getTableName());
        LOGGER.debug("Successfully called DynamoDB.deleteTable('{}')", request.getTableName());
        TableDescription tableDescription = deleteTableResult.getTableDescription();
        return NoSqlTableDeleteResponse.builder().withStatus(ResponseStatus.OK).withId(tableDescription.getTableArn()).withTableStatus(tableDescription.getTableStatus()).build();
    } catch (ResourceNotFoundException e) {
        LOGGER.info("DynamoDB table not found '{}'", request.getTableName());
        return NoSqlTableDeleteResponse.builder().withStatus(ResponseStatus.RESOURCE_NOT_FOUND).build();
    } catch (AmazonDynamoDBException e) {
        LOGGER.error(String.format("DynamoDB exception on deleteTable '%s'", request.getTableName()), e);
        throw new CloudConnectorException(String.format("Cannot delete NoSQL table %s. " + "Provider error message: %s", request.getTableName(), e.getErrorMessage()), e);
    }
}
Also used : AmazonDynamoDBException(com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AmazonDynamoDBClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonDynamoDBClient) DeleteTableResult(com.amazonaws.services.dynamodbv2.model.DeleteTableResult) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription)

Example 3 with AmazonDynamoDBClient

use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonDynamoDBClient in project cloudbreak by hortonworks.

the class AwsNoSqlConnector method getNoSqlTableMetaData.

@Override
public NoSqlTableMetadataResponse getNoSqlTableMetaData(NoSqlTableMetadataRequest request) {
    try {
        LOGGER.debug("Calling DynamoDB.describeTable('{}')", request.getTableName());
        AmazonDynamoDBClient dynamoDbClient = getAmazonDynamoDB(request);
        DescribeTableResult describeTableResult = dynamoDbClient.describeTable(request.getTableName());
        LOGGER.debug("Successfully called DynamoDB.describeTable('{}')", request.getTableName());
        return NoSqlTableMetadataResponse.builder().withStatus(ResponseStatus.OK).withId(describeTableResult.getTable().getTableArn()).withTableStatus(describeTableResult.getTable().getTableStatus()).build();
    } catch (ResourceNotFoundException e) {
        LOGGER.info("DynamoDB table not found '{}'", request.getTableName());
        return NoSqlTableMetadataResponse.builder().withStatus(ResponseStatus.RESOURCE_NOT_FOUND).build();
    } catch (AmazonDynamoDBException e) {
        LOGGER.error(String.format("DynamoDB exception on describeTAble '%s'", request.getTableName()), e);
        throw new CloudConnectorException(String.format("Cannot get metadata for NoSQL table %s. " + "Provider error message: %s", request.getTableName(), e.getErrorMessage()), e);
    }
}
Also used : AmazonDynamoDBException(com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AmazonDynamoDBClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonDynamoDBClient) DescribeTableResult(com.amazonaws.services.dynamodbv2.model.DescribeTableResult) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)

Aggregations

AmazonDynamoDBClient (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonDynamoDBClient)3 AmazonDynamoDBException (com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException)2 ResourceNotFoundException (com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)2 DeleteTableResult (com.amazonaws.services.dynamodbv2.model.DeleteTableResult)1 DescribeTableResult (com.amazonaws.services.dynamodbv2.model.DescribeTableResult)1 ListTablesRequest (com.amazonaws.services.dynamodbv2.model.ListTablesRequest)1 ListTablesResult (com.amazonaws.services.dynamodbv2.model.ListTablesResult)1 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)1 CloudNoSqlTable (com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTable)1 CloudNoSqlTables (com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables)1 ArrayList (java.util.ArrayList)1