Example usage for com.amazonaws.services.dynamodbv2.model DescribeTableRequest setTableName

List of usage examples for com.amazonaws.services.dynamodbv2.model DescribeTableRequest setTableName

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.model DescribeTableRequest setTableName.

Prototype


public void setTableName(String tableName) 

Source Link

Document

The name of the table to describe.

Usage

From source file:DynamoDBUtils.java

License:Open Source License

/**
 * Helper method to get the status of an Amazon DynamoDB table
 *
 * @param client/*from  www .  j  ava 2s .  c o  m*/
 *        The {@link AmazonDynamoDBClient} with Amazon DynamoDB read privileges
 * @param tableName
 *        The Amazon DynamoDB table to get the status of
 * @return
 */
private static TableStatus getTableStatus(AmazonDynamoDBClient client, String tableName) {
    DescribeTableRequest describeTableRequest = new DescribeTableRequest();
    describeTableRequest.setTableName(tableName);
    DescribeTableResult describeTableResult = client.describeTable(describeTableRequest);
    String status = describeTableResult.getTable().getTableStatus();
    return TableStatus.fromValue(status);
}

From source file:DynamoDBUtils.java

License:Open Source License

/**
 * Verifies if the table has the expected schema.
 *
 * @param client/*from ww  w .ja  v a2  s.c o  m*/
 *        The {@link AmazonDynamoDBClient} with Amazon DynamoDB read privileges
 * @param tableName
 *        The Amazon DynamoDB table to check
 * @param key
 *        The expected hashkey for the Amazon DynamoDB table
 * @return true if the Amazon DynamoDB table exists and the expected hashkey matches the table schema,
 *         otherwise return false
 */
private static boolean tableHasCorrectSchema(AmazonDynamoDBClient client, String tableName, String key) {
    DescribeTableRequest describeTableRequest = new DescribeTableRequest();
    describeTableRequest.setTableName(tableName);
    DescribeTableResult describeTableResult = client.describeTable(describeTableRequest);
    TableDescription tableDescription = describeTableResult.getTable();
    if (tableDescription.getAttributeDefinitions().size() != 1) {
        LOG.error("The number of attribute definitions does not match the existing table.");
        return false;
    }
    AttributeDefinition attributeDefinition = tableDescription.getAttributeDefinitions().get(0);
    if (!attributeDefinition.getAttributeName().equals(key)
            || !attributeDefinition.getAttributeType().equals(ScalarAttributeType.S.toString())) {
        LOG.error("Attribute name or type does not match existing table.");
        return false;
    }
    List<KeySchemaElement> KSEs = tableDescription.getKeySchema();
    if (KSEs.size() != 1) {
        LOG.error("The number of key schema elements does not match the existing table.");
        return false;
    }
    KeySchemaElement kse = KSEs.get(0);
    if (!kse.getAttributeName().equals(key) || !kse.getKeyType().equals(KeyType.HASH.toString())) {
        LOG.error("The hash key does not match the existing table.");
        return false;
    }
    return true;

}

From source file:DynamoDBUtils.java

License:Open Source License

/**
 * Helper method to determine if an Amazon DynamoDB table exists.
 *
 * @param client/* www .  j a  va2  s. c  o m*/
 *        The {@link AmazonDynamoDBClient} with Amazon DynamoDB read privileges
 * @param tableName
 *        The Amazon DynamoDB table to check for
 * @return true if the Amazon DynamoDB table exists, otherwise return false
 */
private static boolean tableExists(AmazonDynamoDBClient client, String tableName) {
    DescribeTableRequest describeTableRequest = new DescribeTableRequest();
    describeTableRequest.setTableName(tableName);
    try {
        client.describeTable(describeTableRequest);
        return true;
    } catch (ResourceNotFoundException e) {
        return false;
    }
}

From source file:com.amazon.services.awsrum.utils.DynamoDBUtils.java

License:Open Source License

private static boolean tableHasCorrectSchema(AmazonDynamoDBClient client, String tableName, String key,
        String rangeKey) {/*from w w w .  j  a  v  a  2 s.com*/
    DescribeTableRequest describeTableRequest = new DescribeTableRequest();
    describeTableRequest.setTableName(tableName);
    DescribeTableResult describeTableResult = client.describeTable(describeTableRequest);
    TableDescription tableDescription = describeTableResult.getTable();
    if (tableDescription.getAttributeDefinitions().size() != 2) {
        LOG.error("The number of attribute definitions does not match the existing table.");
        return false;
    }
    AttributeDefinition attributeDefinition = tableDescription.getAttributeDefinitions().get(0);
    if (!attributeDefinition.getAttributeName().equals(key)
            || !attributeDefinition.getAttributeType().equals(ScalarAttributeType.S.toString())) {
        if (!attributeDefinition.getAttributeName().equals(rangeKey)
                || !attributeDefinition.getAttributeType().equals(ScalarAttributeType.N.toString())) {
            LOG.error("Attribute name or type does not match existing table.");
            return false;
        }
    }
    if (!attributeDefinition.getAttributeName().equals(rangeKey)
            || !attributeDefinition.getAttributeType().equals(ScalarAttributeType.N.toString())) {
        if (!attributeDefinition.getAttributeName().equals(key)
                || !attributeDefinition.getAttributeType().equals(ScalarAttributeType.S.toString())) {
            LOG.error("Attribute name or type does not match existing table.");
            return false;
        }
    }

    List<KeySchemaElement> KSEs = tableDescription.getKeySchema();
    if (KSEs.size() != 2) {
        LOG.error("The number of key schema elements does not match the existing table.");
        return false;
    }
    KeySchemaElement kse = KSEs.get(0);
    if (!kse.getAttributeName().equals(key) || !kse.getKeyType().equals(KeyType.HASH.toString())) {
        LOG.error("The hash key does not match the existing table.");
        return false;
    }
    KeySchemaElement seconndKse = KSEs.get(1);
    if (!seconndKse.getAttributeName().equals(rangeKey)
            || !seconndKse.getKeyType().equals(KeyType.RANGE.toString())) {
        LOG.error("The hash range key does not match the existing table.");
        return false;
    }
    return true;

}

From source file:com.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.DbTableDetail.java

License:Open Source License

@Override
public String retrieveDetails(ResourceDetailRequest detailRequest) {

    String response = null;/*from w  ww  . ja  v  a  2s . c o m*/

    try {

        AmazonDynamoDB client = new AmazonDynamoDBClient(credentials);
        client.setRegion(Region.getRegion(Regions.fromName(detailRequest.getRegion())));

        DescribeTableRequest request = new DescribeTableRequest();
        request.setTableName(detailRequest.getResourceName());

        DescribeTableResult result = client.describeTable(request);
        buildUI(result);

    } catch (IllegalArgumentException | AmazonClientException e) {
        response = e.getMessage();
        LOGGER.log(Level.WARNING, "Problem retrieving DynamoDb details from AWS", e);
    }

    return response;
}