public TableDescription describeTable(String tableName) { final DescribeTableRequest describeTablesRequest = new DescribeTableRequest() .withTableName(tableName); try { RetryResult<DescribeTableResult> describeResult = getRetryDriver().runWithRetry( new Callable<DescribeTableResult>() { @Override public DescribeTableResult call() { DescribeTableResult result = dynamoDB.describeTable(describeTablesRequest); log.info("Describe table output: " + result); return result; } }, null, null); return describeResult.result.getTable(); } catch (Exception e) { throw new RuntimeException("Could not lookup table " + tableName + " in DynamoDB.", e); } }
@Override public void execute() { DescribeTableResult result = ddbClient.describeTable(new DescribeTableRequest() .withTableName(determineTableName())); Message msg = getMessageForResponse(exchange); msg.setHeader(DdbConstants.TABLE_NAME, result.getTable().getTableName()); msg.setHeader(DdbConstants.TABLE_STATUS, result.getTable().getTableStatus()); msg.setHeader(DdbConstants.CREATION_DATE, result.getTable().getCreationDateTime()); msg.setHeader(DdbConstants.ITEM_COUNT, result.getTable().getItemCount()); msg.setHeader(DdbConstants.KEY_SCHEMA, result.getTable().getKeySchema()); msg.setHeader(DdbConstants.READ_CAPACITY, result.getTable().getProvisionedThroughput().getReadCapacityUnits()); msg.setHeader(DdbConstants.WRITE_CAPACITY, result.getTable().getProvisionedThroughput().getWriteCapacityUnits()); msg.setHeader(DdbConstants.TABLE_SIZE, result.getTable().getTableSizeBytes()); }
@Override public DescribeTableResult describeTable(DescribeTableRequest describeTableRequest) { this.describeTableRequest = describeTableRequest; String tableName = describeTableRequest.getTableName(); if ("activeTable".equals(tableName)) { return tableWithStatus(TableStatus.ACTIVE); } else if ("creatibleTable".equals(tableName) && createTableRequest != null) { return tableWithStatus(TableStatus.ACTIVE); } else if ("FULL_DESCRIBE_TABLE".equals(tableName)) { return new DescribeTableResult().withTable(new TableDescription() .withTableName(tableName) .withTableStatus(TableStatus.ACTIVE) .withCreationDateTime(new Date(NOW)) .withItemCount(100L) .withKeySchema(new KeySchemaElement().withAttributeName("name")) .withProvisionedThroughput(new ProvisionedThroughputDescription() .withReadCapacityUnits(20L) .withWriteCapacityUnits(10L)) .withTableSizeBytes(1000L)); } throw new ResourceNotFoundException(tableName + " is missing"); }
private void waitForStatus(String tableName, TableStatus status) { logger.info("Waiting for " + tableName + " to become " + status.toString() + "..."); long startTime = System.currentTimeMillis(); long endTime = startTime + (10 * 60 * 1000); while (System.currentTimeMillis() < endTime) { try { Thread.sleep(1000 * 2); } catch (Exception e) { } try { DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = dynamoDb.describeTable(request).getTable(); String tableStatus = tableDescription.getTableStatus(); logger.debug(" - current state: " + tableStatus); if (tableStatus.equals(status.toString())) return; } catch (AmazonServiceException ase) { if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == false) throw ase; } } throw new RuntimeException("Table " + tableName + " never went " + status.toString()); }
private String enableStreamForTable(AmazonDynamoDBClient client, StreamViewType viewType, String tableName) { DescribeTableRequest describeTableRequest = new DescribeTableRequest() .withTableName(tableName); DescribeTableResult describeResult = client.describeTable(describeTableRequest); if (describeResult.getTable().getStreamSpecification().isStreamEnabled()) { //TODO: what if the viewtype doesn't match return describeResult.getTable().getLatestStreamId(); } StreamSpecification streamSpecification = new StreamSpecification(); streamSpecification.setStreamEnabled(true); streamSpecification.setStreamViewType(viewType); UpdateTableRequest updateTableRequest = new UpdateTableRequest() .withTableName(tableName) .withStreamSpecification(streamSpecification); UpdateTableResult result = client.updateTable(updateTableRequest); return result.getTableDescription().getLatestStreamId(); }
public static String enableStreamForTable(AmazonDynamoDBClient client, StreamViewType viewType, String tableName) { DescribeTableRequest describeTableRequest = new DescribeTableRequest() .withTableName(tableName); DescribeTableResult describeResult = client.describeTable(describeTableRequest); if (describeResult.getTable().getStreamSpecification().isStreamEnabled()) { //TODO: what if the viewtype doesn't match return describeResult.getTable().getLatestStreamId(); } StreamSpecification streamSpecification = new StreamSpecification(); streamSpecification.setStreamEnabled(true); streamSpecification.setStreamViewType(viewType); UpdateTableRequest updateTableRequest = new UpdateTableRequest() .withTableName(tableName) .withStreamSpecification(streamSpecification); UpdateTableResult result = client.updateTable(updateTableRequest); return result.getTableDescription().getLatestStreamId(); }
private 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 void waitForTableAvailable(String tableName) { LOG.info("Waiting for table " + tableName + " to become ACTIVE..."); long startTime = System.currentTimeMillis(); long endTime = startTime + (10 * 60 * 1000); while (System.currentTimeMillis() < endTime) { DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = dynamoDBClient.describeTable(describeTableRequest).getTable(); // Display current status of table String tableStatus = tableDescription.getTableStatus(); LOG.info("Current state for table " + tableName + ": " + tableStatus); if (tableStatus.equals(TableStatus.ACTIVE.toString())) { return; } try { Thread.sleep(1000 * 20); } catch (Exception ex) { LOG.warn(ex.getMessage()); } } throw new RuntimeException("Table " + tableName + " never went active"); }
/** * Waits up to 6 minutes to confirm if a table has been deleted or not * * @param pTableName */ private void waitForTableToBeDeleted(String pTableName) { LOG.debug("Waiting for " + pTableName + " to be deleted."); long startTime = System.currentTimeMillis(); long endTime = startTime + WAIT_TIME; while (System.currentTimeMillis() < endTime) { try { Thread.sleep(SLEEP_DELETE_TIME); } catch (Exception e) { } try { DescribeTableRequest request = new DescribeTableRequest() .withTableName(pTableName); TableDescription tableDescription = getDynamoDBClient().describeTable( request).getTable(); String tableStatus = tableDescription.getTableStatus(); LOG.debug(pTableName + " - current state: " + tableStatus); } catch (AmazonServiceException ase) { if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == true) return; LOG.error(ase.getMessage()); } } LOG.debug(pTableName + " deleted."); }
/** * Checks if a resource exists or not * * @param tableName * Table name to be checked * @return */ public TableDescription checkResource(String tableName){ TableDescription tableDescription = null; try{ DescribeTableRequest describeTableRequest = new DescribeTableRequest() .withTableName(tableName); tableDescription = dynamoDBClient.describeTable(describeTableRequest) .getTable(); } catch(ResourceNotFoundException e){ tableDescription = null; } return tableDescription; }
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) { e.printStackTrace(); } } throw new RuntimeException("Table " + tableName + " never went active"); }
public void setupTable() { setupGeoDataManager(); GeoDataManagerConfiguration config = geoDataManager.getGeoDataManagerConfiguration(); DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(config.getTableName()); try { config.getDynamoDBClient().describeTable(describeTableRequest); if (status == Status.NOT_STARTED) { status = Status.READY; } } catch (ResourceNotFoundException e) { PhotoLocationsTable photoLocationsTable = new PhotoLocationsTable(); photoLocationsTable.start(); } }
private void waitForTable(String name) { log.info(String.format("Waiting for creation of table '%s' to complete.", name)); long startTime = System.currentTimeMillis(); long endTime = startTime + (10 * 60 * 1000); while (System.currentTimeMillis() < endTime) { sleep(1000 * 20); try { DescribeTableRequest request = new DescribeTableRequest().withTableName(name); TableDescription tableDescription = client.describeTable(request).getTable(); String tableStatus = tableDescription.getTableStatus(); log.info(String.format("Table '%s' is in state: '%s'.", name, tableStatus)); if (tableStatus.equals(TableStatus.ACTIVE.toString())) { return; } } catch (ResourceNotFoundException e) { // nop - maybe the table isn't showing up yet. } } throw new RuntimeException(String.format("Table '%s' never went active.", name)); }
/** * Create table. * @throws InterruptedException If something fails */ public void create() throws InterruptedException { final AmazonDynamoDB aws = this.region.aws(); final String name = this.request.getTableName(); aws.createTable(this.request); Logger.info(this, "DynamoDB table '%s' creation requested...", name); final DescribeTableRequest req = new DescribeTableRequest() .withTableName(name); while (true) { final DescribeTableResult result = aws.describeTable(req); if ("ACTIVE".equals(result.getTable().getTableStatus())) { Logger.info( this, "DynamoDB table '%s' is %s", name, result.getTable().getTableStatus() ); break; } Logger.info( this, "waiting for DynamoDB table '%s': %s", name, result.getTable().getTableStatus() ); TimeUnit.SECONDS.sleep((long) Tv.TEN); } }
public static String getTestTableStatus() { try { AmazonDynamoDBClient ddb = UserPreferenceDemoActivity.clientManager .ddb(); DescribeTableRequest request = new DescribeTableRequest() .withTableName(Constants.TEST_TABLE_NAME); DescribeTableResult result = ddb.describeTable(request); String status = result.getTable().getTableStatus(); return status == null ? "" : status; } catch (ResourceNotFoundException e) { } catch (AmazonServiceException ex) { UserPreferenceDemoActivity.clientManager .wipeCredentialsOnAuthError(ex); } return ""; }
public void setupTable() { setupGeoDataManager(); GeoDataManagerConfiguration config = geoDataManager.getGeoDataManagerConfiguration(); DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(config.getTableName()); try { config.getDynamoDBClient().describeTable(describeTableRequest); if (status == Status.NOT_STARTED) { status = Status.READY; } } catch (ResourceNotFoundException e) { SchoolDataLoader schoolDataLoader = new SchoolDataLoader(); schoolDataLoader.start(); } }
/** * Create ticket tables. * * @param deleteTables the delete tables */ public void createTicketTables(final boolean deleteTables) { final Collection<TicketDefinition> metadata = this.ticketCatalog.findAll(); metadata.forEach(Unchecked.consumer(r -> { final CreateTableRequest request = new CreateTableRequest() .withAttributeDefinitions(new AttributeDefinition(ColumnNames.ID.getName(), ScalarAttributeType.S)) .withKeySchema(new KeySchemaElement(ColumnNames.ID.getName(), KeyType.HASH)) .withProvisionedThroughput(new ProvisionedThroughput(dynamoDbProperties.getReadCapacity(), dynamoDbProperties.getWriteCapacity())) .withTableName(r.getProperties().getStorageName()); if (deleteTables) { final DeleteTableRequest delete = new DeleteTableRequest(r.getProperties().getStorageName()); LOGGER.debug("Sending delete request [{}] to remove table if necessary", delete); TableUtils.deleteTableIfExists(amazonDynamoDBClient, delete); } LOGGER.debug("Sending delete request [{}] to create table", request); TableUtils.createTableIfNotExists(amazonDynamoDBClient, request); LOGGER.debug("Waiting until table [{}] becomes active...", request.getTableName()); TableUtils.waitUntilActive(amazonDynamoDBClient, request.getTableName()); final DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(request.getTableName()); LOGGER.debug("Sending request [{}] to obtain table description...", describeTableRequest); final TableDescription tableDescription = amazonDynamoDBClient.describeTable(describeTableRequest).getTable(); LOGGER.debug("Located newly created table with description: [{}]", tableDescription); })); }
/** * Create tables. * * @param deleteTables the delete tables */ public void createServicesTable(final boolean deleteTables) { try { final CreateTableRequest request = new CreateTableRequest() .withAttributeDefinitions(new AttributeDefinition(ColumnNames.ID.getName(), ScalarAttributeType.S)) .withKeySchema(new KeySchemaElement(ColumnNames.ID.getName(), KeyType.HASH)) .withProvisionedThroughput(new ProvisionedThroughput(dynamoDbProperties.getReadCapacity(), dynamoDbProperties.getWriteCapacity())) .withTableName(TABLE_NAME); if (deleteTables) { final DeleteTableRequest delete = new DeleteTableRequest(request.getTableName()); LOGGER.debug("Sending delete request [{}] to remove table if necessary", delete); TableUtils.deleteTableIfExists(amazonDynamoDBClient, delete); } LOGGER.debug("Sending delete request [{}] to create table", request); TableUtils.createTableIfNotExists(amazonDynamoDBClient, request); LOGGER.debug("Waiting until table [{}] becomes active...", request.getTableName()); TableUtils.waitUntilActive(amazonDynamoDBClient, request.getTableName()); final DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(request.getTableName()); LOGGER.debug("Sending request [{}] to obtain table description...", describeTableRequest); final TableDescription tableDescription = amazonDynamoDBClient.describeTable(describeTableRequest).getTable(); LOGGER.debug("Located newly created table with description: [{}]", tableDescription); } catch (final Exception e) { throw Throwables.propagate(e); } }
private static void createSettingsTable(final AmazonDynamoDBClient amazonDynamoDBClient, final boolean deleteTables) { try { final CreateTableRequest request = new CreateTableRequest() .withAttributeDefinitions(new AttributeDefinition(ColumnNames.ID.getName(), ScalarAttributeType.S)) .withKeySchema(new KeySchemaElement(ColumnNames.ID.getName(), KeyType.HASH)) .withProvisionedThroughput(new ProvisionedThroughput(PROVISIONED_THROUGHPUT, PROVISIONED_THROUGHPUT)) .withTableName(TABLE_NAME); if (deleteTables) { final DeleteTableRequest delete = new DeleteTableRequest(request.getTableName()); LOGGER.debug("Sending delete request [{}] to remove table if necessary", delete); TableUtils.deleteTableIfExists(amazonDynamoDBClient, delete); } LOGGER.debug("Sending delete request [{}] to create table", request); TableUtils.createTableIfNotExists(amazonDynamoDBClient, request); LOGGER.debug("Waiting until table [{}] becomes active...", request.getTableName()); TableUtils.waitUntilActive(amazonDynamoDBClient, request.getTableName()); final DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(request.getTableName()); LOGGER.debug("Sending request [{}] to obtain table description...", describeTableRequest); final TableDescription tableDescription = amazonDynamoDBClient.describeTable(describeTableRequest).getTable(); LOGGER.debug("Located newly created table with description: [{}]", tableDescription); } catch (final Exception e) { throw Throwables.propagate(e); } }
private void createAppsTable(String tableName) { final AttributeDefinition appKey = new AttributeDefinition().withAttributeName(HASH_KEY).withAttributeType( ScalarAttributeType.S); final ArrayList<AttributeDefinition> tableAttributeDefinitions = Lists.newArrayList(appKey); final ArrayList<KeySchemaElement> tableKeySchema = Lists.newArrayList(); tableKeySchema.add( new KeySchemaElement().withAttributeName(HASH_KEY).withKeyType(KeyType.HASH)); final ProvisionedThroughput tableProvisionedThroughput = new ProvisionedThroughput() .withReadCapacityUnits(10L) .withWriteCapacityUnits(10L); final CreateTableRequest createTableRequest = new CreateTableRequest() .withTableName(tableName) .withKeySchema(tableKeySchema) .withAttributeDefinitions(tableAttributeDefinitions) .withProvisionedThroughput(tableProvisionedThroughput); final TableDescription tableDescription = amazonDynamoDB.createTable(createTableRequest).getTableDescription(); logger.info("created_table {}", tableDescription); final DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName); final TableDescription description = amazonDynamoDB.describeTable(describeTableRequest).getTable(); logger.info("table_description: " + description); }
private void waitForTableToBecomeAvailable(String tableName) { LOG.trace("Waiting for [{}] to become ACTIVE...", tableName); long waitTime = 5 * 60 * 1000; while (waitTime > 0) { try { Thread.sleep(1000 * 5); waitTime -= 5000; } catch (Exception e) { } try { DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = getDdbClient().describeTable(request).getTable(); if (isTableActive(tableDescription)) { LOG.trace("Table [{}] became active", tableName); return; } LOG.trace("Table [{}] not active yet", tableName); } catch (AmazonServiceException ase) { if (!ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException")) { throw ase; } } } throw new RuntimeException("Table " + tableName + " never went active"); }
private DescribeTableResult describeTable(final DescribeTableRequest request) throws BackendException { controlPlaneRateLimiter.acquire(); final Timer.Context apiTimerContext = getTimerContext(DESCRIBE_TABLE, request.getTableName()); DescribeTableResult result; try { result = client.describeTable(request); } catch (final Exception e) { throw processDynamoDbApiException(e, DESCRIBE_TABLE, request.getTableName()); } finally { apiTimerContext.stop(); } return result; }
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; }
/** * Retrieves information about the table, including the current status of * the table, the primary key schema and when the table was created. * * If the table does not exist, Amazon DynamoDB returns a * ResourceNotFoundException. * * @param tableName * - The name of the table * @return The response from the DescribeTable service method, as returned by AmazonDynamoDB */ private TableDescription describeTable(String tableName) { try { DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = dynamoDBClient.describeTable(describeTableRequest).getTable(); if (tableDescription != null) { LOG.info("Table description of " + tableName + ": " + tableDescription); } return tableDescription; } catch (ResourceNotFoundException rnfe) { LOG.warn(rnfe.getMessage()); } return null; }
private void waitForTableDeleted(String tableName) { LOG.info("Waiting for table " + tableName + " while status DELETING..."); long startTime = System.currentTimeMillis(); long endTime = startTime + (10 * 60 * 1000); while (System.currentTimeMillis() < endTime) { try { DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = dynamoDBClient.describeTable(describeTableRequest) .getTable(); String tableStatus = tableDescription.getTableStatus(); LOG.info("Current state for table " + tableName + ": " + tableStatus); if (tableStatus.equals(TableStatus.ACTIVE.toString())) { return; } } catch (ResourceNotFoundException rne) { LOG.warn("Table " + tableName + " is not found. It was deleted."); return; } try { Thread.sleep(1000 * 20); } catch (Exception ex) { LOG.warn(ex.getMessage()); } } throw new RuntimeException("Table " + tableName + " was never deleted"); }
/** * Waits up to 6 minutes to confirm if a table has been created or not * * @param awsClient * @param tableName */ public static void waitForTableToBecomeAvailable(AmazonDynamoDB awsClient, String tableName) { LOG.debug("Waiting for {} to become available", tableName); long startTime = System.currentTimeMillis(); long endTime = startTime + WAIT_TIME; while (System.currentTimeMillis() < endTime) { try { Thread.sleep(SLEEP_TIME); } catch (Exception e) { } try { DescribeTableRequest request = new DescribeTableRequest() .withTableName(tableName); TableDescription tableDescription = awsClient.describeTable(request) .getTable(); String tableStatus = tableDescription.getTableStatus(); LOG.debug("{} - current state: {}", tableName, 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 became active"); }
/** * Retrieves the table description for the specific resource name * * @param tableName * @return */ private TableDescription getTableSchema(String tableName) { TableDescription tableDescription = null; try { DescribeTableRequest describeTableRequest = new DescribeTableRequest() .withTableName(tableName); tableDescription = getDynamoDBClient() .describeTable(describeTableRequest).getTable(); } catch (ResourceNotFoundException e) { LOG.error("Error while getting table schema: " + tableName); return tableDescription; } return tableDescription; }
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()); }
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"); }
private void createTableIfNotExisting() { DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(config().getTableName()); try { config().getDynamoDBClient().describeTable(describeTableRequest); } catch (ResourceNotFoundException e) { createTable(); } }
private void waitForTableToBeReady() { DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(config().getTableName()); DescribeTableResult describeTableResult = config().getDynamoDBClient().describeTable(describeTableRequest); while (!describeTableResult.getTable().getTableStatus().equalsIgnoreCase("ACTIVE")) { try { Thread.sleep(2000); //FIXME no endless retry } catch (InterruptedException e) { throw new RuntimeException(e); } describeTableResult = config().getDynamoDBClient().describeTable(describeTableRequest); } }
protected boolean doesTableExist(String tableName) { try { DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName); DescribeTableResult result = ddb.describeTable(request); return (result != null && "ACTIVE".equals(result.getTable().getTableStatus())); } catch (ResourceNotFoundException e) { return false; } }
private void waitForTableToBeReady() { GeoDataManagerConfiguration config = geoDataManager.getGeoDataManagerConfiguration(); DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(config.getTableName()); DescribeTableResult describeTableResult = config.getDynamoDBClient().describeTable(describeTableRequest); while (!describeTableResult.getTable().getTableStatus().equalsIgnoreCase("ACTIVE")) { try { Thread.sleep(2000); } catch (InterruptedException e) { throw new RuntimeException(e); } describeTableResult = config.getDynamoDBClient().describeTable(describeTableRequest); } }
private boolean tableExists(String name) { try { client.describeTable(new DescribeTableRequest().withTableName(name)); } catch (ResourceNotFoundException e) { return false; } return true; }
/** * Returns true if the specified table exists, and is active and ready for use. */ private static boolean doesTableExist(String tableName) { try { TableDescription table = dynamo.describeTable(new DescribeTableRequest().withTableName(tableName)) .getTable(); return "ACTIVE".equals(table.getTableStatus()); } catch (AmazonServiceException ase) { if (ase.getErrorCode().equals("ResourceNotFoundException")) { return false; } throw ase; } }
private boolean tablesExist() { try { DescribeTableRequest describeTableRequest = new DescribeTableRequest() .withTableName(TABLE_NAME); dynamoDB.describeTable(describeTableRequest).getTable(); return true; } catch (Exception e) { return false; } }