@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getAttributeDefinitions() == null) ? 0 : getAttributeDefinitions().hashCode()); hashCode = prime * hashCode + ((getTableName() == null) ? 0 : getTableName().hashCode()); hashCode = prime * hashCode + ((getKeySchema() == null) ? 0 : getKeySchema().hashCode()); hashCode = prime * hashCode + ((getTableStatus() == null) ? 0 : getTableStatus().hashCode()); hashCode = prime * hashCode + ((getCreationDateTime() == null) ? 0 : getCreationDateTime().hashCode()); hashCode = prime * hashCode + ((getProvisionedThroughput() == null) ? 0 : getProvisionedThroughput().hashCode()); hashCode = prime * hashCode + ((getTableSizeBytes() == null) ? 0 : getTableSizeBytes().hashCode()); hashCode = prime * hashCode + ((getItemCount() == null) ? 0 : getItemCount().hashCode()); hashCode = prime * hashCode + ((getTableArn() == null) ? 0 : getTableArn().hashCode()); hashCode = prime * hashCode + ((getTableId() == null) ? 0 : getTableId().hashCode()); hashCode = prime * hashCode + ((getBillingModeSummary() == null) ? 0 : getBillingModeSummary().hashCode()); hashCode = prime * hashCode + ((getLocalSecondaryIndexes() == null) ? 0 : getLocalSecondaryIndexes().hashCode()); hashCode = prime * hashCode + ((getGlobalSecondaryIndexes() == null) ? 0 : getGlobalSecondaryIndexes().hashCode()); hashCode = prime * hashCode + ((getStreamSpecification() == null) ? 0 : getStreamSpecification().hashCode()); hashCode = prime * hashCode + ((getLatestStreamLabel() == null) ? 0 : getLatestStreamLabel().hashCode()); hashCode = prime * hashCode + ((getLatestStreamArn() == null) ? 0 : getLatestStreamArn().hashCode()); hashCode = prime * hashCode + ((getRestoreSummary() == null) ? 0 : getRestoreSummary().hashCode()); hashCode = prime * hashCode + ((getSSEDescription() == null) ? 0 : getSSEDescription().hashCode()); return hashCode; }
try { retry: for (;;) { TableDescription desc = describe(); String status = desc.getTableStatus(); if (TableStatus.fromValue(status) == TableStatus.ACTIVE) { List<GlobalSecondaryIndexDescription> descriptions = desc.getGlobalSecondaryIndexes(); if (descriptions != null) { for (GlobalSecondaryIndexDescription d: descriptions) {
private void runTest(AmazonDynamoDB client) { CreateTableRequest request = new CreateTableRequest() .withAttributeDefinitions(new AttributeDefinition( "Name", ScalarAttributeType.S)) .withKeySchema(new KeySchemaElement("Name", KeyType.HASH)) .withProvisionedThroughput(new ProvisionedThroughput( new Long(10), new Long(10))) .withTableName("foo"); client.createTable(request); final TableDescription tableDescription = client.describeTable("foo").getTable(); assertNotNull("the description is not null", tableDescription); assertEquals("the table has the right name", "foo", tableDescription.getTableName()); assertEquals("the name has the right primary key", "Name", tableDescription.getKeySchema().get(0).getAttributeName()); } }
while (System.currentTimeMillis() < endTime) { try { table = dynamo.describeTable(new DescribeTableRequest(tableName)).getTable(); if (desiredStatus == null || table.getTableStatus().equals(desiredStatus.toString())) { return table;
/** * Gives basic information about a DynamoDB table (status, creation date, size). * @param appid name of the {@link com.erudika.para.core.App} * @return a map */ public static Map<String, Object> getTableStatus(final String appid) { if (StringUtils.isBlank(appid)) { return Collections.emptyMap(); } try { final TableDescription td = getClient().describeTable(getTableNameForAppid(appid)).getTable(); HashMap<String, Object> dbStatus = new HashMap<>(); dbStatus.put("id", appid); dbStatus.put("status", td.getTableStatus()); dbStatus.put("created", td.getCreationDateTime().getTime()); dbStatus.put("sizeBytes", td.getTableSizeBytes()); dbStatus.put("itemCount", td.getItemCount()); dbStatus.put("readCapacityUnits", td.getProvisionedThroughput().getReadCapacityUnits()); dbStatus.put("writeCapacityUnits", td.getProvisionedThroughput().getWriteCapacityUnits()); return dbStatus; } catch (Exception e) { logger.error(null, e); } return Collections.emptyMap(); }
protected List<KeySchemaElement> getTableSchema(String tableName) throws ResourceNotFoundException { List<KeySchemaElement> schema = tableSchemaCache.get(tableName); if(schema == null) { DescribeTableResult result = client.describeTable(new DescribeTableRequest().withTableName(tableName)); schema = Collections.unmodifiableList(result.getTable().getKeySchema()); tableSchemaCache.put(tableName, schema); } return schema; }
public DynamoTable(Table table) { table.describe(); tableName = table.getTableName(); attributeDefinitions = table.getDescription().getAttributeDefinitions().toString(); tableStatus = table.getDescription().getTableStatus(); keySchema = table.getDescription().getKeySchema().toString(); creationDateTime = new DateTime(table.getDescription().getCreationDateTime()); numberOfDecreasesToday = table.getDescription().getProvisionedThroughput().getNumberOfDecreasesToday(); readCapacityUnits = table.getDescription().getProvisionedThroughput().getReadCapacityUnits(); writeCapacityUnits = table.getDescription().getProvisionedThroughput().getWriteCapacityUnits(); tableSizeBytes = table.getDescription().getTableSizeBytes(); itemCount = table.getDescription().getItemCount(); tableArn = table.getDescription().getTableArn(); provisionedThroughput = table.getDescription().getProvisionedThroughput().toString(); globalSecondaryIndexes = new ArrayList<>(); if (table.getDescription().getGlobalSecondaryIndexes() != null) { for (GlobalSecondaryIndexDescription gsiDesc : table .getDescription() .getGlobalSecondaryIndexes()) { globalSecondaryIndexes.add(new DynamoGSI(gsiDesc)); } } }
private TableStatus tableStatus(String tableName) { DescribeTableRequest request = new DescribeTableRequest(); request.setTableName(tableName); try { DescribeTableResult result = amazonDynamoDB.describeTable(request); TableStatus tableStatus = TableStatus.fromValue(result.getTable().getTableStatus()); logger.debug("table status {} ", tableStatus); return tableStatus; } catch (ResourceNotFoundException e) { logger.debug("ResourceNotFound is TableName {}", tableName); return null; } catch (AmazonClientException e) { logger.error("Unknown error ", e); throw new IllegalStateException("Unknown Exception", e); } }
/** * Interface which will block until a dynamo table reaches a specified * state. Also returns immediately if the object doesn't exist * * @param dynamoClient * Dynamo DB Client to use for connection to Dynamo DB. * @param dynamoTable * The table name to check. * @param status * The status to wait for * @throws Exception */ private static void waitForTableState(final AmazonDynamoDB dynamoClient, final String dynamoTable, TableStatus status) throws Exception { DescribeTableResult tableRequest = null; while (true) { try { tableRequest = dynamoClient.describeTable(dynamoTable); if (tableRequest.getTable().getTableStatus() .equals(status.name())) break; Thread.sleep(1000); } catch (InterruptedException e) { return; } } }
List<LocalSecondaryIndex> localIndexes) { DescribeTableResult describe = client.describeTable(new DescribeTableRequest().withTableName(tableName)); if(! new HashSet<AttributeDefinition>(definitions).equals(new HashSet<AttributeDefinition>(describe.getTable().getAttributeDefinitions()))) { throw new ResourceInUseException("Table " + tableName + " had the wrong AttributesToGet." + " Expected: " + definitions + " " + " Was: " + describe.getTable().getAttributeDefinitions()); if(! keySchema.equals(describe.getTable().getKeySchema())) { throw new ResourceInUseException("Table " + tableName + " had the wrong KeySchema." + " Expected: " + keySchema + " " + " Was: " + describe.getTable().getKeySchema()); if(describe.getTable().getLocalSecondaryIndexes() != null) { theirLSIs = new ArrayList<LocalSecondaryIndex>(); for(LocalSecondaryIndexDescription description : describe.getTable().getLocalSecondaryIndexes()) { LocalSecondaryIndex lsi = new LocalSecondaryIndex() .withIndexName(description.getIndexName()) return describe.getTable().getTableStatus();
static void getTableInformation() { TableDescription tableDescription = client.describeTable( new DescribeTableRequest().withTableName(tableName)).getTable(); System.out.format("Name: %s:\n" + "Status: %s \n" + "Provisioned Throughput (read capacity units/sec): %d \n" + "Provisioned Throughput (write capacity units/sec): %d \n", tableDescription.getTableName(), tableDescription.getTableStatus(), tableDescription.getProvisionedThroughput().getReadCapacityUnits(), tableDescription.getProvisionedThroughput().getWriteCapacityUnits()); }
/** * @param entityInformation * The entity to check for it's table * @throws IllegalStateException * is thrown if the existing table doesn't match the entity's * annotation */ private DescribeTableResult performValidate(DynamoDBEntityInformation<T, ID> entityInformation) throws IllegalStateException { Class<T> domainType = entityInformation.getJavaType(); CreateTableRequest expected = mapper.generateCreateTableRequest(domainType); DescribeTableResult result = amazonDynamoDB.describeTable(expected.getTableName()); TableDescription actual = result.getTable(); if (!expected.getKeySchema().equals(actual.getKeySchema())) { throw new IllegalStateException("KeySchema is not as expected. Expected: <" + expected.getKeySchema() + "> but found <" + actual.getKeySchema() + ">"); } LOGGER.debug("KeySchema is valid"); if (expected.getGlobalSecondaryIndexes() != null) { if (!Arrays.deepEquals(expected.getGlobalSecondaryIndexes().toArray(), actual.getGlobalSecondaryIndexes().toArray())) { throw new IllegalStateException("Global Secondary Indexes are not as expected. Expected: <" + expected.getGlobalSecondaryIndexes() + "> but found <" + actual.getGlobalSecondaryIndexes() + ">"); } } LOGGER.debug("Global Secondary Indexes are valid"); LOGGER.info("Validated table {} for entity{}", expected.getTableName(), domainType); return result; }
.appendDynamoDBDocumentUserAgentString(new DescribeTableRequest(this.tableName)); .describeTable(request); this.tableDescription = result.getTable(); for (final KeySchemaElement element : this.tableDescription.getKeySchema()) { final String keyName = element.getAttributeName(); for (final AttributeDefinition ad : this.tableDescription.getAttributeDefinitions()) { if (ad.getAttributeName().equals(keyName)) { final KeyDescription kd = new KeyDescription(); if (this.tableDescription.getLocalSecondaryIndexes() != null) { for (final LocalSecondaryIndexDescription index : this.tableDescription .getLocalSecondaryIndexes()) { this.localSecondaryIndexes.put(index.getIndexName(), index); this.localSecondaryIndexNames.add(index.getIndexName()); if (this.tableDescription.getGlobalSecondaryIndexes() != null) { for (final GlobalSecondaryIndexDescription index : this.tableDescription .getGlobalSecondaryIndexes()) { this.globalSecondaryIndexes.put(index.getIndexName(), index); this.globalSecondaryIndexNames.add(index.getIndexName()); for (final AttributeDefinition ad : this.tableDescription.getAttributeDefinitions()) { this.attributes.add(ad);
/** * Generate a list of attribute names found in the Aggregator's dynamo * table. Assumes that all Items in the Aggregator table are of the same * structure. * * @param dynamoClient Dynamo DB Client to use for connection to Dynamo DB. * @param dynamoTable The Dynamo Table for the Aggregator * @return A list of attribute names from the Dynamo table * @throws Exception */ protected List<String> getDictionaryEntry() throws Exception { // get a list of all columns in the table, with keys first List<String> columns = new ArrayList<>(); List<KeySchemaElement> keys = dynamoClient.describeTable(this.tableName).getTable().getKeySchema(); for (KeySchemaElement key : keys) { columns.add(key.getAttributeName()); } ScanResult scan = dynamoClient.scan(new ScanRequest().withTableName(this.tableName).withSelect( Select.ALL_ATTRIBUTES).withLimit(1)); List<Map<String, AttributeValue>> scannedItems = scan.getItems(); for (Map<String, AttributeValue> map : scannedItems) { for (String s : map.keySet()) { if (!columns.contains(s)) columns.add(s); } } return columns; }
@PostConstruct public void setup() { try { DescribeTableResult table = dynamoDBClient.describeTable(tableConfig.getTableName()); if (!table.getTable().getKeySchema().equals(PROJECT_KEYSCHEMA)) { throw new IllegalStateException("Dynamodb table for query metadata store has invalid key schema"); } if (!ImmutableSet.copyOf(table.getTable().getAttributeDefinitions()).equals(ATTRIBUTES)) { throw new IllegalStateException("Dynamodb table for query metadata store has invalid attribute schema"); } } catch (ResourceNotFoundException e) { createTable(); } }
private boolean validateOrCreateTable(Integer readUnits, Integer writeUnits) { try { Table table = dynamoDB.getTable(tableName); TableDescription tableDescription = table.describe(); if(tableDescription.getProvisionedThroughput().getWriteCapacityUnits() != writeUnits.longValue() || tableDescription.getProvisionedThroughput().getReadCapacityUnits() != readUnits.longValue()) { ProvisionedThroughput throughput = new ProvisionedThroughput() .withWriteCapacityUnits(writeUnits.longValue()) .withReadCapacityUnits(readUnits.longValue()); table.updateTable(throughput); table.waitForActive(); LOG.info( String.format("Table %s already existed, updated R/W units of %d/%d units/sec", table.getTableName(), table.getDescription().getProvisionedThroughput().getReadCapacityUnits(), table.getDescription().getProvisionedThroughput().getWriteCapacityUnits() LOG.info( String.format("Created table '%s'(%s) with throughput %d read, %d write units/sec", tableDescription.getTableName(), tableDescription.getTableStatus(), tableDescription.getProvisionedThroughput().getReadCapacityUnits(), tableDescription.getProvisionedThroughput().getWriteCapacityUnits()
final ListTablesResult tables = _dynamoDb.listTables(); final List<String> tableNames = tables.getTableNames(); for (final String tableName : tableNames) { schema.addTable(table); final DescribeTableResult descripeTableResult = _dynamoDb.describeTable(tableName); final TableDescription tableDescription = descripeTableResult.getTable(); addColumnFromKeySchema("Primary index", tableDescription.getKeySchema(), table, true); .getGlobalSecondaryIndexes(); if (globalSecondaryIndexes != null) { for (final GlobalSecondaryIndexDescription globalSecondaryIndex : globalSecondaryIndexes) { .getLocalSecondaryIndexes(); if (localSecondaryIndexes != null) { for (final LocalSecondaryIndexDescription localSecondaryIndex : localSecondaryIndexes) { final List<AttributeDefinition> attributeDefinitions = tableDescription.getAttributeDefinitions(); for (final AttributeDefinition attributeDefinition : attributeDefinitions) { final String attributeName = attributeDefinition.getAttributeName();
@Override @Retries.OnceRaw public Map<String, String> getDiagnostics() throws IOException { Map<String, String> map = new TreeMap<>(); if (table != null) { TableDescription desc = getTableDescription(true); map.put("name", desc.getTableName()); map.put(STATUS, desc.getTableStatus()); map.put("ARN", desc.getTableArn()); map.put("size", desc.getTableSizeBytes().toString()); map.put(TABLE, desc.toString()); ProvisionedThroughputDescription throughput = desc.getProvisionedThroughput(); map.put(READ_CAPACITY, throughput.getReadCapacityUnits().toString()); map.put(WRITE_CAPACITY, throughput.getWriteCapacityUnits().toString()); map.put(TABLE, desc.toString()); map.put(MetadataStoreCapabilities.PERSISTS_AUTHORITATIVE_BIT, Boolean.toString(true)); } else { map.put("name", "DynamoDB Metadata Store"); map.put(TABLE, "none"); map.put(STATUS, "undefined"); } map.put("description", DESCRIPTION); map.put("region", region); if (batchWriteRetryPolicy != null) { map.put("retryPolicy", batchWriteRetryPolicy.toString()); } return map; }
private long getProvisionedWrites() { return dynamoClient.describeTable(this.tableName).getTable().getProvisionedThroughput().getWriteCapacityUnits(); }
static void getTableInformation() { System.out.println("Describing " + tableName); TableDescription tableDescription = dynamoDB.getTable(tableName).describe(); System.out.format("Name: %s:\n" + "Status: %s \n" + "Provisioned Throughput (read capacity units/sec): %d \n" + "Provisioned Throughput (write capacity units/sec): %d \n", tableDescription.getTableName(), tableDescription.getTableStatus(), tableDescription.getProvisionedThroughput().getReadCapacityUnits(), tableDescription.getProvisionedThroughput().getWriteCapacityUnits()); }