Example usage for com.amazonaws.services.dynamodbv2.model DescribeTableResult getTable

List of usage examples for com.amazonaws.services.dynamodbv2.model DescribeTableResult getTable

Introduction

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

Prototype


public TableDescription getTable() 

Source Link

Document

The properties of the table.

Usage

From source file:DynamoDBUtils.java

License:Open Source License

/**
 * Helper method to get the status of an Amazon DynamoDB table
 *
 * @param client//from  w w w .j a  va2s. 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 .  j a v a 2s  . co  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:awslabs.lab22.SolutionCode.java

License:Open Source License

@Override
public TableDescription getTableDescription(AmazonDynamoDBClient ddbClient, String tableName) {
    try {//from   w w  w  .  ja  va2  s.  c om
        DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName);

        DescribeTableResult describeTableResult = ddbClient.describeTable(describeTableRequest);

        return describeTableResult.getTable();
    } catch (AmazonServiceException ase) {
        // If the table isn't found, there's no problem.
        // If the error is something else, re-throw the exception to bubble it up to the caller.
        if (!ase.getErrorCode().equals("ResourceNotFoundException")) {
            throw ase;
        }
        return null;
    }
}

From source file:com.acer.batterycapacitydemo.DynamoDBManager.java

License:Open Source License

public static String getTestTableStatus() {

    try {//from www.j av a  2  s.com
        AmazonDynamoDBClient ddb = MainActivity.clientManager.ddb();

        DescribeTableRequest request = new DescribeTableRequest()
                .withTableName(CognitoSyncClientManager.TEST_TABLE_NAME);
        DescribeTableResult result = ddb.describeTable(request);

        String status = result.getTable().getTableStatus();
        return status == null ? "" : status;

    } catch (ResourceNotFoundException e) {
    } catch (AmazonServiceException ex) {
        MainActivity.clientManager.wipeCredentialsOnAuthError(ex);
    }

    return "";
}

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   www  .  j ava 2  s .  c  o m
    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.clicktravel.infrastructure.persistence.aws.dynamodb.integration.DynamoDbDataGenerator.java

License:Apache License

private boolean isTableCreated(final String fullStubItemTableName,
        final DescribeTableResult describeTableResult) {
    return fullStubItemTableName.equals(describeTableResult.getTable().getTableName())
            && "ACTIVE".equals(describeTableResult.getTable().getTableStatus());
}

From source file:com.clicktravel.infrastructure.persistence.aws.dynamodb.manager.DynamoDbTemplateInfrastructureManager.java

License:Apache License

private boolean isTableCreated(final String tableName) {
    try {/*from ww w. java 2s.  c om*/
        final DescribeTableResult result = amazonDynamoDbClient
                .describeTable(new DescribeTableRequest(tableName));
        final TableDescription tableDescription = result.getTable();
        final String tableStatus = tableDescription.getTableStatus();
        final String returnedTableName = tableDescription.getTableName();
        return tableName.equals(returnedTableName) && TableStatus.ACTIVE.toString().equals(tableStatus);
    } catch (final ResourceNotFoundException e) {
        return false;
    }
}

From source file:com.example.kwang27.secmap.DynamoDBManager.java

License:Open Source License

public static String getTestTableStatus() {

    try {//w w w.  j  a v a2s  . c  o m
        AmazonDynamoDBClient ddb = MainActivity.clientManager.ddb();

        DescribeTableRequest request = new DescribeTableRequest().withTableName(Constants.TEST_TABLE_NAME);
        DescribeTableResult result = ddb.describeTable(request);

        String status = result.getTable().getTableStatus();
        return status == null ? "" : status;

    } catch (ResourceNotFoundException e) {
    } catch (AmazonServiceException ex) {
        MainActivity.clientManager.wipeCredentialsOnAuthError(ex);
    }

    return "";
}

From source file:com.github.sdmcraft.slingdynamo.impl.DynamoDBResourceProvider.java

License:Open Source License

/**
 * Returns a resource from this resource provider or null if the resource provider cannot find it.
 * The table-name, id and child-ids are parsed out from the path and queried against dynamodb to fetch the specified resource.
 *
 * @param resolver the ResourceResolver to which the returned Resource is attached.
 * @param req the HttpServletRequest made to get this resource
 * @param path the path of the resource. The path is of the format &lt;table-name&gt;/&lt;id&gt;/[&lt;child-id1&gt;/.../&lt;child-idn&gt;]
 * @return the resource at the specified path if it exists else returns null
 *///www. j  a v a  2s.co  m
