com.amazonaws.services.dynamodbv2.model.TableStatus Java Examples

The following examples show how to use com.amazonaws.services.dynamodbv2.model.TableStatus. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TableHelper.java    From dynamodb-transactions with Apache License 2.0 6 votes vote down vote up
public void waitForTableDeleted(String tableName, long waitTimeSeconds) throws InterruptedException {
    
    if(waitTimeSeconds < 0) {
        throw new IllegalArgumentException("Invalid waitTimeSeconds " + waitTimeSeconds);
    }
    
    long startTimeMs = System.currentTimeMillis();
    long elapsedMs = 0;
    do {
        try {
            DescribeTableResult describe = client.describeTable(new DescribeTableRequest().withTableName(tableName));
            String status = describe.getTable().getTableStatus();
            if(! TableStatus.DELETING.toString().equals(status)) {
                throw new ResourceInUseException("Table " + tableName + " is " + status + ", and waiting for it to not exist is only useful if it is DELETING.");
            }
        } catch (ResourceNotFoundException e) {
            return;
        }
        Thread.sleep(10 * 1000);
        elapsedMs = System.currentTimeMillis() - startTimeMs; 
    } while(elapsedMs / 1000.0 < waitTimeSeconds);
    
    throw new ResourceInUseException("Table " + tableName + " was not deleted after " + waitTimeSeconds + " seconds.");
}
 
Example #2
Source File: LowLevelTableExample.java    From aws-dynamodb-examples with Apache License 2.0 6 votes vote down vote up
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");
}
 
Example #3
Source File: LowLevelLocalSecondaryIndexExample.java    From aws-dynamodb-examples with Apache License 2.0 6 votes vote down vote up
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");
}
 
Example #4
Source File: LowLevelGlobalSecondaryIndexExample.java    From aws-dynamodb-examples with Apache License 2.0 6 votes vote down vote up
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");
}
 
Example #5
Source File: LowLevelParallelScan.java    From aws-dynamodb-examples with Apache License 2.0 6 votes vote down vote up
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");
}
 
Example #6
Source File: LowLevelParallelScan.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
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");
}
 
Example #7
Source File: LowLevelGlobalSecondaryIndexExample.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
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");
}
 
Example #8
Source File: LowLevelLocalSecondaryIndexExample.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
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");
}
 
Example #9
Source File: LowLevelTableExample.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
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");
}
 
Example #10
Source File: GenericDynamoDBTest.java    From strongbox with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTableWithWait() throws Exception {
    // Create fake responses from AWS. First response is still creating the table, second response the table
    // has become active.
    TableDescription creatingDescription = constructTableDescription(TableStatus.CREATING);
    TableDescription createdDescription = constructTableDescription(TableStatus.ACTIVE);
    CreateTableResult mockCreateResult = new CreateTableResult().withTableDescription(creatingDescription);
    DescribeTableResult mockDescribeResultCreating = new DescribeTableResult().withTable(creatingDescription);
    DescribeTableResult mockDescribeResultCreated = new DescribeTableResult().withTable(createdDescription);

    // Create the table.
    CreateTableRequest expectedRequest = dynamoDB.constructCreateTableRequest();
    when(mockDynamoDBClient.createTable(expectedRequest)).thenReturn(mockCreateResult);
    when(mockDynamoDBClient.describeTable(tableName)).thenReturn(mockDescribeResultCreating, mockDescribeResultCreated);
    assertEquals(dynamoDB.create(), TEST_ARN);

    verify(mockDynamoDBClient, times(1)).createTable(expectedRequest);
    verify(mockDynamoDBClient, times(2)).describeTable(tableName);
}
 
Example #11
Source File: TableHelper.java    From dynamodb-transactions with Apache License 2.0 6 votes vote down vote up
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.");
}
 
