/** * * @{inheritDoc */ @Override public void deleteTable(String tableName) { try { if (hasTable(tableName)) { logger.info("Deleting table: " + tableName); DeleteTableRequest deleteTableRequest = new DeleteTableRequest(tableName); DeleteTableResult result = dynamoDb.deleteTable(deleteTableRequest); logger.info("Deleted table: " + result.getTableDescription().getTableName()); waitForDelete(tableName); } } catch (Exception t) { logger.error(t, t); throw new RuntimeException(t); } }
protected void clean(){ /* I had to hardcode the DES- prefix due to the fact that DynamoDBMapper doesn't currently have a generateDeleteTableRequest which takes into account the TableNameOverride settings. I've submited a PR to aws-sdk-java repository. https://github.com/aws/aws-sdk-java/pull/606#issuecomment-172940752 As soon as it gets merged I'll remove it */ String prefix = "DES-"; amazonDynamoDBClient.deleteTable(new DeleteTableRequest(prefix.concat(extractTableName(OCRTransaction.class)))); amazonDynamoDBClient.deleteTable(new DeleteTableRequest(prefix.concat(extractTableName(TaxReceipt.class)))); amazonDynamoDBClient.deleteTable(new DeleteTableRequest(prefix.concat(extractTableName(TaxReceiptArchive.class)))); amazonDynamoDBClient.deleteTable(new DeleteTableRequest(prefix.concat(extractTableName(ElectronicTaxReceipt.class)))); amazonDynamoDBClient.deleteTable(new DeleteTableRequest(prefix.concat(extractTableName(ElectronicTaxReceiptArchive.class)))); }
@Override public boolean deleteTable(String tableName) { try { DeleteTableRequest deleteTableRequest = new DeleteTableRequest().withTableName(tableName); DeleteTableResult deleteTableResult = dynamoDBClient.deleteTable(deleteTableRequest); if (deleteTableRequest != null) { LOG.info("Deleting table description: " + deleteTableResult); // Waiting for table deleted waitForTableDeleted(tableName); LOG.info("Successfully deleted table " + tableName); return true; } } catch (ResourceInUseException rie) { LOG.warn("Table " + tableName + " already exists"); } catch (AmazonServiceException ase) { LOG.error(ase.getMessage(), ase); } catch (AmazonClientException ace) { LOG.error(ace.getMessage(), ace); } return false; }
/** * 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); } }
@AfterClass public static void deleteTable() { final DeleteTableRequest deleteTableRequest = new DeleteTableRequest(tableName); // credentials need to be set in local environment // see http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html TableUtils.deleteTableIfExists(new AmazonDynamoDBClient(), deleteTableRequest); }
@Override public void execute() { TableDescription tableDescription = ddbClient .deleteTable(new DeleteTableRequest(determineTableName())).getTableDescription(); Map tmp = new HashMap<>(); tmp.put(DdbConstants.PROVISIONED_THROUGHPUT, tableDescription.getProvisionedThroughput()); tmp.put(DdbConstants.CREATION_DATE, tableDescription.getCreationDateTime()); tmp.put(DdbConstants.ITEM_COUNT, tableDescription.getItemCount()); tmp.put(DdbConstants.KEY_SCHEMA, tableDescription.getKeySchema()); tmp.put(DdbConstants.TABLE_NAME, tableDescription.getTableName()); tmp.put(DdbConstants.TABLE_SIZE, tableDescription.getTableSizeBytes()); tmp.put(DdbConstants.TABLE_STATUS, tableDescription.getTableStatus()); addToResults(tmp); }
@Override public DeleteTableResult deleteTable(DeleteTableRequest deleteTableRequest) { this.deleteTableRequest = deleteTableRequest; return new DeleteTableResult().withTableDescription(new TableDescription() .withProvisionedThroughput(new ProvisionedThroughputDescription()) .withTableName(deleteTableRequest.getTableName()) .withCreationDateTime(new Date(NOW)) .withItemCount(10L) .withKeySchema(new ArrayList<KeySchemaElement>()) .withTableSizeBytes(20L) .withTableStatus(TableStatus.ACTIVE)); }
public DeleteTableResult deleteTable(final DeleteTableRequest request) throws BackendException { controlPlaneRateLimiter.acquire(); final Timer.Context apiTimerContext = getTimerContext(DELETE_TABLE, request.getTableName()); DeleteTableResult result; try { result = client.deleteTable(request); } catch (Exception e) { throw processDynamoDbApiException(e, DELETE_TABLE, request.getTableName()); } finally { apiTimerContext.stop(); } return result; }
/** * Delete the table with given name * * @param tableName */ public static void deleteTable(String tableName) { try { DynamoDbHandler.CLIENT .deleteTable(new DeleteTableRequest(tableName)); } catch (Exception e) { //Table does not exist } }
/** * Deletes the main table from AWS DynamoDB. * @param appid name of the {@link com.erudika.para.core.App} * @return true if deleted */ public static boolean deleteTable(String appid) { if (StringUtils.isBlank(appid) || !existsTable(appid)) { return false; } try { String table = getTableNameForAppid(appid); getClient().deleteTable(new DeleteTableRequest().withTableName(table)); logger.info("Deleted DynamoDB table '{}'.", table); } catch (Exception e) { logger.error(null, e); return false; } return true; }
/** * Executes a delete table request using the DynamoDB client * * @param pTableName */ public void executeDeleteTableRequest(String pTableName) { try { DeleteTableRequest deleteTableRequest = new DeleteTableRequest() .withTableName(pTableName); DeleteTableResult result = getDynamoDBClient().deleteTable( deleteTableRequest); waitForTableToBeDeleted(pTableName); LOG.debug("Schema: " + result.getTableDescription() + " deleted successfully."); } catch (Exception e) { LOG.debug("Schema: {} deleted.", pTableName, e.getMessage()); throw new RuntimeException(e); } }
private static void deleteTable(String tableName){ try { DeleteTableRequest request = new DeleteTableRequest() .withTableName(tableName); client.deleteTable(request); } catch (AmazonServiceException ase) { System.err.println("Failed to delete table " + tableName + " " + ase); } }
private static void cleanupAndExit(Integer returnValue) { String srcTable = tablePrefix + "-src"; String destTable = tablePrefix + "-dest"; dynamoDBClient.deleteTable(new DeleteTableRequest().withTableName(srcTable)); dynamoDBClient.deleteTable(new DeleteTableRequest().withTableName(destTable)); System.exit(returnValue); }
/** * Drop table. * @throws InterruptedException If something fails */ public void drop() throws InterruptedException { final AmazonDynamoDB aws = this.region.aws(); final String name = this.request.getTableName(); aws.deleteTable(new DeleteTableRequest().withTableName(name)); Logger.info(this, "DynamoDB table '%s' deletion requested", name); while (this.exists()) { Logger.info(this, "DynamoDB table '%s' still exists", name); TimeUnit.SECONDS.sleep((long) Tv.TEN); } Logger.info(this, "DynamoDB table '%s' deleted", name); }
public static void cleanUp() { AmazonDynamoDBClient ddb = UserPreferenceDemoActivity.clientManager .ddb(); DeleteTableRequest request = new DeleteTableRequest() .withTableName(Constants.TEST_TABLE_NAME); try { ddb.deleteTable(request); } catch (AmazonServiceException ex) { UserPreferenceDemoActivity.clientManager .wipeCredentialsOnAuthError(ex); } }
private DeleteTableResult deletePlanoRequestsTable() { DeleteTableRequest request = mapper.generateDeleteTableRequest(DynamoDBPlanoRequest.class); DeleteTableResult deleteTableResult = dynamoDB.deleteTable(request); return deleteTableResult; }
private DeleteTableResult deletePlanoRequestsTable() { DeleteTableRequest request = sDynamoDBMapper.generateDeleteTableRequest(DynamoDBPlanoRequest.class); DeleteTableResult deleteTableResult = sDynamoDB.deleteTable(request); return deleteTableResult; }
DeleteTableResult deleteTable(final String tableName) throws BackendException { return deleteTable(new DeleteTableRequest().withTableName(tableName)); }
public static void cleanupAndExit(AmazonDynamoDBClient dynamoDBClient, String srcTable, Integer returnValue) { dynamoDBClient.deleteTable(new DeleteTableRequest().withTableName(srcTable)); System.exit(returnValue); }
static void deleteExampleTable() { DeleteTableRequest deleteTableRequest = new DeleteTableRequest() .withTableName(tableName); client.deleteTable(deleteTableRequest); waitForTableToBeDeleted(tableName); }
public static void deleteTable(String tableName) { System.out.println("Deleting table " + tableName + "..."); client.deleteTable(new DeleteTableRequest().withTableName(tableName)); waitForTableToBeDeleted(tableName); }