List of usage examples for com.amazonaws.services.dynamodbv2 AmazonDynamoDBClient describeTable
@Override
public DescribeTableResult describeTable(String tableName)
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 a va 2 s . co 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/* w w w .j a v a2 s . 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:DynamoDBUtils.java
License:Open Source License
/** * Helper method to determine if an Amazon DynamoDB table exists. * * @param client// w w w.j a va 2 s .c om * 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:aws.example.dynamodb.DescribeTable.java
License:Open Source License
public static void main(String[] args) { final String USAGE = "\n" + "Usage:\n" + " DescribeTable <table>\n\n" + "Where:\n" + " table - the table to get information about.\n\n" + "Example:\n" + " DescribeTable HelloTable\n"; if (args.length < 1) { System.out.println(USAGE); System.exit(1);//from ww w. j a va2 s . com } String table_name = args[0]; System.out.format("Getting description for %s\n\n", table_name); final AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(); try { TableDescription table_info = ddb.describeTable(table_name).getTable(); if (table_info != null) { System.out.format("Table name : %s\n", table_info.getTableName()); System.out.format("Table ARN : %s\n", table_info.getTableArn()); System.out.format("Status : %s\n", table_info.getTableStatus()); System.out.format("Item count : %d\n", table_info.getItemCount().longValue()); System.out.format("Size (bytes): %d\n", table_info.getTableSizeBytes().longValue()); ProvisionedThroughputDescription throughput_info = table_info.getProvisionedThroughput(); System.out.println("Throughput"); System.out.format(" Read Capacity : %d\n", throughput_info.getReadCapacityUnits().longValue()); System.out.format(" Write Capacity: %d\n", throughput_info.getWriteCapacityUnits().longValue()); List<AttributeDefinition> attributes = table_info.getAttributeDefinitions(); System.out.println("Attributes"); for (AttributeDefinition a : attributes) { System.out.format(" %s (%s)\n", a.getAttributeName(), a.getAttributeType()); } } } catch (AmazonServiceException e) { System.err.println(e.getErrorMessage()); System.exit(1); } System.out.println("\nDone!"); }
From source file:awslabs.lab22.SolutionCode.java
License:Open Source License
@Override public TableDescription getTableDescription(AmazonDynamoDBClient ddbClient, String tableName) { try {/*from ww w .j ava2s .c o m*/ 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 w ww . j a v a 2 s . c o m*/ 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 ww w.jav a 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.example.kwang27.secmap.DynamoDBManager.java
License:Open Source License
public static String getTestTableStatus() { try {//from ww w . jav 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.trk.aboutme.DynamoDB.DynamoDBManagerBooks.java
License:Open Source License
public static String getTestTableStatus(String tablename) { try {//ww w.j a v a2 s . c o m AmazonDynamoDBClient ddb = Shelf.clientManager.ddb(); DescribeTableRequest request = new DescribeTableRequest().withTableName(tablename); DescribeTableResult result = ddb.describeTable(request); String status = result.getTable().getTableStatus(); return status == null ? "" : status; } catch (ResourceNotFoundException e) { } catch (AmazonServiceException ex) { Shelf.clientManager.wipeCredentialsOnAuthError(ex); } return ""; }
From source file:com.trk.aboutme.DynamoDB.DynamoDBManagerUsers.java
License:Open Source License
public static String getTestTableStatus() { try {/*from w w w .ja v a2 s.c o m*/ AmazonDynamoDBClient ddb = Shelf.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) { Shelf.clientManager.wipeCredentialsOnAuthError(ex); } return ""; }