com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException Java Examples
The following examples show how to use
com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException.
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: DynamoDBTableResolver.java From aws-athena-query-federation with Apache License 2.0 | 6 votes |
/** * Fetches table metadata by first doing a DescribeTable on the given table table, falling back to case * insensitive resolution if the table isn't found. * * @param tableName the case insensitive table name * @return the table's metadata */ public DynamoDBTable getTableMetadata(String tableName) throws TimeoutException { try { return DDBTableUtils.getTable(tableName, invoker, ddbClient); } catch (ResourceNotFoundException e) { Optional<String> caseInsensitiveMatch = tryCaseInsensitiveSearch(tableName); if (caseInsensitiveMatch.isPresent()) { return DDBTableUtils.getTable(caseInsensitiveMatch.get(), invoker, ddbClient); } else { throw e; } } }
Example #2
Source File: DynamoDBTableResolver.java From aws-athena-query-federation with Apache License 2.0 | 6 votes |
/** * Fetches table schema by first doing a Scan on the given table name, falling back to case insensitive * resolution if the table isn't found. Delegates actual schema derivation to {@link * DDBTableUtils#peekTableForSchema}. * * @param tableName the case insensitive table name * @return the table's schema */ public Schema getTableSchema(String tableName) throws TimeoutException { try { return DDBTableUtils.peekTableForSchema(tableName, invoker, ddbClient); } catch (ResourceNotFoundException e) { Optional<String> caseInsensitiveMatch = tryCaseInsensitiveSearch(tableName); if (caseInsensitiveMatch.isPresent()) { return DDBTableUtils.peekTableForSchema(caseInsensitiveMatch.get(), invoker, ddbClient); } else { throw e; } } }
Example #3
Source File: TableHelper.java From dynamodb-transactions with Apache License 2.0 | 6 votes |
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 #4
Source File: Utilities.java From dynamodb-geo with Apache License 2.0 | 6 votes |
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(); } }
Example #5
Source File: AbstractDynamoDBRecordWriter.java From emr-dynamodb-connector with Apache License 2.0 | 6 votes |
public AbstractDynamoDBRecordWriter(JobConf jobConf, Progressable progressable) { this.progressable = progressable; client = new DynamoDBClient(jobConf); tableName = jobConf.get(DynamoDBConstants.OUTPUT_TABLE_NAME); if (tableName == null) { throw new ResourceNotFoundException("No output table name was specified."); } deletionMode = jobConf.getBoolean(DynamoDBConstants.DELETION_MODE, DynamoDBConstants.DEFAULT_DELETION_MODE); IopsCalculator iopsCalculator = new WriteIopsCalculator(createJobClient(jobConf), client, tableName); iopsController = new IopsController(iopsCalculator, DEFAULT_AVERAGE_ITEM_SIZE_IN_BYTES, DynamoDBOperationType.WRITE); permissibleWritesPerSecond = iopsController.getTargetItemsPerSecond(); log.info("Number of allocated item writes per second: " + permissibleWritesPerSecond); // Hive may not have a valid Reporter and pass in null progressable // TODO Check whether this would happen when excluding Hive if (progressable instanceof Reporter) { reporter = (Reporter) progressable; } }
Example #6
Source File: DynamoDBPersistenceService.java From openhab1-addons with Eclipse Public License 2.0 | 6 votes |
/** * Flush batch of data to DynamoDB * * @param mapper mapper associated with the batch * @param batch batch of data to write to DynamoDB */ private void flushBatch(DynamoDBMapper mapper, Deque<DynamoDBItem<?>> batch) { long currentTimeMillis = System.currentTimeMillis(); List<FailedBatch> failed = mapper.batchSave(batch); for (FailedBatch failedBatch : failed) { if (failedBatch.getException() instanceof ResourceNotFoundException) { // Table did not exist. Try writing everything again. retryFlushAfterCreatingTable(mapper, batch, failedBatch); break; } else { logger.debug("Batch failed with {}. Retrying next with exponential back-off", failedBatch.getException().getMessage()); new ExponentialBackoffRetry(failedBatch.getUnprocessedItems()).run(); } } if (failed.isEmpty()) { logger.debug("flushBatch ended with {} items in {} ms: {}", batch.size(), System.currentTimeMillis() - currentTimeMillis, batch); } else { logger.warn( "flushBatch ended with {} items in {} ms: {}. There were some failed batches that were retried -- check logs for ERRORs to see if writes were successful", batch.size(), System.currentTimeMillis() - currentTimeMillis, batch); } }
Example #7
Source File: CrossRegionReplicationIntegrationTests.java From dynamodb-cross-region-library with Apache License 2.0 | 6 votes |
@Before public void setup() { dynamoDbIad = buildDynamoDbClient(Regions.US_EAST_1); iadTable = new Table(dynamoDbIad, INVENTORY_TABLE_IAD); dynamoDbPdx = buildDynamoDbClient(Regions.US_WEST_2); pdxTable = new Table(dynamoDbIad, INVENTORY_TABLE_PDX); try { dynamoDbIad.deleteTable(INVENTORY_TABLE_IAD); for (String tableName : dynamoDbIad.listTables().getTableNames()) { if (tableName.contains(CRR_INTEGRATION_TEST)) { dynamoDbIad.deleteTable(tableName); //KCL lease table used in test break; } } dynamoDbPdx.deleteTable(INVENTORY_TABLE_PDX); } catch(ResourceNotFoundException e) { //do nothing } }
Example #8
Source File: Utilities.java From reinvent2013-mobile-photo-share with Apache License 2.0 | 6 votes |
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(); } }
Example #9
Source File: DynamoDBUtils.java From amazon-kinesis-connectors with Apache License 2.0 | 5 votes |
/** * Helper method to determine if an Amazon DynamoDB table exists. * * @param client * The {@link AmazonDynamoDBClient} with Amazon DynamoDB read privileges * @param tableName * The Amazon DynamoDB table to check for * @return true if the Amazon DynamoDB table exists, otherwise return false */ private static boolean tableExists(AmazonDynamoDBClient client, String tableName) { DescribeTableRequest describeTableRequest = new DescribeTableRequest(); describeTableRequest.setTableName(tableName); try { client.describeTable(describeTableRequest); return true; } catch (ResourceNotFoundException e) { return false; } }
Example #10
Source File: TableHelper.java From dynamodb-transactions with Apache License 2.0 | 5 votes |
/** * 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 #11
Source File: TransactionManager.java From dynamodb-transactions with Apache License 2.0 | 5 votes |
protected List<KeySchemaElement> getTableSchema(String tableName) throws ResourceNotFoundException { List<KeySchemaElement> schema = tableSchemaCache.get(tableName); if(schema == null) { DescribeTableResult result = client.describeTable(new DescribeTableRequest().withTableName(tableName)); schema = Collections.unmodifiableList(result.getTable().getKeySchema()); tableSchemaCache.put(tableName, schema); } return schema; }
Example #12
Source File: DynamoDBPersistenceService.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
private boolean sleep() { try { long sleepTime; if (retry == 1 && lastException != null && lastException instanceof ResourceNotFoundException) { sleepTime = WAIT_ON_FIRST_RESOURCE_NOT_FOUND_MILLIS; } else { sleepTime = WAIT_MILLIS_IN_RETRIES[retry]; } Thread.sleep(sleepTime); return true; } catch (InterruptedException e) { logger.debug("Interrupted while writing data!"); return false; } }
Example #13
Source File: DynamoDBPersistenceService.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
@Override public void run() { logger.debug("Error storing object to dynamo, unprocessed items: {}. Retrying with exponential back-off", unprocessedItems); lastException = null; while (!unprocessedItems.isEmpty() && retry < WAIT_MILLIS_IN_RETRIES.length) { if (!sleep()) { // Interrupted return; } retry++; try { BatchWriteItemOutcome outcome = DynamoDBPersistenceService.this.db.getDynamoDB() .batchWriteItemUnprocessed(unprocessedItems); unprocessedItems = outcome.getUnprocessedItems(); lastException = null; } catch (AmazonServiceException e) { if (e instanceof ResourceNotFoundException) { logger.debug( "DynamoDB query raised unexpected exception: {}. This might happen if table was recently created", e.getMessage()); } else { logger.debug("DynamoDB query raised unexpected exception: {}.", e.getMessage()); } lastException = e; continue; } } if (unprocessedItems.isEmpty()) { logger.debug("After {} retries successfully wrote all unprocessed items", retry); } else { logger.warn( "Even after retries failed to write some items. Last exception: {} {}, unprocessed items: {}", lastException == null ? "null" : lastException.getClass().getName(), lastException == null ? "null" : lastException.getMessage(), unprocessedItems); } }
Example #14
Source File: BaseAdmin.java From reinvent2013-mobile-photo-share with Apache License 2.0 | 5 votes |
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; } }
Example #15
Source File: BaseAdmin.java From reinvent2013-mobile-photo-share with Apache License 2.0 | 5 votes |
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; } }
Example #16
Source File: AwsNoSqlConnectorTest.java From cloudbreak with Apache License 2.0 | 5 votes |
@Test public void getNoSqlTableResourceNotFound() { when(dynamoDb.deleteTable(argThat((ArgumentMatcher<String>) argument -> true))).thenThrow(new ResourceNotFoundException("not found")); NoSqlTableDeleteResponse result = underTest.deleteNoSqlTable(new NoSqlTableDeleteRequest()); assertNull(result.getId()); assertNull(result.getTableStatus()); assertEquals(ResponseStatus.RESOURCE_NOT_FOUND, result.getStatus()); }
Example #17
Source File: AwsNoSqlConnectorTest.java From cloudbreak with Apache License 2.0 | 5 votes |
@Test public void getNoSqlTableMetaDataResourceNotFound() { when(dynamoDb.describeTable(argThat((ArgumentMatcher<String>) argument -> true))).thenThrow(new ResourceNotFoundException("not found")); NoSqlTableMetadataResponse result = underTest.getNoSqlTableMetaData(new NoSqlTableMetadataRequest()); assertNull(result.getId()); assertNull(result.getTableStatus()); assertEquals(ResponseStatus.RESOURCE_NOT_FOUND, result.getStatus()); }
Example #18
Source File: DynamoDBManagerTest.java From aws-dynamodb-mars-json-demo with Apache License 2.0 | 5 votes |
@Test public void testTableDoesNotExist() { EasyMock.expect(dynamoDB.describeTable(tableName)).andThrow(new ResourceNotFoundException("")); PowerMock.replayAll(); assertFalse(DynamoDBManager.doesTableExist(dynamoDB, tableName)); PowerMock.verifyAll(); }
Example #19
Source File: DynamoDBManagerTest.java From aws-dynamodb-mars-json-demo with Apache License 2.0 | 5 votes |
@Test public void testCreateTableTableDoesNotExist() { final Collection<AttributeDefinition> ads = Arrays.asList(new AttributeDefinition("Hash", ScalarAttributeType.S)); final Collection<KeySchemaElement> kses = Arrays.asList(new KeySchemaElement("Hash", KeyType.HASH)); final TableDescription description = new TableDescription().withAttributeDefinitions(ads).withKeySchema(kses) .withTableName(tableName); final CreateTableResult cTR = new CreateTableResult().withTableDescription(description); EasyMock.expect(dynamoDB.describeTable(tableName)).andThrow(new ResourceNotFoundException(null)); final CreateTableRequest request = new CreateTableRequest().withAttributeDefinitions(ads).withKeySchema(kses) .withTableName(tableName); EasyMock.expect(dynamoDB.createTable(request)).andReturn(cTR); PowerMock.replayAll(); assertEquals(description, DynamoDBManager.createTable(dynamoDB, request)); PowerMock.verifyAll(); }
Example #20
Source File: DynamoDBManager.java From aws-dynamodb-mars-json-demo with Apache License 2.0 | 5 votes |
/** * Creates DynamoDB table. If the table already exists, it validates the key schema. If the key schemas match, a * warning is logged, otherwise an exception is raised. * * @param dynamoDB * {@link AmazonDynamoDB} used to create the table specified in the request. * @param request * Request for creating a table. * @return TableDescription of the existing table or newly created table */ public static TableDescription createTable(final AmazonDynamoDB dynamoDB, final CreateTableRequest request) { try { final DescribeTableResult result = dynamoDB.describeTable(request.getTableName()); if (!request.getKeySchema().equals(result.getTable().getKeySchema())) { throw new IllegalStateException("Table " + request.getTableName() + " already exists and has an invalid schema"); } LOGGER.warning("Table " + request.getTableName() + " already exists"); return result.getTable(); } catch (final ResourceNotFoundException e) { return dynamoDB.createTable(request).getTableDescription(); } }
Example #21
Source File: KinesisSource.java From datacollector with Apache License 2.0 | 5 votes |
private boolean tableExists(String tableName) { try { dynamoDBClient.describeTable(tableName); return true; } catch (ResourceNotFoundException e) { if (LOG.isDebugEnabled()) { LOG.debug("Table '{}' did not exist.", tableName, e); } return false; } }
Example #22
Source File: KinesisSource.java From datacollector with Apache License 2.0 | 5 votes |
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 #23
Source File: DynamoDbDelegate.java From dynamodb-janusgraph-storage-backend with Apache License 2.0 | 5 votes |
private BackendException processDynamoDbApiException(final Throwable e, final String apiName, final String tableName) { Preconditions.checkArgument(apiName != null); Preconditions.checkArgument(!apiName.isEmpty()); final String prefix; if (tableName == null) { prefix = apiName; } else { prefix = String.format("%s_%s", apiName, tableName); } final String message = String.format("%s %s", prefix, e.getMessage()); if (e instanceof ResourceNotFoundException) { return new BackendNotFoundException(String.format("%s; table not found", message), e); } else if (e instanceof ConditionalCheckFailedException) { return new PermanentLockingException(message, e); } else if (e instanceof AmazonServiceException) { if (e.getMessage() != null && (e.getMessage().contains(HASH_RANGE_KEY_SIZE_LIMIT) || e.getMessage().contains(UPDATE_ITEM_SIZE_LIMIT))) { return new PermanentBackendException(message, e); } else { return new TemporaryBackendException(message, e); } } else if (e instanceof AmazonClientException) { //all client exceptions are retriable by default return new TemporaryBackendException(message, e); } else if (e instanceof SocketException) { //sometimes this doesn't get caught by SDK return new TemporaryBackendException(message, e); } // unknown exception type return new PermanentBackendException(message, e); }
Example #24
Source File: GenericDynamoDBTest.java From strongbox with Apache License 2.0 | 5 votes |
@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 #25
Source File: IntegrationTestHelper.java From strongbox with Apache License 2.0 | 5 votes |
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 #26
Source File: IntegrationTestHelper.java From strongbox with Apache License 2.0 | 5 votes |
public static boolean groupExists(SecretsGroupManager secretsGroupManager, SecretsGroupIdentifier identifier) { try { secretsGroupManager.info(identifier); return true; } catch (NoSuchElementException | ResourceNotFoundException | NoSuchEntityException e) { return false; } }
Example #27
Source File: DefaultSecretsGroupManager.java From strongbox with Apache License 2.0 | 5 votes |
private Store getCurrentStore(SecretsGroupIdentifier group, ReadWriteLock readWriteLock) { if (userConfig.getLocalFilePath(group).isPresent()) { // TODO: load encryptor once final KMSEncryptor kmsEncryptor = getEncryptor(group); return new File(userConfig.getLocalFilePath(group).get(), kmsEncryptor, new FileEncryptionContext(group), readWriteLock); } try { DynamoDB dynamoDB = DynamoDB.fromCredentials(awsCredentials, clientConfiguration, group, readWriteLock); return dynamoDB; } catch (ResourceNotFoundException e) { throw new DoesNotExistException("No storage backend found!", e); } }
Example #28
Source File: GenericDynamoDB.java From strongbox with Apache License 2.0 | 5 votes |
private Optional<TableDescription> describeTable() { try { DescribeTableResult result = client.describeTable(tableName); return Optional.of(result.getTable()); } catch (ResourceNotFoundException e) { return Optional.empty(); } }
Example #29
Source File: DynamoDBManagerTest.java From aws-dynamodb-mars-json-demo with Apache License 2.0 | 4 votes |
@Test(expected = IllegalStateException.class) public void testWaitForTableToBecomeActiveTableDoesNotExist() { EasyMock.expect(dynamoDB.describeTable(tableName)).andThrow(new ResourceNotFoundException(null)); PowerMock.replayAll(); DynamoDBManager.waitForTableToBecomeActive(dynamoDB, tableName); }
Example #30
Source File: RequestTest.java From dynamodb-transactions with Apache License 2.0 | 4 votes |
@Override protected List<KeySchemaElement> getTableSchema(String tableName) throws ResourceNotFoundException { return keySchema; }