public Resource getResource(ResourceResolver resolver, HttpServletRequest req, String path) {
    Resource resource = null;

    try {
        Map<String, Object> resourceProps = new HashMap<String, Object>();
        ResourceMetadata resourceMetadata = new ResourceMetadata();
        resourceMetadata.setResolutionPath(path);

        if (!path.contains(".")) {
            if (path.length() > root.length()) {
                String subPath = path.substring(root.length() + 1);
                String[] subPathSplits = subPath.split("/");
                String table = subPathSplits[0];
                resourceMetadata.put("table", table);

                Table dbtable = dynamoDB.getTable(table);

                if (subPathSplits.length == 1) {
                    DescribeTableRequest describeTableRequest = new DescribeTableRequest(table);
                    DescribeTableResult describeTableResult = null;

                    describeTableResult = dynamoDBClient.describeTable(describeTableRequest);

                    Date creationDate = describeTableResult.getTable().getCreationDateTime();
                    long itemCount = describeTableResult.getTable().getItemCount();

                    resourceProps.put("creation-date", creationDate);
                    resourceProps.put("record-count", itemCount);
                    resourceProps.put("table-name", table);
                } else if (subPathSplits.length == 2) {
                    int id = Integer.parseInt(subPathSplits[1]);
                    ScanFilter idFilter = new ScanFilter("id").eq(id);
                    ItemCollection<ScanOutcome> items = dbtable.scan(idFilter);
                    Iterator<Item> itemItr = items.iterator();

                    Item item = itemItr.next();
                    resourceProps = itemToMap(item);
                } else if (subPathSplits.length > 2) {
                    int parent = Integer.parseInt(subPathSplits[1]);
                    Item item = null;

                    for (int i = 2; i < subPathSplits.length; i++) {
                        int child = Integer.parseInt(subPathSplits[i]);
                        ScanFilter parentFilter = new ScanFilter("parent").eq(parent);
                        ScanFilter childFilter = new ScanFilter("child_id").eq(child);
                        ItemCollection<ScanOutcome> items = dbtable.scan(parentFilter, childFilter);
                        Iterator<Item> itemItr = items.iterator();
                        item = itemItr.next();
                        parent = item.getInt("id");
                    }

                    resourceProps = itemToMap(item);
                }
            }

            resourceProps.put("hello", "world");

            ModifiableValueMapDecorator valueMap = new ModifiableValueMapDecorator(resourceProps);

            resource = new DynamoDBResource(resolver, resourceMetadata, valueMap, resourceType);
        }
    } catch (Throwable ex) {
        LOGGER.error(ex.getMessage(), ex);
        throw new RuntimeException(ex);
    }

    return resource;
}

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

License:Open Source License

private void buildUI(DescribeTableResult detail) {

    this.add(primaryScrollPane, BorderLayout.CENTER);

    if (detail.getTable() != null) {

        TableDescription table = detail.getTable();

        if (table.getCreationDateTime() != null) {
            primaryTableModel.addRow(new Object[] { "Created", getDateString(table.getCreationDateTime()) });
        }//w w  w.j a  v  a  2 s  . c om
        if (table.getItemCount() != null) {
            primaryTableModel.addRow(new Object[] { "Item Count", table.getItemCount() });
        }
        if (table.getLatestStreamArn() != null) {
            primaryTableModel.addRow(new Object[] { "Latest Stream Arn", table.getLatestStreamArn() });
        }
        if (table.getLatestStreamLabel() != null) {
            primaryTableModel.addRow(new Object[] { "Latest Stream Label", table.getLatestStreamLabel() });
        }
        if (table.getTableArn() != null) {
            primaryTableModel.addRow(new Object[] { "Arn", table.getTableArn() });
        }
        if (table.getTableName() != null) {
            primaryTableModel.addRow(new Object[] { "Name", table.getTableName() });
        }
        if (table.getTableSizeBytes() != null) {
            primaryTableModel.addRow(new Object[] { "Size (bytes)", table.getTableSizeBytes() });
        }
        if (table.getTableStatus() != null) {
            primaryTableModel.addRow(new Object[] { "Status", table.getTableStatus() });
        }
    }
}