Example #12
Source File: TableHelper.java    From dynamodb-transactions with Apache License 2.0 6 votes vote down vote up
public void waitForTableActive(String tableName, 
    List<AttributeDefinition> definitions, 
    List<KeySchemaElement> keySchema,
    List<LocalSecondaryIndex> localIndexes,
    long waitTimeSeconds) throws InterruptedException {
    
    if(waitTimeSeconds < 0) {
        throw new IllegalArgumentException("Invalid waitTimeSeconds " + waitTimeSeconds);
    }
    
    long startTimeMs = System.currentTimeMillis();
    long elapsedMs = 0;
    do {
        String status = verifyTableExists(tableName, definitions, keySchema, localIndexes);
        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.");
}
 
Example #13
Source File: TableHelper.java    From dynamodb-transactions with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that the table exists with the specified schema, and creates it if it does not exist.
 * 
 * @param tableName
 * @param definitions
 * @param keySchema
 * @param localIndexes
 * @param provisionedThroughput
 * @param waitTimeSeconds
 * @throws InterruptedException 
 */
public void verifyOrCreateTable(
    String tableName, 
    List<AttributeDefinition> definitions, 
    List<KeySchemaElement> keySchema,
    List<LocalSecondaryIndex> localIndexes,
    ProvisionedThroughput provisionedThroughput,
    Long waitTimeSeconds) throws InterruptedException {
    
    if(waitTimeSeconds != null && waitTimeSeconds < 0) {
        throw new IllegalArgumentException("Invalid waitTimeSeconds " + waitTimeSeconds);
    }
    
    String status = null;
    try {
        status = verifyTableExists(tableName, definitions, keySchema, localIndexes);
    } catch(ResourceNotFoundException e) {
        status = client.createTable(new CreateTableRequest()
            .withTableName(tableName)
            .withAttributeDefinitions(definitions)
            .withKeySchema(keySchema)
            .withLocalSecondaryIndexes(localIndexes)
            .withProvisionedThroughput(provisionedThroughput)).getTableDescription().getTableStatus();
    }
    
    if(waitTimeSeconds != null && ! TableStatus.ACTIVE.toString().equals(status)) {
        waitForTableActive(tableName, definitions, keySchema, localIndexes, waitTimeSeconds);
    }
}
 
Example #14
Source File: DynamoDBDynamicFaultInjection.java    From aws-dynamodb-examples with Apache License 2.0 5 votes vote down vote up
private static void waitForTableToBecomeAvailable(String tableName)
{
    logger.info("Waiting for " + tableName + " to become ACTIVE...");

    long startTime = System.currentTimeMillis();
    long endTime = startTime + (10 * 60 * 1000);
    while (System.currentTimeMillis() < endTime)
    {
        try
        {
            Thread.sleep(1000 * 20);
        }
        catch (Exception e)
        {
        }
        try
        {
            DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
            TableDescription tableDescription = dynamoDBClient.describeTable(request).getTable();
            String tableStatus = tableDescription.getTableStatus();
            logger.info("  - current state: " + tableStatus);
            if (tableStatus.equals(TableStatus.ACTIVE.toString()))
                return;
        }
        catch (AmazonServiceException ase)
        {
            if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == false)
                throw ase;
        }
    }

    throw new RuntimeException("Table " + tableName + " never went active");
}
 
Example #15
Source File: GenericDynamoDB.java    From strongbox with Apache License 2.0 5 votes vote down vote up
private void waitForTableToBecomeActive() {
    int retries = 0;
    String tableStatus = "Unknown";
    try {
        while (retries < MAX_RETRIES) {
            log.info("Waiting for table to become active...");
            Thread.sleep(SLEEP_TIME);
            DescribeTableResult result = client.describeTable(tableName);
            tableStatus = result.getTable().getTableStatus();

            if (tableStatus.equals(TableStatus.ACTIVE.toString()) ||
                    tableStatus.equals(TableStatus.UPDATING.toString())) {
                return;
            }

            if (tableStatus.equals(TableStatus.DELETING.toString())) {
                throw new UnexpectedStateException(
                        tableName, tableStatus, TableStatus.ACTIVE.toString(),
                        "Table state changed to 'DELETING' before creation was confirmed");
            }
            retries++;
        }
    } catch (InterruptedException e) {
        throw new UnexpectedStateException(tableName, tableStatus, TableStatus.ACTIVE.toString(),
                                           "Error occurred while waiting for DynamoDB table", e);
    }
    throw new UnexpectedStateException(tableName, tableStatus, TableStatus.ACTIVE.toString(),
                                       "DynamoDB table did not become active before timeout");
}
 
