Refine search
while (System.currentTimeMillis() < endTime) { try { table = dynamo.describeTable(new DescribeTableRequest(tableName)).getTable(); if (desiredStatus == null || table.getTableStatus().equals(desiredStatus.toString())) { return table;
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) {
/** * Use this in place of valueOf. * * @param value * real value * @return TableStatus corresponding to the value * * @throws IllegalArgumentException * If the specified value does not map to one of the known values in this enum. */ public static TableStatus fromValue(String value) { if (value == null || "".equals(value)) { throw new IllegalArgumentException("Value cannot be null or empty!"); } for (TableStatus enumEntry : TableStatus.values()) { if (enumEntry.toString().equals(value)) { return enumEntry; } } throw new IllegalArgumentException("Cannot create enum from " + value + " value!"); } }
@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; }
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); } }
/** * 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); } }
/** * 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; }
public TableNeverTransitionedToStateException(String tableName, TableStatus desiredStatus) { super("Table " + tableName + " never transitioned to desired state of " + desiredStatus.toString()); }
@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; }
private TableStatus tableStatus() throws DependencyException { DescribeTableRequest request = new DescribeTableRequest(); request.setTableName(table); DescribeTableResult result; try { result = dynamoDBClient.describeTable(request); } catch (ResourceNotFoundException e) { if (LOG.isDebugEnabled()) { LOG.debug(String.format("Got ResourceNotFoundException for table %s in leaseTableExists, returning false.", table)); } return null; } catch (AmazonClientException e) { throw new DependencyException(e); } TableStatus tableStatus = TableStatus.fromValue(result.getTable().getTableStatus()); if (LOG.isDebugEnabled()) { LOG.debug("Lease table exists and is in status " + tableStatus); } return tableStatus; }
/** * 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); } }
/** * 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; }
this.tableStatus = tableStatus.toString(); return this;
/** * 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; } }
/** * 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; } } }
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) {
.withKeySchema(keySchema) .withLocalSecondaryIndexes(localIndexes) .withProvisionedThroughput(provisionedThroughput)).getTableDescription().getTableStatus(); if(waitTimeSeconds != null && ! TableStatus.ACTIVE.toString().equals(status)) { waitForTableActive(tableName, definitions, keySchema, localIndexes, waitTimeSeconds);
this.tableStatus = tableStatus.toString();
/** * Use this in place of valueOf. * * @param value * real value * @return TableStatus corresponding to the value * * @throws IllegalArgumentException * If the specified value does not map to one of the known values in this enum. */ public static TableStatus fromValue(String value) { if (value == null || "".equals(value)) { throw new IllegalArgumentException("Value cannot be null or empty!"); } for (TableStatus enumEntry : TableStatus.values()) { if (enumEntry.toString().equals(value)) { return enumEntry; } } throw new IllegalArgumentException("Cannot create enum from " + value + " value!"); } }
try { TableDescription table = dynamo.describeTable(new DescribeTableRequest(tableName)) .getTable(); if (table != null && table.getTableStatus().equals(TableStatus.ACTIVE.toString())) return; } catch (ResourceNotFoundException rnfe) {