public TableNeverTransitionedToStateException(String tableName, TableStatus desiredStatus) { super("Table " + tableName + " never transitioned to desired state of " + desiredStatus.toString()); }
this.tableStatus = tableStatus.toString(); return this;
/** * 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 { 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); } }
this.tableStatus = tableStatus.toString();
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; } }
TableDescription table = dynamo.describeTable(new DescribeTableRequest(tableName)) .getTable(); if (table != null && table.getTableStatus().equals(TableStatus.ACTIVE.toString())) return; } catch (ResourceNotFoundException rnfe) {
public TableNeverTransitionedToStateException(String tableName, TableStatus desiredStatus) { super("Table " + tableName + " never transitioned to desired state of " + desiredStatus.toString()); }
private static boolean isTableStatus(final TableStatus constant, final String status) { return constant.toString().equals(status); }
/** * 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!"); } }
private static void waitForTableToBecomeAvailable(String tableName) { System.out.println("Waiting for " + tableName + " to become ACTIVE..."); long startTime = System.currentTimeMillis(); long endTime = startTime + (10 * 60 * 1000); while (System.currentTimeMillis() < endTime) { DescribeTableRequest request = new DescribeTableRequest() .withTableName(tableName); TableDescription tableDescription = client.describeTable( request).getTable(); String tableStatus = tableDescription.getTableStatus(); System.out.println(" - current state: " + tableStatus); if (tableStatus.equals(TableStatus.ACTIVE.toString())) return; try { Thread.sleep(1000 * 20); } catch (Exception e) { } } throw new RuntimeException("Table " + tableName + " never went active"); }
private static void waitForTableToBecomeAvailable(String tableName) { System.out.println("Waiting for " + tableName + " to become ACTIVE..."); long startTime = System.currentTimeMillis(); long endTime = startTime + (10 * 60 * 1000); while (System.currentTimeMillis() < endTime) { DescribeTableRequest request = new DescribeTableRequest() .withTableName(tableName); TableDescription tableDescription = client.describeTable( request).getTable(); String tableStatus = tableDescription.getTableStatus(); System.out.println(" - current state: " + tableStatus); if (tableStatus.equals(TableStatus.ACTIVE.toString())) return; try { Thread.sleep(1000 * 20); } catch (Exception e) { } } throw new RuntimeException("Table " + tableName + " never went active"); }
private static void waitForTableToBecomeAvailable(String tableName) { System.out.println("Waiting for " + tableName + " to become ACTIVE..."); long startTime = System.currentTimeMillis(); long endTime = startTime + (10 * 60 * 1000); while (System.currentTimeMillis() < endTime) { DescribeTableRequest request = new DescribeTableRequest() .withTableName(tableName); TableDescription tableDescription = client.describeTable( request).getTable(); String tableStatus = tableDescription.getTableStatus(); System.out.println(" - current state: " + tableStatus); if (tableStatus.equals(TableStatus.ACTIVE.toString())) return; try { Thread.sleep(1000 * 20); } catch (Exception e) { } } throw new RuntimeException("Table " + tableName + " never went active"); }
private static void waitForTableToBeDeleted(String tableName) { System.out.println("Waiting for " + tableName + " while status DELETING..."); long startTime = System.currentTimeMillis(); long endTime = startTime + (10 * 60 * 1000); while (System.currentTimeMillis() < endTime) { try { DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = client.describeTable(request).getTable(); String tableStatus = tableDescription.getTableStatus(); System.out.println(" - current state: " + tableStatus); if (tableStatus.equals(TableStatus.ACTIVE.toString())) return; } catch (ResourceNotFoundException e) { System.out.println("Table " + tableName + " is not found. It was deleted."); return; } try {Thread.sleep(1000 * 20);} catch (Exception e) {} } throw new RuntimeException("Table " + tableName + " was never deleted"); }
private static void waitForTableToBeDeleted(String tableName) { System.out.println("Waiting for " + tableName + " while status DELETING..."); long startTime = System.currentTimeMillis(); long endTime = startTime + (10 * 60 * 1000); while (System.currentTimeMillis() < endTime) { try { DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = client.describeTable(request).getTable(); String tableStatus = tableDescription.getTableStatus(); System.out.println(" - current state: " + tableStatus); if (tableStatus.equals(TableStatus.ACTIVE.toString())) return; } catch (ResourceNotFoundException e) { System.out.println("Table " + tableName + " is not found. It was deleted."); return; } try {Thread.sleep(1000 * 20);} catch (Exception e) {} } throw new RuntimeException("Table " + tableName + " was never deleted"); }
private static void waitForTableToBeDeleted(String tableName) { System.out.println("Waiting for " + tableName + " while status DELETING..."); long startTime = System.currentTimeMillis(); long endTime = startTime + (10 * 60 * 1000); while (System.currentTimeMillis() < endTime) { try { DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = client.describeTable(request).getTable(); String tableStatus = tableDescription.getTableStatus(); System.out.println(" - current state: " + tableStatus); if (tableStatus.equals(TableStatus.ACTIVE.toString())) return; } catch (ResourceNotFoundException e) { System.out.println("Table " + tableName + " is not found. It was deleted."); return; } try {Thread.sleep(1000 * 20);} catch (Exception e) {} } throw new RuntimeException("Table " + tableName + " was never deleted"); }
private static void waitForTableToBecomeAvailable(String tableName) { System.out.println("Waiting for " + tableName + " to become ACTIVE..."); long startTime = System.currentTimeMillis(); long endTime = startTime + (10 * 60 * 1000); while (System.currentTimeMillis() < endTime) { DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = client.describeTable(request).getTable(); String tableStatus = tableDescription.getTableStatus(); System.out.println(" - current state: " + tableStatus); if (tableStatus.equals(TableStatus.ACTIVE.toString())) return; try { Thread.sleep(1000 * 20); } catch (Exception e) { e.printStackTrace(); } } throw new RuntimeException("Table " + tableName + " never went active"); }
public void waitForTableActive(String tableName, long waitTimeSeconds) throws InterruptedException { if(waitTimeSeconds < 0) { throw new IllegalArgumentException("Invalid waitTimeSeconds " + waitTimeSeconds); } long startTimeMs = System.currentTimeMillis(); long elapsedMs = 0; do { DescribeTableResult describe = client.describeTable(new DescribeTableRequest().withTableName(tableName)); String status = describe.getTable().getTableStatus(); if(TableStatus.ACTIVE.toString().equals(status)) { return; } if(TableStatus.DELETING.toString().equals(status)) { throw new ResourceInUseException("Table " + tableName + " is " + status + ", and waiting for it to become ACTIVE is not useful."); } Thread.sleep(10 * 1000); elapsedMs = System.currentTimeMillis() - startTimeMs; } while(elapsedMs / 1000.0 < waitTimeSeconds); throw new ResourceInUseException("Table " + tableName + " did not become ACTIVE after " + waitTimeSeconds + " seconds."); }