Example #16
Source File: DynamoDBOperations.java    From geowave with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #17
Source File: DynamoDBOperations.java    From geowave with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #18
Source File: DynamoDBManagerTest.java    From aws-dynamodb-mars-json-demo with Apache License 2.0 5 votes vote down vote up
@Test
public void testWaitForTableToBecomeActiveUpdatingThenActive() {
    // Updating table
    final TableDescription table1 = new TableDescription();
    table1.setTableStatus(TableStatus.UPDATING);
    final DescribeTableResult result1 = new DescribeTableResult().withTable(table1);
    // Active table
    final TableDescription table2 = new TableDescription();
    table2.setTableStatus(TableStatus.ACTIVE);
    final DescribeTableResult result2 = new DescribeTableResult().withTable(table2);
    EasyMock.expect(dynamoDB.describeTable(tableName)).andReturn(result1);
    EasyMock.expect(dynamoDB.describeTable(tableName)).andReturn(result2);
    PowerMock.replayAll();
    DynamoDBManager.waitForTableToBecomeActive(dynamoDB, tableName);
}
 
Example #19
Source File: DynamoDBManagerTest.java    From aws-dynamodb-mars-json-demo with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void testWaitForTableToBecomeActiveNeverGoingActive() {
    final TableDescription table = new TableDescription();
    final DescribeTableResult result = new DescribeTableResult().withTable(table);
    table.setTableStatus(TableStatus.CREATING);
    EasyMock.expect(dynamoDB.describeTable(tableName)).andReturn(result).anyTimes();
    PowerMock.replayAll();
    DynamoDBManager.waitForTableToBecomeActive(dynamoDB, tableName);
}
 
Example #20
Source File: DynamoDBManagerTest.java    From aws-dynamodb-mars-json-demo with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void testWaitForTableToBecomeActiveDeleting() {
    final TableDescription table = new TableDescription().withTableStatus(TableStatus.DELETING);
    final DescribeTableResult result = new DescribeTableResult().withTable(table);
    PowerMock.expectLastCall().andReturn(result);
    PowerMock.replayAll();
    DynamoDBManager.waitForTableToBecomeActive(dynamoDB, tableName);
}
 
Example #21
Source File: DynamoDBManagerTest.java    From aws-dynamodb-mars-json-demo with Apache License 2.0 5 votes vote down vote up
@Test
public void testWaitForTableToBecomeActiveCreatingThenActive() {
    // Creating table
    final TableDescription table1 = new TableDescription();
    table1.setTableStatus(TableStatus.CREATING);
    final DescribeTableResult result1 = new DescribeTableResult().withTable(table1);
    // Active table
    final TableDescription table2 = new TableDescription();
    table2.setTableStatus(TableStatus.ACTIVE);
    final DescribeTableResult result2 = new DescribeTableResult().withTable(table2);
    EasyMock.expect(dynamoDB.describeTable(tableName)).andReturn(result1);
    EasyMock.expect(dynamoDB.describeTable(tableName)).andReturn(result2);
    PowerMock.replayAll();
    DynamoDBManager.waitForTableToBecomeActive(dynamoDB, tableName);
}
 
Example #22
Source File: DynamoDBManagerTest.java    From aws-dynamodb-mars-json-demo with Apache License 2.0 5 votes vote down vote up
@Test
public void testWaitForTableToBecomeActiveAlreadyActive() {
    final TableDescription table = new TableDescription();
    final DescribeTableResult result = new DescribeTableResult().withTable(table);
    table.setTableStatus(TableStatus.ACTIVE);
    dynamoDB.describeTable(tableName);
    PowerMock.expectLastCall().andReturn(result);
    PowerMock.expectLastCall().andReturn(result);
    PowerMock.replayAll();
    DynamoDBManager.waitForTableToBecomeActive(dynamoDB, tableName);
}
 
Example #23
Source File: DynamoDBManagerTest.java    From aws-dynamodb-mars-json-demo with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetTableStatus() {
    final TableDescription description = new TableDescription();
    final DescribeTableResult result = new DescribeTableResult().withTable(description);
    EasyMock.expect(dynamoDB.describeTable(tableName)).andReturn(result).anyTimes();
    for (final TableStatus status : TableStatus.values()) {
        description.setTableStatus(status);
        PowerMock.replayAll();
        assertEquals(status, DynamoDBManager.getTableStatus(dynamoDB, tableName));
        PowerMock.verifyAll();

    }
}
 
Example #24
Source File: KinesisSource.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private boolean leaseTableExists() {
  DescribeTableRequest request = new DescribeTableRequest();
  request.setTableName(conf.applicationName);
  DescribeTableResult result;
  try {
    result = dynamoDBClient.describeTable(request);
  } catch (ResourceNotFoundException e) {
    LOG.debug("Lease table '{}' does not exist", conf.applicationName);
    return false;
  }

  TableStatus tableStatus = TableStatus.fromValue(result.getTable().getTableStatus());
  LOG.debug("Lease table exists and is in '{}' state", tableStatus);
  return tableStatus == TableStatus.ACTIVE;
}
 
