/** * A convenient blocking call that can be used to wait on a table until it * has either become active or deleted (ie no longer exists) by polling the * table every 5 seconds. * * @return the table description if the table has become active; or null * if the table has been deleted. * * @deprecated If this method is called immediately after * {@link AmazonDynamoDB#createTable(CreateTableRequest)} or * {@link AmazonDynamoDB#deleteTable(DeleteTableRequest)} operation, * the result might be incorrect as all {@link com.amazonaws.services.dynamodbv2.AmazonDynamoDB} * operations are eventually consistent and might have a few seconds delay before the status is changed. */ @Deprecated public TableDescription waitForActiveOrDelete() throws InterruptedException { try { for (;;) { TableDescription desc = describe(); final String status = desc.getTableStatus(); if (TableStatus.fromValue(status) == TableStatus.ACTIVE) return desc; else Thread.sleep(SLEEP_TIME_MILLIS); } } catch(ResourceNotFoundException deleted) { } return null; }
try { table = dynamo.describeTable(new DescribeTableRequest(tableName)).getTable(); if (desiredStatus == null || table.getTableStatus().equals(desiredStatus.toString())) { return table;
/** * Waits up to a specified amount of time for a specified DynamoDB table to * move into the <code>ACTIVE</code> state. If the table does not exist or * does not transition to the <code>ACTIVE</code> state after this time, * then a SdkClientException is thrown. * * @param dynamo * The DynamoDB client to use to make requests. * @param tableName * The name of the table whose status is being checked. * @param timeout * The maximum number of milliseconds to wait. * @param interval * The poll interval in milliseconds. * * @throws TableNeverTransitionedToStateException * If the specified table does not exist or does not transition * into the <code>ACTIVE</code> state before this method times * out and stops polling. * @throws InterruptedException * If the thread is interrupted while waiting for the table to * transition into the <code>ACTIVE</code> state. */ public static void waitUntilActive(final AmazonDynamoDB dynamo, final String tableName, final int timeout, final int interval) throws InterruptedException, TableNeverTransitionedToStateException { TableDescription table = waitForTableDescription(dynamo, tableName, TableStatus.ACTIVE, timeout, interval); if (table == null || !table.getTableStatus().equals(TableStatus.ACTIVE.toString())) { throw new TableNeverTransitionedToStateException(tableName, TableStatus.ACTIVE); } }
if (getKeySchema() != null) sb.append("KeySchema: ").append(getKeySchema()).append(","); if (getTableStatus() != null) sb.append("TableStatus: ").append(getTableStatus()).append(","); if (getCreationDateTime() != null) sb.append("CreationDateTime: ").append(getCreationDateTime()).append(",");
retry: for (;;) { TableDescription desc = describe(); String status = desc.getTableStatus(); if (TableStatus.fromValue(status) == TableStatus.ACTIVE) { List<GlobalSecondaryIndexDescription> descriptions =
@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; }
if (other.getKeySchema() != null && other.getKeySchema().equals(this.getKeySchema()) == false) return false; if (other.getTableStatus() == null ^ this.getTableStatus() == null) return false; if (other.getTableStatus() != null && other.getTableStatus().equals(this.getTableStatus()) == false) return false; if (other.getCreationDateTime() == null ^ this.getCreationDateTime() == null)
/** * Marshall the given parameter object. */ public void marshall(TableDescription tableDescription, ProtocolMarshaller protocolMarshaller) { if (tableDescription == null) { throw new SdkClientException("Invalid argument passed to marshall(...)"); } try { protocolMarshaller.marshall(tableDescription.getAttributeDefinitions(), ATTRIBUTEDEFINITIONS_BINDING); protocolMarshaller.marshall(tableDescription.getTableName(), TABLENAME_BINDING); protocolMarshaller.marshall(tableDescription.getKeySchema(), KEYSCHEMA_BINDING); protocolMarshaller.marshall(tableDescription.getTableStatus(), TABLESTATUS_BINDING); protocolMarshaller.marshall(tableDescription.getCreationDateTime(), CREATIONDATETIME_BINDING); protocolMarshaller.marshall(tableDescription.getProvisionedThroughput(), PROVISIONEDTHROUGHPUT_BINDING); protocolMarshaller.marshall(tableDescription.getTableSizeBytes(), TABLESIZEBYTES_BINDING); protocolMarshaller.marshall(tableDescription.getItemCount(), ITEMCOUNT_BINDING); protocolMarshaller.marshall(tableDescription.getTableArn(), TABLEARN_BINDING); protocolMarshaller.marshall(tableDescription.getTableId(), TABLEID_BINDING); protocolMarshaller.marshall(tableDescription.getBillingModeSummary(), BILLINGMODESUMMARY_BINDING); protocolMarshaller.marshall(tableDescription.getLocalSecondaryIndexes(), LOCALSECONDARYINDEXES_BINDING); protocolMarshaller.marshall(tableDescription.getGlobalSecondaryIndexes(), GLOBALSECONDARYINDEXES_BINDING); protocolMarshaller.marshall(tableDescription.getStreamSpecification(), STREAMSPECIFICATION_BINDING); protocolMarshaller.marshall(tableDescription.getLatestStreamLabel(), LATESTSTREAMLABEL_BINDING); protocolMarshaller.marshall(tableDescription.getLatestStreamArn(), LATESTSTREAMARN_BINDING); protocolMarshaller.marshall(tableDescription.getRestoreSummary(), RESTORESUMMARY_BINDING); protocolMarshaller.marshall(tableDescription.getSSEDescription(), SSEDESCRIPTION_BINDING); } catch (Exception e) { throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e); } }
/** * Checks if a specified table exists and is in <code>ACTIVE</code> state. * * @param dynamo The AWS DynamoDB client to use to make requests. * @param tableName The name of the table being searched for. * @return True if a table already exists with the specified name, otherwise * false. */ public static boolean doesTableExist(AmazonDynamoDB dynamo, String tableName) { try { TableDescription table = dynamo.describeTable(new DescribeTableRequest(tableName)) .getTable(); return TableStatus.ACTIVE.toString().equals(table.getTableStatus()); } catch (ResourceNotFoundException rnfe) { // This means the table doesn't exist in the account yet return false; } }
TableDescription table = dynamo.describeTable(new DescribeTableRequest(tableName)) .getTable(); if (table != null && table.getTableStatus().equals(TableStatus.ACTIVE.toString())) return; } catch (ResourceNotFoundException rnfe) {
if (getKeySchema() != null) sb.append("KeySchema: " + getKeySchema() + ","); if (getTableStatus() != null) sb.append("TableStatus: " + getTableStatus() + ","); if (getCreationDateTime() != null) sb.append("CreationDateTime: " + getCreationDateTime() + ",");
hashCode = prime * hashCode + ((getKeySchema() == null) ? 0 : getKeySchema().hashCode()); hashCode = prime * hashCode + ((getTableStatus() == null) ? 0 : getTableStatus().hashCode()); hashCode = prime * hashCode + ((getCreationDateTime() == null) ? 0 : getCreationDateTime().hashCode());
&& other.getKeySchema().equals(this.getKeySchema()) == false) return false; if (other.getTableStatus() == null ^ this.getTableStatus() == null) return false; if (other.getTableStatus() != null && other.getTableStatus().equals(this.getTableStatus()) == false) return false; if (other.getCreationDateTime() == null ^ this.getCreationDateTime() == null)
public static void assertNoStaleTables(AmazonDynamoDBClient client, String when) { /* Get the list of tables without the ones in the deleting state */ List<String> tables = client.listTables().getTableNames().stream() .filter(t -> System.currentTimeMillis() - AWSUtils.toEpochMillis(t) > AWSUtils.HOUR || !"DELETING".equals(client.describeTable(t).getTable().getTableStatus())) .collect(Collectors.toList()); Assert.assertEquals(String.format("Found stale DynamoDB tables %s running the test: %s", when, tables), 0, tables.size()); }
public static void assertNoStaleTables(AmazonDynamoDBClient client, String when) { /* Get the list of tables without the ones in the deleting state */ List<String> tables = client.listTables().getTableNames().stream() .filter(t -> System.currentTimeMillis() - AWSUtils.toEpochMillis(t) > AWSUtils.HOUR || !"DELETING".equals(client.describeTable(t).getTable().getTableStatus())) .collect(Collectors.toList()); Assert.assertEquals(String.format("Found stale DynamoDB tables %s running the test: %s", when, tables), 0, tables.size()); }
@Override public boolean indexExists(final String indexName) throws IOException { try { return TableStatus.ACTIVE.name().equals( client.describeTable(getQualifiedTableName(indexName)).getTable().getTableStatus()); } catch (final AmazonDynamoDBException e) { LOGGER.info("Unable to check existence of table", e); } return false; }
@Override public boolean metadataExists(final MetadataType type) throws IOException { try { return TableStatus.ACTIVE.name().equals( client.describeTable(getMetadataTableName(type)).getTable().getTableStatus()); } catch (final AmazonDynamoDBException e) { LOGGER.info("Unable to check existence of table", e); } return false; }
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()); }
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()); }
if (tableDescription.getTableStatus() != null) { String tableStatus = tableDescription.getTableStatus(); jsonWriter.name("TableStatus"); jsonWriter.value(tableStatus);