Example #25
Source File: DynamoDBDynamicFaultInjection.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
private static void waitForTableToBecomeAvailable(String tableName) {
    logger.info("Waiting for " + tableName + " to become ACTIVE...");

    long startTime = System.currentTimeMillis();
    long endTime = startTime + (10 * 60 * 1000);
    while (System.currentTimeMillis() < endTime) {
        try {
            Thread.sleep(1000 * 20);
        }
        catch (Exception e) {
        }
        try {
            DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
            TableDescription tableDescription = dynamoDBClient.describeTable(request).getTable();
            String tableStatus = tableDescription.getTableStatus();
            logger.info("  - current state: " + tableStatus);
            if (tableStatus.equals(TableStatus.ACTIVE.toString()))
                return;
        }
        catch (AmazonServiceException ase) {
            if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == false)
                throw ase;
        }
    }

    throw new RuntimeException("Table " + tableName + " never went active");
}
 
Example #26
Source File: GenericDynamoDBTest.java    From strongbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteTableWithWait() throws Exception {
    // Create fake responses from AWS.
    TableDescription deletingDescription = constructTableDescription(TableStatus.DELETING);
    DescribeTableResult mockDescribeResult = new DescribeTableResult().withTable(deletingDescription);

    // Delete the table. First response the table is still deleting, the second response the table has deleted
    // and the ResourceNotFoundException is thrown.
    when(mockDynamoDBClient.describeTable(tableName)).thenReturn(mockDescribeResult).thenThrow(
            new ResourceNotFoundException("Table not found"));
    dynamoDB.delete();

    verify(mockDynamoDBClient, times(1)).deleteTable(tableName);
    verify(mockDynamoDBClient, times(2)).describeTable(tableName);
}
 
Example #27
Source File: IntegrationTestHelper.java    From strongbox with Apache License 2.0 5 votes vote down vote up
private static void cleanUpDynamoDBTables(Regions testRegion, String testResourcePrefix, Date createdBeforeThreshold,
                                          AWSCredentialsProvider awsCredentials) {
    LOG.info("Cleaning DynamoDB...");
    AmazonDynamoDB dynamoDBClient = AmazonDynamoDBClientBuilder.standard()
            .withCredentials(awsCredentials)
            .withRegion(testRegion)
            .build();

    List<String> tableNames = dynamoDBClient.listTables().getTableNames();
    for (String tableName: tableNames) {
        if (!tableName.startsWith(testResourcePrefix)) {
            continue;
        }
        LOG.info(String.format("Checking if table %s needs cleaning...", tableName));

        try {
            TableDescription desc = dynamoDBClient.describeTable(tableName).getTable();
            if (!desc.getTableName().equals(TableStatus.DELETING.toString()) &&
                    desc.getCreationDateTime() != null &&
                    desc.getCreationDateTime().before(createdBeforeThreshold)) {
                LOG.info("Cleaning up table: " + tableName);
                dynamoDBClient.deleteTable(tableName);
            }
        } catch (ResourceNotFoundException e) {
            LOG.info("Looks like table was already cleaned up: " + tableName);
        }
    }
}
 
Example #28
Source File: DynamoDSETranslatorJSONBlob.java    From dynamo-cassandra-proxy with Apache License 2.0 5 votes vote down vote up
private TableDescription getTableDescription(String tableName, Collection<AttributeDefinition> attributeDefinitions, Collection<KeySchemaElement> keySchema) {
    TableDescription tableDescription = (new TableDescription())
            .withTableName(tableName)
            .withAttributeDefinitions(attributeDefinitions)
            .withKeySchema(keySchema)
            .withTableStatus(TableStatus.ACTIVE)
            .withCreationDateTime(new Date())
            .withTableArn(tableName);

    return tableDescription;
}
 
Example #29
Source File: DynamoDbDelegate.java    From dynamodb-janusgraph-storage-backend with Apache License 2.0 4 votes vote down vote up
private static boolean isTableStatus(final TableStatus constant, final String status) {
    return constant.toString().equals(status);
}
 
Example #30
Source File: DynamoDbDelegate.java    From dynamodb-janusgraph-storage-backend with Apache License 2.0 4 votes vote down vote up
private static boolean isTableAcceptingWrites(final String status) {
    return isTableStatus(TableStatus.ACTIVE, status) || isTableStatus(TableStatus.UPDATING, status);
}